/* ============================================================================
   „Unter der Haube" — Karten-Deck
   Ein Kapitel pro Bildschirm, Scroll rastet ein.

   Die Farben tragen Bedeutung und sind im ganzen Deck konsistent:
     Amber  = Stack        Cyan = Heap
     Grau   = Code-Segment Rot  = Fehler (und NUR Fehler)
   Wer Kapitel 04 gesehen hat, liest Kapitel 09 ohne Legende.
============================================================================ */

/* Variable Fonts, selbst gehostet — keine externen Requests. Latin-Subset;
   deshalb kommen Pfeile im Deck aus SVG und nicht aus Zeichen wie U+2192,
   das in diesem Subset fehlt und sonst aus einer Fremdschrift käme. */
@font-face {
  font-family: "Inter var";
  font-style: normal;
  font-display: swap;
  font-weight: 100 900;
  src: url("../assets/fonts/inter-latin-wght-normal.woff2") format("woff2-variations");
  unicode-range: U+0000-00FF,U+0131,U+0152-0153,U+02BB-02BC,U+02C6,U+02DA,U+02DC,
                 U+0304,U+0308,U+0329,U+2000-206F,U+20AC,U+2122,U+2191,U+2193,
                 U+2212,U+2215,U+FEFF,U+FFFD;
}
@font-face {
  font-family: "JetBrains Mono var";
  font-style: normal;
  font-display: swap;
  font-weight: 100 800;
  src: url("../assets/fonts/jetbrains-mono-latin-wght-normal.woff2") format("woff2-variations");
  unicode-range: U+0000-00FF,U+0131,U+0152-0153,U+02BB-02BC,U+02C6,U+02DA,U+02DC,
                 U+0304,U+0308,U+0329,U+2000-206F,U+20AC,U+2122,U+2191,U+2193,
                 U+2212,U+2215,U+FEFF,U+FFFD;
}

:root {
  --bg: #101317;
  --raise: #171b21;
  --sink: #0b0d10;
  --line: #262c35;
  --line-soft: #1c212a;

  --ink: #e8ecf1;
  --ink-mute: #9aa5b2;
  --ink-faint: #808b98;

  /* Bedeutungsfarben — nie dekorativ einsetzen. */
  --stack: #f0a83c;
  --stack-wash: rgb(240 168 60 / 0.13);
  --stack-edge: rgb(240 168 60 / 0.42);
  --heap: #45b7cf;
  --heap-wash: rgb(69 183 207 / 0.13);
  --heap-edge: rgb(69 183 207 / 0.42);
  --code: #8a94a3;
  --code-wash: rgb(138 148 163 / 0.12);
  --err: #f2635c;
  --err-wash: rgb(242 99 92 / 0.13);

  --sans: "Inter var", ui-sans-serif, system-ui, -apple-system, sans-serif;
  --mono: "JetBrains Mono var", ui-monospace, "Cascadia Code", Consolas, monospace;

  /* Fluid; die Obergrenzen sind bewusst niedrig — eine Karte muss auf einen
     Bildschirm passen, nicht möglichst groß aussehen. */
  --t-kicker: clamp(0.66rem, 0.6rem + 0.22vw, 0.78rem);
  --t-body: clamp(0.9rem, 0.84rem + 0.3vw, 1.06rem);
  --t-lead: clamp(0.98rem, 0.9rem + 0.42vw, 1.2rem);
  --t-h2: clamp(1.45rem, 1.15rem + 1.7vw, 2.5rem);
  --t-h1: clamp(2rem, 1.2rem + 4.4vw, 4.6rem);
  --t-code: clamp(0.74rem, 0.68rem + 0.3vw, 0.9rem);
  --t-micro: clamp(0.62rem, 0.58rem + 0.2vw, 0.74rem);

  --pad-x: clamp(1.15rem, 4vw, 4.5rem);
  --pad-y: clamp(1.05rem, 2.6vh, 2.4rem);
  --rail-w: clamp(2.2rem, 3.4vw, 3.4rem);
  --radius: 12px;

  --ease: cubic-bezier(0.22, 0.68, 0.24, 1);
  --dur: 620ms;
}

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

/* display: flex/inline-flex schlägt sonst die Browserregel für [hidden] —
   ohne JS stünden Stepper-Knöpfe und Rückgabewerte sichtbar, aber tot da. */
[hidden] { display: none !important; }

html {
  background: var(--bg);
  color-scheme: dark;
  scroll-behavior: smooth;
  -webkit-text-size-adjust: 100%;
}

body {
  margin: 0;
  font-family: var(--sans);
  font-size: var(--t-body);
  line-height: 1.6;
  color: var(--ink-mute);
  background: var(--bg);
  overflow-x: hidden;
  font-synthesis-weight: none;
}

h1, h2, h3 { margin: 0; font-family: var(--mono); color: var(--ink); font-weight: 700; }
p { margin: 0; }
code, kbd, pre { font-family: var(--mono); }

a { color: var(--stack); text-underline-offset: 3px; }
a:focus-visible,
button:focus-visible { outline: 2px solid var(--stack); outline-offset: 3px; border-radius: 4px; }

.sr-only {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}

/* ---------------------------------------------------------------------------
   Deck & Karten

   min-height statt height: läuft eine Karte auf einem kleinen Gerät doch
   einmal über, wächst sie einfach mit, statt Inhalt abzuschneiden. Der Snap
   fängt weiterhin ihren Anfang.
--------------------------------------------------------------------------- */
.deck {
  scroll-snap-type: y proximity;
  scroll-padding-top: 0;
}

.card {
  position: relative;
  min-height: 100svh;
  scroll-snap-align: start;
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: clamp(0.6rem, 1.5vh, 1.15rem);
  padding: var(--pad-y) calc(var(--pad-x) + var(--rail-w)) var(--pad-y) var(--pad-x);
  border-top: 1px solid var(--line-soft);
}
.card:first-child { border-top: 0; }

.card__inner {
  width: 100%;
  max-width: 78rem;
  margin-inline: auto;
  display: flex;
  flex-direction: column;
  gap: clamp(0.55rem, 1.35vh, 1.05rem);
}

/* Kopfzeile einer Karte */
.kicker {
  display: flex;
  align-items: center;
  gap: 0.7em;
  font-family: var(--mono);
  font-size: var(--t-kicker);
  font-weight: 600;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: var(--ink-faint);
}
.kicker__num { color: var(--stack); }
.kicker::after {
  content: "";
  flex: 1;
  height: 1px;
  background: linear-gradient(90deg, var(--line) 0%, transparent 100%);
}

.card h2 {
  font-size: var(--t-h2);
  line-height: 1.04;
  letter-spacing: -0.025em;
  text-wrap: balance;
}

.lead {
  font-size: var(--t-lead);
  line-height: 1.4;
  color: var(--ink);
  max-width: 46ch;
  text-wrap: pretty;
}
.lead strong { color: var(--stack); font-weight: 600; }

/* Der Hauptteil: Diagramm neben Erklärung, auf schmalen Geräten untereinander. */
.split {
  display: grid;
  gap: clamp(0.85rem, 2.4vw, 2.2rem);
  align-items: center;
  grid-template-columns: 1fr;
}
.split > * { min-width: 0; }
@media (min-width: 62rem) {
  .split { grid-template-columns: minmax(0, 1.05fr) minmax(0, 1fr); }
  .split--wide { grid-template-columns: minmax(0, 1.5fr) minmax(0, 1fr); }
}

.note { color: var(--ink-mute); max-width: 44ch; }
.note + .note { margin-top: 0.6em; }
.note strong { color: var(--ink); font-weight: 600; }

/* Fußnote — der Unterschied zwischen Instagram-Post und Ausarbeitung. */
.caveat {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  gap: 0.6em;
  align-items: start;
  font-size: var(--t-micro);
  line-height: 1.5;
  color: var(--ink-faint);
  max-width: 96ch;
  padding-top: 0.55em;
  border-top: 1px solid var(--line-soft);
}
.caveat__mark {
  flex: none;
  font-family: var(--mono);
  font-weight: 700;
  color: var(--ink-faint);
  letter-spacing: 0.1em;
}

/* Code */
.code {
  margin: 0;
  padding: clamp(0.7rem, 1.5vw, 1.05rem) clamp(0.8rem, 1.6vw, 1.2rem);
  background: var(--sink);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  font-size: var(--t-code);
  line-height: 1.75;
  color: var(--ink);
  overflow-x: auto;
  tab-size: 2;
}
.code__lang {
  display: block;
  white-space: normal;
  font-size: var(--t-micro);
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--ink-faint);
  margin-bottom: 0.55em;
}
.code b { font-weight: 400; color: var(--stack); }        /* Schlüsselwort */
.code i { font-style: normal; color: var(--heap); }        /* Bezeichner/Wert */
.code s { text-decoration: none; color: var(--ink-faint); }/* Kommentar */
.code em { font-style: normal; color: var(--err); }        /* Fehlerstelle */
.code .ln { display: block; padding: 0 0.35em; margin: 0 -0.35em; border-radius: 3px; }
.code .ln--on { background: var(--stack-wash); box-shadow: inset 2px 0 0 var(--stack); }

/* ---------------------------------------------------------------------------
   Fortschrittsleiste rechts — ein Segment je Kapitel, jedes ein echter Anker.
--------------------------------------------------------------------------- */
.rail {
  position: fixed;
  top: 50%;
  right: clamp(0.45rem, 1.2vw, 1.1rem);
  transform: translateY(-50%);
  z-index: 20;
}
.rail__list { list-style: none; margin: 0; padding: 0; display: grid; gap: 6px; }

.rail__item {
  --bar-w: 2px;
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 0.6em;
  padding: 3px 2px;
  text-decoration: none;
  color: var(--ink-faint);
}
.rail__bar {
  display: block;
  width: clamp(14px, 1.6vw, 22px);
  height: var(--bar-w);
  border-radius: 2px;
  background: var(--line);
  transition: background 260ms var(--ease), width 260ms var(--ease), height 260ms var(--ease);
}
.rail__label {
  font-family: var(--mono);
  font-size: var(--t-micro);
  letter-spacing: 0.04em;
  white-space: nowrap;
  opacity: 0;
  transform: translateX(6px);
  transition: opacity 200ms var(--ease), transform 200ms var(--ease);
  pointer-events: none;
  order: -1;
}
.rail__item:hover .rail__label,
.rail__item:focus-visible .rail__label { opacity: 1; transform: none; }
.rail__item:hover .rail__bar { background: var(--ink-faint); }

.rail__item[aria-current="true"] .rail__bar {
  background: var(--stack);
  height: 4px;
  width: clamp(20px, 2.4vw, 30px);
}
.rail__item[aria-current="true"] .rail__label { opacity: 1; transform: none; color: var(--stack); }

@media (max-width: 44rem) {
  .rail__label { display: none; }
  .rail__bar { width: 12px; }
}

/* Scroll-Hinweis auf der Titelkarte */
.hint {
  display: inline-flex;
  align-items: center;
  gap: 0.55em;
  font-family: var(--mono);
  font-size: var(--t-micro);
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--ink-faint);
}
.hint__arrow { display: block; width: 0.9em; height: 0.9em; }
.js .hint__arrow { animation: nudge 2.6s var(--ease) infinite; }
@keyframes nudge {
  0%, 62%, 100% { transform: translateY(0); opacity: 0.65; }
  78%           { transform: translateY(4px); opacity: 1; }
}

kbd {
  font-size: 0.9em;
  padding: 0.12em 0.42em;
  border: 1px solid var(--line);
  border-bottom-width: 2px;
  border-radius: 4px;
  background: var(--sink);
  color: var(--ink-mute);
}

/* ---------------------------------------------------------------------------
   Animationsbasis — Startzustände gelten NUR mit JS (html.js). Ohne JS hat
   .anim keine Regel und alles steht sofort im Endzustand da.
--------------------------------------------------------------------------- */
.js .anim {
  opacity: 0;
  transform: translateY(12px);
  transition:
    opacity var(--dur) var(--ease) var(--d, 0ms),
    transform var(--dur) var(--ease) var(--d, 0ms);
}
.js .is-active .anim { opacity: 1; transform: none; }

.js .anim--grow { transform: scaleY(0); transform-origin: bottom; }
.js .is-active .anim--grow { transform: none; }

.js .anim--wipe { clip-path: inset(0 100% 0 0); transition: clip-path var(--dur) var(--ease) var(--d, 0ms), opacity var(--dur) var(--ease) var(--d, 0ms); }
.js .is-active .anim--wipe { clip-path: inset(0 0 0 0); }

/* ---------------------------------------------------------------------------
   Gemeinsame Diagramm-Bausteine
--------------------------------------------------------------------------- */
.fig {
  margin: 0;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 0.7rem;
}
.fig__cap {
  font-family: var(--mono);
  font-size: var(--t-micro);
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--ink-faint);
}

/* Ein beschriftetes Kästchen — Grundform fast aller Diagramme hier. */
.box {
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--raise);
  padding: 0.6rem 0.75rem;
  font-family: var(--mono);
  font-size: var(--t-code);
  color: var(--ink);
  line-height: 1.35;
}
.box--stack { border-color: var(--stack-edge); background: var(--stack-wash); }
.box--heap  { border-color: var(--heap-edge);  background: var(--heap-wash); }
.box--code  { border-color: var(--line);       background: var(--code-wash); color: var(--ink-mute); }
.box--err   { border-color: var(--err);        background: var(--err-wash); }

.tag {
  display: inline-block;
  font-family: var(--mono);
  font-size: var(--t-micro);
  letter-spacing: 0.12em;
  text-transform: uppercase;
  padding: 0.15em 0.5em;
  border-radius: 999px;
  border: 1px solid currentColor;
}
.tag--stack { color: var(--stack); }
.tag--heap  { color: var(--heap); }
.tag--err   { color: var(--err); }

/* Legende Amber/Cyan — steht einmal auf Kapitel 04 und wird nie wiederholt. */
.legend { display: flex; flex-wrap: wrap; gap: 0.4rem 1.1rem; font-size: var(--t-micro); font-family: var(--mono); color: var(--ink-faint); }
.legend span { display: inline-flex; align-items: center; gap: 0.45em; }
.legend i { width: 0.7em; height: 0.7em; border-radius: 3px; display: block; }

/* ---------------------------------------------------------------------------
   01 — Übersetzungskette
--------------------------------------------------------------------------- */
.pipe { display: flex; align-items: stretch; gap: 0; flex-wrap: wrap; }
.pipe__stage {
  flex: 1 1 5.5rem;
  min-width: 0;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--raise);
  padding: 0.55rem 0.6rem;
  text-align: center;
}
.pipe__stage b { display: block; font-family: var(--mono); font-size: var(--t-code); color: var(--ink); font-weight: 600; }
.pipe__stage span { display: block; font-size: var(--t-micro); color: var(--ink-faint); margin-top: 0.15em; }
.pipe__stage--out { border-color: var(--stack-edge); background: var(--stack-wash); }
.pipe__link { flex: 0 0 clamp(0.9rem, 2.4vw, 2rem); align-self: center; color: var(--line); }
.pipe__link svg { display: block; width: 100%; height: 12px; }

.morph { display: grid; gap: 0.5rem; }
.morph .code { padding-block: 0.5rem; }

/* ---------------------------------------------------------------------------
   02 — Drei Wege zur Ausführung
--------------------------------------------------------------------------- */
.lanes { display: grid; gap: 0.85rem; }
.lane { display: grid; grid-template-columns: 4.6rem minmax(0, 1fr); gap: 0.7rem; align-items: center; }
.lane__name { font-family: var(--mono); font-size: var(--t-code); color: var(--ink); font-weight: 600; }
.lane__track {
  position: relative;
  height: 2.35rem;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--sink);
  display: flex;
  overflow: hidden;
}
.lane__seg {
  flex: 1;
  display: grid;
  place-items: center;
  font-family: var(--mono);
  font-size: var(--t-micro);
  color: var(--ink-faint);
  border-right: 1px dashed var(--line);
  padding-inline: 0.2rem;
  text-align: center;
}
.lane__seg:last-child { border-right: 0; }
.lane__seg--live { color: var(--ink); background: var(--stack-wash); }
.lane__when { font-family: var(--mono); font-size: var(--t-micro); color: var(--ink-faint); }

/* ---------------------------------------------------------------------------
   03 — Bytes im Speicher
--------------------------------------------------------------------------- */
.bytes { display: flex; gap: 0.35rem; flex-wrap: wrap; }
.byte {
  flex: 1 1 3.4rem;
  min-width: 3.1rem;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--raise);
  padding: 0.4rem 0.3rem;
  text-align: center;
}
.byte__addr { display: block; font-family: var(--mono); font-size: 0.62em; color: var(--ink-faint); letter-spacing: -0.02em; }
.byte__val { display: block; font-family: var(--mono); font-size: var(--t-code); color: var(--ink); font-weight: 600; margin-top: 0.15em; }
.byte--lit { border-color: var(--stack-edge); background: var(--stack-wash); }

.reads { display: grid; gap: 0.5rem; }
.read {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  gap: 0.7rem;
  align-items: baseline;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0.45rem 0.7rem;
  background: var(--raise);
}
.read__as { font-family: var(--mono); font-size: var(--t-micro); color: var(--ink-faint); text-transform: uppercase; letter-spacing: 0.1em; }
.read__val { font-family: var(--mono); font-size: var(--t-code); color: var(--ink); }
.read--odd { border-color: var(--err); background: var(--err-wash); }
.read--odd .read__val { color: var(--err); }

/* ---------------------------------------------------------------------------
   04 — Speicherbild eines Prozesses
--------------------------------------------------------------------------- */
.memmap { display: grid; gap: 3px; font-family: var(--mono); }
.seg {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.6rem;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--raise);
  padding: 0.5rem 0.7rem;
  font-size: var(--t-code);
  color: var(--ink);
}
.seg small { font-family: var(--sans); font-size: var(--t-micro); color: var(--ink-faint); text-align: right; }
.seg--stack { border-color: var(--stack-edge); background: var(--stack-wash); }
.seg--heap  { border-color: var(--heap-edge);  background: var(--heap-wash); }
.seg--free  { border-style: dashed; background: transparent; color: var(--ink-faint); justify-content: center; padding-block: 0.85rem; }
.seg--free svg { color: var(--ink-faint); }
.memmap__edge { display: flex; justify-content: space-between; font-size: var(--t-micro); color: var(--ink-faint); letter-spacing: 0.08em; }
.grow { display: inline-flex; align-items: center; gap: 0.4em; font-size: var(--t-micro); color: inherit; }
.grow svg { width: 0.8em; height: 0.8em; }

/* ---------------------------------------------------------------------------
   05 / 06 / 09 — Der Stapel
--------------------------------------------------------------------------- */
.stackview {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--sink);
  padding: 0.7rem;
  display: flex;
  flex-direction: column;
  gap: 0.45rem;
  min-height: clamp(11rem, 27vh, 16.5rem);
  justify-content: flex-end;
}
.frames { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 0.4rem; }

.frame {
  border: 1px solid var(--stack-edge);
  border-radius: 9px;
  background: var(--stack-wash);
  padding: 0.45rem 0.6rem;
  font-family: var(--mono);
  font-size: var(--t-code);
  transition:
    opacity 340ms var(--ease),
    transform 340ms var(--ease),
    border-color 340ms var(--ease),
    background 340ms var(--ease);
  transform-origin: bottom center;
}
.frame--base { border-color: var(--line); background: var(--raise); }
.frame__fn { display: block; color: var(--ink); font-weight: 600; }
.frame__rows { display: flex; flex-wrap: wrap; gap: 0.15rem 0.9rem; margin-top: 0.2rem; }
.frame__row { display: inline-flex; gap: 0.4em; font-size: 0.92em; color: var(--ink-faint); }
.frame__row b { color: var(--ink); font-weight: 500; }

.js .frame.is-off { opacity: 0; transform: translateY(14px) scaleY(0.72); pointer-events: none; }
.frame.is-top { box-shadow: 0 0 0 1px var(--stack), 0 8px 26px -14px var(--stack); }
.frame.is-back { opacity: 0.55; }
.frame.is-dead { border-color: var(--err); background: var(--err-wash); opacity: 0.75; }

.frame__ret {
  display: inline-flex;
  align-items: center;
  gap: 0.35em;
  margin-top: 0.25rem;
  font-size: 0.9em;
  color: var(--stack);
}
.frame__ret svg { width: 0.85em; height: 0.85em; }

/* Steuerung */
.stepper { display: flex; flex-wrap: wrap; align-items: center; gap: 0.45rem; }
.btn {
  font-family: var(--mono);
  font-size: var(--t-micro);
  letter-spacing: 0.09em;
  text-transform: uppercase;
  color: var(--ink-mute);
  background: var(--raise);
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 0.42em 0.95em;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 0.45em;
  transition: color 180ms var(--ease), border-color 180ms var(--ease), background 180ms var(--ease);
}
.btn:hover:not(:disabled) { color: var(--ink); border-color: var(--ink-faint); }
.btn:disabled { opacity: 0.4; cursor: not-allowed; }
.btn--primary { color: var(--bg); background: var(--stack); border-color: var(--stack); font-weight: 700; }
.btn--primary:hover:not(:disabled) { color: var(--bg); background: #ffc264; border-color: #ffc264; }
.btn svg { width: 0.9em; height: 0.9em; }

.stepper__count { font-family: var(--mono); font-size: var(--t-micro); color: var(--ink-faint); margin-left: auto; }
.say {
  min-height: 3.1em;
  font-size: var(--t-body);
  color: var(--ink);
  border-left: 2px solid var(--stack);
  padding-left: 0.8rem;
  max-width: 44ch;
}
.say b { color: var(--stack); font-weight: 600; }

/* ---------------------------------------------------------------------------
   07 — Stack gegen Heap
--------------------------------------------------------------------------- */
.compare { display: grid; gap: 0.7rem; grid-template-columns: 1fr; }
@media (min-width: 34rem) { .compare { grid-template-columns: 1fr 1fr; } }
.col {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 0.75rem 0.85rem;
  background: var(--raise);
  display: flex;
  flex-direction: column;
  gap: 0.55rem;
}
.col--stack { border-color: var(--stack-edge); }
.col--heap  { border-color: var(--heap-edge); }
.col__head { display: flex; align-items: center; justify-content: space-between; gap: 0.5rem; }
.col__head b { font-family: var(--mono); font-size: var(--t-code); color: var(--ink); }
.facts { list-style: none; margin: 0; padding: 0; display: grid; gap: 0.4rem; }
.facts li { display: grid; grid-template-columns: 6.2rem minmax(0, 1fr); gap: 0.5rem; font-size: var(--t-micro); line-height: 1.45; }
.facts dt, .facts .k { font-family: var(--mono); color: var(--ink-faint); letter-spacing: 0.06em; text-transform: uppercase; }
.facts .v { color: var(--ink-mute); }
.facts .v b { color: var(--ink); font-weight: 600; }

/* ---------------------------------------------------------------------------
   06 / 08 — Zeiger-Diagramme als Inline-SVG
   (Pfeile werden gezeichnet, nicht getippt: U+2192 fehlt im Latin-Subset.)
--------------------------------------------------------------------------- */
.svgfig { width: 100%; height: auto; display: block; overflow: visible; }
.svgfig text { font-family: var(--mono); fill: var(--ink); }
.svgfig .t-mute { fill: var(--ink-faint); }
.svgfig .t-stack { fill: var(--stack); }
.svgfig .t-heap { fill: var(--heap); }
.svgfig .t-err { fill: var(--err); }
.svgfig .b-stack { fill: var(--stack-wash); stroke: var(--stack-edge); }
.svgfig .b-heap { fill: var(--heap-wash); stroke: var(--heap-edge); }
.svgfig .b-plain { fill: var(--raise); stroke: var(--line); }
.svgfig .b-err { fill: var(--err-wash); stroke: var(--err); }
.svgfig .arrow { stroke: var(--ink-faint); stroke-width: 1.5; fill: none; }
.svgfig .arrow--stack { stroke: var(--stack); }
.svgfig .arrow--err { stroke: var(--err); stroke-dasharray: 4 3; }

/* Pfad zeichnet sich, sobald die Karte sichtbar ist. */
.js .svgfig .draw { stroke-dasharray: var(--len, 200); stroke-dashoffset: var(--len, 200); transition: stroke-dashoffset 700ms var(--ease) var(--d, 0ms); }
.js .is-active .svgfig .draw { stroke-dashoffset: 0; }

/* ---------------------------------------------------------------------------
   09 — Wenn es kracht
--------------------------------------------------------------------------- */
.crashes { display: grid; gap: 0.7rem; grid-template-columns: 1fr; }
@media (min-width: 50rem) { .crashes { grid-template-columns: repeat(3, 1fr); } }
.crash {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--raise);
  padding: 0.75rem 0.85rem;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}
.crash h3 { font-size: var(--t-code); color: var(--err); letter-spacing: -0.01em; }
.crash p { font-size: var(--t-micro); line-height: 1.55; color: var(--ink-mute); }
.crash__from { font-family: var(--mono); font-size: var(--t-micro); color: var(--ink-faint); margin-top: auto; padding-top: 0.5rem; border-top: 1px solid var(--line-soft); }
.crash__from b { color: var(--stack); font-weight: 600; }

/* Stapel läuft voll */
.overflowbar { height: clamp(4.5rem, 12vh, 7rem); border: 1px solid var(--line); border-radius: 8px; background: var(--sink); display: flex; flex-direction: column-reverse; padding: 3px; gap: 2px; overflow: hidden; }
.overflowbar i { display: block; height: 6px; border-radius: 2px; background: var(--stack); opacity: 0.85; flex: none; }
.overflowbar i.is-over { background: var(--err); }

/* Heap füllt sich mit Müll */
.leakgrid { display: grid; grid-template-columns: repeat(8, 1fr); gap: 3px; }
/* Die Farbe liegt auf ::before, damit sie sich unabhängig von der leeren
   Zelle ein- und ausblenden lässt — sonst müsste die Animation je Zelle eine
   andere Zielfarbe kennen. */
.leakgrid i { position: relative; display: block; aspect-ratio: 1; border-radius: 3px; background: var(--line-soft); }
.leakgrid i::before { content: ""; position: absolute; inset: 0; border-radius: inherit; opacity: 0.8; }
.leakgrid i.is-used::before { background: var(--heap); }
.leakgrid i.is-leak::before { background: var(--err); }

/* ---------------------------------------------------------------------------
   Titelkarte & Abschluss
--------------------------------------------------------------------------- */
.cover { justify-content: center; }
.cover h1 {
  font-family: var(--mono);
  font-size: var(--t-h1);
  line-height: 0.98;
  letter-spacing: -0.045em;
  color: var(--ink);
  text-wrap: balance;
}
.cover h1 em { font-style: normal; color: var(--stack); }
.cover__meta { display: flex; flex-wrap: wrap; gap: 0.5rem 1.4rem; font-family: var(--mono); font-size: var(--t-micro); letter-spacing: 0.12em; text-transform: uppercase; color: var(--ink-faint); }

.glossary { display: grid; gap: 0.45rem 1.6rem; grid-template-columns: 1fr; margin: 0; }
@media (min-width: 46rem) { .glossary { grid-template-columns: 1fr 1fr; } }
.glossary div { display: grid; grid-template-columns: 8.6rem minmax(0, 1fr); gap: 0.6rem; align-items: baseline; }
.glossary dt { font-family: var(--mono); font-size: var(--t-micro); color: var(--stack); }
.glossary dd { margin: 0; font-size: var(--t-micro); line-height: 1.5; color: var(--ink-mute); }

.takeaways { list-style: none; margin: 0; padding: 0; display: grid; gap: 0.6rem; }
.takeaways li { display: grid; grid-template-columns: 1.5rem minmax(0, 1fr); gap: 0.6rem; align-items: start; }
.takeaways .n { font-family: var(--mono); font-size: var(--t-micro); color: var(--stack); padding-top: 0.25em; }

.outro { display: flex; flex-wrap: wrap; gap: 0.7rem 1.4rem; align-items: center; padding-top: 0.6rem; border-top: 1px solid var(--line-soft); }
.outro a { font-family: var(--mono); font-size: var(--t-micro); letter-spacing: 0.1em; text-transform: uppercase; }

/* ---------------------------------------------------------------------------
   Bewegung reduzieren — Endzustände sofort, aber alles bleibt bedienbar.
--------------------------------------------------------------------------- */
/* html.motion-on heißt: hier hat jemand die Bewegung ausdrücklich eingeschaltet,
   obwohl das System sie reduziert haben will. Diese Wahl sticht — sonst liefe
   der Schalter für genau diese Leute ins Leere. */
@media (prefers-reduced-motion: reduce) {
  html:not(.motion-on) { scroll-behavior: auto; }
  html:not(.motion-on) *,
  html:not(.motion-on) *::before,
  html:not(.motion-on) *::after {
    animation-duration: 1ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 1ms !important;
    transition-delay: 0ms !important;
  }
  html:not(.motion-on) .anim { opacity: 1; transform: none; }
  html:not(.motion-on) .svgfig .draw { stroke-dashoffset: 0; }
}

/* ---------------------------------------------------------------------------
   Druck — Snap aufgehoben, Karten untereinander, helle Fläche.
--------------------------------------------------------------------------- */
@media print {
  :root { --bg: #fff; --raise: #fff; --sink: #fafafa; --ink: #111; --ink-mute: #333; --ink-faint: #666; --line: #bbb; --line-soft: #ddd; }
  /* color-scheme: dark färbt sonst die gesamte Seitenfläche inklusive der
     Druckränder dunkel — dort greift keine background-Regel. */
  html { color-scheme: light; }
  html, body { background: #fff; }
  .deck { scroll-snap-type: none; }
  .card { min-height: 0; page-break-after: always; break-after: page; padding: 1.4cm 0; border-top: 0; }
  .rail, .stepper, .hint { display: none; }
  .js .anim, .js .svgfig .draw, .frame.is-off { opacity: 1 !important; transform: none !important; stroke-dashoffset: 0 !important; }
  .say { min-height: 0; }
}

/* ---------------------------------------------------------------------------
   Enge Geräte

   Auf dem Telefon passt der Stoff der schwersten Kapitel nicht auf einen
   Bildschirm. Statt Inhalt zu streichen wird hier alles gestrafft, was keine
   Aussage kostet — der Rest darf scrollen. Der Snap steht auf „proximity“,
   deshalb rastet er dabei nicht störend ein, und die Tastatursteuerung zeigt
   erst den Rest einer Karte, bevor sie zur nächsten springt.
--------------------------------------------------------------------------- */
@media (max-width: 48rem) {
  :root {
    --pad-y: 0.95rem;
    --t-code: clamp(0.7rem, 0.66rem + 0.2vw, 0.8rem);
  }
  .card { gap: 0.5rem; }
  .card__inner { gap: 0.45rem; }
  .split { gap: 0.7rem; }
  .note + .note { margin-top: 0.5em; }
  .stackview { min-height: 9.5rem; padding: 0.5rem; }
  .frame { padding: 0.35rem 0.5rem; }
  .pipe__stage { padding: 0.4rem 0.45rem; }
  .crash { padding: 0.6rem 0.7rem; gap: 0.4rem; }

  /* Umbrechende Kette: der Pfeil am Zeilenende zeigte auf nichts. Auf schmalen
     Geräten wird daraus ein Raster, die Reihenfolge trägt eine Nummer. */
  .pipe { display: grid; grid-template-columns: 1fr 1fr; gap: 0.35rem; counter-reset: stage; }
  .pipe__link { display: none; }
  .pipe__stage { counter-increment: stage; }
  .pipe__stage b::before {
    content: counter(stage) " ";
    color: var(--ink-faint);
    font-weight: 400;
  }
  .overflowbar { height: 3.4rem; }
  .col { padding: 0.6rem 0.7rem; gap: 0.4rem; }
  .code { padding: 0.55rem 0.7rem; line-height: 1.65; }
  .say { min-height: 0; }
}

@media (max-width: 34rem) {
  .card { padding-right: calc(var(--pad-x) + 1.6rem); }
  .lane { grid-template-columns: 3.6rem minmax(0, 1fr); }
  .facts li { grid-template-columns: 5rem minmax(0, 1fr); }
  .glossary div { grid-template-columns: 7rem minmax(0, 1fr); }
  .byte { flex: 1 1 2.6rem; min-width: 2.6rem; }
}

/* Codeblock mit einzeln markierbaren Zeilen (Kapitel 05). Kein <pre>: so
   fallen die Zeilenumbrüche im Quelltext nicht als Leerzeilen ins Ergebnis. */
.code--lines { white-space: normal; }
.code--lines .ln { white-space: pre; min-height: 1lh; }

/* ============================================================================
   BEWEGUNG

   Jede Karte spielt ihren Vorgang ab, sobald sie im Bild ist, und wiederholt
   ihn. Die Regeln hängen an .is-playing — weil sie ohne die Klasse gar nicht
   existieren, beginnt jede Animation beim Hinzufügen von vorn.

   Zwei Muster kommen immer wieder vor:
   · Welle — ein Keyframe, viele Elemente, gestaffelte animation-delay. Der
     Zustand wandert sichtbar durch die Kette und läuft in derselben Reihenfolge
     wieder zurück.
   · Ablauf — mehrere Keyframes mit Prozentfenstern auf einer gemeinsamen
     Dauer. Nötig, wenn Dinge in unterschiedlicher Reihenfolge kommen und gehen.

   Ohne Bewegung (Schalter aus oder ohne JS) steht überall der Endzustand —
   die Diagramme bleiben vollständig aussagekräftig.
============================================================================ */

html.motion-off *,
html.motion-off *::before,
html.motion-off *::after {
  animation: none !important;
}

/* --- Schalter --------------------------------------------------------- */
.motion {
  position: fixed;
  right: clamp(0.45rem, 1.2vw, 1.1rem);
  bottom: clamp(0.55rem, 2vh, 1.3rem);
  z-index: 21;
  display: inline-flex;
  align-items: center;
  gap: 0.55em;
  font-family: var(--mono);
  font-size: var(--t-micro);
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--ink-faint);
  background: rgb(23 27 33 / 0.93);
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 0.42em 0.85em;
  cursor: pointer;
  transition: color 180ms var(--ease), border-color 180ms var(--ease);
}
.motion:hover { color: var(--ink); border-color: var(--ink-faint); }
.motion__dot {
  width: 0.55em;
  height: 0.55em;
  border-radius: 50%;
  background: var(--stack);
  flex: none;
}
.motion[aria-pressed="true"] .motion__dot { animation: pulse 2s ease-in-out infinite; }
.motion[aria-pressed="false"] .motion__dot { background: none; box-shadow: inset 0 0 0 1px var(--ink-faint); }
@keyframes pulse { 0%, 100% { opacity: 1; } 50% { opacity: 0.35; } }

@media (max-width: 34rem) {
  .motion { bottom: 0.5rem; right: 0.5rem; padding: 0.4em 0.7em; }
}

/* --- Titelkarte: der Stapel baut sich auf und wieder ab ---------------- */
.cover__stack {
  position: absolute;
  right: clamp(2.5rem, 11vw, 9rem);
  top: 50%;
  transform: translateY(-50%);
  display: flex;
  flex-direction: column;
  gap: 6px;
  width: clamp(8rem, 15vw, 13rem);
  pointer-events: none;
}
.cframe {
  display: block;
  height: clamp(1.5rem, 3.2vh, 2.3rem);
  border-radius: 9px;
  border: 1px solid var(--stack-edge);
  background: var(--stack-wash);
  transform-origin: bottom center;
}
.cframe--base { border-color: var(--line); background: var(--raise); }
@media (max-width: 66rem) { .cover__stack { display: none; } }

/* Aufgelegt wird von unten nach oben, abgeräumt in umgekehrter Reihenfolge —
   deshalb drei Keyframes statt einem mit Versatz. */
.is-playing .cframe:nth-child(3) { animation: cf-a 7s ease-in-out infinite; }
.is-playing .cframe:nth-child(2) { animation: cf-b 7s ease-in-out infinite; }
.is-playing .cframe:nth-child(1) { animation: cf-c 7s ease-in-out infinite; }
@keyframes cf-a {
  0%, 6%    { opacity: 0; transform: translateY(9px) scaleY(0.5); }
  14%, 74%  { opacity: 1; transform: none; }
  82%, 100% { opacity: 0; transform: translateY(9px) scaleY(0.5); }
}
@keyframes cf-b {
  0%, 18%   { opacity: 0; transform: translateY(9px) scaleY(0.5); }
  26%, 62%  { opacity: 1; transform: none; }
  70%, 100% { opacity: 0; transform: translateY(9px) scaleY(0.5); }
}
@keyframes cf-c {
  0%, 30%   { opacity: 0; transform: translateY(9px) scaleY(0.5); }
  38%, 50%  { opacity: 1; transform: none; }
  58%, 100% { opacity: 0; transform: translateY(9px) scaleY(0.5); }
}

/* --- 01 Die Übersetzung läuft als Welle durch die Kette ---------------- */
.is-playing .pipe__stage { animation: stage-fill 11s ease-in-out infinite; }
.is-playing .pipe__stage:nth-child(1)  { animation-delay: 0ms; }
.is-playing .pipe__stage:nth-child(3)  { animation-delay: 700ms; }
.is-playing .pipe__stage:nth-child(5)  { animation-delay: 1400ms; }
.is-playing .pipe__stage:nth-child(7)  { animation-delay: 2100ms; }
.is-playing .pipe__stage:nth-child(9)  { animation-delay: 2800ms; }
.is-playing .pipe__stage:nth-child(11) { animation-delay: 3500ms; }
@keyframes stage-fill {
  0%, 1%    { border-color: var(--line); background: var(--raise); box-shadow: none; }
  5%        { border-color: var(--stack); background: var(--stack-wash); box-shadow: 0 0 0 2px var(--stack-wash); }
  9%, 62%   { border-color: var(--stack-edge); background: var(--stack-wash); box-shadow: none; }
  70%, 100% { border-color: var(--line); background: var(--raise); box-shadow: none; }
}

.is-playing .pipe__link svg { animation: link-run 11s ease-in-out infinite; }
.is-playing .pipe__link:nth-child(2)  svg { animation-delay: 350ms; }
.is-playing .pipe__link:nth-child(4)  svg { animation-delay: 1050ms; }
.is-playing .pipe__link:nth-child(6)  svg { animation-delay: 1750ms; }
.is-playing .pipe__link:nth-child(8)  svg { animation-delay: 2450ms; }
.is-playing .pipe__link:nth-child(10) svg { animation-delay: 3150ms; }
@keyframes link-run {
  0%, 1%   { color: var(--line); transform: translateX(-3px); }
  5%       { color: var(--stack); transform: translateX(3px); }
  10%, 100% { color: var(--line); transform: none; }
}

/* Der passende Codestreifen leuchtet auf, wenn seine Stufe erreicht ist. */
.is-playing .morph .code { animation: strip-lit 11s ease-in-out infinite; }
.is-playing .morph .code:nth-of-type(1) { animation-delay: 200ms; }
.is-playing .morph .code:nth-of-type(2) { animation-delay: 1600ms; }
.is-playing .morph .code:nth-of-type(3) { animation-delay: 2300ms; }
@keyframes strip-lit {
  0%, 1%    { border-color: var(--line); }
  5%, 60%   { border-color: var(--stack-edge); }
  70%, 100% { border-color: var(--line); }
}

/* --- 02 Marker fahren die drei Bahnen ab ------------------------------- */
.lane__track { position: relative; }
.lane__cursor {
  position: absolute;
  top: 2px;
  bottom: 2px;
  left: 2px;
  width: calc((100% - 4px) / var(--n, 4));
  border-radius: 6px;
  background: var(--stack-wash);
  box-shadow: inset 0 0 0 1px var(--stack-edge);
  opacity: 0;
  pointer-events: none;
}
/* C übersetzt einmal vorher und läuft dann durch — der Marker parkt am Ende. */
.is-playing .lane__cursor--c { animation: run-c 12s ease-in-out infinite; }
@keyframes run-c {
  0%, 4%    { opacity: 1; transform: translateX(0); }
  10%, 14%  { opacity: 1; transform: translateX(100%); }
  20%, 24%  { opacity: 1; transform: translateX(200%); }
  30%, 94%  { opacity: 1; transform: translateX(300%); }
  99%, 100% { opacity: 0; transform: translateX(300%); }
}
/* Python übersetzt beim Start und liest danach dauernd Bytecode — der Marker
   bleibt am Ende stehen und pulsiert. */
.is-playing .lane__cursor--python {
  animation:
    run-py 12s ease-in-out infinite,
    breathe 1.4s ease-in-out infinite;
}
@keyframes run-py {
  0%, 6%    { opacity: 1; transform: translateX(0); }
  14%, 20%  { opacity: 1; transform: translateX(100%); }
  28%, 100% { opacity: 1; transform: translateX(200%); }
}
@keyframes breathe { 0%, 100% { box-shadow: inset 0 0 0 1px var(--stack-edge); } 50% { box-shadow: inset 0 0 0 2px var(--stack); } }
/* Java wechselt zur Laufzeit zwischen Ausführen und Nachübersetzen. */
.is-playing .lane__cursor--java { animation: run-java 12s ease-in-out infinite; }
@keyframes run-java {
  0%, 6%    { opacity: 1; transform: translateX(0); }
  14%, 20%  { opacity: 1; transform: translateX(100%); }
  28%, 40%  { opacity: 1; transform: translateX(200%); }
  48%, 56%  { opacity: 1; transform: translateX(300%); }
  64%, 72%  { opacity: 1; transform: translateX(200%); }
  80%, 88%  { opacity: 1; transform: translateX(300%); }
  96%, 100% { opacity: 1; transform: translateX(200%); }
}

/* --- 03 Bytes werden geschrieben, dann wechselt die Deutung ------------ */
.is-playing .byte { animation: byte-write 11s ease-in-out infinite; }
.is-playing .byte:nth-child(1) { animation-delay: 0ms; }
.is-playing .byte:nth-child(2) { animation-delay: 260ms; }
.is-playing .byte:nth-child(3) { animation-delay: 520ms; }
.is-playing .byte:nth-child(4) { animation-delay: 780ms; }
@keyframes byte-write {
  0%, 1%    { border-color: var(--line); background: var(--raise); transform: scale(0.94); }
  4%        { border-color: var(--stack); background: var(--stack-wash); transform: scale(1.06); }
  8%, 88%   { border-color: var(--stack-edge); background: var(--stack-wash); transform: none; }
  94%, 100% { border-color: var(--line); background: var(--raise); transform: scale(0.94); }
}
/* Die drei Deutungen kommen nacheinander dran — dieselben Bits, andere Antwort. */
.is-playing .read { animation: read-turn 11s ease-in-out infinite; }
.is-playing .read:nth-child(1) { animation-delay: 0ms; }
.is-playing .read:nth-child(2) { animation-delay: 2000ms; }
.is-playing .read:nth-child(3) { animation-delay: 4000ms; }
@keyframes read-turn {
  0%, 14%   { opacity: 0.35; transform: translateX(0); }
  18%, 30%  { opacity: 1; transform: translateX(6px); }
  36%, 100% { opacity: 0.55; transform: none; }
}

/* --- 04 Stack und Heap wachsen sichtbar aufeinander zu ------------------ */
.seg--free { position: relative; overflow: hidden; min-height: 3.6rem; }
.seg__label { position: relative; z-index: 1; }
.creep { position: absolute; left: 0; right: 0; height: 0; }
.creep--stack { top: 0; background: var(--stack-wash); border-bottom: 1px solid var(--stack); }
.creep--heap { bottom: 0; background: var(--heap-wash); border-top: 1px solid var(--heap); }

.is-playing .creep--stack { animation: creep-down 9s ease-in-out infinite; }
.is-playing .creep--heap { animation: creep-up 9s ease-in-out infinite; }
@keyframes creep-down {
  0%, 5%    { height: 0; }
  48%, 68%  { height: 40%; }
  94%, 100% { height: 0; }
}
@keyframes creep-up {
  0%, 12%   { height: 0; }
  56%, 68%  { height: 32%; }
  90%, 100% { height: 0; }
}
/* Der jeweilige Bereich meldet sich, wenn er dran ist. */
.is-playing .seg--stack { animation: seg-glow 9s ease-in-out infinite; }
.is-playing .seg--heap { animation: seg-glow 9s ease-in-out infinite; animation-delay: 800ms; }
@keyframes seg-glow {
  0%, 8%    { box-shadow: none; }
  16%, 30%  { box-shadow: 0 0 0 1px currentColor; }
  40%, 100% { box-shadow: none; }
}

/* --- 06 Erst gilt der Zeiger, dann nicht mehr -------------------------- */
.is-playing .scene6 .s6--a { animation: scene-a 8s ease-in-out infinite; }
.is-playing .scene6 .s6--b { animation: scene-b 8s ease-in-out infinite; }
@keyframes scene-a {
  0%, 5%    { opacity: 0.2; }
  12%, 44%  { opacity: 1; }
  54%, 100% { opacity: 0.28; }
}
@keyframes scene-b {
  0%, 46%   { opacity: 0.15; }
  56%, 94%  { opacity: 1; }
  99%, 100% { opacity: 0.15; }
}
/* Der rote Zeiger findet keinen Halt mehr — die Striche wandern. */
.is-playing .scene6 .s6--b .s6-line { animation: line-drift 1.6s linear infinite; }
@keyframes line-drift { to { stroke-dashoffset: -14; } }

/* --- 07 Ein Sprung gegen eine Suche ------------------------------------ */
.alloc {
  position: relative;
  display: flex;
  gap: 3px;
  padding: 3px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--sink);
}
.alloc__slot { flex: 1; display: block; height: 1.15rem; border-radius: 4px; background: var(--line-soft); }
.alloc--heap .alloc__slot.is-used { background: var(--heap); opacity: 0.5; }
.alloc__ptr, .alloc__scan {
  position: absolute;
  top: 3px;
  bottom: 3px;
  left: 3px;
  width: calc((100% - 6px - 15px) / 6);
  border-radius: 4px;
  pointer-events: none;
}
.alloc__ptr { box-shadow: inset 0 0 0 2px var(--stack); }
.alloc__scan { box-shadow: inset 0 0 0 2px var(--heap); }
.alloc__say { font-size: var(--t-micro); color: var(--ink-faint); font-family: var(--mono); }

/* Die Marke rückt einen Platz weiter, in einem Zug. */
.is-playing .alloc__ptr { animation: ptr-jump 9s ease-in-out infinite; }
@keyframes ptr-jump {
  0%, 24%   { transform: translateX(0); }
  26%, 72%  { transform: translateX(calc(1 * (100% + 3px))); }
  74%, 100% { transform: translateX(0); }
}
/* Der Allokator tastet sich Block für Block vor, bis einer frei ist. */
.is-playing .alloc__scan { animation: scan-walk 9s ease-in-out infinite; }
@keyframes scan-walk {
  0%, 6%    { transform: translateX(0); }
  12%, 20%  { transform: translateX(calc(1 * (100% + 3px))); }
  26%, 34%  { transform: translateX(calc(2 * (100% + 3px))); }
  40%, 48%  { transform: translateX(calc(3 * (100% + 3px))); }
  54%, 86%  { transform: translateX(calc(4 * (100% + 3px))); }
  94%, 100% { transform: translateX(0); }
}
.is-playing .alloc__slot[data-found] { animation: slot-claim 9s ease-in-out infinite; }
@keyframes slot-claim {
  0%, 54%   { background: var(--line-soft); }
  60%, 86%  { background: var(--heap); }
  94%, 100% { background: var(--line-soft); }
}

/* --- 08 Verlinken, ändern, dann kopieren -------------------------------- */
/* Grundzustand ist der Endzustand: „nachher“ steht, „vorher“ ist weg. */
.s8-before { opacity: 0; }

.is-playing .scene8--a { animation: s8-a-focus 12s ease-in-out infinite; }
@keyframes s8-a-focus {
  0%, 44%   { opacity: 1; }
  56%, 92%  { opacity: 0.4; }
  98%, 100% { opacity: 1; }
}
.is-playing .scene8--a .s8-late { animation: s8-appear 12s ease-in-out infinite; }
@keyframes s8-appear {
  0%, 8%    { opacity: 0; }
  16%, 100% { opacity: 1; }
}
.is-playing .scene8--a .s8-before { animation: s8-was 12s ease-in-out infinite; }
.is-playing .scene8--a .s8-after  { animation: s8-now 12s ease-in-out infinite; }
@keyframes s8-was { 0%, 24.9% { opacity: 1; } 25%, 100% { opacity: 0; } }
@keyframes s8-now { 0%, 24.9% { opacity: 0; } 25%, 100% { opacity: 1; } }
.is-playing .scene8--a .s8-obj { animation: obj-hit 12s ease-in-out infinite; }
@keyframes obj-hit {
  0%, 24.9% { stroke-width: 1; }
  25%       { stroke-width: 3; }
  34%, 100% { stroke-width: 1; }
}

.is-playing .scene8--b { animation: s8-b-focus 12s ease-in-out infinite; }
@keyframes s8-b-focus {
  0%, 46%   { opacity: 0.28; }
  58%, 100% { opacity: 1; }
}
.is-playing .scene8--b .s8-late { animation: s8-appear-late 12s ease-in-out infinite; }
@keyframes s8-appear-late {
  0%, 58%   { opacity: 0; }
  66%, 100% { opacity: 1; }
}
.is-playing .scene8--b .s8-before { animation: s8-was-late 12s ease-in-out infinite; }
.is-playing .scene8--b .s8-after  { animation: s8-now-late 12s ease-in-out infinite; }
@keyframes s8-was-late { 0%, 76.9% { opacity: 1; } 77%, 100% { opacity: 0; } }
@keyframes s8-now-late { 0%, 76.9% { opacity: 0; } 77%, 100% { opacity: 1; } }
.is-playing .scene8--b .s8-obj { animation: obj-hit-late 12s ease-in-out infinite; }
@keyframes obj-hit-late {
  0%, 76.9% { stroke-width: 1; }
  77%       { stroke-width: 3; }
  86%, 100% { stroke-width: 1; }
}

/* --- 09 Der Stapel läuft voll, das Leck frisst sich durch --------------- */
.is-playing .overflowbar i { animation: bar-rise 10s ease-in-out infinite; transform-origin: left; }
.is-playing .overflowbar i:nth-child(1)  { animation-delay: 0ms; }
.is-playing .overflowbar i:nth-child(2)  { animation-delay: 260ms; }
.is-playing .overflowbar i:nth-child(3)  { animation-delay: 520ms; }
.is-playing .overflowbar i:nth-child(4)  { animation-delay: 780ms; }
.is-playing .overflowbar i:nth-child(5)  { animation-delay: 1040ms; }
.is-playing .overflowbar i:nth-child(6)  { animation-delay: 1300ms; }
.is-playing .overflowbar i:nth-child(7)  { animation-delay: 1560ms; }
.is-playing .overflowbar i:nth-child(8)  { animation-delay: 1820ms; }
.is-playing .overflowbar i:nth-child(9)  { animation-delay: 2080ms; }
.is-playing .overflowbar i:nth-child(10) { animation-delay: 2340ms; }
@keyframes bar-rise {
  0%, 2%    { transform: scaleX(0); }
  6%, 84%   { transform: scaleX(1); }
  92%, 100% { transform: scaleX(0); }
}
.is-playing .overflowbar { animation: box-hit 10s ease-in-out infinite; }
@keyframes box-hit {
  0%, 30%   { border-color: var(--line); }
  34%, 84%  { border-color: var(--err); }
  92%, 100% { border-color: var(--line); }
}

.is-playing .leakgrid i::before { animation: cell-in 10s ease-in-out infinite; }
.is-playing .leakgrid i:nth-child(1)::before  { animation-delay: 0ms; }
.is-playing .leakgrid i:nth-child(2)::before  { animation-delay: 200ms; }
.is-playing .leakgrid i:nth-child(3)::before  { animation-delay: 400ms; }
.is-playing .leakgrid i:nth-child(4)::before  { animation-delay: 600ms; }
.is-playing .leakgrid i:nth-child(5)::before  { animation-delay: 800ms; }
.is-playing .leakgrid i:nth-child(6)::before  { animation-delay: 1000ms; }
.is-playing .leakgrid i:nth-child(7)::before  { animation-delay: 1200ms; }
.is-playing .leakgrid i:nth-child(8)::before  { animation-delay: 1400ms; }
.is-playing .leakgrid i:nth-child(9)::before  { animation-delay: 1600ms; }
.is-playing .leakgrid i:nth-child(10)::before { animation-delay: 1800ms; }
.is-playing .leakgrid i:nth-child(11)::before { animation-delay: 2000ms; }
.is-playing .leakgrid i:nth-child(12)::before { animation-delay: 2200ms; }
.is-playing .leakgrid i:nth-child(13)::before { animation-delay: 2400ms; }
.is-playing .leakgrid i:nth-child(14)::before { animation-delay: 2600ms; }
.is-playing .leakgrid i:nth-child(15)::before { animation-delay: 2800ms; }
.is-playing .leakgrid i:nth-child(16)::before { animation-delay: 3000ms; }
@keyframes cell-in {
  0%, 3%    { opacity: 0; }
  8%, 84%   { opacity: 0.8; }
  92%, 100% { opacity: 0; }
}

.is-playing .crash .box--err { animation: seg-hit 10s ease-in-out infinite; }
@keyframes seg-hit {
  0%, 44%   { border-color: var(--err); box-shadow: none; }
  50%       { border-color: var(--err); box-shadow: 0 0 0 3px var(--err-wash); }
  62%, 100% { border-color: var(--err); box-shadow: none; }
}
