:root {
  color-scheme: light dark;
  --seite: #f2f2f7;
  --flaeche: #ffffff;
  --leiste: rgba(236, 236, 241, .78);
  --leiste-voll: #ececf1;
  --balken: rgba(249, 249, 251, .8);
  --text: #1c1c1e;
  --leise: #6c6c70;
  --blass: #8e8e93;
  --linie: rgba(60, 60, 67, .16);
  --feld: #f2f2f7;
  --feld-rand: rgba(60, 60, 67, .22);
  --akzent: #d70015;
  --akzent-flaeche: #d70015;
  --akzent-zart: rgba(215, 0, 21, .08);
  --loesung: #eef7f0;
  --loesung-rand: rgba(36, 138, 61, .3);
  --loesung-text: #1b6e31;
  --schatten: 0 1px 2px rgba(0, 0, 0, .05), 0 6px 20px rgba(0, 0, 0, .04);
  --schrift: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI Variable Text", "Segoe UI", system-ui, Roboto, "Helvetica Neue", Arial, sans-serif;
  --titel-schrift: -apple-system, BlinkMacSystemFont, "SF Pro Display", "Segoe UI Variable Display", "Segoe UI", system-ui, Roboto, "Helvetica Neue", Arial, sans-serif;
}

@media (prefers-color-scheme: dark) {
  :root {
    --seite: #000000;
    --flaeche: #1c1c1e;
    --leiste: rgba(36, 36, 38, .78);
    --leiste-voll: #1c1c1e;
    --balken: rgba(22, 22, 24, .8);
    --text: #f5f5f7;
    --leise: #aeaeb2;
    --blass: #8e8e93;
    --linie: rgba(235, 235, 245, .16);
    --feld: #2c2c2e;
    --feld-rand: rgba(235, 235, 245, .2);
    --akzent: #ff6961;
    --akzent-zart: rgba(255, 105, 97, .14);
    --loesung: #15281b;
    --loesung-rand: rgba(48, 209, 88, .32);
    --loesung-text: #6fdc8c;
    --schatten: none;
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
html, body { height: 100%; }
body {
  margin: 0;
  background: var(--seite);
  color: var(--text);
  font: 17px/1.45 var(--schrift);
  -webkit-font-smoothing: antialiased;
}
h1, h2, h3, p { margin: 0; }
a { color: inherit; text-decoration: none; }
code { font: .92em ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; overflow-wrap: anywhere; }
:focus-visible { outline: 3px solid var(--akzent); outline-offset: 2px; }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }
.leise { color: var(--leise); }
.laden { padding: 40vh 16px 0; text-align: center; color: var(--leise); }

/* Kacheln und Knöpfe */
.kachel {
  flex: none;
  display: grid;
  place-items: center;
  width: 30px;
  height: 30px;
  border-radius: 7px;
  background: linear-gradient(180deg, #ff4d42, #d70015);
  color: #fff;
  font: 600 16px/1 var(--titel-schrift);
}
.kachel-gross { width: 64px; height: 64px; border-radius: 15px; font-size: 34px; }
.knopf {
  appearance: none;
  border: 0;
  border-radius: 12px;
  min-height: 46px;
  padding: 10px 20px;
  background: var(--feld);
  color: var(--text);
  font: 600 17px/1.2 var(--schrift);
  cursor: pointer;
  transition: opacity .15s, transform .1s;
}
.knopf:hover { opacity: .85; }
.knopf:active { transform: scale(.98); }
.knopf-haupt { background: var(--akzent-flaeche); color: #fff; }
.knopf-still { background: transparent; color: var(--akzent); }

/* Anmeldung */
.login-seite { display: grid; place-items: center; min-height: 100dvh; padding: 16px; }
.login-karte { width: min(380px, 100%); display: flex; flex-direction: column; align-items: center; text-align: center; padding: 36px 28px; background: var(--flaeche); border-radius: 22px; box-shadow: var(--schatten); }
.login-karte h1 { margin-top: 16px; font: 700 26px/1.2 var(--titel-schrift); letter-spacing: -.01em; }
.login-karte form { width: 100%; display: flex; flex-direction: column; gap: 12px; margin-top: 24px; }
.login-karte input { width: 100%; min-height: 46px; padding: 10px 14px; border: 1px solid var(--feld-rand); border-radius: 12px; background: var(--feld); color: var(--text); font: 17px var(--schrift); }
.login-fehler { color: var(--akzent); font-size: 15px; }

/* Spalten */
.spalten { display: grid; grid-template-columns: 230px minmax(280px, 360px) minmax(0, 1fr); height: 100dvh; }
.spalten.ohne-auswahl { grid-template-columns: 230px minmax(0, 1fr); }
.spalte { min-width: 0; overflow-y: auto; -webkit-overflow-scrolling: touch; padding: max(20px, env(safe-area-inset-top)) 12px 24px; }
.spalte-1 { display: flex; flex-direction: column; background: var(--leiste); -webkit-backdrop-filter: blur(24px); backdrop-filter: blur(24px); border-right: 1px solid var(--linie); }
.spalte-2 { background: var(--flaeche); border-right: 1px solid var(--linie); }
.spalte-3 { padding-inline: 32px; }
.spalten-titel { padding: 4px 8px 14px; font: 700 28px/1.15 var(--titel-schrift); letter-spacing: -.01em; }
.spalten-titel-klein { font-size: 22px; }

.marke { display: flex; align-items: center; gap: 10px; padding: 2px 8px 20px; font: 700 17px/1.2 var(--titel-schrift); }
.zeile {
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
  min-height: 48px;
  padding: 9px 10px;
  border-radius: 10px;
  transition: background-color .12s;
}
a.zeile:hover { background: var(--linie); }
.zeile[aria-current] { background: var(--akzent-flaeche); color: #fff; }
.zeile[aria-current] .leise, .zeile[aria-current] .nummer, .zeile[aria-current] .winkel { color: rgba(255, 255, 255, .85); }
.zeile[aria-current] .kachel { background: rgba(255, 255, 255, .22); }
.zeile-text { flex: 1; min-width: 0; line-height: 1.25; overflow-wrap: break-word; -webkit-hyphens: auto; hyphens: auto; }
.zeile-text small { display: block; margin-top: 2px; font-size: 13px; color: var(--leise); }
.zeile[aria-current] .zeile-text small { color: rgba(255, 255, 255, .85); }
.nummer { flex: none; width: 36px; font: 600 15px/1.3 var(--schrift); font-variant-numeric: tabular-nums; color: var(--akzent); }
.winkel { flex: none; color: var(--blass); font-size: 20px; line-height: 1; }
.folgt { color: var(--blass); }
.folgt .nummer { color: var(--blass); }
.etikett { flex: none; font-size: 13px; color: var(--blass); }
.leiste-fuss { margin-top: auto; padding-top: 16px; }
.leiste-fuss button { width: 100%; min-height: 40px; font-size: 15px; font-weight: 500; }

/* Willkommen und leere Spalte */
.mitte { display: grid; place-content: center; justify-items: center; gap: 8px; min-height: 100%; padding: 24px; text-align: center; }
.mitte h1 { font: 700 clamp(30px, 4vw, 44px)/1.1 var(--titel-schrift); letter-spacing: -.02em; }
.mitte p { font-size: 19px; color: var(--leise); }
.mitte .tipp { margin-top: 16px; font-size: 15px; color: var(--blass); }
.mitte-klein p { font-size: 17px; color: var(--blass); }

/* Testliste */
.kopf-titel { padding: 8px 0 20px; max-width: 720px; }
.kopf-titel .ueber { font: 600 14px/1.3 var(--schrift); color: var(--akzent); }
.kopf-titel h2 { margin-top: 4px; font: 700 clamp(24px, 2.6vw, 32px)/1.15 var(--titel-schrift); letter-spacing: -.015em; overflow-wrap: anywhere; }
.gruppe { max-width: 720px; background: var(--flaeche); border-radius: 14px; box-shadow: var(--schatten); overflow: hidden; }
.gruppe > a { display: flex; align-items: center; gap: 12px; min-height: 60px; padding: 11px 16px; transition: background-color .12s; }
.gruppe > a + a { border-top: 1px solid var(--linie); }
.gruppe > a:hover { background: var(--akzent-zart); }
.gruppe > a:focus-visible { outline-offset: -3px; border-radius: 14px; }
.status { flex: none; padding: 2px 9px; border-radius: 99px; font-size: 13px; font-weight: 500; background: var(--feld); color: var(--leise); }
.status-fertig { background: var(--loesung); color: var(--loesung-text); }

/* Testseite */
.testseite { height: 100dvh; overflow-y: auto; -webkit-overflow-scrolling: touch; }
.balken {
  position: sticky;
  top: 0;
  z-index: 5;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  min-height: 52px;
  padding: max(6px, env(safe-area-inset-top)) 16px 6px;
  background: var(--balken);
  -webkit-backdrop-filter: saturate(180%) blur(20px);
  backdrop-filter: saturate(180%) blur(20px);
  border-bottom: 1px solid var(--linie);
}
.zurueck { display: inline-flex; align-items: center; gap: 2px; min-height: 40px; min-width: 0; color: var(--akzent); font-weight: 500; }
.zurueck span:last-child { overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
.zurueck .winkel { color: inherit; font-size: 26px; margin-right: 2px; }
.fortschritt { flex: none; font-size: 14px; color: var(--leise); font-variant-numeric: tabular-nums; }
.test-inhalt { max-width: 780px; margin: 0 auto; padding: 24px 16px 64px; }
.test-inhalt.mit-loesung { max-width: 1240px; }
.test-kopf { padding: 8px 4px 20px; }
.test-kopf h1 { margin-top: 4px; font: 700 clamp(26px, 3.4vw, 36px)/1.12 var(--titel-schrift); letter-spacing: -.015em; }
.test-kopf h1:focus { outline: none; }
.test-kopf .ueber { font: 600 14px/1.3 var(--schrift); color: var(--akzent); }
.test-kopf .meta { margin-top: 8px; color: var(--leise); font-size: 15px; }
.infokasten { margin-bottom: 20px; padding: 14px 16px; border-radius: 14px; background: var(--flaeche); box-shadow: var(--schatten); font-size: 15px; color: var(--leise); }
.infokasten b { color: var(--text); }

.aufgabe { margin-bottom: 16px; }
.aufgabe-karte { min-width: 0; padding: 18px; border-radius: 16px; background: var(--flaeche); box-shadow: var(--schatten); }
.aufgabe-kopf { display: flex; flex-wrap: wrap; justify-content: space-between; gap: 2px 12px; margin-bottom: 10px; font-size: 13px; color: var(--leise); }
.aufgabe-kopf b { color: var(--text); font-size: 15px; }
.aufgabe-kopf .art { flex-basis: 100%; order: 3; }
.frage { line-height: 1.5; overflow-wrap: anywhere; }
.feldbereich { margin-top: 12px; }

/* Abbildungen behalten in beiden Farbmodi ihren hellen Grund. */
.bild { display: block; width: min(100%, 520px); height: auto; margin: 14px auto 2px; padding: 8px; border-radius: 10px; background: #fff; }
.tafel { display: inline-flex; flex-direction: column; min-width: 58px; margin: 2px 4px; vertical-align: middle; border: 2px solid #111; background: #f28c1e; color: #111; font-weight: 700; text-align: center; }
.tafel span { padding: 1px 8px; }
.tafel span:first-child { border-bottom: 2px solid #111; }

/* Eingaben */
textarea, .eingabe, select {
  width: 100%;
  border: 1px solid var(--feld-rand);
  border-radius: 10px;
  background: var(--feld);
  color: var(--text);
  font: 16px/1.45 var(--schrift);
  transition: border-color .12s, box-shadow .12s;
}
textarea { display: block; padding: 10px 12px; resize: none; overflow: hidden; field-sizing: content; }
.eingabe { min-height: 40px; padding: 7px 10px; }
.eingabe-luecke { display: inline-block; width: 11em; max-width: 100%; margin: 3px 2px; min-height: 36px; padding: 4px 9px; vertical-align: baseline; }
select { min-height: 40px; padding: 7px 8px; cursor: pointer; }
textarea:focus, .eingabe:focus, select:focus { outline: none; border-color: var(--akzent); box-shadow: 0 0 0 3px var(--akzent-zart); }
:disabled { opacity: 1; -webkit-text-fill-color: currentColor; cursor: default; }

.wahlen { display: grid; gap: 8px; margin-top: 12px; }
.wahl { display: flex; align-items: flex-start; gap: 11px; min-height: 46px; padding: 10px 12px; border: 1px solid var(--feld-rand); border-radius: 12px; cursor: pointer; transition: background-color .12s, border-color .12s; }
.wahl input { flex: none; width: 20px; height: 20px; margin: 2px 0 0; accent-color: var(--akzent-flaeche); }
.wahl b { font-weight: 600; }
.wahl:has(input:checked) { border-color: var(--akzent); background: var(--akzent-zart); }
.wahl:has(input:focus-visible) { outline: 3px solid var(--akzent); outline-offset: 2px; }
.gesperrt .wahl { cursor: default; }

/* Zuordnung und Reihenfolge */
.zuordnung { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 16px; margin-top: 12px; }
.zuordnung-einfach { grid-template-columns: minmax(0, 1fr); }
.zu-zeilen { display: grid; align-content: start; gap: 8px; }
.zu-zeile { display: grid; grid-template-columns: minmax(0, 1fr) 84px; align-items: center; gap: 10px; min-height: 40px; }
.zu-zeile-vorn { grid-template-columns: 76px minmax(0, 1fr); }
.zu-text { min-width: 0; overflow-wrap: anywhere; }
.zu-optionen { align-self: start; padding: 10px 12px; border-radius: 12px; background: var(--feld); font-size: 15px; }
.zu-optionen p + p { margin-top: 6px; }
.zu-optionen b { color: var(--akzent); }

/* Tabellen zum Ausfüllen */
.tabelle-rahmen { margin-top: 12px; overflow-x: auto; -webkit-overflow-scrolling: touch; }
.tabelle-rahmen table { width: 100%; min-width: 520px; border-collapse: collapse; }
.tabelle-rahmen th, .tabelle-rahmen td { padding: 6px; border: 1px solid var(--linie); text-align: left; font-size: 15px; vertical-align: middle; }
.tabelle-rahmen textarea { min-width: 88px; padding: 6px 8px; font-size: 15px; }

/* Musterlösung neben der Antwort */
.mit-loesung .aufgabe { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 12px; }
.loesung-karte { min-width: 0; padding: 18px; border-radius: 16px; background: var(--loesung); border: 1px solid var(--loesung-rand); line-height: 1.5; overflow-wrap: anywhere; }
.loesung-karte h3 { margin-bottom: 8px; font: 600 13px/1.3 var(--schrift); color: var(--loesung-text); }
.aktion { display: flex; flex-wrap: wrap; justify-content: flex-end; gap: 8px; margin-top: 24px; padding-bottom: max(0px, env(safe-area-inset-bottom)); }
.speicher-hinweis { margin-top: 8px; text-align: center; font-size: 13px; color: var(--blass); }

/* Rückfrage */
dialog { width: min(340px, calc(100vw - 32px)); padding: 0; border: 0; border-radius: 18px; background: var(--flaeche); color: var(--text); box-shadow: 0 20px 60px rgba(0, 0, 0, .3); text-align: center; }
dialog::backdrop { background: rgba(0, 0, 0, .35); }
.frage-text { padding: 20px 18px; }
.frage-text h2 { font: 600 17px/1.3 var(--schrift); }
.frage-text p { margin-top: 6px; font-size: 14px; color: var(--leise); }
.frage-knoepfe { display: grid; grid-template-columns: 1fr 1fr; border-top: 1px solid var(--linie); }
.frage-knoepfe button { min-height: 48px; border: 0; background: none; color: var(--akzent); font: 400 17px var(--schrift); cursor: pointer; }
.frage-knoepfe button + button { border-left: 1px solid var(--linie); font-weight: 600; }

/* Fehleransicht */
.fehler-box { display: grid; gap: 14px; justify-items: center; padding: 30vh 16px 0; text-align: center; }

/* iPad hochkant: Spalten enger */
@media (max-width: 980px) {
  .spalten { grid-template-columns: 170px minmax(210px, 270px) minmax(0, 1fr); }
  .spalten.ohne-auswahl { grid-template-columns: 170px minmax(0, 1fr); }
  .spalte { padding-inline: 8px; }
  .spalte-3 { padding-inline: 16px; }
  .zeile { gap: 8px; }
  .nummer { width: 30px; }
  .etikett { font-size: 12px; }
  .marke span:last-child { font-size: 15px; }
  .spalten-titel { font-size: 22px; }
  .kopf-titel h2 { font-size: 22px; }
  .gruppe > a { padding-inline: 12px; }
}

@media (max-width: 1000px) {
  .mit-loesung .zuordnung { grid-template-columns: minmax(0, 1fr); }
}

@media (max-width: 680px) {
  .mit-loesung .aufgabe { grid-template-columns: minmax(0, 1fr); gap: 8px; }
}

/* Handy: eine Ebene pro Bildschirm */
@media (max-width: 680px) {
  .spalten, .spalten.ohne-auswahl { display: block; height: 100dvh; }
  .spalte { display: none; height: 100dvh; padding-inline: 16px; background: var(--seite); border: 0; -webkit-backdrop-filter: none; backdrop-filter: none; }
  .spalten[data-ebene="0"] .spalte-1, .spalten[data-ebene="1"] .spalte-2, .spalten[data-ebene="2"] .spalte-3 { display: flex; flex-direction: column; }
  .spalten[data-ebene="0"] .spalte-1 { background: var(--seite); }
  .spalte-3 .mitte { display: none; }
  .marke { padding-inline: 4px; }
  .spalten-titel { padding-inline: 4px; font-size: 30px; }
  .kopf-titel h2 { font-size: 28px; }
  .handy-zurueck { display: inline-flex !important; margin-bottom: 8px; }
  .liste-handy { padding: 4px; border-radius: 14px; background: var(--flaeche); }
  .zuordnung { grid-template-columns: minmax(0, 1fr); }
  .aufgabe-karte, .loesung-karte { padding: 14px; }
  .aktion { justify-content: stretch; }
  .aktion .knopf { flex: 1 1 100%; }
}
.handy-zurueck { display: none; }

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; }
}
