:root {
  --bg: #fff7ea;
  --card: #ffffff;
  --ink: #2b2236;
  --muted: #7a6f86;
  --accent: #14a38b;
  --accent-ink: #0b6b5b;
  --gold: #ffd166;
  --warn: #ff8c42;
  --ok: #2bb673;
  --bad: #e5484d;
  --grid-a: #d9f2c4;
  --grid-b: #cdeab2;
  --line: #efe3cf;
  --code-bg: #2b2236;
  --code-ink: #fff7ea;
  --radius: 18px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #1d1828;
    --card: #272238;
    --ink: #f6eedf;
    --muted: #b2a7c2;
    --accent: #3fd3b5;
    --accent-ink: #9ff0de;
    --line: #3a3350;
    --grid-a: #2f4a3a;
    --grid-b: #29412f;
    --code-bg: #14101e;
    --code-ink: #f6eedf;
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #1d1828;
  --card: #272238;
  --ink: #f6eedf;
  --muted: #b2a7c2;
  --accent: #3fd3b5;
  --accent-ink: #9ff0de;
  --line: #3a3350;
  --grid-a: #2f4a3a;
  --grid-b: #29412f;
  --code-bg: #14101e;
  --code-ink: #f6eedf;
  color-scheme: dark;
}
* { box-sizing: border-box; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: "Nunito", system-ui, -apple-system, "Segoe UI", sans-serif;
  font-size: 17px;
  line-height: 1.5;
}
button { font: inherit; cursor: pointer; }
header.top {
  display: flex; align-items: center; gap: 14px; flex-wrap: wrap;
  padding: 14px 16px; border-bottom: 2px solid var(--line);
  background: var(--card); position: sticky; top: env(safe-area-inset-top, 0px); z-index: 5;
}
.brand { font-weight: 900; font-size: 1.25rem; margin-right: auto; }
.sprache-wahl { display: inline-flex; align-items: center; gap: 8px; }
.flagge {
  width: 36px; height: 24px; padding: 0; border-radius: 5px; overflow: hidden;
  border: 2px solid var(--line); background: none; line-height: 0; cursor: pointer;
}
.flagge svg { display: block; width: 100%; height: 100%; }
.flagge:hover { border-color: var(--muted); }
.flagge[aria-pressed="true"] { border-color: var(--accent); box-shadow: 0 0 0 2px var(--accent); }
.flagge:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }
.brand span { color: var(--accent); }
.progress { min-width: 180px; flex: 0 1 260px; }
.progress-label { font-size: .85rem; color: var(--muted); margin-bottom: 4px; }
.progress-bar { height: 12px; border-radius: 99px; background: var(--line); overflow: hidden; }
.progress-bar > div { height: 100%; width: 0; background: var(--accent); transition: width .4s ease; }
.layout {
  display: grid; grid-template-columns: 300px minmax(0, 1fr);
  gap: 20px; padding: 20px; max-width: 1200px; margin: 0 auto;
}
nav.kapitel { align-self: start; position: sticky; top: calc(84px + env(safe-area-inset-top, 0px)); }
.kapitel h2 {
  font-size: .95rem; margin: 16px 0 6px; color: var(--muted);
  text-transform: uppercase; letter-spacing: .06em;
}
.kapitel h2:first-child { margin-top: 0; }
.kapitel ul { list-style: none; margin: 0; padding: 0; }
.kapitel button.aufgabe {
  display: flex; gap: 10px; align-items: center; width: 100%; text-align: left;
  background: none; border: 0; padding: 8px 10px; border-radius: 12px; color: var(--ink);
}
.kapitel button.aufgabe:hover { background: var(--card); }
.kapitel button.aufgabe[aria-current="true"] { background: var(--card); box-shadow: 0 0 0 2px var(--accent) inset; }
.kapitel button.aufgabe:disabled { opacity: .6; cursor: default; background: none; }
.gruppe {
  font-weight: 900; font-size: 1.05rem; color: var(--accent-ink);
  margin: 22px 0 4px; padding-top: 10px; border-top: 2px solid var(--line);
}
.gruppe:first-child { margin-top: 0; padding-top: 0; border-top: 0; }
[hidden] { display: none !important; }
.frei-wahl { display: block; margin-top: 12px; font-weight: 700; }
.frei-wahl select {
  font: inherit; padding: 6px 10px; margin-left: 6px; border-radius: 12px;
  border: 2px solid var(--line); background: var(--bg); color: var(--ink);
}
.status {
  width: 24px; height: 24px; border-radius: 50%; flex: 0 0 24px;
  display: grid; place-items: center; font-size: .8rem; font-weight: 900;
  border: 2px solid var(--line); color: var(--muted);
}
.status.done { background: var(--ok); border-color: var(--ok); color: #fff; }
.badge {
  display: inline-block; font-size: .75rem; font-weight: 800; padding: 2px 9px;
  border-radius: 99px; background: var(--gold); color: #5a4300; margin-left: 6px; vertical-align: middle;
}
main section.card {
  background: var(--card); border-radius: var(--radius); padding: 20px 22px;
  box-shadow: 0 2px 0 var(--line); margin-bottom: 18px;
}
.kap-titel { font-size: 1.1rem; font-weight: 800; color: var(--accent-ink); margin: 0 0 4px; }
.einleitung { color: var(--muted); margin: 0; }
h1.aufgabe-titel { font-size: 1.5rem; margin: 0 0 6px; line-height: 1.2; }
.aufgabe-text { font-size: 1.1rem; margin: 0 0 14px; }
textarea.code {
  width: 100%; min-height: 200px; resize: vertical; padding: 14px;
  border-radius: 14px; border: 0; background: var(--code-bg); color: var(--code-ink);
  font-family: ui-monospace, "SFMono-Regular", Menlo, Consolas, monospace; font-size: 16px; line-height: 1.6;
  tab-size: 2;
}
textarea.code:focus { outline: 3px solid var(--accent); outline-offset: 2px; }
.actions { display: flex; flex-wrap: wrap; gap: 10px; margin-top: 12px; }
.btn {
  border: 0; border-radius: 14px; padding: 10px 16px; font-weight: 800; color: var(--ink);
  background: var(--line); min-height: 44px;
}
.btn.primary { background: var(--accent); color: #fff; }
.btn.check { background: var(--gold); color: #3d2e00; }
.btn.ghost { background: transparent; box-shadow: 0 0 0 2px var(--line) inset; }
.btn:disabled { opacity: .5; cursor: default; }
.btn:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }
.feedback {
  margin-top: 14px; padding: 12px 14px; border-radius: 14px; font-weight: 700; display: none;
}
.feedback.show { display: block; }
.feedback.ok { background: color-mix(in srgb, var(--ok) 18%, transparent); color: var(--ink); }
.feedback.bad { background: color-mix(in srgb, var(--warn) 20%, transparent); color: var(--ink); }
.feedback.err { background: color-mix(in srgb, var(--bad) 18%, transparent); color: var(--ink); white-space: pre-wrap; font-family: ui-monospace, Menlo, Consolas, monospace; font-weight: 600; font-size: .95rem; }
.hilfe { margin-top: 12px; display: none; }
.hilfe.show { display: block; }
.hilfe pre {
  background: var(--code-bg); color: var(--code-ink); padding: 12px 14px; border-radius: 12px;
  overflow-x: auto; font-size: 15px; margin: 8px 0 0;
}
.hilfe p { margin: 0; }
.grid-2 { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 18px; }
.welt-wrap canvas { width: 100%; height: auto; display: block; border-radius: 14px; background: var(--grid-a); }
.werte { display: grid; grid-template-columns: repeat(2, 1fr); gap: 8px; margin-top: 10px; font-size: .95rem; }
.werte div { background: var(--bg); border-radius: 12px; padding: 6px 10px; }
.werte b { display: block; font-size: .75rem; color: var(--muted); text-transform: uppercase; letter-spacing: .05em; }
pre.ausgabe {
  margin: 0; min-height: 120px; max-height: 260px; overflow: auto; white-space: pre-wrap;
  background: var(--bg); border-radius: 14px; padding: 12px 14px;
  font-family: ui-monospace, Menlo, Consolas, monospace; font-size: 15px;
}
.tools { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; margin-top: 10px; font-size: .9rem; color: var(--muted); }
.tools label { display: inline-flex; gap: 6px; align-items: center; }
.foot { color: var(--muted); font-size: .85rem; text-align: center; padding: 24px 16px 40px; }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }
@media (max-width: 900px) {
  .layout { grid-template-columns: 1fr; padding: 14px 16px; }
  nav.kapitel { position: static; order: 2; }
  main { order: 1; }
  .kapitel-liste { display: grid; grid-template-columns: 1fr; gap: 6px; }
}
@media (max-width: 700px) {
  .grid-2 { grid-template-columns: 1fr; }
  .progress { flex-basis: 100%; }
  header.top { position: static; }
  .brand { font-size: 1.1rem; }
}
