:root {
  --bg: #0b1222;
  --card: #111a30;
  --fg: #f0ead2;
  --muted: #8b93a7;
  --gold: #f0c06a;
  --gold-deep: #e2ad55;
  --line: rgba(240, 234, 210, 0.13);
  --sans: 'Archivo', system-ui, sans-serif;
  --serif: 'Literata', Georgia, serif;
  --mono: 'Martian Mono', ui-monospace, monospace;
}

* { box-sizing: border-box; }

html { scroll-behavior: smooth; }
html, body {
  margin: 0;
  background: var(--bg);
  color: var(--fg);
  font-family: var(--sans);
  -webkit-font-smoothing: antialiased;
}

/* ---------- hero: the machine fills the first screen ---------- */
.hero {
  --star-tail: 120px;
  position: relative;
  height: 100vh;
  height: 100svh;
  min-height: 700px;
  overflow: hidden;
}
/* Clip sideways only, so the card's shadow can fall softly onto the page
   below instead of being cut off in a hard line. */
@supports (overflow: clip) {
  .hero { overflow: visible; overflow-x: clip; }
}
/* The canvas's tail below the hero is only sky: cover it so a swipe or wheel
   there scrolls the page instead of turning the machine. */
.hero::after {
  content: '';
  position: absolute;
  left: 0;
  right: 0;
  top: 100%;
  height: var(--star-tail);
}

#scene {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  /* Runs on below the hero so the stars can fade out above the title. */
  height: calc(100% + var(--star-tail));
  display: block;
  touch-action: none;
  cursor: grab;
}
#scene:active { cursor: grabbing; }
#scene:focus { outline: none; }
/* The ring goes on the hero: the canvas runs on below it (--star-tail). */
.hero:has(#scene:focus-visible) { outline: 2px solid var(--gold-deep); outline-offset: -6px; }
#scene.hovering { cursor: pointer; }

/* ---------- title ---------- */
.hud-top {
  position: absolute;
  top: 28px;
  left: 32px;
  right: 32px;
  pointer-events: none;
}
.eyebrow {
  font-family: var(--mono);
  font-size: 11px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--gold-deep);
}
.hud-top h1 {
  margin: 10px 0 0;
  font-family: var(--serif);
  font-size: clamp(36px, 5.6vw, 76px);
  font-weight: 800;
  letter-spacing: -0.02em;
  line-height: 1;
  white-space: nowrap;
}
.hud-top h1 .clip { display: inline-block; overflow: hidden; vertical-align: top; padding-bottom: 0.1em; }
.hud-top h1 .ch { display: inline-block; will-change: transform; }
.hud-top h1 .ch.hl { color: var(--gold); }
.tagline {
  margin: 12px 0 0;
  max-width: 34ch;
  font-family: var(--serif);
  font-size: 17px;
  line-height: 1.5;
  color: rgba(240, 234, 210, 0.82);
}

/* ---------- control card ---------- */
.card {
  position: absolute;
  left: 32px;
  bottom: 32px;
  width: 330px;
  padding: 18px;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 14px;
  box-shadow: 0 20px 50px rgba(0, 0, 0, 0.35);
}
.row { display: flex; gap: 10px; }
.btn {
  flex: 1;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  height: 40px;
  border-radius: 999px;
  border: 1.5px solid rgba(240, 234, 210, 0.32);
  background: transparent;
  color: var(--fg);
  font: 700 14px/1 var(--sans);
  cursor: pointer;
  transition: background 0.2s, border-color 0.2s, color 0.2s, transform 0.1s;
}
.btn:hover { border-color: rgba(240, 234, 210, 0.6); }
.btn:active { transform: scale(0.98); }
.btn.on { border-color: var(--gold); color: var(--gold); }
.btn.primary { background: var(--gold); border-color: var(--gold); color: var(--bg); }
.btn.primary:hover { background: #f6cd82; }
.btn.primary.on { background: transparent; color: var(--gold); }
.btn .dot { width: 7px; height: 7px; border-radius: 50%; background: currentColor; }
.btn.primary.on .dot { animation: pulse 0.9s ease-in-out infinite; }
@keyframes pulse { 50% { transform: scale(1.8); opacity: 0.35; } }

.group { margin-top: 16px; }
.label-sm {
  font: 600 12px var(--sans);
  color: var(--muted);
  margin-bottom: 8px;
}
.seg {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 6px;
}
.seg button {
  height: 32px;
  border-radius: 999px;
  border: 1.5px solid var(--line);
  background: transparent;
  color: var(--muted);
  font: 600 13px var(--sans);
  cursor: pointer;
  transition: border-color 0.2s, color 0.2s;
}
.seg button:hover { color: var(--fg); }
.seg button[aria-checked='true'] { border-color: var(--gold); color: var(--gold); }

/* ---------- oscilloscope + sliders ---------- */
.scope-head {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 8px;
  white-space: nowrap;
}
.scope-note { font: 400 11px var(--mono); color: var(--muted); }
#scope {
  display: block;
  width: 100%;
  height: 92px;
  border-radius: 10px;
  background: #080d1a;
  border: 1px solid var(--line);
}
.sliders { display: grid; gap: 8px; margin-top: 14px; }
.slider {
  display: grid;
  grid-template-columns: 72px 1fr 78px;
  align-items: center;
  gap: 10px;
  font: 600 12px var(--sans);
  color: var(--muted);
}
.slider output { font: 400 11px var(--mono); color: var(--fg); text-align: right; }
.slider input { width: 100%; margin: 0; accent-color: var(--gold); }

#scene.pluckable { cursor: grab; }
#scene.grabbing { cursor: grabbing; }

.stats {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 14px 16px;
  margin: 18px 0 0;
  padding-top: 16px;
  border-top: 1px solid var(--line);
}
.stats dt { font: 600 12px var(--sans); color: var(--muted); }
.stats dd {
  margin: 5px 0 0;
  font: 600 19px/1 var(--mono);
  font-variant-numeric: tabular-nums;
  color: var(--fg);
}
.stats dd small { font: 400 11px var(--mono); color: var(--muted); margin-left: 5px; }
.stats dd.none { font: 600 14px/19px var(--sans); color: var(--gold-deep); }

.hint { margin: 16px 0 0; font-size: 12.5px; color: var(--muted); line-height: 1.6; }
.hint b { color: var(--fg); font-weight: 700; }
kbd {
  font: 600 10.5px var(--mono);
  padding: 1px 5px;
  border: 1px solid var(--line);
  border-radius: 4px;
  color: var(--fg);
}

/* ---------- leader-line labels ---------- */
#leaders {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  overflow: visible;
}
#leaders line { stroke: var(--gold-deep); stroke-width: 1.6; stroke-dasharray: 5 4; }
#leaders circle { fill: var(--gold-deep); }
#labels { position: absolute; inset: 0; pointer-events: none; }
.plabel {
  position: absolute;
  left: 0;
  top: 0;
  white-space: nowrap;
  font: 700 13.5px var(--sans);
  color: var(--gold);
  text-shadow: 0 0 6px var(--bg), 0 0 2px var(--bg);
  will-change: transform, opacity;
}

/* ---------- tooltip ---------- */
.tip {
  position: fixed;
  left: 0;
  top: 0;
  max-width: 290px;
  padding: 14px 16px;
  border-radius: 12px;
  background: var(--card);
  border: 1px solid var(--line);
  box-shadow: 0 14px 40px rgba(0, 0, 0, 0.4);
  pointer-events: none;
  font: 400 14.5px/1.5 var(--serif);
  color: rgba(240, 234, 210, 0.85);
}
.tip strong { display: block; font: 700 14px var(--sans); color: var(--gold); margin-bottom: 5px; }
.tip[hidden] { display: none; }

.reveal { opacity: 0; }

/* ---------- small screens ---------- */
@media (max-width: 720px) {
  .hud-top { top: 18px; left: 16px; right: 16px; }
  .tagline { display: none; }
  .card { left: 16px; right: 16px; bottom: 16px; width: auto; padding: 14px; }
  .seg { grid-template-columns: repeat(4, 1fr); gap: 4px; }
  .seg button { font-size: 11px; padding: 0 2px; }
  .group { margin-top: 12px; }
  #scope { height: 56px; }
  .scope-note { display: none; }
  .sliders { grid-template-columns: 1fr 1fr; gap: 12px; margin-top: 10px; }
  .slider { grid-template-columns: 1fr auto; gap: 4px 8px; font-size: 11px; }
  .slider input { grid-column: 1 / -1; grid-row: 2; }
  .stats { grid-template-columns: repeat(4, 1fr); gap: 8px; margin-top: 14px; padding-top: 12px; }
  .stats dt { font-size: 10px; }
  .stats dd { font-size: 14px; }
  .stats dd small { display: none; }
  .stats dd.none { font-size: 12px; line-height: 15px; }
  .hint { display: none; }
  .plabel { font-size: 11.5px; }
}

@media (prefers-reduced-motion: reduce) {
  .btn.primary.on .dot { animation: none; }
}

/* ---------- status line + Phase Inverter ---------- */
.status {
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 30px;
  margin-top: 10px;
  font: 500 12.5px/1.35 var(--sans);
  color: var(--muted);
}
.status .sdot {
  flex: none;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--muted);
  opacity: 0.6;
}
.status[data-tone='ok'] .sdot { background: #6fb3a6; opacity: 1; }
.status[data-tone='info'] .sdot { background: var(--gold); opacity: 1; }
.status[data-tone='warn'] { color: var(--fg); }
.status[data-tone='warn'] .sdot { background: #e0694f; opacity: 1; animation: pulse 0.8s ease-in-out infinite; }
#status-text { flex: 1; }
.mini {
  flex: none;
  height: 26px;
  padding: 0 10px;
  border-radius: 999px;
  border: 0;
  background: var(--gold);
  color: var(--bg);
  font: 700 12px var(--sans);
  cursor: pointer;
}
.mini[hidden] { display: none; }

/* ---------- read-more ---------- */
.card-links { display: none; }
.readmore-m {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font: 700 13px var(--sans);
  color: var(--gold);
  text-decoration: none;
}
.readmore {
  position: absolute;
  right: 32px;
  bottom: 32px;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  height: 40px;
  padding: 0 18px;
  border-radius: 999px;
  border: 1.5px solid rgba(240, 234, 210, 0.32);
  background: rgba(11, 18, 34, 0.6);
  color: var(--fg);
  font: 700 14px var(--sans);
  text-decoration: none;
  transition: border-color 0.2s, color 0.2s;
}
.readmore:hover { border-color: var(--gold); color: var(--gold); }
.readmore span { display: inline-block; animation: nudge 1.6s ease-in-out infinite; }
@keyframes nudge { 50% { transform: translateY(3px); } }

/* ---------- the post ---------- */
.post {
  position: relative; /* above the hero canvas's tail of stars */
  max-width: 720px;
  margin: 0 auto;
  padding: 96px 20px 120px;
  font: 400 18.5px/1.75 var(--serif);
  color: rgba(240, 234, 210, 0.88);
}
.post-head { margin-bottom: 36px; }
.post h1 {
  margin: 0;
  font: 800 clamp(34px, 5vw, 48px)/1.1 var(--serif);
  letter-spacing: -0.015em;
  color: var(--fg);
}
.post .meta {
  display: flex;
  flex-wrap: wrap;
  gap: 6px 18px;
  margin-top: 14px;
  font: 400 12px var(--mono);
  color: var(--muted);
  text-transform: uppercase;
}
.post .tags { color: var(--gold-deep); text-transform: none; }
.post h2 {
  margin: 64px 0 14px;
  font: 800 28px/1.2 var(--sans);
  letter-spacing: -0.01em;
  color: var(--fg);
  scroll-margin-top: 24px;
}
.post h3 {
  margin: 36px 0 8px;
  font: 700 19px/1.3 var(--sans);
  color: var(--gold);
}
.post p, .post ul { margin: 0 0 20px; }
.post li { margin-bottom: 6px; }
.post a { color: var(--gold); text-decoration-thickness: 1px; text-underline-offset: 3px; }
.post a:hover { color: #f6cd82; }
.post em { font-style: italic; }
.post code {
  font: 400 0.8em var(--mono);
  padding: 2px 5px;
  border-radius: 5px;
  background: var(--card);
  color: var(--fg);
}
.post pre {
  margin: 0 0 24px;
  padding: 18px 20px;
  overflow-x: auto;
  border-radius: 12px;
  background: var(--card);
  border: 1px solid var(--line);
}
.post pre code {
  padding: 0;
  background: none;
  font-size: 13px;
  line-height: 1.7;
  white-space: pre;
}
.post var { font-style: italic; font-family: var(--serif); }

.callout {
  margin: 28px 0 8px;
  padding: 18px 20px 4px;
  border-radius: 12px;
  background: var(--card);
  border: 1px solid var(--line);
  border-left: 3px solid var(--gold);
}
.callout-label {
  display: inline-block;
  margin-bottom: 8px;
  font: 700 12px var(--sans);
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--gold);
}
.callout p { font-size: 17px; }

.equation {
  margin: 0 0 22px;
  padding: 18px 12px;
  overflow-x: auto;
  text-align: center;
  white-space: nowrap;
  font: 400 21px var(--serif);
  color: var(--fg);
  border-top: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
}

.table-wrap { overflow-x: auto; margin: 0 0 24px; }
.post table { width: 100%; border-collapse: collapse; font: 400 14.5px/1.5 var(--sans); }
.post th {
  text-align: left;
  font-weight: 700;
  color: var(--fg);
  padding: 10px 12px;
  border-bottom: 1.5px solid rgba(240, 234, 210, 0.3);
}
.post td { padding: 10px 12px; border-bottom: 1px solid var(--line); vertical-align: top; }
.post td:first-child { color: var(--gold); font-weight: 600; white-space: nowrap; }

/* ---------- figures ---------- */
.post figure { margin: 32px 0 32px; }
.post figure.wide { margin-left: -60px; margin-right: -60px; }
.post figcaption {
  margin-top: 12px;
  text-align: center;
  font: 400 13px var(--sans);
  color: var(--muted);
}
.sheet-pair { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.sheet-pair img {
  display: block;
  width: 100%;
  height: auto;
  border-radius: 6px;
  filter: grayscale(1) contrast(1.05);
}
.fig-box {
  padding: 18px;
  border-radius: 14px;
  background: var(--card);
  border: 1px solid var(--line);
}
.fig-canvas {
  display: block;
  width: 100%;
  border-radius: 10px;
  background: #080d1a;
  touch-action: none;
}
.fig-canvas.square { max-width: 340px; aspect-ratio: 1; margin: 0 auto; cursor: zoom-in; touch-action: pan-x pan-y; background: rgb(31, 42, 70); }
.fig-canvas.square.zoomed { cursor: grab; touch-action: none; }
.fig-canvas:focus { outline: none; }
.fig-canvas:focus-visible { outline: 2px solid var(--gold-deep); outline-offset: 3px; }
.fig-zoom { position: relative; max-width: 340px; margin: 0 auto; }
.fig-zoom-reset { position: absolute; top: 10px; right: 10px; background: var(--card); }
.fig-zoom-reset[hidden] { display: none; }
.fig-canvas.square.zoomed:active { cursor: grabbing; }
.fig-canvas.strip { height: 180px; cursor: grab; }
.fig-controls {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 12px 22px;
  margin-top: 16px;
  font-family: var(--sans);
}
.fig-controls .slider { flex: 1 1 220px; grid-template-columns: 64px 1fr 48px; }
.check {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font: 600 13px var(--sans);
  color: var(--fg);
  cursor: pointer;
}
.check input { accent-color: var(--gold); width: 16px; height: 16px; margin: 0; }
.btn.small { flex: none; height: 32px; padding: 0 16px; font-size: 13px; }

.post-foot {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  align-items: center;
  gap: 10px 20px;
  margin-top: 56px;
  padding-top: 18px;
  border-top: 1px solid var(--line);
  font: 600 14px var(--sans);
  color: var(--muted);
}
.post-foot .src { display: inline-flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.post-foot .src a { display: inline-flex; align-items: center; gap: 6px; }
.post-foot svg {
  width: 16px;
  height: 16px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

@media (max-width: 900px) {
  .post figure.wide { margin-left: 0; margin-right: 0; }
}

@media (max-width: 720px) {
  .readmore { display: none; }
  .card-links { display: flex; justify-content: center; gap: 22px; margin-top: 10px; }
  .status { margin-top: 8px; font-size: 11.5px; min-height: 26px; }
  .post { padding-top: 64px; font-size: 17.5px; }
  .post h2 { font-size: 24px; margin-top: 52px; }
  .sheet-pair { gap: 8px; }
  .fig-box { padding: 12px; }
  .fig-canvas.strip { height: 140px; }
}

@media (min-width: 721px) and (max-height: 880px) {
  .tagline { display: none; }
}

/* ---------- corner button (source link) ---------- */
.corner-btn {
  position: absolute;
  top: 24px;
  right: 24px;
  display: grid;
  place-items: center;
  width: 40px;
  height: 40px;
  padding: 0;
  border-radius: 50%;
  border: 1.5px solid rgba(240, 234, 210, 0.32);
  background: rgba(11, 18, 34, 0.6);
  color: var(--fg);
  cursor: pointer;
  transition: border-color 0.2s, color 0.2s;
}
.corner-btn:hover { border-color: var(--gold); color: var(--gold); }
.corner-btn svg,
.chev svg {
  width: 18px;
  height: 18px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

/* ---------- collapsible card (chevron toggle) ---------- */
.chev {
  flex: none;
  display: grid;
  place-items: center;
  width: 40px;
  height: 40px;
  padding: 0;
  border-radius: 50%;
  border: 1.5px solid rgba(240, 234, 210, 0.32);
  background: transparent;
  color: var(--fg);
  cursor: pointer;
  transition: border-color 0.2s, color 0.2s;
}
.chev:hover { border-color: var(--gold); color: var(--gold); }
.chev svg { transition: transform 0.48s cubic-bezier(0.455, 0.03, 0.515, 0.955); }
.hero.focus .chev svg { transform: rotate(180deg); }
/* grid-rows 1fr -> 0fr animates the body's height without measuring it */
.card-body {
  display: grid;
  grid-template-rows: 1fr;
  /* same length and easing as the camera's glide (FIT_MS in main.js) */
  transition: grid-template-rows 0.48s cubic-bezier(0.455, 0.03, 0.515, 0.955);
}
.card-inner { min-height: 0; overflow: hidden; }
.hero.focus .card-body { grid-template-rows: 0fr; }
.hero.focus .card-inner { visibility: hidden; transition: visibility 0s 0.48s; }

@media (prefers-reduced-motion: reduce) {
  .card-body,
  .chev svg { transition: none; }
}

@media (max-width: 720px) {
  /* sits beside the eyebrow line, above the title */
  .corner-btn { top: 10px; right: 12px; width: 34px; height: 34px; }
  .corner-btn svg { width: 16px; height: 16px; }
  .hud-top { right: 54px; }
  .eyebrow { font-size: 10px; letter-spacing: 0.04em; white-space: nowrap; }
}

/* ---------- timeline ----------
   After the site's Timeline.astro (itself after the Chirpy theme): a line and
   dots drawn with pseudo-elements. Each row is a date column, the line, then
   the text; the only colour is on the dots. Long titles wrap, so the line runs
   to each row's real bottom and the dot sits on the first line of text. */
.timeline {
  --tl-date-w: 6.5rem; /* fits "15 Apr 1946" */
  --tl-gap: 1.75rem;   /* line sits in the middle of this gap */
  --tl-lh: 1.5rem;
  --tl-pad: 0.6rem;
  list-style: none;
  margin: 28px 0 32px;
  padding: 0;
  font: 400 15.5px/var(--tl-lh) var(--sans);
}
.post .timeline li { margin: 0; }
.timeline li {
  position: relative;
  display: grid;
  grid-template-columns: var(--tl-date-w) 1fr;
  column-gap: var(--tl-gap);
  padding: var(--tl-pad) 0;
  color: var(--fg);
}
/* the line: from row top to row bottom, trimmed to the first and last dots */
.timeline li::before {
  content: '';
  position: absolute;
  left: calc(var(--tl-date-w) + var(--tl-gap) / 2 - 1px);
  top: 0;
  bottom: 0;
  width: 2px;
  background: var(--line);
}
.timeline li:first-child::before { top: calc(var(--tl-pad) + var(--tl-lh) / 2); }
.timeline li:last-child::before { bottom: auto; height: calc(var(--tl-pad) + var(--tl-lh) / 2); }
/* the dot, on the first line of text */
.timeline li::after {
  content: '';
  position: absolute;
  left: calc(var(--tl-date-w) + var(--tl-gap) / 2 - 5px);
  top: calc(var(--tl-pad) + var(--tl-lh) / 2 - 5px);
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--gold);
  box-shadow: 0 0 0 4px var(--bg); /* a little gap where the line meets it */
}
.timeline .tl-date {
  text-align: right;
  font: 400 13px/var(--tl-lh) var(--mono);
  font-variant-numeric: tabular-nums;
  color: var(--muted);
  white-space: nowrap;
}
/* Phones: the date goes above its entry, so the text gets the full width. */
@media (max-width: 560px) {
  .timeline { --tl-date-w: 0px; --tl-gap: 1.75rem; }
  .timeline li { grid-template-columns: 1fr; padding-left: var(--tl-gap); }
  .timeline .tl-date { text-align: left; }
}
.timeline a { color: inherit; text-decoration: none; }
.timeline a:hover {
  color: inherit;
  text-decoration: underline;
  text-decoration-thickness: 1px;
  text-underline-offset: 3px;
}

/* Read by screen readers, not shown. */
.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  margin: -1px;
  padding: 0;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
  border: 0;
}
