/* ============================================================
   sleepbook · explained — animated explainer for the sleepbook diary.
   Shares sleepbook's "Nightfall ink" identity: jade sleep on ink gaps.
   Motif carried through: the night strip. Scroll-driven reveals + the
   strip filling in. Light + dark, WCAG-AA in both. System sans only,
   tabular numerals. Every animation degrades to a legible static state
   under prefers-reduced-motion.
   ============================================================ */

:root {
  /* dark (default) — identical tokens to sleepbook */
  --bg:        #0B0F0E;   /* ink-black with a green cast */
  --surface:   #131A17;
  --surface2:  #182420;
  --line:      #26332D;
  --text:      #E8F3ED;   /* mist — 15.6:1 on --bg */
  --muted:     #9AB0A6;   /* sage — 7.0:1 on --bg */
  --jade:      #2EBD8B;   /* accent */
  --mint:      #9BEFCB;   /* highlight */
  --amber:     #E0A458;   /* attention */
  --rose:      #F08A8A;   /* "blocked" mark (AA on surfaces) */

  --jade-dim:  rgba(46, 189, 139, 0.16);
  --amber-dim: rgba(224, 164, 88, 0.16);
  --rose-dim:  rgba(240, 138, 138, 0.14);

  --on-jade:   #04120C;   /* near-black reads AA on bright jade */

  --sans: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, "SF Mono", "Cascadia Mono", Menlo, Consolas, monospace;

  --radius: 14px;
  --radius-sm: 9px;
  --shadow: 0 20px 46px -26px rgba(0,0,0,0.8);
  --wrap: 980px;
  --ease: cubic-bezier(0.22, 0.61, 0.36, 1);

  --strip-sleep: var(--jade);
  --strip-track: #0E1512;
  --strip-frame: #2A382F;
  --gap-ink:     #0A100D;
}

@media (prefers-color-scheme: light) {
  :root {
    --bg:        #F3FAF6;   /* paper-mint */
    --surface:   #FFFFFF;
    --surface2:  #EAF4EE;
    --line:      #D2E4DA;
    --text:      #122019;   /* ink — 13.9:1 on --bg */
    --muted:     #3F5A4E;   /* 6.3:1 on --bg */
    --jade:      #0F6B4E;   /* deep-jade — 5.4:1 on --bg */
    --mint:      #0F6B4E;
    --amber:     #8A5A17;   /* AA on light surfaces */
    --rose:      #B3261E;   /* AA "blocked" on light */

    --jade-dim:  rgba(15, 107, 78, 0.12);
    --amber-dim: rgba(138, 90, 23, 0.12);
    --rose-dim:  rgba(179, 38, 30, 0.10);

    --shadow: 0 18px 40px -28px rgba(18,32,25,0.35);

    --strip-sleep: #12855F;
    --strip-track: #E7F2EC;
    --strip-frame: #B8D2C6;
    --gap-ink:     #DCEBE3;

    /* deep-jade fill is dark → on-accent text must be WHITE for AA */
    --on-jade: #FFFFFF;
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; scroll-behavior: smooth; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--sans);
  font-size: 16px;
  line-height: 1.55;
  letter-spacing: -0.003em;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
  overflow-x: hidden;
}
.sefinal__val, .step__eq, .clockfig__eq, .herofig__eq, .csp__code { font-variant-numeric: tabular-nums; }

h1, h2, h3 { margin: 0; font-weight: 750; letter-spacing: -0.02em; line-height: 1.12; }
p { margin: 0; }
em { font-style: normal; color: var(--text); }
strong { color: var(--text); }

.ink-jade { color: var(--jade); }
.ink-gap  { color: var(--muted); }

.visually-hidden {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}

/* ambient wash — same signature as the app */
body::before {
  content: ""; position: fixed; inset: 0; z-index: -1; pointer-events: none;
  background:
    radial-gradient(1100px 560px at 82% -10%, rgba(46,189,139,0.10), transparent 60%),
    radial-gradient(760px 460px at 4% 2%, rgba(155,239,203,0.05), transparent 55%);
}
@media (prefers-color-scheme: light) {
  body::before { background:
    radial-gradient(1000px 520px at 84% -12%, rgba(15,107,78,0.07), transparent 60%); }
}

/* ---------- skip link + focus ---------- */
.skip-link {
  position: absolute; left: 12px; top: -60px;
  background: var(--jade); color: var(--on-jade);
  padding: 10px 16px; border-radius: 10px; font-weight: 700;
  z-index: 80; transition: top 0.18s var(--ease); text-decoration: none;
}
.skip-link:focus { top: 12px; }
a:focus-visible, button:focus-visible {
  outline: 3px solid var(--jade); outline-offset: 3px; border-radius: 6px;
}

/* ---------- progress rail ---------- */
.rail {
  position: fixed; top: 0; left: 0; right: 0; height: 3px;
  background: transparent; z-index: 70;
}
.rail__fill {
  display: block; height: 100%; width: 0%;
  background: linear-gradient(90deg, var(--jade), var(--mint));
  transition: width 0.1s linear;
}

/* ---------- buttons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center;
  appearance: none; cursor: pointer; text-decoration: none;
  background: var(--surface2); color: var(--text);
  border: 1px solid var(--line); border-radius: var(--radius-sm);
  padding: 12px 20px; font-size: 15px; font-weight: 700; font-family: inherit;
  transition: transform 0.08s var(--ease), background 0.15s var(--ease), border-color 0.15s var(--ease);
}
.btn:hover { border-color: var(--jade); }
.btn:active { transform: translateY(1px); }
.btn--primary { background: var(--jade); color: var(--on-jade); border-color: transparent; }
.btn--primary:hover { background: var(--mint); color: var(--on-jade); }
.btn--ghost { background: transparent; }
.btn--big { padding: 15px 30px; font-size: 17px; }

/* ---------- hero ---------- */
.hero { padding: 60px 20px 30px; }
.hero__inner { max-width: var(--wrap); margin: 0 auto; }
.brand { display: flex; align-items: center; gap: 12px; margin-bottom: 26px; }
.brand__mark { width: 40px; height: 40px; border-radius: 11px; box-shadow: var(--shadow); }
.brand__name { font-size: 22px; font-weight: 800; letter-spacing: -0.03em; display: inline-flex; align-items: baseline; gap: 7px; }
.brand__sub {
  font-size: 12px; font-weight: 700; letter-spacing: 0.16em; text-transform: uppercase;
  color: var(--jade); padding: 3px 8px; border: 1px solid var(--line); border-radius: 999px;
}
.eyebrow {
  text-transform: uppercase; letter-spacing: 0.14em; font-size: 12.5px;
  font-weight: 700; color: var(--jade); margin-bottom: 14px;
}
.hero__title { font-size: clamp(28px, 5vw, 50px); max-width: 20ch; letter-spacing: -0.03em; }
.hero__lede {
  margin-top: 18px; max-width: 60ch; color: var(--muted);
  font-size: clamp(16px, 2vw, 19px); line-height: 1.55;
}
.hero__lede strong { color: var(--jade); }
.hero__cta { display: flex; flex-wrap: wrap; gap: 12px; margin-top: 26px; }

/* hero animated strip */
.herofig { margin: 44px 0 0; }
.herofig__strip {
  position: relative; height: 44px; border-radius: 22px;
  background: var(--strip-track); border: 1px solid var(--strip-frame); overflow: hidden;
  max-width: 720px;
}
.herofig__seg { position: absolute; top: 0; height: 100%; background: var(--strip-sleep); transform-origin: left center; }
.herofig__seg--a { left: 12%; width: 44%; }
.herofig__seg--b { left: 60%; width: 26%; }
.herofig__seg--c { left: 89%; width: 7%; background: var(--mint); }
.herofig__cap { margin-top: 14px; color: var(--muted); font-size: 14px; font-weight: 600; }
.herofig__k { color: var(--jade); }
.herofig__eq { color: var(--text); font-weight: 700; }
.hero__scrollhint {
  margin-top: 40px; color: var(--muted); font-size: 12.5px; text-transform: uppercase;
  letter-spacing: 0.2em; font-weight: 700;
}

/* strip draw-in animation (hero) */
@keyframes drawSeg { from { transform: scaleX(0); } to { transform: scaleX(1); } }

/* ---------- scenes ---------- */
.scene { padding: 74px 20px; border-top: 1px solid var(--line); }
.scene__inner { max-width: var(--wrap); margin: 0 auto; }
.scene__num {
  font-family: var(--mono); font-size: 13px; font-weight: 700; letter-spacing: 0.1em;
  color: var(--jade); margin-bottom: 12px;
}
.scene__h { font-size: clamp(23px, 3.4vw, 36px); max-width: 22ch; letter-spacing: -0.025em; }
.scene__lede { margin-top: 18px; max-width: 62ch; color: var(--text); font-size: clamp(16px, 1.9vw, 18.5px); }
.scene__lede strong { color: var(--text); }
.scene__note { margin-top: 22px; max-width: 62ch; color: var(--muted); font-size: 15.5px; }
.scene__note strong { color: var(--text); }

/* ---------- reveal-on-scroll ---------- */
.reveal { opacity: 0; transform: translateY(22px); transition: opacity 0.6s var(--ease), transform 0.6s var(--ease); }
.reveal--d1 { transition-delay: 0.08s; }
.reveal--d2 { transition-delay: 0.18s; }
.reveal--d3 { transition-delay: 0.28s; }
.is-in .reveal, .reveal.is-in { opacity: 1; transform: none; }

/* ---------- scene 1: problem ---------- */
.painline { display: flex; flex-wrap: wrap; gap: 10px; margin-top: 26px; }
.painline__t {
  font-family: var(--mono); font-size: 14px; color: var(--muted); font-weight: 600;
  padding: 8px 14px; border: 1px dashed var(--line); border-radius: 999px; background: var(--surface);
}
.painline__t--q { color: var(--amber); border-color: var(--amber); border-style: solid; background: var(--amber-dim); font-weight: 700; }

/* ---------- scene 2: strip motif (labelled SVG) ---------- */
.stripfig { margin: 32px 0 0; }
.nstrip { width: 100%; height: auto; max-width: 100%; display: block; }
.nstrip__track { fill: var(--strip-track); }
.nstrip__frame { fill: none; stroke: var(--strip-frame); stroke-width: 1.5; }
.nstrip__sleep { fill: var(--strip-sleep); transform-box: fill-box; transform-origin: left center; }
.nstrip__lbl line { stroke: var(--muted); stroke-width: 1.5; }
.nstrip__lbl text { fill: var(--muted); font-size: 20px; font-weight: 600; text-anchor: middle; font-family: var(--sans); }
.nstrip__cap { fill: var(--on-jade); font-size: 22px; font-weight: 800; text-anchor: middle; font-family: var(--sans); }
@media (prefers-color-scheme: light) { .nstrip__cap { fill: #FFFFFF; } }

/* strip blocks draw in when the scene enters */
.is-in .nstrip__sleep { animation: drawSeg 0.7s var(--ease) both; }
.is-in .nstrip__sleep.s2 { animation-delay: 0.5s; }
.is-in .nstrip__lbl, .is-in .nstrip__cap { opacity: 0; animation: fadeIn 0.5s var(--ease) forwards; animation-delay: 0.9s; }
@keyframes fadeIn { to { opacity: 1; } }

/* ---------- scene 3: formula steps ---------- */
.steps { list-style: none; margin: 30px 0 0; padding: 0; display: grid; gap: 10px; max-width: 720px; }
.step {
  display: grid; grid-template-columns: minmax(150px, 1fr) minmax(150px, auto) 1fr; gap: 14px;
  align-items: baseline; padding: 14px 18px; border: 1px solid var(--line);
  border-left: 4px solid var(--line); border-radius: var(--radius-sm); background: var(--surface);
}
.step__k { font-weight: 700; font-size: 15px; }
.step__eq { font-size: 15px; color: var(--text); white-space: nowrap; }
.step__eq strong { color: var(--jade); }
.step__why { font-size: 13px; color: var(--muted); }
.step--minus { border-left-color: var(--amber); }
.step--minus .step__eq strong { color: var(--amber); }
.step--total { border-left-color: var(--jade); background: var(--jade-dim); }
.step--total .step__k, .step--total .step__eq strong { color: var(--jade); }
.step--total .step__eq strong { font-size: 17px; }

.sefinal {
  margin-top: 26px; padding: 24px 26px; border: 1px solid var(--jade);
  border-radius: var(--radius); background: var(--jade-dim); max-width: 720px;
}
.sefinal__eq { font-size: clamp(18px, 2.4vw, 24px); display: flex; align-items: center; gap: 12px; flex-wrap: wrap; font-weight: 700; }
.sefinal__frac { display: inline-flex; flex-direction: column; font-size: 0.62em; text-align: center; line-height: 1.15; }
.sefinal__frac span:first-child { border-bottom: 2px solid currentColor; padding-bottom: 2px; }
.sefinal__frac span:last-child { padding-top: 2px; }
.sefinal__val { color: var(--jade); font-size: 1.5em; font-weight: 800; }
.sefinal__pct { font-size: 0.6em; }
.sefinal__note { margin-top: 14px; color: var(--muted); font-size: 14.5px; }

/* ---------- scene 4: midnight ---------- */
.clockfig { margin: 30px 0 0; padding: 22px 24px; border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface); max-width: 720px; }
.clockrow { display: flex; align-items: center; justify-content: space-between; gap: 14px; }
.clockrow__t { font-family: var(--mono); font-size: clamp(22px, 4vw, 34px); font-weight: 800; letter-spacing: -0.02em; }
.clockrow__t--out { color: var(--text); }
.clockrow__t--wake { color: var(--jade); }
.clockrow__mid { font-size: 12px; text-transform: uppercase; letter-spacing: 0.16em; color: var(--amber); font-weight: 700; padding: 0 10px; }
.clockrow__bar { position: relative; height: 34px; margin: 16px 0 12px; border-radius: 8px; background: var(--strip-track); border: 1px solid var(--strip-frame); overflow: hidden; }
.clockrow__wrap {
  position: absolute; inset: 0; display: flex; align-items: center; justify-content: center;
  font-size: 13px; font-weight: 700; color: var(--on-jade);
  background: repeating-linear-gradient(45deg, var(--jade), var(--jade) 10px, var(--mint) 10px, var(--mint) 20px);
  transform-origin: left center;
}
.is-in .clockrow__wrap { animation: drawSeg 0.9s var(--ease) 0.2s both; }
.clockfig__eq { font-size: 16px; font-weight: 600; }
.clockfig__eq strong { color: var(--jade); }

/* ---------- scene 5: privacy ---------- */
.csp { margin: 28px 0 0; max-width: 640px; }
.csp__code {
  margin: 0; padding: 20px 22px; border-radius: var(--radius); overflow-x: auto;
  background: #06100C; color: #CFEFE0; border: 1px solid var(--strip-frame);
  font-family: var(--mono); font-size: 14.5px; line-height: 1.7;
}
@media (prefers-color-scheme: light) { .csp__code { background: #0B211A; color: #E4F5EC; } }
.csp__code .csp__hl { color: var(--mint); font-weight: 700; }
@media (prefers-color-scheme: light) { .csp__code .csp__hl { color: #7FE3B8; } }
.csp__cap { margin-top: 14px; color: var(--muted); font-size: 14.5px; max-width: 60ch; }
.csp__hl-text { font-family: var(--mono); color: var(--jade); font-weight: 700; font-size: 0.94em; }

.netgrid { list-style: none; margin: 26px 0 0; padding: 0; display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 10px; max-width: 720px; }
.net {
  display: flex; align-items: center; gap: 10px; padding: 13px 16px;
  border: 1px solid var(--line); border-radius: var(--radius-sm); background: var(--surface);
  font-size: 15px; font-weight: 600;
}
.net__x { color: var(--rose); font-weight: 800; font-size: 18px; line-height: 1; }
.net__ok { color: var(--jade); font-weight: 800; font-size: 16px; line-height: 1; }
.net__tag { margin-left: auto; font-size: 11px; text-transform: uppercase; letter-spacing: 0.08em; font-weight: 800; color: var(--rose); background: var(--rose-dim); padding: 3px 9px; border-radius: 999px; }
.net__tag--ok { color: var(--jade); background: var(--jade-dim); }
.net--ok { border-color: var(--jade); }

/* ---------- scene 6: feature tour ---------- */
.tourgrid { margin-top: 30px; display: grid; grid-template-columns: repeat(auto-fit, minmax(250px, 1fr)); gap: 14px; }
.tile { padding: 20px 22px; border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface); }
.tile__h { font-size: 16.5px; color: var(--jade); }
.tile__p { margin-top: 8px; color: var(--muted); font-size: 14.5px; line-height: 1.5; }

/* ---------- scene 7: CTA ---------- */
.scene--cta { border-top: 1px solid var(--line); }
.cta { text-align: center; }
.cta__strips { display: grid; gap: 8px; max-width: 460px; margin: 0 auto 30px; }
.cta__strip { position: relative; height: 16px; border-radius: 8px; background: var(--strip-track); border: 1px solid var(--strip-frame); overflow: hidden; }
.cta__strip i { position: absolute; top: 0; height: 100%; background: var(--strip-sleep); transform-origin: left center; }
.cta__strip i.mint { background: var(--mint); }
.is-in .cta__strip i { animation: drawSeg 0.7s var(--ease) both; }
.is-in .cta__strip:nth-child(2) i { animation-delay: 0.08s; }
.is-in .cta__strip:nth-child(3) i { animation-delay: 0.16s; }
.is-in .cta__strip:nth-child(4) i { animation-delay: 0.24s; }
.is-in .cta__strip:nth-child(5) i { animation-delay: 0.32s; }
.cta__h { font-size: clamp(26px, 4vw, 40px); max-width: 18ch; margin: 0 auto; letter-spacing: -0.03em; }
.cta__p { margin: 18px auto 0; max-width: 52ch; color: var(--muted); font-size: 16.5px; }
.scene--cta .btn { margin-top: 28px; }
.cta__sub { margin-top: 16px; color: var(--muted); font-size: 13.5px; font-weight: 600; }

/* ---------- footer ---------- */
.foot { border-top: 1px solid var(--line); padding: 30px 20px 46px; }
.foot__inner { max-width: var(--wrap); margin: 0 auto; }
.foot__disclaimer { color: var(--muted); font-size: 13px; line-height: 1.6; max-width: 92ch; }
.foot__disclaimer strong { color: var(--text); }
.foot__meta { margin-top: 14px; color: var(--muted); font-size: 12.5px; }
.foot__meta a { color: var(--jade); font-weight: 700; text-decoration: underline; text-underline-offset: 2px; }

/* ---------- responsive ---------- */
@media (max-width: 620px) {
  .step { grid-template-columns: 1fr; gap: 4px; }
  .step__eq { white-space: normal; }
}

/* ============================================================
   REDUCED MOTION — every animation collapses to its finished,
   legible end state. Nothing depends on motion to be readable.
   ============================================================ */
@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
  * { transition: none !important; animation: none !important; }
  .reveal { opacity: 1 !important; transform: none !important; }
  .rail { display: none; }
  .hero__scrollhint { display: none; }
  /* SVG strip blocks and CSS strips must be at full width with no keyframe */
  .nstrip__sleep, .herofig__seg, .clockrow__wrap, .cta__strip i { transform: none !important; }
  .nstrip__lbl, .nstrip__cap { opacity: 1 !important; }
}
