/* Petit Somme : palette du crépuscule, pensée pour être lue à 3 h du matin sans éblouir. */
:root {
  --night: #1C2142;
  --night-2: #232A55;
  --slate: #2E3566;
  --line: rgba(199, 193, 238, 0.14);
  --lavender: #C7C1EE;
  --ink: #F3F1FF;
  --muted: #A9A6D3;
  --apricot: #FFC48C;
  --apricot-pale: #FFE3C4;
  --mint: #93D9C3;
  --rose: #F28CA2;
  --round: ui-rounded, 'SF Pro Rounded', 'Nunito', 'Varela Round', system-ui, sans-serif;
  --text: -apple-system, BlinkMacSystemFont, 'Segoe UI', system-ui, sans-serif;
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-t: env(safe-area-inset-top, 0px);
  --tabs-h: 64px;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; background: var(--night); }
body {
  margin: 0;
  min-height: 100dvh;
  background:
    radial-gradient(120% 60% at 50% 0%, #2A3168 0%, transparent 70%),
    var(--night);
  color: var(--ink);
  font: 16px/1.5 var(--text);
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior-y: none;
}
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
a { color: var(--lavender); }
svg { width: 1em; height: 1em; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
:focus-visible { outline: 2px solid var(--apricot); outline-offset: 3px; border-radius: 8px; }
[hidden] { display: none !important; }

h1, h2, h3 { font-family: var(--round); font-weight: 700; letter-spacing: -0.01em; margin: 0; }
h1 { font-size: 1.75rem; line-height: 1.15; }
h2 { font-size: 1.125rem; }
h3 { font-size: 1rem; }

/* ---------- Structure */
.view {
  max-width: 480px;
  margin: 0 auto;
  padding: calc(var(--safe-t) + 16px) 20px calc(var(--tabs-h) + var(--safe-b) + 28px);
}
.view.enter { animation: viewIn 0.28s ease-out; }
@keyframes viewIn { from { opacity: 0; transform: translateY(6px); } }

.top { display: flex; align-items: flex-end; justify-content: space-between; gap: 12px; margin-bottom: 16px; }
.age { margin: 2px 0 0; color: var(--muted); font-size: 0.9375rem; }
.section-title { margin: 32px 0 12px; }
.note { color: var(--muted); font-size: 0.9375rem; margin: 12px 0 0; }
.note.small { font-size: 0.8125rem; }

.boot { display: grid; place-items: center; height: 70dvh; color: var(--apricot); font-size: 56px; }
.boot svg { fill: currentColor; stroke: none; animation: bootPulse 1.6s ease-in-out infinite; }
@keyframes bootPulse { 50% { opacity: 0.4; transform: scale(0.94); } }

/* ---------- Le ciel */
.sky-wrap {
  position: relative;
  border-radius: 28px;
  overflow: hidden;
  aspect-ratio: 360 / 240;
  max-height: 42dvh;
  width: 100%;
  box-shadow: 0 24px 60px -30px rgba(10, 8, 40, 0.9);
}
.sky { display: block; width: 100%; height: 100%; stroke: none; }
.sky .star { fill: #fff; animation: twinkle 4s ease-in-out infinite; }
@keyframes twinkle { 50% { opacity: 0.25; } }
.sky .cloud { fill: rgba(255, 255, 255, 0.42); }
.sky .cloud.c1 { animation: drift 46s ease-in-out infinite alternate; }
.sky .cloud.c2 { animation: drift 64s ease-in-out infinite alternate-reverse; }
@keyframes drift { from { transform: translateX(-14px); } to { transform: translateX(26px); } }
.sky .track { fill: none; stroke: rgba(255, 255, 255, 0.8); stroke-width: 1.4; stroke-dasharray: 1.5 6; }
.sky .window { fill: none; stroke: var(--mint); stroke-width: 5; stroke-linecap: round; }
.sky .window-glow { fill: none; stroke: var(--mint); stroke-width: 13; stroke-linecap: round; opacity: 0.45; }
.sky.in-window .window-glow { animation: breathe 2.4s ease-in-out infinite; }
@keyframes breathe { 50% { stroke-width: 24; } }
.sky .hill.back { fill: #2A3168; }
.sky .hill.front { fill: var(--night); }
.sky .lbl { fill: rgba(243, 241, 255, 0.78); font: 600 11px var(--round); }

/* ---------- Statut */
.status { text-align: center; margin: 20px 0 8px; }
.status-label { margin: 0; color: var(--muted); font-size: 0.9375rem; }
.counter { margin: 0; font-family: var(--round); font-variant-numeric: tabular-nums; line-height: 1.05; }
.counter .big { font-size: 3.75rem; font-weight: 700; letter-spacing: -0.03em; }
.counter .unit { font-size: 1.5rem; font-weight: 600; margin-left: 6px; color: var(--lavender); }
.hint { margin: 10px auto 0; max-width: 34ch; color: var(--ink); opacity: 0.92; }
.hint b { font-family: var(--round); font-variant-numeric: tabular-nums; color: var(--mint); font-weight: 700; }
[data-status='overdue'] .hint b, [data-status='stale'] .hint b { color: var(--rose); }

.pressure { display: grid; gap: 6px; justify-items: center; margin: 14px auto 0; width: min(240px, 70%); }
.pressure-bar { width: 100%; height: 6px; border-radius: 6px; background: rgba(255, 255, 255, 0.08); overflow: hidden; }
.pressure-bar i {
  display: block; height: 100%; width: var(--p, 0%); border-radius: inherit;
  background: linear-gradient(90deg, var(--mint), var(--apricot) 80%, var(--rose));
  background-size: 240px 100%;
  transition: width 0.8s ease;
}
.pressure-label { font-size: 0.8125rem; color: var(--muted); font-variant-numeric: tabular-nums; }

/* ---------- Grand bouton */
.actions { display: grid; gap: 10px; margin: 22px 0 8px; }
.main-btn {
  display: flex; align-items: center; justify-content: center; gap: 12px;
  height: 68px; border: 0; border-radius: 999px;
  background: var(--lavender); color: var(--night);
  font: 700 1.1875rem var(--round);
  box-shadow: 0 14px 30px -14px rgba(199, 193, 238, 0.7);
  transition: transform 0.15s ease, background-color 0.5s ease, box-shadow 0.5s ease;
}
.main-btn:active { transform: scale(0.97); }
.main-btn .ico { font-size: 26px; display: grid; }
.main-btn[data-icon='moon'] svg { fill: currentColor; stroke: none; }
[data-status='window'] .main-btn, [data-status='overdue'] .main-btn {
  background: var(--apricot);
  box-shadow: 0 14px 34px -10px rgba(255, 196, 140, 0.75);
  animation: invite 2.4s ease-in-out infinite;
}
@keyframes invite { 50% { box-shadow: 0 14px 44px -6px rgba(255, 196, 140, 0.9); } }
[data-mode='nap'] .main-btn, [data-mode='night'] .main-btn { background: var(--apricot-pale); }
[data-mode='nap'] .main-btn .ico, [data-mode='night'] .main-btn .ico { color: #E58A3A; }
.alt-btn {
  height: 48px; border-radius: 999px; border: 1px solid var(--line);
  background: transparent; color: var(--lavender); font-weight: 600;
}

/* ---------- Encart notifications */
.nudge {
  display: grid; grid-template-columns: auto 1fr; gap: 4px 12px; align-items: start;
  margin: 18px 0 0; padding: 14px 16px; border-radius: 18px;
  background: rgba(147, 217, 195, 0.09); border: 1px solid rgba(147, 217, 195, 0.22);
}
.nudge p { margin: 0; font-size: 0.9375rem; }
.nudge-ico { color: var(--mint); font-size: 22px; display: grid; }
.nudge-actions { grid-column: 2; display: flex; gap: 8px; margin-top: 8px; }

/* ---------- Plan du jour */
.day { margin-top: 30px; }
.day-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 10px; }
.link-btn {
  display: inline-flex; align-items: center; gap: 6px; border: 0; background: none;
  color: var(--lavender); font-weight: 600; font-size: 0.9375rem; padding: 8px 0;
}
.timeline { list-style: none; margin: 0; padding: 0; position: relative; }
.timeline::before {
  content: ''; position: absolute; left: 63px; top: 18px; bottom: 18px; width: 2px;
  background: linear-gradient(var(--line), var(--line));
}
.tl {
  position: relative; display: grid; grid-template-columns: 52px 24px 1fr; align-items: center;
  gap: 0; padding: 9px 4px; border-radius: 14px;
}
.tl[data-id] { cursor: pointer; }
.tl[data-id]:active { background: rgba(255, 255, 255, 0.05); }
.tl-time { font: 600 0.9375rem var(--round); font-variant-numeric: tabular-nums; color: var(--muted); }
.tl-dot {
  justify-self: center; width: 12px; height: 12px; border-radius: 50%;
  background: var(--lavender); box-shadow: 0 0 0 4px var(--night); position: relative; z-index: 1;
}
.tl-body { display: grid; padding-left: 8px; min-width: 0; }
.tl-body b { font-weight: 600; }
.tl-body small { color: var(--muted); font-size: 0.875rem; font-variant-numeric: tabular-nums; }
.tl-body em { display: block; font-style: normal; color: var(--lavender); opacity: 0.8; }
.tl.wake .tl-dot { background: var(--apricot); }
.tl.night .tl-dot { background: #7C86D6; }
.tl.now .tl-dot { background: var(--mint); animation: nowDot 2s ease-in-out infinite; }
@keyframes nowDot { 50% { box-shadow: 0 0 0 4px var(--night), 0 0 0 9px rgba(147, 217, 195, 0.25); } }
.tl.plan .tl-dot { background: var(--night); border: 2px dashed var(--mint); }
.tl.plan.bed .tl-dot { border: 2px solid var(--apricot); }
.tl.plan .tl-body b { color: var(--ink); opacity: 0.85; font-weight: 500; }
.tl.plan .tl-time { color: var(--mint); }
.tl.plan.bed .tl-time { color: var(--apricot); }
.timeline .empty { color: var(--muted); padding: 12px 0; }
.day-total { margin: 12px 0 0; color: var(--muted); font-size: 0.875rem; }

/* ---------- Semaine */
.stats { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.stat {
  display: grid; gap: 2px; padding: 14px 16px; border-radius: 18px;
  background: var(--night-2); border: 1px solid var(--line);
}
.stat:last-child { grid-column: 1 / -1; }
.stat span { color: var(--muted); font-size: 0.8125rem; }
.stat b { font: 700 1.5rem var(--round); font-variant-numeric: tabular-nums; }
.stat small { color: var(--muted); font-size: 0.75rem; }
.stat.off b { color: var(--apricot); }

.chart { display: grid; gap: 8px; }
.chart-scale, .chart-row { display: grid; grid-template-columns: 74px 1fr 54px; align-items: center; gap: 8px; }
.scale-track { grid-column: 2; position: relative; height: 14px; font-size: 0.6875rem; color: var(--muted); }
.scale-track span { white-space: nowrap; position: absolute; top: 0; transform: translateX(-50%); font-variant-numeric: tabular-nums; }
.scale-track span:first-child { transform: none; }
.scale-track span:last-child { transform: translateX(-100%); }
.chart-day { font-size: 0.8125rem; color: var(--muted); white-space: nowrap; }
.chart-total { font: 600 0.8125rem var(--round); text-align: right; font-variant-numeric: tabular-nums; }
.chart-track { position: relative; height: 26px; border-radius: 8px; background: rgba(255, 255, 255, 0.045); overflow: hidden; }
.chart-track .grid { position: absolute; top: 0; bottom: 0; width: 1px; background: var(--line); }
.g6 { left: 25%; } .g12 { left: 50%; } .g18 { left: 75%; }
.blk { position: absolute; top: 3px; bottom: 3px; border: 0; padding: 0; border-radius: 5px; background: var(--lavender); }
.blk.night { background: #6C76C9; }
.blk.open {
  background-image: repeating-linear-gradient(-45deg, rgba(255, 255, 255, 0.25) 0 4px, transparent 4px 8px);
  background-size: 11px 11px; animation: stripes 1s linear infinite;
}
@keyframes stripes { to { background-position: 11px 0; } }
.now-mark { position: absolute; top: 0; bottom: 0; width: 2px; background: var(--apricot); border-radius: 2px; }
.legend { display: flex; gap: 14px; align-items: center; font-size: 0.8125rem; color: var(--muted); margin: 4px 0 0; }
.lg { display: inline-block; width: 12px; height: 12px; border-radius: 4px; margin-right: -8px; }
.lg.nap { background: var(--lavender); } .lg.night { background: #6C76C9; }

.learned { padding: 16px; border-radius: 20px; background: var(--night-2); border: 1px solid var(--line); }
.learned-intro { margin: 0 0 12px; color: var(--muted); font-size: 0.9375rem; }
.learned ul { list-style: none; margin: 0; padding: 0; display: grid; gap: 12px; }
.learned li { display: grid; grid-template-columns: 1fr auto; gap: 0 12px; }
.learned li b { font: 700 1.125rem var(--round); font-variant-numeric: tabular-nums; }
.learned li small { grid-column: 1 / -1; color: var(--muted); font-size: 0.8125rem; }

/* ---------- Repères */
.card { padding: 18px; border-radius: 20px; background: var(--night-2); border: 1px solid var(--line); margin-bottom: 14px; }
.card h2 { margin-bottom: 12px; }
.profile dl { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; margin: 0 0 12px; }
.profile dt { color: var(--muted); font-size: 0.8125rem; }
.profile dd { margin: 0; font: 700 1.125rem var(--round); font-variant-numeric: tabular-nums; }
.profile p { margin: 0; color: var(--muted); font-size: 0.9375rem; }
.cues { display: grid; gap: 10px; }
.cue { padding: 16px; border-radius: 18px; border: 1px solid var(--line); }
.cue.early { background: rgba(147, 217, 195, 0.08); border-color: rgba(147, 217, 195, 0.25); }
.cue.early h3 { color: var(--mint); }
.cue.late { background: rgba(242, 140, 162, 0.08); border-color: rgba(242, 140, 162, 0.25); }
.cue.late h3 { color: var(--rose); }
.cue ul, .plain { margin: 8px 0 0; padding-left: 1.1em; }
.cue li, .plain li { margin: 4px 0; }
.steps { margin: 0; padding-left: 1.4em; display: grid; gap: 10px; }
.steps li::marker { font-family: var(--round); font-weight: 700; color: var(--apricot); }
.steps.install svg { vertical-align: -2px; }

/* ---------- Formulaires */
.form { display: grid; gap: 14px; }
.field { display: grid; gap: 6px; }
.field > span:first-child, legend { color: var(--muted); font-size: 0.875rem; }
fieldset { border: 0; padding: 0; margin: 0; min-width: 0; }
legend { padding: 0; margin-bottom: 6px; }
input[type='text'], input[type='password'], input[type='date'], input[type='time'], input[type='number'], input:not([type]), select {
  width: 100%; min-height: 48px; padding: 10px 14px; border-radius: 14px;
  border: 1px solid var(--line); background: rgba(255, 255, 255, 0.06);
  font-size: 16px; -webkit-appearance: none; appearance: none;
}
input[type='date'], input[type='time'] { font-family: var(--round); font-variant-numeric: tabular-nums; }
input::-webkit-date-and-time-value { text-align: left; }
select { width: auto; min-height: 36px; padding: 4px 12px; margin-left: auto; }
input:focus, select:focus { border-color: var(--lavender); outline: none; }
input[type='range'] { width: 100%; accent-color: var(--apricot); }
.row2 { display: grid; grid-template-columns: 1.3fr 1fr; gap: 8px; }
.row2 legend { grid-column: 1 / -1; }
.row3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.suffix { position: relative; display: block; }
.suffix i { position: absolute; right: 12px; top: 50%; transform: translateY(-50%); font-style: normal; color: var(--muted); font-size: 0.875rem; }
.inline { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }
.inline input[type='time'] { width: 150px; }
.check { display: flex; align-items: center; gap: 10px; min-height: 44px; }
.check input { width: 22px; height: 22px; accent-color: var(--apricot); flex: none; }
.form-help { margin: 0; color: var(--muted); font-size: 0.875rem; }
.form-error { margin: 0; color: var(--rose); font-size: 0.9375rem; }
.form-actions { display: flex; gap: 10px; justify-content: flex-end; margin-top: 4px; }
.saved { margin: 0; min-height: 1.2em; color: var(--mint); font-size: 0.875rem; text-align: right; }
.notif-prefs { gap: 4px; margin-bottom: 10px; }

.seg { display: grid; grid-auto-flow: column; grid-auto-columns: 1fr; padding: 4px; border-radius: 16px; background: rgba(255, 255, 255, 0.06); }
.seg label { position: relative; }
.seg input { position: absolute; opacity: 0; inset: 0; }
.seg span {
  display: flex; align-items: center; justify-content: center; gap: 6px; min-height: 42px; border-radius: 12px;
  font-weight: 600; color: var(--muted); transition: background-color 0.2s, color 0.2s;
}
.seg input:checked + span { background: var(--slate); color: var(--ink); box-shadow: 0 2px 10px -4px rgba(0, 0, 0, 0.6); }
.seg input:focus-visible + span { outline: 2px solid var(--apricot); }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 48px; padding: 0 20px; border-radius: 999px; border: 1px solid transparent;
  font-weight: 700; text-decoration: none; font-family: var(--round); font-size: 1rem;
}
.btn.solid { background: var(--lavender); color: var(--night); }
.btn.ghost { background: transparent; border-color: var(--line); color: var(--lavender); }
.btn.danger { color: var(--rose); }
.btn.small { min-height: 36px; padding: 0 14px; font-size: 0.875rem; }
.btn.wide { width: 100%; }
.btn:disabled { opacity: 0.5; }
.icon-btn { display: grid; place-items: center; width: 40px; height: 40px; border-radius: 50%; border: 0; background: rgba(255, 255, 255, 0.07); font-size: 20px; }
.colophon { text-align: center; color: var(--muted); font: 600 0.8125rem var(--round); opacity: 0.6; }

/* ---------- Écrans d'entrée */
.gate { min-height: 80dvh; display: grid; align-content: center; gap: 14px; text-align: center; }
.gate p { color: var(--muted); margin: 0 auto; max-width: 32ch; }
.gate .form { text-align: left; margin-top: 12px; }
.gate-moon {
  justify-self: center; font-size: 64px; color: var(--apricot); display: grid;
  filter: drop-shadow(0 0 24px rgba(255, 196, 140, 0.55));
  animation: moonRise 1.2s cubic-bezier(0.2, 0.8, 0.2, 1);
}
.gate-moon svg { fill: currentColor; stroke: none; }
@keyframes moonRise { from { opacity: 0; transform: translateY(30px) rotate(-20deg); } }

/* ---------- Choix (réveil nocturne ou du matin) */
.choices { display: grid; gap: 10px; }
.choice {
  display: grid; grid-template-columns: 48px 1fr; gap: 14px; align-items: center; text-align: left;
  padding: 16px; border-radius: 20px; border: 1px solid var(--line); background: rgba(255, 255, 255, 0.04);
}
.choice b { display: block; font: 700 1.0625rem var(--round); }
.choice small { color: var(--muted); }
.choice.suggested { border-color: var(--apricot); background: rgba(255, 196, 140, 0.08); }
.choice-ico { display: grid; place-items: center; width: 48px; height: 48px; border-radius: 50%; background: var(--slate); font-size: 24px; color: var(--lavender); }
.choice-ico svg { fill: currentColor; stroke: none; }
.choice-ico.sun { color: var(--apricot); }
.choice-ico.sun svg { fill: none; stroke: currentColor; }

/* ---------- Barre d'onglets */
.tabs {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 20;
  display: grid; grid-template-columns: repeat(4, 1fr);
  padding: 6px max(8px, env(safe-area-inset-left)) calc(6px + var(--safe-b));
  background: rgba(28, 33, 66, 0.82); backdrop-filter: blur(18px) saturate(1.4); -webkit-backdrop-filter: blur(18px) saturate(1.4);
  border-top: 1px solid var(--line);
}
.tabs a {
  display: grid; justify-items: center; gap: 2px; padding: 6px 0; text-decoration: none;
  color: var(--muted); font-size: 0.6875rem; font-weight: 600;
}
.tabs a[aria-current='page'] { color: var(--apricot); }
.tab-ico { font-size: 24px; display: grid; }
@media (min-width: 640px) {
  .tabs { left: 50%; right: auto; transform: translateX(-50%); width: 440px; bottom: 16px; border-radius: 24px; border: 1px solid var(--line); }
}

/* ---------- Toast */
.toast {
  position: fixed; left: 50%; z-index: 30; bottom: calc(var(--tabs-h) + var(--safe-b) + 14px);
  width: min(440px, calc(100% - 24px)); transform: translate(-50%, 20px); opacity: 0;
  padding: 14px 16px; border-radius: 20px; background: rgba(46, 53, 102, 0.94);
  backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px);
  border: 1px solid var(--line); box-shadow: 0 18px 40px -16px rgba(0, 0, 0, 0.7);
  transition: transform 0.3s cubic-bezier(0.2, 0.9, 0.3, 1.2), opacity 0.2s;
}
.toast.show { transform: translate(-50%, 0); opacity: 1; }
.toast p { margin: 0; }
.toast b { font-family: var(--round); color: var(--apricot); }
.toast-actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 10px; }
.toast-actions button {
  min-height: 36px; padding: 0 12px; border-radius: 12px; border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.07); font-weight: 600; font-size: 0.875rem;
}

/* ---------- Panneau du bas */
.sheet { position: fixed; inset: 0; z-index: 40; }
.sheet-backdrop { position: absolute; inset: 0; background: rgba(10, 12, 32, 0.55); opacity: 0; transition: opacity 0.3s; }
.sheet-panel {
  position: absolute; left: 0; right: 0; bottom: 0; margin: 0 auto; max-width: 520px;
  max-height: 92dvh; overflow-y: auto; overscroll-behavior: contain;
  padding: 8px 20px calc(20px + var(--safe-b)); border-radius: 28px 28px 0 0;
  background: var(--slate); border: 1px solid var(--line); border-bottom: 0;
  transform: translateY(100%); transition: transform 0.34s cubic-bezier(0.2, 0.9, 0.25, 1);
}
.sheet.open .sheet-backdrop { opacity: 1; }
.sheet.open .sheet-panel { transform: translateY(0); }
.sheet-grip { width: 40px; height: 5px; border-radius: 3px; background: rgba(255, 255, 255, 0.25); margin: 4px auto 10px; }
.sheet-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 14px; }

/* ---------- Petits moments */
body::after {
  content: ''; position: fixed; inset: 0; pointer-events: none; opacity: 0; z-index: 50;
}
body.pulse-sleep::after { background: radial-gradient(80% 60% at 50% 30%, rgba(108, 118, 201, 0.45), transparent 70%); animation: flash 1.4s ease-out; }
body.pulse-wake::after { background: radial-gradient(80% 60% at 50% 30%, rgba(255, 196, 140, 0.4), transparent 70%); animation: flash 1.4s ease-out; }
@keyframes flash { 20% { opacity: 1; } }

.sync-dot { width: 10px; height: 10px; border-radius: 50%; background: var(--rose); margin-bottom: 10px; display: none; }
body.offline .sync-dot { display: block; animation: nowDot 2s ease-in-out infinite; }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}
