/* Lernseite Einführung in die Stochastik – Stil */
:root {
  --bg: #fbfaf7;
  --panel: #ffffff;
  --ink: #1d2230;
  --muted: #5b6272;
  --line: #dfdcd3;
  --accent: #1f4e8c;        /* MidnightBlue-Ton des Skripts */
  --accent-soft: #e8eef7;
  --red: #a8322d;           /* BrickRed */
  --orange: #c9761a;
  --hilfe: #2f7a5b;         /* Lernhilfen */
  --hilfe-soft: #eaf4ee;
  --satz: #1f4e8c;
  --def: #6a4c93;
  --bsp: #7a6a3a;
  --bem: #6b7280;
  --ok: #2f7a5b;
  --bad: #a8322d;
  --shadow: 0 1px 2px rgba(0,0,0,.05);
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #15171c; --panel: #1c1f26; --ink: #e6e7ea; --muted: #a2a8b4; --line: #333844;
    --accent: #8db4ec; --accent-soft: #233148; --red: #e58b84; --orange: #e9a85a;
    --hilfe: #7fcca5; --hilfe-soft: #1d2e27; --satz: #8db4ec; --def: #b9a0dc; --bsp: #cfbd84; --bem: #a2a8b4;
    --ok: #7fcca5; --bad: #e58b84; color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #15171c; --panel: #1c1f26; --ink: #e6e7ea; --muted: #a2a8b4; --line: #333844;
  --accent: #8db4ec; --accent-soft: #233148; --red: #e58b84; --orange: #e9a85a;
  --hilfe: #7fcca5; --hilfe-soft: #1d2e27; --satz: #8db4ec; --def: #b9a0dc; --bsp: #cfbd84; --bem: #a2a8b4;
  --ok: #7fcca5; --bad: #e58b84; color-scheme: dark;
}

* { box-sizing: border-box; }
html { scroll-padding-top: 64px; }
body {
  margin: 0; background: var(--bg); color: var(--ink);
  font: 17px/1.6 "Iowan Old Style", "Palatino Linotype", Palatino, "Book Antiqua", Georgia, serif;
}
a { color: var(--accent); }
.katex { font-size: 1.05em; }

/* Kopfzeile */
.topbar {
  position: sticky; top: 0; z-index: 20; display: flex; align-items: center; gap: 12px;
  padding: 10px 16px; background: var(--panel); border-bottom: 1px solid var(--line);
  font-family: system-ui, -apple-system, "Segoe UI", sans-serif; font-size: 15px;
}
.brand { font-weight: 600; color: var(--ink); text-decoration: none; }
.crumb { color: var(--muted); }
.crumb::before { content: "›"; margin-right: 10px; }
.theme-toggle, .toc-toggle {
  border: 1px solid var(--line); background: transparent; color: var(--ink); border-radius: 6px;
  width: 34px; height: 30px; cursor: pointer; font-size: 16px;
}
.theme-toggle { margin-left: auto; }
.toc-toggle { display: none; }

/* Layout */
.layout { display: grid; grid-template-columns: 270px minmax(0, 1fr); max-width: 1180px; margin: 0 auto; }
.toc {
  position: sticky; top: 51px; align-self: start; height: calc(100vh - 51px); overflow-y: auto;
  padding: 22px 14px 22px 16px; border-right: 1px solid var(--line);
  font-family: system-ui, -apple-system, "Segoe UI", sans-serif; font-size: 14px;
}
.toc-head { font-weight: 600; margin-bottom: 8px; color: var(--muted); text-transform: uppercase; font-size: 12px; letter-spacing: .06em; }
.toc ol { list-style: none; margin: 0; padding: 0; }
.toc li { display: flex; align-items: baseline; gap: 6px; padding: 3px 0; }
.toc li.lvl3 { padding-left: 16px; font-size: 13px; }
.toc a { color: var(--ink); text-decoration: none; flex: 1; }
.toc a:hover { color: var(--accent); }
.toc a.aktiv { color: var(--accent); font-weight: 600; }
.toc .num { color: var(--muted); margin-right: 4px; font-variant-numeric: tabular-nums; }
.done-mark { width: 14px; color: var(--ok); }
.done-mark.done::after { content: "✓"; }
.toc-progress { margin: 18px 0 12px; }
.toc-progress .bar { height: 6px; background: var(--line); border-radius: 3px; overflow: hidden; }
.toc-progress .bar span { display: block; height: 100%; width: 0; background: var(--hilfe); transition: width .3s; }
.toc-progress .txt { color: var(--muted); font-size: 12px; margin-top: 4px; }
.toc-legend p { margin: 4px 0; color: var(--muted); font-size: 12px; display: flex; align-items: center; gap: 6px; }
.sw { display: inline-block; width: 12px; height: 12px; border-radius: 2px; }
.sw.skript { border-left: 3px solid var(--satz); background: var(--accent-soft); }
.sw.hilfe { border-left: 3px solid var(--hilfe); background: var(--hilfe-soft); }

main { padding: 28px 40px 80px; min-width: 0; max-width: 860px; }
.chapter-head .kicker { font-family: system-ui, sans-serif; font-size: 13px; color: var(--muted); letter-spacing: .04em; text-transform: uppercase; }
h1 { font-size: 2em; line-height: 1.2; margin: 6px 0 14px; }
.hinweis { color: var(--muted); font-size: 15px; border-left: 3px solid var(--line); padding-left: 12px; }
h2 { font-size: 1.5em; margin: 2.2em 0 .6em; padding-top: .4em; border-top: 1px solid var(--line); }
h3 { font-size: 1.2em; margin: 1.8em 0 .5em; }
h2 .num, h3 .num { color: var(--muted); margin-right: 6px; }
p { margin: .7em 0; }
.dm { display: block; overflow-x: auto; overflow-y: hidden; padding: 2px 0; }
.dm .katex-display { margin: .6em 0; }

/* Vorlesungsmarke */
.vl {
  display: inline-block; font-family: system-ui, sans-serif; font-size: 12px; color: var(--muted);
  border: 1px solid var(--line); border-radius: 10px; padding: 0 8px; margin: 8px 0;
}

/* Umgebungen aus dem Skript */
.env {
  background: var(--panel); border: 1px solid var(--line); border-left: 4px solid var(--satz);
  border-radius: 6px; padding: 10px 16px 6px; margin: 1.2em 0; box-shadow: var(--shadow);
}
.env.def { border-left-color: var(--def); }
.env.bsp { border-left-color: var(--bsp); background: transparent; box-shadow: none; }
.env.bem { border-left-color: var(--bem); background: transparent; box-shadow: none; }
.env-head { font-family: system-ui, sans-serif; font-size: 15px; display: flex; gap: 6px; align-items: baseline; flex-wrap: wrap; }
.env-name { font-weight: 700; }
.env.satz .env-name { color: var(--satz); }
.env.def .env-name { color: var(--def); }
.env.bsp .env-name { color: var(--bsp); }
.env-title { color: var(--muted); }
.pdfref { margin-left: auto; color: var(--line); text-decoration: none; }
.env:hover .pdfref { color: var(--muted); }
.env.satz .env-body { font-style: italic; }
.env.satz .env-body em { font-style: normal; }
:target { animation: blink 1.6s ease-out; }
@keyframes blink { 0% { box-shadow: 0 0 0 4px var(--accent-soft); } 100% { box-shadow: none; } }

ol.enum { list-style: none; padding-left: 0; margin: .5em 0; }
ol.enum > li { display: flex; gap: 10px; margin: .3em 0; }
ol.enum > li > .lab { flex: 0 0 auto; min-width: 2em; font-style: normal; }
ol.enum > li > div { flex: 1; min-width: 0; }
ol.enum > li > div > p:first-child { margin-top: 0; }
ol.enum > li > div > p:last-child { margin-bottom: 0; }
.center { text-align: center; }
.center p { text-align: left; }

a.ref { text-decoration: none; border-bottom: 1px dotted var(--accent); }
.ref.ext { border-bottom: 1px dotted var(--muted); }

figure.abb { margin: 1.4em 0; text-align: center; }
img.tikz { max-width: 100%; height: auto; }
:root[data-theme="dark"] img.tikz { filter: invert(.88) hue-rotate(180deg); }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) img.tikz { filter: invert(.88) hue-rotate(180deg); } }
figcaption { font-size: 14px; color: var(--muted); max-width: 88%; margin: 8px auto 0; text-align: left; }

/* Beweise */
details.proof { margin: .8em 0 1.2em; border-left: 2px solid var(--line); padding-left: 14px; }
details.proof > summary {
  cursor: pointer; font-family: system-ui, sans-serif; font-size: 15px; font-style: italic; color: var(--muted);
  list-style: none; display: flex; align-items: center; gap: 8px;
}
details.proof > summary::-webkit-details-marker { display: none; }
details.proof > summary::before { content: "▸"; font-style: normal; transition: transform .15s; }
details.proof[open] > summary::before { transform: rotate(90deg); }
.proof-tools { font-family: system-ui, sans-serif; font-size: 13px; display: flex; gap: 8px; margin: 6px 0; flex-wrap: wrap; }
.qed { display: block; text-align: right; }
.proof-body > .verdeckt { display: none; }
.btn {
  font-family: system-ui, sans-serif; font-size: 13px; border: 1px solid var(--line); border-radius: 6px;
  background: var(--panel); color: var(--ink); padding: 5px 10px; cursor: pointer;
}
.btn:hover { border-color: var(--accent); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--panel); }

/* Lernhilfen */
.hilfe, .widget {
  background: var(--hilfe-soft); border: 1px solid color-mix(in srgb, var(--hilfe) 30%, transparent);
  border-left: 4px solid var(--hilfe); border-radius: 6px; padding: 12px 16px; margin: 1.3em 0;
}
.widget:empty { display: none; }
.hilfe h4, .widget h4 { margin: 2px 0 6px; font-family: system-ui, sans-serif; font-size: 16px; }
.hilfe ul { margin: .3em 0; padding-left: 1.2em; }
.hilfe-tag {
  display: inline-block; font-family: system-ui, sans-serif; font-size: 11px; font-weight: 600; letter-spacing: .05em;
  text-transform: uppercase; color: var(--hilfe); margin-bottom: 2px;
}
.hilfe-tag.inline { border: 1px solid var(--hilfe); border-radius: 4px; padding: 0 5px; margin: 0; }
.widget .idee { font-size: 15px; color: var(--ink); margin: 0 0 8px; }
.ctrls { display: flex; flex-wrap: wrap; gap: 8px 18px; font-family: system-ui, sans-serif; font-size: 14px; margin: 8px 0; align-items: center; }
.ctrls label { display: flex; align-items: center; gap: 8px; }
.ctrls input[type=range] { width: 150px; accent-color: var(--hilfe); }
.ctrls output { font-variant-numeric: tabular-nums; min-width: 3.5em; display: inline-block; }
.ctrls select { font: inherit; padding: 2px 4px; background: var(--panel); color: var(--ink); border: 1px solid var(--line); border-radius: 4px; }
.plot { width: 100%; height: auto; display: block; background: var(--panel); border: 1px solid var(--line); border-radius: 4px; margin: 6px 0; }
.plot text { font-family: system-ui, sans-serif; font-size: 12px; fill: var(--muted); }
.plot .axis { stroke: var(--muted); stroke-width: 1; }
.plot .grid { stroke: var(--line); stroke-width: 1; }
.readout { font-family: system-ui, sans-serif; font-size: 14px; display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 6px 16px; margin: 6px 0; }
.readout div { background: var(--panel); border: 1px solid var(--line); border-radius: 4px; padding: 6px 10px; }
.readout b { font-variant-numeric: tabular-nums; }
.legend { font-family: system-ui, sans-serif; font-size: 13px; display: flex; flex-wrap: wrap; gap: 4px 14px; color: var(--muted); }
.legend .li::before { content: ""; display: inline-block; width: 14px; height: 3px; margin-right: 5px; vertical-align: middle; background: var(--c); }
.art { font-family: system-ui, sans-serif; font-size: 12px; color: var(--muted); font-style: italic; }

/* Quiz */
.quiz-block h4 { display: flex; justify-content: space-between; gap: 10px; flex-wrap: wrap; }
.quiz-block .score { font-weight: 400; color: var(--muted); font-size: 14px; }
.frage { background: var(--panel); border: 1px solid var(--line); border-radius: 6px; padding: 10px 14px; margin: 10px 0; }
.frage .prompt { margin: 0 0 8px; }
.frage .opts { display: grid; gap: 6px; }
.frage .opt {
  text-align: left; font: inherit; font-size: 16px; background: transparent; color: var(--ink);
  border: 1px solid var(--line); border-radius: 6px; padding: 6px 10px; cursor: pointer;
}
.frage .opt:hover:not(:disabled) { border-color: var(--accent); }
.frage .opt.richtig { border-color: var(--ok); background: color-mix(in srgb, var(--ok) 12%, transparent); }
.frage .opt.falsch { border-color: var(--bad); background: color-mix(in srgb, var(--bad) 10%, transparent); }
.frage .opt:disabled { cursor: default; }
.frage .erkl { margin-top: 8px; font-size: 15px; border-top: 1px dashed var(--line); padding-top: 8px; }
.frage .erkl b.ok { color: var(--ok); } .frage .erkl b.no { color: var(--bad); }
.frage .eingabe { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; font-family: system-ui, sans-serif; }
.frage .eingabe input { font: inherit; width: 9em; padding: 4px 6px; border: 1px solid var(--line); border-radius: 4px; background: var(--bg); color: var(--ink); }
.done-btn { margin-top: 8px; }

.foot { margin-top: 60px; color: var(--muted); font-size: 14px; border-top: 1px solid var(--line); padding-top: 12px; }

/* Startseite */
.kapitel-liste { list-style: none; padding: 0; }
.kapitel-liste li { background: var(--panel); border: 1px solid var(--line); border-radius: 6px; padding: 12px 16px; margin: 10px 0; display: flex; gap: 12px; align-items: baseline; }
.kapitel-liste li.bald { opacity: .55; }
.kapitel-liste .nr { font-weight: 700; color: var(--accent); min-width: 2em; }
.kapitel-liste .status { margin-left: auto; font-family: system-ui, sans-serif; font-size: 13px; color: var(--muted); }

@media (max-width: 900px) {
  .layout { grid-template-columns: 1fr; }
  .toc-toggle { display: inline-block; }
  .toc { position: fixed; left: 0; top: 51px; width: 290px; max-width: 85vw; z-index: 15; background: var(--panel);
         transform: translateX(-100%); transition: transform .2s; box-shadow: 2px 0 12px rgba(0,0,0,.15); }
  body.toc-offen .toc { transform: none; }
  main { padding: 20px 16px 60px; }
  .crumb { display: none; }
  .brand { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
  body { font-size: 16px; }
  .ctrls input[type=range] { width: 120px; }
}

/* Kapitelnavigation, Tabellen */
.kapnav { display: flex; justify-content: space-between; gap: 12px; margin-top: 48px; font-family: system-ui, sans-serif; font-size: 15px; flex-wrap: wrap; }
.kapnav a { text-decoration: none; }
table.tab { margin: .6em auto; border-collapse: collapse; }
table.tab td { padding: 2px 6px; }

/* Handy: Auswahlfelder nicht breiter als der Bildschirm */
.ctrls label { flex-wrap: wrap; max-width: 100%; }
.ctrls select { max-width: 100%; }

/* Startseite: Teile; Abbildungsnummern */
.kapitel-liste li.teil { background: transparent; border: 0; padding: 18px 0 2px; font-family: system-ui, sans-serif; font-size: 13px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); }
.fig-num { font-weight: 600; color: var(--ink); }

figure.abb { overflow-x: auto; }
table.tab td { vertical-align: top; }
table.tab tr:first-child td { border-bottom: 1px solid var(--line); font-weight: 600; }
.tabwrap { overflow-x: auto; max-width: 100%; }
figure.abb { max-width: 100%; min-width: 0; }
.dm, figure.abb, .tabwrap { position: relative; }
