:root {
  --bg: #faf7f2; --karte: #ffffff; --text: #1d2a24; --leise: #6b756f; --linie: #e5e0d8;
  --gruen: #0f6b4f; --gruen-hell: #e3f2ea; --rot: #c0303b; --rot-hell: #fbe9ea; --gelb: #f4b740; --gelb-hell: #fdf3dc;
  --ich: #0f6b4f; --ich-text: #fff; --schatten: 0 1px 3px rgba(0,0,0,.08);
  --oben: env(safe-area-inset-top); --unten: env(safe-area-inset-bottom);
  color-scheme: light dark;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #121714; --karte: #1c2420; --text: #e8ece9; --leise: #9aa59f; --linie: #2c3631;
    --gruen: #3fbf8a; --gruen-hell: #193a2c; --rot: #ef6b73; --rot-hell: #3a1d20; --gelb: #f4b740; --gelb-hell: #3a301a;
    --ich: #1f7a58; --ich-text: #fff; --schatten: none;
  }
}
[hidden] { display: none !important; }
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { height: 100%; margin: 0; }
body {
  background: var(--bg); color: var(--text);
  font: 17px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  display: flex; flex-direction: column; overflow: hidden;
}
button, input, textarea, select { font: inherit; color: inherit; }
button { cursor: pointer; }
h1, h2, h3 { margin: 0; line-height: 1.2; }
h2 { font-size: 1.3rem; }
h3 { font-size: 1.05rem; margin: 1.4em 0 .5em; }
.leise { color: var(--leise); font-size: .88em; }
.mitte { text-align: center; }

.leiste {
  display: flex; align-items: center; justify-content: space-between;
  padding: calc(var(--oben) + 8px) 16px 8px; background: var(--karte); border-bottom: 1px solid var(--linie);
}
.leiste h1 { font-size: 1.15rem; display: flex; align-items: center; gap: 8px; }
.flagge { width: 18px; height: 14px; border-radius: 2px; background: linear-gradient(90deg, #0f8a5f 33%, #fff 33% 66%, #cf2b37 66%); box-shadow: 0 0 0 1px var(--linie); }
.leiste button { background: none; border: 0; font-size: 1.3rem; padding: 4px 8px; }

main { flex: 1; overflow-y: auto; overscroll-behavior: contain; -webkit-overflow-scrolling: touch; }

nav {
  display: flex; background: var(--karte); border-top: 1px solid var(--linie);
  padding-bottom: var(--unten);
}
nav button {
  flex: 1; background: none; border: 0; padding: 7px 0 6px; font-size: .72rem; color: var(--leise);
  display: flex; flex-direction: column; align-items: center; gap: 1px;
}
nav button span { font-size: 1.35rem; filter: grayscale(1); opacity: .7; }
nav button.aktiv { color: var(--gruen); font-weight: 600; }
nav button.aktiv span { filter: none; opacity: 1; }

/* Knöpfe */
.knopf {
  background: var(--gruen); color: #fff; border: 0; border-radius: 12px; padding: 10px 16px; font-weight: 600;
}
.knopf:disabled { opacity: .5; }
.knopf.zweit { background: var(--gruen-hell); color: var(--gruen); }
.knopf.klein { padding: 6px 12px; font-size: .88rem; border-radius: 10px; }
.knopf.gross { padding: 14px 18px; flex: 1; }
.knopf.gut { background: var(--gruen); flex: 1; padding: 16px; }
.knopf.schlecht { background: var(--rot); flex: 1; padding: 16px; }
.knopf.gefahr { background: var(--rot-hell); color: var(--rot); margin-top: 24px; }
.knopfreihe { display: flex; gap: 10px; margin: 12px 0; flex-wrap: wrap; align-items: center; }
.knopfreihe.links { justify-content: flex-start; }
.laut { background: none; border: 0; font-size: 1.05rem; padding: 2px 4px; vertical-align: middle; }
.laut.klein { font-size: .95rem; }
.laut.gross { font-size: 1.6rem; padding: 6px 10px; background: var(--gruen-hell); border-radius: 50%; margin: 4px; }
.zurueck { background: none; border: 0; font-size: 2rem; line-height: 1; padding: 0 8px 0 0; color: var(--gruen); }

/* Kopf einer Ansicht */
.kopf { display: flex; align-items: center; gap: 8px; }
.kopf > div { flex: 1; min-width: 0; }
.kopf p { margin: 2px 0 0; }

/* Gespräch */
.gespraech { display: flex; flex-direction: column; min-height: 100%; }
.gespraech .kopf { padding: 12px 16px 8px; position: sticky; top: 0; background: var(--bg); z-index: 2; }
.ziel { margin: 0 16px 6px; padding: 8px 12px; background: var(--gelb-hell); border-radius: 10px; font-size: .9rem; }
.verlauf { flex: 1; padding: 6px 12px 12px; display: flex; flex-direction: column; gap: 10px; }
.zeile { display: flex; flex-direction: column; align-items: flex-start; gap: 4px; }
.zeile.ich { align-items: flex-end; }
.blase { max-width: 88%; padding: 10px 13px; border-radius: 18px; box-shadow: var(--schatten); }
.blase.ki { background: var(--karte); border-bottom-left-radius: 6px; }
.blase.ich { background: var(--ich); color: var(--ich-text); border-bottom-right-radius: 6px; }
.blase.fehler { background: var(--rot-hell); color: var(--rot); }
.blase .it { font-size: 1.08rem; font-weight: 500; }
.blase .de { color: var(--leise); font-size: .92rem; margin-top: 3px; }
.verdeckt { filter: blur(5px); cursor: pointer; user-select: none; }
.woerter { display: flex; flex-wrap: wrap; gap: 5px; margin-top: 8px; }
.chip { font-size: .8rem; background: var(--gelb-hell); padding: 3px 8px; border-radius: 99px; cursor: pointer; }
.korrektur { max-width: 88%; background: var(--rot-hell); border-left: 4px solid var(--rot); padding: 8px 12px; border-radius: 10px; font-size: .92rem; }
.korrektur .richtig { font-weight: 600; }
.korrektur .erkl { margin-top: 3px; }
.lob { font-size: .85rem; color: var(--gruen); padding: 0 6px; }
.geschafft { background: var(--gruen-hell); color: var(--gruen); padding: 8px 12px; border-radius: 10px; font-weight: 600; }
.tippt { display: flex; gap: 5px; padding: 14px 16px; }
.tippt span { width: 8px; height: 8px; border-radius: 50%; background: var(--leise); animation: tippt 1.2s infinite; }
.tippt span:nth-child(2) { animation-delay: .2s; } .tippt span:nth-child(3) { animation-delay: .4s; }
@keyframes tippt { 0%, 60%, 100% { opacity: .25; transform: translateY(0); } 30% { opacity: 1; transform: translateY(-3px); } }

.vorschlaege { padding: 0 12px 6px; display: flex; flex-direction: column; gap: 5px; }
.vorschlaege:empty { display: none; }
.vorschlag { display: flex; align-items: center; background: var(--karte); border: 1px solid var(--linie); border-radius: 12px; }
.vtext { flex: 1; text-align: left; background: none; border: 0; padding: 6px 10px; display: flex; flex-direction: column; }
.vtext b { font-weight: 500; font-size: .95rem; }
.vtext small { color: var(--leise); font-size: .78rem; }

.eingabe {
  position: sticky; bottom: 0; display: flex; align-items: flex-end; gap: 6px; padding: 8px 10px;
  background: var(--karte); border-top: 1px solid var(--linie);
}
.eingabe textarea {
  flex: 1; resize: none; border: 1px solid var(--linie); border-radius: 20px; padding: 9px 14px; background: var(--bg);
  max-height: 120px; outline: none; font-size: 16px;
}
.sprachwahl { background: none; border: 0; font-size: 1.4rem; padding: 6px 2px; }
.mikro {
  width: 52px; height: 52px; border-radius: 50%; border: 0; background: var(--gruen); color: #fff; font-size: 1.4rem; flex: none;
}
.mikro.an, #nachsprechen.an { background: var(--rot); animation: puls 1.2s infinite; color: #fff; }
@keyframes puls { 0% { box-shadow: 0 0 0 0 rgba(192,48,59,.5); } 100% { box-shadow: 0 0 0 16px rgba(192,48,59,0); } }
.senden { width: 42px; height: 42px; border-radius: 50%; border: 0; background: var(--gruen-hell); color: var(--gruen); font-size: 1.1rem; flex: none; margin-bottom: 5px; }

/* Listen */
.liste { padding: 16px; }
.liste > .leise { margin: 4px 0 14px; }
.info { background: var(--gelb-hell); padding: 10px 12px; border-radius: 10px; font-size: .92rem; }
.karten-raster { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 10px; }
.kachel {
  background: var(--karte); border: 1px solid var(--linie); border-radius: 14px; padding: 12px; text-align: left;
  display: flex; flex-direction: column; gap: 4px; position: relative; box-shadow: var(--schatten);
}
.kachel .symbol { font-size: 1.8rem; }
.kachel small { color: var(--leise); font-size: .78rem; line-height: 1.3; }
.kachel em { position: absolute; top: 10px; right: 10px; font-style: normal; font-size: .7rem; background: var(--gelb); color: #000; padding: 1px 7px; border-radius: 99px; }
.zeilenform { display: flex; gap: 8px; }
.zeilenform input { flex: 1; min-width: 0; padding: 10px 12px; border: 1px solid var(--linie); border-radius: 12px; background: var(--karte); font-size: 16px; }

.themen { display: flex; flex-direction: column; gap: 8px; }
.thema {
  display: flex; align-items: center; gap: 12px; background: var(--karte); border: 1px solid var(--linie);
  border-radius: 14px; padding: 10px 14px; text-align: left; box-shadow: var(--schatten);
}
.thema .symbol { font-size: 1.7rem; width: 36px; text-align: center; }
.thema .mitte { flex: 1; display: flex; flex-direction: column; text-align: left; }
.thema small { color: var(--leise); font-size: .8rem; }
.thema em { color: var(--rot); font-style: normal; font-weight: 600; }
.balken { display: block; height: 5px; border-radius: 3px; background: var(--linie); margin-top: 5px; overflow: hidden; }
.balken i { display: block; height: 100%; background: var(--gruen); }

.kartenliste { list-style: none; padding: 0; margin: 12px 0; }
.kartenliste li { display: flex; align-items: center; gap: 8px; padding: 10px 0; border-bottom: 1px solid var(--linie); }
.kartenliste li > div { flex: 1; }
.box { font-size: .72rem; min-width: 22px; height: 22px; border-radius: 50%; display: grid; place-items: center; background: var(--linie); }
.box.b1, .box.b2 { background: var(--gelb-hell); } .box.b3, .box.b4 { background: var(--gruen-hell); } .box.b5 { background: var(--gruen); color: #fff; }

/* Lernen */
.lernen { padding: 16px; display: flex; flex-direction: column; gap: 12px; min-height: 100%; }
.fortschritt { height: 6px; background: var(--linie); border-radius: 3px; overflow: hidden; }
.fortschritt i { display: block; height: 100%; background: var(--gruen); transition: width .3s; }
.karteikarte {
  background: var(--karte); border-radius: 20px; min-height: 260px; padding: 24px 18px; box-shadow: 0 4px 16px rgba(0,0,0,.08);
  display: flex; align-items: center; justify-content: center; text-align: center; border: 1px solid var(--linie);
}
.karteikarte > div { display: flex; flex-direction: column; gap: 8px; align-items: center; }
.gross-text { font-size: 1.7rem; font-weight: 600; line-height: 1.25; }
.klein-text { color: var(--leise); }
.tipphinweis { margin-top: 18px; }
.sprechtest { text-align: center; }
#sprechergebnis { margin-top: 8px; min-height: 1.4em; font-size: .92rem; }
.gut-text { color: var(--gruen); } .mittel-text { color: #b07a00; } .schlecht-text { color: var(--rot); }
.bewertung { display: flex; gap: 10px; margin-top: auto; }
.bewertung[hidden] { display: none; }
.lernen.fertig { align-items: center; justify-content: center; text-align: center; }

/* Übersetzer */
.uform textarea { width: 100%; border: 1px solid var(--linie); border-radius: 14px; padding: 12px; background: var(--karte); resize: vertical; font-size: 16px; }
.uform .knopfreihe { flex-wrap: nowrap; }
.laedt { padding: 20px; text-align: center; color: var(--leise); animation: blink 1.4s infinite; }
@keyframes blink { 50% { opacity: .4; } }
.ergebnis { background: var(--karte); border-radius: 16px; padding: 16px; margin-top: 8px; box-shadow: var(--schatten); border: 1px solid var(--linie); }
.satz-it { font-size: 1.4rem; font-weight: 600; line-height: 1.3; }
.satz-de { font-size: 1.05rem; margin-top: 8px; }
.aussprache { margin-top: 2px; }
.woertlich { margin-top: 8px; font-size: .92rem; font-style: italic; }
.wortreihe { display: flex; flex-wrap: wrap; gap: 6px; }
.wort {
  background: var(--bg); border: 1px solid var(--linie); border-radius: 10px; padding: 6px 10px;
  display: flex; flex-direction: column; align-items: center; min-width: 52px;
}
.wort b { font-size: 1.05rem; }
.wort small { font-size: .72rem; color: var(--leise); }
.wort.aktiv { border-color: var(--gruen); background: var(--gruen-hell); }
.wortkarte { margin-top: 10px; background: var(--gruen-hell); border-radius: 12px; padding: 12px 14px; }
.wortkarte .kopfzeile { font-size: 1.2rem; }
.wortkarte p { margin: 6px 0 0; }
.grammatik { padding-left: 20px; margin: 0; }
.grammatik li { margin-bottom: 6px; }
.uverlauf { list-style: none; padding: 0; margin: 0; }
.uverlauf button { width: 100%; text-align: left; background: none; border: 0; border-bottom: 1px solid var(--linie); padding: 8px 0; display: flex; flex-direction: column; }
.uverlauf small { color: var(--leise); }

/* Dialog */
dialog { border: 0; border-radius: 18px; padding: 0; width: min(94vw, 480px); max-height: 88vh; background: var(--karte); color: var(--text); }
dialog::backdrop { background: rgba(0,0,0,.45); }
.einst { padding: 18px; display: flex; flex-direction: column; gap: 14px; }
.einst label { display: flex; flex-direction: column; gap: 4px; font-weight: 500; }
.einst label.schalter { flex-direction: row; align-items: center; gap: 10px; font-weight: 400; }
.einst label.knopf { display: inline-flex; font-weight: 600; }
.einst input[type=password], .einst select { padding: 10px; border: 1px solid var(--linie); border-radius: 10px; background: var(--bg); font-size: 16px; }
.einst input[type=checkbox] { width: 22px; height: 22px; accent-color: var(--gruen); flex: none; }
.einst h3 { margin: 6px 0 0; }

.toast {
  position: fixed; left: 50%; top: calc(var(--oben) + 64px); transform: translateX(-50%); z-index: 50;
  background: var(--text); color: var(--bg); padding: 10px 16px; border-radius: 12px; max-width: 90vw; font-size: .9rem;
  transition: opacity .5s; box-shadow: 0 4px 16px rgba(0,0,0,.2);
}
.toast.gut { background: var(--gruen); color: #fff; }
.toast.schlecht { background: var(--rot); color: #fff; }
.toast.weg { opacity: 0; }
