/* ============================================================
   Design tokens v3 - Badminton Sports Day 2026 (scoreboard + umpire).
   ONE source of colour, type, space, shape and motion. Linked FIRST in both
   index.html and umpire.html; css/base.css no longer declares any of these.
   Contract and usage rules: docs/ux/07-design-system-v3.md (docs branch).
   Every contrast ratio quoted below was computed (WCAG 2.x), not guessed.
   ============================================================ */
/* The hand-lettered Riso numerals (scripts/riso/build-digits-font.py): digits and - : / + # only. It is self-hosted and precached
   because a score must never wait for a font CDN; everything else in the stack falls through to Anton. */
@font-face {
  font-family: 'Riso Num'; src: url(../media/fonts/riso-num.woff2) format('woff2'); font-weight: 400; font-style: normal; font-display: swap;
  unicode-range: U+0030-0039, U+002D, U+003A, U+002F, U+002B, U+0023, U+2013, U+2212;
}
:root {
  color-scheme: dark;

  /* ── surfaces: 0 = page, 1 = card, 2 = raised / sheet, 3 = control, 4 = hover / pressed ── */
  --bg: #07070d;
  --s1: #0f0f1a;
  --s2: #161625;
  --s3: #1e1e30;
  --s4: #28283d;
  --line: rgba(255, 255, 255, .08);          /* hairline between things */
  --line-strong: rgba(255, 255, 255, .16);   /* border of a control / a card that must read as a shape */

  /* ── text on any surface above (all >= 5.2:1 even on --s4) ── */
  --t-hi: #f0f0f5;    /* 17.7 on --bg  */
  --t-mid: #c8c8dc;   /* 12.2          */
  --t-low: #9a9ab8;   /*  7.4 on --bg, 6.0 on --s3: quiet but still AA. Nothing dimmer may carry meaning. */

  /* ── brand: gold is the ONLY accent (primary action, selected, winner, key number) ── */
  --gold: #f0c040;        /* 11.8 on --bg */
  --gold-hi: #ffd766;     /* hover / pressed-in-light */
  --gold-ink: #14120a;    /* text on a gold fill: 11.0 */
  --gold-dim: rgba(240, 192, 64, .14);
  --gold-line: rgba(240, 192, 64, .42);
  --gold-text: var(--gold);   /* gold used as TEXT or an icon colour (a fill stays --gold); the paper theme darkens it */

  /* ── teams. Edge = the colour of a band / dot / outline. Text = the same hue lightened for words.
        Fill = a deep panel of the hue (white digits on it: 16.5 red, 14.4 blue). Never use colour alone:
        pair it with the team word or the shape (.ds-team: circle = red, diamond = blue). ── */
  --red: #ff4d4d;         /* edge 6.1 on --bg */
  --red-text: #ff7a7a;    /* 5.7 even on --s4 */
  --red-ink: #ffb3ac;     /* text on --red-fill 9.7 */
  --red-fill: #3a1119;
  --red-fill-hi: #5c1a27; /* just scored / pressed */
  --red-lost: #d06060;    /* the losing side's big numeral, 4.3 on --s3 (large text needs 3) */
  --red-dim: rgba(255, 77, 77, .14);
  --blue: #4d9fff;        /* edge 7.4 */
  --blue-text: #7ab8ff;   /* 6.9 on --s4 */
  --blue-ink: #a8d1ff;    /* text on --blue-fill 9.1 */
  --blue-fill: #0f2a4e;
  --blue-fill-hi: #17407a;
  --blue-lost: #5a8fd8;   /* 4.9 on --s3 */
  --blue-dim: rgba(77, 159, 255, .14);

  /* ── status. Always icon + word; the hue helps but never carries the meaning alone. ──
        LIVE / connected is green because red already means "team red". */
  --live: #34e39a;        /* 12.0 on --bg */
  --live-fill: rgba(52, 227, 154, .12);
  --live-line: rgba(52, 227, 154, .4);
  --ok: #7fe3a6;
  --warn: #ffb454;
  --warn-fill: rgba(255, 180, 84, .12);
  --warn-line: rgba(255, 180, 84, .42);
  --err: #ff7a9c;         /* rose, not team red; 7.2 on --s2 */
  --err-fill: rgba(255, 122, 156, .12);
  --err-line: rgba(255, 122, 156, .45);
  --info: #7ab8ff;

  --focus: #ffffff;       /* focus ring: 3 px white, 2 px gap - visible on gold, red, blue and dark alike */
  --on-field: var(--t-hi); /* text and digits drawn ON a solid team field (white here, cream on paper) */
  --scrim: rgba(3, 3, 8, .86);   /* the veil behind a dialog */

  /* ── type ── */
  --font-ui: 'Space Grotesk', 'Noto Sans Thai', system-ui, -apple-system, 'Segoe UI', sans-serif;
  --font-th: 'Noto Sans Thai', 'Space Grotesk', system-ui, sans-serif;
  /* digits and short English captions only (Anton has no Thai; the digits come from Riso Num); the fallbacks keep a cold offline start narrow.
     Anton is a single weight: any rule that uses this stack must say font-weight: 400 or the browser fakes a bold. */
  --font-num: 'Riso Num', 'Anton', 'Bebas Neue', 'Oswald', 'Arial Narrow', Impact, 'Noto Sans Thai', sans-serif;
  /* Thai headings and tab labels (paper.css); body and controls stay on --font-th */
  --font-th-head: 'Kanit', 'Noto Sans Thai', system-ui, sans-serif;

  --fs-12: .75rem;  --fs-13: .8125rem; --fs-14: .875rem; --fs-16: 1rem;    --fs-18: 1.125rem;
  --fs-20: 1.25rem; --fs-24: 1.5rem;   --fs-32: 2rem;    --fs-40: 2.5rem;  --fs-56: 3.5rem;
  --lh-num: .85;      /* digits */
  --lh-tight: 1.2;    /* headings, one-line labels in Latin */
  --lh-th: 1.45;      /* Thai: below 1.4 the tone marks clip */
  --lh-body: 1.5;

  /* ── space (4 pt grid), shape, elevation ── */
  --sp-1: 4px; --sp-2: 8px; --sp-3: 12px; --sp-4: 16px; --sp-5: 24px; --sp-6: 32px; --sp-7: 48px; --sp-8: 64px;
  --r-xs: 6px; --r-sm: 10px; --r-md: 16px; --r-lg: 22px; --r-pill: 999px;
  --shadow-pop: 0 12px 32px rgba(0, 0, 0, .55);
  --shadow-sheet: 0 -10px 40px rgba(0, 0, 0, .6);

  /* ── touch targets (WCAG 2.2 asks 24; this app holds 44 on a viewer phone and 48+ on the umpire) ── */
  --tap: 44px; --tap-md: 48px; --tap-lg: 56px; --tap-xl: 64px;

  /* ── motion: short, purposeful, never looping except the LIVE dot ── */
  --dur-press: 90ms; --dur-state: 160ms; --dur-out: 140ms; --dur-in: 220ms; --dur-pop: 140ms;
  --ease-out: cubic-bezier(.2, .8, .2, 1);
  --ease-pop: cubic-bezier(.34, 1.56, .64, 1);

  /* ── stacking: use these, do not invent a new 9999 ── */
  --z-sticky: 100; --z-nav: 200; --z-overlay: 1000; --z-modal: 2000; --z-toast: 3000; --z-blocker: 4000;

  /* ── safe areas (notch, home indicator) ── */
  --sat: env(safe-area-inset-top, 0px);
  --sar: env(safe-area-inset-right, 0px);
  --sab: env(safe-area-inset-bottom, 0px);
  --sal: env(safe-area-inset-left, 0px);

  /* ============================================================
     LEGACY NAMES - the old stylesheets still read these. They point at the tokens above so the whole app
     moves together; delete one only when `grep -r "var(--name)" css js *.html` finds nothing.
     ============================================================ */
  --surface: var(--s1);
  --surface2: var(--s2);
  --surface3: var(--s3);
  --border: var(--line);
  --border2: var(--line-strong);
  --text: var(--t-hi);
  --text2: var(--t-mid);
  --muted: var(--t-low);
  --muted2: var(--t-low);
  --red-glow: rgba(255, 77, 77, .4);
  --blue-glow: rgba(77, 159, 255, .4);
  --gold2: var(--gold-hi);
  --accent: var(--gold);
  --accent-dim: var(--gold-dim);
  --accent-glow: rgba(240, 192, 64, .3);
  --accent-grad: linear-gradient(0deg, var(--gold), var(--gold));   /* flat on purpose: a gradient var that still works as a background */
  --green: var(--live);
  --green-dim: var(--live-fill);
  --purple: #a855f7;
  --danger: var(--err);
  --radius: var(--r-md);
  --radius-sm: var(--r-sm);
}

/* ============================================================
   PAPER THEME - the Color War poster as a UI: warm cream paper, navy ink, solid red / cobalt inks, a yellow marker.
   On paper the "just scored / pressed" fill goes DEEPER (a richer ink), not lighter: the lighter step failed 4.5:1 for the
   cream text on it.
   Switch: <html data-theme="paper"> - the ONLY theme since release 2026.10.30.5 (set before first paint by the head script of
   both pages; ?theme= is ignored). The dark tokens above are the base these paper values override: dormant, no screen asks for them. Only tokens change here; css/paper.css adds the grain,
   ink-coloured court lines and the "ink on a solid field" remap. Colours sampled from the poster
   (paper #f7f2eb / #f8ebd8, navy #092c55, red #ed2f2e, cobalt #0555b3); every text pair below is >= 4.5:1
   on all five surfaces except warn (4.3, used with an icon and a word).
   ============================================================ */
:root[data-theme="paper"] {
  color-scheme: light;
  --bg: #f6f0e4; --s1: #fbf8f1; --s2: #f1e8d6; --s3: #e8dcc3; --s4: #dccfb1;
  --line: rgba(11, 42, 82, .14); --line-strong: rgba(11, 42, 82, .30);
  --t-hi: #0b2a52; --t-mid: #2c4a76; --t-low: #3e5780;
  --gold: #f4c430; --gold-hi: #f8d45e; --gold-ink: #0b2a52; --gold-dim: rgba(244, 196, 48, .30); --gold-line: rgba(11, 42, 82, .35); --gold-text: #7a5200;
  --red: #e11d24; --red-text: #a01217; --red-ink: #fff6ea; --red-fill: #d81a21; --red-fill-hi: #bd141b; --red-lost: #b8454a; --red-dim: rgba(225, 29, 36, .12);
  --blue: #0a5fc4; --blue-text: #064aa0; --blue-ink: #fff6ea; --blue-fill: #0956b8; --blue-fill-hi: #06469a; --blue-lost: #5a86cc; --blue-dim: rgba(10, 95, 196, .12);
  --live: #05683f; --live-fill: rgba(5, 104, 63, .12); --live-line: rgba(5, 104, 63, .40); --ok: #05683f;
  --warn: #8f4b00; --warn-fill: rgba(143, 75, 0, .12); --warn-line: rgba(143, 75, 0, .42);
  --err: #a81c40; --err-fill: rgba(168, 28, 64, .10); --err-line: rgba(168, 28, 64, .42); --info: #064aa0;
  --focus: #0b2a52;
  --on-field: #fff6ea;
  --field-lost: rgba(255, 246, 234, .74);   /* the losing side's numeral ON a solid field: cream at 74 % = 3.1 on red, 4.2 on blue (large text needs 3) */
  --scrim: rgba(11, 42, 82, .78);
  --shadow-pop: 0 8px 24px rgba(11, 42, 82, .18); --shadow-sheet: 0 -8px 30px rgba(11, 42, 82, .20);
}

@media (prefers-reduced-motion: reduce) {
  :root { --dur-press: 1ms; --dur-state: 1ms; --dur-out: 1ms; --dur-in: 1ms; --dur-pop: 1ms; }
}
