:root {
  --bg: #000000;
  --surface: #0d1117;
  --surface-2: #161b22;
  --border: #21262d;
  --text: #e8ecf4;
  --muted: #8b95a8;
  --accent: #6ea8ff;
  --accent-dim: #3d5a8a;
  --rail: #3d4558;
  --success: #4ade80;
  --amber: #fbbf24;
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html {
  font-size: 16px;
  -webkit-font-smoothing: antialiased;
}

body {
  margin: 0;
  min-height: 100vh;
  font-family: "IBM Plex Sans", system-ui, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.55;
}

.app {
  display: grid;
  grid-template-columns: minmax(148px, 188px) minmax(0, 1fr);
  min-height: 100vh;
}

@media (max-width: 900px) {
  .app {
    grid-template-columns: 1fr;
  }
  .rail {
    position: sticky;
    top: 0;
    z-index: 10;
  }
}

.rail {
  background: var(--bg);
  padding: 1.25rem 0.65rem 2rem 0.75rem;
  min-width: 0;
}

.rail h1 {
  font-size: 0.95rem;
  font-weight: 600;
  letter-spacing: 0.02em;
  margin: 0 0 0.35rem;
  color: var(--text);
}

.rail .subtitle {
  font-size: 0.78rem;
  color: var(--muted);
  margin: 0 0 1.25rem;
  line-height: 1.4;
}

.steps {
  display: flex;
  flex-direction: column;
  gap: 0;
}

.step-btn {
  display: flex;
  align-items: flex-start;
  gap: 0.65rem;
  width: 100%;
  padding: 0.55rem 0.5rem;
  margin: 0;
  border: none;
  border-radius: 8px;
  background: transparent;
  color: var(--muted);
  font: inherit;
  text-align: left;
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
}

.step-btn:hover {
  background: rgba(255, 255, 255, 0.04);
  color: var(--text);
}

.step-btn[aria-current="true"] {
  background: rgba(255, 255, 255, 0.06);
  color: var(--text);
}

.step-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  margin-top: 0.35rem;
  flex-shrink: 0;
  background: var(--rail);
  border: 2px solid var(--border);
}

.step-btn[aria-current="true"] .step-dot {
  background: var(--accent);
  border-color: var(--accent-dim);
  box-shadow: 0 0 0 2px rgba(110, 168, 255, 0.25);
}

.step-meta {
  display: flex;
  flex-direction: column;
  gap: 0.15rem;
}

.step-num {
  font-size: 0.7rem;
  font-weight: 600;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

.step-btn[aria-current="true"] .step-num {
  color: var(--accent);
}

.step-title {
  font-size: 0.82rem;
  font-weight: 500;
  line-height: 1.3;
}

/* Was max-width 920px left-aligned in a wide column → huge empty band on the right.
   Center the column and allow a bit more line length on large screens. */
main {
  justify-self: center;
  width: 100%;
  max-width: min(1180px, 100%);
  min-width: 0;
  /* ~3× prior horizontal inset: was clamp(1rem, 3vw, 2rem) */
  padding: 1.25rem clamp(3rem, 9vw, 6rem) 2.5rem;
  background: var(--bg);
}

.panel {
  display: none;
  animation: fade 0.25s ease;
}

.panel.is-active {
  display: block;
}

@keyframes fade {
  from {
    opacity: 0;
    transform: translateY(6px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

/* One flat column on the black canvas — no inset “card” panel */
.card {
  background: transparent;
  border: none;
  border-radius: 0;
  box-shadow: none;
  overflow: visible;
}

.card-header {
  padding: 0 0 0.85rem;
  margin: 0 0 1rem;
  background: none;
}

.card-kicker {
  font-size: 0.72rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--accent);
  margin: 0 0 0.35rem;
}

.card h2 {
  font-size: 1.2rem;
  font-weight: 600;
  margin: 0;
  letter-spacing: -0.02em;
  color: var(--text);
}

.card-body {
  padding: 0;
}

.card-body p {
  margin: 0 0 0.85rem;
  color: #8b949e;
  font-size: 0.94rem;
}

.card-body p:last-child {
  margin-bottom: 0;
}

/* Bridge from the previous step — slightly brighter than body copy */
.card-body p.step-handoff {
  color: var(--text);
  font-size: 0.97rem;
  line-height: 1.55;
  margin-bottom: 1.05rem;
  max-width: 52em;
}

.card-body p.step-handoff + .step-subhead {
  margin-top: 0.45rem;
}

/* Inline math — small horizontal cushion so equations don’t collide with prose */
.card-body p .katex {
  margin: 0 0.12em;
}

.step-subhead {
  font-size: 0.95rem;
  font-weight: 600;
  margin: 0 0 0.5rem;
  color: var(--text);
  letter-spacing: -0.01em;
}

.card-body .step-subhead:not(:first-child) {
  margin-top: 1.35rem;
}

.figure {
  margin: 1rem 0;
  border-radius: 8px;
  overflow: hidden;
  border: 1px solid var(--border);
  background: #000;
}

.figure img {
  display: block;
  width: 100%;
  height: auto;
  vertical-align: middle;
}

.figure-caption {
  font-size: 0.78rem;
  color: var(--muted);
  margin-top: 0.5rem;
}

.figure-row {
  display: grid;
  gap: 1rem;
}

@media (min-width: 640px) {
  .figure-row.two {
    grid-template-columns: 1fr 1fr;
    align-items: start;
  }
}

.math-block {
  margin: 0.85rem 0 1.15rem;
  padding: 0.95rem 0.65rem 1rem 1.2rem;
  background: transparent;
  border-radius: 0;
  border: none;
  overflow-x: auto;
  text-align: left;
}

/* KaTeX defaults to centered display math — looks like a tiny island in a wide column */
.math-block .katex-display {
  display: block;
  margin: 0.4rem 0 0.25rem;
  text-align: left;
}

.math-block .katex-display > .katex {
  font-size: clamp(1.05em, 2.4vw, 1.28em);
  text-align: left;
}

/* Breathing room around relations (=) and binary ops (+, −) inside display blocks */
.math-block .katex .mrel {
  padding: 0 0.14em;
}

.math-block .katex .mbin {
  padding: 0 0.18em;
}

.math-block .katex-display .tag {
  text-align: left;
}

.math-block--tight {
  margin: 0.5rem 0 0.7rem;
}

/*
 * Step 5 pressure derivation: default .math-block KaTeX uses em-based sizing on ~1rem body → tiny next to prose.
 * Match the “featured equation” weight of Step 1 .term-eq-line / Step 4 .prediction-eq-line (rem-scale + padded band).
 */
#panel-5 .step5-color-key {
  margin: 0.35rem 0 0.85rem;
  font-size: 0.95rem;
}

#panel-5 .math-block {
  margin: 1rem 0 1.2rem;
  padding: 1.15rem 1.1rem 1.25rem 1.35rem;
  background: rgba(110, 168, 255, 0.06);
  border-radius: 8px;
  border: none;
}

#panel-5 .math-block .katex-display {
  margin: 0.35rem 0;
}

#panel-5 .math-block .katex-display > .katex {
  font-size: clamp(1.3rem, 1rem + 2.4vw, 2.05rem);
  line-height: 1.38;
}

.solid-edge-diagram {
  margin: 1.1rem 0 1.45rem;
  padding: 1rem 1rem 1.15rem;
  background: rgba(110, 168, 255, 0.05);
  border-radius: 10px;
  border: 1px solid rgba(110, 168, 255, 0.14);
}

.solid-edge-diagram__label {
  font-size: 0.92rem;
  font-weight: 600;
  color: #c8d0e0;
  margin-bottom: 0.2rem;
}

.solid-edge-diagram__arrow {
  text-align: center;
  color: #f87171;
  font-size: 1.45rem;
  line-height: 1.15;
  margin: 0.2rem 0 0.35rem;
  font-weight: 600;
}

#panel-6 .solid-edge-diagram .math-block {
  margin: 0.35rem 0 0;
  padding: 0.85rem 0.95rem 0.95rem 1rem;
}

#panel-6 .solid-edge-diagram .math-block .katex-display > .katex {
  font-size: clamp(1.05rem, 0.85rem + 1.6vw, 1.65rem);
}

/* Step 6: solid-wall math, then code — stacked rows (not side-by-side) */
.solid-neighbor-stack {
  display: flex;
  flex-direction: column;
  gap: 1.5rem;
  margin: 1rem 0 1.35rem;
  align-items: stretch;
}

.solid-neighbor-stack__math .solid-edge-diagram {
  margin: 0;
}

.solid-neighbor-stack__title {
  margin: 0 0 0.45rem;
  font-size: 0.98rem;
  font-weight: 600;
  color: #d6deec;
  letter-spacing: 0.02em;
}

.solid-neighbor-stack__lead {
  margin: 0 0 0.75rem;
  font-size: 0.88rem;
  line-height: 1.55;
  color: #a8b4cc;
}

.solid-neighbor-stack__lead code {
  font-size: 0.84em;
  padding: 0.1em 0.35em;
  border-radius: 4px;
  background: rgba(110, 168, 255, 0.1);
  color: #c8d8f0;
}

.solid-neighbor-stack__code pre.code {
  margin: 0;
  max-height: min(70vh, 28rem);
  overflow: auto;
  font-size: 0.78rem;
  line-height: 1.45;
}

@media (min-width: 960px) {
  .solid-neighbor-stack__code pre.code {
    font-size: 0.8rem;
  }
}

.const-pill {
  color: #6ee7b7;
  font-weight: 500;
}

.callout {
  margin-top: 1rem;
  padding: 0.75rem 0 0.75rem 1rem;
  border-radius: 0;
  border: none;
  background: transparent;
  font-size: 0.86rem;
  color: #e3b341;
}

.callout strong {
  color: #fef3c7;
}

.callout--stagger-note {
  margin-top: 1.15rem;
  line-height: 1.55;
}

pre.code {
  margin: 1rem 0;
  padding: 1rem 0;
  background: transparent;
  border-radius: 0;
  border: none;
  overflow-x: auto;
  font-family: "IBM Plex Mono", ui-monospace, monospace;
  font-size: 0.78rem;
  line-height: 1.5;
  color: #d1d9e8;
}

pre.code .kw {
  color: #c792ea;
}
pre.code .type {
  color: #82aaff;
}
pre.code .fn {
  color: #89ddff;
}

pre.code .str {
  color: #c3e88d;
}

/* Step 2: one-cell figure (left) + MAC grid code (right) */
.one-cell-split {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  gap: 1rem 1.25rem;
  margin: 0 0 1.25rem;
  padding-top: 1.35rem;
}

.one-cell-split__figure {
  min-width: 0;
}

.one-cell-split .mac-grid-code-block {
  margin: 0;
}

.one-cell-split .panel-one-cell-figure {
  margin-top: 0;
  padding-top: 0;
  border-top: none;
}

@media (max-width: 900px) {
  .one-cell-split {
    grid-template-columns: 1fr;
  }
}

.mac-grid-code-block {
  margin: 1.1rem 0 1.25rem;
}

.incomp-split__code {
  min-width: 0;
  display: flex;
  flex-direction: column;
}

.incomp-split__code-kicker {
  margin: 0 0 0.45rem;
  font-size: 0.72rem;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--muted);
}

pre.code.code--panel {
  margin: 0;
  flex: 1;
  padding: 1rem 1rem 1.05rem 1.1rem;
  border-radius: 8px;
  border: 1px solid rgba(255, 255, 255, 0.08);
  background: linear-gradient(165deg, rgba(22, 27, 38, 0.98) 0%, rgba(12, 14, 20, 0.99) 100%);
  box-shadow: 0 12px 32px rgba(0, 0, 0, 0.35), inset 0 1px 0 rgba(255, 255, 255, 0.04);
  font-size: 0.76rem;
  line-height: 1.52;
  color: #d6dce8;
}

pre.code.code--panel .cmt {
  color: #6b7a90;
  font-style: italic;
}

pre.code.code--panel.code--panel--inline {
  margin: 1rem 0 1.15rem;
}

.step-subhead--tight {
  margin-top: 1.35rem;
}

/* Step 3: Per-cell divergence + debug — prose left, code right */
.mac-step-split {
  display: flex;
  flex-direction: column;
  gap: 1.5rem;
  margin: 1.1rem 0 1.35rem;
}

.mac-step-split__row {
  display: grid;
  gap: 1rem 1.35rem;
  align-items: start;
}

@media (min-width: 900px) {
  .mac-step-split__row {
    grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  }
}

@media (max-width: 899px) {
  .mac-step-split__row {
    grid-template-columns: 1fr;
  }
}

.mac-step-split__copy {
  min-width: 0;
}

.mac-step-split__copy .step-subhead {
  margin-top: 0;
}

.mac-step-split__copy p:last-child {
  margin-bottom: 0;
}

.mac-step-split__row:not(:first-child) .step-subhead--tight {
  margin-top: 0;
}

.mac-step-split .mac-step-split__pre {
  margin: 0;
  min-width: 0;
  max-height: min(70vh, 30rem);
  overflow: auto;
}

.mac-demo-toolbar {
  margin-top: 0.75rem;
}

.mac-demo-toolbar--colors {
  align-items: center;
  margin-top: 0.35rem;
}

.mac-color-label {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  font-size: 0.82rem;
  color: var(--muted);
}

.mac-color-label input[type="color"] {
  width: 2.25rem;
  height: 1.5rem;
  padding: 0;
  border: 1px solid var(--border);
  border-radius: 4px;
  background: transparent;
  cursor: pointer;
}

.mac-check-label {
  display: inline-flex;
  align-items: center;
  gap: 0.45rem;
  font-size: 0.82rem;
  color: var(--muted);
}

.kbd {
  display: inline-block;
  padding: 0.1em 0.45em;
  font-size: 0.85em;
  font-family: "IBM Plex Mono", ui-monospace, monospace;
  border: 1px solid var(--border);
  border-radius: 4px;
  background: rgba(255, 255, 255, 0.06);
}

.toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.75rem 1.25rem;
  margin-top: 1rem;
}

.toolbar label {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.82rem;
  color: var(--muted);
}

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

.scroll-next-hint {
  display: flex;
  justify-content: center;
  padding: 2.25rem 1rem 3rem;
  margin-top: 1.5rem;
}

.scroll-next-hint__box {
  display: inline-flex;
  align-items: center;
  gap: 0.65rem;
  padding: 0.65rem 1.1rem;
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.02);
  color: #9aa3b0;
  font-size: 0.82rem;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s;
}

.scroll-next-hint__box:hover {
  background: rgba(255, 255, 255, 0.05);
  border-color: rgba(255, 255, 255, 0.2);
}

.scroll-next-hint__box:focus-visible {
  outline: 2px solid var(--accent-dim);
  outline-offset: 3px;
}

.scroll-next-hint__arrow {
  flex-shrink: 0;
  opacity: 0.55;
  color: var(--accent);
}

.scroll-next-hint__text {
  font-weight: 500;
  letter-spacing: 0.02em;
}

.nav-footer {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 1rem;
  margin-top: 1.5rem;
  padding-top: 1rem;
}

.btn {
  appearance: none;
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text);
  font: inherit;
  font-size: 0.88rem;
  padding: 0.5rem 1rem;
  border-radius: 8px;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s;
}

.btn:hover:not(:disabled) {
  background: #222a38;
  border-color: var(--accent-dim);
}

.btn:disabled {
  opacity: 0.35;
  cursor: not-allowed;
}

.btn-primary {
  background: var(--accent-dim);
  border-color: var(--accent);
  color: #fff;
}

.btn-primary:hover:not(:disabled) {
  background: #4a6fa8;
}

kbd {
  font-family: inherit;
  font-size: 0.75rem;
  padding: 0.1rem 0.35rem;
  border-radius: 4px;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--muted);
}

.hint {
  font-size: 0.8rem;
  color: var(--muted);
}

canvas.demo-canvas {
  display: block;
  width: 100%;
  max-width: 420px;
  height: auto;
  margin: 0.75rem 0;
  border-radius: 0;
  border: none;
  background: #000;
}

pre.code .muted {
  color: #6b7a90;
}

pre.code .cmt {
  color: #5c6370;
  font-style: italic;
}

pre.code .num {
  color: #f78c6c;
}

.math-block--wide {
  max-width: 100%;
  /* Long two-row aligned block: a bit more vertical padding so it doesn’t feel cramped vs. the page */
  padding-top: 0.85rem;
  padding-bottom: 0.9rem;
}

/* Compressible reference block (step 1) */
.math-block.math-block--wide .katex-display > .katex {
  font-size: clamp(1.02em, 2.35vw, 1.32em);
}

.bullet-tight {
  margin: 0.75rem 0 0;
  padding-left: 1.2rem;
  color: #8b949e;
  font-size: 0.92rem;
}

.bullet-tight li {
  margin-bottom: 0.35rem;
}

.mt-1 {
  margin-top: 1rem;
}

/* Step 1: interactive equation cards (hover terms) */
.term-explore-card {
  margin: 1.25rem 0;
  padding: 1rem 1.1rem 1.1rem;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: rgba(255, 255, 255, 0.02);
}

.term-explore-invite {
  margin: 0 0 0.85rem;
  font-size: 0.82rem;
  color: var(--muted);
}

.term-eq-line {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.55rem 0.85rem;
  justify-content: center;
  padding: 1.15rem 1rem 1.4rem;
  /* Large readable equation */
  font-size: clamp(1.45rem, 4vw, 2.15rem);
  line-height: 1.42;
}

.term-eq-op {
  color: #8b949e;
  font-weight: 600;
  font-size: 0.92em;
  user-select: none;
  padding: 0 0.1em;
}

.term-eq-line--div {
  padding: 0.95rem 1rem 1.1rem;
  font-size: clamp(1.35rem, 3.6vw, 1.95rem);
}

.term-eq-op--zero {
  font-size: 1em;
}

/* Hoverable symbols (including inside fractions) */
.eq-atom {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0.2rem 0.35rem;
  margin: 0.08rem 0;
  border-radius: 8px;
  cursor: help;
  outline: none;
  transition: background 0.15s, box-shadow 0.15s;
  border-bottom: 3px solid transparent;
}

.eq-atom:hover,
.eq-atom:focus-visible {
  background: rgba(110, 168, 255, 0.1);
  border-bottom-color: var(--accent);
}

.eq-atom--acc:hover,
.eq-atom--acc:focus-visible {
  background: rgba(251, 191, 36, 0.12);
  border-bottom-color: #fbbf24;
}

.eq-atom--pres:hover,
.eq-atom--pres:focus-visible {
  background: rgba(110, 168, 255, 0.15);
  border-bottom-color: #6ea8ff;
}

.eq-atom--ext:hover,
.eq-atom--ext:focus-visible {
  background: rgba(74, 222, 128, 0.12);
  border-bottom-color: #4ade80;
}

.eq-atom--visc:hover,
.eq-atom--visc:focus-visible {
  background: rgba(251, 113, 133, 0.12);
  border-bottom-color: #fb7185;
}

.eq-atom .katex {
  font-size: 1em;
  color: var(--text);
}

.eq-atom .katex .mord,
.eq-atom .katex .mop,
.eq-atom .katex .mrel {
  color: inherit;
}

.term-title-plain {
  font-size: 1.1em;
  font-weight: 600;
  color: var(--text);
}

/* Whole-term hover (fractions + viscous cluster) */
.term-hit {
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0.2rem 0.45rem;
  margin: 0.08rem 0;
  border-radius: 8px;
  cursor: help;
  outline: none;
  transition: background 0.15s, box-shadow 0.15s;
  border-bottom: 3px solid transparent;
}

.term-hit--omit-active::after {
  content: "✕";
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: clamp(1.15rem, 2.8vw, 1.65rem);
  font-weight: 700;
  color: rgba(248, 113, 113, 0.95);
  pointer-events: none;
  text-shadow: 0 0 8px rgba(0, 0, 0, 0.9), 0 0 2px rgba(0, 0, 0, 1);
  z-index: 2;
}

.term-hit--pres:hover,
.term-hit--pres:focus-visible {
  background: rgba(110, 168, 255, 0.15);
  border-bottom-color: #6ea8ff;
}

.term-hit--ext:hover,
.term-hit--ext:focus-visible {
  background: rgba(74, 222, 128, 0.12);
  border-bottom-color: #4ade80;
}

.term-hit--visc:hover,
.term-hit--visc:focus-visible {
  background: rgba(251, 113, 133, 0.12);
  border-bottom-color: #fb7185;
}

.term-hit--omit-active:hover,
.term-hit--omit-active:focus-visible {
  background: rgba(248, 113, 113, 0.14) !important;
  border-bottom-color: #f87171 !important;
}

.term-hit--incomp:hover,
.term-hit--incomp:focus-visible {
  background: rgba(147, 197, 253, 0.1);
  border-bottom-color: #93c5fd;
}

.term-hit--incomp .katex {
  color: var(--text);
}

.eq-piece--minus {
  padding-right: 0.06em;
  font-weight: 500;
  color: var(--text);
}

.eq-piece {
  display: inline-flex;
  align-items: baseline;
  justify-content: center;
  pointer-events: none;
  padding: 0 0.04em;
}

.eq-piece .katex {
  font-size: 1em;
  color: var(--text);
}

.eq-piece .katex .mord,
.eq-piece .katex .mop,
.eq-piece .katex .mrel {
  color: inherit;
}

.term-cluster {
  display: inline-flex;
  align-items: center;
  vertical-align: middle;
}

.frac {
  display: inline-flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  vertical-align: middle;
  line-height: 1.05;
}

.frac-num {
  display: inline-flex;
  align-items: baseline;
  justify-content: center;
  gap: 0.03em;
  flex-wrap: nowrap;
}

.frac-bar {
  width: 100%;
  min-width: 2.2em;
  height: 0.055em;
  background: currentColor;
  opacity: 0.88;
  margin: 0.14em 0 0.11em;
  border-radius: 1px;
}

.frac-den {
  display: flex;
  justify-content: center;
  align-items: center;
}

.term-cluster--visc {
  display: inline-flex;
  align-items: baseline;
  gap: 0.26em;
  flex-wrap: wrap;
  justify-content: center;
}

.term-explore-readout {
  min-height: 8rem;
  padding: 0.75rem 0 0;
  margin: 0;
  font-size: 0.88rem;
  line-height: 1.5;
  color: #c5cedd;
}

.term-explore-default {
  margin: 0;
  font-size: 0.82rem;
  color: var(--muted);
  font-style: italic;
}

.term-explore-header {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 0.35rem 0.5rem;
  margin-bottom: 0.5rem;
}

.term-explore-label {
  font-size: 0.78rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--accent);
}

.term-explore-readout--omit .term-explore-label {
  color: #f87171;
}

.term-explore-body p.term-explore-note--omit {
  color: #fecaca;
  padding-left: 0;
  margin-top: 0.65rem;
}

.term-explore-body p {
  margin: 0;
  color: #c5cedd;
}

.term-explore-body p + p {
  margin-top: 0.55rem;
}

/* Step 4: five-cell pressure stencil + prediction equation */
.mac-stencil-figure {
  margin: 1.25rem auto 1.5rem;
  max-width: 320px;
}

.mac-stencil-caption {
  margin: 0.75rem 0 0;
  font-size: 0.82rem;
  line-height: 1.5;
  color: var(--muted);
  text-align: center;
}

.mac-stencil {
  position: relative;
  width: 100%;
  max-width: 320px;
  margin: 0 auto;
}

.mac-stencil-svg {
  width: 100%;
  height: auto;
  display: block;
}

.mac-stencil-rect--nb {
  fill: rgba(30, 58, 95, 0.88);
  stroke: rgba(100, 130, 180, 0.45);
  stroke-width: 1;
}

.mac-stencil-rect--c {
  fill: rgba(99, 102, 241, 0.82);
  stroke: rgba(165, 180, 252, 0.55);
  stroke-width: 1;
}

.mac-stencil-label {
  position: absolute;
  transform: translate(-50%, -50%);
  pointer-events: none;
  font-size: clamp(0.88rem, 2.8vw, 1.05rem);
  color: #93c5fd;
}

.mac-stencil-label .katex {
  color: inherit !important;
}

.mac-stencil-label--u {
  font-size: clamp(0.78rem, 2.4vw, 0.95rem);
  color: #fdba74;
}

.mac-stencil-label--pT {
  left: 48.125%;
  top: 21.25%;
}

.mac-stencil-label--pL {
  left: 20.625%;
  top: 50%;
}

.mac-stencil-label--pC {
  left: 48.125%;
  top: 50%;
}

.mac-stencil-label--pR {
  left: 75.625%;
  top: 50%;
}

.mac-stencil-label--pB {
  left: 48.125%;
  top: 77.5%;
}

.mac-stencil-label--uT {
  left: 48.125%;
  top: 35%;
}

.mac-stencil-label--uB {
  left: 48.125%;
  top: 62.5%;
}

.mac-stencil-label--uL {
  left: 34.375%;
  top: 50%;
}

.mac-stencil-label--uR {
  left: 61.875%;
  top: 50%;
}

/* Must beat `.card-body p { font-size: 0.94rem }` — that rule was shrinking this hero line */
.card-body p.prediction-eq-line {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  justify-content: center;
  gap: 0.5rem 0.75rem;
  margin: 1.15rem 0 1.25rem;
  font-size: clamp(1.75rem, 1.15rem + 3.2vw, 2.85rem);
  line-height: 1.2;
  color: var(--text);
}

.card-body p.prediction-eq-line .eq-piece .katex {
  color: inherit !important;
  font-size: 1em;
}

.card-body p.prediction-eq-line .eq-piece--v {
  color: #f472b6;
}

.card-body p.prediction-eq-line .eq-piece--u {
  color: #fdba74;
}

.card-body p.prediction-eq-line .eq-piece--a {
  color: #fbbf24;
}

.card-body p.prediction-eq-line .eq-piece--dt {
  color: #6ee7b7;
}

.card-body p.prediction-eq-line .eq-piece--op {
  color: #e8ecf4;
}

.bilin-pair {
  display: flex;
  flex-wrap: wrap;
  gap: 0.65rem 1rem;
  align-items: flex-start;
  justify-content: center;
  margin: 0.35rem 0 0.2rem;
}

.bilin-pair__col {
  flex: 1 1 320px;
  max-width: min(960px, 100%);
  min-width: min(100%, 280px);
}

.bilin-pair__label {
  margin: 0 0 0.2rem;
  font-size: 0.82rem;
  font-weight: 600;
  color: var(--muted);
}

.bilin-pair__readout {
  margin-top: 0.2rem;
}

.bilin-toolbar {
  margin: 0.4rem 0 0.25rem;
}

/* Step 8 bilinear pair: each canvas 1120×1280 bitmap */
#bilin-canvas-interp,
#bilin-canvas-solver {
  display: block;
  max-width: min(960px, 100%);
  width: 100%;
  height: auto;
  margin: 0.2rem auto;
}

/* Tighter readout under each canvas (overrides .gs-sweep-readout spacing) */
#panel-8 .bilin-pair .gs-sweep-readout {
  margin: 0.15rem 0 0.1rem;
  padding: 0.12rem 0 0.08rem;
}

#panel-8 p.hint {
  margin-top: 0.45rem;
}

/* Pull demo block closer to the prose above (avoid huge margin collapse with last paragraph) */
#panel-8 .card-body p:has(+ .bilin-toolbar) {
  margin-bottom: 0.45rem;
}

#panel-8 #h-8-viz {
  margin-top: 0.95rem;
}

.gs-sweep-toolbar {
  margin: 0.75rem 0 0.5rem;
}

.gs-sweep-toolbar input[type="range"] {
  width: min(240px, 52vw);
}

.gs-sweep-readout {
  margin: 0.45rem 0 0.85rem;
  padding: 0.4rem 0;
  font-family: "IBM Plex Mono", ui-monospace, monospace;
  font-size: 0.82rem;
  line-height: 1.45;
  color: #a8b8d8;
}

.stats-row {
  margin: 0.5rem 0 0.75rem;
  padding: 0.35rem 0;
  background: transparent;
  border-radius: 0;
  border: none;
  font-size: 0.8rem;
  color: #a8b8d8;
  font-family: "IBM Plex Mono", ui-monospace, monospace;
}

.demo-canvas--wide {
  max-width: 480px;
}

/* Step 6 Gauss–Seidel sweep: 2× bitmap (1120×640) vs 560×320 */
#gs-sweep-canvas {
  display: block;
  max-width: min(960px, 100%);
  width: 100%;
  height: auto;
  margin-left: auto;
  margin-right: auto;
}

/* Step 7 pressure projection demo */
#proj-demo-canvas {
  display: block;
  max-width: min(960px, 100%);
  width: 100%;
  height: auto;
  margin-left: auto;
  margin-right: auto;
}

/* Step 3 MAC demo: 2× bitmap vs previous 560×320; allow ~2× display width */
#mac-grid-canvas {
  display: block;
  max-width: min(960px, 100%);
  width: 100%;
  height: auto;
  margin-left: auto;
  margin-right: auto;
  touch-action: none;
}

/* Single-cell flux figure: no frame — sits centered in the card */
canvas.demo-canvas.demo-canvas--single-cell {
  max-width: min(440px, 100%);
  margin: 1rem auto;
  border: none;
  background: transparent;
  outline: none;
}

canvas.demo-canvas.demo-canvas--single-cell:focus-visible {
  outline: 2px solid var(--accent-dim);
  outline-offset: 3px;
}

/* Step 2 (one cell): separate figure block from prose; KaTeX in paragraphs is rendered when panel becomes visible */
.panel-one-cell-figure {
  margin-top: 1.5rem;
  padding-top: 1.35rem;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.65rem;
  width: 100%;
}

#panel-2 .card-body > p {
  margin-bottom: 1rem;
}

#panel-2 .card-body > .one-cell-split {
  margin-top: 1.65rem;
}

.mac-cell-caption {
  margin: 0 auto 0.15rem;
  max-width: min(440px, 100%);
  font-size: 0.88rem;
  line-height: 1.5;
  color: #c5cedd;
  text-align: center;
}

.mac-cell-caption + canvas.demo-canvas--single-cell {
  margin-top: 0.35rem;
}

.mac-cell-legend {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.65rem 1.25rem;
  margin: 0.75rem auto 0;
  max-width: min(440px, 100%);
  font-size: 0.8rem;
  line-height: 1.45;
  color: var(--muted);
}

.mac-cell-legend-sign {
  grid-column: 1 / -1;
  margin: 0.15rem 0 0;
  font-size: 0.78rem;
  line-height: 1.4;
  opacity: 0.95;
}

@media (max-width: 420px) {
  .mac-cell-legend {
    grid-template-columns: 1fr;
  }
}

.mac-cell-legend-col--red strong {
  color: #f87171;
}

.mac-cell-legend-col--green strong {
  color: #4ade80;
}

/* ── Course dropdown nav ── */
.course-dropdown {
  position: relative;
  margin: 0 0 0.35rem;
}

.course-dropdown__toggle {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  width: 100%;
  padding: 0;
  border: none;
  background: transparent;
  color: var(--text);
  font: 600 0.95rem/1.3 "IBM Plex Sans", system-ui, sans-serif;
  letter-spacing: 0.02em;
  cursor: pointer;
  transition: color 0.15s;
}

.course-dropdown__toggle:hover {
  color: var(--accent);
}

.course-dropdown__chevron {
  width: 14px;
  height: 14px;
  flex-shrink: 0;
  opacity: 0.5;
  transition: transform 0.2s, opacity 0.2s;
}

.course-dropdown.is-open .course-dropdown__chevron {
  transform: rotate(180deg);
  opacity: 0.8;
}

.course-dropdown__menu {
  display: none;
  position: absolute;
  top: calc(100% + 4px);
  left: -4px;
  min-width: 200px;
  padding: 4px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--surface-2);
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.5);
  z-index: 100;
  list-style: none;
  margin: 0;
}

.course-dropdown.is-open .course-dropdown__menu {
  display: block;
  animation: fade 0.15s ease;
}

.course-dropdown__item {
  display: block;
  width: 100%;
  padding: 0.5rem 0.65rem;
  border: none;
  border-radius: 6px;
  background: transparent;
  color: var(--muted);
  font: 500 0.82rem/1.3 "IBM Plex Sans", system-ui, sans-serif;
  text-align: left;
  text-decoration: none;
  cursor: pointer;
  transition: background 0.12s, color 0.12s;
}

.course-dropdown__item:hover {
  background: rgba(255, 255, 255, 0.06);
  color: var(--text);
}

.course-dropdown__item[aria-current="page"] {
  color: var(--text);
  background: rgba(255, 255, 255, 0.04);
}

/* ── Boid-specific styles ── */
.boid-split {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  gap: 1rem 1.25rem;
  margin: 0 0 1.25rem;
  padding-top: 1.35rem;
}

/* Steps 1 & 2: same column balance as default .boid-split (zoom is applied on the figure, not via wider grid). */
.boid-split--canvas-tools {
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  align-items: start;
}

@media (max-width: 900px) {
  .boid-split {
    grid-template-columns: 1fr;
  }

  .boid-split--canvas-tools {
    grid-template-columns: 1fr;
  }
}

.boid-split__figure {
  min-width: 0;
}

/*
 * Steps 1–2: magnify the 560×560 boid canvases with CSS zoom (bitmap stays original size).
 * Not the same as widening the grid column or doubling canvas width attributes.
 */
.boid-split__figure--boid-zoom {
  zoom: 2;
  justify-self: center;
}

@media (max-width: 900px) {
  .boid-split__figure--boid-zoom {
    zoom: 1.35;
    justify-self: stretch;
  }
}

.boid-split__code {
  min-width: 0;
  display: flex;
  flex-direction: column;
}

.boid-split__code--controls {
  padding-top: 0.25rem;
}

.boid-eq-row {
  margin: 0 0 1rem;
}

.boid-eq-row .term-explore-card {
  margin: 0;
}

.boid-kernel-split {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  gap: 1rem 1.25rem;
  align-items: start;
  margin: 0.75rem 0 1.25rem;
}

.boid-kernel-split__prose p {
  margin: 0;
  font-size: 0.95rem;
  line-height: 1.55;
}

.boid-kernel-split__code {
  margin: 0;
  max-height: min(70vh, 28rem);
  overflow: auto;
}

@media (max-width: 900px) {
  .boid-kernel-split {
    grid-template-columns: 1fr;
  }
}

.boid-invite {
  margin: 0.75rem 0 0.25rem;
  padding: 0.55rem 0.75rem;
  border-radius: 6px;
  font-size: 0.88rem;
  line-height: 1.45;
  color: #fbbf24;
  background: rgba(251, 191, 36, 0.08);
  border: 1px solid rgba(251, 191, 36, 0.22);
}

.boid-split__code-kicker {
  margin: 0 0 0.45rem;
  font-size: 0.72rem;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--muted);
}

canvas.demo-canvas--boid {
  width: 100%;
  max-width: 100%;
  height: auto;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: #050608;
}

canvas.demo-canvas--tank {
  width: 100%;
  max-width: 100%;
  height: auto;
  display: block;
}

.boid-tank-wrap {
  margin: 0.75rem 0 0.75rem;
}

.boid-tank-wrap canvas {
  width: 100%;
  max-width: 100%;
  height: auto;
  display: block;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: #050608;
}

.boid-controls {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem 1.5rem;
  margin: 0.75rem 0 0;
  padding: 0.65rem 0.75rem;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--surface);
}

.boid-controls--tank {
  margin-top: 0.35rem;
}

.boid-control {
  display: flex;
  flex-direction: column;
  gap: 0.2rem;
  min-width: 120px;
}

.boid-control label {
  font-size: 0.72rem;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--muted);
}

.boid-control input[type="range"] {
  width: 100%;
  accent-color: var(--accent);
}

.boid-control .boid-control__value {
  font-size: 0.72rem;
  color: var(--muted);
  text-align: right;
}

.boid-control--toggle {
  flex-direction: row;
  align-items: center;
  gap: 0.5rem;
  min-width: auto;
}

.boid-control--toggle label {
  text-transform: none;
  font-weight: 500;
  font-size: 0.78rem;
}

/* Side-by-side equation pair */
.boid-eq-pair {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1rem;
  margin: 1.25rem 0;
}

@media (max-width: 900px) {
  .boid-eq-pair {
    grid-template-columns: 1fr;
  }
}

.boid-eq-pair .term-explore-card {
  margin: 0;
}

/* KaTeX equation line — proper baseline alignment */
.term-eq-line--katex {
  display: flex;
  align-items: baseline;
  gap: 0.3em;
  flex-wrap: wrap;
  padding: 1rem 0 0.5rem;
  justify-content: center;
}

.term-eq-line--katex .term-hit {
  display: inline-flex;
  align-items: baseline;
}

.term-eq-line--katex .eq-plain {
  display: inline;
  line-height: 1;
}

/* Compact equation cards for stacking in right column */
.term-explore-card--compact {
  margin: 0 0 0.65rem;
  padding: 0.65rem 0.85rem 0.75rem;
}

.term-explore-card--compact .term-explore-invite {
  font-size: 0.72rem;
  margin-bottom: 0.25rem;
}

.term-explore-card--compact .term-explore-readout {
  font-size: 0.82rem;
}

.term-explore-card--compact .term-explore-default {
  font-size: 0.82rem;
  line-height: 1.4;
}

/* Step 1/2 controls (stacked in right column) */
.boid-step1-controls {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem 1.5rem;
  margin: 0.5rem 0 0.75rem;
  padding: 0.65rem 0.75rem;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--surface);
}

.boid-step1-controls--stack {
  flex-direction: column;
  flex-wrap: nowrap;
  align-items: stretch;
  width: 100%;
  margin-top: 0;
  margin-bottom: 0;
}

.boid-step1-controls--stack .boid-control {
  width: 100%;
  min-width: 0;
}

/* Boid rules list (intro step) */
.boid-rules-list {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  margin: 1.25rem 0;
}

.boid-rule {
  display: flex;
  align-items: flex-start;
  gap: 0.85rem;
  padding: 0.85rem 1rem;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: rgba(255, 255, 255, 0.02);
}

.boid-rule__num {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  flex-shrink: 0;
  border-radius: 50%;
  background: var(--accent-dim);
  color: var(--accent);
  font-weight: 700;
  font-size: 0.82rem;
}

.boid-rule__body {
  font-size: 0.92rem;
  line-height: 1.5;
}

.boid-rule__body strong {
  color: var(--accent);
}

/* Rule groups — toggle + slider stacked */
.boid-rule-group {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
  padding: 0.4rem 0.6rem;
  border-radius: 6px;
  border: 1px solid rgba(255, 255, 255, 0.04);
  background: rgba(255, 255, 255, 0.015);
}

.boid-rule-group--disabled .boid-rule-group__slider {
  opacity: 0.3;
  pointer-events: none;
}

.boid-rule-group__slider {
  transition: opacity 0.2s;
}

.boid-rule-group__slider label {
  font-size: 0.68rem;
}

/* Set to Fibonacci button */
.boid-btn {
  display: inline-block;
  padding: 0.4rem 0.75rem;
  border: 1px solid var(--accent-dim);
  border-radius: 6px;
  background: rgba(110, 168, 255, 0.08);
  color: var(--accent);
  font: 600 0.76rem/1 "IBM Plex Sans", system-ui, sans-serif;
  letter-spacing: 0.03em;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s;
}

.boid-btn:hover {
  background: rgba(110, 168, 255, 0.16);
  border-color: var(--accent);
}

/* 3D canvas orbit hint */
.sphere-orbit-hint {
  margin: 0.35rem 0 0;
  font-size: 0.72rem;
  color: var(--muted);
  text-align: center;
  opacity: 0.6;
  letter-spacing: 0.04em;
}
