:root {
  --bg: #f6f3ee;
  --flaeche: #ffffff;
  --flaeche-2: #efeae2;
  --text: #2a2522;
  --text-2: #6b625b;
  --linie: #ddd5ca;
  --akzent: #8f2d2d;
  --akzent-hover: #7a2424;
  --akzent-zart: #f4e3e0;
  --auf-akzent: #ffffff;
  --richtig: #2f7a4b;
  --richtig-zart: #e3f1e8;
  --falsch: #b23a3a;
  --falsch-zart: #f8e3e1;
  --fortschritt: #c08a2e;
  --schatten: 0 1px 2px rgba(40, 30, 20, .06), 0 6px 20px rgba(40, 30, 20, .06);
  --radius: 14px;
  --serif: "Palatino Linotype", Palatino, "Book Antiqua", Georgia, "Times New Roman", serif;
  --sans: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #1a1716;
    --flaeche: #242020;
    --flaeche-2: #2e2928;
    --text: #efe9e3;
    --text-2: #aaa098;
    --linie: #3d3634;
    --akzent: #d0726a;
    --akzent-hover: #dc8a83;
    --akzent-zart: #3a2524;
    --auf-akzent: #1a1716;
    --richtig: #6cc28c;
    --richtig-zart: #1f3327;
    --falsch: #e9827a;
    --falsch-zart: #3c2322;
    --fortschritt: #d9a54a;
    --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;
  min-height: 100vh;
  min-height: 100dvh;
  background: var(--bg);
  color: var(--text);
  font-family: var(--sans);
  font-size: 16px;
  line-height: 1.5;
  -webkit-tap-highlight-color: transparent;
}

[hidden] { display: none !important; }

button, input { font: inherit; color: inherit; }

.sr-only {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; border: 0;
}

/* ---------- Kopf ---------- */
.kopf {
  padding: max(14px, env(safe-area-inset-top)) 16px 10px;
}
.kopf-inner {
  max-width: 720px;
  margin: 0 auto;
  display: flex;
  align-items: center;
  gap: 12px;
}
.logo {
  display: grid;
  place-items: center;
  width: 40px; height: 40px;
  border-radius: 10px;
  background: var(--akzent);
  color: var(--auf-akzent);
  font-family: var(--serif);
  font-weight: 700;
  font-size: 24px;
}
h1 { margin: 0; font-family: var(--serif); font-size: 1.35rem; line-height: 1.1; }
.untertitel { margin: 0; color: var(--text-2); font-size: .85rem; }

/* ---------- Layout ---------- */
main {
  max-width: 720px;
  margin: 0 auto;
  padding: 8px 16px max(24px, env(safe-area-inset-bottom));
}
h2 { font-size: 1.15rem; margin: 0; }
h3 { font-size: 1rem; margin: 24px 0 8px; }

.hinweis { color: var(--text-2); margin: 6px 0 14px; font-size: .92rem; }
.hinweis.klein { font-size: .82rem; margin-top: 10px; }

.abschnitt-kopf {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
  margin-top: 8px;
}
.schnell { display: flex; gap: 4px; }

/* ---------- Buttons ---------- */
.btn {
  appearance: none;
  border: 1px solid transparent;
  border-radius: 12px;
  padding: 10px 18px;
  font-weight: 600;
  cursor: pointer;
  transition: background-color .15s, transform .05s, border-color .15s;
  touch-action: manipulation;
}
.btn:active { transform: scale(.98); }
.btn:disabled { opacity: .45; cursor: not-allowed; transform: none; }
.btn.gross { min-height: 54px; font-size: 1.05rem; }
.btn.voll { width: 100%; }
.btn.primaer { background: var(--akzent); color: var(--auf-akzent); }
.btn.primaer:hover:not(:disabled) { background: var(--akzent-hover); }
.btn.sekundaer { background: var(--flaeche); border-color: var(--linie); }
.btn.sekundaer:hover { background: var(--flaeche-2); }
.btn.richtig { background: var(--richtig-zart); color: var(--richtig); border-color: var(--richtig); }
.btn.falsch { background: var(--falsch-zart); color: var(--falsch); border-color: var(--falsch); }

.link-btn {
  appearance: none;
  background: none;
  border: none;
  padding: 8px 6px;
  color: var(--akzent);
  font-weight: 600;
  font-size: .92rem;
  cursor: pointer;
  border-radius: 8px;
}
.link-btn:hover { text-decoration: underline; }

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

/* ---------- Lektionen ---------- */
.lektionen {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(92px, 1fr));
  gap: 8px;
}
.lektion {
  appearance: none;
  position: relative;
  text-align: left;
  background: var(--flaeche);
  border: 1.5px solid var(--linie);
  border-radius: 12px;
  padding: 10px 10px 12px;
  cursor: pointer;
  touch-action: manipulation;
  transition: border-color .15s, background-color .15s;
}
.lektion:hover { border-color: var(--text-2); }
.lektion[aria-pressed="true"] {
  border-color: var(--akzent);
  background: var(--akzent-zart);
}
.lektion[aria-pressed="true"]::after {
  content: "✓";
  position: absolute;
  top: 6px; right: 9px;
  color: var(--akzent);
  font-weight: 700;
  font-size: .85rem;
}
.lektion-name { display: block; font-weight: 700; font-size: 1.05rem; }
.lektion-anzahl { display: block; color: var(--text-2); font-size: .78rem; }
.mini-balken {
  height: 4px;
  border-radius: 2px;
  background: var(--flaeche-2);
  margin-top: 8px;
  overflow: hidden;
}
.mini-balken > span {
  display: block;
  height: 100%;
  background: var(--fortschritt);
  border-radius: 2px;
}

/* ---------- Optionen ---------- */
.optionen {
  display: grid;
  gap: 14px;
  margin-top: 22px;
}
.segment { border: 0; margin: 0; padding: 0; min-width: 0; }
.segment legend { font-weight: 600; font-size: .92rem; margin-bottom: 6px; padding: 0; }
.segment {
  display: flex;
  flex-wrap: wrap;
}
.segment legend { width: 100%; }
.segment label {
  flex: 1 1 0;
  min-width: 0;
  position: relative;
}
.segment input { position: absolute; opacity: 0; pointer-events: none; }
.segment span {
  display: block;
  text-align: center;
  padding: 10px 6px;
  background: var(--flaeche);
  border: 1.5px solid var(--linie);
  margin-left: -1.5px;
  cursor: pointer;
  font-weight: 600;
  font-size: .95rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.segment label:first-of-type span { border-radius: 10px 0 0 10px; margin-left: 0; }
.segment label:last-of-type span { border-radius: 0 10px 10px 0; }
.segment input:checked + span {
  background: var(--akzent);
  border-color: var(--akzent);
  color: var(--auf-akzent);
  position: relative;
  z-index: 1;
}
.segment input:focus-visible + span { outline: 3px solid var(--akzent); outline-offset: 2px; z-index: 2; }

.start-leiste {
  position: sticky;
  bottom: 0;
  padding: 12px 0 max(12px, env(safe-area-inset-bottom));
  margin-top: 8px;
  background: linear-gradient(to bottom, transparent, var(--bg) 30%);
}
.start-leiste .btn { width: 100%; }

.fuss {
  margin-top: 20px;
  padding-top: 14px;
  border-top: 1px solid var(--linie);
  color: var(--text-2);
  font-size: .82rem;
  text-align: center;
}
.fuss p { margin: 0 0 2px; }

/* ---------- Abfrage ---------- */
.abfrage-kopf {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-left: -6px;
}
.zaehler { color: var(--text-2); font-variant-numeric: tabular-nums; font-size: .92rem; }
.balken {
  height: 6px;
  background: var(--flaeche-2);
  border-radius: 3px;
  overflow: hidden;
  margin: 6px 0 16px;
}
.balken-fuellung {
  height: 100%;
  width: 0;
  background: var(--akzent);
  border-radius: 3px;
  transition: width .25s ease;
}

.karte {
  position: relative;
  background: var(--flaeche);
  border-radius: var(--radius);
  box-shadow: var(--schatten);
  border: 1px solid var(--linie);
  padding: 34px 20px 26px;
  min-height: 230px;
  display: flex;
  flex-direction: column;
  justify-content: center;
  text-align: center;
}
.lektion-tag {
  position: absolute;
  top: 12px; left: 14px;
  font-size: .75rem;
  font-weight: 600;
  color: var(--text-2);
  background: var(--flaeche-2);
  padding: 2px 8px;
  border-radius: 999px;
}
.latein {
  font-family: var(--serif);
  font-size: clamp(1.9rem, 7vw, 2.6rem);
  font-weight: 700;
  line-height: 1.2;
  margin: 0;
  overflow-wrap: anywhere;
}
.formen {
  font-family: var(--serif);
  color: var(--text-2);
  font-size: clamp(1rem, 3.6vw, 1.2rem);
  margin: 8px 0 0;
  overflow-wrap: anywhere;
}
.loesung {
  margin-top: 20px;
  padding-top: 18px;
  border-top: 1px dashed var(--linie);
  animation: einblenden .2s ease;
}
.deutsch {
  font-size: clamp(1.15rem, 4.4vw, 1.4rem);
  font-weight: 600;
  margin: 0;
}
.urteil {
  display: inline-block;
  font-weight: 700;
  font-size: .9rem;
  padding: 3px 12px;
  border-radius: 999px;
  margin-bottom: 10px;
}
.urteil.ok { background: var(--richtig-zart); color: var(--richtig); }
.urteil.nein { background: var(--falsch-zart); color: var(--falsch); }
.urteil .deine { font-weight: 500; }

.karte:focus { outline: none; }
.karte.ok { border-color: var(--richtig); }
.karte.nein { border-color: var(--falsch); }

@keyframes einblenden {
  from { opacity: 0; transform: translateY(4px); }
  to { opacity: 1; transform: none; }
}

.aktionen {
  margin-top: 16px;
  display: grid;
  gap: 10px;
}
.zwei { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
#nach-pruefung { display: grid; gap: 4px; justify-items: center; }

.eingabe {
  width: 100%;
  min-height: 54px;
  padding: 12px 16px;
  font-size: 1.1rem; /* >= 16px verhindert Zoom auf iOS */
  border-radius: 12px;
  border: 1.5px solid var(--linie);
  background: var(--flaeche);
}
.eingabe:focus { outline: none; border-color: var(--akzent); }
.eingabe:read-only { background: var(--flaeche-2); }

.tasten-hinweis {
  text-align: center;
  color: var(--text-2);
  font-size: .8rem;
  margin: 2px 0 0;
}
@media (hover: none) {
  #tasten-karte { display: none; }
}

/* ---------- Test ---------- */
.test-block {
  background: var(--flaeche);
  border: 1px solid var(--linie);
  border-radius: var(--radius);
  box-shadow: var(--schatten);
  padding: 16px 16px 6px;
  margin-top: 12px;
}
.test-block + .test-block { margin-top: 16px; }
.aufgabe-titel { font-size: 1.02rem; line-height: 1.35; }
.aufgabe-titel .nr { color: var(--akzent); margin-right: 4px; }
.test-block .hinweis.klein { margin-top: 6px; }

.test-liste { list-style: none; margin: 8px 0 0; padding: 0; }
.test-zeile {
  padding: 12px 0;
  border-top: 1px solid var(--linie);
  display: grid;
  gap: 8px;
}
.test-zeile:first-child { border-top: 0; }
.test-kopf { display: flex; align-items: baseline; gap: 8px; }
.buchstabe { color: var(--text-2); font-weight: 600; min-width: 1.4em; }
.test-wort { font-family: var(--serif); font-weight: 700; font-size: 1.2rem; overflow-wrap: anywhere; }
.test-felder { display: grid; gap: 8px; }
.eingabe.test-eingabe { min-height: 46px; font-size: 1rem; padding: 10px 12px; }
.eingabe.ok { border-color: var(--richtig); }
.eingabe.teil { border-color: var(--fortschritt); }
.eingabe.nein { border-color: var(--falsch); }

.korrektur { display: grid; gap: 6px; }
.korrektur-zeile { display: flex; align-items: flex-start; gap: 10px; font-size: .92rem; }
.punkt-btn {
  appearance: none;
  flex: none;
  min-width: 72px;
  padding: 3px 10px;
  border-radius: 999px;
  border: 1px solid currentColor;
  font-weight: 700;
  font-size: .85rem;
  cursor: pointer;
  touch-action: manipulation;
}
.punkt-btn.ok { background: var(--richtig-zart); color: var(--richtig); }
.punkt-btn.teil { background: var(--flaeche-2); color: var(--fortschritt); }
.punkt-btn.nein { background: var(--falsch-zart); color: var(--falsch); }
.loesung-text { padding-top: 2px; overflow-wrap: anywhere; }
.loesung-label { color: var(--text-2); }
.loesung-text [lang="la"] { font-family: var(--serif); }

.punkte {
  text-align: right;
  font-weight: 700;
  margin: 0;
  padding: 10px 0 8px;
  border-top: 1px solid var(--linie);
}
.test-ergebnis { text-align: center; margin-top: 24px; }
.test-ergebnis .aktionen { justify-items: center; }

/* ---------- Ergebnis ---------- */
.ergebnis-kopf { text-align: center; padding: 20px 0 4px; }
.ergebnis-zahl {
  font-family: var(--serif);
  font-size: 3.2rem;
  font-weight: 700;
  line-height: 1;
  margin: 0 0 8px;
  color: var(--akzent);
  font-variant-numeric: tabular-nums;
}
.fehler-liste {
  list-style: none;
  margin: 0;
  padding: 0;
  background: var(--flaeche);
  border: 1px solid var(--linie);
  border-radius: var(--radius);
  overflow: hidden;
}
.fehler-liste li {
  padding: 10px 14px;
  border-top: 1px solid var(--linie);
  display: grid;
  gap: 2px;
}
.fehler-liste li:first-child { border-top: 0; }
.fehler-liste .la { font-family: var(--serif); font-weight: 700; }
.fehler-liste .de { color: var(--text-2); font-size: .92rem; }
#ergebnis .aktionen { justify-items: center; margin-top: 22px; }

/* ---------- Größere Bildschirme ---------- */
@media (min-width: 600px) {
  .kopf { padding-top: 24px; }
  .lektionen { grid-template-columns: repeat(auto-fill, minmax(104px, 1fr)); }
  .optionen { grid-template-columns: 1fr 1fr; }
  .karte { min-height: 280px; padding: 44px 32px 32px; }
  .start-leiste { position: static; background: none; }
  .start-leiste .btn { width: auto; min-width: 260px; display: block; margin: 0 auto; }
  #ergebnis .aktionen .btn.voll,
  .test-ergebnis .btn.voll { max-width: 360px; }
  .test-block { padding: 20px 22px 8px; }
  .test-felder { grid-template-columns: 1fr 1fr; }
  .test-felder:has(> :only-child) { grid-template-columns: 1fr; }
}

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