:root {
  color-scheme: light;   /* sonst dunkelt Chrome die Seite automatisch ab */
  --bg: #f4f6f8; --karte: #fff; --rand: #d9dee3; --text: #1d2228; --matt: #6b7680;
  --akzent: #1f6feb; --gut: #1a7f45; --schlecht: #c0392b; --gut-bg: #e7f6ed;
  --schlecht-bg: #fdecea; --schatten: 0 1px 3px rgba(0,0,0,.08);
  --mark-bg: #fff4d6; --mark-rand: #e0a800; --mark-text: #6b5200;
}

/* Ohne eigene Wahl folgt die App dem System; der Schalter im Kopf setzt
   data-theme und gewinnt dann in beide Richtungen. */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="hell"]) {
    color-scheme: dark;
    --bg: #14181d; --karte: #1c2229; --rand: #2d353e; --text: #e4e8ec; --matt: #93a1ad;
    --akzent: #4d8ef7; --gut: #4ade80; --schlecht: #f87171; --gut-bg: #16301f;
    --schlecht-bg: #3a1d1b; --schatten: 0 1px 3px rgba(0,0,0,.45);
    --mark-bg: #3a2f12; --mark-rand: #b8860b; --mark-text: #f5d97a;
  }
}
:root[data-theme="dunkel"] {
  color-scheme: dark;
  --bg: #14181d; --karte: #1c2229; --rand: #2d353e; --text: #e4e8ec; --matt: #93a1ad;
  --akzent: #4d8ef7; --gut: #4ade80; --schlecht: #f87171; --gut-bg: #16301f;
  --schlecht-bg: #3a1d1b; --schatten: 0 1px 3px rgba(0,0,0,.45);
  --mark-bg: #3a2f12; --mark-rand: #b8860b; --mark-text: #f5d97a;
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
body { margin: 0; font: 16px/1.5 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
       background: var(--bg); color: var(--text); }
header { display: flex; align-items: center; gap: 20px; flex-wrap: wrap;
         background: var(--karte); border-bottom: 1px solid var(--rand);
         padding: 10px 20px; position: sticky; top: 0; z-index: 10; }
.marke { font-weight: 700; text-decoration: none; color: var(--akzent); font-size: 18px; }
header nav { display: flex; gap: 4px; flex-wrap: wrap; }
header nav a { text-decoration: none; color: var(--matt); padding: 6px 10px; border-radius: 6px; }
header nav a:hover { background: var(--bg); color: var(--text); }
header nav a.aktiv { background: var(--akzent); color: #fff; }
.rechts { margin-left: auto; color: var(--matt); font-size: 14px; display: flex;
          align-items: center; gap: 10px; }
main { max-width: 820px; margin: 0 auto; padding: 24px 16px 64px; }
h1 { font-size: 22px; margin: 0 0 4px; }
h2 { font-size: 18px; margin: 24px 0 8px; }
p.hinweis { color: var(--matt); margin: 0 0 20px; }
button { font: inherit; padding: 8px 16px; border: 1px solid var(--rand); border-radius: 6px;
         background: var(--karte); cursor: pointer; }
button:hover { border-color: var(--akzent); }
button.primaer { background: var(--akzent); border-color: var(--akzent); color: #fff; }
button.primaer:disabled { opacity: .45; cursor: not-allowed; }
.karte { background: var(--karte); border: 1px solid var(--rand); border-radius: 10px;
         padding: 18px; box-shadow: var(--schatten); margin-bottom: 14px; }
.kachel { display: block; width: 100%; text-align: left; margin-bottom: 8px; padding: 12px 14px; }
.kachel small { color: var(--matt); display: block; margin-top: 2px; }
/* Bereichskachel + schmaler "Selten"-Knopf nebeneinander */
.kachelzeile { display: flex; gap: 8px; align-items: stretch; margin-bottom: 8px; }
.kachelzeile .kachel { flex: 1 1 auto; min-width: 0; margin-bottom: 0; }
.seltenbtn { display: flex; flex-direction: column; align-items: center; justify-content: center;
             gap: 1px; min-width: 74px; padding: 8px; line-height: 1.15; }
.seltenbtn b { font-size: 16px; font-variant-numeric: tabular-nums; }
.seltenbtn small { font-size: 11px; color: var(--matt); }
.seltenbtn:disabled { opacity: .4; cursor: not-allowed; }
.seltenbtn:disabled:hover { border-color: var(--rand); }
.fq.gut { color: var(--gut); } .fq.schlecht { color: var(--schlecht); }
.matt { color: var(--matt); }
/* Duenne Fortschrittsleiste in der Kachel: Anteil schon geuebter Fragen */
.minileiste { display: block; height: 5px; margin-top: 8px; border-radius: 3px;
              background: var(--rand); overflow: hidden; }
.minileiste i { display: block; height: 100%; background: var(--akzent); border-radius: 3px; }
.leiste { height: 10px; background: var(--rand); border-radius: 5px; overflow: hidden; margin: 10px 0 18px; }
.leiste i { display: block; height: 100%; background: var(--akzent); border-radius: 5px;
            transition: width .25s ease; }
.kopfzeile .stand { font-variant-numeric: tabular-nums; white-space: nowrap; }
.kopfzeile { display: flex; justify-content: space-between; color: var(--matt); font-size: 14px; }
.frage { font-size: 18px; font-weight: 600; margin: 10px 0 16px; }
.opt { display: flex; gap: 12px; align-items: flex-start; width: 100%; text-align: left;
       margin-bottom: 8px; padding: 12px 14px; }
.opt kbd { background: var(--bg); border: 1px solid var(--rand); border-radius: 4px;
           padding: 0 7px; font: 13px/1.6 ui-monospace, monospace; color: var(--matt); }
.opt.gewaehlt { border-color: var(--akzent); box-shadow: inset 0 0 0 1px var(--akzent); }
.opt.richtig { background: var(--gut-bg); border-color: var(--gut); }
.opt.falsch { background: var(--schlecht-bg); border-color: var(--schlecht); }
.opt[disabled] { cursor: default; opacity: 1; color: var(--text); }
.abb { max-width: 100%; max-height: 44vh; object-fit: contain; border: 1px solid var(--rand); border-radius: 8px; cursor: zoom-in;
       background: #fff; margin-bottom: 14px; }
.rueck { font-weight: 600; margin: 14px 0; }
.rueck.gut { color: var(--gut); } .rueck.schlecht { color: var(--schlecht); }
.fuss { display: flex; gap: 10px; align-items: center; margin-top: 16px; flex-wrap: wrap; }
.fuss .tipp { color: var(--matt); font-size: 13px; margin-left: auto; }
.markbtn.an { background: var(--mark-bg); border-color: var(--mark-rand); color: var(--mark-text); }
.themabtn { padding: 6px 10px; line-height: 1; }
form.login { max-width: 340px; margin: 60px auto; }
form.login input { width: 100%; padding: 10px; margin-bottom: 10px; font: inherit;
                   border: 1px solid var(--rand); border-radius: 6px;
                   background: var(--karte); color: var(--text); }
.fehler { color: var(--schlecht); min-height: 22px; font-size: 14px; }
table { width: 100%; border-collapse: collapse; background: var(--karte);
        border: 1px solid var(--rand); border-radius: 10px; overflow: hidden; }
th, td { text-align: left; padding: 10px 12px; border-bottom: 1px solid var(--rand); font-size: 15px; }
th { background: var(--bg); font-size: 13px; color: var(--matt); text-transform: uppercase;
     letter-spacing: .04em; }
tr:last-child td { border-bottom: none; }
.bestanden { color: var(--gut); } .durchgefallen { color: var(--schlecht); }
.gross { font-size: 26px; font-weight: 700; }
.bq { display: flex; gap: 10px; }
.bq .nr { color: var(--matt); min-width: 28px; }
.bq .loesung { color: var(--gut); font-weight: 600; }
#lupe { position: fixed; inset: 0; background: rgba(0,0,0,.85); display: flex;
        align-items: center; justify-content: center; z-index: 100; cursor: zoom-out; padding: 20px; }
#lupe img { max-width: 100%; max-height: 100%; }
/* Touch: kein 300ms-Verzoegerung, kein grauer Blitz beim Tippen */
button, a, .abb { -webkit-tap-highlight-color: transparent; touch-action: manipulation; }

/* ================================================================= Handy */
@media (max-width: 640px) {
  :root { --navh: 46px; }

  /* Kopfzeile schrumpft auf Marke + Abmelden; die Navigation wandert nach unten */
  header { padding: 8px 12px; gap: 8px; }
  .marke { font-size: 17px; }
  .rechts { margin-left: auto; width: auto; font-size: 13px; gap: 8px; }
  .rechts button { padding: 6px 10px; min-height: 0; }

  header nav {
    position: fixed; left: 0; right: 0; bottom: 0; z-index: 20;
    gap: 0; flex-wrap: nowrap;
    background: var(--karte); border-top: 1px solid var(--rand);
    padding: 4px 2px calc(4px + env(safe-area-inset-bottom));
    box-shadow: 0 -1px 4px rgba(0,0,0,.10);
  }
  /* Kurzbeschriftung aus data-kurz — "Schwachstellen" passt sonst nicht in ein Fuenftel */
  header nav a { flex: 1 1 0; min-width: 0; text-align: center; font-size: 0;
                 padding: 9px 2px; border-radius: 8px; }
  header nav a::before { content: attr(data-kurz); font-size: 11px; line-height: 1.3; }

  main { padding: 16px 14px calc(var(--navh) + 40px); }
  h1 { font-size: 20px; }

  /* Fingerkuppen brauchen ~48px */
  button { padding: 11px 16px; min-height: 46px; }
  .karte { padding: 14px; }
  .kachel { min-height: 56px; padding: 14px; }
  .kachel small { font-size: 12px; }
  .seltenbtn { min-width: 64px; padding: 6px; min-height: 0; }
  .opt { padding: 13px 14px; min-height: 52px; align-items: center; }

  /* Bild kleiner, damit Frage + Antworten noch ins Bild passen */
  .abb { max-height: 32vh; }

  /* Pruefen/Markieren kleben ueber der Navigationsleiste, statt unter vier Antworten zu verschwinden */
  .quizfuss {
    position: sticky; bottom: calc(var(--navh) + env(safe-area-inset-bottom));
    margin: 14px -14px -14px; padding: 12px 14px;
    background: var(--karte); border-top: 1px solid var(--rand);
    border-radius: 0 0 10px 10px;
  }
  .quizfuss .tipp { display: none; }          /* Tastaturhinweis ohne Tastatur */
  .quizfuss .primaer { flex: 1 1 auto; }

  .kopfzeile { font-size: 12px; gap: 8px; }
  .kopfzeile span:first-child { min-width: 0; overflow: hidden; text-overflow: ellipsis;
                                white-space: nowrap; }
  .kopfzeile span:last-child { flex: none; }
  .frage { font-size: 17px; }

  /* Tabellen werden zu gestapelten Karten — drei Spalten passen nicht auf 390px */
  table, thead, tbody, tr, td { display: block; }
  table { border: none; background: none; border-radius: 0; }
  thead { display: none; }
  tbody tr { background: var(--karte); border: 1px solid var(--rand); border-radius: 10px;
             box-shadow: var(--schatten); padding: 12px 14px; margin-bottom: 10px; }
  tbody td { border: none; padding: 3px 0; }
  tbody td::before { content: attr(data-label) ": "; color: var(--matt); font-size: 13px; }

  form.login { margin: 28px auto; }
  form.login input { min-height: 46px; }

  #lupe { padding: 8px; }
}
