/* Tart design tokens. Load this file FIRST on every page, before any other stylesheet.
   Source: survey DECISIONS.md §3 and colors-type.md §4–5 (2026-11-23). Ratios are WCAG 2.x contrast, computed.
   Rules that keep the site calm:
   - one solid --accent fill per view (the primary action); selected states use --accent-soft + --accent-ink;
   - accent text only for links and at most one word per heading; never put --accent text on dark (2.7:1);
   - at most one dark band per page: give it class="on-dark" (or data-surface="dark") and the tokens below remap;
   - the sidebar and top bar are always light: nothing may react to html[data-tone] (Mini Tart still reads it);
   - text is never smaller than --fs-xs (13 px; 14 px in Thai). Monospace is for real code only.
   Fonts: dist/fonts.css (self-hosted DM Sans + Anuphan). Legacy names at the end keep older CSS working. */

:root {
  color-scheme: light;

  /* Surfaces */
  --bg: #f7f7f5;            /* page and section background */
  --surface: #ffffff;       /* cards, dialogs, one alternate band */
  --surface-2: #f0f0ec;     /* wells, chips, hover, code */

  /* Text */
  --ink: #16181d;           /* 16.6:1 on --bg */
  --ink-2: #3f444e;         /* 9.1:1, secondary copy and sub-headings */
  --muted: #656a75;         /* 5.06 on --bg, 5.42 on --surface, 4.75 on --surface-2, 4.81 on --accent-soft */
  --subtle: #8a8f99;        /* 3.0–3.3:1: placeholders, disabled, decoration only, never body text */

  /* Lines */
  --line: #e5e5e0;          /* hairlines, dividers */
  --line-strong: #d4d4cd;   /* card and button borders */
  --line-input: #8a8f99;    /* form-field borders, 3.25:1 (WCAG 1.4.11) */

  /* Accent (one blue) */
  --accent: #2d4fd6;        /* fills: primary button, active dot, progress; white on it 6.56:1 */
  --accent-hover: #2442bd;  /* white on it 8.1:1 */
  --accent-ink: #2843b5;    /* accent text and links on light, 7.3–8.2:1 */
  --accent-soft: #eef1fd;   /* selected chip, tab, callout */
  --accent-soft-2: #d9e0fa; /* selected border, ::selection */
  --on-accent: #ffffff;

  /* The single dark band and media frames (raw values; prefer the .on-dark scope below) */
  --dark: #15171c;
  --dark-2: #1e2128;
  --dark-3: #262a32;
  --dark-line: #2c3038;
  --on-dark: #f3f4f6;       /* 16.3:1 on --dark */
  --on-dark-2: #c9ccd3;     /* 11.2:1 */
  --on-dark-muted: #a3a8b3; /* 7.5:1 on --dark, 6.8:1 on --dark-2 */
  --accent-on-dark: #9db0ff;/* 8.6:1 on --dark */

  /* States */
  --focus: #2d4fd6;         /* 6.1:1 against --bg */
  --focus-on-dark: #9db0ff;
  --focus-width: 2px;
  --focus-offset: 2px;
  --success: #1d7a4f;       /* 5.3:1 on white */
  --warning: #9a5b00;       /* 5.4:1 on white */
  --danger: #c0392b;        /* 5.4:1 on white */

  /* Shape */
  --radius-xs: 6px;
  --radius-sm: 8px;
  --radius: 12px;
  --radius-lg: 16px;
  --radius-xl: 24px;
  --radius-pill: 999px;
  --shadow-1: 0 1px 2px rgb(22 24 29 / .05);
  --shadow-2: 0 8px 24px rgb(22 24 29 / .06);
  --shadow-3: 0 24px 56px -24px rgb(22 24 29 / .22), 0 2px 6px rgb(22 24 29 / .05); /* dialogs, popovers */

  /* Spacing: --space-N = N × 4 px */
  --space-1: 4px;
  --space-2: 8px;
  --space-3: 12px;
  --space-4: 16px;
  --space-5: 20px;
  --space-6: 24px;
  --space-8: 32px;
  --space-10: 40px;
  --space-12: 48px;
  --space-16: 64px;
  --space-20: 80px;
  --space-24: 96px;
  --space-30: 120px;
  --gutter: clamp(16px, 4.5vw, 72px);         /* page side padding: 16 px on phones */
  --section-y: clamp(72px, 40px + 6vw, 120px); /* one section rhythm: 72 / 96 / 120 */
  --measure: 68ch;                             /* longest comfortable line */
  --tap: 44px;                                 /* minimum touch target */

  /* Type: one family for both scripts (DM Sans + Anuphan for Thai, see fonts.css) */
  --font-sans: 'DM Sans', 'Anuphan', system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
  --font-mono: ui-monospace, 'Cascadia Mono', 'SF Mono', Menlo, Consolas, monospace;
  --fs-display: clamp(2.75rem, 1.6rem + 4.2vw, 5.5rem);  /* 44 → 88 */
  --fs-h2: clamp(2rem, 1.45rem + 2vw, 3.25rem);          /* 32 → 52 */
  --fs-h3: clamp(1.25rem, 1.1rem + .5vw, 1.5rem);        /* 20 → 24 */
  --fs-h4: 1.125rem;                                     /* 18, card titles */
  --fs-lead: clamp(1.0625rem, 1rem + .35vw, 1.25rem);    /* 17 → 20 */
  --fs-body: 1rem;                                       /* 16 */
  --fs-sm: .875rem;                                      /* 14: meta, captions, buttons */
  --fs-xs: .8125rem;                                     /* 13: labels, chips, eyebrows. The floor. */
  --lh-display: 1.02;
  --lh-heading: 1.15;
  --lh-body: 1.65;
  --lh-ui: 1.4;
  --tr-display: -.035em;
  --tr-heading: -.025em;
  --tr-label: .01em;
  --fw-body: 400;
  --fw-ui: 500;
  --fw-heading: 600;

  /* Motion (durations drop to 0 when motion is off) */
  --ease-out: cubic-bezier(.22, 1, .36, 1);
  --ease-standard: cubic-bezier(.4, 0, .2, 1);
  --dur-1: 120ms;  /* press, hover */
  --dur-2: 200ms;  /* small state changes */
  --dur-3: 320ms;  /* panels, reveals */
  --dur-4: 400ms;  /* the longest allowed flourish */

  /* Legacy names: older CSS keeps working and picks up the new palette.
     Their old :root values in style.css, experience.css, academic.css and project-page.css must be deleted,
     because a later :root declaration wins over this file. */
  --paper: var(--bg);
  --blue: var(--accent);
  --ease: var(--ease-out);
  --motion-ease: var(--ease-out);
  --motion-standard: var(--ease-standard);
  --page-gutter: var(--gutter);
}

/* Thai: looser leading for stacked marks, no tracking, 14 px floor, slightly smaller display size.
   Declared on the root (and on Thai islands) only, so component-level overrides keep working. */
:root:lang(th),
[lang|="th"] {
  --fs-display: clamp(2.5rem, 1.4rem + 4vw, 5rem);       /* 40 → 80 */
  --fs-sm: .9375rem;                                     /* 15 */
  --fs-xs: .875rem;                                      /* 14: Thai floor */
  --lh-display: 1.25;
  --lh-heading: 1.35;
  --lh-body: 1.8;
  --lh-ui: 1.55;
  --tr-display: 0;
  --tr-heading: 0;
  --tr-label: 0;
}

/* The single dark set. Put class="on-dark" (or data-surface="dark") on the one dark band or a dark media frame;
   everything inside that uses the semantic tokens adapts. Never key this to html[data-tone]. */
.on-dark,
[data-surface="dark"] {
  color-scheme: dark;
  --bg: #15171c;
  --surface: #1e2128;
  --surface-2: #262a32;
  --ink: #f3f4f6;           /* 16.3:1 on --bg, 13.1:1 on --surface-2 */
  --ink-2: #c9ccd3;         /* 11.2:1 */
  --muted: #a3a8b3;         /* 7.5:1 on --bg, 6.0:1 on --surface-2 */
  --subtle: #646a77;        /* decoration only */
  --line: #2c3038;
  --line-strong: #3a3f49;
  --line-input: #6f7581;    /* 3.9:1 */
  --accent: #9db0ff;        /* on dark the fill is the light blue, with dark text (8.6:1) */
  --accent-hover: #b8c6ff;
  --accent-ink: #9db0ff;    /* 8.6:1 on --bg, 7.7:1 on --surface */
  --accent-soft: #262c42;   /* --accent-ink on it 6.6:1 */
  --accent-soft-2: #343d60;
  --on-accent: #15171c;
  --focus: #9db0ff;
  --success: #4fbf8a;       /* 7.8:1 */
  --warning: #e0a54a;       /* 8.2:1 */
  --danger: #ff8a7a;        /* 7.8:1 */
  --shadow-1: 0 1px 2px rgb(0 0 0 / .3);
  --shadow-2: 0 8px 24px rgb(0 0 0 / .35);
  background-color: var(--bg);
  color: var(--ink);
}

/* One focus ring everywhere: 2 px accent, 2 px gap (light blue inside the dark set). */
:focus-visible {
  outline: var(--focus-width) solid var(--focus);
  outline-offset: var(--focus-offset);
}
::selection {
  background: var(--accent-soft-2);
  color: var(--ink);
}

@media (prefers-reduced-motion: reduce) {
  :root { --dur-1: 0ms; --dur-2: 0ms; --dur-3: 0ms; --dur-4: 0ms; }
}
:root[data-motion="off"] { --dur-1: 0ms; --dur-2: 0ms; --dur-3: 0ms; --dur-4: 0ms; }
