/*
 * Design tokens for Monolith (FR-014). Every stylesheet uses these
 * custom properties instead of literal values; the primitives that combine
 * them (.panel, buttons, .stack, .cluster, text styles) are documented at the
 * top of base.css.
 *
 * Layers
 *   type        --text-xs..3xl (12/14/16/20/24/32/40 px) and the roles
 *               --text-caption/body/panel-title/section-title/page-title/display;
 *               --line-height(-snug, -tight); --font-weight-*
 *   spacing     --space-1..7 = 4/8/12/16/24/32/48 px
 *   surfaces    --surface-page (the body), --surface-panel (a .panel),
 *               --surface-raised (a control or card on a panel, with
 *               --shadow-raised), --surface-sunken (wells, current rows)
 *   accent      ONE accent: --accent with -hover, -pressed and -contrast (text
 *               on the accent). --color-accent and --color-focus are aliases.
 *   semantic    --color-success/warning/danger/info, each with a tinted
 *               --color-<state>-surface for notices
 *   controls    --control-bg(-hover, -pressed), --color-border (3:1, any
 *               control outline), --color-border-subtle (decorative panel
 *               edges only: never the only boundary of a control)
 *   interaction --touch-target (44 px), --focus-ring-width/-offset,
 *               --disabled-opacity, --transition-fast
 *
 * Older names (--color-surface, --color-surface-raised, --color-surface-sunken,
 * --color-text*, --color-accent*, --color-focus, --color-danger) keep their
 * meaning: --color-surface is the field/inset white (inputs, graph plot),
 * --color-surface-raised the older grey panel tone.
 *
 * Contrast (WCAG 2.x), proven for light and dark by web/test/ui/design-tokens.test.mjs
 * from these exact values: every text colour (text, muted, accent, semantic,
 * --label-*) is at least 4.5:1 on every surface; --color-border, --color-focus
 * and --accent at least 3:1; --accent-contrast at least 4.5:1 on the accent in
 * every state. Pawn fills rely on their stroke tokens, not on fill contrast
 * with a square. Label colours are never the only cue (NFR-008): pair each
 * with its --label-icon-* text and a written label.
 *
 * Dark mode: the same overrides twice, under prefers-color-scheme (unless the
 * page forces light) and under [data-theme="dark"]; the test checks they agree.
 */

:root {
  color-scheme: light dark;

  /* Surfaces */
  --surface-page: #f5f6f8;
  --surface-panel: #ffffff;
  --surface-raised: #ffffff;
  --surface-sunken: var(--color-surface-sunken);
  --color-surface: #ffffff;
  --color-surface-raised: #f3f4f6;
  --color-surface-sunken: #e5e7eb;

  /* Text */
  --color-text: #1b1f24;
  --color-text-muted: #4b5563;
  --color-text-inverse: #ffffff;

  /* The one accent */
  --accent: #1d4ed8;
  --accent-hover: #1e40af;
  --accent-pressed: #1e3a8a;
  --accent-contrast: #ffffff;
  --color-accent: var(--accent);
  --color-accent-contrast: var(--accent-contrast);
  --color-focus: var(--accent);

  /* Borders and controls */
  --color-border: #7c838e;
  --color-border-subtle: #d7dbe0;
  --control-bg: #ffffff;
  --control-bg-hover: #f1f3f5;
  --control-bg-pressed: #e5e7eb;

  /* Semantic states (text colour, notice surface) */
  --color-success: #1a7f37;
  --color-success-surface: #e9f6ed;
  --color-warning: #875f00;
  --color-warning-surface: #fdf5df;
  --color-danger: #b91c1c;
  --color-danger-surface: #fdeeee;
  --color-info: #1d4ed8;
  --color-info-surface: #eaf0fd;

  --backdrop: rgb(0 0 0 / 0.5);

  /* Depth */
  --shadow-raised: 0 1px 2px rgb(16 24 40 / 0.06), 0 1px 3px rgb(16 24 40 / 0.1);
  --shadow-overlay: 0 4px 6px rgb(16 24 40 / 0.06), 0 12px 24px rgb(16 24 40 / 0.14);

  /* Board */
  --board-square-light: #ecdcb8;
  --board-square-dark: #a87d4f;
  --board-square-highlight: #f2c94c;
  --board-square-target: #3b82f6;
  --board-coordinate: #4b3a26;
  --pawn-black-fill: #1a1a1a;
  --pawn-black-stroke: #f5f5f5;
  --pawn-white-fill: #fafafa;
  --pawn-white-stroke: #1a1a1a;

  /* Move labels (best, good, inaccuracy, mistake, blunder) */
  --label-best: #1a7f37;
  --label-good: #0e6f78;
  --label-inaccuracy: #875f00;
  --label-mistake: #b04a05;
  --label-blunder: #b91c1c;

  /* Label icons: text cues that accompany the colours (used with `content:`) */
  --label-icon-best: "\2605";       /* black star */
  --label-icon-good: "\2713";       /* check mark */
  --label-icon-inaccuracy: "?!";
  --label-icon-mistake: "?";
  --label-icon-blunder: "??";

  /* Spacing scale (4 px base): 4/8/12/16/24/32/48 */
  --space-0: 0;
  --space-1: 0.25rem;
  --space-2: 0.5rem;
  --space-3: 0.75rem;
  --space-4: 1rem;
  --space-5: 1.5rem;
  --space-6: 2rem;
  --space-7: 3rem;

  /* Radii */
  --radius-sm: 0.25rem;
  --radius-md: 0.5rem;
  --radius-lg: 0.75rem;
  --radius-round: 999px;

  /* Type scale (system fonts only: no web fonts, C-002/NFR-008) */
  --font-sans: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --font-mono: ui-monospace, SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace;
  --text-xs: 0.75rem;   /* 12 */
  --text-sm: 0.875rem;  /* 14 */
  --text-md: 1rem;      /* 16 */
  --text-lg: 1.25rem;   /* 20 */
  --text-xl: 1.5rem;    /* 24 */
  --text-2xl: 2rem;     /* 32 */
  --text-3xl: 2.5rem;   /* 40 */
  --text-caption: var(--text-sm);
  --text-body: var(--text-md);
  --text-panel-title: var(--text-md);
  --text-section-title: var(--text-lg);
  --text-page-title: var(--text-xl);
  --text-display: var(--text-3xl);
  --line-height: 1.5;
  --line-height-snug: 1.35;
  --line-height-tight: 1.2;
  --font-weight-regular: 400;
  --font-weight-medium: 500;
  --font-weight-semibold: 600;
  --font-weight-bold: 700;

  /* Interaction */
  --touch-target: 44px;
  --focus-ring-width: 3px;
  --focus-ring-offset: 2px;
  --disabled-opacity: 0.55;
  --transition-fast: 120ms ease-out;

  /* Layout */
  --side-panel-width: 22rem;
  --content-max-width: 80rem;
}

/* Dark colours: the system setting, unless the page forces the light theme. */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --surface-page: #111418;
    --surface-panel: #181c22;
    --surface-raised: #1f242b;
    --color-surface: #111418;
    --color-surface-raised: #1c2128;
    --color-surface-sunken: #0b0d10;
    --color-text: #e6e8eb;
    --color-text-muted: #a7afba;
    --color-text-inverse: #111418;
    --accent: #7aa7ff;
    --accent-hover: #9dbcff;
    --accent-pressed: #b7ceff;
    --accent-contrast: #111418;
    --color-border: #7a8390;
    --color-border-subtle: #2e343c;
    --control-bg: #1f242b;
    --control-bg-hover: #242a31;
    --control-bg-pressed: #2a3038;
    --color-success: #4ac26b;
    --color-success-surface: #122a1a;
    --color-warning: #e3b341;
    --color-warning-surface: #2d2410;
    --color-danger: #ff7b72;
    --color-danger-surface: #351817;
    --color-info: #7aa7ff;
    --color-info-surface: #15213a;
    --shadow-raised: 0 1px 2px rgb(0 0 0 / 0.4);
    --shadow-overlay: 0 12px 32px rgb(0 0 0 / 0.55);

    --board-square-light: #c9b48c;
    --board-square-dark: #8a6640;
    --board-coordinate: #2b2116;

    --label-best: #4ac26b;
    --label-good: #3fc1c9;
    --label-inaccuracy: #e3b341;
    --label-mistake: #f0883e;
    --label-blunder: #ff7b72;
  }
}

/* The same dark colours when the page explicitly selects the dark theme. */
:root[data-theme="dark"] {
  --surface-page: #111418;
  --surface-panel: #181c22;
  --surface-raised: #1f242b;
  --color-surface: #111418;
  --color-surface-raised: #1c2128;
  --color-surface-sunken: #0b0d10;
  --color-text: #e6e8eb;
  --color-text-muted: #a7afba;
  --color-text-inverse: #111418;
  --accent: #7aa7ff;
  --accent-hover: #9dbcff;
  --accent-pressed: #b7ceff;
  --accent-contrast: #111418;
  --color-border: #7a8390;
  --color-border-subtle: #2e343c;
  --control-bg: #1f242b;
  --control-bg-hover: #242a31;
  --control-bg-pressed: #2a3038;
  --color-success: #4ac26b;
  --color-success-surface: #122a1a;
  --color-warning: #e3b341;
  --color-warning-surface: #2d2410;
  --color-danger: #ff7b72;
  --color-danger-surface: #351817;
  --color-info: #7aa7ff;
  --color-info-surface: #15213a;
  --shadow-raised: 0 1px 2px rgb(0 0 0 / 0.4);
  --shadow-overlay: 0 12px 32px rgb(0 0 0 / 0.55);

  --board-square-light: #c9b48c;
  --board-square-dark: #8a6640;
  --board-coordinate: #2b2116;

  --label-best: #4ac26b;
  --label-good: #3fc1c9;
  --label-inaccuracy: #e3b341;
  --label-mistake: #f0883e;
  --label-blunder: #ff7b72;
}
