/* ==========================================================================
   MERLIN INTELLIGENCE v3 — BASE
   Fonts, reset, element defaults, typography roles, layout primitives,
   focus, selection, reduced motion, print. Layer: base (+ utilities).
   ========================================================================== */

@font-face {
  font-family: "Source Serif 4";
  src: url("fonts/source-serif-4-var.woff2") format("woff2");
  font-weight: 400 700;
  font-style: normal;
  font-display: swap;
}
@font-face {
  font-family: "IBM Plex Mono";
  src: url("fonts/ibm-plex-mono-400.woff2") format("woff2");
  font-weight: 400;
  font-style: normal;
  font-display: swap;
}
@font-face {
  font-family: "IBM Plex Mono";
  src: url("fonts/ibm-plex-mono-500.woff2") format("woff2");
  font-weight: 500 700;
  font-style: normal;
  font-display: swap;
}

@layer reset {
  *, *::before, *::after { box-sizing: border-box; }
  * { margin: 0; }
  html { -webkit-text-size-adjust: 100%; text-size-adjust: 100%; }
  img, picture, video, canvas, svg { display: block; max-width: 100%; }
  input, button, textarea, select { font: inherit; color: inherit; letter-spacing: inherit; }
  button { background: none; border: 0; padding: 0; cursor: pointer; text-align: inherit; }
  a { color: inherit; }
  ul[role="list"], ol[role="list"] { list-style: none; padding: 0; }
  table { border-collapse: collapse; border-spacing: 0; }
  p, h1, h2, h3, h4, h5, h6 { overflow-wrap: break-word; }
  [hidden] { display: none !important; } /* the one sanctioned !important: hidden must win */
}

@layer base {
  html {
    background: var(--bg);
    color: var(--ink-2);
    font-family: var(--font-sans);
    font-size: 100%;
    line-height: var(--lh-ui);
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    text-rendering: optimizeLegibility;
    font-synthesis-weight: none;
    scrollbar-color: var(--line-3) transparent;
    scroll-padding-top: calc(var(--strip-h) + var(--s-4));
    hanging-punctuation: first;
  }
  body {
    min-height: 100dvh;
    background: var(--bg);
    font-size: var(--fs-4);
    isolation: isolate;
  }
  ::selection { background: var(--selection); color: var(--ink-1); }

  h1, h2, h3, h4 { color: var(--ink-1); font-weight: var(--fw-semibold); line-height: var(--lh-snug); text-wrap: balance; }
  p { text-wrap: pretty; }
  a { text-underline-offset: 0.18em; text-decoration-thickness: 1px; text-decoration-color: color-mix(in srgb, currentColor 40%, transparent); }
  a:hover { text-decoration-color: currentColor; }
  strong, b { color: var(--ink-1); font-weight: var(--fw-semibold); }
  small { font-size: var(--fs-2); }
  hr { border: 0; border-top: 1px solid var(--line-1); }
  code, kbd, samp { font-family: var(--font-mono); font-size: 0.92em; }
  abbr[title] { text-decoration: underline dotted; text-underline-offset: 0.2em; cursor: help; }
  time { font-variant-numeric: tabular-nums; }

  /* Focus: one ring, everywhere. Gold, offset so it reads over any fill. */
  :focus { outline: none; }
  :focus-visible {
    outline: var(--focus-w) solid var(--focus);
    outline-offset: var(--focus-offset);
    border-radius: var(--r-sm);
  }
  /* Inputs: ring sits inside so it never collides with neighbours */
  input:focus-visible, textarea:focus-visible, select:focus-visible { outline-offset: -1px; }

  /* Scrollbars (webkit) — thin, quiet, thumb lights on hover */
  ::-webkit-scrollbar { width: 10px; height: 10px; }
  ::-webkit-scrollbar-track { background: transparent; }
  ::-webkit-scrollbar-thumb { background: var(--line-2); border-radius: 10px; border: 3px solid transparent; background-clip: content-box; }
  ::-webkit-scrollbar-thumb:hover { background: var(--line-3); background-clip: content-box; border: 2px solid transparent; }
}

/* ---- Typography roles ---------------------------------------------------
   Use these classes (or the matching kit components). They encode the
   whole voice: serif for editorial, sans for chrome, mono for numbers.     */
@layer base {
  .t-display {        /* view titles: "State of Merlin" */
    font-family: var(--font-serif);
    font-size: var(--fs-8);
    font-weight: 500;
    line-height: var(--lh-tight);
    letter-spacing: var(--track-tight);
    color: var(--ink-1);
    font-variation-settings: "opsz" 60;
  }
  .t-headline {       /* section heads */
    font-family: var(--font-serif);
    font-size: var(--fs-7);
    font-weight: 500;
    line-height: 1.18;
    letter-spacing: var(--track-tight);
    color: var(--ink-1);
    font-variation-settings: "opsz" 36;
  }
  .t-title {          /* card titles */
    font-family: var(--font-serif);
    font-size: var(--fs-6);
    font-weight: 560;
    line-height: var(--lh-snug);
    letter-spacing: -0.005em;
    color: var(--ink-1);
    font-variation-settings: "opsz" 20;
  }
  .t-kicker {         /* uppercase micro-label above a title */
    font-family: var(--font-sans);
    font-size: var(--fs-1);
    font-weight: var(--fw-semibold);
    line-height: 1.2;
    letter-spacing: var(--track-micro);
    text-transform: uppercase;
    color: var(--ink-3);
  }
  .t-label {          /* field / stat labels (mixed case) */
    font-size: var(--fs-2);
    font-weight: var(--fw-medium);
    line-height: 1.3;
    color: var(--ink-3);
  }
  .t-body { font-size: var(--fs-4); line-height: var(--lh-ui); color: var(--ink-2); }
  .t-small { font-size: var(--fs-3); line-height: 1.4; color: var(--ink-3); }
  .t-meta { font-size: var(--fs-2); line-height: 1.35; color: var(--ink-4); }
  .t-prose {          /* editorial reading text */
    font-family: var(--font-serif);
    font-size: var(--fs-6);
    line-height: var(--lh-prose);
    color: var(--ink-2);
    max-width: var(--prose-max);
    font-variation-settings: "opsz" 18;
    hyphens: auto;
  }
  .t-prose p + p { margin-top: 0.85em; }
  .t-prose a { color: var(--ink-1); }
  .t-dek {            /* standfirst under a display title */
    font-family: var(--font-serif);
    font-size: var(--fs-6);
    line-height: 1.45;
    color: var(--ink-2);
    font-style: normal;
    max-width: 62ch;
    font-variation-settings: "opsz" 18;
  }

  /* Numerals: every number, ticker, tail, timestamp. */
  .num, .t-num {
    font-family: var(--font-mono);
    font-variant-numeric: tabular-nums slashed-zero;
    font-feature-settings: "tnum" 1, "zero" 0;
    letter-spacing: 0;
  }
  .num-xl { font-family: var(--font-mono); font-size: var(--fs-8); font-weight: 500; line-height: 1; letter-spacing: -0.03em; color: var(--ink-1); font-variant-numeric: tabular-nums; }
  .num-lg { font-family: var(--font-mono); font-size: var(--fs-7); font-weight: 500; line-height: 1.05; letter-spacing: -0.025em; color: var(--ink-1); font-variant-numeric: tabular-nums; }
  .num-md { font-family: var(--font-mono); font-size: var(--fs-5); font-weight: 500; line-height: 1.2; color: var(--ink-1); font-variant-numeric: tabular-nums; }
  .num-sm { font-family: var(--font-mono); font-size: var(--fs-3); line-height: 1.3; font-variant-numeric: tabular-nums; }
  .id {               /* identifiers: tails, hexes, ICAO, accession numbers */
    font-family: var(--font-mono);
    font-size: 0.94em;
    letter-spacing: 0.01em;
    font-variant-numeric: tabular-nums;
  }

  .ink-1 { color: var(--ink-1); }
  .ink-2 { color: var(--ink-2); }
  .ink-3 { color: var(--ink-3); }
  .ink-4 { color: var(--ink-4); }
  .is-up { color: var(--up); }
  .is-down { color: var(--down); }
  .is-warn { color: var(--warn); }
  .is-live { color: var(--live); }
  .is-model { color: var(--model); }
  .is-accent { color: var(--accent); }
}

/* ---- Layout primitives -------------------------------------------------- */
@layer base {
  .container { width: 100%; max-width: var(--content-max); margin-inline: auto; padding-inline: var(--gutter); }
  .grid-12 { display: grid; grid-template-columns: repeat(12, minmax(0, 1fr)); gap: var(--gap-grid); }
  .stack { display: flex; flex-direction: column; gap: var(--gap-stack); }
  .stack-sm { display: flex; flex-direction: column; gap: var(--s-2); }
  .stack-lg { display: flex; flex-direction: column; gap: var(--s-8); }
  .cluster { display: flex; flex-wrap: wrap; align-items: center; gap: var(--s-2); }
  .row { display: flex; align-items: center; gap: var(--s-2); min-width: 0; }
  .row-between { display: flex; align-items: center; justify-content: space-between; gap: var(--s-3); min-width: 0; }
  .spacer { flex: 1 1 auto; }
  .truncate { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; min-width: 0; }
  .cq { container-type: inline-size; }
  .divider-v { width: 1px; align-self: stretch; background: var(--line-1); }
}

@layer utilities {
  .visually-hidden, .sr-only {
    position: absolute !important; /* sanctioned: must never be overridden into view */
    width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden;
    clip: rect(0 0 0 0); clip-path: inset(50%); white-space: nowrap; border: 0;
  }
  .no-wrap { white-space: nowrap; }
  .align-right { text-align: right; }
  .mt-0 { margin-top: 0; }
}

/* ---- Motion preferences ---------------------------------------------------
   Reduced motion: movement becomes a short crossfade; nothing loops except
   nothing. JS reads core/motion.js `reducedMotion` for its own animations. */
@media (prefers-reduced-motion: reduce) {
  :root {
    --dur-sheet: 160ms;
    --dur-3: 160ms;
    --dur-2: 140ms;
    --ease-spring: var(--ease-out);
  }
  *, *::before, *::after {
    animation-duration: 1ms !important;   /* sanctioned: OS-level accessibility override */
    animation-iteration-count: 1 !important;
    scroll-behavior: auto !important;
  }
}
:root[data-motion="reduce"] {
  --dur-sheet: 160ms;
  --dur-3: 160ms;
  --dur-2: 140ms;
  --ease-spring: var(--ease-out);
}
:root[data-motion="reduce"] *, :root[data-motion="reduce"] *::before, :root[data-motion="reduce"] *::after {
  animation-duration: 1ms !important;
  animation-iteration-count: 1 !important;
}

/* ---- Print: editorial black-on-white, no chrome ------------------------- */
@media print {
  :root, :root[data-theme] {
    --bg: #fff; --surface-1: #fff; --surface-2: #fff; --surface-3: #fff; --surface-sunken: #fff;
    --ink-1: #000; --ink-2: #1a1a1a; --ink-3: #444; --ink-4: #555;
    --line-1: #ccc; --line-2: #bbb; --line-3: #999;
    --accent: #6b4200; --live: #005a60; --up: #0b5e36; --down: #a1141b; --warn: #7a3d00; --model: #5c2a85;
    color-scheme: light;
  }
  html, body { background: #fff; }
  .no-print, [data-print="hide"] { display: none !important; }
  a[href^="http"]::after { content: " (" attr(href) ")"; font-size: 0.8em; color: #555; word-break: break-all; }
  .card, section { break-inside: avoid; }
}
