/* Figuras design tokens — the one place the visual language is defined.

   Linked by every page BEFORE its own <style>, so a page's rules consume
   these rather than restating them. Before this file each page carried its
   own copy of the palette, and the copies had already drifted.

   Only four base colours are chosen: --paper, --ink, --teal (the accent)
   and --coral (the Figuras marker). applyBranding.js and the <head>
   pre-paint snippet override the first three with the school's own theme,
   inline on <html>. Every other surface, line and text shade below is
   DERIVED from them with color-mix(), so a school on Midnight or Forest
   gets blue- or green-tinted cards and hairlines that belong to its paper,
   not the fixed cream the pages used to hard-code.

   The mix percentages are not taste. --ink-faint at 66% is the lightest
   mix that still clears WCAG AA (4.5:1) on --paper, --paper-2 AND
   --paper-3 for every preset theme in brandingPalette.js; the old fixed
   #a1968a measured 2.6:1, and it was the colour of every inactive tab and
   field hint. --coral and --gold were deepened for the same reason (3.9:1
   and 2.6:1 before). Colour contrast is re-checked by
   tests/design-tokens.test.mjs. */

:root{
  /* ---- base (overridden per school) ---- */
  --paper:#fafaf8;
  --ink:#1a1a18;
  --teal:#0e6e6e;
  --coral:#b5382a;
  --gold:#8a5d10;

  --disp:'Inter', ui-sans-serif, system-ui, -apple-system, 'Segoe UI', sans-serif;
  --body:'Inter', ui-sans-serif, system-ui, -apple-system, 'Segoe UI', sans-serif;
  --mono:ui-monospace,'SF Mono','JetBrains Mono',Menlo,Consolas,monospace;

  /* ---- derived colours, as static fallbacks ----
     The Classic theme's values, precomputed, for a browser without
     color-mix() (pre-2023). The @supports block below replaces every one
     with the live derivation; the test checks the two agree. */
  --paper-2:#fdfdfc;
  --paper-3:#efefed;
  --field:#fefefe;
  --line:#e4e4e2;
  --line-strong:#cfcfcd;
  --ink-soft:#474745;
  --ink-faint:#666664;
  --teal-soft:#e3edec;
  --coral-soft:#f5e7e5;
  --gold-soft:#f0ebe2;
  --teal-line:#bad5d4;
  --coral-line:#eacac5;
  --gold-line:#dfd3bf;
  --scrim:rgba(26,26,24,.42);

  --accent:var(--fig-accent,var(--teal));
  --on-accent:var(--fig-on-accent,#fff);

  /* ---- status ---- */
  --ok-ink:#0f5c48;     --ok-bg:#deede7;
  --warn-ink:#8a5d10;   --warn-bg:#f5ebd8;
  --danger-ink:#8d2c1f; --danger-bg:var(--coral-soft);

  /* ---- radii: four steps and a pill ---- */
  --r-xs:6px; --r-sm:8px; --r-md:12px; --r-lg:16px; --r-pill:999px;

  /* ---- elevation ---- */
  --sh-1:0 1px 2px rgba(26,26,24,.05);
  --sh-2:0 1px 2px rgba(26,26,24,.05), 0 6px 18px -8px rgba(26,26,24,.14);
  --sh-3:0 2px 6px rgba(26,26,24,.07), 0 20px 44px -14px rgba(26,26,24,.26);
  --ring:0 0 0 3px rgba(14,110,110,.26);

  /* ---- type ---- */
  --text-display:clamp(32px,5vw,46px);
  --track-display:-.028em; --track-title:-.012em;

  /* ---- motion ---- */
  --ease:cubic-bezier(.2,.75,.25,1);
  --dur-1:120ms; --dur-2:180ms; --dur-3:260ms;
}

/* ---- the live derivation ----
   Everything below follows the school's paper, ink and accent, because
   applyBranding() overrides those on <html> and these resolve there. */
@supports (color: color-mix(in srgb, red 50%, blue)){
  :root{
    /* surfaces: page → raised → field, and sunken */
    --paper-2:color-mix(in srgb, #fff 62%, var(--paper));
    --paper-3:color-mix(in srgb, var(--ink) 5%, var(--paper));
    --field:color-mix(in srgb, #fff 82%, var(--paper));
    --line:color-mix(in srgb, var(--ink) 10%, var(--paper));
    --line-strong:color-mix(in srgb, var(--ink) 19%, var(--paper));

    /* inks */
    --ink-soft:color-mix(in srgb, var(--ink) 80%, var(--paper));
    --ink-faint:color-mix(in srgb, var(--ink) 66%, var(--paper));

    /* tints */
    --teal-soft:color-mix(in srgb, var(--teal) 11%, var(--paper-2));
    --coral-soft:color-mix(in srgb, var(--coral) 11%, var(--paper-2));
    --gold-soft:color-mix(in srgb, var(--gold) 11%, var(--paper-2));
    --teal-line:color-mix(in srgb, var(--teal) 28%, var(--paper-2));
    --coral-line:color-mix(in srgb, var(--coral) 26%, var(--paper-2));
    --gold-line:color-mix(in srgb, var(--gold) 26%, var(--paper-2));
    --ok-bg:color-mix(in srgb, #1f8a66 14%, var(--paper-2));
    --warn-bg:color-mix(in srgb, #c98a1e 16%, var(--paper-2));
    --scrim:color-mix(in srgb, var(--ink) 42%, transparent);

    /* elevation, tinted by the school's ink so shadows sit in its palette */
    --sh-1:0 1px 2px color-mix(in srgb, var(--ink) 5%, transparent);
    --sh-2:0 1px 2px color-mix(in srgb, var(--ink) 5%, transparent), 0 6px 18px -8px color-mix(in srgb, var(--ink) 14%, transparent);
    --sh-3:0 2px 6px color-mix(in srgb, var(--ink) 7%, transparent), 0 20px 44px -14px color-mix(in srgb, var(--ink) 26%, transparent);
    --ring:0 0 0 3px color-mix(in srgb, var(--accent) 26%, transparent);
  }
}

/* ---- element defaults every page shares ----
   Wrapped in :where() so each carries zero specificity: a page rule of
   any shape still wins, which keeps these as a floor, not an override. */

:where(html){ -webkit-text-size-adjust:100%; text-size-adjust:100%; }
:where(body){ text-rendering:optimizeLegibility; font-feature-settings:'cv11','ss03'; font-optical-sizing:auto; }
:where(h1,h2,h3,h4){ text-wrap:balance; }
:where(p){ text-wrap:pretty; }
:where(button, a, input, select, textarea, summary){ -webkit-tap-highlight-color:transparent; }
:where(input, select, textarea){ accent-color:var(--accent); }
:where(code, kbd, samp){ font-family:var(--mono); }
::selection{ background:color-mix(in srgb, var(--accent) 22%, transparent); }

/* Text fields get a soft accent halo instead of a hard outline — the one
   focus treatment across every form in the app. Specific enough to beat
   each page's bare :focus-visible outline, which buttons and links keep. */
input:not([type="checkbox"]):not([type="radio"]):not([type="range"]):focus-visible,
select:focus-visible,
textarea:focus-visible{
  outline:none;
  border-color:var(--accent);
  box-shadow:var(--ring);
}
:where(input, select, textarea){ transition:border-color var(--dur-1) var(--ease), box-shadow var(--dur-1) var(--ease); }

@media (prefers-reduced-motion: reduce){
  *, *::before, *::after{
    animation-duration:.01ms !important;
    animation-iteration-count:1 !important;
    transition-duration:.01ms !important;
    scroll-behavior:auto !important;
  }
}
