/* base.css — reset, layers, fonts, focus, ambient effects, Calm Mode.
   All colours by var(--token) only (check_no_raw_colors). */

/* ── self-hosted fonts (latin subset, OFL — THIRD_PARTY_NOTICES.md) ── */
@font-face {
  font-family: "JetBrains Mono";
  src: url("../assets/fonts/jetbrains-mono-400.woff2") format("woff2");
  font-weight: 400; font-style: normal; font-display: swap;
}
@font-face {
  font-family: "JetBrains Mono";
  src: url("../assets/fonts/jetbrains-mono-700.woff2") format("woff2");
  font-weight: 700; font-style: normal; font-display: swap;
}
@font-face {
  font-family: "VT323";
  src: url("../assets/fonts/vt323-400.woff2") format("woff2");
  font-weight: 400; font-style: normal; font-display: swap;
}
/* R4 royal display faces — display text only, never body (DESIGN §1.2).
   Both self-hosted, subset, SIL OFL 1.1 (THIRD_PARTY_NOTICES.md). */
@font-face {
  font-family: "Cinzel";
  src: url("../assets/fonts/cinzel-600.woff2") format("woff2");
  font-weight: 600; font-style: normal; font-display: swap;
}
@font-face {
  font-family: "Lalezar";
  src: url("../assets/fonts/lalezar-400.woff2") format("woff2");
  font-weight: 400; font-style: normal; font-display: swap;
  unicode-range: U+0600-06FF, U+0750-077F, U+08A0-08FF, U+FB50-FDFF,
                 U+FE70-FEFF, U+200C-200D;
}

/* ── reset ─────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; }
html, body {
  margin: 0; height: 100%;
  background: var(--bg); color: var(--ink);
  font-family: var(--font-mono);
  font-size: var(--fs-lg); line-height: var(--lh-body);
}
body {
  background:
    radial-gradient(circle at 18% 12%, var(--accent-a05), transparent 40%),
    linear-gradient(var(--bg) 0%, var(--bg-2) 100%);
}
button, input, textarea, select { font: inherit; color: inherit; }
a { color: var(--blue); }
h1, h2, h3, h4 { margin: 0 0 var(--sp-2); line-height: var(--lh-tight); }
ul, ol { margin: 0 0 var(--sp-3); padding-inline-start: var(--sp-5); }
table { border-collapse: collapse; width: 100%; }
th, td {
  text-align: start; padding: var(--sp-1) var(--sp-2);
  border-bottom: var(--border-w) solid var(--grid);
}
th {
  color: var(--ink-dim); font-size: var(--fs-xs);
  letter-spacing: var(--tracking-label); text-transform: uppercase;
}

/* ── focus (WCAG 2.4.7) ────────────────────────────────────────── */
:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

/* ── screen-reader-only utility ───────────────────────────────── */
.sr-only {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}

/* ── labels / micro-typography ────────────────────────────────── */
.micro-label {
  font-size: var(--fs-xs); letter-spacing: var(--tracking-label);
  text-transform: uppercase; color: var(--ink-dim);
}
.display-num {
  font-family: var(--font-display); font-size: var(--fs-2xl);
  color: var(--gold-hot);
}

/* ── ambient effects (Kestrel CRT — subordinate, optional, §2.5) ── */
body:not([data-calm="1"]) .fx-scanlines::before {
  content: ""; position: fixed; inset: 0; pointer-events: none;
  z-index: var(--z-toast);
  background: repeating-linear-gradient(
    to bottom, transparent 0 2px, var(--scanline) 2px 3px);
  /* R4: no mix-blend-mode. Multiply over the whole viewport forces a
     full-screen blend every frame the sky moves; a plain low-alpha
     overlay reads the same and composites for free. */
}
body:not([data-calm="1"]) .fx-flicker::after {
  content: ""; position: fixed; inset: 0; pointer-events: none;
  z-index: var(--z-toast);
  background: radial-gradient(ellipse at center,
    transparent 55%, var(--vignette) 100%);
  animation: crown-flicker 7s infinite steps(40);
}
@keyframes crown-flicker {
  0%, 100% { opacity: 1; }
  47% { opacity: .95; } 48% { opacity: .66; } 49% { opacity: 1; }
  73% { opacity: .92; } 74% { opacity: 1; }
}
.grid-bg {
  position: fixed; inset: 0; z-index: 0; pointer-events: none;
  background-image:
    linear-gradient(var(--grid) 1px, transparent 1px),
    linear-gradient(90deg, var(--grid) 1px, transparent 1px);
  background-size: 48px 48px;
}

/* Calm Mode / reduced motion: every ambient animation off with a single
   rule pair (DESIGN §2.4/§2.5). */
[data-calm="1"] .fx-scanlines::before,
[data-calm="1"] .fx-flicker::after,
[data-calm="1"] .grid-bg { display: none; }
[data-calm="1"] * { animation: none !important; transition: none !important; }
@media (prefers-reduced-motion: reduce) {
  .fx-scanlines::before, .fx-flicker::after { display: none; }
  * { animation: none !important; transition: none !important; }
}

/* ── skeletons (deterministic, mulberry32-seeded in JS) ────────── */
.skeleton {
  background: var(--bg-panel);
  border: var(--border-w) solid var(--grid);
  min-height: var(--sp-4);
}

/* ── generic states ───────────────────────────────────────────── */
.empty-state {
  color: var(--ink-dim); text-align: center; padding: var(--sp-6);
}
.error-state { color: var(--red); padding: var(--sp-4); }
.stale-banner {
  background: var(--red-a15); color: var(--accent-hot);
  border: var(--border-w) solid var(--red-a50);
  padding: var(--sp-2) var(--sp-3);
  font-size: var(--fs-sm); letter-spacing: var(--tracking-label);
  text-transform: uppercase;
}
