/* ============================================================================
   Genesis Cartridges — interactive documentation
   Visual identity: "silicon datasheet meets logic-analyser screen."
   Deep blue-black ground, Genesis-red primary, blue & gold signal traces,
   monospace for every piece of hardware data, sans for prose. A faithful
   sibling of the GameCube courses, re-themed to the Sega Genesis palette.
   ============================================================================ */

:root {
  /* ground + panels (blue-biased neutrals, never a flat grey) */
  --ground:   #0a0b10;
  --ground-2: #0e1017;
  --panel:    #14161f;
  --panel-2:  #1b1e2a;
  --panel-3:  #232736;
  --line:     #262b3a;
  --line-2:   #343a4d;

  /* ink */
  --ink:      #eef1f8;
  --ink-2:    #b3b9cc;
  --muted:    #7e8599;

  /* Genesis signal palette — the accent is spent on the traces */
  --red:      #ff5347;  /* PRIMARY accent — Genesis stripe                  */
  --red-d:    #e23b30;
  --blue:     #3fb5ff;  /* secondary / scope trace A — Sega blue            */
  --gold:     #ffc44d;  /* highlight / scope trace B — 16-BIT gold          */
  --amber:    #ff9d3c;  /* highlights, warnings                             */

  /* working aliases: the shared CSS/JS plumbing keeps its old names so the
     component set matches the sibling courses, but every rendered colour is
     the Genesis palette above (red primary, blue & gold traces). */
  --violet:   var(--red);
  --violet-d: var(--red-d);
  --cyan:     var(--blue);
  --magenta:  var(--gold);

  /* semantic (kept separate from the accent) */
  --good:     #4fd08a;
  --warn:     #ffb14e;
  --bad:      #ff5f5f;

  --radius:   14px;
  --radius-s: 9px;
  --shadow:   0 18px 50px -22px rgba(0,0,0,.85);
  --glow-v:   0 0 24px -4px rgba(255,83,71,.5);

  --mono: ui-monospace, "SF Mono", "JetBrains Mono", "Cascadia Code", Menlo, Consolas, monospace;
  --sans: system-ui, -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;

  --sidebar-w: 288px;
  --player-h: 0px;
  --measure: 74ch;
}

* { box-sizing: border-box; }

html { scroll-behavior: smooth; }
@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
  * { animation-duration: .001ms !important; transition-duration: .001ms !important; }
}

body {
  margin: 0;
  font-family: var(--sans);
  color: var(--ink);
  background: var(--ground);
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}
/* Viewport-anchored vignette. Done as a fixed pseudo-element rather than
   `background-attachment: fixed`, which triggers a repaint bug on iOS Safari
   where sections abruptly vanish while scrolling. Red + blue glows. */
body::before {
  content: "";
  position: fixed;
  inset: 0;
  z-index: -1;
  pointer-events: none;
  background:
    radial-gradient(1200px 700px at 78% -8%, rgba(255,83,71,.14), transparent 60%),
    radial-gradient(900px 600px at 0% 100%, rgba(63,181,255,.08), transparent 55%);
}

::selection { background: rgba(255,83,71,.32); color: #fff; }

a { color: var(--red); text-decoration: none; }
a:hover { text-decoration: underline; text-underline-offset: 3px; }

:focus-visible {
  outline: 2px solid var(--blue);
  outline-offset: 2px;
  border-radius: 4px;
}

/* ------------------------------------------------------------------ layout */

.app {
  display: grid;
  grid-template-columns: var(--sidebar-w) minmax(0, 1fr);
  min-height: 100vh;
}

/* reading-progress bar (course feel) */
.progress {
  position: fixed; top: 0; left: 0; right: 0; height: 3px; z-index: 70;
  background: transparent;
}
.progress .fill {
  height: 100%; width: 0%;
  background: linear-gradient(90deg, var(--blue), var(--red) 55%, var(--gold));
  box-shadow: 0 0 10px rgba(255,83,71,.6);
  transition: width .08s linear;
}

/* ------------------------------------------------------------------ sidebar */

.sidebar {
  position: sticky;
  top: 0;
  align-self: start;
  height: 100vh;
  overflow-y: auto;
  border-right: 1px solid var(--line);
  background: linear-gradient(180deg, var(--ground-2), var(--ground));
  padding: 22px 18px calc(var(--player-h) + 28px);
  scrollbar-width: thin;
  scrollbar-color: var(--line-2) transparent;
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 6px;
}
.brand .logo {
  width: 38px; height: 38px; flex: none;
  border-radius: 9px;
  background:
    radial-gradient(circle at 30% 30%, var(--red), var(--red-d) 55%, #8a1f18);
  box-shadow: var(--glow-v), inset 0 0 0 1px rgba(255,255,255,.12);
  position: relative;
}
.brand .logo::after {
  /* cartridge-slot bar motif */
  content: "";
  position: absolute; left: 8px; right: 8px; top: 15px; height: 8px;
  border-radius: 2px;
  background: rgba(10,11,16,.78);
  box-shadow: inset 0 0 0 1px rgba(255,255,255,.06);
}
.brand h1 {
  font: 700 15px/1.2 var(--sans);
  margin: 0; letter-spacing: .2px;
}
.brand .sub {
  display: block;
  font: 500 10.5px/1.3 var(--mono);
  color: var(--muted);
  letter-spacing: .12em;
  text-transform: uppercase;
  margin-top: 2px;
}

.toc {
  margin-top: 20px;
  display: flex;
  flex-direction: column;
  gap: 1px;
}
.toc .toc-group {
  font: 600 10px/1 var(--mono);
  letter-spacing: .16em;
  text-transform: uppercase;
  color: var(--muted);
  padding: 16px 10px 8px;
}
.toc a {
  display: flex;
  align-items: baseline;
  gap: 10px;
  padding: 7px 10px;
  border-radius: 8px;
  color: var(--ink-2);
  font-size: 13.5px;
  border-left: 2px solid transparent;
  transition: background .15s, color .15s, border-color .15s;
}
.toc a .n {
  font: 600 10.5px/1 var(--mono);
  color: var(--muted);
  min-width: 20px;
}
.toc a:hover { background: var(--panel); color: var(--ink); text-decoration: none; }
.toc a.active {
  background: linear-gradient(90deg, rgba(255,83,71,.16), transparent);
  color: #fff;
  border-left-color: var(--red);
}
.toc a.active .n { color: var(--red); }
.toc a.done .n { color: var(--good); }
.toc a.done .n::after { content: " ✓"; }

.progress-note {
  margin: 14px 10px 0;
  font: 600 10px/1.5 var(--mono);
  letter-spacing: .1em;
  text-transform: uppercase;
  color: var(--muted);
}
.progress-note b { color: var(--blue); }

/* ------------------------------------------------------------------ main */

.main {
  min-width: 0;
  padding-bottom: calc(var(--player-h) + 40px);
}

.wrap {
  max-width: 940px;
  margin: 0 auto;
  padding: 0 34px;
}

/* ------------------------------------------------------------------ hero */

.hero {
  position: relative;
  padding: 74px 0 46px;
  border-bottom: 1px solid var(--line);
  overflow: hidden;
}
.hero canvas {
  position: absolute;
  inset: 0;
  width: 100%; height: 100%;
  opacity: .5;
  pointer-events: none;
  mask-image: linear-gradient(180deg, transparent, #000 22%, #000 78%, transparent);
}
.hero .inner { position: relative; z-index: 1; max-width: var(--measure); }
.eyebrow {
  font: 600 11px/1 var(--mono);
  letter-spacing: .22em;
  text-transform: uppercase;
  color: var(--blue);
  display: inline-flex;
  align-items: center;
  gap: 9px;
}
.eyebrow::before {
  content: ""; width: 26px; height: 1px; background: var(--blue); opacity: .7;
}
.hero h2 {
  font: 800 clamp(34px, 6vw, 62px)/1.02 var(--sans);
  letter-spacing: -.02em;
  margin: 20px 0 0;
  text-wrap: balance;
}
.hero h2 .grad {
  background: linear-gradient(100deg, var(--blue), var(--red) 55%, var(--gold));
  -webkit-background-clip: text; background-clip: text; color: transparent;
}
.hero p.lede {
  font-size: 18.5px;
  color: var(--ink-2);
  margin: 22px 0 0;
  max-width: 60ch;
}
.hero .cta-row { display: flex; flex-wrap: wrap; gap: 12px; margin-top: 30px; }

.btn {
  font: 600 13.5px/1 var(--sans);
  padding: 12px 18px;
  border-radius: 10px;
  border: 1px solid var(--line-2);
  background: var(--panel-2);
  color: var(--ink);
  cursor: pointer;
  display: inline-flex; align-items: center; gap: 9px;
  transition: transform .12s, background .15s, border-color .15s, box-shadow .15s;
}
.btn:hover { background: var(--panel-3); transform: translateY(-1px); }
.btn.primary {
  background: linear-gradient(180deg, var(--red), var(--red-d));
  border-color: transparent; color: #240b09; box-shadow: var(--glow-v);
}
.btn.primary:hover { box-shadow: 0 0 30px -4px rgba(255,83,71,.7); }
.btn svg { width: 15px; height: 15px; }

/* ------------------------------------------------------------------ course scaffolding */

/* part divider banner */
.part {
  scroll-margin-top: 20px;
  padding: 62px 0 8px;
}
.part .part-inner {
  position: relative;
  border-radius: var(--radius);
  border: 1px solid var(--line-2);
  background:
    linear-gradient(180deg, var(--panel-2), var(--panel));
  padding: 26px 28px;
  overflow: hidden;
}
.part .part-inner::before {
  content: "";
  position: absolute; right: -60px; top: -60px; width: 220px; height: 220px;
  background: radial-gradient(circle, rgba(255,83,71,.22), transparent 60%);
  pointer-events: none;
}
.part .kicker {
  font: 700 11px/1 var(--mono); letter-spacing: .24em; text-transform: uppercase;
  color: var(--blue);
}
.part h3 { font: 800 clamp(22px,3.4vw,30px)/1.1 var(--sans); margin: 12px 0 0; letter-spacing: -.015em; }
.part p { margin: 12px 0 0; color: var(--ink-2); max-width: 62ch; font-size: 15px; }
.part .part-meta { margin-top: 16px; display: flex; gap: 18px; flex-wrap: wrap; font: 600 11px/1 var(--mono); color: var(--muted); letter-spacing: .06em; }
.part .part-meta b { color: var(--ink); }

/* course landing cards */
.arc-cards { display: grid; grid-template-columns: repeat(3, 1fr); gap: 14px; margin: 34px 0 0; }
.arc-cards .arc {
  display: block;
  background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 18px; transition: transform .14s, border-color .14s, background .14s;
}
.arc-cards .arc:hover { transform: translateY(-3px); border-color: var(--line-2); background: var(--panel-2); text-decoration: none; }
.arc-cards .arc .an { font: 700 11px/1 var(--mono); letter-spacing: .16em; color: var(--red); }
.arc-cards .arc h4 { font: 700 16px/1.25 var(--sans); margin: 12px 0 6px; color: var(--ink); }
.arc-cards .arc p { font-size: 13px; color: var(--muted); margin: 0; }
.arc-cards .arc .cnt { margin-top: 12px; font: 600 10.5px/1 var(--mono); color: var(--blue); letter-spacing: .08em; }
@media (max-width: 720px){ .arc-cards { grid-template-columns: 1fr; } }

/* module header */
.mod-head { margin-bottom: 10px; }
.mod-head .eye {
  display: inline-flex; align-items: center; gap: 10px;
  font: 700 10.5px/1 var(--mono); letter-spacing: .16em; text-transform: uppercase; color: var(--red);
}
.mod-head .eye .part-tag { color: var(--muted); }
.mod-head h3 {
  font: 800 clamp(23px, 3.4vw, 33px)/1.1 var(--sans);
  letter-spacing: -.015em; margin: 12px 0 0; text-wrap: balance;
}
.mod-head .objective {
  display: grid; grid-template-columns: auto 1fr; gap: 10px; align-items: baseline;
  margin: 14px 0 0; padding: 12px 15px;
  background: rgba(63,181,255,.06); border: 1px solid rgba(63,181,255,.18);
  border-radius: var(--radius-s);
}
.mod-head .objective .lbl { font: 700 9.5px/1.4 var(--mono); letter-spacing: .14em; text-transform: uppercase; color: var(--blue); }
.mod-head .objective span.txt { font-size: 13.5px; color: var(--ink-2); }

/* key takeaways */
.takeaway {
  margin: 30px 0 0;
  border: 1px solid var(--line-2);
  border-radius: var(--radius);
  background: linear-gradient(180deg, var(--panel-2), var(--panel));
  padding: 18px 20px;
}
.takeaway .th { font: 700 10.5px/1 var(--mono); letter-spacing: .16em; text-transform: uppercase; color: var(--red); display: flex; align-items: center; gap: 9px; }
.takeaway .th::before { content: "✦"; color: var(--blue); }
.takeaway ul { margin: 14px 0 0; padding-left: 20px; }
.takeaway li { margin: 7px 0; font-size: 14px; color: var(--ink-2); }
.takeaway li::marker { color: var(--blue); }

/* module footer nav */
.mod-nav {
  display: flex; justify-content: space-between; gap: 12px; margin-top: 26px;
}
.mod-nav a {
  flex: 1 1 0; min-width: 0;
  display: flex; flex-direction: column; gap: 4px;
  padding: 14px 16px; border-radius: var(--radius-s);
  border: 1px solid var(--line); background: var(--panel);
  color: var(--ink); transition: border-color .14s, background .14s;
}
.mod-nav a:hover { border-color: var(--red); background: var(--panel-2); text-decoration: none; }
.mod-nav a .dir { font: 600 10px/1 var(--mono); letter-spacing: .12em; text-transform: uppercase; color: var(--muted); }
.mod-nav a .ttl { font: 700 14px/1.2 var(--sans); }
.mod-nav a.next { text-align: right; align-items: flex-end; }
.mod-nav a.disabled { opacity: .4; pointer-events: none; }

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

section.doc { padding: 40px 0 46px; border-bottom: 1px solid var(--line); scroll-margin-top: 20px; }

.sec-head { display: flex; align-items: baseline; gap: 14px; margin-bottom: 6px; }
.sec-head .num {
  font: 700 12px/1 var(--mono);
  color: var(--red);
  letter-spacing: .1em;
  padding-top: 4px;
}
.sec-head h3 {
  font: 800 clamp(24px, 3.4vw, 34px)/1.1 var(--sans);
  letter-spacing: -.015em;
  margin: 0;
  text-wrap: balance;
}
.prose { max-width: var(--measure); }
.prose p { margin: 16px 0; color: var(--ink-2); }
.prose p strong { color: var(--ink); font-weight: 650; }
.prose h4 {
  font: 700 16px/1.3 var(--sans);
  margin: 34px 0 4px;
  color: var(--ink);
}
.prose ul, .prose ol { color: var(--ink-2); padding-left: 22px; margin: 14px 0; }
.prose li { margin: 8px 0; }
.prose li::marker { color: var(--red); }

code, .kbd {
  font: 500 .88em/1.4 var(--mono);
  background: var(--panel-2);
  border: 1px solid var(--line);
  padding: .12em .42em;
  border-radius: 5px;
  color: #f0d6d3;
}
.prose a code { color: var(--red); }

/* callouts */
.note {
  display: grid;
  grid-template-columns: 34px 1fr;
  gap: 14px;
  margin: 24px 0;
  padding: 16px 18px;
  border-radius: var(--radius-s);
  background: var(--panel);
  border: 1px solid var(--line);
  border-left: 3px solid var(--red);
}
.note .ico { font: 600 18px/1 var(--mono); color: var(--red); }
.note.hw { border-left-color: var(--blue); }
.note.hw .ico { color: var(--blue); }
.note.warn { border-left-color: var(--amber); }
.note.warn .ico { color: var(--amber); }
.note p { margin: 0; font-size: 14px; color: var(--ink-2); }
.note p + p { margin-top: 8px; }

/* spec grid */
.specs {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 12px;
  margin: 28px 0;
}
.spec {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius-s);
  padding: 15px 16px;
}
.spec .k { font: 600 10px/1 var(--mono); letter-spacing: .14em; text-transform: uppercase; color: var(--muted); }
.spec .v { font: 700 22px/1.1 var(--mono); color: var(--ink); margin-top: 9px; font-variant-numeric: tabular-nums; }
.spec .d { font-size: 12px; color: var(--muted); margin-top: 5px; }
.spec .v small { font-size: 12px; color: var(--ink-2); font-weight: 500; }

/* memory map bar */
.memmap { margin: 26px 0; }
.memmap .bar { display: flex; height: 46px; border-radius: 8px; overflow: hidden; border: 1px solid var(--line-2); }
.memmap .seg {
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  font: 600 11px/1.2 var(--mono);
  color: #0a0b10;
  text-align: center;
  min-width: 0;
}
.memmap .seg small { font-size: 9.5px; opacity: .8; }

/* tables (hex etc.) */
.tbl-wrap { overflow-x: auto; margin: 24px 0; border: 1px solid var(--line); border-radius: var(--radius-s); }
table { border-collapse: collapse; width: 100%; font-size: 13px; }
thead th {
  text-align: left;
  font: 600 10.5px/1 var(--mono);
  letter-spacing: .12em;
  text-transform: uppercase;
  color: var(--muted);
  padding: 12px 14px;
  background: var(--panel-2);
  border-bottom: 1px solid var(--line-2);
  white-space: nowrap;
}
tbody td { padding: 11px 14px; border-bottom: 1px solid var(--line); color: var(--ink-2); vertical-align: top; }
tbody tr:last-child td { border-bottom: 0; }
tbody tr:hover { background: rgba(255,83,71,.05); }
td .crc { font: 600 12.5px/1 var(--mono); color: var(--blue); }
.pill {
  display: inline-block;
  font: 600 10px/1 var(--mono);
  letter-spacing: .06em;
  padding: 4px 8px;
  border-radius: 999px;
  border: 1px solid var(--line-2);
  color: var(--ink);
  white-space: nowrap;
}
.pill.ax { color: var(--blue); border-color: rgba(63,181,255,.4); }
.pill.zelda { color: var(--amber); border-color: rgba(255,157,60,.4); }
.pill.axwii { color: var(--red); border-color: rgba(255,83,71,.45); }
.pill.util { color: var(--muted); }
.pill.hb { color: var(--gold); border-color: rgba(255,196,77,.4); }

/* ------------------------------------------------------------- two-up cards */
.vs {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
  margin: 28px 0;
}
.vs .card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 20px;
}
.vs .card h4 { margin: 0 0 4px; display: flex; align-items: center; gap: 10px; font-size: 17px; }
.vs .card .tag { font: 600 10px/1 var(--mono); letter-spacing: .1em; padding: 4px 8px; border-radius: 6px; }
.vs .lle .tag { background: rgba(63,181,255,.14); color: var(--blue); }
.vs .hle .tag { background: rgba(255,83,71,.16); color: var(--red); }
.vs .card ul { margin: 14px 0 0; padding-left: 18px; font-size: 13.5px; }
.vs .card .verdict { margin-top: 16px; padding-top: 14px; border-top: 1px solid var(--line); font-size: 13px; color: var(--muted); }

/* pipeline diagram */
.pipe {
  display: flex; flex-wrap: wrap; align-items: stretch; gap: 10px;
  margin: 28px 0; padding: 22px; background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius);
}
.pipe .stage {
  flex: 1 1 120px;
  background: var(--panel-2);
  border: 1px solid var(--line-2);
  border-radius: var(--radius-s);
  padding: 14px;
  position: relative;
}
.pipe .stage .t { font: 700 13px/1.2 var(--sans); }
.pipe .stage .d { font-size: 11.5px; color: var(--muted); margin-top: 5px; }
.pipe .arrow { align-self: center; color: var(--red); font-family: var(--mono); }

/* ------------------------------------------------------- interactive labs */
.lab {
  margin: 30px 0;
  background:
    linear-gradient(180deg, var(--panel-2), var(--panel));
  border: 1px solid var(--line-2);
  border-radius: var(--radius);
  overflow: hidden;
  box-shadow: var(--shadow);
}
.lab .lab-head {
  display: flex; align-items: center; gap: 12px;
  padding: 15px 18px;
  border-bottom: 1px solid var(--line);
  background: rgba(0,0,0,.2);
}
.lab .lab-head .dot { width: 9px; height: 9px; border-radius: 50%; background: var(--blue); box-shadow: 0 0 10px var(--blue); flex: none; }
.lab .lab-head .title { font: 700 13.5px/1 var(--sans); }
.lab .lab-head .badge { margin-left: auto; font: 600 10px/1 var(--mono); letter-spacing: .12em; text-transform: uppercase; color: var(--muted); }
.lab .lab-body { padding: 18px; display: grid; gap: 16px; }

/* All lab canvases MUST have a fixed CSS height. Their draw() routines set
   canvas.height = getBoundingClientRect().height * dpr; without a CSS height
   the element's displayed height derives from the bitmap, so every resize
   (iOS Safari fires one on each scroll as the URL bar toggles) doubles it. */
.scope {
  width: 100%;
  height: 150px;
  border-radius: var(--radius-s);
  background:
    linear-gradient(180deg, #06070d, #090b12);
  border: 1px solid var(--line);
  display: block;
}

.controls { display: flex; flex-wrap: wrap; gap: 14px 20px; align-items: flex-end; }
.ctrl { display: flex; flex-direction: column; gap: 7px; min-width: 120px; }
.ctrl label { font: 600 10px/1 var(--mono); letter-spacing: .1em; text-transform: uppercase; color: var(--muted); }
.ctrl .val { font: 600 11px/1 var(--mono); color: var(--blue); }
input[type=range] {
  -webkit-appearance: none; appearance: none;
  width: 100%; height: 4px; border-radius: 4px;
  background: var(--line-2);
  outline-offset: 4px;
}
input[type=range]::-webkit-slider-thumb {
  -webkit-appearance: none; appearance: none;
  width: 16px; height: 16px; border-radius: 50%;
  background: var(--red); cursor: pointer; border: 2px solid #0a0b10;
  box-shadow: var(--glow-v);
}
input[type=range]::-moz-range-thumb {
  width: 16px; height: 16px; border-radius: 50%;
  background: var(--red); cursor: pointer; border: 2px solid #0a0b10;
}
select, .seg-btns {
  font: 500 13px/1 var(--sans);
  background: var(--panel-3);
  color: var(--ink);
  border: 1px solid var(--line-2);
  border-radius: 8px;
  padding: 9px 11px;
}
.seg-btns { display: inline-flex; padding: 3px; gap: 3px; }
.seg-btns button {
  font: 600 12px/1 var(--mono);
  border: 0; background: transparent; color: var(--ink-2);
  padding: 7px 11px; border-radius: 6px; cursor: pointer;
}
.seg-btns button.on { background: var(--red); color: #240b09; }

.play-btn {
  font: 600 13px/1 var(--sans);
  display: inline-flex; align-items: center; gap: 8px;
  padding: 10px 16px; border-radius: 9px; cursor: pointer;
  background: linear-gradient(180deg, var(--blue), #2b93da);
  color: #04121f; border: 0;
}
.play-btn:hover { filter: brightness(1.08); }
.play-btn svg { width: 13px; height: 13px; }

/* text input (hex entry in labs) */
.hex-in {
  font: 700 15px/1 var(--mono);
  background: var(--panel-3);
  color: var(--gold);
  border: 1px solid var(--line-2);
  border-radius: 8px;
  padding: 10px 12px;
  width: 100%;
  letter-spacing: .05em;
}
.hex-in:focus { outline: 2px solid var(--blue); outline-offset: 1px; }

/* ------------------------------------------------------------- footer */
.foot { padding: 40px 0 60px; color: var(--muted); font-size: 13px; max-width: var(--measure); }
.foot a { color: var(--ink-2); }
.foot .src { font-family: var(--mono); font-size: 12px; }

/* ------------------------------------------------- glossary tooltips */
.term {
  border-bottom: 1.5px dotted var(--red);
  color: var(--ink);
  font-weight: 600;
  cursor: help;
}
.term:focus-visible { outline: 2px solid var(--blue); outline-offset: 2px; border-radius: 3px; }

.tip-bubble {
  position: fixed;
  z-index: 90;
  max-width: min(320px, calc(100vw - 20px));
  background: var(--panel-3);
  color: var(--ink-2);
  border: 1px solid var(--line-2);
  border-radius: 11px;
  padding: 11px 13px;
  font: 500 13px/1.55 var(--sans);
  box-shadow: var(--shadow);
  opacity: 0;
  transform: translateY(5px);
  pointer-events: none;
  transition: opacity .14s ease, transform .14s ease;
}
.tip-bubble .tt { color: var(--blue); font-weight: 700; }
.tip-bubble.show { opacity: 1; transform: translateY(0); }
.tip-bubble::after {
  content: "";
  position: absolute;
  top: 100%;
  left: var(--arrow-x, 50%);
  transform: translateX(-50%);
  border: 7px solid transparent;
  border-top-color: var(--panel-3);
}
.tip-bubble.below::after {
  top: auto;
  bottom: 100%;
  border-top-color: transparent;
  border-bottom-color: var(--panel-3);
}

/* ------------------------------------------------- worked examples */
.example {
  margin: 22px 0;
  padding: 16px 18px;
  border: 1px solid var(--line);
  border-left: 3px solid var(--amber);
  border-radius: var(--radius-s);
  background: linear-gradient(180deg, rgba(255,157,60,.06), transparent);
}
.example .lbl {
  font: 700 10px/1 var(--mono);
  letter-spacing: .16em;
  text-transform: uppercase;
  color: var(--amber);
}
.example p { margin: 10px 0 0; font-size: 14px; color: var(--ink-2); }
.example p + p { margin-top: 9px; }

/* Analogy callout — an everyday comparison to anchor an abstract idea */
.analogy {
  margin: 22px 0;
  padding: 16px 18px;
  border: 1px solid var(--line);
  border-left: 3px solid var(--blue);
  border-radius: var(--radius-s);
  background: linear-gradient(180deg, rgba(63,181,255,.05), transparent);
}
.analogy .lbl {
  font: 700 10px/1 var(--mono);
  letter-spacing: .16em;
  text-transform: uppercase;
  color: var(--blue);
}
.analogy p { margin: 10px 0 0; font-size: 14px; color: var(--ink-2); }

/* Glossary-style definition list */
.defs { margin: 22px 0; display: grid; gap: 1px; border: 1px solid var(--line); border-radius: var(--radius-s); overflow: hidden; background: var(--line); }
.defs .row { display: grid; grid-template-columns: 168px 1fr; gap: 14px; padding: 12px 15px; background: var(--panel); }
.defs .row dt { font: 600 13px/1.4 var(--sans); color: var(--ink); margin: 0; }
.defs .row dd { margin: 0; font-size: 13.5px; color: var(--ink-2); }
@media (max-width: 560px) { .defs .row { grid-template-columns: 1fr; gap: 4px; } }

/* --------------------------------------------- architecture / figure diagrams */
.dsp-diagram, .figure {
  margin: 26px 0;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background:
    radial-gradient(120% 100% at 50% 0%, rgba(255,83,71,.06), transparent 60%),
    var(--ground-2);
  padding: 20px 18px 14px;
}
.dsp-diagram svg, .figure svg { width: 100%; height: auto; display: block; }
.dsp-diagram .fig-cap, .figure .fig-cap { font-size: 12.5px; color: var(--muted); margin: 12px 4px 2px; line-height: 1.55; }
.figure .fig-cap strong { color: var(--ink); font-weight: 650; }
/* SVG element theming — kept in CSS so it tracks the palette */
.d-fill-panel { fill: #1b1e2a; }
.d-fill-panel2 { fill: #232736; }
.d-fill-ground { fill: #0e1017; }
.d-stroke-line { stroke: #343a4d; }
.d-cyan { fill: #3fb5ff; } .d-cyan-s { stroke: #3fb5ff; }
.d-violet { fill: #ff5347; } .d-violet-s { stroke: #ff5347; }
.d-amber { fill: #ff9d3c; } .d-amber-s { stroke: #ff9d3c; }
.d-magenta { fill: #ffc44d; } .d-magenta-s { stroke: #ffc44d; }
.d-red { fill: #ff5347; } .d-red-s { stroke: #ff5347; }
.d-blue { fill: #3fb5ff; } .d-blue-s { stroke: #3fb5ff; }
.d-gold { fill: #ffc44d; } .d-gold-s { stroke: #ffc44d; }
.d-good { fill: #4fd08a; } .d-good-s { stroke: #4fd08a; }
.d-label { fill: #eef1f8; font: 600 15px/1 var(--sans); }
.d-sub { fill: #7e8599; font: 500 11px/1 var(--mono); }
.d-tag { fill: #b3b9cc; font: 600 12px/1 var(--sans); }
.d-flow { fill: #7e8599; font: 600 10.5px/1 var(--mono); letter-spacing: .04em; }
/* extra helpers for the conceptual (wave) diagrams */
.d-grid { stroke: #262b3a; stroke-width: 1; }
.d-axis { stroke: #343a4d; stroke-width: 1.5; }
.d-wave-c { fill: none; stroke: #3fb5ff; stroke-width: 2.4; stroke-linejoin: round; stroke-linecap: round; }
.d-wave-m { fill: none; stroke: #ffc44d; stroke-width: 2.4; stroke-linejoin: round; stroke-linecap: round; }
.d-wave-v { fill: none; stroke: #ff5347; stroke-width: 2.4; stroke-linejoin: round; stroke-linecap: round; }
.d-dot-v { fill: #ff5347; stroke: #0e1017; stroke-width: 1.5; }
.d-dot-m { fill: #ffc44d; stroke: #0e1017; stroke-width: 1.5; }
.d-stem { stroke: #ff5347; stroke-width: 1.4; stroke-dasharray: 2 3; opacity: .8; }
.d-num { fill: #eef1f8; font: 600 12px/1 var(--mono); }
.d-val { fill: #b3b9cc; font: 600 13px/1 var(--mono); }

/* ------------------------------------------------------------- lab canvas sizes */
.scope.lab-mid  { height: 240px; }
.scope.lab-tall { height: 300px; }
.scope.lab-sq   { height: 340px; }

/* live readout chips */
.readouts { display: flex; flex-wrap: wrap; gap: 10px; }
.readout {
  font: 600 11.5px/1.5 var(--mono);
  color: var(--muted);
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 8px 12px;
  letter-spacing: .02em;
}
.readout b { color: var(--blue); font-weight: 700; font-variant-numeric: tabular-nums; }
.readout.warn b { color: var(--amber); }
.readout.bad b { color: var(--bad); }
.readout.good b { color: var(--good); }

.seg-btns.wrap { flex-wrap: wrap; }

.reset-btn {
  font: 600 10.5px/1 var(--mono);
  padding: 8px 12px;
  border-radius: 7px;
  border: 1px solid var(--line-2);
  background: var(--panel-2);
  color: var(--ink-2);
  cursor: pointer;
  letter-spacing: .06em;
  text-transform: uppercase;
}
.reset-btn:hover { color: var(--ink); border-color: var(--red); }

.sim-note { font-size: 12.5px; color: var(--muted); margin: 0; }

/* ------------------------------------------------------------- mobile */
.menu-btn {
  display: none;
  position: fixed; top: 14px; left: 14px; z-index: 60;
  width: 42px; height: 42px; border-radius: 10px;
  background: var(--panel-2); border: 1px solid var(--line-2); color: var(--ink);
  cursor: pointer;
}
.scrim { display: none; }

@media (max-width: 940px) {
  .app { grid-template-columns: 1fr; }
  .menu-btn { display: grid; place-items: center; }
  .sidebar {
    position: fixed; z-index: 55; width: 300px; left: 0; top: 0;
    transform: translateX(-104%); transition: transform .24s ease;
  }
  .sidebar.open { transform: none; }
  .scrim.show { display: block; position: fixed; inset: 0; z-index: 50; background: rgba(0,0,0,.5); }
  .wrap { padding: 0 20px; }
  .hero { padding-top: 66px; }
  .vs { grid-template-columns: 1fr; }
}

@media (max-width: 560px) {
  .sec-head { flex-direction: column; gap: 4px; }
}

/* ---- Back-link to the oldmachines hub site (sidebar) ---- */
.collection-link{
  display:inline-flex; align-items:center; gap:7px; margin:0 0 16px;
  font:600 11px/1 var(--mono); letter-spacing:.14em; text-transform:uppercase;
  color:var(--muted);
}
.collection-link:hover{ color:var(--ink); text-decoration:none; }
