/* Phantom — editorial CSS, dark default. */
:root {
  --bg: #0a0d12;
  --bg-2: #0e1219;
  --surface: #131821;
  --surface-2: #1b2230;
  --line: #232a3a;
  --line-soft: #1a2030;

  --text: #ecedf0;
  --text-mid: #b6bbc7;
  --text-dim: #7c8493;
  --inverse: #0a0d12;

  --accent: #ffb547;
  --accent-2: #7dd3fc;
  --warn: #ff7a8a;
  --jam: #ff5d6a;
  --free: #6ee7a0;
  --slow: #ffb547;

  --focus: #ffffff;

  --font-sans: "Inter", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --font-display: "Fraunces", Georgia, serif;
  --font-mono: "JetBrains Mono", ui-monospace, SFMono-Regular, Menlo, monospace;

  --measure: 64ch;
  --maxw: 1000px;
  --gutter: clamp(20px, 4vw, 56px);
  --t-fast: 150ms;
  --t-mid: 280ms;
  --ease-out: cubic-bezier(0.22, 1, 0.36, 1);
}

*, *::before, *::after { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
html { color-scheme: dark; }
body {
  font-family: var(--font-sans);
  font-size: 17px;
  line-height: 1.65;
  color: var(--text);
  background:
    radial-gradient(900px 400px at 50% -10%, rgba(255,181,71,0.06), transparent 70%),
    linear-gradient(180deg, var(--bg), var(--bg-2));
  background-attachment: fixed;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-rendering: optimizeLegibility;
}
img, svg, canvas { max-width: 100%; display: block; }
button, output { font: inherit; }
button { cursor: pointer; }
:focus { outline: none; }
:focus-visible {
  outline: 2px solid var(--focus);
  outline-offset: 2px;
  border-radius: 3px;
}

.sr-only {
  position: absolute !important;
  width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0,0,0,0); white-space: nowrap; border: 0;
}
.skip-link {
  position: absolute; left: 16px; top: -40px;
  background: var(--surface); color: var(--text);
  border: 1px solid var(--line);
  padding: 10px 16px; border-radius: 8px;
  z-index: 100;
  transition: top var(--t-fast) var(--ease-out);
  font-weight: 600;
}
.skip-link:focus { top: 12px; }
main:focus { outline: none; }
section[id], article[id] { scroll-margin-top: 80px; }

/* TOPBAR */
.topbar {
  position: sticky; top: 0; z-index: 50;
  background: color-mix(in oklab, var(--bg) 85%, transparent);
  backdrop-filter: saturate(140%) blur(10px);
  border-bottom: 1px solid var(--line);
}
.topbar-inner {
  max-width: var(--maxw); margin: 0 auto;
  padding: 14px var(--gutter);
  display: flex; align-items: center; gap: 16px;
}
.mark {
  display: inline-flex; align-items: center; gap: 10px;
  color: var(--text); text-decoration: none; font-weight: 700;
}
.mark:hover { color: var(--accent); }
.mark-glyph {
  font-family: var(--font-display);
  font-size: 24px;
  color: var(--accent);
  line-height: 1;
  width: 1em; text-align: center;
}
.mark-text { font-family: var(--font-display); font-size: 18px; letter-spacing: -0.01em; }
.topbar-meta { margin: 0 0 0 auto; color: var(--text-dim); font-family: var(--font-mono); font-size: 12px; }
.rm-btn {
  margin-left: 12px;
  padding: 6px 12px; min-height: 32px;
  background: transparent; color: var(--text-mid);
  border: 1px solid var(--line); border-radius: 999px;
  font-size: 12px; font-family: var(--font-mono);
  letter-spacing: 0.04em;
  transition: var(--t-fast);
}
.rm-btn:hover { color: var(--text); border-color: var(--accent); }
.rm-btn[aria-pressed="true"] { background: var(--accent); color: var(--inverse); border-color: var(--accent); }

/* HERO */
.hero {
  position: relative;
  padding: 110px var(--gutter) 70px;
  max-width: var(--maxw); margin: 0 auto;
  isolation: isolate;
}
.hero-grid {
  position: absolute; inset: 0; z-index: -1;
  background-image:
    linear-gradient(var(--line-soft) 1px, transparent 1px),
    linear-gradient(90deg, var(--line-soft) 1px, transparent 1px);
  background-size: 64px 64px;
  mask-image: radial-gradient(ellipse 60% 70% at 30% 30%, black 30%, transparent 70%);
  opacity: 0.4;
}
.kicker {
  font-family: var(--font-mono); font-size: 12px;
  text-transform: uppercase; letter-spacing: 0.18em;
  color: var(--text-dim); margin: 0 0 20px;
}
.hero h1 {
  font-family: var(--font-display);
  font-weight: 700; font-style: italic;
  font-size: clamp(38px, 7vw, 74px);
  line-height: 1.04;
  letter-spacing: -0.025em;
  margin: 0 0 24px;
  max-width: 16ch;
}
.hero-lede {
  font-family: var(--font-display);
  font-weight: 400;
  font-size: clamp(19px, 2.2vw, 24px);
  line-height: 1.5;
  color: var(--text-mid);
  max-width: 56ch;
  margin: 0 0 16px;
}
.hero-meta {
  font-family: var(--font-mono); font-size: 13px;
  color: var(--text-dim);
  margin: 0 0 32px;
  max-width: 60ch;
}
.cta {
  display: inline-flex; align-items: center; gap: 10px;
  padding: 14px 22px; min-height: 48px;
  background: var(--accent); color: var(--inverse);
  font-weight: 700; text-decoration: none;
  border-radius: 999px;
  box-shadow: 0 0 0 1px rgba(255,181,71,0.4), 0 14px 40px -10px rgba(255,181,71,0.35);
  transition: transform var(--t-fast) var(--ease-out), background var(--t-fast);
}
.cta:hover { transform: translateY(-2px); background: #ffc66e; }
.cta::after { content: "→"; font-weight: 400; }

/* ARTICLE */
.part {
  max-width: var(--maxw); margin: 0 auto;
  padding: 72px var(--gutter);
  border-top: 1px solid var(--line);
}
.part-head { margin: 0 0 28px; }
.part-num {
  font-family: var(--font-mono); font-size: 12px;
  text-transform: uppercase; letter-spacing: 0.18em;
  color: var(--accent);
  margin: 0 0 12px;
}
.part-head h2 {
  font-family: var(--font-display);
  font-weight: 700; font-style: italic;
  font-size: clamp(30px, 5vw, 48px);
  line-height: 1.05;
  letter-spacing: -0.02em;
  margin: 0;
  max-width: 22ch;
}

.prose { max-width: var(--measure); margin: 0 0 28px; }
.prose p { margin: 0 0 18px; font-size: 18px; line-height: 1.7; color: var(--text); }
.prose p:last-child { margin-bottom: 0; }
.prose code {
  font-family: var(--font-mono); font-size: 0.94em;
  background: var(--surface-2);
  border: 1px solid var(--line);
  color: var(--accent);
  padding: 1px 6px; border-radius: 4px;
}
.prose em { font-family: var(--font-display); font-style: italic; }
.prose sub { font-size: 0.72em; }

.rule-list {
  margin: 0 0 24px;
  padding-left: 22px;
  color: var(--text);
}
.rule-list li { margin: 8px 0; font-size: 17px; line-height: 1.65; }
.rule-list strong { color: var(--accent); }

/* STAGE */
.stage {
  margin: 28px 0;
  padding: 22px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 12px;
  box-shadow: 0 14px 40px -22px rgba(0,0,0,0.6);
}
.stage-title {
  font-family: var(--font-mono);
  font-size: 12px;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--text-dim);
  margin: 0 0 16px;
  padding-bottom: 12px;
  border-bottom: 1px solid var(--line-soft);
}
.stage-controls {
  display: flex; flex-wrap: wrap;
  gap: 14px;
  align-items: flex-end;
  margin-bottom: 16px;
}
.walker-controls { gap: 8px; }
.stage-canvas {
  background: var(--bg-2);
  border-radius: 8px;
  padding: 12px;
  border: 1px solid var(--line-soft);
}
.stage-canvas svg, .stage-canvas canvas { width: 100%; height: auto; display: block; }
.ring-canvas { display: flex; justify-content: center; }
.ring-canvas svg { max-width: 360px; max-height: 360px; }
.walker-canvas svg { height: 80px; }
.spacetime-canvas canvas { image-rendering: pixelated; height: auto; max-height: 320px; }
.stage-note {
  font-size: 14px; color: var(--text-mid);
  margin: 14px 0 0; max-width: 80ch;
}

/* CONTROLS */
.control {
  display: flex; flex-direction: column; gap: 6px;
  min-width: 180px; flex: 1 1 200px;
}
.control-label {
  font-family: var(--font-mono);
  font-size: 11px; letter-spacing: 0.06em;
  color: var(--text-dim);
  display: flex; justify-content: space-between;
}
.control-value { color: var(--accent); font-weight: 700; }
.control input[type="range"] {
  -webkit-appearance: none; appearance: none;
  width: 100%; height: 26px;
  background: transparent;
  margin: 0;
}
.control input[type="range"]::-webkit-slider-runnable-track {
  height: 4px; background: var(--surface-2); border-radius: 999px;
}
.control input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none; appearance: none;
  width: 18px; height: 18px;
  border-radius: 50%;
  background: var(--accent);
  border: 2px solid var(--bg-2);
  margin-top: -7px;
}
.control input[type="range"]:focus-visible::-webkit-slider-thumb {
  outline: 2px solid var(--focus); outline-offset: 2px;
}
.control input[type="range"]::-moz-range-track {
  height: 4px; background: var(--surface-2); border-radius: 999px;
}
.control input[type="range"]::-moz-range-thumb {
  width: 18px; height: 18px; border-radius: 50%;
  background: var(--accent); border: 2px solid var(--bg-2);
}

/* BUTTONS */
.btn {
  display: inline-flex; align-items: center; justify-content: center;
  padding: 10px 16px; min-height: 40px;
  background: var(--accent); color: var(--inverse);
  border: 1px solid var(--accent);
  border-radius: 8px;
  font-weight: 600; font-size: 13px;
  letter-spacing: 0.02em;
  transition: transform var(--t-fast) var(--ease-out), background var(--t-fast), color var(--t-fast);
}
.btn:hover { transform: translateY(-1px); background: #ffc66e; }
.btn[aria-disabled="true"] { opacity: 0.55; cursor: not-allowed; transform: none; }
.btn[aria-pressed="true"] { background: var(--accent-2); border-color: var(--accent-2); }
.btn-secondary { background: var(--surface-2); color: var(--text); border-color: var(--line); }
.btn-secondary:hover { background: var(--surface); color: var(--accent); border-color: var(--accent); }
.btn-ghost { background: transparent; color: var(--text-mid); border-color: var(--line); }
.btn-ghost:hover { background: var(--surface-2); color: var(--text); }
.btn-warn { background: var(--warn); color: var(--inverse); border-color: var(--warn); }
.btn-warn:hover { background: #ff96a4; }
.btn-step { background: var(--surface-2); color: var(--text); border-color: var(--accent); }
.btn-step:hover { background: var(--accent); color: var(--inverse); }
.btn-step[aria-disabled="true"] { border-color: var(--line); color: var(--text-dim); }

/* READOUT */
.readout {
  margin: 14px 0 0;
  display: grid; gap: 8px;
  grid-template-columns: repeat(auto-fit, minmax(120px, 1fr));
  padding: 12px;
  background: var(--bg-2);
  border: 1px solid var(--line-soft);
  border-radius: 8px;
}
.readout > div { display: flex; flex-direction: column; gap: 2px; }
.readout dt {
  font-family: var(--font-mono); font-size: 10.5px;
  text-transform: uppercase; letter-spacing: 0.08em;
  color: var(--text-dim);
}
.readout dd {
  margin: 0;
  font-family: var(--font-mono); font-weight: 700;
  font-size: 16px; color: var(--text);
}
.readout output { color: inherit; font: inherit; }
.readout-compact { grid-template-columns: repeat(auto-fit, minmax(100px, 1fr)); padding: 10px; }
.readout-compact dd { font-size: 14px; }
.readout-prose {
  margin: 0;
  font-size: 14px; color: var(--text-mid);
  line-height: 1.55;
  padding: 12px;
  background: var(--bg-2);
  border: 1px solid var(--line-soft);
  border-radius: 8px;
}

.status-line {
  margin: 12px 0 0;
  padding: 10px 12px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-left: 3px solid var(--accent);
  border-radius: 6px;
  font-size: 13px;
  color: var(--text-mid);
  font-family: var(--font-mono);
  letter-spacing: 0.02em;
}
.status-line:empty { display: none; }
.walker-status { font-family: var(--font-sans); font-size: 14px; }

/* PANELS */
.grid-2 {
  display: grid; gap: 14px;
  grid-template-columns: 1fr 1fr;
  margin-top: 14px;
}
@media (max-width: 800px) { .grid-2 { grid-template-columns: 1fr; } }
.stage-panel {
  background: var(--bg-2);
  border: 1px solid var(--line-soft);
  border-radius: 8px;
  padding: 14px;
}
.panel-h {
  margin: 0 0 10px;
  font-family: var(--font-mono);
  font-size: 11px; letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--text-dim);
}

/* RADIO GROUP */
.radio-group {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 14px 16px;
  margin: 0 0 14px;
  background: var(--bg-2);
}
.radio-group legend {
  padding: 0 8px;
  font-family: var(--font-mono); font-size: 11px;
  text-transform: uppercase; letter-spacing: 0.12em;
  color: var(--text-dim);
}
.radio {
  display: flex; align-items: flex-start; gap: 10px;
  padding: 6px 0;
  font-size: 14px; color: var(--text-mid);
  cursor: pointer;
}
.radio input {
  width: 18px; height: 18px;
  accent-color: var(--accent);
  flex-shrink: 0;
  margin-top: 2px;
}
.radio:has(input:checked) span { color: var(--text); }

/* SVG primitives */
.car {
  fill: var(--free);
  stroke: var(--bg-2); stroke-width: 0.6;
  transition: fill 60ms linear;
}
.car.slow { fill: var(--slow); }
.car.jam { fill: var(--jam); stroke: var(--text); stroke-width: 0.8; }
.car-label {
  font-family: var(--font-mono); font-size: 9px; font-weight: 700;
  fill: var(--inverse);
  pointer-events: none;
  text-anchor: middle;
  dominant-baseline: central;
}
.car-label.empty { fill: var(--text-dim); }
.ring-spoke { stroke: var(--line); stroke-width: 0.5; fill: none; }
.ring-track { stroke: var(--line); stroke-width: 36; fill: none; opacity: 0.4; }
.ring-track-outer { stroke: var(--line-soft); stroke-width: 1; fill: none; }
.cell-arc { stroke-linecap: butt; fill: none; }
.cell-arc.empty { stroke: var(--surface-2); }
.cell-arc.free { stroke: var(--free); }
.cell-arc.slow { stroke: var(--slow); }
.cell-arc.jam { stroke: var(--jam); }

/* phase plot */
.phase-grid { stroke: var(--line-soft); stroke-width: 1; }
.phase-axis { stroke: var(--text-dim); stroke-width: 1; }
.phase-dot { fill: var(--accent-2); }
.phase-dot-current { fill: var(--accent); stroke: var(--text); stroke-width: 1; }
.phase-cursor { stroke: var(--accent); stroke-width: 1; stroke-dasharray: 3 3; }
.phase-label { font-family: var(--font-mono); font-size: 10px; fill: var(--text-dim); }
.phase-line { stroke: var(--text-dim); stroke-width: 0.8; stroke-dasharray: 4 4; fill: none; }

/* WALKER linear road */
.walk-cell { fill: var(--surface-2); stroke: var(--line); stroke-width: 0.4; }
.walk-cell.recent { stroke: var(--accent); stroke-width: 1.2; }
.walk-car { fill: var(--free); stroke: var(--bg-2); stroke-width: 0.6; }
.walk-car.slow { fill: var(--slow); }
.walk-car.jam { fill: var(--jam); }
.walk-label {
  font-family: var(--font-mono); font-size: 11px; font-weight: 700;
  fill: var(--inverse); text-anchor: middle; dominant-baseline: central;
}
.walk-tick-label {
  font-family: var(--font-mono); font-size: 10px;
  fill: var(--text-dim);
}

/* COLOPHON */
.colophon {
  max-width: var(--maxw); margin: 0 auto;
  padding: 80px var(--gutter);
  border-top: 1px solid var(--line);
}
.colophon h2 {
  font-family: var(--font-display);
  font-weight: 700; font-style: italic;
  font-size: 28px;
  margin: 0 0 16px;
  color: var(--text);
}
.colophon p {
  max-width: var(--measure);
  color: var(--text-mid);
  font-size: 15px; line-height: 1.7;
  margin: 0 0 14px;
}
.colophon em { font-family: var(--font-display); font-style: italic; color: var(--text); }

.foot {
  padding: 32px var(--gutter);
  border-top: 1px solid var(--line);
  margin-top: 40px;
}
.foot p {
  max-width: var(--maxw); margin: 0 auto;
  font-family: var(--font-mono); font-size: 12px;
  color: var(--text-dim);
}

@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;
  }
}
