/* ═══════════════════════════════════════════════════════════════
   E/M FIELD STUDY — cyberbrutalist dark design system
   Type: Clash Display (display) · Satoshi (body) · JetBrains Mono
   Palette: void black · bone white · field cyan (E) · field magenta (B)
   ═══════════════════════════════════════════════════════════════ */

:root {
  /* surfaces */
  --color-bg: #08080a;
  --color-surface: #0e0e12;
  --color-surface-2: #14141a;
  --color-border: rgba(242, 242, 238, 0.14);
  --color-border-strong: rgba(242, 242, 238, 0.3);

  /* text */
  --color-text: #f2f2ee;
  --color-text-muted: #9b9ba4;
  --color-text-faint: #5c5c66;

  /* field accents — E is cyan, B is magenta, signal is acid */
  --color-e: #00e5ff;
  --color-b: #ff2e88;
  --color-signal: #d9ff3d;

  /* type */
  --font-display: 'Clash Display', 'Arial Narrow', sans-serif;
  --font-body: 'Satoshi', 'Helvetica Neue', sans-serif;
  --font-mono: 'JetBrains Mono', 'Courier New', monospace;

  --text-xs: clamp(0.75rem, 0.7rem + 0.25vw, 0.875rem);
  --text-sm: clamp(0.875rem, 0.82rem + 0.3vw, 1rem);
  --text-base: clamp(1rem, 0.95rem + 0.25vw, 1.125rem);
  --text-lg: clamp(1.125rem, 1rem + 0.75vw, 1.5rem);
  --text-xl: clamp(1.5rem, 1.2rem + 1.25vw, 2.25rem);
  --text-2xl: clamp(2rem, 1.2rem + 2.5vw, 3.5rem);
  --text-3xl: clamp(2.5rem, 1rem + 4vw, 5rem);
  --text-hero: clamp(3.2rem, 0.4rem + 11.5vw, 10.5rem);

  /* spacing (4px base) */
  --space-1: 0.25rem; --space-2: 0.5rem; --space-3: 0.75rem; --space-4: 1rem;
  --space-5: 1.25rem; --space-6: 1.5rem; --space-8: 2rem; --space-10: 2.5rem;
  --space-12: 3rem; --space-16: 4rem; --space-20: 5rem; --space-24: 6rem;
  --space-32: 8rem;

  /* cyberbrutalism = sharp corners, hard offset shadows */
  --radius: 0;
  --ease-out: cubic-bezier(0.16, 1, 0.3, 1);
  --ease-in: cubic-bezier(0.4, 0, 1, 1);
  --transition-interactive: 180ms cubic-bezier(0.16, 1, 0.3, 1);

  --content-default: 1100px;
  --content-wide: 1400px;
  --gutter: clamp(1.25rem, 4vw, 4rem);
}

/* ── base ─────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html {
  -webkit-text-size-adjust: none; text-size-adjust: none;
  -webkit-font-smoothing: antialiased; -moz-osx-font-smoothing: grayscale;
  text-rendering: optimizeLegibility;
  scroll-behavior: smooth;
  scroll-padding-top: var(--space-16);
  overflow-x: clip;
}

body {
  min-height: 100dvh;
  line-height: 1.6;
  font-family: var(--font-body);
  font-size: var(--text-base);
  color: var(--color-text);
  background: var(--color-bg);
}

/* faint blueprint grid over the void */
body::before {
  content: '';
  position: fixed; inset: 0;
  background-image:
    repeating-linear-gradient(to right, rgba(242,242,238,0.03) 0 1px, transparent 1px 96px),
    repeating-linear-gradient(to bottom, rgba(242,242,238,0.03) 0 1px, transparent 1px 96px);
  pointer-events: none;
  z-index: 1;
}

img, svg, canvas { display: block; max-width: 100%; }
ul[role='list'] { list-style: none; }
input, button, select { font: inherit; color: inherit; }

h1, h2, h3, h4 { text-wrap: balance; line-height: 1.08; font-family: var(--font-display); font-weight: 600; }
p, li, figcaption { text-wrap: pretty; }

::selection { background: var(--color-e); color: #050507; }

:focus-visible {
  outline: 2px solid var(--color-e);
  outline-offset: 2px;
}

.mono { font-family: var(--font-mono); font-weight: 500; letter-spacing: 0.04em; }

.skip-link {
  position: fixed; top: -100px; left: var(--space-4); z-index: 200;
  background: var(--color-e); color: #050507;
  padding: var(--space-3) var(--space-4);
  font-family: var(--font-mono); font-size: var(--text-sm); text-decoration: none;
  transition: top var(--transition-interactive);
}
.skip-link:focus { top: var(--space-4); }

/* ── WebGL stage ──────────────────────────────────────────────── */
#gl {
  position: fixed; inset: 0; z-index: 0;
  pointer-events: none;
}
#gl-canvas { width: 100%; height: 100%; }
#webgl-fail {
  position: fixed; inset: auto 0 0 0; z-index: 2;
  padding: var(--space-3) var(--space-4);
  background: var(--color-surface); border-top: 2px solid var(--color-b);
  font-family: var(--font-mono); font-size: var(--text-xs); color: var(--color-text-muted);
}
.scanlines {
  position: fixed; inset: 0; z-index: 2; pointer-events: none; opacity: 0.5;
  background: repeating-linear-gradient(to bottom, rgba(0,0,0,0.22) 0 1px, transparent 1px 3px);
  mix-blend-mode: multiply;
}
.vignette {
  position: fixed; inset: 0; z-index: 2; pointer-events: none;
  background: radial-gradient(ellipse at center, transparent 64%, rgba(4,4,6,0.5) 100%);
}

/* ── custom cursor ────────────────────────────────────────────── */
.cursor { position: fixed; inset: 0; z-index: 120; pointer-events: none; display: none; }
@media (hover: hover) and (pointer: fine) {
  .cursor { display: block; }
  body { cursor: none; }
  a, button, input, [data-hover] { cursor: none; }
}
.cursor-dot {
  position: absolute; top: 0; left: 0; width: 7px; height: 7px;
  background: var(--color-e);
  transform: translate(-50%, -50%);
  mix-blend-mode: difference;
}
.cursor-ring {
  position: absolute; top: 0; left: 0; width: 38px; height: 38px;
  border: 1px solid rgba(242,242,238,0.85);
  transform: translate(-50%, -50%);
  transition: width 220ms var(--ease-out), height 220ms var(--ease-out),
              border-color 220ms var(--ease-out), background-color 220ms var(--ease-out);
}
.cursor.is-hover .cursor-ring {
  width: 64px; height: 64px;
  border-color: var(--color-e);
  background: rgba(0,229,255,0.08);
}
.cursor.is-down .cursor-ring { width: 26px; height: 26px; border-color: var(--color-b); }
.cursor-ripple {
  position: absolute; top: 0; left: 0; width: 14px; height: 14px;
  border: 2px solid var(--color-e);
  transform: translate(-50%, -50%) scale(0);
  animation: ripple 650ms var(--ease-out) forwards;
}
@keyframes ripple {
  to { transform: translate(-50%, -50%) scale(9); opacity: 0; }
}

/* ── header ───────────────────────────────────────────────────── */
.site-header {
  position: fixed; top: 0; left: 0; right: 0; z-index: 100;
  display: flex; align-items: center; justify-content: space-between;
  padding: var(--space-4) var(--gutter);
  background: linear-gradient(to bottom, rgba(8,8,10,0.88), rgba(8,8,10,0.55));
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--color-border);
}
.progress {
  position: absolute; top: 0; left: 0; right: 0; height: 3px;
  background: rgba(242,242,238,0.06);
}
.progress span {
  display: block; height: 100%; width: 0;
  background: linear-gradient(to right, var(--color-e), var(--color-b));
}
.brand {
  display: flex; align-items: center; gap: var(--space-3);
  color: var(--color-text); text-decoration: none;
}
.brand-mark { color: var(--color-e); }
.brand-name {
  font-family: var(--font-display); font-weight: 700; font-size: var(--text-lg);
  letter-spacing: 0.02em;
}
.brand-sub { font-family: var(--font-mono); font-size: var(--text-xs); color: var(--color-text-faint); margin-left: var(--space-2); letter-spacing: 0.12em; }

.site-nav { display: flex; gap: clamp(var(--space-2), 1.5vw, var(--space-6)); }
.site-nav a {
  font-family: var(--font-mono); font-size: var(--text-xs);
  color: var(--color-text-muted); text-decoration: none;
  padding: var(--space-2) var(--space-1);
  border-bottom: 2px solid transparent;
  transition: color var(--transition-interactive), border-color var(--transition-interactive);
}
.site-nav a span { margin-left: 0.4em; }
.site-nav a:hover, .site-nav a:focus-visible { color: var(--color-text); }
.site-nav a.is-active { color: var(--color-e); border-color: var(--color-e); }
@media (max-width: 900px) { .site-nav a span { display: none; } .brand-sub { display: none; } }

/* chapter rail — right edge markers */
.chapter-rail {
  position: fixed; right: var(--space-4); top: 50%; translate: 0 -50%;
  z-index: 90; display: flex; flex-direction: column; gap: var(--space-3);
}
.chapter-rail a {
  font-family: var(--font-mono); font-size: var(--text-xs);
  color: var(--color-text-faint); text-decoration: none;
  text-align: right; padding: var(--space-1) 0;
  transition: color var(--transition-interactive);
}
.chapter-rail a i { font-style: normal; }
.chapter-rail a:hover, .chapter-rail a:focus-visible { color: var(--color-text); }
.chapter-rail a.is-active { color: var(--color-e); }
@media (max-width: 900px) { .chapter-rail { display: none; } }

/* ── hero ─────────────────────────────────────────────────────── */
.hero {
  position: relative; z-index: 3;
  min-height: 100svh;
  display: flex; flex-direction: column; justify-content: center;
  padding: calc(var(--space-24) + var(--space-8)) var(--gutter) var(--space-16);
}
.hero-eyebrow { display: flex; gap: var(--space-3); flex-wrap: wrap; margin-bottom: var(--space-6); }
.tag {
  font-family: var(--font-mono); font-size: var(--text-xs);
  padding: var(--space-2) var(--space-3);
  border: 1px solid var(--color-e); color: var(--color-e);
  background: rgba(0,229,255,0.06);
}
.tag-dim { border-color: var(--color-border-strong); color: var(--color-text-muted); background: transparent; }

.hero-title { font-size: var(--text-hero); font-weight: 700; text-transform: uppercase; letter-spacing: -0.02em; }
.hero-title .line { display: block; overflow: hidden; padding-right: 0.05em; }
.line-outline {
  color: transparent;
  -webkit-text-stroke: 2px var(--color-text);
}
.hero-title .char {
  display: inline-block;
  transform: translateY(110%) rotate(4deg);
  opacity: 0;
}
.hero-title .char.char-in {
  transform: translateY(0) rotate(0deg);
  opacity: 1;
  transition: transform 900ms var(--ease-out), opacity 700ms var(--ease-out);
  transition-delay: calc(var(--ci) * 55ms);
}
.line-outline .char.char-in { transition-delay: calc(360ms + var(--ci) * 55ms); }

/* scroll-linked kinetic drift where supported */
@supports (animation-timeline: view()) {
  .hero-title { animation: hero-drift linear both; animation-timeline: view(); animation-range: exit 0% exit 100%; }
  @keyframes hero-drift {
    to { transform: translateY(-14vh) skewY(-2.5deg); opacity: 0.08; }
  }
  .hero .hero-foot, .hero .scroll-cue {
    animation: fade-away linear both; animation-timeline: view(); animation-range: exit 0% exit 60%;
  }
  @keyframes fade-away { to { opacity: 0; } }
}

.hero-foot {
  margin-top: var(--space-10);
  display: grid; grid-template-columns: minmax(0, 1.2fr) minmax(0, 1fr);
  gap: var(--space-8);
  align-items: end;
  border-top: 1px solid var(--color-border);
  padding-top: var(--space-6);
}
.hero-sub { max-width: 46ch; color: var(--color-text-muted); font-size: var(--text-lg); line-height: 1.5; }
.hero-by { font-family: var(--font-mono); font-size: var(--text-xs); color: var(--color-text-faint); letter-spacing: 0.06em; }
.hero-by strong { color: var(--color-text); font-weight: 700; }
@media (max-width: 768px) { .hero-foot { grid-template-columns: 1fr; } }

.scroll-cue {
  position: absolute; bottom: var(--space-10); left: var(--gutter);
  display: flex; align-items: center; gap: var(--space-4);
  font-family: var(--font-mono); font-size: var(--text-xs); color: var(--color-text-muted);
  letter-spacing: 0.14em;
}
.cue-arrow { display: inline-block; animation: cue 1.6s var(--ease-out) infinite; color: var(--color-e); }
@keyframes cue { 0%,100% { transform: translateY(0); } 50% { transform: translateY(7px); } }

/* ── ticker ───────────────────────────────────────────────────── */
.ticker {
  position: relative; z-index: 3;
  border-block: 1px solid var(--color-border);
  background: var(--color-surface);
  display: flex; overflow: hidden;
  padding: var(--space-3) 0;
}
.ticker-track {
  display: flex; gap: var(--space-8); align-items: center;
  flex-shrink: 0; min-width: 100%;
  justify-content: space-around;
  font-family: var(--font-mono); font-size: var(--text-xs);
  color: var(--color-text-muted); white-space: nowrap;
  animation: ticker 36s linear infinite;
}
.tick-sep { color: var(--color-b); }
@keyframes ticker { to { transform: translateX(-100%); } }

/* ── chapters: shared ──────────────────────────────────────────── */
.chapter { position: relative; z-index: 3; }
.container { max-width: var(--content-default); margin-inline: auto; padding-inline: var(--gutter); }

.chapter-head { margin-bottom: var(--space-12); }
.chapter-index {
  font-size: var(--text-xs); color: var(--color-e);
  border: 1px solid var(--color-e); display: inline-block;
  padding: var(--space-2) var(--space-3); margin-bottom: var(--space-6);
  background: rgba(0,229,255,0.06);
}
.chapter-title {
  font-size: clamp(var(--text-2xl), 1rem + 5.5vw, var(--text-3xl));
  text-transform: uppercase; letter-spacing: -0.01em;
}
.chapter-title .line { display: inline-block; overflow: hidden; vertical-align: bottom; padding-right: 0.06em; }
.chapter-title .char {
  display: inline-block;
  transform: translateY(110%);
}
.chapter-title .char.char-in {
  transform: translateY(0);
  transition: transform 750ms var(--ease-out);
  transition-delay: calc(var(--ci) * 34ms);
}

/* reveal system — opacity/clip only, no CLS */
.reveal { opacity: 0; }
.reveal.reveal-in { opacity: 1; transition: opacity 800ms var(--ease-out); }

/* ── CH.00 intro ──────────────────────────────────────────────── */
/* legibility scrim painted in-box — backgrounds can't cause overflow */
.chapter-intro, .chapter-colophon {
  background:
    radial-gradient(closest-side, rgba(8,8,10,0.72) 0%, rgba(8,8,10,0.35) 68%, transparent 100%)
    42% 48% / 105% 105% no-repeat;
}
.chapter-intro { padding: clamp(var(--space-24), 14vh, var(--space-32)) 0; }
.chapter-intro .container, .chapter-colophon .container { max-width: 840px; }
.intro-grid {
  display: grid; grid-template-columns: minmax(0, 1.15fr) minmax(0, 1fr);
  gap: var(--space-12); align-items: start;
}
.lede {
  font-family: var(--font-display); font-weight: 500;
  font-size: clamp(var(--text-xl), 1rem + 2vw, var(--text-2xl));
  line-height: 1.3; max-width: 24ch;
}
.lede em { font-style: normal; color: var(--color-e); }
.prose-block p { max-width: 52ch; color: var(--color-text-muted); }
.prose-block p + p { margin-top: var(--space-4); }
.prose-block strong { color: var(--color-text); }
.fact-grid {
  margin-top: var(--space-12);
  display: grid; grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 1px; background: var(--color-border);
  border: 1px solid var(--color-border);
}
.fact { background: var(--color-surface); padding: var(--space-5) var(--space-4); }
.fact dt { color: var(--color-e); font-size: var(--text-lg); margin-bottom: var(--space-2); }
.fact dd { font-size: var(--text-sm); color: var(--color-text-muted); }
@media (max-width: 860px) {
  .intro-grid { grid-template-columns: 1fr; }
  .fact-grid { grid-template-columns: 1fr; }
}

/* ── sticky stages (Maxwell / Lorentz / Fields) ───────────────── */
.chapter-maxwell, .chapter-history { height: 440vh; }
.chapter-lorentz, .chapter-fields { height: 320vh; }
.stage {
  position: sticky; top: 0; height: 100svh;
  display: grid; place-items: center;
  padding: calc(var(--space-16) + var(--space-4)) var(--gutter) var(--space-16);
}
.stage-frame .corner {
  position: absolute; width: 26px; height: 26px;
  border: 0 solid var(--color-border-strong);
}
.stage-frame .tl { top: 18px; left: 18px; border-top-width: 2px; border-left-width: 2px; }
.stage-frame .tr { top: 18px; right: 18px; border-top-width: 2px; border-right-width: 2px; }
.stage-frame .bl { bottom: 18px; left: 18px; border-bottom-width: 2px; border-left-width: 2px; }
.stage-frame .br { bottom: 18px; right: 18px; border-bottom-width: 2px; border-right-width: 2px; }
.stage-label {
  position: absolute; top: calc(var(--space-12) + var(--space-2)); left: var(--gutter);
  font-size: var(--text-xs); color: var(--color-text-faint); letter-spacing: 0.14em;
}
.stage-hud {
  position: absolute; bottom: var(--space-10); left: 50%; transform: translateX(-50%);
  font-size: var(--text-xs); color: var(--color-text-faint); letter-spacing: 0.18em;
  white-space: nowrap;
}
@media (max-width: 640px) { .stage-hud { display: none; } }

/* panels — brutalist cards with hard offset shadows */
.panel {
  position: absolute;
  top: calc(50% + 1.75rem); translate: 0 -50%;
  max-height: calc(100svh - 6.5rem); overflow-y: auto; overscroll-behavior: contain;
  width: min(460px, 100%);
  background: rgba(14,14,18,0.74);
  border: 2px solid var(--color-border-strong);
  box-shadow: 10px 10px 0 rgba(0,229,255,0.16);
  padding: clamp(var(--space-4), 2vw, var(--space-6));
  opacity: 0; visibility: hidden;
  transform: translateY(24px);
  transition: opacity 500ms var(--ease-out), transform 500ms var(--ease-out), visibility 0s 500ms;
  backdrop-filter: blur(4px);
}
.panel.is-active {
  opacity: 1; visibility: visible; transform: translateY(0);
  transition: opacity 500ms var(--ease-out), transform 500ms var(--ease-out), visibility 0s;
}
.panel-step { font-size: var(--text-xs); color: var(--color-b); margin-bottom: var(--space-4); letter-spacing: 0.12em; }
.panel-name {
  font-size: clamp(var(--text-xl), 1rem + 2.4vw, var(--text-2xl));
  text-transform: uppercase; margin-bottom: var(--space-5);
}
.panel-name span { color: var(--color-text-muted); font-weight: 400; }
.equation {
  font-family: var(--font-mono), 'DejaVu Sans Mono', 'STIX Two Math', 'Segoe UI Symbol', monospace; font-weight: 500;
  font-size: clamp(var(--text-xl), 1rem + 2.8vw, var(--text-3xl));
  border-block: 1px solid var(--color-border);
  padding: var(--space-4) 0; margin-bottom: var(--space-5);
  white-space: nowrap; overflow-x: auto;
}
.equation-lg { font-size: clamp(1.4rem, 1rem + 3.2vw, 2.6rem); }
/* the Ampère–Maxwell equation is long — step it down so it never clips */
#maxwell .panel[data-panel="3"] .equation,
#oersted .panel .equation {
  font-size: clamp(0.95rem, 0.72rem + 1.9vw, 1.9rem);
  letter-spacing: -0.01em;
}
.c-e { color: var(--color-e); }
.c-b { color: var(--color-b); }
.panel-copy { color: var(--color-text-muted); font-size: var(--text-base); max-width: 52ch; }
.panel-watch {
  margin-top: var(--space-5); font-size: var(--text-xs);
  color: var(--color-signal); letter-spacing: 0.1em;
}

/* maxwell panels alternate sides */
.chapter-maxwell .panel[data-panel='1'], .chapter-maxwell .panel[data-panel='3'], .chapter-history .panel[data-panel='1'], .chapter-history .panel[data-panel='3'] { margin-left: auto; box-shadow: -10px 10px 0 rgba(255,46,136,0.16); }
@media (max-width: 860px) {
  .chapter-maxwell .panel[data-panel='1'], .chapter-maxwell .panel[data-panel='3'], .chapter-history .panel[data-panel='1'], .chapter-history .panel[data-panel='3'] { margin-left: 0; }
}

/* ── lorentz controls ──────────────────────────────────────────── */
.lorentz-panel { box-shadow: 10px 10px 0 rgba(255,46,136,0.16); }
.controls { margin-top: var(--space-6); display: grid; gap: var(--space-5); }
.control label {
  display: flex; justify-content: space-between; gap: var(--space-4);
  font-size: var(--text-xs); color: var(--color-text-muted);
  margin-bottom: var(--space-3); letter-spacing: 0.08em;
}
.control output { color: var(--color-e); }
input[type='range'] {
  -webkit-appearance: none; appearance: none;
  width: 100%; height: 30px; background: transparent;
  cursor: none;
}
input[type='range']::-webkit-slider-runnable-track {
  height: 4px; background: var(--color-surface-2); border: 1px solid var(--color-border);
}
input[type='range']::-webkit-slider-thumb {
  -webkit-appearance: none; appearance: none;
  width: 18px; height: 18px; margin-top: -8px;
  background: var(--color-e); border: 2px solid var(--color-bg);
  box-shadow: 0 0 0 1px var(--color-e);
}
input[type='range']::-moz-range-track {
  height: 4px; background: var(--color-surface-2); border: 1px solid var(--color-border);
}
input[type='range']::-moz-range-thumb {
  width: 18px; height: 18px; border-radius: 0;
  background: var(--color-e); border: 2px solid var(--color-bg);
  box-shadow: 0 0 0 1px var(--color-e);
}
input[type='range']:focus-visible { outline: 2px solid var(--color-e); outline-offset: 4px; }

.control-row { display: flex; gap: var(--space-3); flex-wrap: wrap; }
.btn-charge, .btn-inject, .btn-flip {
  font-family: var(--font-mono); font-size: var(--text-xs); letter-spacing: 0.1em;
  padding: var(--space-3) var(--space-5); min-height: 44px;
  background: var(--color-surface-2); color: var(--color-text);
  border: 2px solid var(--color-border-strong);
  transition: transform var(--transition-interactive), background var(--transition-interactive),
              border-color var(--transition-interactive), color var(--transition-interactive),
              box-shadow var(--transition-interactive);
}
.btn-charge:hover, .btn-inject:hover, .btn-flip:hover {
  border-color: var(--color-e); color: var(--color-e);
  box-shadow: 4px 4px 0 rgba(0,229,255,0.35);
  transform: translate(-2px, -2px);
}
.btn-charge:active, .btn-inject:active, .btn-flip:active { transform: translate(0, 0); box-shadow: none; }
.btn-charge.is-active { background: var(--color-e); color: #050507; border-color: var(--color-e); }
.btn-charge[data-charge='-1'].is-active { background: var(--color-b); border-color: var(--color-b); }
.btn-inject { border-color: var(--color-b); color: var(--color-b); }
.btn-inject:hover { box-shadow: 4px 4px 0 rgba(255,46,136,0.4); border-color: var(--color-b); color: var(--color-b); }
.readout {
  margin-top: var(--space-5); font-size: var(--text-xs); color: var(--color-text-faint);
  border-top: 1px dashed var(--color-border); padding-top: var(--space-4);
  font-variant-numeric: tabular-nums;
}
.readout span { color: var(--color-signal); }

/* ── fields panel ──────────────────────────────────────────────── */
.fields-panel { box-shadow: 10px 10px 0 rgba(0,229,255,0.16); max-width: 560px; }
.legend {
  margin-top: var(--space-6); display: flex; flex-wrap: wrap; gap: var(--space-4) var(--space-6);
  font-size: var(--text-xs); color: var(--color-text-muted);
}
.legend span { display: inline-flex; align-items: center; gap: var(--space-2); }
.swatch { width: 12px; height: 12px; display: inline-block; }
.swatch-e { background: var(--color-e); }
.swatch-b { background: var(--color-b); }
.swatch-cursor { background: var(--color-signal); box-shadow: 0 0 8px var(--color-signal); }
.btn-flip { margin-top: var(--space-6); border-color: var(--color-signal); color: var(--color-signal); }
.btn-flip:hover { box-shadow: 4px 4px 0 rgba(217,255,61,0.35); }

/* ── colophon ──────────────────────────────────────────────────── */
.chapter-colophon { padding: clamp(var(--space-24), 16vh, var(--space-32)) 0 var(--space-24); text-align: left; }
.chapter-colophon .lede { max-width: 30ch; margin-bottom: var(--space-16); }
.colophon-grid {
  list-style: none;
  display: grid; grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 1px; background: var(--color-border);
  border: 1px solid var(--color-border);
  margin-bottom: var(--space-16);
}
.colophon-grid li {
  background: var(--color-surface); padding: var(--space-6);
  display: grid; gap: var(--space-2);
}
.colophon-grid .mono { font-size: var(--text-xs); color: var(--color-text-faint); letter-spacing: 0.1em; }
.colophon-grid strong { font-family: var(--font-display); font-weight: 500; font-size: var(--text-lg); }
@media (max-width: 700px) { .colophon-grid { grid-template-columns: 1fr; } }

.btn-top {
  display: inline-flex; align-items: center; gap: var(--space-4);
  color: var(--color-text); text-decoration: none;
  border: 2px solid var(--color-border-strong);
  padding: var(--space-4) var(--space-6);
  font-size: var(--text-xs);
  transition: border-color var(--transition-interactive), box-shadow var(--transition-interactive),
              transform var(--transition-interactive);
}
.btn-top:hover {
  border-color: var(--color-e);
  box-shadow: 6px 6px 0 rgba(0,229,255,0.35);
  transform: translate(-3px, -3px);
}
.btn-top .cue-arrow { color: var(--color-e); }

.site-footer {
  position: relative; z-index: 3;
  border-top: 1px solid var(--color-border);
  padding: var(--space-6) var(--gutter);
  display: flex; justify-content: center;
}
.site-footer p { font-size: var(--text-xs); color: var(--color-text-faint); letter-spacing: 0.1em; }

/* ── reduced motion ───────────────────────────────────────────── */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
    scroll-behavior: auto !important;
  }
  .hero-title .char, .chapter-title .char { transform: none; opacity: 1; }
  .reveal { opacity: 1; }
  .panel { opacity: 0; }
  .panel.is-active { opacity: 1; }
}

/* ── small screens: compact panels that clear the fixed header ── */
@media (max-width: 640px) {
  .panel { padding: var(--space-4); box-shadow: 6px 6px 0 rgba(0,229,255,0.16); top: calc(50% + 2.25rem); max-height: calc(100svh - 7rem); }
  .panel-step { margin-bottom: var(--space-2); }
  .panel-name { margin-bottom: var(--space-3); }
  .equation { padding: var(--space-3) 0; margin-bottom: var(--space-3); }
  .panel-copy { font-size: var(--text-sm); line-height: 1.5; }
  .panel-watch { margin-top: var(--space-3); }
  .controls { margin-top: var(--space-4); gap: var(--space-3); }
  .readout { margin-top: var(--space-3); padding-top: var(--space-3); }
  .legend { margin-top: var(--space-4); gap: var(--space-2) var(--space-4); }
  .btn-flip { margin-top: var(--space-4); }
  .stage-label { top: calc(var(--space-16) + var(--space-2)); }
}

/* ═══════════════════════════════════════════════════════════════
   UPGRADE PASS — preloader · sound · spectrum · HUD
   ═══════════════════════════════════════════════════════════════ */

/* ── preloader ────────────────────────────────────────────────── */
html.is-loading { overflow: hidden; }
.preloader {
  position: fixed; inset: 0; z-index: 300;
  background: var(--color-bg);
  display: grid; place-items: center;
  color: var(--color-e);
  transition: transform 700ms var(--ease-in);
}
.preloader.pre-done { transform: translateY(-101%); }
.pre-inner { text-align: center; display: grid; gap: var(--space-4); justify-items: center; padding: var(--space-4); }
.pre-mark { color: var(--color-e); }
.pre-log { font-size: var(--text-xs); color: var(--color-text-muted); letter-spacing: 0.22em; min-height: 1.5em; }
.pre-count {
  font-family: var(--font-display); font-weight: 700;
  font-size: clamp(4rem, 16vw, 9rem); line-height: 1;
  color: var(--color-text); font-variant-numeric: tabular-nums;
}
.pre-eq { font-size: var(--text-xs); color: var(--color-text-faint); max-width: min(560px, 90vw); }
.pre-bar {
  position: absolute; bottom: 0; left: 0; right: 0; height: 4px;
  background: rgba(242,242,238,0.08);
}
.pre-bar span {
  display: block; height: 100%; width: 100%;
  background: linear-gradient(to right, var(--color-e), var(--color-b));
  transform: scaleX(0); transform-origin: left;
}

/* ── sound toggle ─────────────────────────────────────────────── */
.btn-sound {
  font-size: var(--text-xs); letter-spacing: 0.1em;
  padding: var(--space-2) var(--space-3); min-height: 44px;
  color: var(--color-text-muted);
  border: 1px solid var(--color-border-strong);
  background: transparent;
  transition: color var(--transition-interactive), border-color var(--transition-interactive), background var(--transition-interactive);
}
.btn-sound:hover { color: var(--color-e); border-color: var(--color-e); }
.btn-sound[aria-pressed='true'] { color: var(--color-e); border-color: var(--color-e); background: rgba(0,229,255,0.08); }

/* ── scroll readout HUD ───────────────────────────────────────── */
.scroll-readout {
  position: fixed; bottom: var(--space-4); left: var(--gutter); z-index: 90;
  font-size: var(--text-xs); color: var(--color-text-faint);
  letter-spacing: 0.14em; pointer-events: none;
  font-variant-numeric: tabular-nums;
}
#scroll-pct { color: var(--color-e); }
@media (max-width: 900px) { .scroll-readout { display: none; } }

/* ── chapter flash (subtle scanline pulse) ────────────────────── */
.scanlines { transition: opacity 200ms linear; }
.chapter-flash .scanlines { opacity: 0.9; }
@media (prefers-reduced-motion: reduce) { .chapter-flash .scanlines { opacity: 0.5; } }

/* ── scroll-velocity skew — headings only, never panels ────────── */
.chapter-title, .lede, .panel-name { transform: skewY(var(--skew, 0deg)); }

/* ── nav links need a box for the magnet transform ────────────── */
.site-nav a { display: inline-block; }

/* ── EM spectrum strip ────────────────────────────────────────── */
.spectrum { margin-bottom: var(--space-16); }
.spectrum-head {
  font-size: var(--text-xs); color: var(--color-text-muted);
  letter-spacing: 0.16em; margin-bottom: var(--space-4);
}
.spectrum-bar {
  display: flex; gap: 2px;
  border: 1px solid var(--color-border-strong);
}
.spectrum-bar button {
  flex: 1; min-height: 64px; min-width: 0;
  font-family: var(--font-mono); font-size: var(--text-xs); font-weight: 500;
  letter-spacing: 0.06em; color: rgba(242,242,238,0.85);
  padding: var(--space-2) var(--space-1);
  transition: filter var(--transition-interactive), outline-color var(--transition-interactive);
  outline: 2px solid transparent; outline-offset: -2px;
}
.spectrum-bar button:hover, .spectrum-bar button:focus-visible { filter: brightness(1.6); outline-color: var(--color-e); }
.spectrum-bar button:nth-child(1) { background: #14141c; }
.spectrum-bar button:nth-child(2) { background: #241d33; }
.spectrum-bar button:nth-child(3) { background: #3d2140; }
.spectrum-bar button:nth-child(4) {
  background: linear-gradient(90deg, #d0342c, #d98e2b, #cdd93a, #3ad97e, #2bd0cd, #3a6bd9, #8c3ad9);
  color: #0a0a0e; font-weight: 700;
}
.spectrum-bar button:nth-child(5) { background: #3b2f86; }
.spectrum-bar button:nth-child(6) { background: #6b2f86; }
.spectrum-bar button:nth-child(7) { background: #b32d6e; }
.spectrum-out {
  margin-top: var(--space-4); font-size: var(--text-xs);
  color: var(--color-signal); letter-spacing: 0.08em; min-height: 1.5em;
}
@media (max-width: 700px) {
  .spectrum-bar { flex-wrap: wrap; }
  .spectrum-bar button { flex: 1 1 24%; }
  .spectrum-bar button:nth-child(4) { flex: 1 1 48%; }
}

.lede, .prose-block p, .fact dd, .fact dt, .spectrum-out, .colophon-grid strong {
  text-shadow: 0 1px 3px rgba(0,0,0,0.85), 0 0 14px rgba(0,0,0,0.45);
}

/* hero foot legibility over the bright wave core on small screens */
@media (max-width: 640px) {
  .hero-foot {
    background: linear-gradient(to bottom, rgba(8,8,10,0.22), rgba(8,8,10,0.5));
    padding: var(--space-5) var(--space-4) var(--space-6);
    margin-inline: calc(var(--gutter) * -1);
    backdrop-filter: blur(3px);
  }
}

/* hero title fits one line per word on small screens */
@media (max-width: 480px) {
  .hero-title { font-size: clamp(2.4rem, 11vw, 3rem); }
}

/* ── modo imersivo — só o campo, zero texto ──────────────────── */
main {
  transition: opacity 500ms var(--ease-out), transform 500ms var(--ease-out);
  will-change: opacity, transform;
}
.ticker, .site-footer, .scroll-readout, .site-nav, .chapter-rail, .site-header {
  transition: opacity 450ms var(--ease-out);
}
body.immersive main {
  opacity: 0; pointer-events: none;
  transform: scale(0.985);
}
.btn-immersive {
  position: fixed; bottom: var(--space-4); right: var(--space-4); z-index: 110;
  font-size: var(--text-xs); letter-spacing: 0.1em;
  padding: var(--space-3) var(--space-4); min-height: 44px;
  color: var(--color-signal);
  border: 2px solid var(--color-signal);
  background: rgba(8,8,10,0.72);
  backdrop-filter: blur(4px);
  transition: background var(--transition-interactive), box-shadow var(--transition-interactive), transform var(--transition-interactive);
}
.btn-immersive:hover {
  box-shadow: 4px 4px 0 rgba(217,255,61,0.35);
  transform: translate(-2px, -2px);
}
.btn-immersive:active { transform: translate(0, 0); box-shadow: none; }
.btn-immersive[aria-pressed='true'] { color: #0a0a0e; background: var(--color-signal); }

body.immersive main,
body.immersive .ticker,
body.immersive .site-footer,
body.immersive .scroll-readout { opacity: 0; pointer-events: none; }
body.immersive .site-nav, body.immersive .chapter-rail { opacity: 0.2; }
body.immersive .site-header {
  background: transparent;
  border-bottom-color: transparent;
  backdrop-filter: none;
}
body.immersive .vignette { opacity: 0.4; }
body.immersive .stage-hud { display: block; }
body:not(.immersive) .stage-hud { display: none; }
body.immersive { touch-action: pan-y; }

/* HUD imersivo — canto inferior esquerdo */
.im-hud {
  position: fixed; inset-inline: var(--gutter); bottom: var(--space-4); z-index: 105;
  pointer-events: none; opacity: 0; visibility: hidden;
  transition: opacity 500ms var(--ease-out) 150ms, visibility 0s 650ms;
}
body.immersive .im-hud {
  opacity: 1; visibility: visible;
  transition: opacity 500ms var(--ease-out) 350ms, visibility 0s;
}
.im-chapter {
  font-size: var(--text-xs); letter-spacing: 0.16em;
  color: var(--color-e);
  text-shadow: 0 0 14px rgba(0,229,255,0.5);
}
.im-chapter::before {
  content: ''; display: inline-block; width: 10px; height: 10px;
  margin-right: var(--space-3); background: var(--color-e);
  animation: im-blink 2.4s steps(1) infinite;
}
@keyframes im-blink { 0%, 70% { opacity: 1; } 70.1%, 100% { opacity: 0.25; } }
.im-hint {
  position: absolute; bottom: 0; left: 50%; translate: -50% 0;
  white-space: nowrap; font-size: 10px; letter-spacing: 0.12em;
  color: var(--color-text-faint);
  opacity: 0; transition: opacity 700ms var(--ease-out);
}
body.immersive .im-hint { opacity: 0.85; }
body.immersive .im-hint.is-gone { opacity: 0; }
@media (max-width: 900px) {
  .im-hint { display: none; }
}
@media (prefers-reduced-motion: reduce) {
  body.immersive main { transform: none; }
  .im-chapter::before { animation: none; }
}
