/* ── Farben & Grundlagen ─────────────────────────────────────────────────── */
:root {
  --bg: #f3f5fa;
  --flaeche: #ffffff;
  --flaeche-2: #f7f8fc;
  --text: #172033;
  --gedimmt: #5d6679;
  --rand: #e1e5ee;
  --primaer: #2f5bea;
  --primaer-text: #ffffff;
  --primaer-hell: #e9eefe;
  --ok: #188a52;
  --ok-hell: #e2f5ea;
  --fehler: #cf3434;
  --fehler-hell: #fdeaea;
  --warn: #b26b00;
  --warn-hell: #fff3dc;
  --schatten: 0 1px 2px rgba(20, 30, 60, .06), 0 4px 16px rgba(20, 30, 60, .06);
  --radius: 14px;
  --radius-klein: 10px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="hell"]) {
    --bg: #0e131b; --flaeche: #171e29; --flaeche-2: #1c2431; --text: #e6ebf3; --gedimmt: #98a3b6; --rand: #2a3443;
    --primaer: #6f8dff; --primaer-text: #0b1020; --primaer-hell: #1e2847; --ok: #4cc98a; --ok-hell: #133222;
    --fehler: #ff7a7a; --fehler-hell: #3b1b1d; --warn: #f0b049; --warn-hell: #3a2c12;
    --schatten: 0 1px 2px rgba(0, 0, 0, .3), 0 6px 20px rgba(0, 0, 0, .25);
    color-scheme: dark;
  }
}
:root[data-theme="dunkel"] {
  --bg: #0e131b; --flaeche: #171e29; --flaeche-2: #1c2431; --text: #e6ebf3; --gedimmt: #98a3b6; --rand: #2a3443;
  --primaer: #6f8dff; --primaer-text: #0b1020; --primaer-hell: #1e2847; --ok: #4cc98a; --ok-hell: #133222;
  --fehler: #ff7a7a; --fehler-hell: #3b1b1d; --warn: #f0b049; --warn-hell: #3a2c12;
  --schatten: 0 1px 2px rgba(0, 0, 0, .3), 0 6px 20px rgba(0, 0, 0, .25);
  color-scheme: dark;
}

*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  font: 16px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
}
h1, h2, h3 { line-height: 1.25; margin: 0 0 .5rem; }
h1 { font-size: 1.6rem; }
h2 { font-size: 1.25rem; }
h3 { font-size: 1.05rem; }
p { margin: 0 0 .75rem; }
a { color: var(--primaer); }
button, input, select, textarea { font: inherit; color: inherit; }
.gedimmt { color: var(--gedimmt); }
.klein { font-size: .875rem; }
.versteckt { display: none !important; }

/* ── Layout ──────────────────────────────────────────────────────────────── */
.kopf {
  position: sticky; top: 0; z-index: 20;
  background: color-mix(in srgb, var(--flaeche) 88%, transparent);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--rand);
}
.kopf-innen {
  max-width: 1000px; margin: 0 auto; padding: .7rem 1rem;
  display: flex; align-items: center; gap: 1rem;
}
.logo { font-weight: 700; font-size: 1.05rem; text-decoration: none; color: var(--text); display: flex; align-items: center; gap: .5rem; margin-right: auto; }
.logo-zeichen { width: 30px; height: 30px; border-radius: 8px; background: var(--primaer); color: var(--primaer-text); display: grid; place-items: center; font-size: .9rem; font-weight: 800; }
.nav { display: flex; gap: .25rem; }
.nav a {
  display: flex; align-items: center; gap: .4rem;
  text-decoration: none; color: var(--gedimmt); padding: .45rem .75rem; border-radius: 999px; font-size: .95rem; font-weight: 500;
}
.nav a:hover { background: var(--flaeche-2); color: var(--text); }
.nav a.aktiv { background: var(--primaer-hell); color: var(--primaer); }
.nav svg { width: 20px; height: 20px; }

main { max-width: 1000px; margin: 0 auto; padding: 1.25rem 1rem 6rem; }

@media (max-width: 760px) {
  /* backdrop-filter würde position: fixed der Navigationsleiste an den Kopf binden */
  .kopf { backdrop-filter: none; background: var(--flaeche); }
  .kopf .nav {
    position: fixed; bottom: 0; left: 0; right: 0; z-index: 30;
    background: var(--flaeche); border-top: 1px solid var(--rand);
    justify-content: space-around; padding: .3rem .25rem calc(.3rem + env(safe-area-inset-bottom));
  }
  .kopf .nav a { flex-direction: column; gap: .1rem; font-size: .7rem; padding: .35rem .5rem; border-radius: 10px; min-width: 60px; }
  .kopf .nav a.aktiv { background: none; }
  main { padding-bottom: 6.5rem; }
  h1 { font-size: 1.35rem; }
}

/* ── Bausteine ───────────────────────────────────────────────────────────── */
.karte {
  background: var(--flaeche); border: 1px solid var(--rand); border-radius: var(--radius);
  padding: 1.1rem 1.2rem; box-shadow: var(--schatten);
}
.karte + .karte, .abschnitt + .abschnitt { margin-top: 1rem; }
.abschnitt { margin-top: 1.75rem; }
.abschnitt-kopf { display: flex; align-items: baseline; gap: .75rem; flex-wrap: wrap; margin-bottom: .75rem; }
.abschnitt-kopf h2 { margin: 0; }
.abschnitt-kopf .rechts { margin-left: auto; display: flex; gap: .5rem; flex-wrap: wrap; }
.raster { display: grid; gap: .85rem; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); }
.raster.kompakt { grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); }
.zeile { display: flex; gap: .6rem; align-items: center; flex-wrap: wrap; }
.stapel > * + * { margin-top: .75rem; }
.zurueck { display: inline-flex; align-items: center; gap: .3rem; color: var(--gedimmt); text-decoration: none; font-size: .95rem; margin-bottom: .75rem; }
.zurueck:hover { color: var(--text); }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: .45rem;
  border: 1px solid var(--rand); background: var(--flaeche); color: var(--text);
  padding: .6rem 1rem; border-radius: var(--radius-klein); font-weight: 600; font-size: .95rem;
  cursor: pointer; text-decoration: none; transition: background .15s, border-color .15s, transform .05s;
  min-height: 44px;
}
.btn:hover { background: var(--flaeche-2); }
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: .55; cursor: not-allowed; }
.btn-primaer { background: var(--primaer); border-color: var(--primaer); color: var(--primaer-text); }
.btn-primaer:hover { background: color-mix(in srgb, var(--primaer) 88%, black); }
.btn-gefahr { color: var(--fehler); }
.btn-gefahr:hover { background: var(--fehler-hell); border-color: var(--fehler); }
.btn-klein { padding: .3rem .65rem; min-height: 34px; font-size: .85rem; }
.btn-gross { padding: .85rem 1.4rem; font-size: 1.05rem; }
.btn-breit { width: 100%; }
.btn-text { border: none; background: none; color: var(--primaer); padding: .3rem .4rem; min-height: 0; }
.btn-text:hover { background: var(--primaer-hell); }

.chip { display: inline-flex; align-items: center; gap: .3rem; font-size: .78rem; font-weight: 600; padding: .15rem .55rem; border-radius: 999px; background: var(--flaeche-2); color: var(--gedimmt); border: 1px solid var(--rand); }
.chip-primaer { background: var(--primaer-hell); color: var(--primaer); border-color: transparent; }
.chip-ok { background: var(--ok-hell); color: var(--ok); border-color: transparent; }
.chip-warn { background: var(--warn-hell); color: var(--warn); border-color: transparent; }
.chip-fehler { background: var(--fehler-hell); color: var(--fehler); border-color: transparent; }

.balken { height: 8px; background: var(--flaeche-2); border: 1px solid var(--rand); border-radius: 999px; overflow: hidden; }
.balken > div { height: 100%; background: var(--ok); border-radius: 999px; transition: width .4s; }
.balken.primaer > div { background: var(--primaer); }

/* Formulare */
label.feld { display: block; }
label.feld > span { display: block; font-size: .875rem; font-weight: 600; margin-bottom: .3rem; }
input[type=text], input[type=password], input[type=number], input[type=date], select, textarea {
  width: 100%; padding: .6rem .75rem; border: 1px solid var(--rand); border-radius: var(--radius-klein);
  background: var(--flaeche); min-height: 44px;
}
textarea { min-height: 90px; resize: vertical; }
input:focus-visible, select:focus-visible, textarea:focus-visible, .btn:focus-visible, a:focus-visible, .antwort:focus-visible, .lernkarte:focus-visible {
  outline: 3px solid color-mix(in srgb, var(--primaer) 45%, transparent); outline-offset: 1px;
}
.formular-raster { display: grid; gap: .8rem; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); }
.meldung { padding: .7rem .9rem; border-radius: var(--radius-klein); font-size: .95rem; }
.meldung-fehler { background: var(--fehler-hell); color: var(--fehler); }
.meldung-ok { background: var(--ok-hell); color: var(--ok); }
.meldung-info { background: var(--primaer-hell); color: var(--primaer); }
.meldung-warn { background: var(--warn-hell); color: var(--warn); }

.leer { text-align: center; padding: 2.5rem 1rem; color: var(--gedimmt); }
.leer .gross { font-size: 2.5rem; margin-bottom: .5rem; }

/* Tabs */
.tabs { display: flex; gap: .25rem; border-bottom: 1px solid var(--rand); margin-bottom: 1rem; overflow-x: auto; }
.tabs button, .tabs a {
  border: none; background: none; padding: .6rem .9rem; cursor: pointer; color: var(--gedimmt); font-weight: 600;
  border-bottom: 2px solid transparent; margin-bottom: -1px; white-space: nowrap; text-decoration: none;
}
.tabs .aktiv { color: var(--primaer); border-bottom-color: var(--primaer); }

/* Tabelle */
.tabelle-huelle { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: .93rem; }
th, td { text-align: left; padding: .6rem .5rem; border-bottom: 1px solid var(--rand); vertical-align: middle; }
th { font-size: .8rem; color: var(--gedimmt); font-weight: 600; text-transform: uppercase; letter-spacing: .03em; }
td.zahl, th.zahl { text-align: right; font-variant-numeric: tabular-nums; }

/* ── Startseite ──────────────────────────────────────────────────────────── */
.held {
  background: linear-gradient(135deg, var(--primaer), color-mix(in srgb, var(--primaer) 60%, #7b3fe4));
  color: #fff; border: none; padding: 1.5rem 1.4rem;
}
.held h1 { color: #fff; }
.held p { color: rgba(255, 255, 255, .88); }
.held .btn { background: #fff; color: #1d3bb3; border-color: #fff; }
.held .btn:hover { background: #eef2ff; }
.held .balken { background: rgba(255, 255, 255, .25); border-color: transparent; }
.held .balken > div { background: #fff; }
.held-zahlen { display: flex; gap: 1.5rem; flex-wrap: wrap; margin: .5rem 0 1.1rem; }
.held-zahlen b { display: block; font-size: 1.5rem; line-height: 1.1; }
.held-zahlen span { font-size: .82rem; opacity: .85; }

.thema-kachel { display: flex; flex-direction: column; gap: .6rem; text-decoration: none; color: inherit; transition: transform .1s, border-color .15s; }
.thema-kachel:hover { border-color: var(--primaer); transform: translateY(-1px); }
.thema-kachel h3 { margin: 0; }
.thema-kachel .zeile { justify-content: space-between; }

/* ── Quiz ────────────────────────────────────────────────────────────────── */
.quiz { max-width: 720px; margin: 0 auto; }
.quiz-kopf { display: flex; align-items: center; gap: .75rem; margin-bottom: 1rem; }
.quiz-kopf .balken { flex: 1; }
.frage-text { font-size: 1.2rem; font-weight: 600; margin: .4rem 0 1.1rem; white-space: pre-wrap; }
.antworten { display: grid; gap: .6rem; }
.antwort {
  display: flex; gap: .8rem; align-items: flex-start; text-align: left; width: 100%;
  padding: .85rem 1rem; border: 2px solid var(--rand); border-radius: var(--radius); background: var(--flaeche);
  cursor: pointer; font-size: 1rem; transition: border-color .15s, background .15s;
}
.antwort:hover:not(:disabled) { border-color: var(--primaer); }
.antwort:disabled { cursor: default; }
.antwort .buchstabe {
  flex: none; width: 28px; height: 28px; border-radius: 8px; display: grid; place-items: center;
  background: var(--flaeche-2); border: 1px solid var(--rand); font-weight: 700; font-size: .85rem;
}
.antwort.richtig { border-color: var(--ok); background: var(--ok-hell); }
.antwort.richtig .buchstabe { background: var(--ok); color: #fff; border-color: var(--ok); }
.antwort.falsch { border-color: var(--fehler); background: var(--fehler-hell); }
.antwort.falsch .buchstabe { background: var(--fehler); color: #fff; border-color: var(--fehler); }
.antwort.blass { opacity: .6; }
.erklaerung { margin-top: 1rem; border-left: 4px solid var(--primaer); background: var(--flaeche-2); padding: .8rem 1rem; border-radius: 0 var(--radius-klein) var(--radius-klein) 0; }
.quiz-fuss { display: flex; justify-content: flex-end; gap: .6rem; margin-top: 1.1rem; }
.antwort-text { flex: 1; }
.antwort-mehrfach .urteil { flex: none; font-size: .78rem; font-weight: 600; color: var(--gedimmt); padding-top: .25rem; white-space: nowrap; }
.antwort-mehrfach.markiert { border-color: var(--primaer); background: var(--flaeche-2); }
.antwort-mehrfach.markiert .buchstabe { background: var(--primaer); color: #fff; border-color: var(--primaer); }
.antwort-mehrfach.markiert .urteil { color: var(--primaer); }
.antwort-mehrfach.richtig .urteil { color: var(--ok); }
.antwort-mehrfach.falsch .urteil { color: var(--fehler); }
.antwort-mehrfach .urteil small { display: block; font-weight: 500; text-align: right; }
.erklaerung .inhalt-text p { margin: .5rem 0 0; }
.skizze { margin: .8rem 0 .2rem; padding: .6rem; background: #fff; border: 1px solid var(--rand); border-radius: var(--radius-klein); text-align: center; }
.skizze img { max-width: 100%; height: auto; max-height: 420px; }
.ergebnis-kreis {
  width: 140px; height: 140px; border-radius: 50%; margin: .5rem auto 1rem; display: grid; place-items: center;
  font-size: 2rem; font-weight: 800;
}
.ergebnis-kreis span { width: 112px; height: 112px; border-radius: 50%; background: var(--flaeche); display: grid; place-items: center; }

/* ── Karteikarten ────────────────────────────────────────────────────────── */
.lernkarte-buehne { perspective: 1400px; max-width: 680px; margin: 0 auto; }
.lernkarte {
  position: relative; width: 100%; min-height: 320px; cursor: pointer; border: none; padding: 0; background: none; text-align: left;
  transform-style: preserve-3d; transition: transform .45s cubic-bezier(.2, .7, .3, 1); display: block;
}
.lernkarte.umgedreht { transform: rotateY(180deg); }
.lernkarte .seite {
  position: absolute; inset: 0; backface-visibility: hidden; -webkit-backface-visibility: hidden;
  background: var(--flaeche); border: 1px solid var(--rand); border-radius: 18px; box-shadow: var(--schatten);
  padding: 1.6rem 1.5rem; display: flex; flex-direction: column; overflow-y: auto;
}
.lernkarte .vorne { justify-content: center; align-items: center; text-align: center; }
.lernkarte .vorne .titel { font-size: 1.4rem; font-weight: 700; }
.lernkarte .hinten { transform: rotateY(180deg); }
.lernkarte .hinweis { position: absolute; bottom: .8rem; left: 0; right: 0; text-align: center; font-size: .8rem; color: var(--gedimmt); }
.karten-steuerung { display: flex; justify-content: center; align-items: center; gap: .75rem; margin-top: 1rem; }
.karten-liste .karte h3 { margin-bottom: .4rem; }
.inhalt-text ul { margin: .25rem 0 .5rem; padding-left: 1.2rem; }
.inhalt-text p { margin: 0 0 .5rem; }
.quelle { font-size: .8rem; color: var(--gedimmt); margin-top: .6rem; }

/* ── Admin ───────────────────────────────────────────────────────────────── */
.eintrag { display: flex; gap: .8rem; align-items: flex-start; }
.eintrag + .eintrag { border-top: 1px solid var(--rand); padding-top: .9rem; margin-top: .9rem; }
.eintrag input[type=checkbox] { width: 20px; height: 20px; margin-top: .2rem; flex: none; }
.eintrag .inhalt { flex: 1; min-width: 0; }
.eintrag .aktionen { display: flex; gap: .3rem; flex-wrap: wrap; flex: none; }
.antwort-liste { list-style: none; padding: 0; margin: .4rem 0; font-size: .93rem; }
.antwort-liste li { padding: .15rem 0 .15rem 1.4rem; position: relative; }
.antwort-liste li::before { content: "○"; position: absolute; left: 0; color: var(--gedimmt); }
.antwort-liste li.ist-richtig { color: var(--ok); font-weight: 600; }
.antwort-liste li.ist-richtig::before { content: "✓"; color: var(--ok); }
.leiste { position: sticky; top: 62px; z-index: 5; background: var(--flaeche); border: 1px solid var(--rand); border-radius: var(--radius-klein); padding: .5rem .7rem; margin-bottom: .8rem; }
.job { padding: .75rem .9rem; border-radius: var(--radius-klein); background: var(--flaeche-2); border: 1px solid var(--rand); }
.job + .job { margin-top: .5rem; }
.dropzone { border: 2px dashed var(--rand); border-radius: var(--radius); padding: 1.2rem; text-align: center; }
.dropzone.drueber { border-color: var(--primaer); background: var(--primaer-hell); }

/* ── Dialog & Hinweise ───────────────────────────────────────────────────── */
dialog {
  border: none; border-radius: 18px; padding: 0; width: min(620px, calc(100vw - 2rem)); max-height: calc(100vh - 2rem);
  background: var(--flaeche); color: var(--text); box-shadow: 0 20px 60px rgba(0, 0, 0, .3);
}
dialog::backdrop { background: rgba(10, 15, 25, .5); }
.dialog-kopf { padding: 1.1rem 1.3rem .2rem; }
.dialog-inhalt { padding: .6rem 1.3rem; }
.dialog-fuss { padding: .8rem 1.3rem 1.2rem; display: flex; justify-content: flex-end; gap: .5rem; flex-wrap: wrap; }

.toasts { position: fixed; left: 50%; bottom: 90px; transform: translateX(-50%); z-index: 100; display: grid; gap: .5rem; width: min(420px, calc(100vw - 2rem)); }
.toast { background: var(--text); color: var(--bg); padding: .7rem 1rem; border-radius: var(--radius-klein); box-shadow: var(--schatten); font-size: .95rem; animation: rein .2s ease-out; }
.toast.fehler { background: var(--fehler); color: #fff; }
@keyframes rein { from { opacity: 0; transform: translateY(8px); } }

.laden { display: grid; place-items: center; padding: 3rem; }
.laden::after { content: ""; width: 32px; height: 32px; border: 3px solid var(--rand); border-top-color: var(--primaer); border-radius: 50%; animation: drehen .8s linear infinite; }
@keyframes drehen { to { transform: rotate(360deg); } }

/* ── Login ───────────────────────────────────────────────────────────────── */
.login-seite { min-height: 100vh; display: grid; place-items: center; padding: 1rem; }
.login-box { width: min(400px, 100%); }
.login-box .logo { justify-content: center; margin: 0 0 1.25rem; font-size: 1.2rem; }

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

/* Lehrer-Gruppen */
.lehrer-block + .lehrer-block { margin-top: .85rem; }
.lehrer-kopf { display: flex; justify-content: space-between; align-items: flex-start; gap: .75rem; flex-wrap: wrap; padding-bottom: .7rem; border-bottom: 1px solid var(--rand); margin-bottom: .2rem; }
.lehrer-kopf .aktionen { display: flex; gap: .3rem; flex-wrap: wrap; }
.lehrer-kopf + .eintrag, .lehrer-kopf + p + .eintrag { border-top: none; margin-top: .7rem; padding-top: 0; }
.lehrer-titel { display: flex; align-items: baseline; gap: .6rem; flex-wrap: wrap; margin: 1.1rem 0 .6rem; }
.lehrer-titel h3 { margin: 0; }
.lehrer-titel .rechts { margin-left: auto; }
tr.gruppe td { background: var(--flaeche-2); font-weight: 700; font-size: .88rem; padding-top: .45rem; padding-bottom: .45rem; }
.mit-icon { display: inline-flex; align-items: center; gap: .4rem; }
.mit-icon svg { width: 18px !important; height: 18px !important; color: var(--primaer); }

/* Kapitel */
.kapitel-zeile .inhalt { min-width: 0; }
.kapitel-zeile .aktionen { display: flex; gap: .35rem; align-self: center; }
.kapitel-titel { font-size: 1.05rem; margin: 1.4rem 0 .6rem; color: var(--primaer); }
.kapitel-titel:first-child { margin-top: .2rem; }
.lernkarte .kapitel-marke { font-size: .78rem; font-weight: 600; color: var(--primaer); text-transform: uppercase; letter-spacing: .04em; margin-bottom: .6rem; }
.gruppen-kopf { font-weight: 700; font-size: .85rem; text-transform: uppercase; letter-spacing: .04em; color: var(--gedimmt); padding-bottom: .5rem; border-bottom: 1px solid var(--rand); }
.gruppen-kopf + .eintrag { border-top: none; }
select.filter-auswahl { width: auto; padding: .3rem .5rem; font-size: .85rem; }
.btn { white-space: nowrap; }
