/* ===== Mathe Basisfach — Schulheft & Neobrutalismus ===== */
:root {
  --ink: #111;
  --paper: #fbf6e9;
  --karo: rgba(41, 98, 164, .14);
  --blue: #4d9fff;
  --pink: #ff5ea8;
  --green: #8be78b;
  --yellow: #ffd93d;
  --red: #ff6b6b;
  --marker: #ffe86b;
  --shadow: 6px 6px 0 var(--ink);
  --shadow-sm: 3px 3px 0 var(--ink);
  --maxw: 720px;
}

* { margin: 0; padding: 0; box-sizing: border-box; }

/* Formeln nie von text-transform der Umgebung erfassen lassen: aus \(a\) würde
   sonst in einer Großbuchstaben-Beschriftung ein A — eine andere Größe. */
.katex { text-transform: none; font-size: 1.05em; }

/* Eine abgesetzte Formel, die auf dem Handy nicht in eine Zeile passt, darf nicht
   die ganze Seite querscrollen lassen. Sie scrollt in ihrer eigenen Zeile —
   dasselbe Prinzip wie .table-scroll bei breiten Tabellen. */
/* position: relative ist hier kein Schmuck, sondern nötig: KaTeX legt neben die
   sichtbare Formel eine zweite in MathML (.katex-mathml, position: absolute).
   Ohne einen positionierten Vorfahren ist deren Bezug das Fenster — dann greift
   das overflow des Scrollkastens nicht mehr, und die versteckte Kopie schiebt
   die ganze Seite breiter. Gilt genauso für .table-scroll. */
.katex-display { position: relative; overflow-x: auto; overflow-y: hidden; padding-bottom: 3px; }

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

body {
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  font-size: 17px;
  line-height: 1.6;
  color: var(--ink);
  background-color: var(--paper);
  background-image:
    linear-gradient(var(--karo) 1px, transparent 1px),
    linear-gradient(90deg, var(--karo) 1px, transparent 1px);
  background-size: 26px 26px;
  padding: 16px 14px 50px;
}

main { max-width: var(--maxw); margin: 0 auto; }

/* ===== Kopf: Wo bin ich? ===== */
.crumbs {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px;
  margin-bottom: 18px;
}
.crumbs a, .crumbs .here {
  display: inline-block;
  font-size: .72rem;
  font-weight: 900;
  text-transform: uppercase;
  letter-spacing: .02em;
  text-decoration: none;
  color: var(--ink);
  background: #fff;
  border: 3px solid var(--ink);
  box-shadow: 2px 2px 0 var(--ink);
  padding: 5px 10px;
}
.crumbs .here { background: var(--yellow); box-shadow: var(--shadow-sm); }
.crumbs a:active { transform: translate(2px, 2px); box-shadow: 0 0 0 var(--ink); }
.crumbs .sep { font-weight: 900; opacity: .45; }

h1 {
  display: inline-block;
  font-size: 1.7rem;
  line-height: 1.15;
  font-weight: 900;
  text-transform: uppercase;
  letter-spacing: -.6px;
  background: var(--yellow);
  border: 3px solid var(--ink);
  box-shadow: var(--shadow);
  padding: 10px 16px;
  margin: 6px 0 22px;
  transform: rotate(-1.5deg);
}

/* Schrittleiste: alle Stationen des Kapitels auf einen Blick */
.steps { display: flex; flex-wrap: wrap; gap: 6px; margin: 0 0 30px 2px; }
.step {
  display: block;
  width: 42px; height: 42px;
  line-height: 36px;
  text-align: center;
  font-size: .95rem;
  font-weight: 900;
  text-decoration: none;
  color: var(--ink);
  background: #fff;
  border: 3px solid var(--ink);
  box-shadow: 2px 2px 0 var(--ink);
}
.step:active { transform: translate(2px, 2px); box-shadow: 0 0 0 var(--ink); }
.step--rb { background: var(--green); }
.step.is-here {
  background: var(--pink);
  box-shadow: 4px 4px 0 var(--ink);
  transform: rotate(-4deg);
}

/* ===== Fließtext ===== */
p { margin: .7em 0; }
.intro em { font-style: normal; background: var(--marker); padding: 0 3px; font-weight: 700; }
.lead { font-weight: 500; }

ul.plain { list-style: none; margin: 14px 0; }
ul.plain li {
  background: #fff;
  border: 3px solid var(--ink);
  box-shadow: var(--shadow-sm);
  padding: 10px 14px;
  margin-bottom: 10px;
  font-size: .97em;
}
ul.plain li b { display: block; }

/* ===== Kästen ===== */
.chip {
  display: inline-block;
  font-size: .76rem;
  font-weight: 900;
  text-transform: uppercase;
  letter-spacing: .03em;
  background: #fff;
  border: 3px solid var(--ink);
  box-shadow: var(--shadow-sm);
  padding: 5px 12px;
  transform: rotate(-2deg);
}

.box {
  position: relative;
  background: #fff;
  border: 3px solid var(--ink);
  box-shadow: var(--shadow);
  padding: 30px 16px 16px;
  margin: 36px 0;
}
.box > .chip { position: absolute; top: -15px; left: 14px; }
.box--plain { padding-top: 16px; }

.box--merk { background: #f2f8ff; }
.box--merk > .chip { background: var(--blue); }
.box--bsp  > .chip { background: var(--yellow); }
.box--try  > .chip { background: var(--pink); }
.box--tipp { background: #fffbe9; }
.box--tipp > .chip { background: var(--marker); }
.box--warn { background: #fff2f2; }
.box--warn > .chip { background: var(--red); }

/* ===== Ausprobieren ===== */
.sub { font-size: .93em; margin: 0 0 12px; }

/* ">" bewusst: eine Formel mit \sqrt bringt ihr eigenes <svg> mit */
.plot-wrap > svg {
  display: block;
  width: 100%;
  height: auto;
  touch-action: none;
  background: #fff;
  border: 3px solid var(--ink);
  box-shadow: 4px 4px 0 var(--ink);
}
.plot-wrap + .plot-wrap { margin-top: 12px; }

.plot-wrap [data-layer="grid"] line { stroke: rgba(41, 98, 164, .17); }
.plot-wrap [data-layer="axes"] line { stroke: var(--ink); stroke-width: 2.2; }
.plot-wrap [data-layer="axes"] text { fill: #333; }
.plot-wrap [data-layer="marker"] circle { stroke: var(--ink); stroke-width: 3; }

/* ===== Schrägbild: drehen und zoomen =====
   Die Klasse setzt makeSpace selbst auf den Kasten. Sie tut nur zweierlei:
   sie gibt den Knöpfen im Bild einen Bezugsrahmen und lässt beim Ziehen
   keinen Text markieren — sonst fährt ein Zug über das Bild die blaue
   Auswahl über die halbe Seite. */
.space { position: relative; user-select: none; -webkit-user-select: none; }

.space-tools {
  position: absolute;
  top: 10px; right: 10px;
  display: flex;
  gap: 8px;
}
.space-btn {
  width: 40px; height: 40px;
  font-family: inherit;
  font-size: 1.15rem;
  font-weight: 900;
  line-height: 1;
  color: var(--ink);
  background: #fff;
  border: 3px solid var(--ink);
  box-shadow: var(--shadow-sm);
  cursor: pointer;
  touch-action: manipulation;
}
.space-btn:active { transform: translate(3px, 3px); box-shadow: 0 0 0 var(--ink); }
.space-btn:focus-visible { outline: 3px solid var(--pink); outline-offset: 2px; }

.space-hint {
  margin: 8px 0 0;
  font-size: .82em;
  font-weight: 700;
  color: #5b6b7a;
}

/* Auf dem iPad sind die Knöpfe Tippziele, keine Mausziele. */
@media (pointer: coarse) {
  .space-tools { top: 12px; right: 12px; gap: 10px; }
  .space-btn { width: 46px; height: 46px; font-size: 1.3rem; }
}

/* Auf dem Handy ist das Bild selbst nur noch rund 290px breit — drei Tippziele
   in seiner Ecke nähmen die halbe Bildbreite ein. Dort stehen sie deshalb
   unter dem Bild statt darin; das iPad behält sie im Bild. */
@media (max-width: 560px) {
  .space-tools { position: static; margin-top: 10px; }
  .space-hint { margin-top: 8px; }
}

.legend { margin-top: 12px; font-size: .88em; font-weight: 700; }
/* Nur die eigenen Zeilen ansprechen (">"): ohne das trifft die Regel auch
   die verschachtelten Spans, aus denen KaTeX seine Formeln aufbaut. */
.legend > span { display: block; margin-top: 5px; }
.legend .key {
  display: inline-block;
  width: 26px; height: 12px;
  border: 2.5px solid var(--ink);
  margin-right: 8px;
  vertical-align: -1px;
}

.controls { margin-top: 16px; }
.ctl { display: flex; align-items: center; gap: 12px; margin-bottom: 6px; }
.ctl .name {
  flex: 0 0 auto;
  font-weight: 900;
  font-size: .9em;
  text-transform: uppercase;
  min-width: 74px;
}
.ctl output {
  flex: 0 0 auto;
  min-width: 62px;
  text-align: center;
  font-weight: 800;
  background: var(--marker);
  border: 3px solid var(--ink);
  padding: 3px 6px;
}

input[type=range] {
  flex: 1 1 auto;
  min-width: 90px;
  -webkit-appearance: none;
  appearance: none;
  height: 44px;
  background: transparent;
}
input[type=range]::-webkit-slider-runnable-track {
  height: 14px; background: #fff; border: 3px solid var(--ink);
}
input[type=range]::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 30px; height: 30px; margin-top: -8px;
  background: var(--pink); border: 3px solid var(--ink);
  box-shadow: 2px 2px 0 var(--ink); cursor: pointer;
}
input[type=range]::-moz-range-track {
  height: 14px; background: #fff; border: 3px solid var(--ink);
}
input[type=range]::-moz-range-thumb {
  width: 26px; height: 26px; border-radius: 0;
  background: var(--pink); border: 3px solid var(--ink); cursor: pointer;
}

/* bewusst kein Flex: Knopftexte mischen Formeln und Wörter */
.btn {
  display: inline-block;
  white-space: nowrap;
  font-family: inherit;
  font-size: 1rem;
  font-weight: 900;
  line-height: 1.4;
  min-height: 46px;
  margin: 6px 8px 6px 0;
  padding: 10px 18px;
  border: 3px solid var(--ink);
  box-shadow: 5px 5px 0 var(--ink);
  background: #fff;
  color: var(--ink);
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}
.btn:active { transform: translate(4px, 4px); box-shadow: 1px 1px 0 var(--ink); }
.btn.primary { background: var(--blue); }
.btn.on { background: var(--pink); }
/* Ein Schritt, der gerade nicht an der Reihe ist: sichtbar, aber flach */
.btn:disabled { opacity: .4; box-shadow: 2px 2px 0 var(--ink); cursor: default; }
.btn:disabled:active { transform: none; box-shadow: 2px 2px 0 var(--ink); }
.btn--sm { font-size: .88rem; min-height: 40px; padding: 7px 14px; box-shadow: var(--shadow-sm); }
.btn--sm:active { transform: translate(3px, 3px); box-shadow: 0 0 0 var(--ink); }
/* Knopf mit ganzem Satz darauf - Blocklayout bleibt, nur der Umbruch wird erlaubt */
.btn--wrap { white-space: normal; text-align: left; max-width: 100%; }

/* ===== Gleichungssysteme ===== */
/* Ein LGS ist eine abgesetzte Formel, soll aber wie im Heft am linken Rand
   stehen - KaTeX zentriert abgesetzte Formeln von Haus aus. */
.lgs { margin: 4px 0; }
.lgs .katex-display { margin: .4em 0; text-align: left; }
.lgs .katex-display > .katex { text-align: left; }

/* Die Umformungen als eigene Zeilen unter dem System - als Spalte daneben
   passen sie auf dem Handy nicht mehr neben das LGS. */
.protokoll { margin: 2px 0 0; font-size: .9em; }
/* ">" bewusst: eine Formel bringt ihre eigenen Spans mit */
.protokoll > span { display: block; padding: 3px 0 3px 12px; border-left: 3px solid var(--ink); }

.readout {
  margin-top: 16px;
  background: var(--marker);
  border: 3px solid var(--ink);
  box-shadow: var(--shadow-sm);
  padding: 12px 14px;
  line-height: 2;
}
.readout .katex { font-size: 1.12em; }

/* ===== Tabellen ===== */
/* position: relative wie bei .katex-display — siehe den Kommentar dort. */
.table-scroll { position: relative; overflow-x: auto; }
.formel-tabelle {
  width: 100%;
  border-collapse: collapse;
  margin: 10px 0;
  font-size: .95em;
}
.formel-tabelle th, .formel-tabelle td {
  border: 2px solid var(--ink);
  padding: 8px 10px;
  text-align: left;
  vertical-align: top;
}
.formel-tabelle th {
  background: var(--marker);
  font-weight: 900;
  text-transform: uppercase;
  font-size: .78rem;
}

/* ===== Selbsttest ===== */
h2 {
  display: inline-block;
  font-size: 1.05rem;
  font-weight: 900;
  text-transform: uppercase;
  background: var(--green);
  border: 3px solid var(--ink);
  box-shadow: 4px 4px 0 var(--ink);
  padding: 6px 14px;
  margin: 44px 0 18px 4px;
  transform: rotate(-2deg);
}

details.quiz {
  background: #fff;
  border: 3px solid var(--ink);
  box-shadow: var(--shadow-sm);
  margin-bottom: 12px;
}
details.quiz summary {
  list-style: none;
  cursor: pointer;
  position: relative;
  padding: 14px 16px 14px 48px;
  font-weight: 700;
  -webkit-tap-highlight-color: transparent;
}
details.quiz summary::-webkit-details-marker { display: none; }
details.quiz summary::before {
  content: "?";
  position: absolute;
  left: 12px; top: 12px;
  width: 26px; height: 26px;
  background: var(--yellow);
  border: 3px solid var(--ink);
  font-weight: 900;
  text-align: center;
  line-height: 21px;
}
details.quiz[open] summary::before { content: "!"; background: var(--green); }
details.quiz .answer {
  border-top: 3px solid var(--ink);
  background: #f6fff6;
  padding: 12px 16px;
}

/* ===== Zuordnungsspiel ===== */
.match-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin-top: 12px;
}
.match-card {
  min-height: 64px;
  padding: 10px 12px;
  background: #fff;
  border: 3px solid var(--ink);
  box-shadow: var(--shadow-sm);
  font-size: .92em;
  line-height: 1.4;
  display: flex;
  align-items: center;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  transition: background .15s, opacity .3s;
}
.match-card.sel { background: var(--yellow); transform: translate(2px, 2px); box-shadow: 1px 1px 0 var(--ink); }
.match-card.ok  { background: var(--green); opacity: .55; pointer-events: none; }
.match-card.err { background: var(--red); }

/* ===== Übersichtslisten ===== */
.nav-list { list-style: none; margin: 18px 0; }
.nav-list li { margin-bottom: 12px; }
.nav-list a, .nav-list .soon {
  display: flex;
  align-items: center;
  gap: 14px;
  background: #fff;
  border: 3px solid var(--ink);
  box-shadow: var(--shadow-sm);
  padding: 12px 14px;
  text-decoration: none;
  color: var(--ink);
}
.nav-list a:active { transform: translate(3px, 3px); box-shadow: 0 0 0 var(--ink); }
.nav-list .soon { opacity: .5; box-shadow: none; border-style: dashed; }
.nav-list .nl-num {
  flex: 0 0 auto;
  width: 44px; height: 44px;
  line-height: 38px;
  text-align: center;
  font-weight: 900;
  background: var(--blue);
  border: 3px solid var(--ink);
}
.nav-list .soon .nl-num { background: #e8e4d8; }
.nav-list .nl-rb .nl-num { background: var(--green); }
.nav-list .nl-txt { flex: 1 1 auto; min-width: 0; }
.nav-list .nl-txt b { display: block; font-weight: 900; }
.nav-list .nl-txt small { display: block; font-size: .82em; opacity: .7; }

/* ===== Blättern: zurück und weiter nebeneinander ===== */
/* minmax(0, 1fr) statt 1fr: Rasterspalten sind von Haus aus mindestens so breit
   wie ihr laengstes Wort. „Koordinatengleichung“ im Blaettern-Kasten macht die
   Seite sonst breiter als das Fenster. Dazu darf ein solches Wort umbrechen. */
.pager {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  gap: 12px;
  margin-top: 44px;
}
.pager a {
  display: block;
  background: #fff;
  border: 3px solid var(--ink);
  box-shadow: var(--shadow-sm);
  padding: 12px 14px;
  text-decoration: none;
  color: var(--ink);
  font-weight: 900;
  font-size: .95rem;
  line-height: 1.3;
  overflow-wrap: break-word;
}
.pager .next { background: var(--blue); text-align: right; }
.pager a small {
  display: block;
  font-size: .7rem;
  text-transform: uppercase;
  font-weight: 800;
  opacity: .6;
  margin-bottom: 3px;
}
.pager a:active { transform: translate(3px, 3px); box-shadow: 0 0 0 var(--ink); }

footer {
  max-width: var(--maxw);
  margin: 40px auto 0;
  font-size: .8rem;
  font-weight: 600;
  opacity: .55;
}

@media (max-width: 420px) {
  body { font-size: 16px; }
  h1 { font-size: 1.42rem; }
  .ctl .name { min-width: 0; }
  .match-grid { grid-template-columns: 1fr; }
}
