/* ═══════════════════════════════════════════════════════════════════════════
   design/tokens.css — Vitalité design system · colour, type, space, motion

   THE ONLY PLACE COLOUR AND TYPE ARE DECIDED. Nothing else should hardcode a
   hex value; if a rule needs a colour it takes a token from here.

   How it works
   ------------
   The site already contains ~7 000 `var(--…)` references, so this file does not
   replace any stylesheet — it redefines the names those stylesheets already use,
   in two surfaces:

     1. `:root`  → `--bg --surface --text --accent …` (gold-blue-theme.css names)
                   used by every app page and all 14 textbook chapters.
     2. `body.jr` → `--jr-paper --jr-ink --jr-gold …` (journal.css names)
                   used by the landing, dashboard and every redesigned page.

   Load order: LAST, after journal.css. journal.css is the current cascade
   winner; this file must come after it or nothing changes.

   Brand direction
   ---------------
   Deep navy ink on warm ivory, muted teal as the single interactive accent,
   amber reserved for emphasis and never for clicks. Editorial structure,
   product-grade interface. No gradients, no glow, no decorative colour.

   Accessibility
   -------------
   Every text/background pair below meets WCAG 2.2 AA (≥4.5:1 body, ≥3:1 large
   and UI). The brief's #4F9D91 is 2.9:1 on ivory and therefore exists only as
   --brand-teal for fills; text teal is #2E6F66 at 5.3:1.
   ═══════════════════════════════════════════════════════════════════════════ */

/* ═══ 1. Brand primitives ═══════════════════════════════════════════════════ */
:root{
  /* the seven brand values, verbatim */
  --brand-navy:#172B3A;
  --brand-ivory:#F6F4EE;
  --brand-teal:#4F9D91;
  --brand-sage:#DCE8DF;
  --brand-amber:#DDA66F;
  --brand-mist:#E8EAF0;
  --brand-white:#FFFFFF;

  /* accessible derivatives */
  --brand-teal-ink:#2E6F66;   /* 5.3:1 on ivory  — text, icons, borders */
  --brand-teal-deep:#256157;  /* 7.0:1 on ivory  — hover, active */
  --brand-teal-lift:#7FC3B4;  /* 8.4:1 on navy   — text in dark mode */
  --brand-clay:#9A5726;       /* 5.0:1 on ivory  — editorial emphasis */
  --brand-clay-lift:#E0A97B;

  /* ── type ────────────────────────────────────────────────────────────── */
  /* Body: Nunito Sans — the open stand-in for Avenir (see fonts.css). */
  --font-sans:"Nunito Sans",-apple-system,BlinkMacSystemFont,
              "SF Pro Text","Segoe UI",Inter,"PingFang SC","Hiragino Sans GB",
              "Microsoft YaHei",sans-serif;
  /* Display: Newsreader — the open stand-in for Anthropic Serif / Tiempos. */
  --font-display:"Newsreader",Georgia,"Times New Roman",
                 "Songti SC","STSong",serif;
  --font-mono:ui-monospace,"SF Mono",SFMono-Regular,Menlo,Consolas,monospace;

  /* fluid scale — one ramp for the whole site, no page-level font-size hacks */
  --t-display:clamp(2.55rem,5.4vw,4.35rem);
  --t-h1:clamp(2.05rem,3.9vw,3.15rem);
  --t-h2:clamp(1.6rem,2.5vw,2.15rem);
  --t-h3:clamp(1.22rem,1.5vw,1.45rem);
  --t-h4:1.0625rem;
  --t-lead:clamp(1.0625rem,1.15vw,1.1875rem);
  --t-body:1rem;
  --t-sm:.9063rem;
  --t-xs:.875rem;    /* was 13px — too small for captions read at arm's length */
  --t-label:.75rem;  /* was 11px — tracked caps at 11px read as texture, not words */

  --w-regular:400; --w-medium:500; --w-semibold:600; --w-bold:700;

  --lh-display:1.015; --lh-head:1.10; --lh-snug:1.32; --lh-body:1.62;
  --tr-display:-.028em; --tr-head:-.021em; --tr-body:-.004em;
  --tr-label:.135em;
  /* a serif needs a looser display leading and about half the negative
     tracking a grotesque can take before the joins close up */
  --tr-serif:-.014em;
  --lh-serif:1.06;

  /* ── space · 4px base ─────────────────────────────────────────────────── */
  --s1:.25rem; --s2:.5rem;  --s3:.75rem; --s4:1rem;   --s5:1.5rem;
  --s6:2rem;   --s7:3rem;   --s8:4rem;   --s9:6rem;   --s10:8rem;

  /* ── shape ────────────────────────────────────────────────────────────── */
  --r-xs:3px; --r-sm:6px; --r-md:10px; --r-lg:16px; --r-pill:999px;
  --rule-w:1px;

  /* ── measure ──────────────────────────────────────────────────────────── */
  --measure:66ch;          /* comfortable reading line */
  --measure-tight:52ch;    /* captions, leads */
  --shell:1200px;
  --shell-wide:1360px;
  --gutter:clamp(20px,4vw,48px);

  /* ── motion ───────────────────────────────────────────────────────────── */
  --ease:cubic-bezier(.2,.7,.1,1);
  --ease-out:cubic-bezier(.16,1,.3,1);
  --dur-1:120ms; --dur-2:180ms; --dur-3:260ms;
}

/* ═══ 2. Surface A — light (default) ════════════════════════════════════════ */
:root{
  --canvas:#F6F4EE;
  --canvas-2:#EFEDE7;
  --surface:#FFFFFF;
  --surface-2:#F1EFE9;
  --surface-3:var(--brand-sage);
  --surface-sunk:#EAE7DF;

  --ink:var(--brand-navy);
  --ink-2:#3E5566;
  --ink-3:#56697A;   /* was #6E8595 — 3.5:1 on ivory and 4.38:1 on the footer's
     #F1EFE9, both short of AA for 12–14px captions. Now 5.16:1 / 4.94:1. */

  --line:#DCDDD6;
  --line-2:#C7CBC3;
  --line-strong:var(--brand-navy);

  --accent:var(--brand-teal-ink);
  --accent-hover:var(--brand-teal-deep);
  --accent-bright:var(--brand-teal);
  --accent-wash:#E9F1EF;
  --on-accent:#FFFFFF;

  --emphasis:var(--brand-clay);
  --emphasis-wash:#F7EEE6;

  --ok:#2E7D5B;    --ok-wash:#E7F2EC;
  --warn:#9A6B1F;  --warn-wash:#F8F1E4;
  --err:#A8433F;   --err-wash:#F8EAE9;
  --info:#2F6191;  --info-wash:#EAF0F6;

  --focus:var(--brand-teal-ink);
  --focus-ring:0 0 0 2px var(--canvas),0 0 0 4px var(--focus);

  --shadow-1:0 1px 2px rgba(23,43,58,.05),0 1px 3px rgba(23,43,58,.06);
  --shadow-2:0 2px 6px rgba(23,43,58,.06),0 8px 20px rgba(23,43,58,.06);
  --shadow-3:0 8px 28px rgba(23,43,58,.10),0 2px 8px rgba(23,43,58,.05);
}

/* ═══ 2c. Lesson-card tints ═════════════════════════════════════════════════ */
/* Every lesson slide is tagged by kind, and the tag is what a reader learns to
   scan for. There were five category colours: purple, pink, green, red, blue —
   a rainbow that also collided with the green "correct" and the red "wrong"
   used thirty lines further down the same sheet, so a purple "idea" card and a
   green "note" card and a green "you got it right" tile all competed for the
   same glance.

   The mapping below keeps the categories distinguishable, binds them to the
   same navy / teal / clay family as the rest of the site, and demotes
   "example" — two of every three cards — to the quietest value in the set, so
   a page of examples reads as text with labels instead of a wall of colour.

   Nothing here needs a dark override: every value is another token that
   already flips. */
:root{
  --tint-idea:var(--accent);      /* the one thing to remember   · teal  */
  --tint-def:var(--ink);          /* definition — the spine      · navy  */
  --tint-note:var(--info);        /* aside, caveat               · steel */
  --tint-analogy:var(--emphasis); /* a different lens            · clay  */
  --tint-example:var(--ink-2);    /* the most frequent card      · quiet */
  --tint-mistake:var(--err);      /* do not do this              · red   */
  --tint-hint:var(--accent);
}

/* ═══ 2d. Data-series colours ═══════════════════════════════════════════════ */
/* Every interactive model in ib-sehs-models.js paints with --c0, --c1 and --c2:
   607 declarations in ib-sehs-lesson.css alone, plus inline `bar(...,'var(--c0)')`
   calls in the script. THEY WERE NEVER DEFINED BY ANY STYLESHEET.

   A `fill: color-mix(in srgb, var(--c0) 20%, var(--surface))` whose variable is
   undefined is invalid at computed-value time, so the property takes its initial
   value — which for SVG fill is black. That is why the muscle fibre in the
   synapse figure rendered as a solid black blob with a red outline, why its
   "striated muscle fibre" legend swatch was invisible, and why the "synaptic
   cleft" label was dark-on-dark. It is not a contrast accident; the shapes had
   no colour at all.

   The three are a severity ramp, not decoration: the models step through them
   in that order (`risk === 2 ? c0 : risk === 1 ? c1 : green`), and the synapse
   legend reads knob = c2 (blue), neurotransmitter = c1 (amber),
   receptor/fibre = c0 (red). So they map onto the semantic ramp, and inherit the
   dark values from the block below because a custom property resolves where it
   is declared — declaring them only on :root would pin them to the light ramp. */
:root{
  --c0:var(--err);
  --c1:var(--warn);
  --c2:var(--info);
}

/* ═══ 3. Surface B — dark ═══════════════════════════════════════════════════ */
/* `body.dark` is how every app page and all 14 chapters mark dark mode;
   `html.jr-dk` is the landing. Both are covered here. The alias block at the
   end of this section matters: `--bg:var(--canvas)` declared only on `:root`
   would resolve to the light canvas even in dark mode, because custom
   properties resolve where they are declared. */
:root[data-theme="dark"],
html.jr-dk,
body.dark{
  --canvas:#121E28;
  --canvas-2:#0E1820;
  --surface:#172632;
  --surface-2:#1B2C38;
  --surface-3:#223642;
  --surface-sunk:#0F1A23;

  --ink:#EDF1EE;
  --ink-2:#B7C6C9;
  --ink-3:#7F9499;

  --line:#2A3D4A;
  --line-2:#35505F;
  --line-strong:#EDF1EE;

  --accent:var(--brand-teal-lift);
  --accent-hover:#9BD6C8;
  --accent-bright:var(--brand-teal);
  --accent-wash:#1B302F;
  --on-accent:#0C1A22;

  --emphasis:var(--brand-clay-lift);
  --emphasis-wash:#2B2018;

  --ok:#6FC49B;   --ok-wash:#152C22;
  --warn:#E0B36A; --warn-wash:#2B2416;
  --err:#E2897F;  --err-wash:#2E1A19;
  --info:#8FB6DC; --info-wash:#152430;

  /* the series ramp, re-resolved against the dark values above (see 2d) */
  --c0:var(--err);
  --c1:var(--warn);
  --c2:var(--info);

  --focus:var(--brand-teal-lift);
  --focus-ring:0 0 0 2px var(--canvas),0 0 0 4px var(--focus);

  --shadow-1:0 1px 2px rgba(0,0,0,.30);
  --shadow-2:0 2px 8px rgba(0,0,0,.34),0 10px 24px rgba(0,0,0,.28);
  --shadow-3:0 10px 34px rgba(0,0,0,.44);
  color-scheme:dark;

  /* re-alias, so the legacy names resolve to the dark values at this level */
  --bg:var(--canvas);
  --text:var(--ink);
  --text2:var(--ink-2);
  --text3:var(--ink-3);
  --text-1:var(--ink); --text-2:var(--ink-2); --text-muted:var(--ink-3);
  --border:var(--line);
  --border2:var(--line-2);
  --accent2:var(--accent-hover);
  --accent-bg:var(--accent-wash);
  --green:var(--ok); --red:var(--err); --amber:var(--warn);
  --shadow-sm:var(--shadow-1); --shadow:var(--shadow-2); --shadow-lg:var(--shadow-3);
  --card:var(--surface); --card-2:var(--surface-2);
}
:root{color-scheme:light}
body.dark{background:var(--canvas);color:var(--ink)}

/* ═══ 4. Map the design tokens onto the existing variable names ═════════════ */
/* 4a — the app surface (gold-blue-theme.css names, `:root` scope) */
:root{
  --bg:var(--canvas);
  --text:var(--ink);
  --text2:var(--ink-2);
  --text3:var(--ink-3);
  --border:var(--line);
  --border2:var(--line-2);
  --accent2:var(--accent-hover);
  --accent-bg:var(--accent-wash);
  --green:var(--ok); --red:var(--err); --amber:var(--warn);
  --shadow-sm:var(--shadow-1); --shadow:var(--shadow-2); --shadow-lg:var(--shadow-3);
  --radius:var(--r-md); --radius-sm:var(--r-sm); --radius-lg:var(--r-lg);
  --font:var(--font-sans);
  /* `--font-heading` is not "the headline face" in this codebase — 28 legacy
     sheets point it at component titles (quiz questions, flashcard terms,
     video captions). The serif belongs on real headings only, so this token
     stays on the text face and the h1–h3 rule below carries the display. */
  --font-heading:var(--font-sans);
  /* aliases used by some legacy sheets */
  --text-1:var(--ink); --text-2:var(--ink-2); --text-muted:var(--ink-3);
  --card:#FFFFFF; --card-2:var(--surface-2);
}

/* 4b — the editorial surface (journal.css names, `body.jr` scope) */
body.jr{
  --jr-paper:var(--canvas);
  --jr-paper2:var(--canvas-2);
  --jr-card:var(--surface);
  --jr-ink:var(--ink);
  --jr-ink2:var(--ink-2);
  --jr-ink3:var(--ink-3);
  --jr-rule:var(--line-2);
  --jr-rule2:var(--line);
  --jr-gold:var(--accent);
  --jr-gold-hi:var(--accent);   /* NOT --accent-bright: that is #4F9D91, 2.9:1 on
     ivory, and every eyebrow, button fill and inline link on a journal page
     reads through --jr-gold-hi. Decorative fills that want the literal brand
     teal ask for --accent-bright by name. */
  --jr-navy:var(--ink);
  --jr-ox:var(--emphasis);
  /* `--jr-display` is NOT "the headline face" — it is journal.css's general
     display family, used for stat numbers, nav-row labels, list items, badges
     and card titles alike. Pointing it at the serif turned the dashboard's
     digits, button labels and 17px list items into Newsreader, which reads as
     a font-loading accident rather than a hierarchy. It stays sans; the serif
     is attached to the individual title rules in journal.css instead. */
  --jr-display:var(--font-sans);
  --jr-text:var(--font-sans);
  /* --jr-w / --jr-pad are NOT remapped: journal.css ships 1240px and
     clamp(20px,4vw,48px), and pointing them at --shell (1200px) narrowed every
     page by 40px. Geometry stays where the legacy sheets put it. */
  --jr-ease:var(--ease);

  /* journal.css derives the shared widget tokens from --jr-*; keep them live.

     NOT --surface. `--jr-card:var(--surface)` two lines up plus
     `--surface:var(--jr-card)` here is a cycle, and a cycle makes both names
     guaranteed-invalid — `getPropertyValue('--surface')` returns the empty
     string on body and on every descendant, while still returning #FFFFFF /
     #172632 on <html>. Everything reading --surface below body silently failed:
     `background:var(--surface)` fell back to transparent, and every
     `color-mix(…, var(--surface))` was invalid at computed-value time, which
     for an SVG `fill` means the initial value — black. That is why the SEHS
     model figures had a solid black muscle fibre and unreadable labels, and why
     607 `--c0/--c1/--c2` declarations resolved to nothing.

     --surface already carries a literal at :root and in the dark block, so it
     inherits here correctly. The alias only needs to run one way. */
  --bg:var(--jr-paper); --surface2:var(--jr-paper2);
  --text:var(--jr-ink); --text2:var(--jr-ink2); --text3:var(--jr-ink3);
  --border:var(--jr-rule2); --border2:var(--jr-rule);
  /* --accent is re-stated as a primitive, not as var(--jr-gold-hi).
     journal.css declares `--accent:var(--jr-gold-hi)` on body.jr, and the
     `--jr-gold-hi:var(--accent)` line above would close a cycle with it —
     guaranteed-invalid, so the token reads as "" on body and the primary
     button loses its fill. Pointing at the primitive ends the loop: text teal
     is 5.3:1 on ivory and white-on-button is 5.9:1, where the old
     `--jr-gold-hi` → --accent-bright chain gave 2.9:1. */
  --accent:var(--brand-teal-ink);
  --font:var(--jr-text); --font-heading:var(--font-sans);
}

/* 4c — journal.css declares its own `body.jr.dark` palette with higher
   specificity than the `body.jr` block above, so it has to be answered at the
   same specificity or the landing keeps the old warm-black night edition. */
body.jr.dark{
  --jr-paper:var(--canvas);   --jr-paper2:var(--canvas-2);
  --jr-card:var(--surface);   --jr-ink:var(--ink);
  --jr-ink2:var(--ink-2);     --jr-ink3:var(--ink-3);
  --jr-rule:var(--line-2);    --jr-rule2:var(--line);
  --jr-gold:var(--accent);    --jr-gold-hi:var(--accent-bright);
  --jr-navy:var(--ink);       --jr-ox:var(--emphasis);
  --bg:var(--jr-paper); --surface2:var(--jr-paper2);
  --text:var(--jr-ink); --text2:var(--jr-ink2); --text3:var(--jr-ink3);
  --border:var(--jr-rule2); --border2:var(--jr-rule);
  /* dark keeps the bright teal: #4F9D91 is 5.3:1 on #121E28, so the same value
     works as text and as a fill. Only the light surface had to change. */
  --accent:var(--jr-gold-hi);
  /* no --surface here either — see the cycle note in 4b */
}

/* ═══ 5. Typographic base ═══════════════════════════════════════════════════ */
body{
  font-family:var(--font-sans);
  font-size:var(--t-body);
  line-height:var(--lh-body);
  letter-spacing:var(--tr-body);
  -webkit-font-smoothing:antialiased;
  -moz-osx-font-smoothing:grayscale;
  text-rendering:optimizeLegibility;
  font-variant-numeric:tabular-nums;
}

/* headline hierarchy — display serif at h1–h3, UI sans at h4 and below.
   The split is deliberate: a display face earns its keep at 26px and up, and
   stops earning it at 17px where a card title just needs to be legible.

   SIZE IS NOT SET HERE. The old sheets already own every heading size on every
   page (journal.css's .jr-shead h2, sections.css's h1, the per-page clamps),
   and re-ramping them to a single site scale shrank the whole site by ~40%.
   This layer re-skins — face, weight, tracking, colour — and leaves geometry
   alone. Same reason there is no line-height here. */
body.jr h1,body.jr h2,body.jr h3,
body.jr .jr-head h2,body.jr .jr-h1,
.jr-mast .jr-word,h1,h2,h3{
  font-family:var(--font-display);
  font-weight:var(--w-medium);
  letter-spacing:var(--tr-serif);
  text-wrap:balance;
}
body.jr h4,h4{
  font-family:var(--font-sans);
  font-weight:var(--w-semibold);
  letter-spacing:-.008em;
  text-wrap:balance;
}

/* the cover headline — face and tracking only; its clamp lives in journal.css */
body.jr .hero h1,
body.jr .ch-hero h1,
body.jr .ib-hero h1{
  letter-spacing:var(--tr-serif)!important;
}

/* the italic emphasis in a headline — one phrase per headline, in the accent */
body.jr h1 em,body.jr h2 em,body.jr .jr-h1 em,
body.jr .jr-head h2 em,.jr-cover h1 em{
  font-style:italic;
  font-weight:var(--w-regular);
  color:var(--accent);
  letter-spacing:-.01em;
}

/* paragraph measure — long-form pages were running to the full 1240px shell */
body.jr p,body.jr li{max-width:none}
.jr-colo p,.jr-body p,.prose p,article p{max-width:var(--measure)}

/* eyebrows / labels */
body.jr .jr-k,.jr-k{
  font-family:var(--font-sans);
  font-size:var(--t-label);
  font-weight:var(--w-bold);
  letter-spacing:var(--tr-label);
  text-transform:uppercase;
  color:var(--accent);
}

/* Chinese typography: no negative tracking, looser leading, taller labels */
body.lang-zh{
  --tr-display:0em; --tr-head:0em; --tr-body:0em; --tr-label:.06em;
  --tr-serif:0em;
  --lh-body:1.78; --lh-head:1.26; --lh-display:1.16; --lh-serif:1.24;

  /* The CJK webfaces are scoped to Chinese mode, not to :root, and that is a
     payload decision rather than a typographic one. They are 336–436 KB each,
     and an English page contains exactly one Chinese glyph — the 中 on the
     language toggle. Put "Noto Sans SC" in the global stack and that single
     character pulls 680 KB onto every English page. Scoped here, English
     visitors never touch the files and any stray Chinese falls back to
     PingFang, which is the same face they saw before. */
  --font-sans:"Nunito Sans","Noto Sans SC",-apple-system,BlinkMacSystemFont,
              "SF Pro Text","Segoe UI",Inter,"PingFang SC","Hiragino Sans GB",
              "Microsoft YaHei",sans-serif;
  --font-display:"Newsreader","Noto Serif SC",Georgia,"Times New Roman",
                 "Songti SC","STSong",serif;
}
body.lang-zh h1,body.lang-zh h2,body.lang-zh h3,
body.lang-zh .jr-head h2,body.lang-zh .jr-h1{letter-spacing:0}
body.lang-zh .jr-k{letter-spacing:.06em;font-size:.75rem}

/* links */
a{color:var(--accent);text-decoration-thickness:1px;text-underline-offset:.18em}
body.jr a{color:inherit}
body.jr a:not([class]):hover{color:var(--accent)}

/* selection + focus: the one place the bright teal is allowed on text */
::selection{background:var(--accent-bright);color:#04201C}
body.jr ::selection{background:var(--accent-bright);color:#04201C}
:focus-visible{outline:2px solid var(--focus);outline-offset:2px;border-radius:var(--r-xs)}
body.jr :focus-visible{outline:2px solid var(--focus);outline-offset:3px}

/* ═══ 6. Chrome: paper grain removed, scrollbars, rules ═════════════════════ */
/* the grain texture was tuned for warm stock; on cool ivory it reads as dirt */
body.jr{background-image:none}
html.jr-root{background:var(--canvas)}
body.jr{background:var(--canvas);color:var(--ink)}
body.jr.dark{background:var(--canvas);color:var(--ink)}

/* the double rule under the masthead is the brand's strongest editorial mark —
   keep the structure, thin it to match a sans-serif setting */
body.jr .jr-rule2{
  height:3px;
  border-top:1px solid var(--line-strong);
  border-bottom:1px solid var(--line-strong);
}
body.jr .jr-rule{border-top:1px solid var(--line)}

::-webkit-scrollbar{width:11px;height:11px}
::-webkit-scrollbar-track{background:transparent}
::-webkit-scrollbar-thumb{background:var(--line-2);border-radius:var(--r-pill);border:3px solid var(--canvas)}
::-webkit-scrollbar-thumb:hover{background:var(--ink-3)}

/* ═══ 7. Motion — one rhythm, and a real reduced-motion contract ════════════ */
:root{--motion-ok:1}
@media (prefers-reduced-motion:reduce){
  :root{--motion-ok:0}
  *,*::before,*::after{
    animation-duration:.01ms !important;
    animation-iteration-count:1 !important;
    transition-duration:.01ms !important;
    scroll-behavior:auto !important;
  }
}
