:root {
  --bg: #070b11;
  --bg-soft: #0b111a;
  --panel: rgba(148, 178, 214, 0.045);
  --panel-solid: #0d141d;
  --line: rgba(148, 173, 204, 0.16);
  --line-strong: rgba(148, 173, 204, 0.3);
  --text: #dde5ef;
  --muted: #8ea0b5;
  --cyan: #38bdf8;
  --amber: #fbbf24;
  --green: #34d399;
  --red: #fb7185;
  --mono: ui-monospace, "SF Mono", "JetBrains Mono", Menlo, Consolas, monospace;
  --sans: system-ui, -apple-system, "Segoe UI", Inter, Roboto, sans-serif;
}

* { box-sizing: border-box; }

html { scroll-behavior: smooth; }

body {
  margin: 0;
  background:
    radial-gradient(1200px 600px at 50% -220px, rgba(56, 189, 248, 0.13), transparent 70%),
    var(--bg);
  color: var(--text);
  font-family: var(--sans);
  font-size: 16.5px;
  line-height: 1.65;
  -webkit-font-smoothing: antialiased;
}

code, kbd { font-family: var(--mono); font-size: 0.88em; }

code {
  background: rgba(56, 189, 248, 0.1);
  border: 1px solid rgba(56, 189, 248, 0.18);
  border-radius: 4px;
  padding: 0.06em 0.34em;
  color: #bfe6ff;
}

kbd {
  background: rgba(255, 255, 255, 0.07);
  border: 1px solid var(--line-strong);
  border-bottom-width: 2px;
  border-radius: 5px;
  padding: 0.08em 0.4em;
  color: var(--text);
}

/* -------------------------------------------------------------- section nav */

.section-nav {
  position: fixed;
  left: 26px;
  top: 50%;
  transform: translateY(-50%);
  z-index: 40;
  /* Capped so a long label can never reach into the content beside it; the
     176px gutter reserved below is 26px of offset plus this. */
  max-width: 150px;
}

.section-nav ol {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  gap: 2px;
  counter-reset: navitem;
}

.section-nav a {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 5px 8px 5px 0;
  text-decoration: none;
  font-size: 0.76rem;
  line-height: 1.3;
  color: var(--muted);
  opacity: 0.65;
  transition: color 0.18s, opacity 0.18s, transform 0.18s;
}

/* The tick grows and lights up rather than the text moving, so the labels stay
   on a stable baseline as you scroll past them. */
.section-nav .tick {
  flex: none;
  width: 16px;
  height: 1px;
  background: currentColor;
  transition: width 0.22s ease, background 0.18s;
}

.section-nav a:hover { color: var(--text); opacity: 1; }
.section-nav a:hover .tick { width: 24px; }

.section-nav a.on {
  color: var(--cyan);
  opacity: 1;
}

.section-nav a.on .tick {
  width: 30px;
  height: 2px;
  box-shadow: 0 0 10px -1px var(--cyan);
}

.section-nav a:focus-visible {
  outline: 2px solid var(--cyan);
  outline-offset: 2px;
  border-radius: 3px;
}

/* Below this width there is no gutter to give the rail, so it goes away
   entirely rather than sitting on top of the canvas. */
@media (max-width: 1279px) {
  .section-nav { display: none; }
}

/* Keep the stage clear of the rail. Capped at 1500px as before, so on a wide
   screen the hero is unchanged and the gutter is simply the leftover margin. */
@media (min-width: 1280px) {
  .stage-wrap { width: calc(100% - 352px); }
}

@media (prefers-reduced-motion: reduce) {
  .section-nav, .section-nav a, .section-nav .tick { transition: none; }
}

/* Keep jumped-to headings clear of the sticky donate pill. */
.prose section, .stage-wrap { scroll-margin-top: 84px; }

/* ------------------------------------------------------------------ topbar */

.topbar {
  position: sticky;
  top: 0;
  z-index: 50;
  max-width: 1500px;
  margin: 0 auto;
  padding: 20px 24px 0;
  display: flex;
  justify-content: flex-end;
  /* The bar spans the full width but is invisible, so without this it would
     swallow clicks and orbit-drags across the top strip of whatever scrolls
     beneath it — including the canvas. Only the pill itself takes input. */
  pointer-events: none;
}

.topbar[hidden] { display: none; }

/* Tightened up only when the bar is actually showing. */
body.has-donate .masthead { padding-top: 34px; }

.donate {
  pointer-events: auto;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-size: 0.86rem;
  color: #d8f1ff;
  text-decoration: none;
  /* Opaque enough to stay legible once prose scrolls behind it, with the cyan
     tint layered over a dark base rather than over the page. */
  background:
    linear-gradient(rgba(56, 189, 248, 0.15), rgba(56, 189, 248, 0.15)),
    rgba(8, 13, 20, 0.88);
  backdrop-filter: blur(10px);
  box-shadow: 0 8px 24px -12px rgba(0, 0, 0, 0.9);
  border: 1px solid rgba(56, 189, 248, 0.45);
  border-radius: 999px;
  padding: 8px 18px;
  transition: background 0.16s, border-color 0.16s, transform 0.1s, box-shadow 0.16s;
}

.donate svg { color: var(--red); flex: none; }

.donate:hover {
  background:
    linear-gradient(rgba(56, 189, 248, 0.26), rgba(56, 189, 248, 0.26)),
    rgba(8, 13, 20, 0.9);
  border-color: var(--cyan);
  box-shadow: 0 0 26px -8px rgba(56, 189, 248, 0.75);
}

.donate:active { transform: translateY(1px); }

.donate:focus-visible {
  outline: 2px solid var(--cyan);
  outline-offset: 3px;
}

@media (max-width: 700px) {
  .topbar { padding: 14px 20px 0; }
  .donate { font-size: 0.8rem; padding: 7px 15px; }
}

/* ---------------------------------------------------------------- masthead */

.masthead {
  max-width: 900px;
  margin: 0 auto;
  padding: 68px 24px 40px;
  text-align: center;
}

.eyebrow {
  font-family: var(--mono);
  font-size: 0.76rem;
  letter-spacing: 0.28em;
  text-transform: uppercase;
  color: var(--cyan);
  margin: 0 0 18px;
}

.masthead h1 {
  font-size: clamp(1.9rem, 4.6vw, 3.1rem);
  line-height: 1.14;
  letter-spacing: -0.022em;
  margin: 0 0 22px;
  font-weight: 650;
}

.lede {
  font-size: 1.06rem;
  color: #b9c6d6;
  max-width: 68ch;
  margin: 0 auto;
  text-align: left;
}

/* ------------------------------------------------------------------- stage */

.stage-wrap {
  max-width: 1500px;
  margin: 0 auto;
  padding: 8px 24px 24px;
  display: grid;
  gap: 20px;
  grid-template-columns: minmax(0, 1fr);
  align-items: start;
}

@media (min-width: 1080px) {
  .stage-wrap { grid-template-columns: minmax(0, 1fr) 350px; }
  .panel-col { position: sticky; top: 18px; }
  /* Both stick to the right edge, so drop the sidebar clear of the pill. */
  body.has-donate .panel-col { top: 74px; }
}

.canvas-shell {
  position: relative;
  height: clamp(460px, 72vh, 830px);
  border: 1px solid var(--line);
  border-radius: 16px;
  overflow: hidden;
  background: #070b11;
  box-shadow: 0 30px 70px -40px rgba(0, 0, 0, 0.9), inset 0 0 0 1px rgba(255, 255, 255, 0.02);
}

#stage { display: block; width: 100%; height: 100%; }

.hud {
  position: absolute;
  left: 0;
  right: 0;
  padding: 14px 16px;
  pointer-events: none;
}

.hud-top { top: 0; }
.hud-bottom { bottom: 0; display: grid; gap: 10px; justify-items: center; }

.phases { display: flex; flex-wrap: wrap; gap: 8px; justify-content: center; }

.chip {
  display: grid;
  gap: 1px;
  padding: 6px 12px;
  border-radius: 9px;
  border: 1px solid var(--line);
  background: rgba(7, 11, 17, 0.72);
  backdrop-filter: blur(6px);
  transition: border-color 0.18s, background 0.18s, opacity 0.18s;
  opacity: 0.5;
}

.chip b {
  font-family: var(--mono);
  font-size: 0.7rem;
  letter-spacing: 0.14em;
}

.chip span {
  font-size: 0.68rem;
  color: var(--muted);
  line-height: 1.25;
  max-width: 20ch;
}

.chip.done { opacity: 0.72; border-color: rgba(56, 189, 248, 0.22); }

.chip.on {
  opacity: 1;
  border-color: var(--cyan);
  background: rgba(56, 189, 248, 0.14);
  box-shadow: 0 0 22px -6px rgba(56, 189, 248, 0.6);
}

.chip.on b { color: var(--cyan); }

.instruction {
  margin: 0;
  font-family: var(--mono);
  font-size: 0.8rem;
  text-align: center;
  color: #cfe0f0;
  background: rgba(7, 11, 17, 0.76);
  backdrop-filter: blur(6px);
  border: 1px solid var(--line);
  border-radius: 9px;
  padding: 7px 14px;
}

.instruction em { color: var(--muted); font-style: normal; }

.readout {
  display: flex;
  gap: 2px;
  padding: 7px 10px;
  border-radius: 9px;
  background: rgba(7, 11, 17, 0.76);
  border: 1px solid var(--line);
  backdrop-filter: blur(6px);
  max-width: 100%;
  overflow: hidden;
}

.tcell {
  font-family: var(--mono);
  font-size: 0.82rem;
  min-width: 1.35em;
  text-align: center;
  border-radius: 3px;
  color: #e7eef7;
}

.tcell.blank { color: rgba(142, 160, 181, 0.45); }

.tcell.head {
  background: var(--cyan);
  color: #04121c;
  font-weight: 700;
  box-shadow: 0 0 14px -2px rgba(56, 189, 248, 0.8);
}

.fallback {
  position: absolute;
  inset: 50% 12% auto;
  transform: translateY(-50%);
  margin: 0;
  padding: 18px 20px;
  border: 1px solid var(--line-strong);
  border-radius: 12px;
  background: rgba(7, 11, 17, 0.94);
  font-size: 0.92rem;
  text-align: center;
  line-height: 1.8;
}

/* ---------------------------------------------------------------- controls */

.controls {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px;
  margin-top: 14px;
}

.btn {
  font: inherit;
  font-size: 0.9rem;
  color: var(--text);
  background: var(--panel);
  border: 1px solid var(--line-strong);
  border-radius: 9px;
  padding: 8px 16px;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s, transform 0.08s;
}

.btn:hover:not(:disabled) { background: rgba(148, 178, 214, 0.12); border-color: var(--cyan); }
.btn:active:not(:disabled) { transform: translateY(1px); }
.btn:disabled { opacity: 0.38; cursor: not-allowed; }
.btn.small { padding: 6px 12px; font-size: 0.83rem; }

.btn.primary {
  background: rgba(56, 189, 248, 0.16);
  border-color: rgba(56, 189, 248, 0.55);
  color: #d8f1ff;
}

.ctl {
  display: flex;
  align-items: center;
  gap: 9px;
  font-size: 0.83rem;
  color: var(--muted);
  border: 1px solid var(--line);
  border-radius: 9px;
  padding: 6px 12px;
  background: var(--panel);
}

.ctl b { color: var(--text); font-family: var(--mono); font-size: 0.8rem; }

.ctl input[type="range"] { width: 120px; accent-color: var(--cyan); }

.ctl select {
  font: inherit;
  font-size: 0.86rem;
  color: var(--text);
  background: var(--panel-solid);
  border: 1px solid var(--line-strong);
  border-radius: 7px;
  padding: 4px 8px;
}

.hint {
  font-size: 0.79rem;
  color: var(--muted);
  margin: 10px 0 0;
}

.hint.warn { color: var(--amber); }

/* ------------------------------------------------------------------ panels */

.panel-col { display: grid; gap: 14px; }

.card {
  border: 1px solid var(--line);
  border-radius: 14px;
  background: linear-gradient(180deg, rgba(148, 178, 214, 0.055), rgba(148, 178, 214, 0.02));
  padding: 16px 18px;
}

.card h2 {
  font-size: 0.74rem;
  font-family: var(--mono);
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--muted);
  margin: 0 0 12px;
  font-weight: 600;
}

.card h2 .sub {
  text-transform: none;
  letter-spacing: 0;
  color: rgba(142, 160, 181, 0.6);
  font-weight: 400;
}

.state-big {
  font-family: var(--mono);
  font-size: 1.9rem;
  line-height: 1.1;
  margin: 0;
  color: var(--cyan);
  letter-spacing: -0.01em;
}

.state-doc { margin: 4px 0 0; font-size: 0.85rem; color: var(--muted); }

.stats {
  display: flex;
  gap: 26px;
  margin: 14px 0 0;
  padding-top: 12px;
  border-top: 1px solid var(--line);
}

.stats div { display: grid; gap: 1px; }
.stats dt { font-size: 0.68rem; text-transform: uppercase; letter-spacing: 0.12em; color: var(--muted); }
.stats dd { margin: 0; font-family: var(--mono); font-size: 1.02rem; }

.verdict { color: var(--muted); }
.verdict.good { color: var(--green); }
.verdict.bad { color: var(--red); }

.aside-note {
  margin: 12px 0 0;
  font-size: 0.8rem;
  line-height: 1.55;
  color: var(--muted);
  padding-top: 11px;
  border-top: 1px solid var(--line);
}

.aside-note em { color: #b9c6d6; font-style: normal; font-weight: 600; }

.blurb { margin: 0 0 10px; font-size: 0.88rem; color: #b9c6d6; }

.tape-edit { display: flex; gap: 7px; }

.tape-edit input {
  flex: 1;
  min-width: 0;
  font-family: var(--mono);
  font-size: 0.9rem;
  color: var(--text);
  background: #060a10;
  border: 1px solid var(--line-strong);
  border-radius: 8px;
  padding: 7px 10px;
  letter-spacing: 0.12em;
}

.tape-edit input:focus { outline: none; border-color: var(--cyan); }

.alphabet { font-size: 0.79rem; color: var(--muted); margin: 8px 0 0; }
.alphabet span { font-family: var(--mono); color: #bfe6ff; }

/* The binary-addition table is 33 rules, so long programs scroll in place. */
.rules-wrap {
  position: relative; /* so a firing rule can be scrolled into view */
  max-height: 330px;
  overflow-y: auto;
  scroll-behavior: smooth;
  margin: 0 -4px;
  padding: 0 4px;
  scrollbar-width: thin;
  scrollbar-color: rgba(148, 173, 204, 0.35) transparent;
}

.rules-wrap::-webkit-scrollbar { width: 8px; }
.rules-wrap::-webkit-scrollbar-track { background: transparent; }
.rules-wrap::-webkit-scrollbar-thumb {
  background: rgba(148, 173, 204, 0.3);
  border-radius: 4px;
}

.rules-wrap thead th {
  position: sticky;
  top: 0;
  background: #0e151e;
  z-index: 1;
}

table.rules {
  width: 100%;
  border-collapse: collapse;
  font-family: var(--mono);
  font-size: 0.8rem;
}

table.rules th {
  text-align: left;
  font-weight: 500;
  font-size: 0.68rem;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--muted);
  padding: 0 6px 7px;
  border-bottom: 1px solid var(--line);
}

table.rules td {
  padding: 4px 6px;
  border-bottom: 1px solid rgba(148, 173, 204, 0.07);
  color: #c8d5e3;
  transition: background 0.12s;
}

table.rules .state-cell { color: var(--amber); }

table.rules tr.active td {
  background: rgba(56, 189, 248, 0.16);
  color: #eaf6ff;
}

table.rules tr.active td:first-child { box-shadow: inset 3px 0 0 var(--cyan); }

.state-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 7px; }

.state-list li {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 9px;
  align-items: baseline;
  font-size: 0.8rem;
  color: var(--muted);
  opacity: 0.72;
}

.state-list li code { color: #c8d5e3; background: rgba(148, 178, 214, 0.09); border-color: var(--line); }
.state-list li.halt code { color: var(--green); border-color: rgba(52, 211, 153, 0.3); background: rgba(52, 211, 153, 0.09); }

.state-list li.current { opacity: 1; }
.state-list li.current code { color: #04121c; background: var(--cyan); border-color: var(--cyan); }
.state-list li.current span { color: var(--text); }

/* ------------------------------------------------------------------- prose */

.prose {
  max-width: 860px;
  margin: 0 auto;
  padding: 40px 24px 20px;
}

.prose section { margin: 0 0 62px; }

.prose h2 {
  font-size: clamp(1.35rem, 2.6vw, 1.72rem);
  letter-spacing: -0.018em;
  line-height: 1.24;
  margin: 0 0 18px;
  padding-bottom: 12px;
  border-bottom: 1px solid var(--line);
  font-weight: 640;
}

.prose h3 {
  font-size: 1.02rem;
  margin: 30px 0 10px;
  color: #cfdcea;
}

.prose p { margin: 0 0 17px; color: #c4d0de; }
.prose b { color: var(--text); font-weight: 650; }

.callout {
  border-left: 2px solid var(--cyan);
  background: rgba(56, 189, 248, 0.06);
  border-radius: 0 10px 10px 0;
  padding: 14px 18px;
  margin: 24px 0 !important;
  font-size: 0.97rem;
}

.parts {
  display: grid;
  gap: 14px;
  grid-template-columns: repeat(auto-fit, minmax(230px, 1fr));
  margin: 26px 0;
}

.part {
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 15px 17px;
  background: var(--panel);
}

.part h3 {
  margin: 0 0 7px;
  font-size: 0.94rem;
  color: var(--cyan);
  font-family: var(--mono);
  letter-spacing: -0.01em;
}

.part p { margin: 0; font-size: 0.87rem; line-height: 1.6; color: var(--muted); }

.beats { list-style: none; margin: 24px 0; padding: 0; display: grid; gap: 12px; }

.beats li {
  display: grid;
  grid-template-columns: 108px 1fr;
  gap: 16px;
  align-items: start;
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 14px 16px;
  background: var(--panel);
}

.beat {
  font-family: var(--mono);
  font-size: 0.72rem;
  letter-spacing: 0.14em;
  color: var(--cyan);
  border: 1px solid rgba(56, 189, 248, 0.32);
  background: rgba(56, 189, 248, 0.09);
  border-radius: 7px;
  padding: 4px 0;
  text-align: center;
}

.beats p { margin: 0 0 6px; font-size: 0.88rem; line-height: 1.55; }
.beats p:last-child { margin: 0; color: var(--muted); }
.beats p b { font-size: 0.8rem; }

table.analogy {
  width: 100%;
  border-collapse: collapse;
  margin: 24px 0;
  font-size: 0.87rem;
}

table.analogy th {
  text-align: left;
  font-size: 0.7rem;
  letter-spacing: 0.13em;
  text-transform: uppercase;
  color: var(--muted);
  padding: 0 12px 9px;
  border-bottom: 1px solid var(--line-strong);
  font-weight: 600;
}

table.analogy td {
  padding: 11px 12px;
  border-bottom: 1px solid rgba(148, 173, 204, 0.09);
  vertical-align: top;
  line-height: 1.5;
}

table.analogy td:first-child { color: var(--cyan); font-family: var(--mono); font-size: 0.83rem; width: 27%; }
table.analogy td:nth-child(2) { color: var(--text); width: 30%; }
table.analogy td:last-child { color: var(--muted); font-size: 0.83rem; }
table.analogy tr:hover td { background: rgba(148, 178, 214, 0.035); }

/* Inline links into the glossary: present but quiet, so a paragraph with six of
   them still reads as prose rather than as a list of links. */
.gterm {
  color: inherit;
  text-decoration: none;
  border-bottom: 1px dotted rgba(56, 189, 248, 0.55);
  transition: color 0.14s, border-color 0.14s, background 0.14s;
}

.gterm:hover {
  color: #bfe6ff;
  border-bottom-color: var(--cyan);
  background: rgba(56, 189, 248, 0.09);
}

.gterm:focus-visible {
  outline: 2px solid var(--cyan);
  outline-offset: 2px;
  border-radius: 2px;
}

/* ---------------------------------------------------------------- glossary */

/* Multi-column rather than grid, so alphabetical order reads top-to-bottom
   down one column before starting the next. */
.glossary {
  margin: 26px 0 0;
  columns: 2;
  column-gap: 38px;
}

.glossary > div {
  break-inside: avoid;
  margin: 0 0 18px;
  padding-left: 12px;
  border-left: 1px solid var(--line);
  /* Clears the sticky donate pill when jumped to from a prose link. */
  scroll-margin-top: 90px;
  transition: border-color 0.4s, background 0.4s;
}

/* Show which entry a prose link just jumped to, or it's easy to lose. */
.glossary > div:target {
  border-left-color: var(--cyan);
  background: rgba(56, 189, 248, 0.07);
  border-radius: 0 6px 6px 0;
}

.glossary > div:target dt { color: #eaf6ff; }

.glossary dt {
  font-weight: 620;
  font-size: 0.92rem;
  color: var(--text);
  margin-bottom: 3px;
  line-height: 1.45;
}

.glossary dd {
  margin: 0;
  font-size: 0.85rem;
  line-height: 1.55;
  color: var(--muted);
}

.glossary dd code { font-size: 0.82em; }

.tag {
  display: inline-block;
  font-family: var(--mono);
  font-size: 0.58rem;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  vertical-align: 0.14em;
  padding: 1px 6px;
  border-radius: 999px;
  border: 1px solid currentColor;
  font-weight: 500;
  white-space: nowrap;
}

.tag.machine { color: #7dd3fc; }
.tag.hardware { color: var(--amber); }
.tag.theory { color: var(--green); }

@media (max-width: 760px) {
  .glossary { columns: 1; }
}

ul.tight { margin: 0 0 18px; padding-left: 22px; }
ul.tight li { margin-bottom: 11px; color: #c4d0de; }

/* ------------------------------------------------------------------ footer */

.footer {
  max-width: 860px;
  margin: 0 auto;
  padding: 28px 24px 70px;
  border-top: 1px solid var(--line);
  font-size: 0.83rem;
  color: var(--muted);
}

.footer p { margin: 0 0 7px; }
.footer .muted { opacity: 0.7; }

@media (max-width: 700px) {
  .masthead { padding-top: 44px; }
  .beats li { grid-template-columns: 1fr; gap: 9px; }
  .beat { width: 108px; }
  table.analogy td:first-child,
  table.analogy td:nth-child(2) { width: auto; }
  .chip span { display: none; }
}

@media (prefers-reduced-motion: reduce) {
  html, .rules-wrap { scroll-behavior: auto; }
}
