/* ==========================================================================
   BuK — Berechenbarkeit und Komplexität
   Digitales Lehrbuch · Designsystem
   ========================================================================== */

/* --- 1. Design Tokens --------------------------------------------------- */

:root {
  /* Farben — Light Mode (warmes Papier) */
  --bg:            #faf8f4;
  --bg-elevated:   #ffffff;
  --bg-sunken:     #f2eee7;
  --bg-code:       #f5f1ea;

  --text:          #23262b;
  --text-muted:    #5c6470;
  --text-faint:    #8b939f;

  --border:        #e2dcd1;
  --border-strong: #cec6b8;

  --accent:        #2f5d8a;   /* Schieferblau */
  --accent-soft:   #e8f0f7;
  --accent-hover:  #24486b;

  --def:           #2f5d8a;   /* Definition */
  --def-bg:        #eef4f9;
  --satz:          #7a4a9c;   /* Satz / Lemma / Korollar */
  --satz-bg:       #f4eefa;
  --bsp:           #2c7a5a;   /* Beispiel */
  --bsp-bg:        #e9f5ef;
  --warn:          #a8571c;   /* Klausurfehler */
  --warn-bg:       #fbf0e4;
  --merke:         #b0872a;   /* Merke */
  --merke-bg:      #fcf6e6;
  --intu:          #1f7a8c;   /* Intuition */
  --intu-bg:       #e6f4f6;
  --tipp:          #a03b5c;   /* Prüfungstipp */
  --tipp-bg':      #fbecf1;
  --tipp-bg:       #fbecf1;
  --gegen:         #a33a3a;   /* Gegenbeispiel */
  --gegen-bg:      #fbebeb;

  /* Typografie */
  --font-ui:    "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  --font-body:  "Lora", "Iowan Old Style", "Palatino Linotype", Georgia, serif;
  --font-mono:  "JetBrains Mono", "SF Mono", "Cascadia Mono", Consolas, monospace;

  --fs-base: 17px;
  --lh-body: 1.72;

  /* Maße */
  --sidebar-w: 310px;
  --content-max: 780px;
  --radius: 10px;
  --radius-sm: 6px;

  --shadow-sm: 0 1px 2px rgba(30,25,15,.06), 0 1px 3px rgba(30,25,15,.05);
  --shadow-md: 0 4px 12px rgba(30,25,15,.09), 0 1px 3px rgba(30,25,15,.06);
  --shadow-lg: 0 12px 32px rgba(30,25,15,.14);

  --transition: 160ms cubic-bezier(.4,0,.2,1);
}

[data-theme="dark"] {
  --bg:            #171a1f;
  --bg-elevated:   #1e2229;
  --bg-sunken:     #13161a;
  --bg-code:       #22262e;

  --text:          #dfe3e8;
  --text-muted:    #9aa3b0;
  --text-faint:    #6d7684;

  --border:        #2c323b;
  --border-strong: #3d454f;

  --accent:        #7ab3e0;
  --accent-soft:   #1c2b3a;
  --accent-hover:  #9cc8ee;

  --def:           #7ab3e0;  --def-bg:   #182533;
  --satz:          #b48ad6;  --satz-bg:  #251d33;
  --bsp:           #6cc79b;  --bsp-bg:   #15291f;
  --warn:          #e0a06a;  --warn-bg:  #2e2116;
  --merke:         #dcc06a;  --merke-bg: #2c2716;
  --intu:          #6dc3d4;  --intu-bg:  #14282c;
  --tipp:          #e08aa6;  --tipp-bg:  #2e1a22;
  --gegen:         #e08585;  --gegen-bg: #2e1a1a;

  --shadow-sm: 0 1px 2px rgba(0,0,0,.4);
  --shadow-md: 0 4px 12px rgba(0,0,0,.45);
  --shadow-lg: 0 12px 32px rgba(0,0,0,.55);
}

/* --- 2. Reset & Basis --------------------------------------------------- */

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

html {
  font-size: var(--fs-base);
  scroll-behavior: smooth;
  scroll-padding-top: 84px;
  -webkit-text-size-adjust: 100%;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-body);
  line-height: var(--lh-body);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
  transition: background var(--transition), color var(--transition);
}

img, svg { max-width: 100%; height: auto; }

a {
  color: var(--accent);
  text-decoration-color: color-mix(in srgb, var(--accent) 35%, transparent);
  text-underline-offset: 3px;
  transition: color var(--transition);
}
a:hover { color: var(--accent-hover); text-decoration-color: currentColor; }

::selection { background: color-mix(in srgb, var(--accent) 25%, transparent); }

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

/* --- 3. Fortschrittsbalken ---------------------------------------------- */

#progress-bar {
  position: fixed;
  top: 0; left: 0;
  height: 3px;
  width: 0%;
  background: linear-gradient(90deg, var(--accent), color-mix(in srgb, var(--satz) 70%, var(--accent)));
  z-index: 200;
  transition: width 80ms linear;
}

/* --- 4. Topbar ---------------------------------------------------------- */

.topbar {
  position: sticky;
  top: 0;
  z-index: 150;
  height: 60px;
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 0 20px;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: saturate(160%) blur(12px);
  -webkit-backdrop-filter: saturate(160%) blur(12px);
  border-bottom: 1px solid var(--border);
}

.topbar__brand {
  font-family: var(--font-ui);
  font-weight: 700;
  font-size: .95rem;
  letter-spacing: -.01em;
  color: var(--text);
  text-decoration: none;
  white-space: nowrap;
  display: flex;
  align-items: center;
  gap: 9px;
}
.topbar__brand:hover { color: var(--accent); }
.topbar__logo {
  width: 27px; height: 27px;
  flex: 0 0 27px;
  border-radius: 7px;
  background: var(--accent);
  color: #fff;
  display: grid; place-items: center;
  font-size: .72rem; font-weight: 800; letter-spacing: -.03em;
}
[data-theme="dark"] .topbar__logo { color: #101317; }

.topbar__spacer { flex: 1 1 auto; }

.icon-btn {
  width: 38px; height: 38px;
  flex: 0 0 38px;
  display: grid; place-items: center;
  border: 1px solid var(--border);
  background: var(--bg-elevated);
  color: var(--text-muted);
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: all var(--transition);
  font-size: 1rem;
  line-height: 1;
  padding: 0;
}
.icon-btn:hover {
  color: var(--accent);
  border-color: var(--accent);
  background: var(--accent-soft);
}
.icon-btn svg { width: 18px; height: 18px; stroke: currentColor; fill: none; stroke-width: 1.9; stroke-linecap: round; stroke-linejoin: round; }

#menu-toggle { display: none; }

/* --- 5. Suche ----------------------------------------------------------- */

.search {
  position: relative;
  flex: 0 1 300px;
  font-family: var(--font-ui);
}
.search__input {
  width: 100%;
  height: 38px;
  padding: 0 12px 0 34px;
  font: inherit;
  font-size: .86rem;
  color: var(--text);
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  transition: all var(--transition);
}
.search__input::placeholder { color: var(--text-faint); }
.search__input:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 15%, transparent);
}
.search__icon {
  position: absolute;
  left: 11px; top: 50%;
  transform: translateY(-50%);
  width: 15px; height: 15px;
  stroke: var(--text-faint);
  fill: none; stroke-width: 2;
  pointer-events: none;
}
.search__results {
  position: absolute;
  top: calc(100% + 7px);
  left: 0; right: 0;
  max-height: 62vh;
  overflow-y: auto;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-lg);
  display: none;
  z-index: 160;
  padding: 5px;
}
.search__results.open { display: block; }
.search__hit {
  display: block;
  padding: 9px 11px;
  border-radius: var(--radius-sm);
  text-decoration: none;
  color: var(--text);
  transition: background var(--transition);
}
.search__hit:hover, .search__hit.active { background: var(--accent-soft); }
.search__hit-title { font-weight: 600; font-size: .87rem; display: block; }
.search__hit-ctx { font-size: .77rem; color: var(--text-muted); display: block; margin-top: 2px; }
.search__hit-ctx mark { background: color-mix(in srgb, var(--merke) 35%, transparent); color: inherit; padding: 0 1px; border-radius: 2px; }
.search__empty { padding: 14px; font-size: .84rem; color: var(--text-muted); text-align: center; }

/* --- 6. Layout ---------------------------------------------------------- */

.layout {
  display: flex;
  align-items: flex-start;
  max-width: 1500px;
  margin: 0 auto;
}

/* --- 7. Sidebar --------------------------------------------------------- */

.sidebar {
  position: sticky;
  top: 60px;
  flex: 0 0 var(--sidebar-w);
  width: var(--sidebar-w);
  height: calc(100vh - 60px);
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: 22px 12px 60px 20px;
  border-right: 1px solid var(--border);
  font-family: var(--font-ui);
  scrollbar-width: thin;
}
.sidebar::-webkit-scrollbar { width: 8px; }
.sidebar::-webkit-scrollbar-thumb { background: var(--border-strong); border-radius: 4px; }

.sidebar__part {
  font-size: .68rem;
  font-weight: 700;
  letter-spacing: .1em;
  text-transform: uppercase;
  color: var(--text-faint);
  margin: 22px 0 8px 10px;
}
.sidebar__part:first-child { margin-top: 0; }

.sidebar__link {
  display: flex;
  align-items: baseline;
  gap: 9px;
  padding: 7px 10px;
  border-radius: var(--radius-sm);
  font-size: .845rem;
  line-height: 1.42;
  color: var(--text-muted);
  text-decoration: none;
  transition: all var(--transition);
}
.sidebar__link:hover { background: var(--bg-sunken); color: var(--text); }
.sidebar__link.current {
  background: var(--accent-soft);
  color: var(--accent);
  font-weight: 600;
}
.sidebar__num {
  flex: 0 0 auto;
  font-family: var(--font-mono);
  font-size: .72rem;
  color: var(--text-faint);
  font-variant-numeric: tabular-nums;
}
.sidebar__link.current .sidebar__num { color: var(--accent); }
.sidebar__link.done .sidebar__num::after { content: " ✓"; color: var(--bsp); }

.sidebar__toc {
  margin: 2px 0 8px 26px;
  padding-left: 11px;
  border-left: 1px solid var(--border);
  display: none;
}
.sidebar__link.current + .sidebar__toc { display: block; }
.sidebar__toc a {
  display: block;
  padding: 4px 8px;
  font-size: .79rem;
  color: var(--text-muted);
  text-decoration: none;
  border-radius: 4px;
  line-height: 1.4;
}
.sidebar__toc a:hover { color: var(--accent); background: var(--bg-sunken); }
.sidebar__toc a.active { color: var(--accent); font-weight: 600; }

.sidebar__backdrop { display: none; }

/* --- 8. Hauptbereich ---------------------------------------------------- */

.main {
  flex: 1 1 auto;
  min-width: 0;
  padding: 40px 40px 100px;
  display: flex;
  justify-content: center;
}
.content { width: 100%; max-width: var(--content-max); }

/* --- 9. Typografie ------------------------------------------------------ */

.chapter-eyebrow {
  font-family: var(--font-ui);
  font-size: .72rem;
  font-weight: 700;
  letter-spacing: .13em;
  text-transform: uppercase;
  color: var(--accent);
  margin: 0 0 10px;
}

h1 {
  font-family: var(--font-ui);
  font-size: clamp(1.85rem, 1.3rem + 2vw, 2.6rem);
  font-weight: 800;
  line-height: 1.14;
  letter-spacing: -.025em;
  margin: 0 0 14px;
}

h2 {
  font-family: var(--font-ui);
  font-size: 1.52rem;
  font-weight: 750;
  line-height: 1.24;
  letter-spacing: -.017em;
  margin: 3.1em 0 .7em;
  padding-top: .35em;
  border-top: 1px solid var(--border);
  scroll-margin-top: 84px;
}
h2:first-of-type { margin-top: 2.2em; }

h3 {
  font-family: var(--font-ui);
  font-size: 1.16rem;
  font-weight: 700;
  line-height: 1.32;
  letter-spacing: -.011em;
  margin: 2.2em 0 .55em;
  scroll-margin-top: 84px;
}

h4 {
  font-family: var(--font-ui);
  font-size: .97rem;
  font-weight: 700;
  margin: 1.7em 0 .4em;
  color: var(--text);
  scroll-margin-top: 84px;
}

p { margin: 0 0 1.15em; }

.lead {
  font-size: 1.13rem;
  line-height: 1.62;
  color: var(--text-muted);
  margin-bottom: 1.7em;
}

strong, b { font-weight: 650; color: var(--text); }
em { font-style: italic; }

ul, ol { margin: 0 0 1.2em; padding-left: 1.45em; }
li { margin-bottom: .48em; }
li > ul, li > ol { margin-top: .48em; margin-bottom: .2em; }

ul.tight li, ol.tight li { margin-bottom: .2em; }

hr { border: 0; border-top: 1px solid var(--border); margin: 2.6em 0; }

code {
  font-family: var(--font-mono);
  font-size: .86em;
  background: var(--bg-code);
  padding: .15em .38em;
  border-radius: 4px;
  border: 1px solid var(--border);
}
pre {
  font-family: var(--font-mono);
  font-size: .82rem;
  line-height: 1.65;
  background: var(--bg-code);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 15px 18px;
  overflow-x: auto;
  margin: 0 0 1.4em;
}
pre code { background: none; border: 0; padding: 0; font-size: inherit; }

blockquote {
  margin: 1.4em 0;
  padding: .2em 0 .2em 1.15em;
  border-left: 3px solid var(--border-strong);
  color: var(--text-muted);
  font-style: italic;
}

/* --- 10. Tabellen ------------------------------------------------------- */

.table-wrap { overflow-x: auto; margin: 0 0 1.6em; -webkit-overflow-scrolling: touch; }

table {
  width: 100%;
  border-collapse: collapse;
  font-family: var(--font-ui);
  font-size: .855rem;
  line-height: 1.5;
}
th, td {
  padding: 8px 12px;
  text-align: left;
  border-bottom: 1px solid var(--border);
  vertical-align: top;
}
thead th {
  font-weight: 700;
  font-size: .77rem;
  letter-spacing: .03em;
  text-transform: uppercase;
  color: var(--text-muted);
  background: var(--bg-sunken);
  border-bottom: 2px solid var(--border-strong);
  white-space: nowrap;
}
tbody tr:last-child td { border-bottom: 0; }
tbody tr:hover { background: var(--bg-sunken); }
table.mono td:first-child, table.mono th:first-child { font-family: var(--font-mono); font-size: .82em; }
td.c, th.c { text-align: center; }
td.num { font-variant-numeric: tabular-nums; text-align: right; }

/* Übergangstabelle einer TM */
table.delta {
  font-family: var(--font-mono);
  font-size: .84rem;
  width: auto;
  min-width: 100%;
}
table.delta th, table.delta td { text-align: center; padding: 6px 11px; border: 1px solid var(--border); }
table.delta thead th { background: var(--bg-sunken); }
table.delta tbody th { background: var(--bg-sunken); font-family: var(--font-mono); text-transform: none; font-size: .8rem; }

/* Konfigurationsfolge */
table.konfig { font-family: var(--font-mono); font-size: .84rem; }

/* Tiefgestellte Indizes in den Maschinentabellen. Als Unicode-Glyphen (q₀)
   waren ₀, ₂ und ₃ in Monospace bei dieser Größe nicht auseinanderzuhalten;
   <sub> rendert eine normale Ziffer und ist deutlich klarer. */
table.delta sub, table.konfig sub {
  font-size: .8em;
  line-height: 0;
  vertical-align: -.28em;
  padding-left: .04em;
}
table.konfig td:first-child { color: var(--text-faint); width: 3.2em; text-align: right; }

/* --- 11. Boxen (Definition, Satz, ...) ---------------------------------- */

.box {
  position: relative;
  margin: 1.7em 0;
  padding: 15px 19px 15px 19px;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  border-left: 3px solid var(--text-faint);
  background: var(--bg-elevated);
  font-size: .965rem;
}
.box > :last-child { margin-bottom: 0; }
.box__label {
  font-family: var(--font-ui);
  font-size: .71rem;
  font-weight: 800;
  letter-spacing: .1em;
  text-transform: uppercase;
  display: flex;
  align-items: center;
  gap: 7px;
  margin-bottom: 8px;
}
.box__label .num { font-weight: 700; opacity: .72; letter-spacing: .04em; }
.box__title {
  font-family: var(--font-ui);
  font-weight: 700;
  font-size: .96rem;
  margin: -4px 0 8px;
  letter-spacing: -.01em;
}

.box--def   { border-left-color: var(--def);   background: var(--def-bg);   }
.box--def   .box__label { color: var(--def);   }
.box--satz  { border-left-color: var(--satz);  background: var(--satz-bg);  }
.box--satz  .box__label { color: var(--satz);  }
.box--bsp   { border-left-color: var(--bsp);   background: var(--bsp-bg);   }
.box--bsp   .box__label { color: var(--bsp);   }
.box--gegen { border-left-color: var(--gegen); background: var(--gegen-bg); }
.box--gegen .box__label { color: var(--gegen); }
.box--merke { border-left-color: var(--merke); background: var(--merke-bg); }
.box--merke .box__label { color: var(--merke); }
.box--warn  { border-left-color: var(--warn);  background: var(--warn-bg);  }
.box--warn  .box__label { color: var(--warn);  }
.box--intu  { border-left-color: var(--intu);  background: var(--intu-bg);  }
.box--intu  .box__label { color: var(--intu);  }
.box--tipp  { border-left-color: var(--tipp);  background: var(--tipp-bg);  }
.box--tipp  .box__label { color: var(--tipp);  }
.box--note  { border-left-color: var(--text-faint); background: var(--bg-sunken); }
.box--note  .box__label { color: var(--text-muted); }

/* Beweis-Ende */
.qed { display: inline-block; float: right; font-weight: 700; }
.qed::after { content: "□"; }

/* --- 12. Ausklappbare Beweise ------------------------------------------- */

details.proof {
  margin: 1.5em 0;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg-elevated);
  overflow: hidden;
  transition: border-color var(--transition);
}
details.proof[open] { border-color: var(--border-strong); box-shadow: var(--shadow-sm); }
details.proof > summary {
  cursor: pointer;
  padding: 11px 17px;
  font-family: var(--font-ui);
  font-size: .8rem;
  font-weight: 650;
  color: var(--text-muted);
  list-style: none;
  display: flex;
  align-items: center;
  gap: 9px;
  user-select: none;
  transition: all var(--transition);
}
details.proof > summary::-webkit-details-marker { display: none; }
details.proof > summary::before {
  content: "";
  width: 0; height: 0;
  border-left: 5px solid currentColor;
  border-top: 4px solid transparent;
  border-bottom: 4px solid transparent;
  transition: transform var(--transition);
  flex: 0 0 auto;
}
details.proof[open] > summary::before { transform: rotate(90deg); }
details.proof > summary:hover { color: var(--accent); background: var(--bg-sunken); }
details.proof[open] > summary {
  color: var(--text);
  border-bottom: 1px solid var(--border);
  background: var(--bg-sunken);
}
.proof__body { padding: 16px 19px 4px; font-size: .955rem; }
.proof__body > :last-child { margin-bottom: 1em; }

details.proof.hint > summary { font-style: italic; }

/* --- 13. Merkkarten (Flip) ---------------------------------------------- */

.cards {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(215px, 1fr));
  gap: 13px;
  margin: 1.7em 0;
}
.card {
  perspective: 1100px;
  cursor: pointer;
  font-family: var(--font-ui);
}
/* Beide Seiten liegen in derselben Rasterzelle übereinander. Dadurch wächst
   die Karte auf die Höhe der längeren Seite — eine feste Höhe würde lange
   Rückseiten abschneiden. */
.card__inner {
  display: grid;
  min-height: 165px;
  transition: transform 520ms cubic-bezier(.4,.05,.2,1);
  transform-style: preserve-3d;
}
.card.flipped .card__inner { transform: rotateY(180deg); }
.card__face {
  grid-area: 1 / 1;
  position: relative;
  backface-visibility: hidden;
  -webkit-backface-visibility: hidden;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  padding: 15px 15px 26px;
  /* Bewusst kein Flex-Container: dort würde jedes Element-Kind — auch jede
     von MathJax erzeugte <mjx-container> — zu einem eigenen Flex-Item und
     damit auf eine eigene Zeile rutschen. Zentriert wird über das Raster,
     der Inhalt steckt gesammelt in .card__body. */
  display: grid;
  align-content: center;
  font-size: .85rem;
  line-height: 1.48;
  box-shadow: var(--shadow-sm);
}
.card__body { min-width: 0; }
.card__body :is(p, ul, ol):last-child { margin-bottom: 0; }
.card__face--front {
  background: var(--bg-elevated);
  font-weight: 650;
  text-align: center;
}
.card__face--back {
  background: var(--accent-soft);
  border-color: color-mix(in srgb, var(--accent) 32%, transparent);
  transform: rotateY(180deg);
  font-size: .8rem;
}
.card__hint {
  position: absolute;
  bottom: 7px; right: 11px;
  font-size: .63rem;
  color: var(--text-faint);
  letter-spacing: .05em;
  text-transform: uppercase;
}

/* --- 14. Hover-Erklärungen ---------------------------------------------- */

.term {
  border-bottom: 1px dashed var(--accent);
  cursor: help;
  color: inherit;
}
.term:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 2px; }

/* Der Kasten hängt am <body> und ist fixed positioniert, nicht am Begriff.
   Als absolut positioniertes ::after wurde er von jedem Vorfahren mit
   overflow (z. B. .table-wrap) abgeschnitten und lief am Fensterrand hinaus.
   Positioniert wird in js/navigation.js, dort auch die Randkorrektur. */
.buk-tip {
  position: fixed;
  top: 0; left: 0;
  max-width: min(300px, calc(100vw - 24px));
  background: var(--text);
  color: var(--bg);
  font-family: var(--font-ui);
  font-size: .77rem;
  font-style: normal;
  font-weight: 400;
  line-height: 1.45;
  padding: 8px 11px;
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow-md);
  opacity: 0;
  pointer-events: none;
  transition: opacity var(--transition);
  z-index: 400;
  white-space: normal;
  text-align: left;
}
.buk-tip.open { opacity: 1; }

/* --- 15. Figuren / SVG -------------------------------------------------- */

figure {
  margin: 1.9em 0;
  padding: 0;
}
figure svg {
  display: block;
  margin: 0 auto;
  max-width: 100%;
  height: auto;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 10px;
}
figcaption {
  font-family: var(--font-ui);
  font-size: .79rem;
  line-height: 1.5;
  color: var(--text-muted);
  text-align: center;
  margin-top: 10px;
  padding: 0 8px;
}
figcaption b { color: var(--text); font-weight: 700; }

/* SVG-Farbklassen — folgen dem Theme */
svg .s-bg     { fill: var(--bg-elevated); }
svg .s-node   { fill: var(--bg-elevated); stroke: var(--text); stroke-width: 1.6; }
svg .s-node-a { fill: var(--bsp-bg); stroke: var(--bsp); stroke-width: 1.8; }
svg .s-node-r { fill: var(--gegen-bg); stroke: var(--gegen); stroke-width: 1.8; }
svg .s-node-s { fill: var(--accent-soft); stroke: var(--accent); stroke-width: 1.8; }
svg .s-edge   { stroke: var(--text-muted); stroke-width: 1.5; fill: none; }
svg .s-edge-hi{ stroke: var(--accent); stroke-width: 2.2; fill: none; }
svg .s-edge-d { stroke: var(--text-faint); stroke-width: 1.4; fill: none; stroke-dasharray: 5 4; }
svg .s-txt    { fill: var(--text); font-family: var(--font-ui); font-size: 13px; }
svg .s-txt-s  { fill: var(--text-muted); font-family: var(--font-ui); font-size: 11px; }
svg .s-txt-m  { fill: var(--text); font-family: var(--font-mono); font-size: 12px; }
svg .s-fill-a { fill: var(--accent); }
svg .s-fill-m { fill: var(--text-muted); }
svg .s-cell   { fill: var(--bg-elevated); stroke: var(--border-strong); stroke-width: 1.2; }
svg .s-cell-hi{ fill: var(--accent-soft); stroke: var(--accent); stroke-width: 1.6; }
svg .s-band   { fill: var(--bg-sunken); }
svg .s-head   { fill: var(--accent); }

/* --- 16. Quiz ----------------------------------------------------------- */

.quiz {
  margin: 2em 0;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg-elevated);
  overflow: hidden;
  font-family: var(--font-ui);
  box-shadow: var(--shadow-sm);
}
.quiz__head {
  padding: 15px 19px;
  border-bottom: 1px solid var(--border);
  background: var(--bg-sunken);
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
}
.quiz__title { font-weight: 750; font-size: 1rem; margin: 0; letter-spacing: -.01em; }
.quiz__meta { font-size: .78rem; color: var(--text-muted); margin-left: auto; font-variant-numeric: tabular-nums; }

.q {
  padding: 17px 19px;
  border-bottom: 1px solid var(--border);
}
.q:last-of-type { border-bottom: 0; }
.q__num {
  font-size: .68rem;
  font-weight: 800;
  letter-spacing: .09em;
  text-transform: uppercase;
  color: var(--text-faint);
  margin-bottom: 5px;
}
.q__text { font-size: .93rem; line-height: 1.55; margin: 0 0 12px; font-weight: 550; }
.q__text code { font-size: .84em; }

.opts { display: flex; flex-direction: column; gap: 6px; }
.opt {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  padding: 9px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--bg);
  cursor: pointer;
  font-size: .875rem;
  line-height: 1.5;
  transition: all var(--transition);
  text-align: left;
}
.opt:hover:not(.locked) { border-color: var(--accent); background: var(--accent-soft); }
.opt input { margin: .32em 0 0; accent-color: var(--accent); flex: 0 0 auto; cursor: pointer; }
.opt.locked { cursor: default; }
.opt.correct {
  border-color: var(--bsp);
  background: var(--bsp-bg);
}
.opt.wrong {
  border-color: var(--gegen);
  background: var(--gegen-bg);
}
.opt.missed {
  border-color: var(--bsp);
  border-style: dashed;
}
.opt__mark { margin-left: auto; font-weight: 800; flex: 0 0 auto; }
.opt.correct .opt__mark { color: var(--bsp); }
.opt.wrong .opt__mark { color: var(--gegen); }

/* Lückentext */
.q input.gap {
  font-family: var(--font-mono);
  font-size: .85rem;
  padding: 5px 9px;
  border: 1px solid var(--border-strong);
  border-radius: 5px;
  background: var(--bg);
  color: var(--text);
  min-width: 130px;
  transition: all var(--transition);
}
.q input.gap:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 14%, transparent); }
.q input.gap.correct { border-color: var(--bsp); background: var(--bsp-bg); }
.q input.gap.wrong   { border-color: var(--gegen); background: var(--gegen-bg); }

/* Zuordnung */
.match { display: grid; gap: 8px; }
.match__row {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 11px;
  align-items: center;
  padding: 8px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--bg);
  font-size: .875rem;
}
.match__row select {
  font-family: var(--font-ui);
  font-size: .8rem;
  padding: 5px 9px;
  border: 1px solid var(--border-strong);
  border-radius: 5px;
  background: var(--bg-elevated);
  color: var(--text);
  cursor: pointer;
  max-width: 260px;
}
.match__row.correct { border-color: var(--bsp); background: var(--bsp-bg); }
.match__row.wrong   { border-color: var(--gegen); background: var(--gegen-bg); }

.q__fb {
  margin-top: 11px;
  padding: 10px 13px;
  border-radius: var(--radius-sm);
  font-size: .8rem;
  line-height: 1.56;
  display: none;
  border-left: 3px solid var(--text-faint);
  background: var(--bg-sunken);
}
.q__fb.show { display: block; }
.q__fb.ok   { border-left-color: var(--bsp);   background: var(--bsp-bg);   }
.q__fb.no   { border-left-color: var(--gegen); background: var(--gegen-bg); }
.q__fb b { display: block; margin-bottom: 3px; }

.quiz__foot {
  padding: 15px 19px;
  border-top: 1px solid var(--border);
  background: var(--bg-sunken);
  display: flex;
  align-items: center;
  gap: 11px;
  flex-wrap: wrap;
}
.quiz__score {
  margin-left: auto;
  font-weight: 750;
  font-size: .92rem;
  font-variant-numeric: tabular-nums;
}
.quiz__score.good { color: var(--bsp); }
.quiz__score.mid  { color: var(--merke); }
.quiz__score.bad  { color: var(--gegen); }

.btn {
  font-family: var(--font-ui);
  font-size: .8rem;
  font-weight: 650;
  padding: 9px 17px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--accent);
  background: var(--accent);
  color: #fff;
  cursor: pointer;
  transition: all var(--transition);
  line-height: 1.3;
}
[data-theme="dark"] .btn { color: #10141a; }
.btn:hover { background: var(--accent-hover); border-color: var(--accent-hover); transform: translateY(-1px); }
.btn:active { transform: none; }
.btn--ghost {
  background: transparent;
  color: var(--text-muted);
  border-color: var(--border-strong);
}
.btn--ghost:hover { background: var(--bg-elevated); color: var(--accent); border-color: var(--accent); transform: none; }

/* --- 17. Klausuraufgaben ------------------------------------------------ */

.exercise {
  margin: 1.9em 0;
  border: 1px solid var(--border);
  border-left: 3px solid var(--accent);
  border-radius: var(--radius);
  background: var(--bg-elevated);
  overflow: hidden;
}
.exercise__head {
  padding: 13px 18px;
  background: var(--bg-sunken);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: baseline;
  gap: 11px;
  flex-wrap: wrap;
  font-family: var(--font-ui);
}
.exercise__title { font-weight: 750; font-size: .97rem; margin: 0; letter-spacing: -.01em; }
.exercise__stars {
  font-size: .8rem;
  letter-spacing: .11em;
  color: var(--merke);
}
.exercise__pts {
  margin-left: auto;
  font-size: .77rem;
  font-weight: 700;
  color: var(--text-muted);
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: 2px 11px;
  white-space: nowrap;
}
.exercise__body { padding: 16px 18px 4px; font-size: .955rem; }
.exercise__body > :last-child { margin-bottom: 1em; }
.exercise details.proof { margin: 1.1em 0; }

.rubric {
  font-family: var(--font-ui);
  font-size: .8rem;
  margin: 1.2em 0 1em;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  overflow: hidden;
}
.rubric__head {
  padding: 7px 12px;
  background: var(--bg-sunken);
  font-weight: 700;
  font-size: .71rem;
  letter-spacing: .08em;
  text-transform: uppercase;
  color: var(--text-muted);
  border-bottom: 1px solid var(--border);
}
.rubric table { font-size: .8rem; }
.rubric td { padding: 6px 12px; }
.rubric td:last-child { text-align: right; font-weight: 700; white-space: nowrap; font-variant-numeric: tabular-nums; }

/* --- 18. Zusammenfassung ------------------------------------------------ */

.summary {
  margin: 2.2em 0;
  padding: 20px 24px;
  border-radius: var(--radius);
  background: var(--bg-sunken);
  border: 1px solid var(--border);
}
.summary h3 {
  margin-top: 0;
  font-size: 1.03rem;
  display: flex;
  align-items: center;
  gap: 9px;
}
.summary ol { counter-reset: sm; list-style: none; padding: 0; margin: 0; }
.summary ol li {
  counter-increment: sm;
  position: relative;
  padding-left: 36px;
  margin-bottom: 13px;
  font-size: .95rem;
  line-height: 1.6;
}
.summary ol li:last-child { margin-bottom: 0; }
.summary ol li::before {
  content: counter(sm);
  position: absolute;
  left: 0; top: .1em;
  width: 24px; height: 24px;
  border-radius: 50%;
  background: var(--accent);
  color: #fff;
  font-family: var(--font-ui);
  font-size: .74rem;
  font-weight: 800;
  display: grid;
  place-items: center;
}
[data-theme="dark"] .summary ol li::before { color: #10141a; }

/* --- 19. Kapitelnavigation ---------------------------------------------- */

.chapnav {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 13px;
  margin: 3.5em 0 0;
  padding-top: 2em;
  border-top: 1px solid var(--border);
  font-family: var(--font-ui);
}
.chapnav a {
  display: block;
  padding: 14px 17px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  text-decoration: none;
  color: var(--text);
  background: var(--bg-elevated);
  transition: all var(--transition);
}
.chapnav a:hover { border-color: var(--accent); box-shadow: var(--shadow-md); transform: translateY(-2px); }
.chapnav a.next { text-align: right; }
.chapnav__dir { font-size: .69rem; font-weight: 800; letter-spacing: .1em; text-transform: uppercase; color: var(--text-faint); display: block; margin-bottom: 4px; }
.chapnav__t { font-weight: 650; font-size: .91rem; line-height: 1.35; display: block; }
.chapnav a:hover .chapnav__t { color: var(--accent); }
.chapnav .empty { visibility: hidden; }

/* --- 20. "Nach oben" ---------------------------------------------------- */

#to-top {
  position: fixed;
  right: 24px; bottom: 24px;
  width: 44px; height: 44px;
  border-radius: 50%;
  border: 1px solid var(--border);
  background: var(--bg-elevated);
  color: var(--text-muted);
  cursor: pointer;
  display: grid;
  place-items: center;
  box-shadow: var(--shadow-md);
  opacity: 0;
  pointer-events: none;
  transform: translateY(10px);
  transition: all var(--transition);
  z-index: 120;
  padding: 0;
}
#to-top.show { opacity: 1; pointer-events: auto; transform: none; }
#to-top:hover { color: var(--accent); border-color: var(--accent); }
#to-top svg { width: 19px; height: 19px; stroke: currentColor; fill: none; stroke-width: 2.1; stroke-linecap: round; stroke-linejoin: round; }


/* --- 20b. Zwischenchecks ------------------------------------------------ */

/* Kompakte Variante des Quiz, mitten im Kapitel nach einem Theorieblock.
   Bewusst schmaler und ruhiger als das Kapitelquiz, damit der Lesefluss
   nicht zerrissen wird. */
.check {
  margin: 2.1em 0;
  border: 1px solid var(--border);
  border-left: 3px solid var(--intu);
  border-radius: var(--radius);
  background: color-mix(in srgb, var(--intu-bg) 55%, var(--bg-elevated));
  font-family: var(--font-ui);
  overflow: hidden;
}
.check__head {
  display: flex;
  align-items: baseline;
  flex-wrap: wrap;
  gap: 10px;
  padding: 13px 17px 0;
}
.check__badge {
  font-size: .64rem;
  font-weight: 700;
  letter-spacing: .09em;
  text-transform: uppercase;
  color: var(--intu);
  border: 1px solid color-mix(in srgb, var(--intu) 40%, transparent);
  border-radius: 999px;
  padding: 2px 9px;
  flex: 0 0 auto;
}
.check__title {
  margin: 0;
  font-size: .93rem;
  font-weight: 650;
  line-height: 1.4;
  color: var(--text);
}
.check__body { padding: 4px 17px 0; }
.check__body .q { border-bottom: none; padding: 13px 0 4px; }
.check__body .q:not(:last-child) { border-bottom: 1px dashed var(--border); padding-bottom: 13px; }
.check__foot {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 10px;
  padding: 13px 17px;
}

.check__task {
  border-top: 1px solid var(--border);
  background: color-mix(in srgb, var(--bg-elevated) 82%, transparent);
  padding: 15px 17px;
}
.check__task-label {
  font-size: .64rem;
  font-weight: 700;
  letter-spacing: .09em;
  text-transform: uppercase;
  color: var(--text-muted);
  margin-bottom: 7px;
}
.check__task-q { font-size: .9rem; line-height: 1.6; }
.check__task-q p:last-child { margin-bottom: 0; }
.check__hint {
  font-size: .8rem;
  color: var(--text-muted);
  margin: .7em 0 0;
}
.check__sol { margin: 1.1em 0 0; font-size: .88rem; }
.check__sol > summary { font-size: .84rem; }

@media (max-width: 620px) {
  .check__head, .check__body, .check__foot, .check__task { padding-left: 13px; padding-right: 13px; }
}

/* --- 21. Startseite ----------------------------------------------------- */

.hero {
  padding: 30px 0 12px;
  border-bottom: 1px solid var(--border);
  margin-bottom: 34px;
}
.hero h1 { margin-bottom: 12px; }
.hero__sub { font-size: 1.14rem; color: var(--text-muted); line-height: 1.6; max-width: 60ch; }
.hero__meta {
  display: flex;
  gap: 9px;
  flex-wrap: wrap;
  margin: 20px 0 26px;
  font-family: var(--font-ui);
}
.chip {
  font-size: .77rem;
  font-weight: 600;
  padding: 5px 12px;
  border-radius: 20px;
  background: var(--bg-sunken);
  border: 1px solid var(--border);
  color: var(--text-muted);
}
.chip--accent { background: var(--accent-soft); border-color: color-mix(in srgb, var(--accent) 30%, transparent); color: var(--accent); }

.stats {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: 13px;
  margin: 0 0 34px;
  font-family: var(--font-ui);
}
.stat {
  padding: 15px 17px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg-elevated);
}
.stat__v { font-size: 1.6rem; font-weight: 800; letter-spacing: -.03em; line-height: 1.1; color: var(--accent); font-variant-numeric: tabular-nums; }
.stat__l { font-size: .76rem; color: var(--text-muted); margin-top: 3px; line-height: 1.35; }

.parts { display: grid; gap: 26px; }
.part__head {
  font-family: var(--font-ui);
  display: flex;
  align-items: baseline;
  gap: 11px;
  margin-bottom: 12px;
}
.part__num {
  font-size: .68rem;
  font-weight: 800;
  letter-spacing: .12em;
  text-transform: uppercase;
  color: #fff;
  background: var(--accent);
  padding: 3px 9px;
  border-radius: 4px;
}
[data-theme="dark"] .part__num { color: #10141a; }
.part__t { font-size: 1.12rem; font-weight: 750; margin: 0; letter-spacing: -.015em; }
.part__d { font-size: .83rem; color: var(--text-muted); margin: 0; }

.chapgrid { display: grid; grid-template-columns: repeat(auto-fill, minmax(285px, 1fr)); gap: 12px; }
.chapcard {
  display: block;
  padding: 15px 17px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg-elevated);
  text-decoration: none;
  color: var(--text);
  transition: all var(--transition);
  font-family: var(--font-ui);
  position: relative;
}
.chapcard:hover { border-color: var(--accent); box-shadow: var(--shadow-md); transform: translateY(-2px); }
.chapcard__n {
  font-family: var(--font-mono);
  font-size: .72rem;
  color: var(--text-faint);
  font-weight: 600;
}
.chapcard__t { font-weight: 700; font-size: .96rem; margin: 3px 0 5px; line-height: 1.32; letter-spacing: -.012em; }
.chapcard:hover .chapcard__t { color: var(--accent); }
.chapcard__d { font-size: .81rem; color: var(--text-muted); line-height: 1.48; margin: 0; }
.chapcard__tags { margin-top: 9px; display: flex; gap: 5px; flex-wrap: wrap; }
.tag {
  font-size: .67rem;
  font-weight: 650;
  padding: 2px 7px;
  border-radius: 4px;
  background: var(--bg-sunken);
  color: var(--text-muted);
  border: 1px solid var(--border);
}
.tag--exam { background: var(--warn-bg); color: var(--warn); border-color: color-mix(in srgb, var(--warn) 28%, transparent); }
.chapcard.done::after {
  content: "✓";
  position: absolute;
  top: 13px; right: 15px;
  color: var(--bsp);
  font-weight: 800;
  font-size: .9rem;
}

/* --- 22. MathJax -------------------------------------------------------- */

mjx-container { max-width: 100%; }
/* Nur abgesetzte Formeln bekommen eine Scrollbox. Auf Inline-Mathe würde
   overflow-y: hidden hohe Konstruktionen (Brüche, \overline{}) oben oder
   unten abschneiden. */
mjx-container[display="true"] {
  margin: 1.15em 0 !important;
  padding: 2px 0;
  overflow-x: auto;
  overflow-y: hidden;
}
mjx-container:focus { outline: none; }

/* --- 23. Utilities ------------------------------------------------------ */

.muted { color: var(--text-muted); }
.small { font-size: .87rem; }
.center { text-align: center; }
.nowrap { white-space: nowrap; }
.mt0 { margin-top: 0; }
.mb0 { margin-bottom: 0; }

.kbd {
  font-family: var(--font-mono);
  font-size: .78em;
  padding: 1px 6px;
  border: 1px solid var(--border-strong);
  border-bottom-width: 2px;
  border-radius: 4px;
  background: var(--bg-sunken);
}

.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 15px; }
.grid-2 > .box { margin: 0; }

.callout-row { display: grid; grid-template-columns: repeat(auto-fit, minmax(230px, 1fr)); gap: 13px; margin: 1.7em 0; }
.callout-row > .box { margin: 0; }

.no-print { }

/* --- 24. Responsive ----------------------------------------------------- */

@media (max-width: 1080px) {
  :root { --sidebar-w: 268px; }
  .main { padding: 32px 28px 90px; }
}

@media (max-width: 900px) {
  #menu-toggle { display: grid; }
  .sidebar {
    position: fixed;
    top: 60px; left: 0;
    z-index: 140;
    width: 300px;
    background: var(--bg-elevated);
    box-shadow: var(--shadow-lg);
    transform: translateX(-104%);
    transition: transform 240ms cubic-bezier(.4,0,.2,1);
  }
  .sidebar.open { transform: none; }
  .sidebar__backdrop {
    display: block;
    position: fixed;
    inset: 60px 0 0 0;
    background: rgba(0,0,0,.42);
    z-index: 139;
    opacity: 0;
    pointer-events: none;
    transition: opacity var(--transition);
  }
  .sidebar__backdrop.open { opacity: 1; pointer-events: auto; }
  .main { padding: 26px 20px 80px; }
  .search { flex: 1 1 auto; max-width: none; }
  .topbar__brand span.long { display: none; }
}

@media (max-width: 620px) {
  :root { --fs-base: 16px; }
  .main { padding: 20px 15px 70px; }
  .chapnav { grid-template-columns: 1fr; }
  .chapnav a.next { text-align: left; }
  .grid-2 { grid-template-columns: 1fr; }
  .box { padding: 13px 15px; }
  .cards { grid-template-columns: 1fr 1fr; }
  .card__inner { min-height: 155px; }
  #to-top { right: 14px; bottom: 14px; }
  .exercise__pts { margin-left: 0; }
  h2 { font-size: 1.34rem; }
  h3 { font-size: 1.07rem; }
}

@media (max-width: 400px) {
  .cards { grid-template-columns: 1fr; }
}


/* --- 26. Sidebar einklappen, Kennungen, Mobil ---------------------------- */

/* Auf großen Schirmen lässt sich die Sidebar wegklappen — auf schmalen und
   hochkant gehaltenen Geräten gewinnt der Text dadurch spürbar Breite.
   Der Zustand steht schon vor dem ersten Zeichnen an <html>, damit nichts
   springt. */
html.sb-collapsed .sidebar { display: none; }
html.sb-collapsed .content { max-width: min(var(--content-max), 100%); }
#sidebar-toggle { display: grid; }
html.sb-collapsed #sidebar-toggle { color: var(--accent); border-color: var(--accent); background: var(--accent-soft); }

/* Zitierbare Kennung. Sichtbar am Rand, ein Klick kopiert einen Verweis
   wie „03.4“ — damit lässt sich im Gespräch eindeutig auf eine Stelle zeigen. */
.sid {
  font-family: var(--font-mono);
  font-size: .66rem;
  font-weight: 500;
  color: var(--text-faint);
  background: none;
  border: 1px solid transparent;
  border-radius: 4px;
  padding: 1px 5px;
  margin-left: .5em;
  cursor: pointer;
  vertical-align: middle;
  opacity: 0;
  transition: opacity var(--transition), color var(--transition), border-color var(--transition);
  white-space: nowrap;
}
h2:hover .sid, h3:hover .sid, .box:hover > .sid, .check:hover > .sid,
.sid:focus-visible { opacity: 1; }
.sid:hover { color: var(--accent); border-color: var(--border-strong); }
.sid.copied { color: var(--bsp); border-color: var(--bsp); opacity: 1; }
.box > .sid, .check > .sid { position: absolute; top: 6px; right: 8px; margin: 0; }
.box, .check { position: relative; }
/* Auf Touchgeräten gibt es kein Hover — dort immer zeigen, dafür dezenter. */
@media (hover: none) {
  .sid { opacity: .45; }
}

/* Kurzmeldungen (Kopiert, Gespeichert, Fehler) */
.toast {
  position: fixed;
  left: 50%;
  bottom: calc(18px + env(safe-area-inset-bottom, 0px));
  transform: translateX(-50%) translateY(12px);
  background: var(--text);
  color: var(--bg);
  font-family: var(--font-ui);
  font-size: .82rem;
  line-height: 1.45;
  padding: 10px 16px;
  border-radius: 999px;
  box-shadow: var(--shadow-lg);
  z-index: 500;
  opacity: 0;
  pointer-events: none;
  transition: opacity var(--transition), transform var(--transition);
  max-width: min(90vw, 460px);
  text-align: center;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
.toast.warn { background: var(--warn); color: #fff; border-radius: var(--radius); }

/* --- Mobil: Tippziele, Ränder, Hochkant --------------------------------- */

@media (max-width: 900px) {
  /* Sidebar ist hier bereits ausgeklappt-per-Overlay; der Klappknopf wäre
     doppelt gemoppelt und verschwindet. */
  #sidebar-toggle { display: none; }
  html.sb-collapsed .sidebar { display: block; }
}

@media (max-width: 620px) {
  /* Tippziele auf mindestens ~44 px bringen. */
  .opt { padding: 11px 13px; align-items: flex-start; }
  .opt input { margin-top: .18em; transform: scale(1.15); }
  .match__row { grid-template-columns: 1fr; gap: 6px; align-items: stretch; }
  .match__row select { width: 100%; min-height: 42px; font-size: .9rem; }
  input.gap { min-height: 38px; font-size: .95rem; }
  .btn { min-height: 42px; padding: 0 16px; }
  details.proof > summary { padding: 13px 14px; }
  .card__inner { min-height: 0; }
  .card__face { padding: 14px 14px 24px; }

  /* Formeln laufen auf schmalen Schirmen sonst rechts hinaus. */
  mjx-container[display="true"] { font-size: .95em; }

  /* Kopfzeile schlanker, damit über der Falz mehr Text steht. */
  .topbar { height: 54px; padding: 0 12px; gap: 8px; }
  .layout, .sidebar { top: 54px; }
  .sidebar { height: calc(100vh - 54px); inset-block-start: 54px; }
  .sidebar__backdrop { inset: 54px 0 0 0; }
  html { scroll-padding-top: 66px; }

  /* Randabstand bei Geräten mit runden Ecken / Notch */
  .main { padding-left: max(15px, env(safe-area-inset-left));
          padding-right: max(15px, env(safe-area-inset-right)); }

  .exercise__head { flex-wrap: wrap; gap: 6px 10px; }
  .quiz__foot, .check__foot { gap: 8px; }
  .quiz__score { flex-basis: 100%; }
}

/* Hochkant auf dem Tablet: Text darf breiter werden, weil die Sidebar
   dort ohnehin als Overlay läuft. */
@media (max-width: 900px) and (orientation: portrait) {
  .content { max-width: none; }
}

/* Sehr schmal: Tabellen bekommen einen sichtbaren Hinweis aufs Wischen. */
@media (max-width: 520px) {
  .table-wrap { position: relative; }
  .table-wrap::after {
    content: "→ wischen";
    position: sticky;
    left: 100%;
    bottom: 0;
    display: block;
    width: max-content;
    font-family: var(--font-ui);
    font-size: .62rem;
    color: var(--text-faint);
    padding: 1px 0 3px;
  }
  table { font-size: .88rem; }
}


/* Gelesene Abschnitte in der Sidebar */
.sidebar__toc a.read::before {
  content: "✓";
  color: var(--bsp);
  font-size: .72em;
  margin-right: .35em;
  opacity: .85;
}
.sidebar__toc a.read { color: var(--text-muted); }

/* Fortschrittszeile am Kapitelanfang */
.chapter-meter {
  font-family: var(--font-ui);
  font-size: .78rem;
  color: var(--text-muted);
  margin: -.4em 0 1.8em;
}


/* --- 27. Schreibflächen für offene Aufgaben ----------------------------- */

.answer {
  margin: 1.3em 0 .3em;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg-elevated);
  overflow: hidden;
  font-family: var(--font-ui);
}
.answer__head {
  display: flex; align-items: center; gap: 10px;
  padding: 7px 9px;
  border-bottom: 1px solid var(--border);
  background: var(--bg-sunken);
}
.answer__tabs { display: flex; gap: 4px; }
.answer__tab {
  display: inline-flex; align-items: center; gap: 6px;
  border: 1px solid transparent;
  background: none;
  color: var(--text-muted);
  font: inherit; font-size: .78rem; font-weight: 500;
  padding: 6px 11px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  min-height: 36px;
  transition: all var(--transition);
}
.answer__tab svg { width: 15px; height: 15px; stroke: currentColor; fill: none; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.answer__tab:hover { color: var(--text); background: var(--bg-elevated); }
.answer__tab.on { background: var(--bg-elevated); color: var(--accent); border-color: var(--border); }
.answer__state { margin-left: auto; font-size: .72rem; color: var(--bsp); }

.answer__body { padding: 9px; }
.answer[data-mode="ink"] [data-view="txt"],
.answer[data-mode="txt"] [data-view="ink"] { display: none; }

.answer__text {
  width: 100%;
  min-height: 140px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-mono);
  font-size: .86rem;
  line-height: 1.65;
  padding: 11px 13px;
  resize: vertical;
}
.answer__text:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 14%, transparent); }

/* --- Zeichenfläche ------------------------------------------------------ */

.pad__bar {
  display: flex; align-items: center; gap: 5px;
  flex-wrap: wrap;
  margin-bottom: 7px;
}
.pad__pen, .pad__btn {
  width: 34px; height: 34px;
  display: grid; place-items: center;
  border: 1px solid var(--border);
  background: var(--bg);
  border-radius: var(--radius-sm);
  cursor: pointer;
  color: var(--text-muted);
  padding: 0;
  transition: all var(--transition);
}
.pad__btn svg { width: 16px; height: 16px; stroke: currentColor; fill: none; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.pad__pen:hover, .pad__btn:hover { border-color: var(--accent); color: var(--accent); }
.pad__pen.on, .pad__btn.on { border-color: var(--accent); box-shadow: 0 0 0 2px color-mix(in srgb, var(--accent) 22%, transparent); }
.pad__btn--danger:hover { border-color: var(--gegen); color: var(--gegen); }
.pad__swatch { width: 16px; height: 16px; border-radius: 50%; display: block; }
.pad__sep { width: 1px; height: 22px; background: var(--border); margin: 0 3px; }
.pad__spacer { flex: 1 1 auto; }
.pad__hint { font-size: .7rem; color: var(--text-faint); white-space: nowrap; }

.pad__canvas {
  display: block;
  width: 100%;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--bg);
  /* Entscheidend fürs Tablet: Der Browser darf auf dieser Fläche nicht
     selbst scrollen oder zoomen, sonst reißt jeder Strich ab. */
  touch-action: none;
  cursor: crosshair;
}

@media (max-width: 620px) {
  .answer__body { padding: 7px; }
  .answer__tab { padding: 6px 9px; font-size: .74rem; }
  .pad__hint { display: none; }
}

@media print {
  .answer__head, .pad__bar { display: none !important; }
  .answer[data-mode="txt"] [data-view="ink"] { display: none; }
}

/* --- 28. Lernstand sichern ---------------------------------------------- */

.datasheet {
  position: fixed;
  inset: 0;
  z-index: 480;
  display: none;
  place-items: center;
  background: rgba(0,0,0,.45);
  padding: 18px;
}
.datasheet.open { display: grid; }
.datasheet__box {
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-lg);
  width: min(520px, 100%);
  max-height: 86vh;
  overflow-y: auto;
  padding: 20px 22px 22px;
  font-family: var(--font-ui);
}
.datasheet h3 { margin: 0 0 4px; font-size: 1.05rem; }
.datasheet p { font-size: .84rem; color: var(--text-muted); line-height: 1.6; }
.datasheet__row { display: flex; gap: 8px; flex-wrap: wrap; margin: 14px 0 0; }
.datasheet__stat {
  font-family: var(--font-mono); font-size: .76rem;
  color: var(--text-muted); background: var(--bg-sunken);
  border-radius: var(--radius-sm); padding: 9px 12px; margin-top: 14px;
}
.datasheet__close { position: absolute; top: 0; right: 0; }


/* Abgleichanzeige in der Kopfzeile */
.sync {
  font-family: var(--font-ui);
  font-size: .7rem;
  color: var(--text-faint);
  white-space: nowrap;
  padding: 0 2px;
}
.sync--ok   { color: var(--bsp); }
.sync--busy { color: var(--text-muted); }
.sync--bad  { color: var(--warn); }
@media (max-width: 620px) { .sync { display: none; } }

/* --- 25. Druck ---------------------------------------------------------- */

@media print {
  .topbar, .sidebar, .sidebar__backdrop, #to-top, #progress-bar, .chapnav, .quiz__foot { display: none !important; }
  body { background: #fff; color: #000; font-size: 11pt; }
  .main { padding: 0; }
  .content { max-width: none; }
  details.proof, details { open: true; }
  details.proof > summary { display: none; }
  .proof__body { display: block !important; padding: 0; }
  .box, .exercise, .quiz { break-inside: avoid; page-break-inside: avoid; }
  h2, h3 { break-after: avoid; page-break-after: avoid; }
  a { color: #000; text-decoration: none; }
}

/* --- 26. Reduced motion ------------------------------------------------- */

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: .01ms !important;
    transition-duration: .01ms !important;
    scroll-behavior: auto !important;
  }
}
