:root {
  --bg: #f2f4f6;
  --surface: #ffffff;
  --ink: #18202b;
  --muted: #566170;
  --line: #d9dee4;
  --offen: #b9c1cb;
  --erledigt: #9a5b00;
  --abgenommen: #1e6b52;
  --focus: #2b5fd9;
  --fehler: #b42318;
  color-scheme: light dark;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #12161c;
    --surface: #1a2029;
    --ink: #e6eaf0;
    --muted: #a3adba;
    --line: #2c3440;
    --offen: #47515e;
    --erledigt: #e0a040;
    --abgenommen: #4fbf92;
    --focus: #7aa2ff;
    --fehler: #ff8a80;
  }
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 1rem/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

main {
  max-width: 40rem;
  margin: 0 auto;
  padding: 0 16px 4rem;
}

h1, h2, h3 { line-height: 1.2; margin: 0; }
h2 { font-size: 1.125rem; font-weight: 650; margin: 2rem 0 0.75rem; }
h3 { font-size: 1rem; font-weight: 600; }
p { margin: 0.25rem 0; }

.leise { color: var(--muted); font-size: 0.9375rem; }

/* Kopf mit Wochenzahl */
header {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 1rem;
  padding: 1.25rem 0 0.5rem;
}
.woche-gross {
  font-size: clamp(2.75rem, 12vw, 4rem);
  font-weight: 750;
  letter-spacing: -0.03em;
  font-variant-numeric: tabular-nums;
}

/* Segmentbalken: eine Zelle pro Aufgabe */
.fortschritt { margin-top: 1.25rem; }
.phase .fortschritt { margin-top: 0.75rem; }
.balken { display: flex; gap: 3px; margin-bottom: 0.375rem; }
.balken span { flex: 1; height: 10px; border-radius: 2px; background: var(--offen); }
.balken .erledigt { background: var(--erledigt); }
.balken .abgenommen { background: var(--abgenommen); }

nav {
  position: sticky;
  top: 0;
  z-index: 1;
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  background: var(--bg);
  border-bottom: 1px solid var(--line);
  margin: 0 -16px;
  padding: 0 16px;
}
nav button {
  min-height: 48px;
  border: 0;
  background: none;
  color: var(--muted);
  font: inherit;
  font-weight: 600;
  border-bottom: 3px solid transparent;
  cursor: pointer;
}
nav button[aria-current="page"] { color: var(--ink); border-bottom-color: var(--ink); }

.flaeche {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 1rem;
}
.auftrag { font-size: 1.0625rem; }
.auftrag :first-child { margin-top: 0; }
.auftrag :last-child { margin-bottom: 0; }

ul.liste { list-style: none; margin: 0; padding: 0; }
ul.liste > li { padding: 1rem 0; border-top: 1px solid var(--line); }
ul.liste > li:first-child { border-top: 0; }

.aufgabe { display: grid; grid-template-columns: 1fr auto; gap: 0.25rem 1rem; align-items: start; }
.aufgabe .beschreibung { grid-column: 1 / -1; color: var(--muted); }
.aufgabe .beschreibung p { margin: 0; }

.status { font-size: 0.875rem; font-weight: 600; white-space: nowrap; }
.status::before {
  content: "";
  display: inline-block;
  width: 0.625rem;
  height: 0.625rem;
  border-radius: 2px;
  margin-right: 0.375rem;
  background: var(--offen);
}
.status.offen { color: var(--muted); }
.status.erledigt { color: var(--erledigt); }
.status.erledigt::before { background: var(--erledigt); }
.status.abgenommen { color: var(--abgenommen); }
.status.abgenommen::before { background: var(--abgenommen); }

.notiz { grid-column: 1 / -1; font-size: 0.9375rem; }

button.aktion, button.zweit {
  min-height: 44px;
  padding: 0 1rem;
  border-radius: 8px;
  font: inherit;
  font-weight: 600;
  cursor: pointer;
}
button.aktion { background: var(--ink); color: var(--bg); border: 1px solid var(--ink); }
button.zweit { background: none; color: var(--ink); border: 1px solid var(--line); }
.aufgabe > button { grid-column: 1 / -1; justify-self: start; margin-top: 0.5rem; }
button:disabled { opacity: 0.6; cursor: wait; }

:focus-visible { outline: 3px solid var(--focus); outline-offset: 2px; }

form { display: grid; gap: 1rem; margin-top: 1rem; }
form > button { justify-self: start; }
.login > button { justify-self: stretch; }
label { display: grid; gap: 0.375rem; font-weight: 600; }
label .leise { font-weight: 400; }
input, textarea, select {
  width: 100%;
  min-height: 44px;
  padding: 0.625rem 0.75rem;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  color: var(--ink);
  font: inherit;
}
textarea { min-height: 6rem; resize: vertical; }
.zeile { display: grid; grid-template-columns: 1fr 1fr; gap: 0.75rem; }

.phase { padding: 1.25rem 0; border-top: 1px solid var(--line); }
.phase:first-of-type { border-top: 0; }
.phase-titel { margin: 0; }
.legende { margin-top: 1.25rem; }

.zeiten td, .zeiten th { padding: 0.5rem 0; text-align: left; border-top: 1px solid var(--line); }
.zeiten { width: 100%; border-collapse: collapse; }
.zeiten td.h, .zeiten th.h { text-align: right; font-variant-numeric: tabular-nums; }

.antwort { margin-top: 0.5rem; padding: 0.75rem; border-radius: 8px; background: var(--bg); }
.meldung { padding: 0.75rem 1rem; border-radius: 8px; background: var(--surface); border: 1px solid var(--line); }
.meldung.fehler { color: var(--fehler); }

/* Übungen */
.uebungen { grid-column: 1 / -1; margin-top: 0.5rem; }
.uebungen summary::before { content: "\25B8"; width: 1.25rem; color: var(--muted); }
.uebungen[open] summary::before { content: "\25BE"; }
.uebungen summary {
  min-height: 44px;
  display: flex;
  align-items: center;
  font-weight: 600;
  cursor: pointer;
}
.uebung { padding: 1rem 0; border-top: 1px solid var(--line); }
.uebung .frage { font-weight: 600; margin-bottom: 0.75rem; }

.code {
  list-style: none;
  counter-reset: zeile;
  margin: 0 0 1rem;
  padding: 0.5rem 0;
  border-radius: 8px;
  background: var(--surface);
  border: 1px solid var(--line);
  font: 0.875rem/1.6 ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  overflow-x: auto;
}
.code li {
  counter-increment: zeile;
  display: flex;
  align-items: stretch;
  white-space: pre;
  padding: 0 0.75rem 0 0;
}
.code li::before {
  content: counter(zeile);
  display: flex;
  align-items: center;
  justify-content: flex-end;
  flex: 0 0 2.5rem;
  padding-right: 0.75rem;
  text-align: right;
  color: var(--muted);
  user-select: none;
}
.code li.gewaehlt { background: var(--bg); font-weight: 700; }
.code input.luecke { font: inherit; min-height: 40px; padding: 0.25rem 0.5rem; min-width: 14rem; }
.code button.zeile {
  flex: 1;
  display: flex;
  align-items: center;
  min-height: 44px;
  text-align: left;
  white-space: pre;
  font: inherit;
  color: var(--ink);
  background: none;
  border: 1px solid transparent;
  border-radius: 6px;
  padding: 0 0.5rem;
  cursor: pointer;
}
.code button.zeile[aria-pressed="true"] { border-color: var(--ink); background: var(--bg); font-weight: 700; }

fieldset.optionen { border: 0; margin: 0; padding: 0; display: grid; gap: 0.5rem; }
.option {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  min-height: 44px;
  padding: 0 0.75rem;
  border: 1px solid var(--line);
  border-radius: 8px;
  font-weight: 400;
  cursor: pointer;
}
.option input { width: auto; min-height: 0; margin: 0; }

.richtig { color: var(--abgenommen); font-weight: 600; }
.falsch { color: var(--erledigt); font-weight: 600; }
.aufloesung { white-space: pre-line; padding: 0.75rem; border-radius: 8px; background: var(--surface); border: 1px solid var(--line); }

.login { max-width: 22rem; margin: 18vh auto 0; }
.login h1 { font-size: 1.75rem; margin-bottom: 1.5rem; }

@media (prefers-reduced-motion: no-preference) {
  .balken span { transition: background-color 200ms ease-out; }
}
