/*
 * tokens.css — the single source of truth for UI-A §3.1.
 *
 * Every raw colour value in the application lives here and nowhere else
 * (UI-A §2 non-goal 3). Components consume `var(--token)` only; the
 * inline-style -> token migration that makes that true of the existing
 * components is UI-A2 (spec 0025), not this slice.
 *
 * Two theme scopes, selected by the `data-theme` attribute (set at runtime by
 * UI-A2; this file only defines what the scopes contain):
 *
 *   scriptorium — dark, the default (UI-A §6 D-1). Warm near-black ground,
 *                 warm off-white ink. Elevation by lightening (§3.4).
 *   lectorium   — light. The printed page.
 *
 * Constraints enforced mechanically by `bb theme-lint` (UI-A §3.3, AC-2):
 *   1. --ink on --surface >= 10:1, --ink-muted on --surface >= 4.5:1 (WCAG).
 *   2. --surface never #000/#fff; --ink never #fff/#000.
 *   3. --tier-1 <-> --rubric CIEDE2000 ΔE00 >= 15 in BOTH themes.
 *   4. --tier-1..5 pairwise distinguishable under deutan + protan (Machado 2009).
 *   5. --tier-*/--viz-* series desaturated in dark vs their light counterparts.
 *
 * Token semantics (which concept each family names) are UI-A §3.2 — read it
 * before adding or repurposing a token. The tier ramp colours the priority TIER
 * (P1..P5), never severity; severity keeps its own --severity-* family (§3.2, D-1).
 */

/* --- Typography roles (UI-A §4) -------------------------------------------- *
 * Roles, not faces, are the vocabulary. Faces are theme-independent, so they
 * live in :root, not in a theme scope. Small caps come from the OpenType
 * feature (font-variant-caps), never a CSS uppercase transform (§4).
 *
 * W2 / best-effort: the @font-face blocks below point at self-hosted woff2
 * paths under /fonts/. The binaries are NOT vendored in this slice (no network
 * in the build sandbox); until they are fetched, the stacks fall back to the
 * next family in the list. Fonts are W2 and covered by no AC, so this is a
 * TODO, not a blocker.
 */
:root {
  --font-display: "EB Garamond", Georgia, "Times New Roman", serif;
  --font-body: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --font-mono: "JetBrains Mono", ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, monospace;
}

/* TODO(UI-A2/W2): vendor the woff2 binaries under
 * presentation/server/resources/public/fonts/ and drop the fallbacks above.
 * Declarations kept here so the role is frozen; the reference aesthetic is
 * early print (incunabula), never a gothic display face (§2 non-goal 2). */
@font-face {
  font-family: "EB Garamond";
  font-style: normal;
  font-weight: 400 700;
  font-display: swap;
  src: url("/fonts/eb-garamond-var.woff2") format("woff2");
}
@font-face {
  font-family: "JetBrains Mono";
  font-style: normal;
  font-weight: 400 700;
  font-display: swap;
  src: url("/fonts/jetbrains-mono-var.woff2") format("woff2");
}

/* --- scriptorium (dark, default) ------------------------------------------ */
:root[data-theme="scriptorium"] {
  /* ground & elevation */
  --surface: #191512;
  --surface-raised: #241f1a;
  --surface-inset: #131009;

  /* ink */
  --ink: #e7dfd0;
  --ink-muted: #a89e8c;
  --ink-faint: #5f574b;

  /* structural ornament (never a tier, never a severity) */
  --rubric: #c9503c;
  --accent-verdict: #b99a4a;

  /* priority tier ramp P1..P5 (desaturated for the dark ground) */
  --tier-1: #b83a5a;
  --tier-2: #c07033;
  --tier-3: #cdb84a;
  --tier-4: #5081bf;
  --tier-5: #8b99a6;

  /* severity enum (3-value; distinct concept from the tier ramp) */
  --severity-info: #6a97c4;
  --severity-warning: #c79a3e;
  --severity-error: #c15f4c;

  /* non-tier categorical chart series (§3.2.1, N=2: cycles, complexity) */
  --viz-1: #9160a5;
  --viz-2: #4a86b3;
  --viz-grid: #2c2721;
  --viz-axis: #4a443b;

  /* focus ring */
  --focus: #7bb3e8;

  /* operational states (jobs/network; not the severity enum) */
  --state-ok: #6f9e5a;
  --state-warn: #c79a3e;
  --state-error: #c15f4c;
}

/* --- lectorium (light) ---------------------------------------------------- */
:root[data-theme="lectorium"] {
  /* ground & elevation */
  --surface: #f3ecdd;
  --surface-raised: #faf6ec;
  --surface-inset: #eae2cf;

  /* ink */
  --ink: #26201a;
  --ink-muted: #5c5347;
  --ink-faint: #b8ad97;

  /* structural ornament (never a tier, never a severity) */
  --rubric: #8f2318;
  --accent-verdict: #7a6224;

  /* priority tier ramp P1..P5 (full saturation on the light ground) */
  --tier-1: #d5004e;
  --tier-2: #e8710a;
  --tier-3: #f5d800;
  --tier-4: #2f6fd0;
  --tier-5: #a7bccb;

  /* severity enum (3-value; distinct concept from the tier ramp) */
  --severity-info: #2f6db5;
  --severity-warning: #b9791a;
  --severity-error: #c0392b;

  /* non-tier categorical chart series (§3.2.1, N=2: cycles, complexity) */
  --viz-1: #8e44ad;
  --viz-2: #2980b9;
  --viz-grid: #ded4bf;
  --viz-axis: #b7ac95;

  /* focus ring */
  --focus: #1e6fd0;

  /* operational states (jobs/network; not the severity enum) */
  --state-ok: #3d7a2e;
  --state-warn: #b9791a;
  --state-error: #c0392b;
}

/* --- base application ground (UI-A2 §6) ----------------------------------- *
 * Applies the active theme to the page itself so the data-theme switch is
 * visible at the frame, not only inside migrated components. References tokens
 * only (no raw colour), so it is neutral to the AC-1 grep. */
html { background: var(--surface); }
body {
  margin: 0;
  background: var(--surface);
  color: var(--ink);
  font-family: var(--font-body);
}

/* --- print & export: force lectorium (UI-A2 §7) --------------------------- *
 * The printed page is light by nature (UI-A1). Under print media the lectorium
 * token set is forced regardless of the on-screen data-theme, and export views
 * render it unconditionally. `!important` on :root overrides the themed scopes'
 * higher-specificity selectors in print context. These raw values live in
 * tokens.css — the one file the AC-1 grep excludes — so they are not duplicated
 * raw colour in a component. Frame ornament is stripped (§7.1); verdict
 * manicules carry information and are kept. No frame ornament exists in the DOM
 * yet, so the strip rule is a forward-looking guard keyed on the ornament
 * data-attribute UI-C will set. */
@media print {
  :root {
    --surface: #f3ecdd !important;
    --surface-raised: #faf6ec !important;
    --surface-inset: #eae2cf !important;
    --ink: #26201a !important;
    --ink-muted: #5c5347 !important;
    --ink-faint: #b8ad97 !important;
    --rubric: #8f2318 !important;
    --accent-verdict: #7a6224 !important;
    --tier-1: #d5004e !important;
    --tier-2: #e8710a !important;
    --tier-3: #f5d800 !important;
    --tier-4: #2f6fd0 !important;
    --tier-5: #a7bccb !important;
    --severity-info: #2f6db5 !important;
    --severity-warning: #b9791a !important;
    --severity-error: #c0392b !important;
    --viz-1: #8e44ad !important;
    --viz-2: #2980b9 !important;
    --viz-grid: #ded4bf !important;
    --viz-axis: #b7ac95 !important;
    --focus: #1e6fd0 !important;
    --state-ok: #3d7a2e !important;
    --state-warn: #b9791a !important;
    --state-error: #c0392b !important;
  }
  /* strip frame ornament (§7.1), keep the verdict manicule (it is information) */
  [data-ornament]:not([data-ornament="manicule"]) { display: none !important; }
}

/* --- reduced motion, respected globally (UI-A2 §6.5) ---------------------- *
 * Independent of theme: a reader who asks the OS to reduce motion gets it
 * everywhere. No colour concern — motion only. */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.001ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.001ms !important;
    scroll-behavior: auto !important;
  }
}
