/* Design tokens (design section 11, UX-6).
 *
 * Every colour, space, radius and type value in the codebase comes from here.
 * Nothing else writes a raw colour. Light values live on bare :root; dark values
 * are overridden in exactly one place, twice -- once for the OS preference and
 * once for the explicit data-theme, so the manual toggle wins in both directions
 * (UX-7).
 *
 * The contrast pairs are asserted by a test rather than eyeballed (UX-8): a
 * contrast failure is invisible in review and obvious to a user.
 */

:root {
  color-scheme: light;

  /* Colour: a neutral ramp plus one accent. Colour carries meaning only -- focus,
   * error, selection -- and never decoration (UX-2). */
  --bg: #ffffff;
  --bg-subtle: #f7f7f5;
  --surface: #ffffff;
  --border: #e5e4e0;
  --text: #1a1a19;
  --text-muted: #6b6a64;
  --accent: #3b5bdb;
  --accent-contrast: #ffffff;
  --danger: #b4342b;
  --code-bg: #f7f7f5;

  /* Syntax highlighting. Here rather than in a vendored highlight.js theme, so
   * "nothing else in the codebase writes a raw colour" stays true and the two
   * themes are defined side by side like every other token. */
  --syn-comment: #6b6a64;
  --syn-keyword: #8250a8;
  --syn-string: #2c6e49;
  --syn-number: #9a5518;
  --syn-function: #2b5ca8;
  --syn-type: #8a5a13;
  --syn-variable: #a03050;

  /* Type. System stack only: nothing to load, nothing to flash, no external
   * origin to allow in CSP. */
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue",
    Arial, sans-serif;
  --font-mono: ui-monospace, "Cascadia Code", "Cascadia Mono", Consolas,
    "SF Mono", Menlo, monospace;

  --text-xs: 12px;
  --text-sm: 13px;
  --text-base: 15px;
  --text-md: 17px;
  --text-lg: 20px;
  --text-xl: 24px;
  --leading-prose: 1.6;
  --leading-tight: 1.3;

  /* Space */
  --space-1: 4px;
  --space-2: 8px;
  --space-3: 12px;
  --space-4: 16px;
  --space-5: 24px;
  --space-6: 32px;
  --space-7: 48px;

  /* Radius */
  --radius-sm: 6px;
  --radius-md: 10px;
  --radius-pill: 999px;

  /* One shadow token, used only for the mobile drawer and menus (UX-3). */
  --shadow-overlay: 0 8px 32px rgb(0 0 0 / 18%);

  /* Layout */
  --measure: 72ch;
  --sidebar-width: 272px;
  --touch-target: 44px;

  --focus-ring: 2px solid var(--accent);
  --focus-offset: 2px;
  --transition: 120ms ease;
}

/* The OS preference, which is the default (UX-7). Guarded so that an explicit
 * light choice is not overridden by a dark OS. */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --bg: #1a1a19;
    --bg-subtle: #222221;
    --surface: #262624;
    --border: #35342f;
    --text: #ededea;
    --text-muted: #9c9a92;
    --accent: #7a93f0;
    --accent-contrast: #14142a;
    --danger: #f08279;
    --code-bg: #222221;
    --syn-comment: #8f8d85;
    --syn-keyword: #c9a0e8;
    --syn-string: #8fd0a0;
    --syn-number: #e0a878;
    --syn-function: #90b8f0;
    --syn-type: #e0c088;
    --syn-variable: #f095b0;
    --shadow-overlay: 0 8px 32px rgb(0 0 0 / 55%);
  }
}

/* The explicit choice, which must win over a light OS too. */
:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #1a1a19;
  --bg-subtle: #222221;
  --surface: #262624;
  --border: #35342f;
  --text: #ededea;
  --text-muted: #9c9a92;
  --accent: #7a93f0;
  --accent-contrast: #14142a;
  --danger: #f08279;
  --code-bg: #222221;
  --syn-comment: #8f8d85;
  --syn-keyword: #c9a0e8;
  --syn-string: #8fd0a0;
  --syn-number: #e0a878;
  --syn-function: #90b8f0;
  --syn-type: #e0c088;
  --syn-variable: #f095b0;
  --shadow-overlay: 0 8px 32px rgb(0 0 0 / 55%);
}

@media (prefers-reduced-motion: reduce) {
  :root {
    --transition: 0ms;
  }
}
