/* ============================================================
   How a Computer Works — stylesheet
   ============================================================ */

:root {
  --bg:        #080d16;
  --bg-alt:    #0b1220;
  --surface:   #101a2b;
  --surface-2: #16223a;
  --line:      #24334f;
  --line-soft: #1a2740;
  --text:      #e3eafb;
  --dim:       #8ea5c8;
  --dimmer:    #5e7398;
  --accent:    #3de3c8;
  --accent-dk: #17a68f;
  --amber:     #ffb648;
  --rose:      #ff6b8a;
  --violet:    #a58cff;
  --on:        #3de3c8;
  --on-glow:   rgba(61, 227, 200, .45);
  --off:       #2b3a57;
  --shadow:    0 18px 48px rgba(0, 0, 0, .45);
  --radius:    14px;
  --mono: ui-monospace, "SF Mono", "JetBrains Mono", Menlo, Consolas, monospace;
  --sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Inter, Roboto, "Helvetica Neue", Arial, sans-serif;
}

:root[data-theme="light"] {
  --bg:        #f4f7fc;
  --bg-alt:    #eaf0f9;
  --surface:   #ffffff;
  --surface-2: #f2f6fc;
  --line:      #d2dcec;
  --line-soft: #e2e9f4;
  --text:      #0e1729;
  --dim:       #56688a;
  --dimmer:    #8195b4;
  --accent:    #0e9d87;
  --accent-dk: #0b7a69;
  --amber:     #c27608;
  --rose:      #d63a5e;
  --violet:    #6b4fd8;
  --on:        #0e9d87;
  --on-glow:   rgba(14, 157, 135, .28);
  --off:       #c6d2e4;
  --shadow:    0 14px 34px rgba(24, 45, 82, .10);
}

* { box-sizing: border-box; }

html { scroll-behavior: smooth; scroll-padding-top: 88px; }
@media (prefers-reduced-motion: reduce) { html { scroll-behavior: auto; } }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--sans);
  font-size: 17px;
  line-height: 1.65;
  -webkit-font-smoothing: antialiased;
  overflow-x: hidden;
}

/* background texture: faint circuit grid */
body::before {
  content: "";
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 0;
  background-image:
    linear-gradient(var(--line-soft) 1px, transparent 1px),
    linear-gradient(90deg, var(--line-soft) 1px, transparent 1px);
  background-size: 52px 52px;
  opacity: .35;
  mask-image: radial-gradient(ellipse 90% 60% at 50% 0%, #000 0%, transparent 78%);
}

main { position: relative; z-index: 1; }

a { color: var(--accent); }
code {
  font-family: var(--mono);
  font-size: .88em;
  background: var(--surface-2);
  border: 1px solid var(--line-soft);
  padding: .08em .38em;
  border-radius: 5px;
}

.skip-link {
  position: absolute; left: -9999px; top: 0; z-index: 100;
  background: var(--accent); color: #04121a; padding: .6rem 1rem; border-radius: 0 0 8px 0;
}
.skip-link:focus { left: 0; }

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

/* ── top bar ─────────────────────────────────────────────── */
.topbar {
  position: sticky; top: 0; z-index: 50;
  display: flex; align-items: center; gap: 1rem;
  padding: .55rem clamp(.8rem, 3vw, 2rem);
  background: color-mix(in srgb, var(--bg) 86%, transparent);
  backdrop-filter: blur(14px);
  border-bottom: 1px solid var(--line-soft);
}
.brand { display: flex; align-items: center; gap: .55rem; text-decoration: none; color: var(--text); flex: none; }
.brand-mark {
  width: 18px; height: 18px; border-radius: 4px;
  border: 2px solid var(--accent);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 12%, transparent);
  position: relative;
}
.brand-mark::after {
  content: ""; position: absolute; inset: 3px; border-radius: 1px; background: var(--accent);
  animation: pulse 2.6s ease-in-out infinite;
}
@keyframes pulse { 0%,100% { opacity: .25; } 50% { opacity: 1; } }
@media (prefers-reduced-motion: reduce) { .brand-mark::after { animation: none; opacity: .7; } }
.brand-text { font-weight: 650; font-size: .95rem; letter-spacing: -.01em; white-space: nowrap; }

.nav { display: flex; gap: .15rem; margin-left: auto; overflow-x: auto; scrollbar-width: none; }
.nav::-webkit-scrollbar { display: none; }
.nav a {
  display: flex; align-items: baseline; gap: .38rem;
  padding: .34rem .62rem; border-radius: 8px;
  text-decoration: none; color: var(--dim); font-size: .85rem; white-space: nowrap;
  border: 1px solid transparent; transition: color .18s, background .18s, border-color .18s;
}
.nav a:hover { color: var(--text); background: var(--surface); }
.nav a.active { color: var(--accent); border-color: color-mix(in srgb, var(--accent) 35%, transparent); background: color-mix(in srgb, var(--accent) 9%, transparent); }
.nav-n { font-family: var(--mono); font-size: .7rem; opacity: .65; }

.theme-toggle {
  flex: none; width: 34px; height: 34px; border-radius: 9px; cursor: pointer;
  background: var(--surface); border: 1px solid var(--line); display: grid; place-items: center;
}
.theme-toggle:hover { border-color: var(--accent); }
.theme-icon { width: 15px; height: 15px; border-radius: 50%; background: var(--dim);
  box-shadow: inset -4px -2px 0 0 var(--surface); transition: .2s; }
:root[data-theme="light"] .theme-icon { background: var(--amber); box-shadow: 0 0 0 2px color-mix(in srgb, var(--amber) 30%, transparent); }

@media (max-width: 760px) {
  .brand-text { display: none; }
  .topbar { gap: .6rem; }
}
@media (max-width: 420px) {
  .nav a { padding: .34rem .46rem; }
}

.progress { position: sticky; top: 47px; z-index: 49; height: 2px; background: transparent; }
.progress-bar { height: 100%; width: 0; background: linear-gradient(90deg, var(--accent), var(--amber)); transition: width .1s linear; }

/* ── layout ──────────────────────────────────────────────── */
.wrap { width: 100%; max-width: 820px; margin: 0 auto; padding: 0 clamp(1rem, 4vw, 2rem); }
.wrap-wide { max-width: 1280px; }

.section { padding: clamp(3.5rem, 9vw, 7rem) 0; position: relative; }
.section.alt { background: var(--bg-alt); border-block: 1px solid var(--line-soft); }

.hero { padding: clamp(3rem, 8vw, 6rem) 0 clamp(3rem, 8vw, 5rem); }
.eyebrow { font-family: var(--mono); font-size: .78rem; letter-spacing: .14em; text-transform: uppercase;
  color: var(--accent); margin: 0 0 1rem; }
h1 {
  margin: 0 0 1.2rem; font-size: clamp(2.1rem, 6.2vw, 3.7rem); line-height: 1.06;
  letter-spacing: -.035em; font-weight: 700;
}
h2 { margin: .2rem 0 1rem; font-size: clamp(1.7rem, 4.2vw, 2.5rem); line-height: 1.15; letter-spacing: -.028em; }
h3 { margin: 0; font-size: 1rem; letter-spacing: -.01em; }
h4 { margin: 0 0 .5rem; font-size: 1.02rem; letter-spacing: -.01em; }

.lede { font-size: clamp(1.02rem, 2.3vw, 1.2rem); color: var(--dim); max-width: 62ch; margin: 0 0 .8rem; }
.lede-sub { font-family: var(--mono); font-size: .84rem; color: var(--accent); margin: 0 0 2.4rem; }
.copy { color: var(--dim); max-width: 64ch; margin: 0 0 1.6rem; }
.copy strong, .lede strong { color: var(--text); font-weight: 620; }
.copy em, .lede em { color: var(--text); font-style: italic; }
.closing { margin-top: 2.4rem; }
.hint { font-size: .92rem; color: var(--dimmer); max-width: 62ch; margin: 1.6rem 0 0; }

.kicker { font-family: var(--mono); font-size: .76rem; letter-spacing: .13em; text-transform: uppercase;
  color: var(--dimmer); margin: 0 0 .7rem; display: flex; align-items: center; gap: .6rem; }
.kicker-n { color: var(--accent); }
.kicker::after { content: ""; flex: 1; height: 1px; background: var(--line-soft); max-width: 140px; }

/* ── panels ──────────────────────────────────────────────── */
.panel {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  box-shadow: var(--shadow); margin: 0 0 1.8rem; overflow: hidden;
}
.panel-head {
  display: flex; align-items: center; gap: .8rem; flex-wrap: wrap;
  padding: .7rem 1rem; border-bottom: 1px solid var(--line-soft); background: var(--surface-2);
}
.panel-head h3 { font-size: .86rem; font-weight: 620; color: var(--text); }
.panel-actions { margin-left: auto; display: flex; gap: .4rem; align-items: center; flex-wrap: wrap; }
.panel-note { font-size: .76rem; color: var(--dimmer); font-family: var(--mono); }

.btn {
  font: inherit; font-size: .8rem; font-weight: 560;
  padding: .36rem .74rem; border-radius: 8px; cursor: pointer;
  background: var(--surface); color: var(--dim);
  border: 1px solid var(--line); transition: .16s;
  white-space: nowrap;
}
.btn:hover:not(:disabled) { color: var(--text); border-color: var(--accent); }
.btn:disabled { opacity: .4; cursor: not-allowed; }
.btn-primary { background: color-mix(in srgb, var(--accent) 14%, var(--surface)); color: var(--accent);
  border-color: color-mix(in srgb, var(--accent) 45%, transparent); }
.btn-accent { background: color-mix(in srgb, var(--amber) 14%, var(--surface)); color: var(--amber);
  border-color: color-mix(in srgb, var(--amber) 45%, transparent); }
.btn-accent:hover:not(:disabled) { border-color: var(--amber); color: var(--amber); }

.callout {
  border-left: 3px solid var(--accent); background: var(--surface);
  border-radius: 0 var(--radius) var(--radius) 0; padding: 1.1rem 1.3rem; margin: 2rem 0 0;
}
.callout p { margin: 0; color: var(--dim); font-size: .95rem; }
.callout p + .nand-demo { margin-top: 1rem; }

svg { display: block; max-width: 100%; height: auto; }
.svg-text { font-family: var(--mono); fill: var(--dim); }

/* ── intro: von Neumann ──────────────────────────────────── */
.vn { display: grid; gap: 1rem; grid-template-columns: minmax(0, 1.55fr) minmax(0, 1fr); align-items: start; }
@media (max-width: 760px) { .vn { grid-template-columns: 1fr; } }
.vn-diagram { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  padding: .6rem; box-shadow: var(--shadow); }
.vn-detail {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 1rem 1.1rem; min-height: 150px;
}
.vn-detail h4 { color: var(--accent); font-family: var(--mono); font-size: .8rem; letter-spacing: .06em;
  text-transform: uppercase; }
.vn-detail p { margin: 0 0 .7rem; font-size: .92rem; color: var(--dim); }
.vn-detail a { font-size: .84rem; font-family: var(--mono); text-decoration: none; border-bottom: 1px solid currentColor; }
.vn-block { cursor: pointer; }
.vn-block rect { transition: fill .18s, stroke .18s; }
.vn-block:hover rect.vn-body { stroke: var(--accent); }

/* ── bits ────────────────────────────────────────────────── */
.switch-demo { padding: 1.4rem 1rem; display: grid; gap: 1rem; justify-items: center; }
.switch-demo .sw-readout { display: flex; gap: 1.6rem; align-items: center; font-family: var(--mono); font-size: .84rem; color: var(--dimmer); }
.switch-demo .sw-readout b { color: var(--accent); font-size: 1.05rem; }

.byte-demo { padding: 1.3rem 1rem 1.5rem; }
.bits-row { display: flex; gap: .4rem; justify-content: center; flex-wrap: wrap; }
.bit {
  width: 58px; border: 1px solid var(--line); background: var(--surface-2);
  border-radius: 10px; padding: .45rem .2rem .4rem; cursor: pointer; text-align: center;
  transition: .16s; font-family: var(--mono); color: var(--dimmer);
}
.bit:hover { border-color: var(--accent); }
.bit .bit-val { display: block; font-size: 1.35rem; font-weight: 600; line-height: 1.1; color: var(--off); transition: .16s; }
.bit .bit-place { display: block; font-size: .64rem; margin-top: .15rem; opacity: .8; }
.bit.on { border-color: var(--on); background: color-mix(in srgb, var(--on) 12%, var(--surface-2)); }
.bit.on .bit-val { color: var(--on); text-shadow: 0 0 14px var(--on-glow); }
.bit.on .bit-place { color: var(--on); opacity: 1; }
@media (max-width: 560px) { .bit { width: 40px; } .bit .bit-val { font-size: 1.1rem; } .bit .bit-place { font-size: .55rem; } }

.byte-readout {
  display: flex; flex-wrap: wrap; justify-content: center; gap: .55rem; margin-top: 1.3rem;
}
.chip {
  background: var(--surface-2); border: 1px solid var(--line-soft); border-radius: 9px;
  padding: .4rem .8rem; font-family: var(--mono); font-size: .8rem; color: var(--dimmer);
  display: flex; gap: .5rem; align-items: baseline;
}
.chip b { color: var(--text); font-size: .98rem; font-weight: 600; }
.chip.hero-chip b { color: var(--accent); font-size: 1.25rem; }

/* ── gates ───────────────────────────────────────────────── */
.gate-grid { display: grid; gap: 1rem; grid-template-columns: repeat(auto-fit, minmax(235px, 1fr)); }
.gate-card {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  padding: .9rem; box-shadow: var(--shadow); display: flex; flex-direction: column; gap: .7rem;
}
.gate-card h3 { font-family: var(--mono); font-size: .82rem; color: var(--accent); letter-spacing: .08em; }
.gate-card .gate-desc { font-size: .82rem; color: var(--dimmer); margin: 0; line-height: 1.45; }
.gate-svg-holder { display: grid; place-items: center; }
.tt { width: 100%; border-collapse: collapse; font-family: var(--mono); font-size: .74rem; }
.tt th, .tt td { padding: .18rem .3rem; text-align: center; border-bottom: 1px solid var(--line-soft); color: var(--dimmer); }
.tt th { color: var(--dim); font-weight: 500; font-size: .68rem; text-transform: uppercase; letter-spacing: .07em; }
.tt tr.hot td { background: color-mix(in srgb, var(--accent) 13%, transparent); color: var(--text); }
.tt tr.hot td:last-child { color: var(--accent); font-weight: 700; }
.pad { cursor: pointer; }
.pad:hover circle { stroke: var(--accent); }

.nand-demo { display: grid; gap: .9rem; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); }
.nand-card { background: var(--surface-2); border: 1px solid var(--line-soft); border-radius: 10px; padding: .7rem; }
.nand-card h5 { margin: 0 0 .35rem; font-family: var(--mono); font-size: .74rem; color: var(--dim); letter-spacing: .06em; }

/* ── adder ───────────────────────────────────────────────── */
.fa-demo { padding: 1rem; }
.fa-readout { display: flex; gap: .55rem; justify-content: center; flex-wrap: wrap; margin-top: .6rem; }

.ripple { padding: 1.2rem 1rem 1.4rem; }
.ripple-grid { display: grid; gap: .28rem; justify-content: center;
  grid-template-columns: 74px repeat(8, minmax(0, 40px)); align-items: center; }
@media (max-width: 620px) { .ripple-grid { grid-template-columns: 52px repeat(8, minmax(0, 30px)); font-size: .8rem; } }
.rp-label { font-family: var(--mono); font-size: .7rem; color: var(--dimmer); text-align: right; padding-right: .4rem;
  letter-spacing: .04em; }
.rp-cell {
  font-family: var(--mono); font-size: 1rem; text-align: center; padding: .25rem 0; border-radius: 7px;
  border: 1px solid var(--line-soft); background: var(--surface-2); color: var(--off); user-select: none;
}
.rp-cell.click { cursor: pointer; }
.rp-cell.click:hover { border-color: var(--accent); }
.rp-cell.on { color: var(--on); border-color: color-mix(in srgb, var(--on) 40%, transparent);
  background: color-mix(in srgb, var(--on) 10%, var(--surface-2)); }
.rp-cell.carry.on { color: var(--amber); border-color: color-mix(in srgb, var(--amber) 45%, transparent);
  background: color-mix(in srgb, var(--amber) 10%, var(--surface-2)); }
.rp-cell.lit { box-shadow: 0 0 0 2px var(--amber), 0 0 18px color-mix(in srgb, var(--amber) 45%, transparent); }
.rp-cell.settled { opacity: 1; }
.rp-cell.pending { opacity: .22; }
.rp-sum { border-color: var(--line); }
.ripple-foot { display: flex; justify-content: center; gap: .55rem; margin-top: 1.1rem; flex-wrap: wrap; }

/* ── memory ──────────────────────────────────────────────── */
.latch { padding: 1rem; display: grid; gap: .9rem; justify-items: center; }
.latch-btns { display: flex; gap: .6rem; }
.btn-hold {
  font: inherit; font-size: .8rem; font-weight: 600; padding: .45rem 1.3rem; border-radius: 9px;
  cursor: pointer; background: var(--surface-2); color: var(--dim); border: 1px solid var(--line);
  user-select: none; -webkit-user-select: none; touch-action: manipulation;
}
.btn-hold.pressed { background: color-mix(in srgb, var(--amber) 22%, var(--surface)); color: var(--amber);
  border-color: var(--amber); }
.latch-note { font-size: .82rem; color: var(--dimmer); text-align: center; max-width: 48ch;
  margin: 0 auto; line-height: 1.55; }

.decoder { padding: 1rem; display: grid; gap: 1rem; justify-items: center; }
.dec-addr { display: flex; gap: .45rem; align-items: center; font-family: var(--mono); font-size: .76rem; color: var(--dimmer); }

/* ── CPU ─────────────────────────────────────────────────── */
.cpu {
  display: grid; gap: 1rem;
  grid-template-columns: minmax(0, 1fr) 330px;
  grid-template-areas: "stage side" "ram side";
  align-items: start;
}
@media (max-width: 1020px) {
  .cpu { grid-template-columns: 1fr; grid-template-areas: "stage" "side" "ram"; }
}
.cpu > * { min-width: 0; }   /* let a grid item be narrower than its content */
.cpu-stage { grid-area: stage; background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--radius); box-shadow: var(--shadow); padding: .7rem .7rem .5rem; }
.cpu-side { grid-area: side; display: grid; gap: 1rem; }
.ram-wrap { grid-area: ram; background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--radius); box-shadow: var(--shadow); overflow: hidden; }

.cpu-diagram { position: relative; }
/* On a narrow screen the block diagram would shrink to unreadable type, so let
   it keep a usable width and pan instead. */
@media (max-width: 720px) {
  .cpu-diagram { overflow-x: auto; -webkit-overflow-scrolling: touch; padding-bottom: .3rem; }
  .cpu-diagram svg { min-width: 580px; }
}
.cpu-narrate {
  margin-top: .5rem; padding: .55rem .75rem; border-radius: 9px; background: var(--surface-2);
  border: 1px solid var(--line-soft); font-family: var(--mono); font-size: .8rem; color: var(--dim);
  min-height: 2.9em; display: flex; align-items: center; gap: .6rem; line-height: 1.45;
}
.cpu-narrate .t-badge { flex: none; font-size: .68rem; padding: .12rem .45rem; border-radius: 5px;
  background: color-mix(in srgb, var(--amber) 18%, transparent); color: var(--amber);
  border: 1px solid color-mix(in srgb, var(--amber) 40%, transparent); letter-spacing: .05em; }
.cpu-narrate em { color: var(--accent); font-style: normal; }

.signals { display: flex; flex-wrap: wrap; gap: .3rem; margin-top: .55rem; padding: 0 .1rem .3rem; }
.sig {
  font-family: var(--mono); font-size: .66rem; letter-spacing: .04em;
  padding: .16rem .42rem; border-radius: 5px; border: 1px solid var(--line-soft);
  background: var(--surface-2); color: var(--off); transition: .12s;
}
.sig.on { color: var(--amber); border-color: color-mix(in srgb, var(--amber) 55%, transparent);
  background: color-mix(in srgb, var(--amber) 15%, transparent);
  box-shadow: 0 0 12px color-mix(in srgb, var(--amber) 28%, transparent); }

.cpu-controls { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  padding: .8rem; display: grid; gap: .55rem; box-shadow: var(--shadow); }
.btn-row { display: grid; grid-template-columns: 1fr 1fr; gap: .5rem; }
.btn-row .btn { width: 100%; padding: .48rem .5rem; }
.slider { display: grid; gap: .3rem; }
.slider-label { display: flex; justify-content: space-between; font-family: var(--mono); font-size: .72rem;
  color: var(--dimmer); letter-spacing: .05em; text-transform: uppercase; }
.slider-val { color: var(--accent); text-transform: none; }
.slider input[type=range] { width: 100%; accent-color: var(--accent); }

.out-display {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  padding: .8rem; box-shadow: var(--shadow);
}
.out-label { font-family: var(--mono); font-size: .68rem; letter-spacing: .12em; text-transform: uppercase; color: var(--dimmer); }
.out-value {
  display: block; font-family: var(--mono); font-size: 2.6rem; font-weight: 700; line-height: 1.1;
  color: var(--amber); text-shadow: 0 0 26px color-mix(in srgb, var(--amber) 40%, transparent);
  font-variant-numeric: tabular-nums;
}
.out-log { display: flex; flex-wrap: wrap; gap: .28rem; margin-top: .45rem; max-height: 68px; overflow-y: auto; }
.out-log span { font-family: var(--mono); font-size: .7rem; padding: .08rem .35rem; border-radius: 4px;
  background: var(--surface-2); border: 1px solid var(--line-soft); color: var(--dimmer); }
.out-log span:last-child { color: var(--amber); border-color: color-mix(in srgb, var(--amber) 40%, transparent); }

.prog { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  padding: .8rem; box-shadow: var(--shadow); display: grid; gap: .55rem; }
.prog-head { display: flex; align-items: center; gap: .5rem; }
.prog-head label { font-family: var(--mono); font-size: .68rem; letter-spacing: .12em; text-transform: uppercase; color: var(--dimmer); }
.prog-head select { margin-left: auto; font: inherit; font-size: .76rem; background: var(--surface-2);
  color: var(--dim); border: 1px solid var(--line); border-radius: 7px; padding: .22rem .4rem; max-width: 60%; }
#cpu-source {
  width: 100%; font-family: var(--mono); font-size: .78rem; line-height: 1.6; resize: vertical;
  background: var(--bg-alt); color: var(--text); border: 1px solid var(--line); border-radius: 9px;
  padding: .6rem .7rem; tab-size: 6;
}
.prog-foot { display: flex; align-items: center; gap: .55rem; flex-wrap: wrap; }
.asm-status { font-family: var(--mono); font-size: .72rem; color: var(--dimmer); flex: 1 1 100%; }
.asm-status.ok { color: var(--accent); }
.asm-status.err { color: var(--rose); }

.isa summary { font-family: var(--mono); font-size: .72rem; color: var(--dim); cursor: pointer;
  letter-spacing: .05em; padding: .2rem 0; }
.isa-table { width: 100%; border-collapse: collapse; font-family: var(--mono); font-size: .7rem; margin-top: .4rem; }
.isa-table td { padding: .18rem .3rem; border-bottom: 1px solid var(--line-soft); color: var(--dimmer); vertical-align: top; }
.isa-table td:first-child { color: var(--accent); white-space: nowrap; }
.isa-table td:nth-child(2) { color: var(--dim); white-space: nowrap; }
.isa-note { font-size: .72rem; color: var(--dimmer); margin: .5rem 0 0; line-height: 1.5; }

.ram-head { padding: .7rem 1rem; border-bottom: 1px solid var(--line-soft); background: var(--surface-2);
  display: flex; align-items: center; gap: .8rem; flex-wrap: wrap; }
.ram-head h3 { font-size: .86rem; }
.ram-legend { margin: 0 0 0 auto; font-family: var(--mono); font-size: .7rem; color: var(--dimmer);
  display: flex; align-items: center; gap: .35rem; flex-wrap: wrap; }
.lg { width: 10px; height: 10px; border-radius: 3px; display: inline-block; }
.lg-pc { background: color-mix(in srgb, var(--accent) 60%, transparent); border: 1px solid var(--accent); }
.lg-mar { background: color-mix(in srgb, var(--amber) 55%, transparent); border: 1px solid var(--amber); margin-left: .6rem; }
.ram-hint { margin-left: .8rem; opacity: .75; }

.ram { display: grid; grid-template-columns: repeat(4, 1fr); gap: 1px; background: var(--line-soft); padding: 1px; }
@media (max-width: 620px) { .ram { grid-template-columns: repeat(2, 1fr); } }
.cell {
  background: var(--surface); padding: .5rem .55rem; display: grid; gap: .1rem;
  border: 1px solid transparent; transition: background .2s, border-color .2s;
}
.cell-top { display: flex; align-items: baseline; gap: .45rem; }
.cell-addr { font-family: var(--mono); font-size: .66rem; color: var(--dimmer); }
.cell-dis { font-family: var(--mono); font-size: .74rem; color: var(--dim); margin-left: auto; }
.cell-dis.data { color: var(--dimmer); opacity: .85; }
.cell-bits { font-family: var(--mono); font-size: .8rem; letter-spacing: .06em; color: var(--text); cursor: pointer;
  border-bottom: 1px dashed transparent; justify-self: start; }
.cell-bits:hover { border-bottom-color: var(--accent); }
.cell-bits .nib { opacity: .55; }
.cell input {
  font-family: var(--mono); font-size: .78rem; width: 100%; background: var(--bg-alt); color: var(--text);
  border: 1px solid var(--accent); border-radius: 5px; padding: .05rem .25rem;
}
.cell.is-pc { background: color-mix(in srgb, var(--accent) 11%, var(--surface));
  border-color: color-mix(in srgb, var(--accent) 45%, transparent); }
.cell.is-mar { background: color-mix(in srgb, var(--amber) 12%, var(--surface));
  border-color: color-mix(in srgb, var(--amber) 55%, transparent); }
.cell.is-pc.is-mar { background: linear-gradient(135deg,
  color-mix(in srgb, var(--accent) 14%, var(--surface)) 0 50%,
  color-mix(in srgb, var(--amber) 14%, var(--surface)) 50% 100%); }
.cell.flash { animation: cellflash .6s ease-out; }
@keyframes cellflash { from { background: color-mix(in srgb, var(--rose) 40%, var(--surface)); } }

/* CPU svg bits */
.reg-box rect.reg-body { transition: stroke .15s, fill .15s; }
.reg-box.active rect.reg-body { stroke: var(--amber); fill: color-mix(in srgb, var(--amber) 14%, var(--surface-2)); }
.reg-box.src rect.reg-body { stroke: var(--accent); fill: color-mix(in srgb, var(--accent) 14%, var(--surface-2)); }
.bus-rail { transition: fill .15s; }
.bus-rail.hot { fill: color-mix(in srgb, var(--amber) 26%, transparent); }

/* ── latency ─────────────────────────────────────────────── */
.latency { padding: 1.1rem 1rem 1.3rem; display: grid; gap: .45rem; }
.lat-row {
  display: grid; grid-template-columns: 138px minmax(0, 1fr) auto; gap: .6rem; align-items: center;
  cursor: pointer; padding: .2rem .25rem; border-radius: 8px; transition: background .15s;
}
.lat-row:hover, .lat-row.open { background: var(--surface-2); }
.lat-name { font-family: var(--mono); font-size: .76rem; color: var(--dim); white-space: nowrap; }
.lat-track { height: 16px; background: var(--surface-2); border: 1px solid var(--line-soft); border-radius: 5px; overflow: hidden; }
.lat-fill { height: 100%; width: 0; border-radius: 4px; transition: width .9s cubic-bezier(.22,.9,.3,1); }
.lat-human { font-family: var(--mono); font-size: .76rem; color: var(--amber); white-space: nowrap; font-variant-numeric: tabular-nums; }
.lat-detail { grid-column: 1 / -1; font-size: .82rem; color: var(--dimmer); padding: .1rem .25rem .5rem 138px;
  display: none; line-height: 1.5; }
@media (max-width: 620px) {
  .lat-row { grid-template-columns: 84px minmax(0, 1fr) auto; }
  .lat-name { font-size: .68rem; }
  .lat-human { font-size: .68rem; }
  .lat-detail { padding-left: .25rem; }
}
.lat-row.open + .lat-detail, .lat-detail.open { display: block; }
.lat-real { color: var(--dim); font-family: var(--mono); }

/* ── tower ───────────────────────────────────────────────── */
.tower { display: grid; gap: .3rem; margin: 0 0 1rem; }
.floor {
  display: grid; grid-template-columns: 30px 1fr auto; gap: .8rem; align-items: center;
  background: var(--surface); border: 1px solid var(--line); border-radius: 10px;
  padding: .62rem .85rem; cursor: pointer; text-align: left; font: inherit; color: var(--text);
  transition: .18s; width: 100%;
}
.floor:hover { border-color: var(--accent); transform: translateX(3px); }
.floor.open { border-color: var(--accent); background: color-mix(in srgb, var(--accent) 8%, var(--surface)); }
.floor-n { font-family: var(--mono); font-size: .7rem; color: var(--dimmer); }
.floor-t { font-weight: 600; font-size: .95rem; }
.floor-s { font-family: var(--mono); font-size: .7rem; color: var(--dimmer); text-align: right; }
.floor-body { font-size: .9rem; color: var(--dim); padding: .1rem .9rem .8rem 3.5rem; margin: -.15rem 0 .2rem;
  line-height: 1.55; }
.floor-body a { font-family: var(--mono); font-size: .8rem; }
.is-hidden { display: none !important; }
@media (max-width: 560px) {
  .floor { grid-template-columns: 24px 1fr; }
  .floor-s { display: none; }
  .floor-body { padding-left: 1rem; }
}

/* ── footer ──────────────────────────────────────────────── */
.footer { border-top: 1px solid var(--line-soft); padding: 2.5rem 0 3rem; background: var(--bg-alt); position: relative; z-index: 1; }
.footer p { color: var(--dimmer); font-size: .86rem; max-width: 62ch; margin: 0 0 .7rem; }
.footer-meta a { font-family: var(--mono); font-size: .8rem; }

/* ── reveal ──────────────────────────────────────────────── */
.reveal { opacity: 0; transform: translateY(18px); transition: opacity .6s ease, transform .6s ease; }
.reveal.shown { opacity: 1; transform: none; }
@media (prefers-reduced-motion: reduce) {
  .reveal { opacity: 1; transform: none; transition: none; }
  .lat-fill { transition: none; }
  .floor:hover { transform: none; }
}

/* ── shared across pages ─────────────────────────────────── */
.wrap-mid { max-width: 1040px; }

.nav a.nav-page {
  color: var(--violet);
  border-color: color-mix(in srgb, var(--violet) 40%, transparent);
  background: color-mix(in srgb, var(--violet) 8%, transparent);
}
.nav a.nav-page:hover { color: var(--text); border-color: var(--violet); }
.nav a.nav-page::after { content: "\2197"; font-size: .72rem; margin-left: .1rem; }
.nav a.nav-back::after { content: none; }
.nav a.nav-back::before { content: "\2190"; font-size: .72rem; margin-right: .1rem; }

.next-part {
  display: grid; gap: .25rem; margin-top: 2.2rem; padding: 1.3rem 1.4rem;
  border: 1px solid color-mix(in srgb, var(--violet) 45%, transparent);
  border-radius: var(--radius); text-decoration: none; color: var(--text);
  background:
    radial-gradient(120% 140% at 100% 0%, color-mix(in srgb, var(--violet) 16%, transparent), transparent 60%),
    var(--surface);
  box-shadow: var(--shadow); transition: border-color .18s, transform .18s;
}
.next-part:hover { border-color: var(--violet); transform: translateY(-2px); }
.next-kicker { font-family: var(--mono); font-size: .72rem; letter-spacing: .12em; text-transform: uppercase; color: var(--violet); }
.next-title { font-size: 1.35rem; font-weight: 700; letter-spacing: -.02em; }
.next-title::after { content: " \2192"; color: var(--violet); }
.next-sub { color: var(--dim); font-size: .92rem; }
@media (prefers-reduced-motion: reduce) { .next-part:hover { transform: none; } }
