/* ============================================================
   The Field Manual — Operator's Manual visual world.
   See index.html <!-- DIRECTION CONTRACT --> for the thesis.
   ============================================================ */

/* ---------- Tokens ---------- */

:root {
  /* Palette — printed stock (light) */
  --ground:        #F4F1E6;
  --surface:       #ECE7D5;
  --surface-2:     #DFD8C0;
  --ink:           #14140F;
  --ink-2:         #55524A;
  --ink-3:         #8A8574;
  --rule:          #C4BBA3;
  --rule-hair:     #D9D2BC;
  --rule-strong:   #14140F;
  --accent:        #F5C400;   /* safety yellow */
  --accent-ink:    #14140F;
  --accent-quiet:  #F5EBB9;
  --danger:        #C63018;   /* procedural red */
  --success:       #4E6B3A;

  /* Type stacks */
  --font-headline: "Antic Slab", "Rockwell", "Rockwell Nova", "Sitka Heading", Georgia, "Times New Roman", serif;
  --font-display: "Recursive", "Helvetica Neue", Helvetica, Arial, sans-serif;
  --font-body:    "Charter", "Bitstream Charter", "Sitka Text", Cambria, Georgia, serif;
  --font-mono:    "JetBrains Mono", "Recursive", "SF Mono", ui-monospace, Menlo, Consolas, monospace;

  /* Recursive axis presets — used with font-variation-settings */
  --rec-sans:       "MONO" 0, "CASL" 0.35, "slnt" 0;
  --rec-sans-tight: "MONO" 0, "CASL" 0.15, "slnt" 0;
  --rec-mono:       "MONO" 1, "CASL" 0, "slnt" 0;

  /* Depth (used sparingly) */
  --shadow-lift: 0 1px 0 rgba(20, 20, 15, 0.05), 0 8px 24px -12px rgba(20, 20, 15, 0.16);

  color-scheme: light;
}

/* Dark theme — neutral warm-dark (low saturation) with blue-green accent */
:root:not([data-theme="light"]) {
  @media (prefers-color-scheme: dark) {
    --ground:        #1B1712;   /* near-black with whisper of warmth, low saturation */
    --surface:       #241F19;
    --surface-2:     #2E2822;
    --ink:           #EBE4D0;
    --ink-2:         #A19A87;
    --ink-3:         #6A6555;
    --rule:          #2F2A22;
    --rule-hair:     #221D17;
    --rule-strong:   #EBE4D0;
    --accent:        #38C3AC;   /* teal — sits naturally on neutral-warm ground */
    --accent-ink:    #082019;
    --accent-quiet:  #12241F;
    --danger:        #F5C400;
    --success:       #97B667;
    --shadow-lift:   0 1px 0 rgba(0, 0, 0, 0.4), 0 12px 32px -16px rgba(0, 0, 0, 0.7);
    color-scheme: dark;
  }
}

:root[data-theme="dark"] {
  --ground:        #1B1712;
  --surface:       #241F19;
  --surface-2:     #2E2822;
  --ink:           #EBE4D0;
  --ink-2:         #A19A87;
  --ink-3:         #6A6555;
  --rule:          #2F2A22;
  --rule-hair:     #221D17;
  --rule-strong:   #EBE4D0;
  --accent:        #38C3AC;
  --accent-ink:    #082019;
  --accent-quiet:  #12241F;
  --danger:        #F5C400;
  --success:       #97B667;
  --shadow-lift:   0 1px 0 rgba(0, 0, 0, 0.4), 0 12px 32px -16px rgba(0, 0, 0, 0.7);
  color-scheme: dark;
}

/* ---------- Reset ---------- */

* { box-sizing: border-box; }
[hidden] { display: none !important; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  background-color: var(--ground);
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='300' height='300'><filter id='n'><feTurbulence type='fractalNoise' baseFrequency='0.9' numOctaves='2' stitchTiles='stitch'/><feColorMatrix values='0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0.04 0'/></filter><rect width='100%25' height='100%25' filter='url(%23n)'/></svg>");
  background-attachment: fixed;
  color: var(--ink);
  font-family: var(--font-body);
  font-size: 17.5px;
  line-height: 1.55;
  font-feature-settings: "kern" 1, "liga" 1, "onum" 1;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
  min-height: 100vh;
  position: relative;
}

/* Pastel aurora wash — same palette as the loop hero, positioned so the eye
   catches a soft glow at opposite corners without competing with the type. */
body::before {
  content: '';
  position: fixed;
  inset: 0;
  z-index: -1;
  pointer-events: none;
  background:
    radial-gradient(ellipse 110vw 80vw at -15% -20%,  rgba(143, 180, 217, 0.20), transparent 80%),
    radial-gradient(ellipse 100vw 75vw at 115% -15%,  rgba(184, 168, 217, 0.18), transparent 80%),
    radial-gradient(ellipse 100vw 75vw at 115% 115%,  rgba(217, 168, 184, 0.20), transparent 80%),
    radial-gradient(ellipse 110vw 80vw at -15% 115%,  rgba(229, 200, 160, 0.20), transparent 80%);
}
:root:not([data-theme="light"]) body::before,
:root[data-theme="dark"] body::before {
  background:
    radial-gradient(ellipse 120vw 85vw at -20% -20%,  rgba(72, 216, 190, 0.16), transparent 82%),
    radial-gradient(ellipse 110vw 80vw at 120% -15%,  rgba(160, 128, 220, 0.18), transparent 82%),
    radial-gradient(ellipse 105vw 75vw at 115% 115%,  rgba(230, 132, 168, 0.14), transparent 82%),
    radial-gradient(ellipse 115vw 80vw at -20% 115%,  rgba(232, 176, 108, 0.14), transparent 82%);
}


::selection { background: var(--accent); color: var(--accent-ink); }
::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--rule); border: 2px solid var(--ground); border-radius: 0; }
::-webkit-scrollbar-thumb:hover { background: var(--ink-3); }

a { color: inherit; text-decoration-color: var(--rule); text-underline-offset: 3px; text-decoration-thickness: 1px; }
a:hover { text-decoration-color: var(--accent); }

button {
  font: inherit;
  color: inherit;
  cursor: pointer;
}

/* ---------- App container ---------- */

.app {
  max-width: 1200px;
  margin: 0 auto;
  padding: 28px clamp(20px, 4vw, 56px) 120px;
  position: relative;
  animation: page-in .38s cubic-bezier(.22,.9,.29,1) both;
}

@keyframes page-in {
  from { opacity: 0; filter: blur(3px); }
  to   { opacity: 1; filter: none; }
}

@media (prefers-reduced-motion: reduce) {
  .app { animation: none; }
}

/* ---------- Masthead ---------- */

.masthead {
  display: flex;
  justify-content: space-between;
  align-items: flex-end;
  gap: 32px;
  padding-bottom: 18px;
  border-bottom: 1.5px solid var(--rule-strong);
}

.masthead-brand { flex-shrink: 0; }

.masthead-title {
  font-family: var(--font-mono);
  font-variation-settings: var(--rec-mono);
  font-weight: 700;
  font-size: clamp(1.5rem, 3.2vw, 2.15rem);
  line-height: 1;
  letter-spacing: -0.03em;
  color: var(--ink);
  margin: 0;
  text-transform: none;
}
.masthead-title::before {
  content: "▍";
  color: var(--accent);
  margin-right: 6px;
  font-size: 0.85em;
  display: inline-block;
  transform: translateY(-1px);
}

.masthead-subtitle {
  font-family: var(--font-body);
  font-style: italic;
  font-size: clamp(0.95rem, 1.4vw, 1.05rem);
  color: var(--ink-2);
  margin-top: 4px;
  line-height: 1.2;
}

.masthead-meta {
  display: flex;
  gap: clamp(14px, 2.6vw, 30px);
  align-items: flex-end;
  font-family: var(--font-mono);
  font-variation-settings: var(--rec-mono);
  font-size: 11.5px;
  color: var(--ink-2);
  letter-spacing: 0.02em;
}

.meta-cell { display: inline-flex; flex-direction: column; gap: 2px; line-height: 1.1; }
.meta-key {
  font-family: var(--font-display);
  font-variation-settings: "wght" 500, var(--rec-sans);
  font-size: 9.5px;
  letter-spacing: 0.22em;
  text-transform: uppercase;
  color: var(--ink-3);
}
.meta-val {
  font-family: var(--font-mono);
  font-variation-settings: var(--rec-mono);
  font-weight: 500;
  font-size: 13.5px;
  color: var(--ink);
  font-variant-numeric: tabular-nums;
}

/* ---------- Control bar ---------- */

.ctrl-bar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 16px;
  padding: 10px 0 22px;
  border-bottom: 1px solid var(--rule-hair);
  margin-bottom: 44px;
  flex-wrap: wrap;
}

/* When reading a chapter or taking an exam, constrain header to reading column
   width so the rule beneath the header aligns with content below. */
body.reading .masthead,
body.reading .ctrl-bar {
  max-width: 1040px;
  margin-left: auto;
  margin-right: auto;
}

.ctrl-status {
  font-family: var(--font-display);
  font-variation-settings: "wght" 500, var(--rec-sans);
  font-size: 10.5px;
  letter-spacing: 0.22em;
  text-transform: uppercase;
  color: var(--ink-3);
}
.ctrl-status::before {
  content: "";
  display: inline-block;
  width: 6px;
  height: 6px;
  background: var(--accent);
  margin-right: 10px;
  vertical-align: 1px;
}

.ctrl-actions { display: flex; align-items: center; gap: 6px; }

.ctrl-btn {
  background: transparent;
  border: none;
  padding: 6px 10px;
  font-family: var(--font-display);
  font-variation-settings: "wght" 500, var(--rec-sans);
  font-size: 10.5px;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: var(--ink-2);
  border-radius: 0;
  transition: color .12s ease, background .12s ease;
  position: relative;
}
.ctrl-btn:not(:disabled):hover { color: var(--ink); background: var(--surface); }
.ctrl-btn:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.ctrl-btn:disabled { opacity: .35; cursor: default; }

/* ---------- Loop hero — DevOps continuous-cycle infinity (two-ring) ---------- */

.loop-hero {
  text-align: center;
  padding: 12px 0 28px;
  margin-bottom: 20px;
  border-bottom: 1px solid var(--rule-hair);
}
.loop-svg {
  width: 100%;
  max-width: 620px;
  height: auto;
  display: inline-block;
  overflow: visible;
}
/* Two loop paths — each stroked as a thick ring. They share (390,170) — where they cross. */
.ring-arc {
  fill: none;
  stroke-width: 40;
  stroke-linejoin: round;
  stroke-linecap: round;
}
.ring-dev { stroke: url(#devGrad); }
.ring-ops { stroke: url(#opsGrad); }

/* Stage labels ride along each half-loop via <textPath>. Every half-path is drawn
   left-to-right so all labels stay upright. Dark ink for readability on pastel rings. */
.stage-flow {
  font-family: var(--font-mono);
  font-variation-settings: var(--rec-mono);
  font-size: 12.5px;
  font-weight: 700;
  fill: #2A2418;
  letter-spacing: 0.06em;
  text-transform: lowercase;
}

.loop-word {
  font-family: var(--font-headline);
  font-weight: 400;
  font-size: 62px;
  letter-spacing: -0.02em;
  fill: var(--ink);
}
.loop-orbit {
  fill: #6B7C99;
  filter: drop-shadow(0 0 8px rgba(107, 124, 153, 0.6));
}
@media (prefers-reduced-motion: reduce) {
  .loop-orbit animateMotion { display: none; }
}
.loop-caption {
  font-family: var(--font-body);
  font-style: italic;
  font-size: 13.5px;
  color: var(--ink-3);
  margin-top: 14px;
  max-width: 60ch;
  margin-left: auto;
  margin-right: auto;
}
@media (prefers-reduced-motion: reduce) {
  .loop-orbit animateMotion { display: none; }
}
@media (max-width: 700px) {
  .loop-svg { max-width: 100%; }
  .loop-word { font-size: 52px; }
  .stage-label { font-size: 11.5px; }
}
@media (max-width: 480px) {
  .loop-hero { padding: 6px 0 20px; }
  .loop-caption { font-size: 12.5px; }
}

/* ---------- Plate — today's procedure + operator status ---------- */

.plate {
  display: grid;
  border: 1px solid var(--rule);
  background: var(--surface);
  margin-bottom: 32px;
  position: relative;
}

.plate-today {
  grid-template-columns: minmax(0, 1.6fr) minmax(0, 1fr);
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='24' height='24'><path d='M 0 0 L 24 0 M 0 0 L 0 24' stroke='rgba(28,20,10,0.09)' stroke-width='0.5' fill='none'/></svg>");
  background-repeat: repeat;
}
:root:not([data-theme="light"]) .plate-today,
:root[data-theme="dark"] .plate-today {
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='24' height='24'><path d='M 0 0 L 24 0 M 0 0 L 0 24' stroke='rgba(255,240,220,0.07)' stroke-width='0.5' fill='none'/></svg>");
}

@media (max-width: 720px) {
  .plate-today { grid-template-columns: 1fr; }
}

.plate-block {
  padding: 32px clamp(24px, 3.2vw, 44px) 30px;
  position: relative;
}

.plate-block + .plate-block { border-left: 1px solid var(--rule); }
@media (max-width: 720px) {
  .plate-block + .plate-block { border-left: 0; border-top: 1px solid var(--rule); }
}

.plate-eyebrow {
  font-family: var(--font-display);
  font-variation-settings: "wght" 700, var(--rec-sans);
  font-size: 10.5px;
  letter-spacing: 0.24em;
  text-transform: uppercase;
  color: var(--accent);
  display: inline-block;
  margin-bottom: 24px;
  line-height: 1;
  position: relative;
  padding-left: 12px;
}
.plate-eyebrow::before {
  content: "";
  position: absolute;
  left: 0;
  top: 50%;
  width: 6px;
  height: 6px;
  background: var(--accent);
  transform: translateY(-50%);
}

.plate-title {
  font-family: var(--font-headline);
  font-weight: 400;
  font-size: clamp(1.7rem, 3.4vw, 2.4rem);
  line-height: 1.02;
  letter-spacing: -0.01em;
  color: var(--ink);
  margin: 0 0 10px;
  text-wrap: balance;
  max-width: 14ch;
}

.plate-tag {
  font-family: var(--font-body);
  font-style: italic;
  color: var(--ink-2);
  font-size: 1.05rem;
  line-height: 1.35;
  margin: 0 0 22px;
  max-width: 46ch;
}

.plate-metaline {
  font-family: var(--font-mono);
  font-variation-settings: var(--rec-mono);
  font-size: 12px;
  letter-spacing: 0.02em;
  color: var(--ink-3);
  margin-bottom: 22px;
  font-variant-numeric: tabular-nums;
}

.plate-open {
  display: inline-block;
  padding: 6px 0;
  font-family: var(--font-display);
  font-variation-settings: "wght" 600, var(--rec-sans);
  font-size: 12px;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: var(--ink);
  text-decoration: none;
  border-bottom: 1.5px solid var(--ink);
  transition: color .12s ease, border-color .12s ease, transform .12s ease;
}
.plate-open:hover { color: var(--accent-ink); background: var(--accent); border-bottom-color: var(--accent); padding-left: 6px; padding-right: 6px; }

/* Operator status */

.status-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 22px;
  padding-top: 2px;
}

.status-cell {
  display: grid;
  grid-template-columns: auto 1fr;
  align-items: baseline;
  gap: 14px;
  border-bottom: 1px dotted var(--rule);
  padding-bottom: 14px;
}
.status-cell:last-child { border-bottom: 0; padding-bottom: 0; }

.status-figure {
  font-family: var(--font-mono);
  font-variation-settings: var(--rec-mono);
  font-weight: 500;
  font-size: clamp(1.75rem, 3vw, 2.2rem);
  color: var(--ink);
  line-height: 1;
  font-variant-numeric: tabular-nums;
  letter-spacing: -0.01em;
}
.status-of { color: var(--ink-3); font-size: 0.55em; margin-left: 2px; }
.stat-total { color: inherit; }

.status-label {
  font-family: var(--font-display);
  font-variation-settings: "wght" 500, var(--rec-sans);
  font-size: 10.5px;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: var(--ink-3);
  text-align: right;
}

/* ---------- Glossary plate ---------- */

.plate-def {
  grid-template-columns: minmax(220px, 320px) minmax(0, 1fr) auto;
  align-items: center;
  padding: 26px clamp(20px, 3vw, 40px);
  gap: 32px;
  background-color: var(--ground);
  background-image:
    radial-gradient(ellipse 60% 120% at 100% 50%, color-mix(in srgb, var(--accent) 14%, transparent), transparent 70%),
    radial-gradient(ellipse 40% 90% at 0% 100%, color-mix(in srgb, var(--ink) 6%, transparent), transparent 65%);
  border-color: var(--rule-hair);
  margin-bottom: 56px;
}
.plate-def > * { padding: 0; }
@media (max-width: 720px) {
  .plate-def { grid-template-columns: 1fr; gap: 12px; }
}

.def-side { padding: 0; }
.def-eyebrow {
  font-family: var(--font-mono);
  font-variation-settings: var(--rec-mono);
  font-size: 11px;
  letter-spacing: 0.06em;
  color: var(--ink-3);
  margin-bottom: 6px;
  font-variant-numeric: tabular-nums;
}
.def-term {
  font-family: var(--font-display);
  font-variation-settings: "wght" 700, var(--rec-sans-tight);
  font-size: 1.55rem;
  line-height: 1;
  letter-spacing: -0.015em;
  color: var(--ink);
  margin: 0;
}

.def-body {
  font-family: var(--font-body);
  font-size: 15.5px;
  line-height: 1.55;
  color: var(--ink-2);
  margin: 0;
  max-width: 60ch;
}
.def-body code {
  font-family: var(--font-mono);
  font-variation-settings: var(--rec-mono);
  font-size: 0.9em;
  color: var(--ink);
  background: var(--surface);
  padding: 1px 5px;
}

.def-seen {
  font-family: var(--font-mono);
  font-variation-settings: var(--rec-mono);
  font-size: 11.5px;
  color: var(--ink-3);
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
}

/* ---------- TOC (Table of Procedures) ---------- */

.toc-heading {
  display: grid;
  grid-template-columns: auto 1fr auto;
  align-items: baseline;
  gap: 16px;
  padding-bottom: 14px;
  margin-bottom: 8px;
  border-bottom: 1.5px solid var(--rule-strong);
}
.toc-numeral {
  font-family: var(--font-display);
  font-variation-settings: "wght" 700, var(--rec-sans);
  font-size: 1.4rem;
  color: var(--accent-ink);
  background: var(--accent);
  width: 32px;
  height: 32px;
  display: inline-grid;
  place-items: center;
  line-height: 1;
}
.toc-heading h2 {
  font-family: var(--font-headline);
  font-weight: 400;
  font-size: clamp(1.5rem, 2.2vw, 1.9rem);
  letter-spacing: -0.005em;
  color: var(--ink);
  margin: 0;
}
.toc-count {
  font-family: var(--font-mono);
  font-variation-settings: var(--rec-mono);
  font-size: 11.5px;
  color: var(--ink-3);
  font-variant-numeric: tabular-nums;
  letter-spacing: 0.02em;
}

/* Part sections — bordered container, chapters + exam grouped inside */
.part-section {
  margin-bottom: 20px;
  border: 1px solid var(--rule);
  background: var(--surface);
  padding: 0 clamp(14px, 2vw, 22px);
}
.part-section:last-child { margin-bottom: 0; }

.part-header {
  display: grid;
  grid-template-columns: auto auto 1fr auto;
  align-items: baseline;
  gap: 18px;
  padding: 22px 0 12px;
  border-bottom: 1px solid var(--rule);
  cursor: pointer;
  user-select: none;
  color: var(--ink);
  transition: color .12s ease;
}
.part-header:hover { color: var(--accent); }
.part-header:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.part-section.collapsed .part-header { border-bottom: 0; }
.part-caret {
  font-family: var(--font-mono);
  font-variation-settings: var(--rec-mono);
  color: var(--accent);
  font-size: 11px;
  line-height: 1;
  transition: transform .18s cubic-bezier(.22,.9,.29,1);
  display: inline-block;
  width: 14px;
  text-align: center;
}
.part-section.collapsed .part-caret { transform: rotate(-90deg); }
.part-section.collapsed .grid { display: none; }

.part-num {
  font-family: var(--font-mono);
  font-variation-settings: var(--rec-mono);
  font-size: 12px;
  letter-spacing: 0.1em;
  color: var(--ink-3);
  font-variant-numeric: tabular-nums;
}
.part-title {
  font-family: var(--font-display);
  font-variation-settings: "wght" 700, var(--rec-sans-tight);
  font-size: 1.25rem;
  color: var(--ink);
  margin: 0;
  letter-spacing: -0.01em;
}
.part-desc {
  font-family: var(--font-body);
  font-style: italic;
  color: var(--ink-3);
  font-size: 14px;
  text-align: right;
  max-width: 42ch;
  justify-self: end;
}
@media (max-width: 720px) {
  .part-header { grid-template-columns: auto auto 1fr; }
  .part-desc { display: none; }
}

/* Chapter rows — table-of-procedures, not cards */

.grid {
  display: block;
  background: transparent;
  border: 0;
}

.chapter, .exam-card {
  display: grid;
  grid-template-columns: 44px minmax(0, 1fr) 130px 90px;
  align-items: baseline;
  gap: 20px;
  padding: 14px 0;
  margin: 0 -8px;
  padding-left: 8px;
  padding-right: 8px;
  border: 0;
  border-bottom: 1px solid var(--rule-hair);
  background: transparent;
  color: var(--ink);
  text-align: left;
  cursor: pointer;
  font-family: inherit;
  width: calc(100% + 16px);
  transition: background .12s ease;
  position: relative;
}
.chapter:hover, .exam-card:hover { background: var(--accent-quiet); }
.chapter:focus-visible, .exam-card:focus-visible { outline: 2px solid var(--accent); outline-offset: -2px; }
.grid > :last-child { border-bottom: 0; }

.chapter-num {
  font-family: var(--font-mono);
  font-variation-settings: var(--rec-mono);
  font-size: 13.5px;
  font-weight: 500;
  color: var(--ink);
  font-variant-numeric: tabular-nums;
  letter-spacing: 0.02em;
  padding-top: 2px;
}
.chapter-body { min-width: 0; }
.chapter-title {
  font-family: var(--font-display);
  font-variation-settings: "wght" 600, var(--rec-sans-tight);
  font-size: 1.1rem;
  line-height: 1.2;
  color: var(--ink);
  margin: 0 0 3px;
  letter-spacing: -0.005em;
}
.chapter-tag {
  font-family: var(--font-body);
  font-style: italic;
  color: var(--ink-3);
  font-size: 13.5px;
  line-height: 1.35;
  margin: 0;
  overflow: hidden;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
}
.chapter-stat {
  font-family: var(--font-display);
  font-variation-settings: "wght" 500, var(--rec-sans);
  font-size: 10.5px;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--ink-3);
  white-space: nowrap;
  padding-top: 4px;
}
.chapter-stat.done { color: var(--success); }
.chapter-stat.wip { color: var(--accent); font-variation-settings: "wght" 700, var(--rec-sans); }
.chapter-score {
  font-family: var(--font-mono);
  font-variation-settings: var(--rec-mono);
  font-size: 13px;
  color: var(--ink-2);
  text-align: right;
  font-variant-numeric: tabular-nums;
  padding-top: 4px;
}

@media (max-width: 720px) {
  .chapter, .exam-card {
    grid-template-columns: 36px minmax(0, 1fr) auto;
    gap: 14px;
  }
  .chapter-tag { -webkit-line-clamp: 3; }
  .chapter-score { grid-column: 2 / -1; text-align: left; padding-top: 0; margin-top: 2px; }
  .chapter-stat { grid-row: 1; }
}

/* Exam card variant — the last row of its section, subtly tinted */
.exam-card {
  border-top: 1px dashed var(--rule);
  border-bottom: 0;
  padding-top: 20px;
  padding-bottom: 22px;
  margin-top: 4px;
  background: color-mix(in srgb, var(--accent) 5%, transparent);
}
.exam-card:hover { background: color-mix(in srgb, var(--accent) 12%, transparent); }
.exam-card .chapter-num {
  color: var(--accent);
  border: 1px solid var(--accent);
  padding: 2px 5px 3px;
  text-align: center;
  font-size: 11px;
  letter-spacing: 0.14em;
}
.exam-card .chapter-title { font-variation-settings: "wght" 700, var(--rec-sans-tight); }
.exam-card .chapter-stat { color: var(--ink-2); font-weight: 500; }

/* ---------- Colophon ---------- */

.colophon {
  margin-top: 72px;
  padding-top: 22px;
  border-top: 1px solid var(--rule-hair);
  font-family: var(--font-body);
  font-style: italic;
  color: var(--ink-3);
  font-size: 14px;
  text-align: center;
}
.col-mark { font-family: var(--font-display); color: var(--accent-ink); background: var(--accent); padding: 1px 5px 2px; margin-right: 8px; font-variation-settings: "wght" 700, var(--rec-sans); font-size: 12px; }

/* ---------- Topic (procedure) view ---------- */

.topic-view {
  display: none;
  max-width: 1040px;
  margin: 0 auto;
}
.topic-view.active { display: block; }
.home-view.hidden { display: none; }

/* Every reading element inside topic-view is centered within the reading column. */
.topic-view .topic-head,
.topic-view .topic-section,
.topic-view .quiz,
.topic-view .quiz-gate {
  margin-left: auto;
  margin-right: auto;
}
.topic-view .topic-title,
.topic-view .topic-lede {
  margin-left: 0;
  margin-right: auto;
}

.back-link {
  background: transparent;
  border: 0;
  padding: 0;
  font-family: var(--font-display);
  font-variation-settings: "wght" 500, var(--rec-sans);
  font-size: 11px;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: var(--ink-2);
  margin-bottom: 32px;
  cursor: pointer;
}
.back-link:hover { color: var(--accent-ink); background: var(--accent); padding: 2px 8px; }

.topic-head {
  padding: 24px 0 28px;
  margin-bottom: 40px;
  border-top: 4px solid var(--ink);
  border-bottom: 1px solid var(--rule);
  position: relative;
}
.topic-eyebrow {
  display: flex;
  align-items: baseline;
  gap: 14px;
  font-family: var(--font-mono);
  font-variation-settings: var(--rec-mono);
  font-size: 11.5px;
  letter-spacing: 0.04em;
  color: var(--ink-3);
  margin-bottom: 12px;
  flex-wrap: wrap;
}
.topic-eyebrow .num {
  color: var(--accent);
  border: 1px solid var(--accent);
  padding: 1px 5px 2px;
  font-weight: 500;
}
.topic-title {
  font-family: var(--font-headline);
  font-weight: 400;
  font-size: clamp(2.1rem, 4.6vw, 3.25rem);
  line-height: 1.02;
  letter-spacing: -0.01em;
  color: var(--ink);
  margin: 0 0 12px;
  text-wrap: balance;
  max-width: 22ch;
}
.topic-lede {
  font-family: var(--font-body);
  font-style: italic;
  color: var(--ink-2);
  font-size: 1.15rem;
  line-height: 1.4;
  margin: 0;
  max-width: 46ch;
}

.topic-section { margin-bottom: 48px; max-width: 100%; }
.topic-section h3 {
  font-family: var(--font-display);
  font-variation-settings: "wght" 700, var(--rec-sans-tight);
  font-size: 1.15rem;
  letter-spacing: -0.005em;
  color: var(--ink);
  margin: 0 0 18px;
  padding-bottom: 8px;
  border-bottom: 1px solid var(--rule-hair);
  display: flex;
  align-items: baseline;
  gap: 12px;
}
.topic-section h3 .sub-num {
  font-family: var(--font-mono);
  font-variation-settings: var(--rec-mono);
  font-size: 12px;
  color: var(--ink-3);
  font-weight: 500;
  letter-spacing: 0.04em;
}
.prose p {
  margin: 0 0 16px;
  max-width: none;
  font-size: 18px;
  line-height: 1.62;
}
.prose p:last-child { margin-bottom: 0; }

/* Editorial drop cap on the first paragraph of a chapter's introduction */
.topic-section:first-of-type .prose p:first-of-type::first-letter {
  font-family: var(--font-headline);
  font-weight: 400;
  font-size: 3.6rem;
  line-height: 0.85;
  float: left;
  margin: 8px 12px 0 0;
  padding: 0;
  color: var(--accent);
}
.prose code, .glossary dd code, .q-text code, .q-option code, .q-explanation code, .topic-lede code {
  font-family: var(--font-mono);
  font-variation-settings: var(--rec-mono);
  font-size: 0.9em;
  background: var(--surface);
  padding: 1px 5px;
  color: var(--ink);
  border-radius: 0;
}
.prose em, .topic-lede em, .plate-tag em, .chapter-tag em { color: var(--ink); font-style: italic; }

/* Glossary — definition list styled as a table */
.glossary {
  display: grid;
  grid-template-columns: minmax(200px, 260px) 1fr;
  gap: 4px 40px;
  max-width: 100%;
  margin: 0;
}
@media (max-width: 640px) { .glossary { grid-template-columns: 1fr; gap: 4px 0; } }

.glossary dt {
  font-family: var(--font-display);
  font-variation-settings: "wght" 600, var(--rec-sans-tight);
  font-size: 1.08rem;
  color: var(--ink);
  padding: 16px 0 16px 0;
  border-top: 1px solid var(--rule-hair);
  letter-spacing: -0.005em;
  line-height: 1.3;
}
.glossary dd {
  margin: 0;
  padding: 16px 0;
  color: var(--ink-2);
  font-size: 17.5px;
  line-height: 1.55;
  border-top: 1px solid var(--rule-hair);
}
@media (max-width: 640px) {
  .glossary dt { border-top: 1px solid var(--rule-hair); padding-bottom: 6px; margin-top: 4px; }
  .glossary dd { border-top: 0; padding-top: 0; }
}

/* Figure — inline SVG diagram, break out of the reading column */
.figure {
  margin: 32px -70px;
  border: 1px solid var(--rule);
  background: var(--surface);
  padding: 22px 28px 18px;
  color: var(--ink);
}
@media (max-width: 900px) {
  .figure { margin: 32px 0; padding: 20px 18px 16px; }
}
.figure-tag {
  font-family: var(--font-display);
  font-variation-settings: "wght" 700, var(--rec-sans);
  font-size: 10px;
  letter-spacing: 0.24em;
  text-transform: uppercase;
  color: var(--accent);
  margin-bottom: 16px;
}
.figure-svg {
  display: block;
  width: 100%;
  max-width: 640px;
  height: auto;
  margin: 0 auto;
  color: var(--ink);
}
.figure-svg text { font-family: var(--font-mono); font-variation-settings: var(--rec-mono); fill: currentColor; }
.figure-svg .fig-em { fill: var(--accent); }
.figure-svg .fig-muted { opacity: 0.6; }
.figure-caption {
  font-family: var(--font-body);
  font-style: italic;
  color: var(--ink-2);
  font-size: 14.5px;
  line-height: 1.5;
  margin: 16px auto 0;
  padding-top: 12px;
  border-top: 1px dotted var(--rule);
  max-width: 64ch;
}

/* Code block — a real runbook example.
   Breaks out of the reading column so wide code doesn't clip.
   Visible scrollbar so overflow is discoverable. */
.code-block {
  background: var(--surface);
  color: var(--ink);
  padding: 44px 20px 18px 20px;
  font-family: var(--font-mono);
  font-variation-settings: var(--rec-mono);
  font-size: 12.5px;
  line-height: 1.55;
  border: 1px solid var(--rule);
  overflow-x: auto;
  white-space: pre;
  tab-size: 2;
  margin: 0 -70px 12px -70px;
  max-width: none;
  width: calc(100% + 140px);
  position: relative;
  scrollbar-width: thin;
  scrollbar-color: var(--rule) var(--surface);
}
/* Badge sits inside the block's top padding — no overhang, no clipping. */
.code-block::before {
  content: "$ LISTING";
  position: absolute;
  top: 16px;
  left: 20px;
  line-height: 1;
  font-family: var(--font-display);
  font-variation-settings: "wght" 700, var(--rec-sans);
  font-size: 10px;
  letter-spacing: 0.24em;
  text-transform: uppercase;
  color: var(--ink-3);
  background: transparent;
  padding: 0;
  transform: none;
  pointer-events: none;
}
.code-block::-webkit-scrollbar { height: 8px; -webkit-appearance: none; }
.code-block::-webkit-scrollbar-track { background: var(--surface); }
.code-block::-webkit-scrollbar-thumb { background: var(--rule); border: 1px solid var(--surface); }
.code-block::-webkit-scrollbar-thumb:hover { background: var(--ink-3); }
@media (max-width: 900px) {
  .code-block { margin: 0 0 12px; width: 100%; padding: 38px 14px 12px; font-size: 11.5px; }
  .code-block::before { top: 14px; left: 14px; font-size: 9.5px; }
}
.code-cap {
  font-family: var(--font-body);
  font-style: italic;
  font-size: 14px;
  color: var(--ink-3);
  margin-top: 8px;
  max-width: 64ch;
}

/* ---------- Chapter navigation (bottom of each topic) ---------- */

.chapter-nav {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
  margin-top: 56px;
  padding-top: 32px;
  border-top: 1px solid var(--rule-hair);
  max-width: 100%;
  margin-left: auto;
  margin-right: auto;
}
.chapter-nav-btn {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 6px;
  padding: 18px 20px;
  background: transparent;
  border: 1px solid var(--rule);
  color: var(--ink);
  text-align: left;
  cursor: pointer;
  font-family: inherit;
  transition: border-color .15s ease, background .15s ease;
}
.chapter-nav-btn:hover {
  border-color: var(--accent);
  background: var(--surface);
}
.chapter-nav-btn.next { align-items: flex-end; text-align: right; }
.chapter-nav-btn.placeholder { visibility: hidden; }
.chapter-nav-dir {
  font-family: var(--font-display);
  font-variation-settings: "wght" 600, var(--rec-sans);
  font-size: 10.5px;
  letter-spacing: 0.22em;
  text-transform: uppercase;
  color: var(--accent);
}
.chapter-nav-num {
  font-family: var(--font-mono);
  font-variation-settings: var(--rec-mono);
  font-size: 11px;
  letter-spacing: 0.06em;
  color: var(--ink-3);
}
.chapter-nav-title {
  font-family: var(--font-headline);
  font-size: 1.05rem;
  line-height: 1.2;
  color: var(--ink);
}
@media (max-width: 640px) {
  .chapter-nav { grid-template-columns: 1fr; gap: 12px; margin-top: 40px; padding-top: 24px; }
  .chapter-nav-btn { padding: 14px 16px; }
  .chapter-nav-btn.next { align-items: flex-start; text-align: left; }
  .chapter-nav-btn.placeholder { display: none; }
}
.code-block .k { color: var(--ink);    font-weight: 700; }
.code-block .s { color: var(--success); }
.code-block .c { color: var(--ink-3);  font-style: italic; }
.code-block .n { color: var(--ink);    font-weight: 500; }

/* ---------- Examination ---------- */

.quiz-gate {
  border: 1px solid var(--rule);
  padding: 36px 32px;
  background: var(--surface);
  text-align: center;
  max-width: 100%;
}
.quiz-gate-eyebrow {
  font-family: var(--font-display);
  font-variation-settings: "wght" 700, var(--rec-sans);
  font-size: 10.5px;
  letter-spacing: 0.24em;
  text-transform: uppercase;
  color: var(--accent);
  display: inline-block;
  margin-bottom: 16px;
  line-height: 1;
}
.quiz-gate-title {
  font-family: var(--font-headline);
  font-weight: 400;
  font-size: 1.7rem;
  color: var(--ink);
  margin: 0 0 8px;
  letter-spacing: -0.005em;
  line-height: 1.1;
}
.quiz-gate-sub {
  font-family: var(--font-body);
  font-style: italic;
  color: var(--ink-2);
  font-size: 14.5px;
  max-width: 44ch;
  margin: 0 auto 24px;
}
.quiz-start {
  background: var(--ink);
  color: var(--ground);
  border: 0;
  font-family: var(--font-display);
  font-variation-settings: "wght" 600, var(--rec-sans);
  font-size: 11.5px;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  padding: 12px 22px;
  cursor: pointer;
  transition: background .12s ease, color .12s ease, transform .1s ease;
}
.quiz-start:hover { background: var(--accent); color: var(--accent-ink); }
.quiz-start .arrow { display: inline-block; margin-left: 6px; }

.quiz {
  border: 1px solid var(--rule);
  padding: 30px clamp(20px, 3vw, 34px) 26px;
  background: var(--surface);
  max-width: 74ch;
}
.quiz-heading {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 12px;
  border-bottom: 1px solid var(--rule);
  padding-bottom: 14px;
  margin-bottom: 22px;
  flex-wrap: wrap;
}
.quiz-heading h3 {
  font-family: var(--font-display);
  font-variation-settings: "wght" 700, var(--rec-sans-tight);
  font-size: 1.2rem;
  color: var(--ink);
  margin: 0;
  border: 0;
  padding: 0;
}
.quiz-score {
  font-family: var(--font-mono);
  font-variation-settings: var(--rec-mono);
  font-size: 12px;
  color: var(--ink-3);
  font-variant-numeric: tabular-nums;
}
.quiz-score b { color: var(--ink); font-weight: 500; }

.question {
  padding: 20px 0 22px;
  border-bottom: 1px dotted var(--rule);
}
.question:last-of-type { border-bottom: 0; padding-bottom: 8px; }

.q-label {
  font-family: var(--font-mono);
  font-variation-settings: var(--rec-mono);
  font-size: 11.5px;
  color: var(--ink-3);
  margin-bottom: 10px;
  letter-spacing: 0.02em;
  font-variant-numeric: tabular-nums;
}
.q-label b { color: var(--accent); font-weight: 600; padding: 0 2px; }
.q-source { color: var(--accent); font-weight: 500; margin-left: 6px; letter-spacing: 0.02em; }
.exam-view .q-source { font-weight: 500; }

.q-text {
  font-family: var(--font-body);
  font-size: 1.05rem;
  line-height: 1.45;
  color: var(--ink);
  margin: 0 0 16px;
  max-width: 60ch;
}
.q-options { display: flex; flex-direction: column; gap: 6px; }

.q-option {
  display: flex;
  gap: 12px;
  align-items: baseline;
  text-align: left;
  border: 1px solid var(--rule);
  background: var(--ground);
  color: var(--ink);
  font-family: var(--font-body);
  font-size: 15.5px;
  line-height: 1.4;
  padding: 12px 14px;
  cursor: pointer;
  transition: border-color .12s ease, background .12s ease;
}
.q-option:hover:not(:disabled) { border-color: var(--ink); background: var(--surface); }
.q-option:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.q-option:disabled { cursor: default; }
.q-option .letter {
  font-family: var(--font-mono);
  font-variation-settings: var(--rec-mono);
  color: var(--ink-3);
  flex-shrink: 0;
  width: 20px;
  font-size: 13px;
  padding-top: 1px;
}
.q-option .mark {
  margin-left: auto;
  flex-shrink: 0;
  font-family: var(--font-mono);
  font-variation-settings: var(--rec-mono);
  font-size: 14px;
  display: none;
}
.q-option.correct { border-color: var(--success); background: color-mix(in srgb, var(--success) 10%, var(--ground)); }
.q-option.correct .letter { color: var(--success); }
.q-option.correct .mark { display: inline; color: var(--success); }
.q-option.wrong { border-color: var(--danger); background: color-mix(in srgb, var(--danger) 10%, var(--ground)); }
.q-option.wrong .letter { color: var(--danger); }
.q-option.wrong .mark { display: inline; color: var(--danger); }

.q-explanation {
  display: none;
  margin-top: 12px;
  padding: 12px 14px 12px 34px;
  background: var(--ground);
  border: 1px solid var(--rule-hair);
  font-family: var(--font-body);
  font-style: italic;
  font-size: 14.5px;
  color: var(--ink-2);
  line-height: 1.5;
  max-width: 60ch;
  position: relative;
}
.q-explanation::before {
  content: "→";
  position: absolute;
  left: 14px;
  top: 12px;
  font-family: var(--font-mono);
  font-variation-settings: var(--rec-mono);
  font-style: normal;
  color: var(--accent-ink);
  background: var(--accent);
  width: 14px;
  height: 14px;
  display: inline-grid;
  place-items: center;
  font-size: 10px;
  line-height: 1;
}
.q-explanation.shown { display: block; }
.q-explanation strong { font-style: normal; color: var(--ink); font-weight: 600; }

.quiz-footer {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
  border-top: 1px solid var(--rule);
  padding-top: 16px;
  margin-top: 20px;
}
.quiz-reset {
  background: transparent;
  border: 1px solid var(--rule);
  color: var(--ink-2);
  font-family: var(--font-display);
  font-variation-settings: "wght" 500, var(--rec-sans);
  font-size: 11px;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  padding: 6px 12px;
  cursor: pointer;
  border-radius: 0;
}
.quiz-reset:hover { color: var(--ink); border-color: var(--ink); }
.quiz-verdict {
  font-family: var(--font-body);
  font-style: italic;
  color: var(--ink);
  font-size: 15px;
}
.quiz-verdict.excellent { color: var(--success); }
.quiz-verdict.partial   { color: var(--danger); }

/* Exam breakdown */
.exam-breakdown {
  margin-top: 26px;
  border-top: 1px solid var(--rule);
  padding-top: 20px;
}
.exam-breakdown h3 {
  font-family: var(--font-display);
  font-variation-settings: "wght" 700, var(--rec-sans-tight);
  font-size: 1.05rem;
  color: var(--ink);
  margin: 0 0 14px;
  border: 0;
  padding: 0;
}
.breakdown-list { list-style: none; padding: 0; margin: 0; }
.breakdown-list li {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 16px;
  padding: 10px 0;
  border-bottom: 1px dotted var(--rule);
  font-family: var(--font-body);
  font-size: 15px;
}
.breakdown-list li:last-child { border-bottom: 0; }
.breakdown-list .brk-ch { color: var(--ink); }
.breakdown-list .brk-score {
  font-family: var(--font-mono);
  font-variation-settings: var(--rec-mono);
  color: var(--ink-2);
  font-variant-numeric: tabular-nums;
}
.breakdown-list .brk-score.perfect { color: var(--success); }
.breakdown-list .brk-score.weak    { color: var(--danger); }

/* ---------- Auth modal ---------- */

.auth-user-info {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-family: var(--font-mono);
  font-variation-settings: var(--rec-mono);
  font-size: 11px;
  color: var(--ink-2);
}
.auth-user-email {
  font-family: var(--font-body);
  font-style: italic;
  font-size: 13px;
  color: var(--ink);
  max-width: 22ch;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.auth-modal {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}
.auth-backdrop {
  position: absolute;
  inset: 0;
  background: color-mix(in srgb, var(--ground) 88%, transparent);
  backdrop-filter: blur(3px);
  -webkit-backdrop-filter: blur(3px);
}
.auth-dialog {
  position: relative;
  background: var(--surface);
  border: 1px solid var(--rule-strong);
  padding: 36px 40px 28px;
  max-width: 440px;
  width: 100%;
  box-shadow: var(--shadow-lift);
  animation: auth-in .18s cubic-bezier(.22,.9,.29,1);
}
@keyframes auth-in {
  from { transform: translateY(6px); opacity: 0; }
  to   { transform: none; opacity: 1; }
}
.auth-close {
  position: absolute;
  top: 8px;
  right: 10px;
  background: transparent;
  border: 0;
  color: var(--ink-3);
  font-size: 22px;
  line-height: 1;
  padding: 6px 10px;
  cursor: pointer;
}
.auth-close:hover { color: var(--ink); background: var(--ground); }
.auth-eyebrow {
  font-family: var(--font-display);
  font-variation-settings: "wght" 700, var(--rec-sans);
  font-size: 10.5px;
  letter-spacing: 0.22em;
  text-transform: uppercase;
  color: var(--accent);
  display: inline-block;
  margin-bottom: 14px;
  line-height: 1;
}
.auth-title {
  font-family: var(--font-headline);
  font-weight: 400;
  font-size: 1.8rem;
  color: var(--ink);
  margin: 0 0 22px;
  letter-spacing: -0.005em;
  line-height: 1.1;
}
.auth-tabs { display: flex; margin-bottom: 22px; border-bottom: 1px solid var(--rule); }
.auth-tab {
  background: transparent;
  border: 0;
  padding: 10px 14px;
  font-family: var(--font-display);
  font-variation-settings: "wght" 500, var(--rec-sans);
  font-size: 11px;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--ink-3);
  cursor: pointer;
  border-bottom: 2px solid transparent;
  margin-bottom: -1px;
}
.auth-tab:hover { color: var(--ink); }
.auth-tab.active { color: var(--ink); border-bottom-color: var(--accent); font-variation-settings: "wght" 700, var(--rec-sans); }
.auth-form { display: flex; flex-direction: column; gap: 14px; }
.auth-field { display: flex; flex-direction: column; gap: 6px; }
.auth-field > span {
  font-family: var(--font-display);
  font-variation-settings: "wght" 600, var(--rec-sans);
  font-size: 10.5px;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--ink-3);
}
.auth-field input {
  background: var(--ground);
  border: 1px solid var(--rule);
  color: var(--ink);
  font-family: var(--font-body);
  font-size: 15.5px;
  padding: 10px 14px;
  caret-color: var(--accent);
}
.auth-field input:focus { outline: 0; border-color: var(--ink); }
.auth-error {
  color: var(--danger);
  font-family: var(--font-body);
  font-style: italic;
  font-size: 13.5px;
  min-height: 1.2em;
}
.auth-error:empty { display: none; }
.auth-submit {
  background: var(--ink);
  color: var(--ground);
  border: 0;
  font-family: var(--font-display);
  font-variation-settings: "wght" 600, var(--rec-sans);
  font-size: 11.5px;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  padding: 12px 20px;
  cursor: pointer;
  transition: background .12s ease, color .12s ease;
}
.auth-submit:hover:not(:disabled) { background: var(--accent); color: var(--accent-ink); }
.auth-submit:disabled { opacity: .6; cursor: default; }
.auth-note {
  font-family: var(--font-body);
  font-style: italic;
  font-size: 13px;
  color: var(--ink-3);
  margin: 8px 0 0;
  text-align: center;
  max-width: 44ch;
  align-self: center;
}

/* ---------- Focus & keyboard ---------- */

:focus { outline: 0; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* ---------- Mobile & narrow viewport ---------- */

@media (max-width: 900px) {
  .masthead {
    flex-direction: column;
    align-items: stretch;
    gap: 18px;
  }
  .masthead-meta {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 12px;
  }
  .meta-cell { gap: 2px; align-items: flex-start; }
}

/* -------- Tablet & narrow desktop -------- */
@media (max-width: 900px) {
  .loop-hero { padding: 8px 0 22px; }
  .loop-word { font-size: 48px; }
  .stage-flow { font-size: 11px; }
}

/* -------- Phone (portrait tablets & down) -------- */
@media (max-width: 640px) {
  body { font-size: 16.5px; line-height: 1.6; }
  .app { padding: 20px 16px 80px; }

  /* --- Masthead --- */
  .masthead { gap: 12px; padding-bottom: 12px; }
  .masthead-title { font-size: 1.5rem; line-height: 1; letter-spacing: -0.04em; }
  .masthead-subtitle { font-size: 0.88rem; margin-top: 3px; }
  .masthead-meta {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 10px 20px;
  }
  .meta-key { font-size: 8.5px; letter-spacing: 0.2em; }
  .meta-val { font-size: 12px; }

  /* --- Ctrl bar --- */
  .ctrl-bar {
    gap: 8px;
    padding: 8px 0 14px;
    margin-bottom: 24px;
  }
  .ctrl-status { flex-basis: 100%; margin-bottom: 2px; font-size: 9.5px; }
  .ctrl-status::before { width: 5px; height: 5px; margin-right: 8px; }
  .ctrl-actions { gap: 2px; flex-wrap: wrap; }
  .ctrl-btn { padding: 5px 7px; font-size: 9.5px; letter-spacing: 0.12em; }

  /* --- Loop hero: give it real breathing room but scale down --- */
  .loop-hero { padding: 4px 0 20px; margin-bottom: 16px; }
  .loop-word { font-size: 38px; }
  .stage-flow { font-size: 10px; letter-spacing: 0.04em; }
  .loop-caption { font-size: 12px; margin-top: 10px; }

  /* --- Today's plate — single column stack, tighter --- */
  .plate-today { grid-template-columns: 1fr; }
  .plate-block { padding: 22px 18px 20px; }
  .plate-block + .plate-block { border-left: 0; border-top: 1px solid var(--rule); }
  .plate-eyebrow { font-size: 9.5px; letter-spacing: 0.22em; margin-bottom: 16px; }
  .plate-title { font-size: 1.55rem; line-height: 1.05; max-width: none; margin-bottom: 8px; }
  .plate-tag { font-size: 0.97rem; margin-bottom: 16px; }
  .plate-metaline { font-size: 10.5px; margin-bottom: 16px; }
  .plate-open { font-size: 10.5px; padding: 6px 0; }

  /* Status stack: two per row on phone */
  .status-grid { gap: 14px; }
  .status-cell { grid-template-columns: auto 1fr; gap: 12px; padding-bottom: 12px; }
  .status-figure { font-size: 1.7rem; }
  .status-of { font-size: 0.5em; }
  .status-label { font-size: 9.5px; letter-spacing: 0.14em; text-align: right; }

  /* --- Glossary plate --- */
  .plate-def { padding: 18px 18px; gap: 8px; }
  .def-eyebrow { font-size: 10px; }
  .def-term { font-size: 1.3rem; }
  .def-body { font-size: 14.5px; line-height: 1.5; }
  .def-seen { font-size: 10.5px; }

  /* --- TOC heading + Parts --- */
  .toc-heading { grid-template-columns: auto 1fr; gap: 10px; padding-bottom: 10px; }
  .toc-heading h2 { font-size: 1.25rem; }
  .toc-count { grid-column: 1 / -1; font-size: 10.5px; margin-top: 2px; }
  .toc-numeral { width: 24px; height: 24px; font-size: 0.95rem; }

  .part-section { padding: 0 12px; margin-bottom: 16px; }
  .part-header { padding: 18px 0 8px; gap: 10px; }
  .part-num { font-size: 10.5px; }
  .part-title { font-size: 1rem; letter-spacing: -0.005em; }

  /* --- Chapter rows — two-line layout, no cramping --- */
  .chapter, .exam-card {
    grid-template-columns: 30px minmax(0, 1fr);
    grid-template-rows: auto auto;
    gap: 2px 12px;
    padding: 14px 4px;
    margin: 0 -4px;
    width: calc(100% + 8px);
  }
  .chapter-num { font-size: 12px; padding-top: 2px; grid-row: 1; }
  .chapter-body { grid-row: 1 / 3; grid-column: 2; min-width: 0; }
  .chapter-title { font-size: 0.98rem; line-height: 1.2; margin-bottom: 3px; }
  .chapter-tag { font-size: 12.5px; line-height: 1.35; -webkit-line-clamp: 2; }
  .chapter-stat {
    grid-column: 2;
    grid-row: 2;
    padding-top: 8px;
    font-size: 9.5px;
    letter-spacing: 0.12em;
    justify-self: start;
  }
  .chapter-score {
    grid-column: 1;
    grid-row: 2;
    text-align: left;
    padding-top: 8px;
    font-size: 11px;
    color: var(--ink-3);
  }
  .exam-card { padding-top: 18px; padding-bottom: 18px; }
  .exam-card .chapter-num { font-size: 9.5px; padding: 2px 4px 3px; letter-spacing: 0.12em; }

  /* --- Topic view --- */
  .topic-view { max-width: 100%; }
  .topic-head { padding: 20px 0 22px; margin-bottom: 32px; }
  .topic-eyebrow { font-size: 10.5px; margin-bottom: 10px; gap: 10px; }
  .topic-title { font-size: 1.95rem; line-height: 1.05; margin-bottom: 10px; max-width: none; }
  .topic-lede { font-size: 1rem; line-height: 1.42; max-width: none; }
  .topic-section { margin-bottom: 34px; max-width: none; }
  .topic-section h3 { font-size: 1rem; gap: 8px; }
  .prose p { font-size: 15.5px; line-height: 1.58; margin-bottom: 14px; }

  /* Drop cap looks silly at small sizes — scale it down */
  .topic-section:first-of-type .prose p:first-of-type::first-letter {
    font-size: 2.6rem;
    margin: 5px 8px 0 0;
  }

  /* Glossary — no columns on phone */
  .glossary { grid-template-columns: 1fr; gap: 4px 0; }
  .glossary dt { font-size: 0.95rem; padding-top: 14px; padding-bottom: 4px; }
  .glossary dd { font-size: 14.5px; padding-top: 0; border-top: 0; }

  /* Figure — no negative-margin breakout on phone */
  .figure { margin: 26px 0; padding: 16px 14px 14px; }
  .figure-tag { font-size: 9.5px; margin-bottom: 12px; }
  .figure-caption { font-size: 13px; padding-top: 10px; }

  /* Quiz */
  .quiz, .quiz-gate { padding: 22px 18px 20px; max-width: none; }
  .quiz-gate-eyebrow { font-size: 9.5px; margin-bottom: 12px; }
  .quiz-gate-title { font-size: 1.3rem; line-height: 1.15; }
  .quiz-gate-sub { font-size: 13.5px; margin-bottom: 20px; }
  .quiz-start { font-size: 10.5px; padding: 10px 16px; letter-spacing: 0.14em; }
  .quiz-heading { gap: 6px; padding-bottom: 12px; margin-bottom: 18px; }
  .quiz-heading h3 { font-size: 1.05rem; }
  .quiz-score { font-size: 11px; }
  .q-text { font-size: 0.98rem; line-height: 1.42; }
  .q-options { gap: 5px; }
  .q-option { font-size: 14px; padding: 10px 12px; }
  .q-option .letter { width: 18px; font-size: 11.5px; }
  .q-label { font-size: 10.5px; margin-bottom: 8px; }
  .q-source { display: block; margin-left: 0; margin-top: 2px; }
  .q-explanation { font-size: 13.5px; padding: 10px 12px 10px 30px; }
  .q-explanation::before { left: 10px; top: 10px; }
  .quiz-footer { padding-top: 14px; margin-top: 16px; }
  .quiz-reset { font-size: 10px; padding: 5px 10px; }
  .quiz-verdict { font-size: 13.5px; }

  /* Exam breakdown */
  .exam-breakdown { margin-top: 20px; padding-top: 16px; }
  .breakdown-list li { font-size: 13.5px; padding: 8px 0; gap: 12px; }

  /* Auth modal */
  .auth-modal { padding: 16px; }
  .auth-dialog { padding: 24px 22px 20px; }
  .auth-eyebrow { font-size: 9.5px; }
  .auth-title { font-size: 1.5rem; }
  .auth-tab { padding: 8px 12px; font-size: 10.5px; }
  .auth-field input { font-size: 15px; padding: 9px 12px; }
  .auth-submit { padding: 11px 18px; font-size: 10.5px; }
  .auth-note { font-size: 12px; }

  .colophon { margin-top: 44px; font-size: 12.5px; padding-top: 18px; }
  .back-link { margin-bottom: 22px; font-size: 9.5px; }
}

/* -------- Tiny phones (SE etc.) -------- */
@media (max-width: 380px) {
  .app { padding: 18px 14px 72px; }
  .masthead-title { font-size: 1.35rem; }
  .masthead-meta {
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 8px 12px;
  }
  .masthead-meta .meta-cell:nth-child(4) { display: none; }
  .loop-word { font-size: 32px; }
  .stage-flow { font-size: 9px; }
  .plate-title { font-size: 1.4rem; }
  .status-figure { font-size: 1.5rem; }
  .topic-title { font-size: 1.7rem; }
  .toc-heading h2 { font-size: 1.15rem; }
  .chapter, .exam-card { padding: 12px 4px; }
  .chapter-title { font-size: 0.94rem; }
  .chapter-tag { font-size: 12px; -webkit-line-clamp: 2; }
}

/* ---------- Reduced motion ---------- */

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; animation: none !important; }
}

/* ---------- Font loading (Recursive) ---------- */
/*
   Recursive is loaded via Google Fonts <link> in index.html.
   Its variable axes are set through font-variation-settings above.
   No fallback ships the same character; the system stack is a graceful degrade only.
*/
