/* ==========================================================================
   Quantitative Collatz Descent — site design system
   Ink-on-paper academic typography with a single accent. Light/dark aware.
   ========================================================================== */

:root {
  --paper:        #fcfbf9;
  --paper-raised: #ffffff;
  --paper-sunk:   #f3f1ec;
  --rule:         #e2ddd3;
  --rule-strong:  #cfc8ba;
  --ink:          #1a1a1c;
  --ink-soft:     #4a4a52;
  --ink-faint:    #7a7a85;
  --accent:       #4c3bcf;
  --accent-soft:  #ece9fb;
  --accent-ink:   #372aa0;
  --good:         #1c7a4a;
  --good-soft:    #e4f4ec;
  --warn:         #a8641a;
  --warn-soft:    #fbf0e2;

  --serif: "Iowan Old Style", "Palatino Linotype", Palatino, Charter,
           "Source Serif 4", Georgia, serif;
  --sans:  ui-sans-serif, -apple-system, BlinkMacSystemFont, "Segoe UI",
           Inter, Roboto, Helvetica, Arial, sans-serif;
  --mono:  ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas,
           "Liberation Mono", monospace;

  --measure: 34rem;
  --wide: 60rem;
  --radius: 10px;
  --shadow: 0 1px 2px rgba(20,18,14,.05), 0 8px 28px -12px rgba(20,18,14,.18);
}

@media (prefers-color-scheme: dark) {
  :root {
    --paper:        #131316;
    --paper-raised: #1b1b20;
    --paper-sunk:   #0e0e11;
    --rule:         #2c2c34;
    --rule-strong:  #3d3d47;
    --ink:          #eceaf0;
    --ink-soft:     #b3b1bd;
    --ink-faint:    #82808d;
    --accent:       #a99bff;
    --accent-soft:  #221d45;
    --accent-ink:   #c5baff;
    --good:         #5fd39b;
    --good-soft:    #122b20;
    --warn:         #e0a862;
    --warn-soft:    #2e2213;
    --shadow: 0 1px 2px rgba(0,0,0,.4), 0 8px 28px -12px rgba(0,0,0,.7);
  }
}

:root[data-theme="light"] {
  --paper:#fcfbf9; --paper-raised:#fff; --paper-sunk:#f3f1ec; --rule:#e2ddd3;
  --rule-strong:#cfc8ba; --ink:#1a1a1c; --ink-soft:#4a4a52; --ink-faint:#7a7a85;
  --accent:#4c3bcf; --accent-soft:#ece9fb; --accent-ink:#372aa0;
  --good:#1c7a4a; --good-soft:#e4f4ec; --warn:#a8641a; --warn-soft:#fbf0e2;
  --shadow: 0 1px 2px rgba(20,18,14,.05), 0 8px 28px -12px rgba(20,18,14,.18);
}
:root[data-theme="dark"] {
  --paper:#131316; --paper-raised:#1b1b20; --paper-sunk:#0e0e11; --rule:#2c2c34;
  --rule-strong:#3d3d47; --ink:#eceaf0; --ink-soft:#b3b1bd; --ink-faint:#82808d;
  --accent:#a99bff; --accent-soft:#221d45; --accent-ink:#c5baff;
  --good:#5fd39b; --good-soft:#122b20; --warn:#e0a862; --warn-soft:#2e2213;
  --shadow: 0 1px 2px rgba(0,0,0,.4), 0 8px 28px -12px rgba(0,0,0,.7);
}

* { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; scroll-behavior: smooth; }
@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
  *, *::before, *::after { animation-duration: .01ms !important; transition-duration: .01ms !important; }
}

body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font-family: var(--serif);
  font-size: 1.0625rem;
  line-height: 1.7;
  overflow-x: hidden;
  text-rendering: optimizeLegibility;
}

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

.wrap { width: min(100% - 2.5rem, var(--wide)); margin-inline: auto; }
.col  { width: min(100%, var(--measure)); margin-inline: auto; }
.wrap > .col { margin-inline: auto; }

main section { padding-block: clamp(2.5rem, 6vw, 4.5rem); }
main section + section { border-top: 1px solid var(--rule); }
main section[id] { scroll-margin-top: 4.5rem; }

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

.masthead {
  position: sticky; top: 0; z-index: 50;
  background: color-mix(in srgb, var(--paper) 88%, transparent);
  backdrop-filter: saturate(1.6) blur(10px);
  border-bottom: 1px solid var(--rule);
}
.masthead .wrap {
  display: flex; align-items: center; gap: 1.25rem;
  min-height: 3.5rem; font-family: var(--sans); font-size: .8125rem;
}
.masthead a.brand {
  font-weight: 650; letter-spacing: -.01em; color: var(--ink);
  text-decoration: none; margin-right: auto;
}
.masthead nav { display: flex; gap: 1.1rem; align-items: center; }
.masthead nav a { color: var(--ink-soft); text-decoration: none; }
.masthead nav a:hover, .masthead nav a[aria-current="page"] { color: var(--accent); }
.theme-toggle {
  background: none; border: 1px solid var(--rule-strong); color: var(--ink-soft);
  border-radius: 6px; width: 2rem; height: 2rem; cursor: pointer; font-size: .9rem;
  display: grid; place-items: center; padding: 0;
}
.theme-toggle:hover { border-color: var(--accent); color: var(--accent); }
@media (max-width: 34rem) { .masthead nav a.opt { display: none; } }

/* ---------- in-page navigation ---------- */

.page-rail { display: none; }
.section-links a {
  color: var(--ink-faint); text-decoration: none;
  font: 500 .75rem/1.35 var(--sans);
  transition: color .15s, border-color .15s, background .15s;
}
.section-links a:hover { color: var(--accent); }
.section-links a[aria-current="location"] {
  color: var(--accent); font-weight: 650;
}

.section-menu {
  position: sticky; top: 3.5rem; z-index: 45;
  margin: 0; background: color-mix(in srgb, var(--paper) 94%, transparent);
  backdrop-filter: saturate(1.4) blur(10px);
  border-bottom: 1px solid var(--rule); font-family: var(--sans);
}
.section-menu summary {
  width: min(100% - 2.5rem, var(--wide)); margin-inline: auto;
  padding: .55rem 0; cursor: pointer; color: var(--ink-soft);
  font-size: .75rem; font-weight: 650; list-style: none;
}
.section-menu summary::-webkit-details-marker { display: none; }
.section-menu summary::after {
  content: "▾"; float: right; color: var(--accent);
  transition: transform .15s;
}
.section-menu[open] summary::after { transform: rotate(180deg); }
.section-menu .section-links {
  width: min(100% - 2.5rem, var(--wide)); max-height: min(65vh, 28rem);
  margin: 0 auto; padding: .25rem 0 .8rem; overflow-y: auto;
  display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: .25rem;
}
.section-menu .section-links a {
  padding: .45rem .55rem; border-radius: 6px;
}
.section-menu .section-links a:hover,
.section-menu .section-links a[aria-current="location"] {
  background: var(--accent-soft);
}

@media (min-width: 72rem) {
  .section-menu { display: none; }
  main { padding-left: clamp(0rem, calc(86rem - 100vw), 14rem); }
  .page-rail {
    display: block; position: fixed; z-index: 35; top: 5.1rem;
    left: max(1rem, calc(50vw - 42rem)); width: 10.5rem;
    max-height: calc(100vh - 6.5rem); overflow-y: auto;
    padding: .25rem .4rem .5rem 0; scrollbar-width: thin;
  }
  .page-rail > p {
    margin: 0 0 .55rem .8rem; color: var(--ink-faint);
    font: 650 .65rem/1.2 var(--sans); letter-spacing: .08em;
    text-transform: uppercase;
  }
  .page-rail .section-links { display: grid; gap: .12rem; }
  .page-rail .section-links a {
    display: block; padding: .35rem .5rem .35rem .7rem;
    border-left: 2px solid var(--rule); border-radius: 0 5px 5px 0;
  }
  .page-rail .section-links a:hover {
    border-left-color: var(--rule-strong); background: var(--paper-sunk);
  }
  .page-rail .section-links a[aria-current="location"] {
    border-left-color: var(--accent); background: var(--accent-soft);
  }
}

@media (max-width: 31rem) {
  .section-menu .section-links { grid-template-columns: 1fr; }
}

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

.hero { padding-block: clamp(3rem, 9vw, 6rem) clamp(2rem, 5vw, 3.5rem); }
.eyebrow {
  font-family: var(--sans); font-size: .75rem; font-weight: 600;
  letter-spacing: .09em; text-transform: uppercase; color: var(--accent);
  margin: 0 0 1.1rem;
}
h1 {
  font-size: clamp(2rem, 5.2vw, 3.15rem); line-height: 1.1; letter-spacing: -.022em;
  font-weight: 600; margin: 0 0 1.25rem; max-width: 20ch;
}
.hero .paper-title {
  max-width: 24ch;
  font-size: clamp(1.8rem, 4.4vw, 2.72rem);
  line-height: 1.14;
}
.tagline {
  font-size: clamp(1.15rem, 2.4vw, 1.4rem); line-height: 1.5; color: var(--ink-soft);
  margin: 0 0 2rem; max-width: 46ch;
}
.tagline strong { color: var(--ink); font-weight: 600; }
.byline {
  font-family: var(--sans); font-size: .875rem; color: var(--ink-faint);
  display: flex; flex-wrap: wrap; gap: .5rem 1.25rem; align-items: center;
  margin-bottom: 2rem;
}
.byline a { color: var(--ink-soft); }

/* ---------- beginner orbit primer ---------- */

.primer-section {
  background:
    radial-gradient(circle at 12% 18%, color-mix(in srgb, var(--accent) 9%, transparent), transparent 34rem),
    var(--paper);
}
.collatz-primer {
  display: grid; grid-template-columns: minmax(15rem, .8fr) minmax(0, 1.35fr);
  align-items: start; gap: clamp(1.5rem, 5vw, 4rem);
}
.primer-heading { padding-top: .65rem; }
.primer-heading h2 { max-width: 14ch; }
.primer-heading .lede { margin-bottom: 0; }
.primer-console {
  min-width: 0; padding: clamp(1rem, 3vw, 1.45rem);
  background: var(--paper-raised); border: 1px solid var(--rule);
  border-radius: var(--radius); box-shadow: var(--shadow);
}
.map-toggle {
  display: inline-flex; max-width: 100%; gap: .25rem; padding: .25rem;
  background: var(--paper-sunk); border: 1px solid var(--rule);
  border-radius: 8px; font-family: var(--sans);
}
.map-option {
  min-width: 0; cursor: pointer; border: 0; border-radius: 6px;
  padding: .48rem .68rem; color: var(--ink-faint); background: transparent;
  font: 600 .72rem/1.35 var(--sans); text-align: center;
}
.map-option[aria-pressed="true"] {
  color: var(--accent); background: var(--paper-raised);
  box-shadow: 0 1px 4px color-mix(in srgb, var(--ink) 12%, transparent);
}
.primer-form { margin-top: 1rem; }
.primer-form > label {
  display: flex; justify-content: space-between; align-items: baseline; gap: 1rem;
  margin-bottom: .35rem; color: var(--ink-soft);
  font: 650 .8rem/1.4 var(--sans);
}
.primer-form label small { color: var(--ink-faint); font-weight: 450; }
.primer-input-row {
  display: grid; grid-template-columns: minmax(0, 1fr) auto auto;
  align-items: stretch; gap: .5rem;
}
.primer-input-row input {
  min-width: 0; width: 100%; padding: .6rem .72rem;
  border: 1px solid var(--rule-strong); border-radius: 7px;
  color: var(--ink); background: var(--paper-sunk);
  font: 600 .9rem var(--mono); font-variant-numeric: tabular-nums;
}
.primer-input-row .btn { justify-content: center; cursor: pointer; }
.primer-input-row .btn:disabled { cursor: default; opacity: .45; }
.primer-examples {
  display: flex; flex-wrap: wrap; align-items: center; gap: .38rem;
  margin-top: .7rem; color: var(--ink-faint); font: .7rem var(--sans);
}
.primer-examples button {
  cursor: pointer; padding: .2rem .5rem; border-radius: 99px;
  border: 1px solid var(--rule); color: var(--ink-soft);
  background: var(--paper-sunk); font: 600 .7rem var(--mono);
}
.primer-examples button:hover { border-color: var(--accent); color: var(--accent); }
.primer-map-note {
  margin: .85rem 0 .45rem; color: var(--ink-faint);
  font: .72rem/1.5 var(--sans);
}
.primer-summary {
  min-height: 2.1rem; margin: 0 0 .65rem; color: var(--ink-soft);
  font: 600 .78rem/1.5 var(--sans); font-variant-numeric: tabular-nums;
}
.primer-summary.success { color: var(--good); }
.primer-summary.stopped,
.primer-summary.error { color: var(--warn); }
.chain-window {
  min-height: 8.5rem; max-height: 22rem; overflow: auto;
  padding: .9rem; border: 1px solid var(--rule); border-radius: 8px;
  background:
    linear-gradient(90deg, color-mix(in srgb, var(--rule) 36%, transparent) 1px, transparent 1px),
    linear-gradient(color-mix(in srgb, var(--rule) 36%, transparent) 1px, transparent 1px),
    var(--paper-sunk);
  background-size: 18px 18px;
  scrollbar-width: thin;
}
.collatz-chain {
  display: flex; flex-wrap: wrap; align-items: center; gap: .48rem .38rem;
  list-style: none; margin: 0; padding: 0;
}
.chain-step {
  display: inline-flex; align-items: center; gap: .35rem; max-width: 100%;
  margin: 0; opacity: 0; transform: translateY(5px);
  transition: opacity .18s ease, transform .18s ease;
}
.chain-step.is-visible { opacity: 1; transform: none; }
.chain-arrow { color: var(--ink-faint); font: 600 .78rem var(--sans); }
.chain-op {
  padding: .12rem .35rem; border-radius: 99px;
  color: var(--ink-faint); background: var(--paper-raised);
  border: 1px solid var(--rule); font: 600 .58rem/1.25 var(--mono);
}
.chain-value {
  max-width: 100%; overflow-wrap: anywhere; padding: .32rem .52rem;
  border: 1px solid var(--rule-strong); border-radius: 6px;
  color: var(--ink); background: var(--paper-raised);
  font: 650 .78rem/1.25 var(--mono); font-variant-numeric: tabular-nums;
}
.chain-step.is-peak .chain-value { border-color: var(--warn); color: var(--warn); }
.chain-step.is-one .chain-value {
  border-color: var(--good); color: var(--good); background: var(--good-soft);
}
.chain-gap {
  color: var(--ink-faint); font: 650 .7rem/1.4 var(--sans); margin: 0 .25rem;
  opacity: 0; transform: translateY(5px);
  transition: opacity .18s ease, transform .18s ease;
}
.chain-gap.is-visible { opacity: 1; transform: none; }
.primer-caveat {
  margin: .8rem 0 0; color: var(--ink-faint); font: .7rem/1.55 var(--sans);
}
@media (max-width: 47rem) {
  .collatz-primer { grid-template-columns: 1fr; gap: 1.25rem; }
  .primer-heading { width: min(100%, var(--measure)); }
  .primer-heading h2 { max-width: none; }
}
@media (max-width: 34rem) {
  .map-toggle { display: grid; width: 100%; }
  .primer-form > label { display: grid; gap: .1rem; }
  .primer-input-row { grid-template-columns: 1fr 1fr; }
  .primer-input-row input { grid-column: 1 / -1; }
}
@media (prefers-reduced-motion: reduce) {
  .chain-step,
  .chain-gap { opacity: 1; transform: none; transition: none; }
}

/* ---------- buttons ---------- */

.actions { display: flex; flex-wrap: wrap; gap: .75rem; }
.btn {
  font-family: var(--sans); font-size: .875rem; font-weight: 550;
  display: inline-flex; align-items: center; gap: .5rem;
  padding: .6rem 1.05rem; border-radius: 8px; text-decoration: none;
  border: 1px solid var(--rule-strong); color: var(--ink); background: var(--paper-raised);
  transition: border-color .15s, transform .15s, background .15s;
}
.btn:hover { border-color: var(--accent); transform: translateY(-1px); }
.btn-primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn-primary:hover { background: var(--accent-ink); border-color: var(--accent-ink); color: #fff; }
@media (prefers-color-scheme: dark) {
  .btn-primary, .btn-primary:hover { color: #16121f; }
}
:root[data-theme="dark"] .btn-primary,
:root[data-theme="dark"] .btn-primary:hover { color: #16121f; }
:root[data-theme="light"] .btn-primary,
:root[data-theme="light"] .btn-primary:hover { color: #fff; }

/* ---------- typography ---------- */

h2 {
  font-size: clamp(1.5rem, 3vw, 1.95rem); line-height: 1.2; letter-spacing: -.017em;
  font-weight: 600; margin: 0 0 1rem; max-width: 24ch;
}
h3 {
  font-size: 1.2rem; line-height: 1.3; letter-spacing: -.01em; font-weight: 600;
  margin: 2.25rem 0 .6rem;
}
h4 { font-family: var(--sans); font-size: .9rem; font-weight: 650; margin: 1.75rem 0 .5rem; }
p { margin: 0 0 1.15rem; }
.lede { font-size: 1.15rem; color: var(--ink-soft); margin-bottom: 1.75rem; }
a { color: var(--accent); text-decoration-thickness: 1px; text-underline-offset: 2px; }
strong { font-weight: 650; }
ul, ol { margin: 0 0 1.15rem; padding-left: 1.35rem; }
li { margin-bottom: .5rem; }
li::marker { color: var(--ink-faint); }
code {
  font-family: var(--mono); font-size: .875em;
  background: var(--paper-sunk); padding: .12em .38em; border-radius: 4px;
  border: 1px solid var(--rule);
}
pre {
  font-family: var(--mono); font-size: .8125rem; line-height: 1.6;
  background: var(--paper-sunk); border: 1px solid var(--rule);
  border-radius: var(--radius); padding: 1rem 1.15rem; overflow-x: auto; margin: 0 0 1.5rem;
}
pre code { background: none; border: 0; padding: 0; font-size: inherit; }
hr { border: 0; border-top: 1px solid var(--rule); margin: 2.5rem 0; }

/* ---------- callouts ---------- */

.card {
  background: var(--paper-raised); border: 1px solid var(--rule);
  border-radius: var(--radius); padding: 1.35rem 1.5rem; box-shadow: var(--shadow);
}
.theorem {
  background: var(--paper-raised); border: 1px solid var(--rule);
  border-left: 3px solid var(--accent); border-radius: var(--radius);
  padding: 1.35rem 1.5rem; margin: 0 0 1.75rem; box-shadow: var(--shadow);
}
.theorem .label {
  font-family: var(--sans); font-size: .7rem; font-weight: 650; letter-spacing: .08em;
  text-transform: uppercase; color: var(--accent); display: block; margin-bottom: .6rem;
}
.theorem p:last-child { margin-bottom: 0; }

.note {
  background: var(--paper-sunk); border: 1px solid var(--rule);
  border-radius: var(--radius); padding: 1.1rem 1.3rem; margin: 0 0 1.75rem;
  font-size: .95rem; color: var(--ink-soft);
}
.note strong { color: var(--ink); }
.note.caution { background: var(--warn-soft); border-color: color-mix(in srgb, var(--warn) 35%, transparent); }
.note.caution strong { color: var(--warn); }
.note p:last-child { margin-bottom: 0; }

/* ---------- fundamentals + proof architecture ---------- */

.fundamentals-grid {
  width: min(100%, var(--wide)); margin: 2rem auto 1.5rem;
  display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 1rem;
}
.fundamental-card {
  position: relative; min-width: 0; padding: 1.35rem 1.5rem 1.25rem;
  background: var(--paper-raised); border: 1px solid var(--rule);
  border-radius: var(--radius); box-shadow: var(--shadow);
}
.fundamental-card h3 { margin: .15rem 0 .7rem; }
.fundamental-card p { font-size: .96rem; color: var(--ink-soft); }
.fundamental-card mjx-container[display="true"] { margin: .85rem 0 !important; }
.concept-figure {
  margin: .9rem 0 1rem; overflow: hidden;
  background: var(--paper-sunk); border: 1px solid var(--rule);
  border-radius: 8px;
}
.concept-figure svg {
  display: block; width: 100%; height: auto; color: var(--ink-soft);
}
.concept-figure figcaption {
  margin: 0; padding: .55rem .75rem .6rem; border-top: 1px solid var(--rule);
  color: var(--ink-faint); font: 550 .68rem/1.45 var(--sans);
}
.concept-figure .concept-label,
.concept-figure .concept-main-label,
.concept-figure .concept-bit-label {
  font-family: var(--sans); fill: var(--ink-faint);
}
.concept-figure .concept-label { font-size: 10px; }
.concept-figure .concept-main-label { font-size: 12px; font-weight: 650; fill: var(--ink-soft); }
.concept-figure .concept-bit-label {
  font: 650 13px var(--mono); text-anchor: middle; fill: var(--ink-soft);
}
.concept-figure .concept-good-text { fill: var(--good); }
.concept-figure .concept-warn-text { fill: var(--warn); }
.concept-figure .concept-accent-text { fill: var(--accent); }
.concept-rule,
.concept-divider,
.concept-clock,
.concept-chip {
  fill: none; stroke: var(--rule-strong); stroke-width: 1.2;
}
.concept-dashed { stroke-dasharray: 4 4; }
.concept-divider { stroke-dasharray: 2 4; }
.concept-chip { fill: var(--paper-raised); }
.concept-trace {
  fill: none; stroke: var(--accent); stroke-width: 2.2;
  stroke-linecap: round; stroke-linejoin: round;
}
.concept-draw {
  stroke-dasharray: 1; stroke-dashoffset: 1;
  animation: concept-draw 6s cubic-bezier(.4,0,.2,1) infinite;
}
.concept-point { fill: var(--good); stroke: var(--paper-raised); stroke-width: 2; }
.concept-small-point { fill: var(--accent); }
.concept-pulse {
  transform-box: fill-box; transform-origin: center;
  animation: concept-pulse 3.2s ease-in-out infinite;
}
.delay-1 { animation-delay: .35s; }
.delay-2 { animation-delay: .7s; }
.delay-3 { animation-delay: 1.05s; }
.concept-direct {
  fill: none; stroke: var(--good); stroke-width: 1.35; stroke-dasharray: 4 4;
}
.concept-arrow,
.concept-arrow-head {
  fill: none; stroke: var(--ink-faint); stroke-width: 1.4;
  stroke-linecap: round; stroke-linejoin: round;
}
.concept-bit {
  fill: var(--paper-raised); stroke: var(--rule-strong); stroke-width: 1.1;
  animation: concept-bit 6s ease-in-out infinite;
}
.bit-delay-1 { animation-delay: 0s; }
.bit-delay-2 { animation-delay: .18s; }
.bit-delay-3 { animation-delay: .36s; }
.bit-delay-4 { animation-delay: .54s; }
.bit-delay-5 { animation-delay: .72s; }
.bit-delay-6 { animation-delay: .9s; }
.concept-envelope {
  fill: none; stroke: var(--warn); stroke-width: 1.4; stroke-dasharray: 4 3;
}
.concept-clock { fill: var(--paper-raised); }
.concept-clock-fill {
  fill: var(--warn); opacity: .52; transform-box: fill-box; transform-origin: left center;
  animation: concept-clock 6s ease-in-out infinite;
}
.concept-timeout-tick { stroke: var(--warn); stroke-width: 2; }
.concept-source-dots circle { fill: var(--rule-strong); }
.concept-source-dots .bad { fill: var(--accent); }
.concept-target-bad { fill: var(--accent); stroke: var(--paper-raised); stroke-width: 2; }
.concept-flow {
  fill: none; stroke: var(--accent); stroke-width: 1.4;
  stroke-dasharray: 5 5; animation: concept-flow 3.2s linear infinite;
}
.concept-ceiling { stroke: var(--warn); stroke-width: 1.5; stroke-dasharray: 5 3; }
.concept-witness-line { stroke: var(--good); stroke-width: 1.2; stroke-dasharray: 3 3; }
.concept-after {
  fill: none; stroke: var(--ink-faint); stroke-width: 1.5;
  stroke-dasharray: 3 4; opacity: .48;
}
@keyframes concept-draw {
  0%, 9% { stroke-dashoffset: 1; }
  42%, 100% { stroke-dashoffset: 0; }
}
@keyframes concept-pulse {
  0%, 100% { transform: scale(.86); opacity: .72; }
  50% { transform: scale(1.18); opacity: 1; }
}
@keyframes concept-bit {
  0%, 15%, 55%, 100% { fill: var(--paper-raised); stroke: var(--rule-strong); }
  24%, 40% { fill: var(--accent-soft); stroke: var(--accent); }
}
@keyframes concept-clock {
  0%, 10% { transform: scaleX(.04); opacity: .3; }
  52%, 100% { transform: scaleX(1); opacity: .58; }
}
@keyframes concept-flow { to { stroke-dashoffset: 20; } }
@media (prefers-reduced-motion: reduce) {
  .concept-draw,
  .concept-pulse,
  .concept-bit,
  .concept-clock-fill,
  .concept-flow {
    animation: none !important; transform: none; opacity: 1;
  }
  .concept-draw { stroke-dashoffset: 0; }
}
.concept-number {
  display: block; color: var(--accent); font: 650 .68rem var(--mono);
  letter-spacing: .06em;
}
.fundamental-card .concept-use {
  margin: .9rem 0 0; padding-top: .75rem; border-top: 1px solid var(--rule);
  color: var(--ink-faint); font: .78rem/1.55 var(--sans);
}
.concept-use strong { color: var(--ink-soft); }

.literature-table {
  width: min(100%, var(--wide)); margin: 2rem auto 1.5rem;
  background: var(--paper-raised); box-shadow: var(--shadow);
}
.literature-table table { min-width: 48rem; table-layout: fixed; }
.literature-table caption {
  padding: .75rem .85rem; text-align: left; color: var(--ink-faint);
  background: var(--paper-sunk); border-bottom: 1px solid var(--rule);
  font: 550 .72rem/1.4 var(--sans);
}
.literature-table th,
.literature-table td {
  padding: .9rem 1rem; vertical-align: top; white-space: normal; line-height: 1.55;
}
.literature-table thead th:nth-child(1) { width: 19%; }
.literature-table thead th:nth-child(2) { width: 38%; }
.literature-table tbody th {
  color: var(--ink); font: 650 .8rem/1.5 var(--sans);
}
.literature-table tbody td { color: var(--ink-soft); }
.literature-table .literature-outcome th,
.literature-table .literature-outcome td {
  background: var(--accent-soft); border-bottom-color: transparent;
}
.literature-takeaway { border-left-color: var(--accent); }
.comparison-scope {
  color: var(--ink-faint); font: .8rem/1.6 var(--sans);
}

.anchor-alias {
  display: block; position: relative; top: -4.5rem; visibility: hidden;
}
.architecture-map {
  width: min(100%, var(--wide)); margin: 2rem auto 1.5rem; padding: .2rem 0 .8rem;
  display: grid; grid-template-columns: repeat(6, minmax(8.6rem, 1fr));
  gap: .7rem; overflow-x: auto; scroll-snap-type: x proximity;
}
.architecture-map a {
  position: relative; display: grid; align-content: start; gap: .35rem;
  min-height: 9rem; padding: .9rem; scroll-snap-align: start;
  color: var(--ink-soft); text-decoration: none;
  background: var(--paper-raised); border: 1px solid var(--rule);
  border-radius: 9px; box-shadow: var(--shadow);
  transition: transform .15s, border-color .15s, background .15s;
}
.architecture-map a:hover,
.architecture-map a[aria-current="step"] {
  transform: translateY(-2px); border-color: var(--accent);
  background: var(--accent-soft);
}
.architecture-map a > span {
  width: 1.7rem; height: 1.7rem; display: grid; place-items: center;
  border-radius: 50%; color: var(--accent); background: var(--accent-soft);
  font: 650 .72rem var(--sans);
}
.architecture-map a[aria-current="step"] > span {
  color: var(--paper-raised); background: var(--accent);
}
.architecture-map strong { color: var(--ink); font: 650 .82rem/1.25 var(--sans); }
.architecture-map small { color: var(--ink-faint); font: .7rem/1.4 var(--sans); }

.proof-lab-toolbar {
  position: sticky; top: 4.1rem; z-index: 20;
  display: flex; align-items: center; justify-content: space-between; gap: .65rem;
  margin: 1.4rem 0 1rem; padding: .6rem;
  background: color-mix(in srgb, var(--paper-raised) 94%, transparent);
  backdrop-filter: blur(9px); border: 1px solid var(--rule);
  border-radius: 8px; box-shadow: var(--shadow);
  font-family: var(--sans);
}
.proof-lab-toolbar button {
  cursor: pointer; padding: .38rem .7rem; border-radius: 6px;
  border: 1px solid var(--rule-strong); color: var(--ink-soft);
  background: var(--paper-sunk); font: 550 .75rem var(--sans);
}
.proof-lab-toolbar button:hover:not(:disabled) {
  border-color: var(--accent); color: var(--accent);
}
.proof-lab-toolbar button:disabled { cursor: default; opacity: .42; }
.proof-lab-toolbar span {
  color: var(--accent); font: 650 .75rem var(--mono);
}
.proof-steps details { scroll-margin-top: 8rem; }

@media (max-width: 44rem) {
  .fundamentals-grid { grid-template-columns: 1fr; }
}

/* ---------- graduate study lab ---------- */

.lab-grid {
  width: min(100%, var(--wide)); margin: 2rem auto 1.25rem;
  display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 1rem;
}
.lab-card {
  min-width: 0; background: var(--paper-raised); border: 1px solid var(--rule);
  border-radius: var(--radius); padding: 1.35rem 1.5rem; box-shadow: var(--shadow);
}
.lab-card h3 { margin: 0 0 .55rem; }
.lab-card > label,
.control-stack label {
  display: flex; justify-content: space-between; align-items: baseline; gap: 1rem;
  margin: 1rem 0 .35rem; font-family: var(--sans); font-size: .8125rem;
  font-weight: 650; color: var(--ink-soft);
}
.lab-card output { color: var(--accent); font-family: var(--mono); font-weight: 500; }
.lab-card input[type="range"] { width: 100%; accent-color: var(--accent); }
.lab-intro {
  min-height: 5.2rem; color: var(--ink-soft); font-size: .9375rem;
}
.lab-status {
  margin: 1.1rem 0 .75rem; padding: .7rem .8rem; border-radius: 7px;
  font-family: var(--sans); font-size: .8125rem; font-weight: 600;
}
.lab-status.valid { color: var(--good); background: var(--good-soft); }
.lab-status.invalid { color: var(--warn); background: var(--warn-soft); }
.formula-panel {
  display: grid; gap: .15rem; background: var(--paper-sunk);
  border: 1px solid var(--rule); border-radius: 8px; padding: .8rem .9rem;
  font-family: var(--sans);
}
.formula-panel span {
  color: var(--ink-faint); font-size: .68rem; font-weight: 650;
  letter-spacing: .07em; text-transform: uppercase;
}
.formula-panel strong { color: var(--ink); font-family: var(--mono); font-size: 1rem; }
.formula-panel small { color: var(--ink-faint); font-size: .75rem; line-height: 1.45; }
.preset-row { display: flex; flex-wrap: wrap; gap: .45rem; margin-top: .75rem; }
.preset-row button {
  cursor: pointer; padding: .35rem .6rem; border-radius: 6px;
  border: 1px solid var(--rule-strong); color: var(--ink-soft);
  background: var(--paper-raised); font: 500 .72rem var(--sans);
}
.preset-row button:hover { border-color: var(--accent); color: var(--accent); }
.metric-grid {
  display: grid; grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: .55rem; margin: 1.2rem 0 0;
}
.metric-grid div {
  min-width: 0; background: var(--paper-sunk); border: 1px solid var(--rule);
  border-radius: 8px; padding: .75rem;
}
.metric-grid dt {
  font: 650 .68rem var(--sans); letter-spacing: .04em;
  text-transform: uppercase; color: var(--ink-faint);
}
.metric-grid dd {
  margin: .35rem 0 .15rem; color: var(--accent);
  font: 600 clamp(.84rem, 1.8vw, 1rem) var(--mono);
  font-variant-numeric: tabular-nums; overflow-wrap: anywhere;
}
.metric-grid small {
  display: block; color: var(--ink-faint); font: .7rem/1.4 var(--sans);
}
.quantifier-chain {
  width: min(100%, var(--wide)); margin: 0 auto 1.5rem;
  display: flex; align-items: stretch; gap: .45rem;
  font-family: var(--sans); font-size: .75rem; color: var(--ink-soft);
}
.quantifier-chain span {
  flex: 1; display: grid; place-items: center; min-height: 4.2rem;
  padding: .7rem; text-align: center; background: var(--paper-sunk);
  border: 1px solid var(--rule); border-radius: 8px;
}
.quantifier-chain i { align-self: center; color: var(--accent); font-style: normal; }
@media (max-width: 44rem) {
  .lab-grid { grid-template-columns: 1fr; }
  .lab-intro { min-height: 0; }
  .metric-grid { grid-template-columns: 1fr; }
  .quantifier-chain { flex-direction: column; }
  .quantifier-chain span { min-height: 0; }
  .quantifier-chain i { transform: rotate(90deg); }
}

/* ---------- figures ---------- */

figure { margin: 2rem 0; }
figure.bleed { width: min(100vw - 2.5rem, var(--wide)); margin-inline: auto; }
.figbox {
  background: var(--paper-raised); border: 1px solid var(--rule);
  border-radius: var(--radius); padding: 1.15rem; box-shadow: var(--shadow);
  overflow: hidden;
}
figcaption {
  font-family: var(--sans); font-size: .8125rem; line-height: 1.6;
  color: var(--ink-faint); margin-top: .9rem;
}
figcaption b { color: var(--ink-soft); font-weight: 650; }
canvas { display: block; width: 100%; height: auto; }

.fig-controls {
  display: flex; flex-wrap: wrap; gap: .6rem; align-items: center;
  font-family: var(--sans); font-size: .8125rem; color: var(--ink-soft);
  margin-top: .9rem; padding-top: .9rem; border-top: 1px solid var(--rule);
}
.fig-controls button {
  font-family: var(--sans); font-size: .8125rem; cursor: pointer;
  background: var(--paper-sunk); border: 1px solid var(--rule-strong);
  color: var(--ink); border-radius: 6px; padding: .35rem .8rem;
}
.fig-controls button:hover { border-color: var(--accent); color: var(--accent); }
.fig-controls input[type="range"] { accent-color: var(--accent); flex: 1; min-width: 8rem; }
.fig-controls .val { font-family: var(--mono); font-size: .8125rem; color: var(--accent); min-width: 4.5rem; }
.orbit-controls {
  display: grid; grid-template-columns: minmax(0, 1fr) auto;
  align-items: end; gap: .6rem; margin-top: 1.1rem; font-family: var(--sans);
}
.orbit-controls label {
  grid-column: 1 / -1; display: grid; gap: .12rem;
  color: var(--ink-soft); font-size: .8125rem; font-weight: 650;
}
.orbit-controls label small {
  color: var(--ink-faint); font-weight: 400; line-height: 1.45;
}
.orbit-controls input[type="text"] {
  width: 100%; min-width: 0; border: 1px solid var(--rule-strong);
  border-radius: 6px; padding: .55rem .65rem; color: var(--ink);
  background: var(--paper-sunk); font: .8125rem var(--mono);
}
.orbit-controls input[type="range"] { flex: 0 1 8rem; min-width: 6rem; }
.orbit-controls output { min-width: 2.4rem; color: var(--accent); font-family: var(--mono); }
@media (max-width: 28rem) {
  .orbit-controls { grid-template-columns: 1fr; }
  .orbit-controls .btn { justify-content: center; }
}
.orbit-result {
  margin: 1rem 0 0; padding: 1rem;
  color: var(--ink-soft); background: var(--paper-raised);
  border: 1px solid var(--rule); border-radius: 9px; box-shadow: var(--shadow);
  font: .78rem/1.5 var(--sans); font-variant-numeric: tabular-nums;
}
.orbit-result.is-updated { animation: orbit-result-in .25s ease both; }
.orbit-result:empty { display: none; }
.orbit-result.reached { border-color: color-mix(in srgb, var(--good) 45%, var(--rule)); }
.orbit-result.stopped,
.orbit-result.error { border-color: color-mix(in srgb, var(--warn) 48%, var(--rule)); }
.orbit-result-head {
  display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between;
  gap: .55rem; margin-bottom: .75rem;
}
.orbit-result-head > strong { color: var(--warn); font-size: .8rem; }
.orbit-status {
  color: var(--good); font-weight: 750; font-size: .82rem;
  letter-spacing: .01em;
}
.orbit-result.stopped .orbit-status { color: var(--warn); }
.orbit-verdict {
  padding: .22rem .55rem; border-radius: 99px;
  font-size: .66rem; font-weight: 700;
}
.orbit-verdict.inside { color: var(--good); background: var(--good-soft); }
.orbit-verdict.outside { color: var(--warn); background: var(--warn-soft); }
.orbit-target { margin: 0 0 .7rem; color: var(--ink-faint); font-size: .72rem; }
.orbit-result-grid {
  display: grid; grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: .5rem; margin: 0;
}
.orbit-result-grid div {
  min-width: 0; padding: .65rem; background: var(--paper-sunk);
  border: 1px solid var(--rule); border-radius: 7px;
}
.orbit-result-grid dt {
  color: var(--ink-faint); font-size: .6rem; font-weight: 700;
  letter-spacing: .05em; text-transform: uppercase;
}
.orbit-result-grid dd {
  margin: .25rem 0 0; color: var(--accent);
  font: 700 clamp(.82rem, 2vw, 1rem)/1.25 var(--mono);
  overflow-wrap: anywhere;
}
.orbit-result-grid small { color: var(--ink-faint); font-size: .62rem; }
.orbit-finite-note {
  margin: .75rem 0 0; padding-top: .65rem; border-top: 1px solid var(--rule);
  color: var(--ink-faint); font-size: .68rem;
}
@keyframes orbit-result-in {
  from { opacity: 0; transform: translateY(5px); }
  to { opacity: 1; transform: none; }
}
@media (max-width: 38rem) {
  .orbit-result-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (prefers-reduced-motion: reduce) {
  .orbit-result { animation: none; }
}

.legend { display: flex; flex-wrap: wrap; gap: .5rem 1.1rem; font-family: var(--sans); font-size: .75rem; color: var(--ink-soft); margin-top: .75rem; }
.legend span { display: inline-flex; align-items: center; gap: .4rem; }
.legend i { width: 1.1rem; height: 0; border-top-width: 2px; border-top-style: solid; display: inline-block; }

/* ---------- tables ---------- */

.tablewrap { overflow-x: auto; margin: 0 0 1.5rem; border: 1px solid var(--rule); border-radius: var(--radius); }
table { border-collapse: collapse; width: 100%; font-family: var(--sans); font-size: .8125rem; }
th, td { padding: .6rem .85rem; text-align: left; border-bottom: 1px solid var(--rule); white-space: nowrap; }
thead th {
  background: var(--paper-sunk); font-weight: 650; font-size: .7rem;
  letter-spacing: .05em; text-transform: uppercase; color: var(--ink-faint);
}
tbody tr:last-child td { border-bottom: 0; }
td.num { font-family: var(--mono); font-variant-numeric: tabular-nums; }
.pill {
  display: inline-block; font-size: .7rem; font-weight: 650; padding: .12rem .5rem;
  border-radius: 99px; font-family: var(--sans);
}
.pill.yes { background: var(--good-soft); color: var(--good); }
.pill.no  { background: var(--warn-soft); color: var(--warn); }

/* ---------- steps ---------- */

.steps { counter-reset: step; list-style: none; padding: 0; margin: 0; }
.steps li {
  counter-increment: step; position: relative; padding-left: 3rem;
  margin-bottom: 1.5rem;
}
.steps li::before {
  content: counter(step); position: absolute; left: 0; top: -.1rem;
  width: 2rem; height: 2rem; border-radius: 50%;
  background: var(--accent-soft); color: var(--accent);
  font-family: var(--sans); font-size: .8125rem; font-weight: 650;
  display: grid; place-items: center;
}
.steps li b { display: block; font-weight: 650; margin-bottom: .2rem; }
.proof-steps li { margin-bottom: .8rem; }
.proof-steps details {
  border: 1px solid var(--rule); border-radius: 8px;
  background: var(--paper-raised); overflow: hidden;
}
.proof-steps summary {
  cursor: pointer; padding: .85rem 1rem; color: var(--ink);
  font-weight: 650; list-style-position: outside;
}
.proof-steps details[open] summary {
  color: var(--accent); border-bottom: 1px solid var(--rule);
  background: var(--accent-soft);
}
.proof-steps details > p:not(.step-interface) { margin: 0; padding: .9rem 1rem 1rem; }
.step-interface {
  display: flex; align-items: center; flex-wrap: wrap; gap: .45rem;
  margin: 0; padding: .65rem 1rem 0; color: var(--ink-faint);
  font: .72rem/1.45 var(--sans);
}
.step-interface span {
  padding: .2rem .45rem; border-radius: 99px;
  background: var(--paper-sunk); border: 1px solid var(--rule);
}
.step-interface i { color: var(--accent); font-style: normal; }

/* ---------- link grid ---------- */

.grid { display: grid; gap: 1rem; grid-template-columns: repeat(auto-fit, minmax(15rem, 1fr)); }
a.tile {
  display: block; text-decoration: none; color: inherit;
  background: var(--paper-raised); border: 1px solid var(--rule);
  border-radius: var(--radius); padding: 1.2rem 1.3rem;
  transition: border-color .15s, transform .15s;
}
a.tile:hover { border-color: var(--accent); transform: translateY(-2px); }
a.tile b { display: block; font-family: var(--sans); font-size: .9375rem; font-weight: 650; margin-bottom: .3rem; }
a.tile span { font-family: var(--sans); font-size: .8125rem; color: var(--ink-faint); line-height: 1.55; display: block; }
a.tile .doi { font-family: var(--mono); font-size: .75rem; color: var(--accent); margin-top: .5rem; display: block; }

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

footer {
  border-top: 1px solid var(--rule); background: var(--paper-sunk);
  padding-block: 3rem; font-family: var(--sans); font-size: .8125rem; color: var(--ink-faint);
}
footer a { color: var(--ink-soft); }
footer .cols { display: grid; gap: 2rem; grid-template-columns: repeat(auto-fit, minmax(13rem, 1fr)); margin-bottom: 2rem; }
footer h5 { font-size: .7rem; letter-spacing: .08em; text-transform: uppercase; color: var(--ink); margin: 0 0 .7rem; font-weight: 650; }
footer ul { list-style: none; padding: 0; margin: 0; }
footer li { margin-bottom: .4rem; }
.cite {
  font-family: var(--mono); font-size: .75rem; line-height: 1.6; color: var(--ink-soft);
  background: var(--paper-raised); border: 1px solid var(--rule);
  border-radius: var(--radius); padding: .9rem 1.05rem; overflow-x: auto; white-space: pre-wrap;
  word-break: break-word;
}

/* ---------- math ---------- */

mjx-container { overflow-x: auto; overflow-y: hidden; max-width: 100%; }
mjx-container[display="true"] { margin: 1.4rem 0 !important; padding-block: .2rem; }

/* ---------- skip link + a11y ---------- */

.skip {
  position: absolute; left: -9999px; top: 0; background: var(--accent); color: #fff;
  padding: .6rem 1rem; z-index: 100; font-family: var(--sans); font-size: .875rem;
  border-radius: 0 0 6px 0;
}
.skip:focus { left: 0; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 3px; }

/* ---------- reveal on scroll ---------- */

/* Only hide when JS is present to un-hide. Without the .js class the content
   renders normally, so a script failure can never blank the page. */
.js .reveal { opacity: 0; transform: translateY(12px); transition: opacity .6s ease, transform .6s ease; }
.js .reveal.in { opacity: 1; transform: none; }
@media (prefers-reduced-motion: reduce) {
  .js .reveal { opacity: 1; transform: none; }
}

/* ---------- print ---------- */

@media print {
  .masthead, .page-rail, .section-menu, .fig-controls, .preset-row,
  .proof-lab-toolbar,
  .theme-toggle, footer { display: none; }
  body { background: #fff; color: #000; font-size: 10pt; }
  a { color: #000; }
}
