:root {
  --grund: #f5f5f7;
  --karte: #ffffff;
  --text: #1d1d1f;
  --text-leise: #6e6e73;
  --linie: #e3e3e8;
  --akzent: #0071e3;
  --akzent-text: #ffffff;
  --gut: #1f8a4c;
  --gut-grund: #e5f6ec;
  --warn-grund: #fff4d1;
  --warn-linie: #f0c33c;
  --warn-text: #7a5600;
  --fehler: #c9302c;
  --fehler-grund: #fdecea;
  --radius: 20px;
  --schatten: 0 1px 2px rgba(0, 0, 0, 0.04), 0 8px 24px rgba(0, 0, 0, 0.06);
  color-scheme: light dark;
}

@media (prefers-color-scheme: dark) {
  :root {
    --grund: #000000;
    --karte: #1c1c1e;
    --text: #f5f5f7;
    --text-leise: #a1a1a6;
    --linie: #38383a;
    --akzent: #2997ff;
    --gut: #4cd07d;
    --gut-grund: #12331f;
    --warn-grund: #3d3110;
    --warn-linie: #8a6d1a;
    --warn-text: #ffd866;
    --fehler: #ff6961;
    --fehler-grund: #3b1513;
    --schatten: none;
  }
}

* { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  background: var(--grund);
  color: var(--text);
  font: 17px/1.5 -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
}

.seite {
  max-width: 1100px;
  margin: 0 auto;
  padding: 16px max(16px, env(safe-area-inset-right)) 64px max(16px, env(safe-area-inset-left));
}
.seite.schmal { max-width: 460px; }

.kopf {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
  padding: 12px 0 20px;
}
.kopf h1 { margin: 0; }

h1 { font-size: 1.9rem; line-height: 1.15; letter-spacing: -0.02em; font-weight: 700; }
h2 { font-size: 1.3rem; line-height: 1.2; letter-spacing: -0.01em; margin: 0 0 12px; }
h3 { font-size: 1.05rem; margin: 0; }
p { margin: 0 0 12px; }
.leise { color: var(--text-leise); }
.klein { font-size: 0.88rem; }
a { color: var(--akzent); text-decoration: none; }

.karte {
  background: var(--karte);
  border-radius: var(--radius);
  box-shadow: var(--schatten);
  padding: 20px;
  margin-bottom: 20px;
}

/* Buttons */
.knopf {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 48px;
  padding: 10px 22px;
  border: 0;
  border-radius: 999px;
  background: var(--akzent);
  color: var(--akzent-text);
  font: inherit;
  font-weight: 600;
  cursor: pointer;
  transition: opacity 0.15s, transform 0.05s;
}
.knopf:active { transform: scale(0.98); }
.knopf:disabled { opacity: 0.5; cursor: default; }
.knopf.zweit { background: var(--grund); color: var(--akzent); }
.knopf.gefahr { background: var(--fehler-grund); color: var(--fehler); }
.knopf.gross { min-height: 64px; font-size: 1.2rem; width: 100%; border-radius: var(--radius); }
.knopf.klein { min-height: 40px; padding: 6px 16px; font-size: 0.92rem; }
.knopf-reihe { display: flex; gap: 10px; flex-wrap: wrap; }

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

/* Formulare */
.feld { display: block; margin-bottom: 16px; }
.feld > span { display: block; font-weight: 600; margin-bottom: 6px; }
input[type="text"], input[type="password"], input[type="number"], select, textarea {
  width: 100%;
  min-height: 52px;
  padding: 12px 16px;
  border: 1.5px solid var(--linie);
  border-radius: 14px;
  background: var(--karte);
  color: var(--text);
  font: inherit;
}
.gross-feld input { min-height: 60px; font-size: 1.2rem; }
textarea { min-height: 96px; resize: vertical; line-height: 1.4; }
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--akzent); }

.passwort-feld { position: relative; display: block; }
.passwort-feld input { padding-right: 110px; }
.passwort-feld button {
  position: absolute;
  right: 6px;
  top: 50%;
  transform: translateY(-50%);
  min-height: 44px;
  padding: 0 14px;
  border: 0;
  border-radius: 10px;
  background: transparent;
  color: var(--akzent);
  font: inherit;
  font-weight: 600;
  cursor: pointer;
}

.haken { display: flex; align-items: center; gap: 10px; margin-bottom: 16px; }
.haken input { width: 22px; height: 22px; }

/* Meldungen */
.meldung { border-radius: 14px; padding: 12px 16px; margin-bottom: 16px; }
.meldung.fehler { background: var(--fehler-grund); color: var(--fehler); }
.meldung.warnung { background: var(--warn-grund); color: var(--warn-text); }
.meldung.gut { background: var(--gut-grund); color: var(--gut); }

.marke {
  display: inline-block;
  padding: 2px 10px;
  border-radius: 999px;
  font-size: 0.8rem;
  font-weight: 600;
  background: var(--grund);
  color: var(--text-leise);
  white-space: nowrap;
}
.marke.gut { background: var(--gut-grund); color: var(--gut); }
.marke.warnung { background: var(--warn-grund); color: var(--warn-text); }
.marke.fehler { background: var(--fehler-grund); color: var(--fehler); }

/* Listen */
.liste { list-style: none; margin: 0; padding: 0; }
.liste > li {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
  padding: 14px 0;
  border-top: 1px solid var(--linie);
}
.liste > li:first-child { border-top: 0; }
.liste a.zeile { color: inherit; flex: 1; min-width: 200px; min-height: 48px; display: flex; flex-direction: column; justify-content: center; }
.marken { display: flex; gap: 6px; flex-wrap: wrap; }

.tabelle-rahmen { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 0.95rem; }
th, td { text-align: left; padding: 10px 12px 10px 0; border-top: 1px solid var(--linie); white-space: nowrap; }
th { border-top: 0; color: var(--text-leise); font-weight: 600; }
td.zahl, th.zahl { text-align: right; font-variant-numeric: tabular-nums; }

/* Dialog */
dialog {
  width: min(480px, calc(100vw - 32px));
  border: 0;
  border-radius: var(--radius);
  padding: 24px;
  background: var(--karte);
  color: var(--text);
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.3);
}
dialog::backdrop { background: rgba(0, 0, 0, 0.4); }

/* Vorlagen-Ansicht: Foto und Aufgaben nebeneinander, am Handy untereinander */
.vorlage-raster { display: grid; gap: 20px; grid-template-columns: 1fr; align-items: start; }
@media (min-width: 800px) {
  .vorlage-raster { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); }
  .foto-karte { position: sticky; top: 16px; max-height: calc(100vh - 32px); overflow: auto; }
}
.foto-karte { padding: 10px; }
.foto-karte img { display: block; width: 100%; height: auto; border-radius: 12px; }

.aufgabe { border-top: 1px solid var(--linie); padding: 16px 0; }
.aufgabe:first-child { border-top: 0; padding-top: 0; }
.aufgabe.unsicher {
  background: var(--warn-grund);
  border: 1.5px solid var(--warn-linie);
  border-radius: 14px;
  padding: 14px;
  margin: 8px 0;
}
.aufgabe-kopf { display: flex; align-items: center; justify-content: space-between; gap: 8px; flex-wrap: wrap; margin-bottom: 6px; }
.aufgabe-text { overflow-wrap: anywhere; }
.teilaufgaben { list-style: none; margin: 8px 0 0; padding: 0; }
.teilaufgaben li { display: flex; gap: 10px; padding: 4px 0; }
.teilaufgaben .bez { font-weight: 600; min-width: 1.6em; }
.teil-zeile { display: grid; grid-template-columns: 70px 1fr; gap: 8px; margin-bottom: 8px; }
.mathe-fehler { color: var(--fehler); font-family: ui-monospace, Menlo, monospace; }
.katex { font-size: 1.1em; }

.kreisel {
  width: 22px; height: 22px; border-radius: 50%;
  border: 3px solid var(--linie); border-top-color: var(--akzent);
  animation: drehen 0.8s linear infinite; display: inline-block; vertical-align: middle;
}
@keyframes drehen { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) { .kreisel { animation-duration: 3s; } }

[hidden] { display: none !important; }

/* Übungsvarianten (Elternansicht) */
.varianten { margin-top: 14px; padding-top: 12px; border-top: 1px dashed var(--linie); }
.varianten h4 { font-size: 0.98rem; margin: 0; }
.varianten h5 { font-size: 0.9rem; margin: 14px 0 6px; color: var(--text-leise); }
.variante { background: var(--grund); border-radius: 14px; padding: 12px 14px; margin-top: 10px; }
.variante.aussortiert { background: var(--fehler-grund); }
.variante.gesperrt { opacity: 0.75; }
.variante .marken { margin-bottom: 8px; }
.variante details { margin: 10px 0; }
.variante summary { cursor: pointer; color: var(--akzent); font-weight: 600; min-height: 40px; display: flex; align-items: center; }
.feld-zeile { margin-top: 10px; }
.optionen { list-style: none; margin: 8px 0 0; padding: 0; }
.optionen li { display: flex; gap: 10px; padding: 4px 8px; border-radius: 8px; }
.optionen li.richtig { background: var(--gut-grund); }
.optionen .bez { font-weight: 600; min-width: 1.6em; }
.vergleich { margin-top: 10px; }
.vergleich-raster { display: grid; grid-template-columns: 1fr; gap: 8px; }
.vergleich-spalte { background: var(--karte, #fff); border-radius: 10px; padding: 8px 12px; }
.vergleich-wert { font-size: 1.15rem; font-weight: 600; overflow-wrap: anywhere; }
.roh { white-space: pre-wrap; overflow-wrap: anywhere; font-size: 0.82rem; margin: 6px 0 0; }
@media (min-width: 520px) {
  .vergleich-raster { grid-template-columns: 1fr 1fr; }
}

/* Üben (Stufe 2b): große Touch-Ziele, richtig = grün, falsch = orange (nie rot als Strafe) */
:root { --orange: #b45f06; --orange-grund: #fff0dc; }
@media (prefers-color-scheme: dark) {
  :root { --orange: #ffb454; --orange-grund: #3a2710; }
}
.seite.schmal-mittel { max-width: 640px; }
.ueben-kacheln { display: grid; gap: 12px; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); }
.ueben-kachel {
  display: flex; flex-direction: column; gap: 6px; padding: 16px; border-radius: 16px;
  background: var(--grund); color: inherit; min-height: 150px;
}
.ueben-kachel .knopf { align-self: flex-start; margin-top: auto; }
progress { width: 100%; height: 10px; border: 0; border-radius: 5px; overflow: hidden; background: var(--linie); accent-color: var(--gut); }
progress::-webkit-progress-bar { background: var(--linie); }
progress::-webkit-progress-value { background: var(--gut); border-radius: 5px; }
progress::-moz-progress-bar { background: var(--gut); }
.fortschritt { display: grid; gap: 6px; margin-bottom: 18px; }
.ueben-text { font-size: 1.25rem; line-height: 1.5; margin-bottom: 22px; }
.eingabe-zeile { display: flex; align-items: center; justify-content: center; gap: 12px; flex-wrap: wrap; margin-bottom: 8px; }
.zahl-feld { width: 100%; max-width: 240px; min-height: 60px; font-size: 1.5rem; text-align: center; }
.einheit { font-size: 1.3rem; font-weight: 600; }
.knopf.vorzeichen { min-width: 56px; min-height: 56px; padding: 0 10px; font-size: 1.1rem; }
.bruch { display: flex; flex-direction: column; align-items: stretch; gap: 6px; width: 120px; }
.bruch .zahl-feld, .bruch-ganz .zahl-feld { max-width: none; }
.bruchstrich { height: 3px; border-radius: 2px; background: var(--text); }
.bruch-ganz { display: flex; flex-direction: column; align-items: center; gap: 4px; width: 96px; }
#kuerzen-hinweis { text-align: center; }
#antwort-formular .knopf.gross { margin-top: 10px; }
.auswahl { display: grid; gap: 12px; grid-template-columns: 1fr; }
.knopf.auswahl-knopf {
  min-height: 64px; width: 100%; font-size: 1.15rem; border-radius: 16px; justify-content: center;
  background: var(--grund); color: var(--text); border: 2px solid var(--linie);
}
.knopf.auswahl-knopf.daneben { opacity: 0.4; }
.knopf.auswahl-knopf.treffer { background: var(--gut-grund); border-color: var(--gut); color: var(--gut); opacity: 1; }
.rueckmeldung { border-radius: 14px; padding: 14px 16px; margin: 16px 0 0; font-size: 1.1rem; font-weight: 600; text-align: center; background: var(--grund); }
.rueckmeldung.richtig { background: var(--gut-grund); color: var(--gut); }
.rueckmeldung.fast { background: var(--warn-grund); color: var(--warn-text); }
.rueckmeldung.falsch { background: var(--orange-grund); color: var(--orange); }
.tipp { background: var(--warn-grund); color: var(--warn-text); border-radius: 14px; padding: 12px 16px; margin-top: 14px; }
.tipp strong { display: block; margin-bottom: 4px; }
.rechenweg, .loesung { margin-top: 16px; background: var(--grund); border-radius: 14px; padding: 12px 16px; }
.rechenweg summary { cursor: pointer; color: var(--akzent); font-weight: 600; min-height: 44px; display: flex; align-items: center; }
.loesung-ergebnis { margin-top: 12px; font-size: 1.15rem; }
#weiter { margin-top: 16px; }
.hilfe-knoepfe { margin-top: 22px; justify-content: center; }
.hilfe-knoepfe .knopf { min-height: 52px; }
.knopf-stapel { display: grid; gap: 12px; margin-top: 18px; }
a.knopf { display: inline-flex; align-items: center; justify-content: center; text-decoration: none; }
.ende-liste > li { justify-content: space-between; min-height: 52px; }
@media (min-width: 520px) { .auswahl { grid-template-columns: 1fr 1fr; } }

/* Übungsverlauf (Eltern) */
.verlauf-runde { border-top: 1px solid var(--linie); }
.verlauf-runde:first-child { border-top: 0; }
.verlauf-runde > summary { cursor: pointer; min-height: 52px; display: flex; align-items: center; justify-content: space-between; gap: 10px; flex-wrap: wrap; }
.verlauf-aufgabe { background: var(--grund); border-radius: 14px; padding: 12px 14px; margin: 0 0 10px; }
.eingaben { margin: 6px 0 0; padding-left: 1.4em; }
.eingabe-wert { font-family: ui-monospace, Menlo, monospace; }
