/*
  Kinlight design tokens.

  learning-site/'s OWN copy — a THIRD physical copy, alongside
  frontend/css/tokens.css and marketing/assets/tokens.css, kept for the exact
  same reason marketing/ has its own: learning-site/ is deployed as its own,
  separate Render Static Site (see docs/kinlight-learning-site.md) with its
  own document root and no build step to import a file living under
  frontend/ or marketing/. NOT covered by tests/test_color_contrast.py's
  tokens-sync check (that check is scoped to the frontend/marketing pair
  only) and NOT scanned by tests/test_no_hardcoded_colors.py (scoped to
  frontend/*.html + marketing/*.html, not learning-site/) — keep this file's
  values in sync with the other two BY HAND if a token value ever changes,
  since no automated check will catch a drift here.

  THIS IS A PHYSICAL COPY of frontend/css/tokens.css, not a shared reference —
  a deliberate, disclosed exception, not an oversight. marketing/ is deployed
  as its own, separate Render static site with its own document root (see
  CLAUDE.md's "marketing/ is intentionally NOT part of the app.py request-
  pipeline diagram" note) and has no build step to import a file living under
  frontend/. A path like /css/tokens.css would 404 here in production, since
  this site's root only ever contains marketing/'s own files.

  If you change a token value, update BOTH copies (this file and
  frontend/css/tokens.css) — see docs/design-system.md for the full rules
  this file encodes: one meaning per accent (gold=AI, sage=teacher's
  content/positive, ember=needs attention), contrast findings, and every
  specific remapping decision.

  tests/test_color_contrast.py's own tokens-sync check enforces this two-file
  requirement automatically: it compares this file and frontend/css/tokens.css
  with comments stripped, requiring every actual CSS rule (every :root/
  media-query/data-theme block and every declaration inside it) to be
  byte-for-byte identical — only the surrounding comment TEXT (like this one,
  naming which file is the "real" one vs. its copy) is allowed to differ.
  If you edit ONE file's actual rules without the other, that check fails
  the next time it runs, naming the exact mismatch.

  Dark theme: two mechanisms, both supported —
    1. Automatic, following the device/browser's own prefers-color-scheme.
    2. An explicit override via <html data-theme="dark"|"light">, checked
       BEFORE the media query, for a future in-app settings toggle (no
       toggle UI exists yet — this file just makes the CSS ready for one).
  --hearthwood and --oatlight are deliberately treated as a matched
  inverse pair in both themes: anywhere a rule does
  `background: var(--hearthwood); color: var(--oatlight);` (or the
  reverse), the pairing stays correctly high-contrast in both themes
  automatically, since the two tokens always invert together. This is why
  the universal `button { background: var(--hearthwood); color: white; }`
  pattern across every app file was changed to
  `color: var(--oatlight)` as part of this rollout — a literal "white"
  would have gone invisible against a dark-mode hearthwood button in that
  now-inverted state, and this is what your `color: var(--oatlight)`
  buttons rely on.

  REVISED, second dark-theme pass — gold/sage/ember now have REAL dark-theme
  variants (see the dark-theme block below), superseding this file's own
  original "these stay constant" decision. That first version caused a real
  bug: a tinted box (e.g. --ember-bg) stayed light while its own text
  (--ember-text, if left constant) either stayed dark (illegible on
  unrelated dark surfaces) or was patched to a fixed dark value that read as
  a light card floating on a dark page, not a real dark-theme surface. Now
  BOTH halves of each `-bg`/`-text` (and `-border`) pair flip together —
  dark, desaturated tinted backgrounds paired with light, higher-luminance
  text — the same "flip together" contract --hearthwood/--oatlight already
  had, extended to gold/sage/ember.

  This uncovered a SECOND, more widespread pre-existing bug while fixing the
  first: --ember-text/--sage-text are also used standalone, as plain error/
  success text sitting on the ORDINARY page/card background (e.g.
  #loginError, #billingError, #newProfileError — dozens of sites), never
  inside a tinted box at all. Under the old "stays constant" design, these
  rendered at only ~2.6–2.9:1 contrast against a dark-mode page (see
  docs/design-system.md's contrast findings) — failing AA, and nobody had
  caught it because dark theme had never been screenshotted for these
  specific elements before this pass. Making --ember-text/--sage-text
  theme-dependent fixes BOTH bugs from one change: a dark page's surfaces
  (both the ordinary page/card background AND the new dark tinted-box
  backgrounds) are all dark, so the same light --ember-text/--sage-text
  value reads correctly against either.

  ONE ROLE HAD TO STAY CONSTANT, and needed its own new token to do so:
  --ember-text/--sage-text are ALSO used as a SOLID FILL for a few small,
  saturated UI chips (.dangerBtn, a .pill badge, the mic "recording" pulse),
  always paired with white/--on-accent text. Flipping --ember-text/
  --sage-text for THIS role would break that pairing (a light fill can't
  carry white text). --ember-solid/--sage-solid are new, deliberately
  constant tokens carrying exactly the value --ember-text/--sage-text used
  to have everywhere (before they became theme-dependent) — used ONLY by
  those specific solid-fill-with-on-accent-text call sites, never by a
  tinted-box background or its own text. --gold-text has no such fill usage
  anywhere in the codebase (checked directly), so it needed no equivalent
  --gold-solid token — it flips cleanly on its own.
*/

:root {
  /* Neutrals */
  --hearthwood: #2E2A22;
  --oatlight: #F1EFE5;
  --fog: #D8D3C6;
  --muted: #6B6659;
  --card-bg: #FFFFFF;
  --chat-card-bg: #F9F7F2; /* index.html's own floating chat-card layer — deliberately distinct from --card-bg, never merged into it */

  /* Gold — AI-generated content only. Never a non-AI UI element.
     --gold-bg/--gold-text are the tinted-box pair (see the dark-theme
     block below for their dark-mode values); bare --gold is the constant
     icon/border/link accent, unaffected by this pass. */
  --gold: #BD8A3D;
  --gold-text: #8A6224;
  --gold-bg: #FBF1D9;

  /* Sage — teacher's own published content, and positive/confirmed status.
     --sage-bg/--sage-text are the tinted-box pair (dark-mode values below);
     bare --sage is the constant icon/fill/border accent (fails AA as body
     text, never use it for text); --sage-solid is the constant SOLID-FILL
     value (see the file header comment) for a chip/button paired with
     --on-accent white text — never used for a tinted box or its own text. */
  --sage: #6B8564;
  --sage-solid: #4F6B4A;
  --sage-text: #4F6B4A;
  --sage-bg: #E4EBE0;
  --sage-lesson-bg: #EDF2EA;   /* new, distinct pairing: "this content is drawn from your teacher's published lesson" — tracks --sage-bg/--sage-text's own dark-mode values, see below */
  --sage-lesson-text: #4F6B4A;

  /* Ember — needs attention / destructive / error. Same three-role split as
     sage above: --ember-bg/--ember-text tinted-box pair (dark-mode values
     below), bare --ember reserved for future icon/border use (currently
     unused directly, kept for symmetry), --ember-solid the constant
     solid-fill value for a chip/button paired with --on-accent. */
  --ember: #9C4A3C;
  --ember-solid: #9C4A3C;
  --ember-text: #9C4A3C;
  --ember-bg: #F6E9DD;
  --ember-border: #E7C4B8;

  /* Text color for a saturated, CONSTANT solid-fill accent (--ember-solid/
     --sage-solid, or bare --gold's own border-only uses) — a plain white
     that never needs to flip, since the fills it sits on don't either. */
  --on-accent: #FFFFFF;

  /* Sign in with Apple's own official black-button style (see CLAUDE.md's
     design report) — a genuinely NEW category, not --hearthwood: Apple's
     own Human Interface Guidelines require this button stay black (or
     white/white-outline) regardless of the host app's own theming, since
     re-theming it would undermine the brand recognition the guidelines
     exist to protect. --hearthwood is the wrong token here specifically
     BECAUSE it correctly flips to a light value in dark theme (see this
     file's own header comment) — this token deliberately does NOT flip,
     same "constant, theme-invariant" contract as --on-accent right above
     it, for the same underlying reason (a fixed brand requirement, not a
     themeable UI color). */
  --apple-signin-bg: #000000;

  /* index.html's own ".headerPillLink" text color — kept as its own token
     rather than merged into --muted, since its exact value was independently
     contrast-checked and documented (~6.10:1 against its own pill fill,
     ~6.81:1 against the plain card background) and merging it into --muted
     (a very close but not identical value) would make that specific,
     already-verified math stale without re-checking it. */
  --header-pill-text: #5c5648;

  /* Translucent overlay tints — hover states / shadows derived from --gold /
     --hearthwood at a few specific opacities, used repeatedly across the app.
     CSS custom properties can't be interpolated into rgba()'s alpha channel
     directly (short of `rgb(from var(...) ...)`, patchy support), so these
     are their own literal tokens rather than computed from --gold/--hearthwood
     at each call site. */
  --shadow-soft: rgba(46, 42, 34, 0.08);
  --gold-tint-08: rgba(189, 138, 61, 0.08);
  --gold-tint-10: rgba(189, 138, 61, 0.1);
  --gold-tint-12: rgba(189, 138, 61, 0.12);
  --gold-tint-22: rgba(189, 138, 61, 0.22);

  /* Hearthwood-based hover/interaction tints — REPLACE the equivalent
     --gold-tint-* values at every hover/focus/nav-link site this rollout's
     third pass moved off gold (see docs/design-system.md): gold is reserved
     for AI content, and a generic hover highlight isn't that. Unlike the
     gold tints, these MUST be theme-aware (overridden in the dark-theme
     blocks below) — they're derived from --hearthwood's own RGB, which
     itself flips between themes, so a tint of it has to flip too (a
     "dark tint" of a color that's gone light would be backwards). */
  --hearthwood-tint-08: rgba(46, 42, 34, 0.08);
  --hearthwood-tint-10: rgba(46, 42, 34, 0.1);
  --hearthwood-tint-12: rgba(46, 42, 34, 0.12);
  --hearthwood-tint-22: rgba(46, 42, 34, 0.22);

  /* Neutral black-based scrims (modal backdrops, subtle hover states, the
     mobile drawer's own shadow) — not brand-hued, so not derived from any
     other token above, but still real color literals needing a name for
     the color-lint script to accept. */
  --scrim-backdrop: rgba(0, 0, 0, 0.4);
  --scrim-hover: rgba(0, 0, 0, 0.06);
  --scrim-drawer-shadow: rgba(0, 0, 0, 0.15);

  /* dashboard.html's own hearthwood-based scrims/shadows (dismissable modal
     backdrop, non-dismissable wizard/consent-overlay backdrop, elevated
     panel shadow, hovered stat-tile shadow) — same reasoning as the
     scrim-*/gold-tint-* tokens above. */
  --overlay-backdrop-modal: rgba(46, 42, 34, 0.45);
  --overlay-backdrop-strong: rgba(46, 42, 34, 0.6);
  --shadow-elevated: rgba(46, 42, 34, 0.25);
  --shadow-hover: rgba(46, 42, 34, 0.12);

  /* Muted, desaturated class-color palette — for distinguishing CLASSES
     (a school's Period 3 vs. Period 4, a family's multiple kids' subjects,
     etc.) only. Never use one of these for a status/severity signal —
     that's what gold/sage/ember are for. */
  --class-color-1: #8695A6;
  --class-color-2: #A68C6D;
  --class-color-3: #7C9885;
  --class-color-4: #A67C96;
  --class-color-5: #8C8367;
  --class-color-6: #6D8AA6;
  --class-color-7: #A6836D;
  --class-color-8: #7C7C99;

  /* TUT-5/B1 (see CLAUDE.md's design report) — a separate, deliberately
     distinct "playful" palette for the younger age band's big tap-option
     buttons (hint chips, quick-check-your-understanding choices). Same
     carve-out as --class-color-* above: purely decorative rotation, NEVER
     a status/severity signal — the right/wrong outcome of a tap is shown
     by sage/ember, never by which of these four a given button happened
     to be. Chosen to sit clearly apart from gold/sage/ember's own hues (no
     amber-brown, no olive-green, no red-brown) so a playful button can
     never read as "this is AI content" / "this is correct" / "this needs
     attention" by accident. Each -bg/-text pair below is contrast-checked
     by tests/test_color_contrast.py in both themes, same as every other
     tinted-box pair in this file. */
  --playful-1-bg: #DCEBF7; /* sky blue */
  --playful-1-text: #2C5F82;
  --playful-2-bg: #EADCF2; /* lavender */
  --playful-2-text: #6B3F82;
  --playful-3-bg: #F7DCE3; /* coral pink */
  --playful-3-text: #9C3F5C;
  --playful-4-bg: #DCF2F0; /* turquoise */
  --playful-4-text: #166359;

  /* Factor A / Factor B — two-factor color-coding for a binomial/trinomial
     factoring diagram (first introduced for the Animated Explanations
     prototype, frontend/js/animated-explanation.js: tracking which term in
     an equation/box-diagram/expansion came from which of the two factors
     being multiplied, e.g. the "3" vs. the "4" in (x+3)(x+4)). Factor A is
     whichever factor is introduced/discussed first in a given worked
     example; Factor B the second — NOT a status/severity signal (same
     spirit as the class-color-* palette above), purely a way to visually
     track one term's origin as a diagram builds up. Deliberately NOT drawn
     from the --playful-* palette (reserved for the younger age band's
     tap-option buttons — this needs to read as grown-up/calm, not playful/
     game-like) and chosen with real hue separation from every other token
     here (gold/sage/ember/class-color-6/playful-*) so neither factor color
     is mistaken for an existing meaning or for the other factor. Each
     -bg/-text pair is contrast-checked by tests/test_color_contrast.py in
     both themes — both against each other AND against the plain --card-bg/
     --oatlight page surfaces, since a factor color is also used as a bare
     text color directly on those (a box diagram's own side labels), not
     only inside its own tinted-box fill. */
  --factor-a-bg: #E6E5F6; /* muted indigo */
  --factor-a-text: #4A4A9C;
  --factor-b-bg: #F2E3EF; /* muted plum */
  --factor-b-text: #7A3570;

  /* Typography */
  --font-serif: "Fraunces", serif;
  --font-sans: "Work Sans", -apple-system, sans-serif;
  --font-mono: "IBM Plex Mono", monospace;

  /* UX redesign round 1 (W3-01) -- values only, not yet consumed by any
     marketing page. Kept here solely so this file's own rules stay in
     sync with frontend/css/tokens.css (see that file's own, much longer
     comment for the full reasoning behind each value -- contrast math,
     why --border-input doesn't need a dark-theme override, and the
     §3.1 type-scale table this mirrors). */
  --border-input: #897F71;

  --text-display: 28px;
  --line-display: 1.2;
  --text-h1: 24px;
  --line-h1: 1.25;
  --text-h2: 19px;
  --line-h2: 1.3;
  --text-body: 16px;
  --line-body: 1.5;
  --text-secondary: 15px;
  --line-secondary: 1.45;
  --text-helper: 14px;
  --line-helper: 1.4;
  --text-caption: 13px;
  --line-caption: 1.35;
  --text-button: 16px;
  --text-overline: 12px;

  --text-kid-younger-display: 34px;
  --line-kid-younger-display: 1.15;
  --text-kid-younger-h1: 28px;
  --line-kid-younger-h1: 1.2;
  --text-kid-younger-h2: 24px;
  --line-kid-younger-h2: 1.25;
  --text-kid-younger-body: 20px;
  --line-kid-younger-body: 1.45;
  --text-kid-younger-secondary: 18px;
  --line-kid-younger-secondary: 1.4;
  --text-kid-younger-button: 22px;

  --text-kid-mid-display: 30px;
  --line-kid-mid-display: 1.2;
  --text-kid-mid-h1: 26px;
  --line-kid-mid-h1: 1.2;
  --text-kid-mid-h2: 22px;
  --line-kid-mid-h2: 1.25;
  --text-kid-mid-body: 18px;
  --line-kid-mid-body: 1.5;
  --text-kid-mid-secondary: 16px;
  --line-kid-mid-secondary: 1.45;
  --text-kid-mid-helper: 15px;
  --text-kid-mid-caption: 14px;
  --text-kid-mid-button: 20px;

  --text-kid-teen-display: 28px;
  --line-kid-teen-display: 1.2;
  --text-kid-teen-h1: 24px;
  --line-kid-teen-h1: 1.25;
  --text-kid-teen-h2: 19px;
  --line-kid-teen-h2: 1.3;
  --text-kid-teen-body: 16px;
  --line-kid-teen-body: 1.5;
  --text-kid-teen-secondary: 15px;
  --line-kid-teen-secondary: 1.45;
  --text-kid-teen-helper: 14px;
  --text-kid-teen-caption: 13px;
  --text-kid-teen-button: 16px;
  --text-kid-teen-overline: 12px;
}

/*
  Dark-theme overrides.

  Neutrals (hearthwood/oatlight/fog/muted/card-bg/chat-card-bg) invert, as
  before. gold-bg/gold-text, sage-bg/sage-text (+ sage-lesson-bg/-text),
  and ember-bg/ember-text/ember-border ALSO now have real dark-mode values —
  see the file header comment for why this superseded the original "stays
  constant" design, and for why --ember-solid/--sage-solid/bare --gold/
  --sage/--ember/--on-accent/the class-color palette are deliberately left
  OUT of this block and so stay byte-for-byte the same in both themes: they
  back small, saturated solid-fill chips (paired with --on-accent) or plain
  icon/border accents, never a tinted box, so flipping them would break
  those existing pairings for no benefit.

  Every value below is verified against tests/test_color_contrast.py's own
  automated pair-contrast check (see that file, and docs/design-system.md's
  "Dark theme" section for the exact ratios) — not eyeballed.
*/
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --hearthwood: #F1EFE5;
    --oatlight: #1C1A15;
    --fog: #3A362C;
    --muted: #B0A99C;
    --card-bg: #24221C;
    --chat-card-bg: #211F1A;

    --gold-bg: #3A2E1A;
    --gold-text: #EAD39D;

    --sage-bg: #243024;
    --sage-text: #9CC291;
    --sage-lesson-bg: #243024;
    --sage-lesson-text: #9CC291;

    --ember-bg: #3A211D;
    --ember-text: #E8A99A;
    --ember-border: #B07A6C;

    --playful-1-bg: #1E2F3A;
    --playful-1-text: #9CC8E8;
    --playful-2-bg: #2E1F3A;
    --playful-2-text: #D4A8E8;
    --playful-3-bg: #3A1F28;
    --playful-3-text: #E8A8BC;
    --playful-4-bg: #1A3230;
    --playful-4-text: #8DDBD2;

    --factor-a-bg: #26264A;
    --factor-a-text: #B3B3EC;
    --factor-b-bg: #34182F;
    --factor-b-text: #E3A8DB;

    --hearthwood-tint-08: rgba(241, 239, 229, 0.08);
    --hearthwood-tint-10: rgba(241, 239, 229, 0.1);
    --hearthwood-tint-12: rgba(241, 239, 229, 0.12);
    --hearthwood-tint-22: rgba(241, 239, 229, 0.22);
  }
}

:root[data-theme="dark"] {
  --hearthwood: #F1EFE5;
  --oatlight: #1C1A15;
  --fog: #3A362C;
  --muted: #B0A99C;
  --card-bg: #24221C;
  --chat-card-bg: #211F1A;

  --gold-bg: #3A2E1A;
  --gold-text: #EAD39D;

  --sage-bg: #243024;
  --sage-text: #9CC291;
  --sage-lesson-bg: #243024;
  --sage-lesson-text: #9CC291;

  --ember-bg: #3A211D;
  --ember-text: #E8A99A;
  --ember-border: #B07A6C;

  --playful-1-bg: #1E2F3A;
  --playful-1-text: #9CC8E8;
  --playful-2-bg: #2E1F3A;
  --playful-2-text: #D4A8E8;
  --playful-3-bg: #3A1F28;
  --playful-3-text: #E8A8BC;
  --playful-4-bg: #1A3230;
  --playful-4-text: #8DDBD2;

  --factor-a-bg: #26264A;
  --factor-a-text: #B3B3EC;
  --factor-b-bg: #34182F;
  --factor-b-text: #E3A8DB;

  --hearthwood-tint-08: rgba(241, 239, 229, 0.08);
  --hearthwood-tint-10: rgba(241, 239, 229, 0.1);
  --hearthwood-tint-12: rgba(241, 239, 229, 0.12);
  --hearthwood-tint-22: rgba(241, 239, 229, 0.22);
}
