/* Design tokens — single source of truth for colour, type, spacing, radius. */

:root {
  /* Room kept above a portrait phone's foot bar for the exercise-name pill
     that opens above its circles (#252, R5). Measured: the open pill spans
     61px above the bar's top edge (it is staggered above the subject
     circle's), so 64 clears it with a few px to spare. */
  --foot-reserve: 64px;
  /* ── Safe-area insets (protected UI zones, CLAUDE.md §6) ──────────────
     The Android WebView shell draws the system status overlay (clock, network,
     battery) over the top of the page; a browser and an installed PWA do not.
     `viewport-fit=cover` in index.html makes these env() values real on the
     shell and 0px everywhere else, so one set of rules serves both.

     --vh is the USABLE viewport height. Every height calculation must use it
     rather than raw var(--vh): the shell is padded by the insets below, so var(--vh)
     would overshoot by exactly that amount and push content off-screen. */
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-left: env(safe-area-inset-left, 0px);
  --safe-right: env(safe-area-inset-right, 0px);
  /* Usable height. The top inset is NOT subtracted since v265 — the page no
     longer pads for it, so subtracting it here would leave the app short by
     exactly that much and open a gap above the gesture bar. */
  --vh: calc(100vh - var(--safe-bottom));

  /* Top offset for CONTENT that must clear the camera (v265). The camera sits
     mid-top on some phones and top-right on others, so no fixed "safe corner"
     exists — env() is the only thing that knows, per device. But it should push
     CONTENT down, not the whole page: the background draws full-bleed behind
     the camera (nothing lives there to hide), which is what stops the band
     reading as wasted space. One token so this stays a global rule rather than
     per-control patches. */
  --content-top: calc(var(--space-md) + var(--safe-top));

  /* Outer shell rounding. A phone screen rounds at roughly 40px; a 12px card
     radius inside a uniform margin leaves a visibly wider gap at the corners
     than along the edges — the "not parallel" margin (owner 2026-08-01). A
     larger radius on the outermost surface reads concentric with the screen. */
  --radius-shell: 28px;

  /* Left rail (decision #98). 56px is deliberately NARROWER than the left
     reserve the layout already keeps for the HUD (190px full / 76px lite, #87),
     so the rail drops into space that is already spoken for and no content has
     to re-flow. The ★ handle is floored at 44px — it is the app's only route to
     the menu, and #89 caught it at 39px once already. */
  /* TWO TOKENS, because they answer two questions (#164 step 2). The BAR is
     the spine's own column — the trail circle, the ✕ and the ★ are placed
     inside it and it never changes width. The RESERVE is how much of the page
     content has to give up for it, and during an activity that is NOTHING: the
     spine stops painting and the three controls float over the content, which
     already keeps a 56px slot for the ✕ in its header. Splitting them is what
     #164 measured as the trap — three rail-internal rules read this token, and
     `.wu-rail-trail-slot { left: calc((var(--rail-w) - 44px) / 2) }` resolves
     to -22px the moment the reserve goes to zero. */
  --rail-bar-w: 56px;
  --rail-w: var(--rail-bar-w);
  --rail-star: 44px;

  /* Palette — surfaces & text (light theme — kid-friendly warm paper) */
  --colour-bg: #F6F4EF;
  --colour-surface: #FFFFFF;
  --colour-border: #E4E0D8;
  --colour-text-primary: #2B2926;
  /* Darkened #8B867E → #726D65 (v360, contrast audit). The original measured
     3.29:1 on the warm paper and 3.62:1 on white cards — BELOW the 4.5:1 AA
     floor for body text, everywhere it was used: every label, every <small>
     hint, every game tile's name. One token, so one change fixes all of them,
     and #726D65 is the smallest darkening that clears AA on BOTH surfaces
     (4.67 / 5.13) while keeping the warm-grey hue the palette is built on. */
  --colour-text-secondary: #726D65;

  /* Palette — semantic (darkened for contrast on light surfaces) */
  --colour-accent: #2196F3;
  --colour-success: #43A047;
  /* Success as TEXT (v471). #43A047 is a FILL colour: as the glyph on its own
     22% tint it measured 2.41:1 (#121), under even the 3:1 large-text floor,
     on the key that commits every maths answer. #2E7D32 is the green #123(e)
     already measured for the Study Timer's Start (5.13:1 white on it); as ink
     on that tint it reads 3.74:1, and 4.27:1 on the quieter ▸ tint. */
  --colour-success-ink: #2E7D32;
  --colour-warning: #F59E0B;
  --colour-danger: #E53935;

  /* WarmUp brand amber — matches the app icon (amber tile, white star).
     Used for the flower's centre brand tile and the HUD ★ pill. */
  --colour-brand: #FFB74D;
  --colour-brand-deep: #FB8C00;
  /* Gold — the avatar kit's legendary tier and a checkers king's raised star. */
  --colour-gold: #FFC107;
  /* Notes — the music game's eight lanes, C up to the next C, in the colours of
     the child's colour-coded practice-book keyboard, so a note is the same
     colour in the book and on the screen. */
  --colour-note-1: #E53935;
  --colour-note-2: #7E3FA6;
  --colour-note-3: #FDD835;
  --colour-note-4: #F48FB1;
  --colour-note-5: #90CAF9;
  --colour-note-6: #F07F2E;
  --colour-note-7: #2E8B57;
  --colour-note-8: #1F3F8F;
  /* 🎒 Weekday colours for homework backpacks (#195): Mon red, Thu blue
     (owner), the rest chosen to be told apart at 22px. JS getDay() order. */
  --colour-day-0: #8E24AA; /* Sun purple */
  --colour-day-1: #E53935; /* Mon red */
  --colour-day-2: #FB8C00; /* Tue orange */
  --colour-day-3: #43A047; /* Wed green */
  --colour-day-4: #1E88E5; /* Thu blue */
  --colour-day-5: #D81B60; /* Fri pink */
  --colour-day-6: #00897B; /* Sat teal */

  /* Lattice — thin ring on each ghost cell is the line; the gap between
     cells is a quiet padding zone, not part of the line weight */
  --colour-grid-line: color-mix(in srgb, var(--colour-border) 85%, var(--colour-text-secondary));
  --colour-grid-bg: color-mix(in srgb, var(--colour-border) 35%, var(--colour-bg));

  /* Default activity colours */
  --activity-reading: #4FC3F7;
  --activity-maths: #69D98C;
  --activity-music: #CE93D8;
  --activity-sport: #FFB74D;
  --activity-other: #90A4AE;

  /* Typography */
  --font-display: "Nunito", system-ui, -apple-system, "Segoe UI", sans-serif;
  --font-body: "Inter", system-ui, -apple-system, "Segoe UI", sans-serif;
  --font-mono: "JetBrains Mono", ui-monospace, "SFMono-Regular", Menlo, monospace;

  --font-size-xs: 0.75rem;
  --font-size-sm: 0.875rem;
  --font-size-md: 1rem;
  --font-size-lg: 1.25rem;
  --font-size-xl: 1.5rem;
  --font-size-2xl: 2rem;
  --font-size-3xl: 2.5rem;

  --font-weight-regular: 400;
  --font-weight-medium: 500;
  --font-weight-semibold: 600;
  --font-weight-bold: 700;

  --line-height-tight: 1.15;
  --line-height-normal: 1.4;
  --line-height-loose: 1.6;

  /* Spacing scale — 4px base */
  --space-xs: 4px;
  --space-sm: 8px;
  --space-md: 16px;
  --space-lg: 24px;
  --space-xl: 40px;
  --space-2xl: 64px;

  /* Border radius */
  --radius-cell: 6px;
  --radius-button: 8px;
  --radius-card: 12px;
  --radius-pill: 999px;

  /* Hex tile sizing — viewport-adaptive: the 5-row flower plus one full
     ghost ring must fit the pane height (flower ≈ 6.35 hex-widths tall
     incl. ring). Tiles stay at 132px max, shrinking only when needed. */
  --hex-w: clamp(80px, calc((var(--vh) - 56px) / 6.4), 132px);
  --hex-h: calc(var(--hex-w) * 1.1547);
  --hex-gap: 5px;
  --hex-outline: 2px;

  /* Misc */
  --tap-target-min: 44px;
  --transition-fast: 120ms ease-out;
  --transition-base: 200ms ease-out;
}

@media (max-width: 1024px) {
  :root {
    --hex-w: clamp(72px, calc((var(--vh) - 56px) / 6.4), 116px);
    --hex-gap: 4px;
  }
}

@media (max-width: 720px) {
  :root {
    /* Compact flower on phones — portrait has height to spare but the flower
       reads better small; cap 96 → 66 → 54 (decision #56, tuned 2026-06-15).
       Tighter height divisor (10.5) so shorter viewports shrink it more too. */
    --hex-w: clamp(42px, calc((var(--vh) - 56px) / 10.5), 54px);
    --hex-gap: 3px;
  }
}

html,
body {
  background: var(--colour-bg);
  color: var(--colour-text-primary);
  font-family: var(--font-body);
  font-size: var(--font-size-md);
  line-height: var(--line-height-normal);
  margin: 0;
  padding: 0;
  -webkit-font-smoothing: antialiased;
  /* No double-tap zoom anywhere (it broke game taps); scroll/pan still work.
     The viewport meta blocks pinch too — this covers browsers that override
     it (e.g. Chrome's "force enable zoom" accessibility setting). */
  touch-action: manipulation;
}

/* Global safe-area padding (CLAUDE.md §6 "Protected UI zones"). Keeps ALL
   content — including absolutely-positioned view chrome — clear of the Android
   status overlay and gesture bar in ONE place, so individual views never need
   their own inset handling. Zero on web/PWA.

   On <body> ONLY, never also on <html>: the two nest, so declaring it on both
   would apply the inset twice.

   MUST stay BELOW the `html, body` reset above (fixed 2026-08-01). Both rules
   match <body> at the same specificity, so the later one wins — and the reset's
   `padding: 0` SHORTHAND clobbers all four longhands. Sat above it since v236,
   which silently disabled the whole global inset: verified by forcing
   --safe-top:37px and reading back a computed padding-top of 0px. */
body {
  /* NO top inset (v265, owner: "camera safe area to be ignored"). Padding the
     whole page by --safe-top left a dead band above the app on any phone with
     a camera cutout. The surface now runs edge to edge behind it and the top
     inset moves onto CONTENT via --content-top, so nothing tappable can hide
     under the camera wherever that phone puts it.
     Bottom/left/right insets stay: those are the gesture bar and curved edges,
     where the intrusion is physical rather than an overlay drawn on top. */
  padding-top: 0;
  padding-bottom: var(--safe-bottom);
  /* The left rail (#98) is position:fixed, so it does not push content itself —
     the shell reserves its width HERE, once, and every view clears it. Doing it
     per-view is how this project ended up with reserves that broke whenever a
     control's size changed (#89/#90); one shell-level reserve cannot drift.
     Measured need: at 375×812 the flower sat at x=45 under a 56px spine. */
  padding-left: calc(var(--safe-left) + var(--rail-w));
  padding-right: var(--safe-right);
  box-sizing: border-box;
}

h1, h2, h3, h4 {
  font-family: var(--font-display);
  font-weight: var(--font-weight-bold);
  line-height: var(--line-height-tight);
}
