:root {
  --bg: #f6f7fb;
  --panel: #ffffff;
  --text: #1d2233;
  --muted: #5d6478;
  --line: #e1e4ee;
  --accent: #4f46e5;
  --accent-soft: #eef0ff;
  --ok: #15803d;
  --ok-soft: #e7f6ec;
  --bad: #b91c1c;
  --bad-soft: #fdecec;
  --warn: #92400e;
  --warn-soft: #fff6e0;
  --radius: 12px;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #12141c;
    --panel: #1b1e29;
    --text: #e7e9f1;
    --muted: #a0a6b8;
    --line: #2d3142;
    --accent: #8b85ff;
    --accent-soft: #262a45;
    --ok: #4ade80;
    --ok-soft: #173024;
    --bad: #f87171;
    --bad-soft: #3a1d1f;
    --warn: #fbbf24;
    --warn-soft: #3a2f14;
  }
}
* { box-sizing: border-box; }
html { scroll-behavior: smooth; }
body {
  margin: 0;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.6;
}
a { color: var(--accent); }
code { background: var(--accent-soft); padding: 1px 5px; border-radius: 5px; font-size: .92em; }

/* 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);
}
.brand { font-weight: 700; text-decoration: none; color: var(--text); font-size: 1.05rem; }
.brand span { color: var(--accent); font-weight: 600; }
.modes { margin-left: auto; display: flex; gap: 4px; flex-wrap: wrap; }
.modes a {
  text-decoration: none; color: var(--muted);
  padding: 6px 10px; border-radius: 8px; font-weight: 500;
}
.modes a.active, .modes a:hover { background: var(--accent-soft); color: var(--accent); }
.icon-btn {
  background: none; border: 1px solid var(--line); color: var(--text);
  border-radius: 8px; padding: 4px 10px; font-size: 1.1rem; cursor: pointer;
}
#menuBtn { display: none; }

/* Layout */
.layout { display: grid; grid-template-columns: 280px 1fr; min-height: calc(100vh - 54px); }
#sidebar {
  border-right: 1px solid var(--line);
  background: var(--panel);
  padding: 16px 12px;
  position: sticky; top: 54px; height: calc(100vh - 54px); overflow-y: auto;
}
#chapterList { list-style: none; margin: 0; padding: 0; }
#chapterList li a {
  display: flex; align-items: center; gap: 8px;
  padding: 7px 10px; border-radius: 8px;
  text-decoration: none; color: var(--text); font-size: .95rem;
}
#chapterList li a:hover { background: var(--accent-soft); }
#chapterList li a.active { background: var(--accent); color: #fff; }
#chapterList .nr { font-variant-numeric: tabular-nums; color: var(--muted); width: 1.6em; }
#chapterList a.active .nr { color: #fff; }
#chapterList .done-mark { margin-left: auto; color: var(--ok); }
#chapterList a.active .done-mark { color: #fff; }

.progress-box { padding: 4px 10px 14px; }
.progress-label { display: flex; justify-content: space-between; font-size: .85rem; color: var(--muted); }
.progress-bar { height: 8px; background: var(--line); border-radius: 99px; overflow: hidden; margin-top: 6px; }
#progressFill { height: 100%; width: 0; background: var(--ok); transition: width .3s; }

main { padding: 28px clamp(16px, 4vw, 48px) 80px; max-width: 980px; width: 100%; outline: none; }

/* Inhalte */
h1 { font-size: clamp(1.5rem, 3vw, 2rem); line-height: 1.25; margin: 0 0 8px; }
h2 { font-size: 1.2rem; margin: 32px 0 12px; }
.chap-kicker { color: var(--accent); font-weight: 600; letter-spacing: .04em; font-size: .85rem; text-transform: uppercase; }
.card {
  background: var(--panel); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 16px 20px; margin: 12px 0;
}
.kernsatz { border-left: 4px solid var(--accent); font-size: 1.08rem; }
.hinweis { background: var(--warn-soft); border-color: transparent; color: var(--text); }
.hinweis strong { color: var(--warn); }
.punkte { padding-left: 1.2em; margin: 0; }
.punkte li { margin: 8px 0; }

figure { margin: 16px 0; }
figure img {
  width: 100%; height: auto; border-radius: var(--radius);
  border: 1px solid var(--line); cursor: zoom-in; display: block;
}
figcaption { color: var(--muted); font-size: .85rem; margin-top: 6px; }
.img-missing { padding: 24px; text-align: center; color: var(--muted); border: 1px dashed var(--line); border-radius: var(--radius); }

.begriffe { display: grid; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); gap: 10px; }
.begriff { background: var(--panel); border: 1px solid var(--line); border-radius: 10px; padding: 10px 14px; }
.begriff b { display: block; color: var(--accent); }

details.frage {
  background: var(--panel); border: 1px solid var(--line);
  border-radius: 10px; margin: 8px 0; padding: 0;
}
details.frage summary {
  cursor: pointer; padding: 12px 16px; font-weight: 500; list-style: none;
}
details.frage summary::-webkit-details-marker { display: none; }
details.frage summary::before { content: "▸ "; color: var(--accent); }
details.frage[open] summary::before { content: "▾ "; }
details.frage .loesung { padding: 0 16px 14px 34px; color: var(--text); }
details.frage .loesung::before { content: "Lösung: "; font-weight: 700; color: var(--ok); }

.btn {
  background: var(--accent); color: #fff; border: none;
  padding: 9px 16px; border-radius: 9px; font-size: .95rem; font-weight: 600; cursor: pointer;
}
.btn.secondary { background: var(--accent-soft); color: var(--accent); }
.btn:disabled { opacity: .5; cursor: default; }
.btn-row { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; margin: 16px 0; }

.check-row { display: flex; align-items: center; gap: 10px; font-weight: 600; cursor: pointer; }
.check-row input { width: 20px; height: 20px; accent-color: var(--ok); }

.chap-nav { display: flex; justify-content: space-between; gap: 10px; margin-top: 36px; flex-wrap: wrap; }
.chap-nav a { text-decoration: none; }

/* Quiz */
.quiz-q { font-weight: 600; margin-bottom: 10px; }
.quiz-opts { display: grid; gap: 8px; }
.quiz-opts button {
  text-align: left; background: var(--bg); color: var(--text);
  border: 1px solid var(--line); border-radius: 9px;
  padding: 10px 14px; font-size: .95rem; cursor: pointer;
}
.quiz-opts button:hover:not(:disabled) { border-color: var(--accent); }
.quiz-opts button.richtig { background: var(--ok-soft); border-color: var(--ok); }
.quiz-opts button.falsch { background: var(--bad-soft); border-color: var(--bad); }
.quiz-opts button:disabled { cursor: default; }
.quiz-feedback { margin-top: 10px; font-size: .95rem; }
.quiz-feedback.ok b { color: var(--ok); }
.quiz-feedback.bad b { color: var(--bad); }
.quiz-meta { color: var(--muted); font-size: .85rem; margin-bottom: 4px; }
select { padding: 8px 10px; border-radius: 8px; border: 1px solid var(--line); background: var(--panel); color: var(--text); font-size: .95rem; max-width: 100%; }
.score { font-size: 2rem; font-weight: 700; }

/* Karteikarten */
.karte {
  perspective: 1000px; height: 220px; cursor: pointer; margin: 16px 0;
}
.karte-inner {
  position: relative; width: 100%; height: 100%;
  transition: transform .45s; transform-style: preserve-3d;
}
.karte.umgedreht .karte-inner { transform: rotateY(180deg); }
.karte-seite {
  position: absolute; inset: 0; backface-visibility: hidden;
  display: flex; align-items: center; justify-content: center; text-align: center;
  padding: 24px; border-radius: var(--radius);
  background: var(--panel); border: 1px solid var(--line); font-size: 1.15rem;
}
.karte-vorne { font-size: 1.6rem; font-weight: 700; color: var(--accent); }
.karte-hinten { transform: rotateY(180deg); }

/* Startseite */
.kapitel-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 12px; }
.kapitel-kachel {
  display: block; text-decoration: none; color: var(--text);
  background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden;
}
.kapitel-kachel:hover { border-color: var(--accent); }
.kapitel-kachel img { width: 100%; aspect-ratio: 16/9; object-fit: cover; display: block; background: var(--line); }
.kapitel-kachel div { padding: 10px 12px; font-weight: 600; font-size: .95rem; }
.kapitel-kachel small { color: var(--muted); display: block; font-weight: 500; }

/* Bildprüfung */
.bild-pruefung { margin-top: -4px; font-size: .95rem; }
.bild-pruefung.ok { background: var(--ok-soft); border-color: transparent; }
.bild-pruefung.ok strong { color: var(--ok); }
.bild-pruefung.fehler { background: var(--bad-soft); border-color: var(--bad); }
.bild-pruefung.fehler strong { color: var(--bad); }
.bild-pruefung strong.sub { display: block; margin-top: 8px; color: var(--text); }

/* Lightbox */
#lightbox {
  position: fixed; inset: 0; z-index: 50; background: rgba(0,0,0,.85);
  display: flex; align-items: center; justify-content: center; padding: 16px;
}
#lightbox[hidden] { display: none; }
#lightbox img { max-width: 100%; max-height: 100%; border-radius: 8px; }
.lb-close { position: absolute; top: 12px; right: 12px; color: #fff; border-color: #fff6; }

/* Handy */
@media (max-width: 820px) {
  #menuBtn { display: inline-block; }
  .layout { grid-template-columns: 1fr; }
  #sidebar {
    position: fixed; top: 54px; left: 0; bottom: 0; width: 280px; height: auto; z-index: 15;
    transform: translateX(-100%); transition: transform .25s; box-shadow: 0 0 30px #0004;
  }
  #sidebar.open { transform: none; }
  .modes a { padding: 6px 8px; font-size: .9rem; }
  .brand span { display: none; }
  .brand, .modes a { white-space: nowrap; }
  .modes { flex-wrap: nowrap; }
}
@media (max-width: 480px) {
  .brand { display: none; }
}
@media print {
  .topbar, #sidebar, .btn-row, .chap-nav { display: none; }
  .layout { display: block; }
  details.frage { break-inside: avoid; }
}
