/* Colours are OKLCH; every colour and font below is a token. Tints and
   shadows live here too so the light theme can redefine them. */
:root {
  --bg: oklch(17.3% 0.034 269.5);
  --panel: oklch(21% 0.052 270.1);
  --panel-2: oklch(23.6% 0.059 269);
  --raised: oklch(26.5% 0.062 269.5); /* cards over the diagram: lighter = higher */
  --line: oklch(32.2% 0.076 269.7);   /* panel borders, dividers */
  --link: oklch(52% 0.088 269.9);     /* inactive diagram links (3.4:1 on --bg) */
  --grid: oklch(64% 0.12 272 / 0.07);
  --fg: oklch(92.7% 0.035 273.3);
  --muted: oklch(66.4% 0.066 269.6);
  --accent: oklch(53.7% 0.215 265.2);      /* fills, borders, lines */
  --accent-text: oklch(71.4% 0.148 268.1); /* accent as text on dark panels */
  --on-accent: oklch(99% 0.005 268);       /* text on accent fills */
  --on-kind: oklch(17.3% 0.034 269.5);     /* text on request/attack/response/safe fills */
  --request: oklch(80.4% 0.146 75.3);
  --attack: oklch(65.5% 0.194 24.2);
  --response: oklch(70.9% 0.159 293.5);
  --safe: oklch(77.3% 0.153 163.2);
  --selection: oklch(58.5% 0.212 265.3 / 0.4);
  --accent-tint: oklch(58.5% 0.212 265.3 / 0.14);
  --attack-tint: oklch(65.5% 0.194 24.2 / 0.14);
  --safe-tint: oklch(77.3% 0.153 163.2 / 0.14);
  --mark-vuln: oklch(65.5% 0.194 24.2 / 0.25);
  --mark-fix: oklch(77.3% 0.153 163.2 / 0.2);
  --shadow: 0 2px 8px oklch(0% 0 0 / 0.3);
  --font-body: "IBM Plex Sans", system-ui, -apple-system, "Segoe UI", sans-serif;
  --font-mono: "IBM Plex Mono", ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  --ease-out: cubic-bezier(0.23, 1, 0.32, 1);
  --ease-in: cubic-bezier(0.55, 0, 1, 0.45);
  --ease-in-out: cubic-bezier(0.65, 0, 0.35, 1);
  accent-color: var(--accent);
}

@media (prefers-color-scheme: light) {
  :root {
    --bg: oklch(97% 0.008 271.3);
    --panel: oklch(99.4% 0.004 268);
    --panel-2: oklch(97.9% 0.007 268.5);
    --raised: oklch(99.4% 0.004 268);
    --line: oklch(89.1% 0.022 268.4);
    --link: oklch(59.2% 0.051 268.8);
    --grid: oklch(40% 0.14 270 / 0.06);
    --fg: oklch(22.3% 0.04 270.2);
    --muted: oklch(51.1% 0.044 266.9);
    --accent: oklch(51.7% 0.224 264.7);
    --accent-text: oklch(51.7% 0.224 264.7);
    --on-kind: oklch(99.4% 0.004 268);
    --request: oklch(54.5% 0.126 61.6);
    --attack: oklch(53.4% 0.193 26.8);
    --response: oklch(55% 0.206 293.7);
    --safe: oklch(50.8% 0.105 165.6);
    --selection: oklch(51.7% 0.224 264.7 / 0.25);
    --accent-tint: oklch(51.7% 0.224 264.7 / 0.1);
    --attack-tint: oklch(53.4% 0.193 26.8 / 0.1);
    --safe-tint: oklch(50.8% 0.105 165.6 / 0.1);
    --mark-vuln: oklch(53.4% 0.193 26.8 / 0.16);
    --mark-fix: oklch(50.8% 0.105 165.6 / 0.16);
    --shadow: 0 2px 8px oklch(30% 0.05 270 / 0.12);
  }
}

* { box-sizing: border-box; }
/* `hidden` always wins, even over components that set their own display. */
[hidden] { display: none !important; }

/* First Tab stop: jump straight to the playback controls. */
.skip-link {
  position: absolute;
  left: 0.75rem;
  top: -4rem;
  z-index: 20;
  padding: 0.6rem 0.9rem;
  border-radius: 6px;
  background: var(--accent);
  color: var(--on-accent);
  font-weight: 600;
  text-decoration: none;
}
.skip-link:focus { top: 0.75rem; }
.skip-link:focus-visible { outline: 2px solid var(--fg); outline-offset: 2px; }
#playback:focus { outline: none; } /* focused only as the skip link's target */

/* Browser surfaces in the palette: selection, scrollbars, numerals. */
html { scrollbar-color: var(--link) var(--bg); }
::selection { background: var(--selection); color: var(--fg); }
/* Nothing may scroll the page sideways; clip (not hidden) keeps sticky working. */
html, body { overflow-x: clip; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--fg);
  font-family: var(--font-body);
  line-height: 1.5;
}

h1, h2, h3, h4 { text-wrap: balance; }
p { text-wrap: pretty; }

button {
  font-family: inherit;
  font-size: 0.875rem;
  font-weight: 600;
  line-height: 1.2;
  padding: 0.45rem 0.8rem;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--panel-2);
  color: var(--fg);
  cursor: pointer;
}
button:hover:not(:disabled) { border-color: var(--accent); }
button:disabled { opacity: 0.35; cursor: default; }
button:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
button.primary { background: var(--accent); border-color: var(--accent); color: var(--on-accent); }

/* Interface icons: one stroke set, sized to the text they sit with. */
.ui-icon {
  width: 1.1em; height: 1.1em;
  flex: none;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

/* ---------- top bar ---------- */
.topbar {
  display: flex;
  align-items: center;
  gap: 2rem;
  padding: 0.75rem 1rem;
  border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: center; gap: 0.75rem; }
.brand-title { margin: 0; font-size: 1.15rem; font-weight: 700; letter-spacing: -0.01em; } /* the wordmark */
.brand small { display: block; color: var(--muted); font-size: 0.8rem; }
.logo {
  width: 34px; height: 34px;
  border: 2px solid var(--accent);
  border-radius: 8px;
  background: linear-gradient(135deg, transparent 45%, var(--attack) 45%, var(--attack) 55%, transparent 55%);
}
.now { margin: 0; border-left: 1px solid var(--line); padding-left: 1.5rem; }
.now strong { font-size: 1.05rem; font-weight: 700; }

/* ---------- layout ---------- */
.layout {
  display: grid;
  grid-template-columns: 280px minmax(0, 1fr) 320px;
  grid-template-rows: auto 1fr;
  grid-template-areas:
    "side stage details"
    "side log details";
  align-items: start; /* panels keep their own height; no stretched empty space */
  gap: 0.75rem;
  padding: 0.75rem;
}
.sidebar { grid-area: side; }
.stage-panel { grid-area: stage; }
.details { grid-area: details; }
.log { grid-area: log; }

/* Wider screens: the lesson list scrolls on its own, so the diagram never
   leaves the screen while browsing lessons. */
@media (min-width: 761px) {
  .sidebar {
    position: sticky;
    top: 0.75rem;
    max-height: calc(100vh - 1.5rem);
    overflow-y: auto;
    overscroll-behavior: contain;
    scrollbar-width: thin;
  }
}

/* One framed surface: the diagram panel. The lesson list, details and log
   sit on the page and are separated by space and hairlines. */
.panel {
  padding: 1rem;
  min-width: 0;
}
.stage-panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 10px;
}
.log { border-top: 1px solid var(--line); }
@media (min-width: 1101px) {
  .sidebar { border-right: 1px solid var(--line); }
  .details { border-left: 1px solid var(--line); }
}
.panel-title {
  margin: 0 0 0.75rem;
  font-size: 1.05rem;
  font-weight: 700;
}

/* ---------- sidebar ---------- */
.group { margin-bottom: 0.5rem; }
.group-head {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  width: 100%;
  padding: 0.55rem 0.7rem;
  text-align: left;
  background: var(--panel-2);
}
.chevron { display: inline-grid; transition: transform 200ms var(--ease-out); }
.group.open .chevron { transform: rotate(90deg); }
.group-label { flex: 1; }
.group-count { font-size: 0.8rem; font-weight: 400; color: var(--muted); }
.group-body { padding: 0.5rem 0 0.25rem; }
.group-caption { margin: 0 0 0.6rem 0.2rem; font-size: 0.8rem; color: var(--muted); }
.lesson { margin-bottom: 0.4rem; }
.lesson-btn {
  display: grid;
  grid-template-columns: auto 1fr;
  align-items: center;
  gap: 0 0.6rem;
  width: 100%;
  text-align: left;
  padding: 0.6rem 0.7rem;
  background: transparent;
}
.lesson.active .lesson-btn { border-color: var(--accent); background: var(--panel-2); }
.lesson-dot { grid-row: span 2; width: 10px; height: 10px; border-radius: 50%; border: 2px solid var(--muted); }
.lesson.active .lesson-dot { border-color: var(--accent); background: var(--accent); }
.lesson-name { font-size: 0.9rem; font-weight: 600; }
.lesson-id { font: 0.75rem var(--font-mono); color: var(--muted); }

.steps { list-style: none; margin: 0.5rem 0 0.75rem; padding: 0 0 0 0.4rem; }
.step-btn {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  width: 100%;
  border: 0;
  background: transparent;
  text-align: left;
  padding: 0.35rem 0.25rem;
}
.step-num {
  display: grid;
  place-items: center;
  flex: none;
  width: 22px; height: 22px;
  border-radius: 50%;
  font-size: 0.75rem;
  font-variant-numeric: tabular-nums;
  background: var(--panel-2);
  border: 1px solid var(--line);
  color: var(--muted);
}
.step-num .ui-icon { width: 14px; height: 14px; stroke-width: 2.5; }
.step-title { font-size: 0.875rem; font-weight: 400; color: var(--muted); }
.steps .done .step-num { background: var(--safe); border-color: var(--safe); color: var(--on-kind); }
.steps .current .step-num { background: var(--accent); border-color: var(--accent); color: var(--on-accent); }
.steps .current .step-title { color: var(--fg); font-weight: 700; }

/* ---------- stage ---------- */
.stage-bar { display: flex; align-items: center; gap: 1rem; flex-wrap: wrap; margin-bottom: 0.6rem; }
.seg { display: flex; border: 1px solid var(--line); border-radius: 7px; padding: 2px; }
.seg button { border: 0; background: transparent; color: var(--muted); }
#mode-vuln[aria-pressed="true"] { background: var(--attack); color: var(--on-kind); }
#mode-fix[aria-pressed="true"] { background: var(--safe); color: var(--on-kind); }
.summary { color: var(--muted); font-size: 0.85rem; flex: 1; min-width: 200px; max-width: 65ch; }

/* One line naming the version on screen; its colour follows the mode. */
.mode-strip {
  display: flex;
  align-items: center;
  gap: 0.45rem;
  margin: 0 0 0.6rem;
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--attack);
}
body[data-mode="fix"] .mode-strip { color: var(--safe); }

.stage-wrap { position: relative; }
.stage {
  position: relative;
  height: 340px;
  border-radius: 8px;
  overflow: hidden;
  background-color: var(--bg);
  background-image:
    linear-gradient(var(--grid) 1px, transparent 1px),
    linear-gradient(90deg, var(--grid) 1px, transparent 1px);
  background-size: 28px 28px;
}

.links { position: absolute; inset: 0; width: 100%; height: 100%; }
.links line {
  stroke: var(--link);
  stroke-width: 2px;
  vector-effect: non-scaling-stroke;
  stroke-dasharray: 4 6;
  transition: stroke 300ms var(--ease-in-out);
}
/* The current link takes the travelling packet's colour (--kind). */
.links line.current {
  stroke: var(--kind, var(--accent));
  animation: march 0.7s linear infinite;
}
@keyframes march { to { stroke-dashoffset: -10; } }

.node {
  position: absolute;
  transform: translate(-50%, -50%);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  transition: opacity 200ms var(--ease-out), transform 200ms var(--ease-out);
}
.node .icon {
  width: 60px; height: 60px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--panel);
  fill: none;
  stroke: currentColor;
  stroke-width: 1.5;
  stroke-linecap: round;
  stroke-linejoin: round;
  transition: border-color 200ms var(--ease-out), color 200ms var(--ease-out), background-color 200ms var(--ease-out);
}
.node-label { font: 600 0.75rem/1.25 var(--font-mono); max-width: 7.5rem; text-align: center; }
.node.dim { opacity: 0.65; } /* labels stay ≥4.5:1 */
.node.active { transform: translate(-50%, -50%) scale(1.08); }
.node.active .icon {
  color: var(--accent-text);
  border-color: var(--accent);
  background: var(--accent-tint);
}

/* An attack lands: the target turns red, pulses once, and is flagged
   "Under attack". In the fixed version the same device turns green and is
   flagged "Blocked", with the same timing and pulse.
   --arrive delays it to the moment the packet reaches the device. */
.node-flag {
  position: absolute;
  top: 100%; /* under the label: packet cards prefer the space above links */
  left: 50%;
  margin-top: 4px;
  transform: translateX(-50%);
  padding: 1px 6px;
  border-radius: 4px;
  background: var(--attack);
  color: var(--on-kind);
  font-size: 0.72rem;
  font-weight: 700;
  white-space: nowrap;
  opacity: 0;
  pointer-events: none;
}
.node.hit .node-flag,
.node.blocked .node-flag { opacity: 1; transition: opacity 150ms var(--ease-out) var(--arrive, 0ms); }
.node.blocked .node-flag { background: var(--safe); }
.node.hit .icon,
.node.blocked .icon {
  color: var(--attack);
  border-color: var(--attack);
  background: var(--attack-tint);
  transition-delay: var(--arrive, 0ms);
  animation: hit 420ms var(--ease-out) var(--arrive, 0ms) 1 both;
}
.node.blocked .icon { color: var(--safe); border-color: var(--safe); background: var(--safe-tint); }
@keyframes hit {
  0% { transform: scale(1); }
  35% { transform: scale(1.12); }
  100% { transform: scale(1); }
}

.packet {
  position: absolute;
  left: 0;
  top: 0;
  transform: translate(-50%, -50%); /* app.js replaces this with the card's position */
  will-change: transform;
  display: flex;
  flex-direction: column;
  /* max-content keeps the size independent of where the card sits, so
     app.js can measure it before positioning. */
  width: max-content;
  min-width: 110px;
  max-width: min(260px, 44%); /* % of the stage width */
  border: 1px solid var(--kind);
  border-radius: 6px;
  background: var(--raised);
  box-shadow: var(--shadow);
  font: 0.75rem/1.35 var(--font-mono); /* 12px: the card is the lesson's subject */
  z-index: 2;
  overflow: hidden;
}
.packet-tag {
  padding: 2px 8px;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  background: var(--kind);
  color: var(--on-kind);
}
.packet-body { padding: 3px 8px 4px; color: var(--fg); overflow-wrap: anywhere; } /* wraps on narrow stages */

/* kind colours (packet, link, badge, tag, legend dot) */
.request { --kind: var(--request); }
.attack { --kind: var(--attack); }
.response { --kind: var(--response); }
.safe { --kind: var(--safe); }

/* End of lesson: the outcome under the playback bar (it replaces the hint),
   so the diagram's final state stays in full view. Its two actions live in
   the bar itself (#endcard-flip, #endcard-next). */
.endcard {
  margin-top: 0.75rem;
  padding-top: 0.75rem;
  border-top: 1px solid var(--line);
  animation: endcard-in 250ms var(--ease-out) both;
}
.endcard-title { margin: 0; font-size: 1rem; font-weight: 700; }
.endcard p { margin: 0.2rem 0 0; font-size: 0.9rem; color: var(--muted); max-width: 65ch; }
body.done .hint { display: none; }
@keyframes endcard-in { from { opacity: 0; transform: translateY(4px); } }

/* Phones only: the step's text right under the diagram, and the lesson's
   name right above it. */
.caption { display: none; }
.stage-title { display: none; }

/* ---------- playback ---------- */
/* Directly under the diagram (see the phone rule further down). */
.controls { display: flex; align-items: center; gap: 0.4rem; margin-top: 0.75rem; }
.controls button { display: inline-flex; align-items: center; justify-content: center; gap: 0.35rem; white-space: nowrap; }
#play { min-width: 7.5rem; }
.counter { margin-left: auto; white-space: nowrap; font: 0.75rem var(--font-mono); font-variant-numeric: tabular-nums; color: var(--muted); }
.hint { margin: 0.6rem 0 0; font-size: 0.85rem; color: var(--muted); }

/* ---------- details ---------- */
.details h3 { margin: 0; font-size: 1.3rem; font-weight: 700; line-height: 1.25; }
.sub { margin: 0.2rem 0 0.6rem; color: var(--accent-text); font-size: 0.9rem; }
.note { margin: 0 0 0.9rem; font-size: 1rem; }
.details p { max-width: 65ch; }
.details-toggle { display: none; } /* phones only */

/* Code gets a typographic frame (rules above and below), not a box. */
pre {
  margin: 0 0 1rem;
  padding: 0.75rem 0;
  min-height: 2.5rem;
  border-top: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
  white-space: pre-wrap;
  word-break: break-word;
  font: 0.8rem/1.6 var(--font-mono);
}
mark { padding: 1px 2px; border-radius: 3px; color: inherit; }
mark.vuln { background: var(--mark-vuln); outline: 1px solid var(--attack); }
mark.fix { background: var(--mark-fix); outline: 1px solid var(--safe); }
mark:empty { display: none; }

.case {
  margin: 0 0 1rem;
  padding: 0.85rem 0 0;
  border-top: 1px solid var(--line);
}
.case-heading { margin: 0 0 0.3rem; font-size: 0.95rem; font-weight: 700; }
#case-id { display: block; font: 700 0.95rem var(--font-mono); }
.case-name { display: block; font: 0.8rem var(--font-mono); color: var(--muted); }
#case-text { margin: 0.4rem 0 0; font-size: 0.85rem; }

dl { display: grid; grid-template-columns: max-content 1fr; gap: 0; margin: 0; font-size: 0.8rem; }
dt, dd { padding: 0.45rem 0; border-top: 1px solid var(--line); }
dt { font-size: 0.8rem; font-weight: 600; color: var(--muted); padding-right: 1rem; }
dd { margin: 0; }

/* ---------- log ---------- */
.log-bar { display: flex; align-items: center; flex-wrap: wrap; gap: 0.75rem 1.25rem; margin-bottom: 0.5rem; }
.log-bar .panel-title { margin: 0; }
.legend { display: flex; flex-wrap: wrap; gap: 0.4rem 0.9rem; margin: 0; padding: 0; list-style: none; font-size: 0.8rem; color: var(--muted); }
.legend li { display: flex; align-items: center; gap: 0.35rem; }
.dot { width: 8px; height: 8px; border-radius: 50%; background: var(--kind); }

.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font: 0.78rem var(--font-mono); font-variant-numeric: tabular-nums; }
th { text-align: left; color: var(--muted); font-family: var(--font-body); font-size: 0.8rem; font-weight: 600; padding: 0.4rem 0.6rem; }
td { padding: 0.4rem 0.6rem; border-top: 1px solid var(--line); white-space: nowrap; }
td.info { white-space: normal; }
tbody tr { cursor: pointer; }
tbody tr:hover { background: var(--panel-2); }
tbody tr.current { background: var(--panel-2); font-weight: 700; }
tbody tr.new { animation: row-in 450ms var(--ease-out); }
@keyframes row-in { from { opacity: 0; transform: translateY(-6px); } }
/* The step number is the row's keyboard target. */
.row-btn { display: inline-grid; padding: 0; border: 0; background: none; border-radius: 50%; }

.badge {
  display: inline-grid;
  place-items: center;
  width: 22px; height: 22px;
  border-radius: 50%;
  background: var(--kind);
  color: var(--on-kind);
  font-weight: 700;
}
.tag { color: var(--kind); font-weight: 700; font-size: 0.78rem; }

/* Phones only (see the 760px rule): the lesson list folds behind this button. */
.lessons-toggle { display: none; }

/* Visually hidden, still read by screen readers. */
.sr-only {
  position: absolute;
  width: 1px; height: 1px;
  margin: -1px; padding: 0;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
  border: 0;
}

/* Touch screens and phones: 44px targets with 8px between them. */
@media (max-width: 760px), (pointer: coarse) {
  .controls { gap: 0.5rem; }
  .controls button, .seg button, .group-head, .step-btn, .lessons-toggle { min-height: 44px; }
  .controls button:not(.primary) { min-width: 44px; }
  .row-btn { padding: 11px; margin: -11px; }
}

/* ---------- lesson switch (View Transitions API) ---------- */
/* Only the panels that change crossfade; the page itself and the sidebar stay still. */
.now { view-transition-name: now; }
.stage-panel { view-transition-name: stage; }
.controls { view-transition-name: controls; } /* captured on its own so it stays put */
::view-transition-old(controls),
::view-transition-new(controls) { animation: none; }
.details { view-transition-name: details; }
.log { view-transition-name: log; }
::view-transition-old(root),
::view-transition-new(root) { animation: none; }
::view-transition-group(now),
::view-transition-group(stage),
::view-transition-group(details),
::view-transition-group(log) { animation-duration: 250ms; animation-timing-function: var(--ease-out); }
::view-transition-old(now),
::view-transition-old(stage),
::view-transition-old(details),
::view-transition-old(log) { animation: vt-out 200ms var(--ease-in) both; }
::view-transition-new(now),
::view-transition-new(stage),
::view-transition-new(details),
::view-transition-new(log) { animation: vt-in 250ms var(--ease-out) both; }
@keyframes vt-out { to { opacity: 0; } }
@keyframes vt-in { from { opacity: 0; } }

/* ---------- responsive ---------- */
@media (max-width: 1100px) {
  .stage { height: 380px; } /* narrower diagram: more height keeps 12px cards clear */
  .layout {
    grid-template-columns: 264px minmax(0, 1fr);
    grid-template-rows: none;
    grid-template-areas:
      "side stage"
      "side details"
      "log log";
  }
}
@media (max-width: 760px) {
  .topbar { flex-direction: column; align-items: flex-start; gap: 0.5rem; }
  .now { display: none; } /* the lesson's name sits right above its diagram instead */
  .stage-title { display: block; margin: 0 0 0.6rem; font-size: 1.05rem; font-weight: 700; line-height: 1.3; }
  /* The summary is the lesson's intro: on phones it gives way to the diagram. */
  .summary { display: none; }
  .layout {
    grid-template-columns: minmax(0, 1fr);
    grid-template-rows: none;
    grid-template-areas: "side" "stage" "details" "log";
    padding: 0.5rem 16px;
  }
  /* Tall enough for four devices and a card; the step caption still fits
     under it, above the pinned bar, on a 375×812 screen. */
  .stage { height: 360px; }
  .node .icon { width: 48px; height: 48px; padding: 9px; }
  .node-label { white-space: normal; max-width: 64px; text-align: center; font-size: 0.72rem; line-height: 1.2; }
  .caption { display: block; margin-top: 0.6rem; }
  .caption strong { display: block; font-size: 1rem; }
  .caption span { display: block; font-size: 0.95rem; }

  .lessons-toggle {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.75rem;
    width: 100%;
    text-align: left;
  }
  .toggle-hint { font-weight: 400; color: var(--accent-text); }
  .sidebar:not(.open) #lessons { display: none; }
  .sidebar .panel-title { margin-bottom: 0.5rem; font-size: 0.9rem; color: var(--muted); }
  .sidebar.open #lessons { margin-top: 0.75rem; }

  /* Details: the step text is already under the diagram; the rest folds. */
  .details #title, .details .sub, .details .note { display: none; }
  .details-toggle { display: block; width: 100%; min-height: 44px; margin-bottom: 0.25rem; }
  .details:not(.open) .details-more { display: none; }
  .details.open .details-more { margin-top: 0.75rem; }

  /* Log: keep the number, type and info in view. */
  .col-from, .col-to { display: none; }

  /* Icons alone on the pinned bar; the words stay for screen readers. */
  .controls .btn-text {
    position: absolute; width: 1px; height: 1px; margin: -1px; padding: 0;
    overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0;
  }
  .hint { display: none; } /* the pinned bar is self-explanatory on touch */
  /* Details and log stack below the diagram on phones, so keep playback
     reachable: pin the bar to the bottom of the screen. */
  .controls {
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 10;
    margin: 0;
    padding: 0.6rem 16px calc(0.6rem + env(safe-area-inset-bottom));
    background: var(--panel);
    border-top: 1px solid var(--line);
  }
  body { padding-bottom: 4.5rem; } /* room so the bar never covers the end of the page */
  /* .stage-panel's view-transition-name makes it a stacking context, so the
     bar's z-index only counts inside it. Lift the whole panel above the later
     panels (they never overlap it on phones) so the pinned bar paints on top. */
  .stage-panel { position: relative; z-index: 10; }
  /* Unframed sections line up with the diagram card's edge. */
  .sidebar, .details, .log { padding-inline: 0; }
  /* A tighter diagram margin keeps cards clear of devices. */
  .stage-panel { padding: 0.75rem; }
  /* Last step: the two next moves fill the bar; the counter just says 6 / 6. */
  body.done .counter,
  body.done .controls #reset { display: none; } /* "See the fix/attack" restarts too */
  body.done .controls #endcard-flip,
  body.done .controls #endcard-next { flex: 1; }
}

/* Narrowest phones (320–360px): give the diagram every spare pixel. */
@media (max-width: 360px) {
  .stage-panel { padding: 0.5rem; }
  .node .icon { width: 44px; height: 44px; padding: 8px; }
  body.done .controls #prev { display: none; } /* room for both labels on one line */
  .stage { height: 400px; } /* narrowest diagram: height makes up for width */
}

@media (prefers-reduced-motion: reduce) {
  /* Keep opacity feedback; drop movement. */
  .links line.current { animation: none; }
  .node { transition: opacity 150ms var(--ease-out); }
  .node.active { transform: translate(-50%, -50%); }
  .node.hit .icon, .node.blocked .icon { animation: none; }
  .chevron { transition: none; }
  tbody tr.new { animation: row-fade 150ms var(--ease-out); }
  .endcard { animation: row-fade 150ms var(--ease-out); }
  /* Lesson switch: keep the crossfade, drop the panels' size/position morph. */
  ::view-transition-group(*) { animation: none; }
}
@keyframes row-fade { from { opacity: 0; } }
