:root {
  color-scheme: light dark;
  --grund: #f3f5f8; --flaeche: #ffffff; --linie: #dfe4ea; --text: #1f2933; --leise: #5c6875;
  --leiste: #1d3547; --leiste-aktiv: #2a4a60; --leiste-text: #c9d6df;
  --akzent: #2a6f97; --akzent-dunkel: #215a7b; --akzent-hell: #e3f0f7; --auf-akzent: #ffffff;
  --gruen: #237a4b; --gruen-hell: #dcf2e4; --rot: #b83227; --rot-hell: #fbe2df; --stern: #8f6300;
  --fach0: #dde2e8; --fach1: #d9534f; --fach2: #f0a13c; --fach3: #e9cf4a; --fach4: #93cf72; --fach5: #2f9e5b;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --grund: #12181f; --flaeche: #1c242d; --linie: #323d49; --text: #e7ecf1; --leise: #a3afbc;
    --leiste: #0d1319; --leiste-aktiv: #24313d; --leiste-text: #b6c3cf;
    --akzent: #5aa9d6; --akzent-dunkel: #7cbde2; --akzent-hell: #1f3a4c; --auf-akzent: #0d1319;
    --gruen: #5cc98b; --gruen-hell: #173a28; --rot: #f0837a; --rot-hell: #48201d; --stern: #e8bb55;
    --fach0: #46525f;
  }
}
:root[data-theme="dark"] {
  --grund: #12181f; --flaeche: #1c242d; --linie: #323d49; --text: #e7ecf1; --leise: #a3afbc;
  --leiste: #0d1319; --leiste-aktiv: #24313d; --leiste-text: #b6c3cf;
  --akzent: #5aa9d6; --akzent-dunkel: #7cbde2; --akzent-hell: #1f3a4c; --auf-akzent: #0d1319;
  --gruen: #5cc98b; --gruen-hell: #173a28; --rot: #f0837a; --rot-hell: #48201d; --stern: #e8bb55;
  --fach0: #46525f;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--grund); color: var(--text);
  font: 16px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}
button, input, select { font: inherit; color: inherit; }
button { cursor: pointer; touch-action: manipulation; -webkit-tap-highlight-color: transparent; }
h1 { font-size: 30px; line-height: 1.2; margin: 0; }
h2 { font-size: 18px; margin: 0 0 12px; }
.leise { color: var(--leise); }
.klein { font-size: 14px; }
.fett { font-weight: 650; }

/* Gerüst */
.geruest { display: flex; min-height: 100vh; min-height: 100dvh; }
.leiste {
  background: var(--leiste); color: var(--leiste-text); width: 210px; flex: none;
  display: flex; flex-direction: column;
  padding: max(24px, env(safe-area-inset-top)) 0 max(16px, env(safe-area-inset-bottom)) env(safe-area-inset-left);
  position: sticky; top: 0; height: 100vh; height: 100dvh;
}
.marke { padding: 0 20px 22px; }
.marke b { display: block; color: #fff; font-size: 22px; }
.marke span { font-size: 14px; }
.nav { display: flex; flex-direction: column; }
.nav button, .abmelden {
  background: none; border: 0; color: inherit; text-align: left; padding: 11px 20px; min-height: 44px; white-space: nowrap;
}
.nav button.aktiv { background: var(--leiste-aktiv); color: #fff; }
.menue { display: flex; flex-direction: column; flex: 1; }
.menue-knopf, .menue-schleier { display: none; }
.abmelden { margin-top: auto; display: flex; flex-direction: column; justify-content: center; }
.abmelden-name { font-size: 13px; opacity: .75; }
.inhalt {
  flex: 1; min-width: 0; max-width: 1120px; margin: 0 auto;
  padding: max(24px, env(safe-area-inset-top)) max(28px, env(safe-area-inset-right)) max(28px, env(safe-area-inset-bottom)) 28px;
}
.im-test .leiste { display: none; }
.im-test .inhalt { display: flex; flex-direction: column; min-height: 100dvh; max-width: 860px; width: 100%; }

@media (max-width: 899px) {
  .geruest { flex-direction: column; }
  .leiste {
    width: 100%; height: auto; display: block; z-index: 30;
    padding: env(safe-area-inset-top) max(8px, env(safe-area-inset-right)) 0 max(16px, env(safe-area-inset-left));
    box-shadow: 0 1px 0 rgba(0, 0, 0, .25);
  }
  .kopfzeile { display: flex; align-items: center; justify-content: space-between; gap: 12px; min-height: 56px; }
  .marke { padding: 0; min-width: 0; }
  .marke b { font-size: 18px; line-height: 1.2; }
  .marke span { display: block; font-size: 12px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
  .menue-knopf {
    display: inline-flex; align-items: center; gap: 10px; flex: none;
    background: var(--leiste-aktiv); color: #fff; border: 0; border-radius: 10px;
    padding: 8px 14px; min-height: 42px; font-weight: 600; max-width: 60vw;
  }
  .menue-titel { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .pfeil {
    width: 8px; height: 8px; flex: none; border: solid currentColor; border-width: 0 2px 2px 0;
    transform: translateY(-2px) rotate(45deg); transition: transform .2s;
  }
  .leiste.offen .pfeil { transform: translateY(2px) rotate(-135deg); }
  .menue {
    position: absolute; top: 100%; right: max(8px, env(safe-area-inset-right)); left: auto;
    width: min(280px, calc(100vw - 16px)); margin-top: 6px; padding: 6px;
    background: var(--flaeche); color: var(--text); border: 1px solid var(--linie); border-radius: 14px;
    box-shadow: 0 12px 32px rgba(0, 0, 0, .22);
    max-height: calc(100dvh - 80px); overflow-y: auto;
    opacity: 0; visibility: hidden; transform: translateY(-6px) scale(.98); transform-origin: top right;
    transition: opacity .15s, transform .15s, visibility 0s .15s;
  }
  .leiste.offen .menue { opacity: 1; visibility: visible; transform: none; transition: opacity .15s, transform .15s; }
  .nav button, .abmelden { padding: 12px 14px; min-height: 48px; border-radius: 9px; width: 100%; }
  .nav button.aktiv { background: var(--akzent-hell); color: var(--akzent-dunkel); font-weight: 650; }
  .abmelden {
    margin: 6px 0 0; border-top: 1px solid var(--linie); border-radius: 0 0 9px 9px;
    flex-direction: row; justify-content: space-between; align-items: center; color: var(--rot);
  }
  .abmelden-name { color: var(--leise); opacity: 1; }
  .leiste.offen ~ .menue-schleier {
    display: block; position: fixed; inset: 0; z-index: 20; background: rgba(0, 0, 0, .25);
  }
  .inhalt { width: 100%; padding: 20px 16px max(24px, env(safe-area-inset-bottom)); }
  .im-test .inhalt { padding-top: max(20px, env(safe-area-inset-top)); }
}

.kopf { margin-bottom: 16px; }
.karte { background: var(--flaeche); border: 1px solid var(--linie); border-radius: 12px; padding: 16px 18px; margin-bottom: 12px; }

/* Knöpfe und Felder */
.knopf {
  border: 1px solid var(--linie); background: var(--flaeche); border-radius: 9px;
  padding: 9px 16px; min-height: 44px; font-weight: 600;
}
.knopf.haupt { background: var(--akzent); border-color: var(--akzent); color: var(--auf-akzent); }
.knopf.klein { padding: 4px 12px; min-height: 36px; font-size: 14px; }
.reihe { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.zwischen { justify-content: space-between; }
input[type=text], input[type=search], input[type=password], input[type=number], select {
  background: var(--flaeche); border: 1px solid var(--linie); border-radius: 9px;
  padding: 9px 11px; min-height: 44px; font-size: 16px; max-width: 100%;
}
.form-zeile { display: grid; grid-template-columns: 90px minmax(0, 1fr); gap: 10px; align-items: center; margin-bottom: 10px; }
.form-zeile select { width: 100%; }
.form-zeile input[type=number] { width: 84px; }
.haken { display: flex; gap: 10px; align-items: center; min-height: 40px; }
.haken input { width: 20px; height: 20px; accent-color: var(--akzent); flex: none; }
.meldung { color: var(--rot); margin: 8px 0 0; min-height: 1.4em; font-size: 14px; }

/* Übersicht */
.kacheln { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 10px; margin-bottom: 10px; }
.kacheln .karte { margin: 0; }
.zahl { font-size: 32px; font-weight: 700; line-height: 1.2; }
.spalten { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; align-items: start; }
@media (max-width: 899px) { .spalten { grid-template-columns: minmax(0, 1fr); gap: 0; } }
@media (max-width: 560px) { .kacheln { grid-template-columns: minmax(0, 1fr); } }
.fachbalken { display: flex; gap: 2px; height: 16px; }
.fachbalken i { display: block; min-width: 4px; border-radius: 4px; }
.legende { display: flex; flex-wrap: wrap; gap: 4px 14px; margin-top: 10px; font-size: 14px; }
.legende span { display: inline-flex; align-items: center; gap: 5px; }
.farbfeld { width: 11px; height: 11px; border-radius: 3px; display: inline-block; flex: none; }
.f0 { background: var(--fach0); } .f1 { background: var(--fach1); } .f2 { background: var(--fach2); }
.f3 { background: var(--fach3); } .f4 { background: var(--fach4); } .f5 { background: var(--fach5); }
.fortschritt { display: grid; grid-template-columns: minmax(0, 1.2fr) minmax(50px, 1fr) 46px 62px 70px; gap: 6px 10px; align-items: center; }
.fortschritt.ohne-knopf { grid-template-columns: minmax(0, 1.2fr) minmax(50px, 1fr) 46px 62px; }
.spur { height: 8px; background: var(--linie); border-radius: 4px; overflow: hidden; }
.spur i { display: block; height: 100%; background: var(--akzent); border-radius: 4px; }
.ueberschrift2 { margin-top: 18px; margin-bottom: 2px; }

/* Lernrunde */
.frage-kopf { display: flex; justify-content: space-between; align-items: center; gap: 12px; }
.stern { background: none; border: 0; color: var(--stern); min-height: 44px; padding: 0 0 0 12px; white-space: nowrap; }
.balken { height: 6px; background: var(--linie); border-radius: 3px; overflow: hidden; margin: 6px 0 20px; }
.balken i { display: block; height: 100%; background: var(--akzent); }
.fragetext { font-size: 22px; font-weight: 650; line-height: 1.35; margin: 0 0 18px; }
.antwort {
  display: flex; width: 100%; align-items: center; gap: 12px; text-align: left; margin-bottom: 8px;
  background: var(--flaeche); border: 2px solid var(--linie); border-radius: 12px; padding: 12px 14px; min-height: 60px; font-size: 18px;
}
.antwort .kennung {
  flex: none; width: 34px; height: 34px; border-radius: 8px; display: grid; place-items: center;
  background: var(--grund); color: var(--leise); font-weight: 700; font-size: 16px;
}
.antwort .inhalt-text { flex: 1; min-width: 0; }
.antwort .status { flex: none; font-weight: 700; font-size: 15px; }
.antwort.gewaehlt { background: var(--akzent-hell); border-color: var(--akzent); }
.antwort.gewaehlt .kennung { background: var(--akzent); color: var(--auf-akzent); }
.antwort.richtig { background: var(--gruen-hell); border-color: var(--gruen); }
.antwort.richtig .kennung { background: var(--gruen); color: var(--flaeche); }
.antwort.richtig .status { color: var(--gruen); }
.antwort.falsch { background: var(--rot-hell); border-color: var(--rot); }
.antwort.falsch .kennung { background: var(--rot); color: var(--flaeche); }
.antwort.falsch .status { color: var(--rot); }
.rueckmeldung { margin: 10px 0 0; min-height: 1.4em; color: var(--leise); font-size: 15px; }
.fuss {
  position: sticky; bottom: 0; margin-top: auto; padding: 14px 0 max(4px, env(safe-area-inset-bottom));
  background: var(--grund); display: flex; justify-content: space-between; gap: 10px; align-items: center;
}
.fuss .knopf.haupt { min-width: 150px; min-height: 52px; font-size: 18px; }
@media (hover: hover) {
  .knopf:hover { filter: brightness(.96); }
  .antwort:not(.richtig):not(.falsch):not(.gewaehlt):hover { border-color: var(--akzent); }
  .zeile:hover, .runde-zeile:hover { background: var(--akzent-hell); }
  .nav button:hover, .abmelden:hover { background: var(--leiste-aktiv); }
}
@media (hover: hover) and (max-width: 899px) {
  .nav button:not(.aktiv):hover, .abmelden:hover { background: var(--grund); }
}
@media (max-width: 899px) {
  h1 { font-size: 25px; }
  .karte { padding: 14px 15px; }
  .zahl { font-size: 28px; }
  .fragetext { font-size: 20px; }
  .antwort { font-size: 17px; }
}

/* Ergebnis */
.falsche h3 { font-size: 17px; margin: 0 0 4px; }
.falsche > div { padding: 12px 0; border-bottom: 1px solid var(--linie); }
.falsche > div:last-child { border: 0; }
.txt-richtig { color: var(--gruen); }
.txt-falsch { color: var(--rot); }

/* Verlauf */
.diagramm { position: relative; height: 200px; }
.diagramm svg { display: block; width: 100%; height: 100%; touch-action: pan-y; }
.diagramm .gitter { stroke: var(--linie); stroke-width: 1; }
.diagramm .achse { fill: var(--leise); font-size: 12px; }
.diagramm .kurve { fill: none; stroke: var(--akzent); stroke-width: 2; stroke-linejoin: round; stroke-linecap: round; }
.diagramm .punkt { fill: var(--akzent); stroke: var(--flaeche); stroke-width: 2; }
.diagramm .fadenkreuz { stroke: var(--leise); stroke-dasharray: 2 2; }
.tooltip {
  position: absolute; background: var(--text); color: var(--grund); font-size: 14px; font-weight: 600;
  padding: 3px 8px; border-radius: 6px; white-space: nowrap; pointer-events: none;
}
.runden { padding: 4px; overflow-x: auto; }
.runde-zeile, .runde-kopf {
  display: grid; grid-template-columns: minmax(150px, 2fr) repeat(var(--spalten, 5), minmax(62px, 1fr)); gap: 8px; align-items: center;
  width: 100%; min-width: 560px; padding: 10px 12px; text-align: left; font-size: 15px;
}
.runde-kopf { color: var(--leise); font-weight: 650; font-size: 14px; border-bottom: 1px solid var(--linie); }
.runde-zeile { background: none; border: 0; border-bottom: 1px solid var(--linie); min-height: 44px; }
.runde-zeile:last-child { border: 0; }

/* Listen */
.liste { padding: 4px; }
.zeile {
  display: grid; grid-template-columns: 112px 22px minmax(0, 1fr) 84px 52px; gap: 10px; align-items: center;
  width: 100%; background: none; border: 0; border-bottom: 1px solid var(--linie);
  padding: 10px 12px; min-height: 48px; text-align: left; font-size: 15px;
}
.zeile.offen { background: var(--akzent-hell); }
.fachname { display: inline-flex; gap: 6px; align-items: center; font-size: 14px; }
.zeile .stern-zelle { color: var(--stern); }
@media (max-width: 640px) {
  .zeile { grid-template-columns: 22px minmax(0, 1fr) 46px; }
  .zeile .fachname, .zeile .kat-zelle { display: none; }
}
.detail { padding: 14px 16px; border-bottom: 1px solid var(--linie); background: var(--grund); }
.detail .frage { font-weight: 650; margin: 0 0 8px; }
.detail ul { list-style: none; margin: 0 0 8px; padding: 0; }
.detail li { padding: 2px 0 2px 22px; text-indent: -22px; }
.detail li.richtig { color: var(--gruen); font-weight: 650; }
.filter { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 10px; align-items: center; }
.filter input[type=search] { flex: 1 1 220px; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 10px; }
.chip { border: 0; background: var(--linie); border-radius: 18px; padding: 7px 14px; min-height: 40px; font-size: 15px; }
.chip.aktiv { background: var(--akzent); color: var(--auf-akzent); }

/* Konto */
.formular { align-items: flex-start; }
.formular input[type=text], .formular input[type=password] { flex: 1 1 180px; }
.formular .meldung { flex-basis: 100%; margin: 0; }
.meldung.ok { color: var(--gruen); }
.knopf.gefahr { color: var(--rot); }
.nutzer-kopf, .nutzer-zeile {
  display: grid; grid-template-columns: minmax(0, 2fr) 90px 100px 190px; gap: 10px; align-items: center; padding: 10px 12px;
}
.nutzer-zeile > .reihe { justify-content: flex-end; }
.nutzer-kopf { color: var(--leise); font-weight: 650; font-size: 14px; border-bottom: 1px solid var(--linie); }
.nutzer-block { border-bottom: 1px solid var(--linie); }
.nutzer-block:last-child { border: 0; }
.nutzer-block > .formular { padding: 0 12px 12px; }
@media (max-width: 640px) {
  .nutzer-kopf { display: none; }
  .nutzer-zeile { grid-template-columns: minmax(0, 1fr) auto; }
  .nutzer-zeile > :nth-child(2), .nutzer-zeile > :nth-child(3) { display: none; }
}

/* Anmeldung und Status */
.anmeldung { min-height: 100vh; min-height: 100dvh; display: grid; place-items: center; padding: 16px; }
.anmeldung form { width: min(380px, 100%); }
.anmeldung label { display: block; margin-bottom: 12px; font-size: 15px; }
.anmeldung input { display: block; width: 100%; margin-top: 4px; }
.anmeldung .knopf { width: 100%; }
.wechsel { display: block; width: 100%; background: none; border: 0; color: var(--akzent); padding: 10px; min-height: 44px; font-size: 15px; }
#sync {
  position: fixed; right: 12px; bottom: max(12px, env(safe-area-inset-bottom)); z-index: 20;
  background: var(--text); color: var(--grund); padding: 6px 12px; border-radius: 16px; font-size: 14px;
}
