:root {
  --bg: #f5f6fa; --surface: #ffffff; --surface2: #eef0f6; --text: #151a2c; --muted: #636b84; --line: #dfe3ee;
  --accent: #4f46e5; --accent-weak: #e6e5fd; --accent-text: #ffffff;
  --ok: #138a4b; --ok-weak: #dff5e8; --warn: #b36b00; --warn-weak: #fff1d6; --bad: #c4283c; --bad-weak: #fde4e8;
  --code-bg: #101528; --code-text: #e5e9f7;
  --shadow: 0 1px 2px rgba(20,25,50,.06), 0 6px 18px rgba(20,25,50,.06);
  --radius: 14px;
  --nav-w: 232px;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0c1020; --surface: #151b30; --surface2: #1d2540; --text: #e8ebf7; --muted: #9aa3c0; --line: #29324f;
    --accent: #8b87ff; --accent-weak: #25285a; --accent-text: #0c1020;
    --ok: #4cd08a; --ok-weak: #123324; --warn: #f0b34a; --warn-weak: #3a2c10; --bad: #ff7a8c; --bad-weak: #3d1620;
    --code-bg: #0a0e1d; --code-text: #e5e9f7; --shadow: 0 1px 2px rgba(0,0,0,.4), 0 6px 18px rgba(0,0,0,.3);
  }
}
:root[data-theme="dark"] {
  --bg: #0c1020; --surface: #151b30; --surface2: #1d2540; --text: #e8ebf7; --muted: #9aa3c0; --line: #29324f;
  --accent: #8b87ff; --accent-weak: #25285a; --accent-text: #0c1020;
  --ok: #4cd08a; --ok-weak: #123324; --warn: #f0b34a; --warn-weak: #3a2c10; --bad: #ff7a8c; --bad-weak: #3d1620;
  --code-bg: #0a0e1d; --code-text: #e5e9f7; --shadow: 0 1px 2px rgba(0,0,0,.4), 0 6px 18px rgba(0,0,0,.3);
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; background: var(--bg); color: var(--text); font: 16px/1.55 system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", sans-serif; }
[hidden] { display: none !important; }
a { color: var(--accent); }
h1, h2, h3, h4 { line-height: 1.25; margin: 0 0 .5em; }
h1 { font-size: 1.6rem; } h2 { font-size: 1.25rem; } h3 { font-size: 1.05rem; }
.muted { color: var(--muted); } .small { font-size: .86rem; } .right { text-align: right; }
.error { color: var(--bad); min-height: 1.4em; margin: .3rem 0 0; }

/* Login */
.login { min-height: 100dvh; display: grid; place-items: center; padding: 20px; }
.login-card { width: min(380px, 100%); background: var(--surface); border-radius: 20px; box-shadow: var(--shadow); padding: 28px; display: grid; gap: 12px; }
.login-card h1 { margin: 0; }
.login-card label { display: grid; gap: 4px; font-size: .9rem; color: var(--muted); }
.logo { width: 56px; height: 56px; border-radius: 14px; background: var(--accent); color: var(--accent-text); display: grid; place-items: center; font-weight: 800; font-size: 1.2rem; }
input, select, textarea { font: inherit; color: var(--text); background: var(--surface); border: 1px solid var(--line); border-radius: 10px; padding: .6rem .75rem; width: 100%; }
input:focus, select:focus, textarea:focus, button:focus-visible, a:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
textarea { min-height: 140px; resize: vertical; line-height: 1.5; }
input[type=checkbox], input[type=radio] { width: auto; accent-color: var(--accent); }

/* Layout */
.app { display: flex; min-height: 100dvh; }
.nav { width: var(--nav-w); flex: none; background: var(--surface); border-right: 1px solid var(--line); padding: 18px 12px; position: sticky; top: 0; height: 100dvh; overflow-y: auto; display: flex; flex-direction: column; gap: 2px; }
.nav .brand { display: flex; align-items: center; gap: 10px; padding: 4px 10px 16px; font-weight: 700; }
.nav .brand .logo { width: 34px; height: 34px; font-size: .78rem; border-radius: 9px; }
.nav a { display: flex; align-items: center; gap: 11px; padding: 9px 12px; border-radius: 10px; color: var(--text); text-decoration: none; font-weight: 500; }
.nav a svg { width: 19px; height: 19px; flex: none; opacity: .75; }
.nav a:hover { background: var(--surface2); }
.nav a.active { background: var(--accent-weak); color: var(--accent); font-weight: 650; }
.nav a.active svg { opacity: 1; }
.nav .sp { flex: 1; }
.nav .who { padding: 8px 12px; font-size: .82rem; color: var(--muted); }
.main { flex: 1; min-width: 0; }
.topbar { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 14px 24px 0; max-width: 1100px; margin: 0 auto; }
main { padding: 14px 24px 90px; max-width: 1100px; margin: 0 auto; outline: none; }
.crumbs { font-size: .88rem; color: var(--muted); }
.crumbs a { color: var(--muted); text-decoration: none; } .crumbs a:hover { color: var(--accent); text-decoration: underline; }

@media (max-width: 880px) {
  .app { display: block; }
  .nav { position: fixed; z-index: 30; left: 0; right: 0; bottom: 0; top: auto; width: auto; height: auto; flex-direction: row; padding: 6px 6px calc(6px + env(safe-area-inset-bottom)); border-right: 0; border-top: 1px solid var(--line); justify-content: space-around; overflow: visible; gap: 0; }
  .nav .brand, .nav .sp, .nav .who { display: none; }
  .nav a { flex-direction: column; gap: 2px; font-size: .68rem; padding: 6px 4px; flex: 1; text-align: center; border-radius: 8px; min-width: 0; }
  .nav a span { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 100%; }
  .nav a.minor { display: none; }
  .topbar, main { padding-left: 16px; padding-right: 16px; }
  main { padding-bottom: 100px; }
}

/* Karten & Grid */
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 18px; box-shadow: var(--shadow); }
.card + .card { margin-top: 14px; }
.card.flat { box-shadow: none; }
.card h2, .card h3 { margin-top: 0; }
.grid { display: grid; gap: 14px; }
.grid.c2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.grid.c3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.grid.auto { grid-template-columns: repeat(auto-fill, minmax(250px, 1fr)); }
@media (max-width: 720px) { .grid.c2, .grid.c3 { grid-template-columns: 1fr; } }
.grid .card + .card { margin-top: 0; }
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.row.between { justify-content: space-between; }
.stack > * + * { margin-top: 12px; }
.hero { display: flex; gap: 18px; align-items: stretch; flex-wrap: wrap; }
.hero > .card { flex: 1 1 260px; margin-top: 0; }
.big { font-size: 2.4rem; font-weight: 750; line-height: 1.05; letter-spacing: -.02em; }
.kpi { display: grid; gap: 2px; } .kpi .lbl { color: var(--muted); font-size: .85rem; }

/* Buttons */
.btn { font: inherit; font-weight: 600; border: 1px solid var(--line); background: var(--surface); color: var(--text); padding: .55rem .95rem; border-radius: 10px; cursor: pointer; text-decoration: none; display: inline-flex; align-items: center; gap: 8px; justify-content: center; }
.btn:hover { background: var(--surface2); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-text); }
.btn.primary:hover { filter: brightness(1.08); }
.btn.ghost { border-color: transparent; background: transparent; }
.btn.small { padding: .3rem .65rem; font-size: .88rem; }
.btn[disabled] { opacity: .5; cursor: not-allowed; }
.btn.danger { color: var(--bad); }

/* Chips, Balken */
.chip { display: inline-flex; align-items: center; gap: 5px; font-size: .78rem; font-weight: 600; padding: 2px 9px; border-radius: 99px; background: var(--surface2); color: var(--muted); white-space: nowrap; }
.chip.ok { background: var(--ok-weak); color: var(--ok); } .chip.warn { background: var(--warn-weak); color: var(--warn); } .chip.bad { background: var(--bad-weak); color: var(--bad); } .chip.acc { background: var(--accent-weak); color: var(--accent); }
.bar { height: 8px; border-radius: 99px; background: var(--surface2); overflow: hidden; }
.bar > i { display: block; height: 100%; border-radius: 99px; background: var(--accent); transition: width .4s; }
.bar.ok > i { background: var(--ok); } .bar.warn > i { background: var(--warn); } .bar.bad > i { background: var(--bad); }
.bar2 { height: 10px; border-radius: 99px; background: var(--surface2); position: relative; overflow: hidden; }
.bar2 > i { position: absolute; top: 0; bottom: 0; left: 0; border-radius: 99px; }
.bar2 > .cov { background: var(--accent-weak); } .bar2 > .acc { background: var(--accent); }

/* Themenkarten */
.topic { display: grid; gap: 8px; text-decoration: none; color: inherit; transition: transform .12s, border-color .12s; }
.topic:hover { border-color: var(--accent); transform: translateY(-1px); }
.topic .t { font-weight: 650; } .topic .k { color: var(--muted); font-size: .86rem; }
.group-h { margin: 22px 0 10px; font-size: .8rem; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); font-weight: 700; }

/* Listen */
.list { list-style: none; margin: 0; padding: 0; }
.list > li { display: flex; gap: 12px; align-items: center; padding: 10px 0; border-top: 1px solid var(--line); }
.list > li:first-child { border-top: 0; }
.list .grow { flex: 1; min-width: 0; }
.task.done .lbl { text-decoration: line-through; color: var(--muted); }
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--line); margin-bottom: 16px; overflow-x: auto; }
.tabs button { font: inherit; background: none; border: 0; padding: 9px 14px; cursor: pointer; color: var(--muted); border-bottom: 2px solid transparent; font-weight: 600; white-space: nowrap; }
.tabs button.on { color: var(--accent); border-color: var(--accent); }

/* Markdown */
.md { overflow-wrap: anywhere; }
.md h1 { font-size: 1.4rem; margin-top: 1.4em; } .md h2 { font-size: 1.2rem; margin-top: 1.6em; padding-top: .4em; border-top: 1px solid var(--line); }
.md h3 { font-size: 1.05rem; margin-top: 1.3em; } .md > :first-child { margin-top: 0; }
.md p { margin: .65em 0; } .md ul, .md ol { padding-left: 1.3em; margin: .5em 0; } .md li { margin: .2em 0; }
.md code { background: var(--surface2); padding: .08em .35em; border-radius: 6px; font: .9em ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; }
.md pre { max-width: 100%; background: var(--code-bg); color: var(--code-text); padding: 14px 16px; border-radius: 12px; overflow-x: auto; line-height: 1.45; margin: .8em 0; }
.md pre code { background: none; padding: 0; color: inherit; font-size: .86rem; white-space: pre; }
.md .tw { overflow-x: auto; margin: .8em 0; }
.md table { border-collapse: collapse; font-size: .92rem; min-width: 60%; }
.md th, .md td { border: 1px solid var(--line); padding: 6px 10px; text-align: left; vertical-align: top; }
.md th { background: var(--surface2); }
.md blockquote { margin: .8em 0; padding: .4em 1em; border-left: 4px solid var(--accent); background: var(--accent-weak); border-radius: 0 10px 10px 0; }
.md blockquote p { margin: .3em 0; }
.md hr { border: 0; border-top: 1px solid var(--line); margin: 1.4em 0; }
.md img { max-width: 100%; }

/* Fragenkarte */
.q { display: grid; gap: 14px; grid-template-columns: minmax(0, 1fr); }
.q > * { min-width: 0; }
.card, .anlage, .solution { min-width: 0; }
.q-head { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.q-title { font-weight: 700; font-size: 1.1rem; }
.anlage { background: var(--surface2); border: 1px dashed var(--line); border-radius: 12px; padding: 12px 14px; }
.anlage .al { font-size: .78rem; text-transform: uppercase; letter-spacing: .07em; color: var(--muted); font-weight: 700; margin-bottom: 6px; }
.opts { display: grid; gap: 8px; }
.opt { display: flex; gap: 10px; align-items: flex-start; padding: 10px 12px; border: 1px solid var(--line); border-radius: 10px; cursor: pointer; background: var(--surface); }
.opt:hover { border-color: var(--accent); }
.opt.right { border-color: var(--ok); background: var(--ok-weak); } .opt.wrong { border-color: var(--bad); background: var(--bad-weak); }
.opt.missed { border-color: var(--ok); border-style: dashed; }
.zt { border-collapse: collapse; width: 100%; font-size: .93rem; }
.zt th, .zt td { border: 1px solid var(--line); padding: 7px 9px; text-align: center; }
.zt td:first-child, .zt th:first-child { text-align: left; }
.zt tr.right td:first-child { background: var(--ok-weak); } .zt tr.wrong td:first-child { background: var(--bad-weak); }
.zt td.cell-ok { background: var(--ok-weak); } .zt td.cell-bad { background: var(--bad-weak); }
.solution { border: 1px solid var(--ok); background: color-mix(in srgb, var(--ok-weak) 55%, var(--surface)); border-radius: 12px; padding: 14px 16px; }
.solution > h4 { margin: 0 0 6px; color: var(--ok); font-size: .82rem; text-transform: uppercase; letter-spacing: .07em; }
.raster { display: grid; gap: 6px; margin-top: 12px; }
.raster label { display: flex; gap: 10px; align-items: flex-start; padding: 8px 10px; border-radius: 10px; background: var(--surface); border: 1px solid var(--line); cursor: pointer; }
.raster label.on { border-color: var(--ok); background: var(--ok-weak); }
.raster .pt { margin-left: auto; font-weight: 700; color: var(--muted); white-space: nowrap; }
.score-line { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; font-weight: 650; }
.hint { background: var(--warn-weak); color: var(--warn); border-radius: 10px; padding: 8px 12px; font-size: .92rem; }
.merke { background: var(--accent-weak); border-radius: 10px; padding: 8px 12px; font-size: .92rem; }
.num-in { max-width: 220px; }
.verdict.ok { color: var(--ok); font-weight: 650; } .verdict.bad { color: var(--bad); font-weight: 650; }

/* Prüfungsmodus */
.examtop { position: sticky; top: 0; z-index: 20; background: color-mix(in srgb, var(--bg) 92%, transparent); backdrop-filter: blur(8px); padding: 10px 0; margin: -4px 0 12px; display: flex; align-items: center; gap: 12px; flex-wrap: wrap; border-bottom: 1px solid var(--line); }
.timer { font: 700 1.3rem ui-monospace, Menlo, monospace; font-variant-numeric: tabular-nums; }
.timer.low { color: var(--warn); } .timer.over { color: var(--bad); }
.aufgabe { margin-top: 22px; }
.aufgabe > h2 { display: flex; justify-content: space-between; gap: 12px; align-items: baseline; border-bottom: 2px solid var(--accent); padding-bottom: 6px; }
.teil { padding: 14px 0; border-top: 1px solid var(--line); }
.teil:first-of-type { border-top: 0; }
.teil-id { font-weight: 800; color: var(--accent); margin-right: 6px; }
.grade { display: grid; place-items: center; width: 72px; height: 72px; border-radius: 18px; background: var(--accent); color: var(--accent-text); font-size: 2rem; font-weight: 800; }

/* Heatmap / Tabellen */
.tw { overflow-x: auto; }
table.heat { border-collapse: separate; border-spacing: 3px; font-size: .86rem; width: 100%; }
table.heat th { font-weight: 600; text-align: left; padding: 4px 6px; color: var(--muted); }
table.heat th.c { text-align: center; }
table.heat td { text-align: center; padding: 7px 4px; border-radius: 8px; min-width: 52px; background: var(--surface2); font-variant-numeric: tabular-nums; }
table.heat td.lbl { text-align: left; background: none; font-weight: 600; padding-left: 6px; }
table.plain { border-collapse: collapse; width: 100%; font-size: .92rem; }
table.plain th, table.plain td { padding: 7px 9px; border-bottom: 1px solid var(--line); text-align: left; }
table.plain th { color: var(--muted); font-weight: 600; font-size: .82rem; }

/* Rechentrainer */
.cmd { font: .95rem ui-monospace, Menlo, monospace; background: var(--surface2); padding: 2px 8px; border-radius: 6px; }
.field { display: grid; gap: 4px; } .field label { font-size: .85rem; color: var(--muted); }
.fields { display: grid; gap: 10px; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); }
.ok-in { border-color: var(--ok) !important; background: var(--ok-weak) !important; } .bad-in { border-color: var(--bad) !important; background: var(--bad-weak) !important; }
.mono { font-family: ui-monospace, Menlo, Consolas, monospace; }

/* Toast */
.toast { position: fixed; left: 50%; bottom: 90px; transform: translate(-50%, 20px); background: var(--text); color: var(--bg); padding: 10px 16px; border-radius: 12px; font-weight: 600; opacity: 0; pointer-events: none; transition: .25s; z-index: 100; max-width: 90vw; }
.toast.show { opacity: 1; transform: translate(-50%, 0); }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }
.empty { text-align: center; padding: 30px 10px; color: var(--muted); }
details.fold { border: 1px solid var(--line); border-radius: 12px; padding: 4px 14px; background: var(--surface); }
details.fold + details.fold { margin-top: 8px; }
details.fold > summary { cursor: pointer; font-weight: 600; padding: 10px 0; }
@media print { .nav, .topbar, .examtop, .btn { display: none !important; } body { background: #fff; } }
