:root {
  --bg: #f4f1ff;
  --bg2: #e6f7ff;
  --card: #ffffff;
  --text: #2d2a4a;
  --muted: #7a7799;
  --primary: #6c5ce7;
  --primary-dark: #5444c9;
  --good: #22c55e;
  --good-bg: #dcfce7;
  --bad: #ef4444;
  --bad-bg: #fee2e2;
  --border: #e3e0f5;
  --shadow: 0 4px 0 rgba(45, 42, 74, 0.08), 0 8px 24px rgba(45, 42, 74, 0.06);
  --radius: 20px;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body { margin: 0; min-height: 100%; }
/* Nichts darf breiter als der Bildschirm werden (z. B. Wackel-Animation, lange Wörter). */
html { overflow-x: hidden; }
body { overflow-x: clip; }

body {
  font-family: ui-rounded, "SF Pro Rounded", "Nunito", "Segoe UI", Roboto, system-ui, sans-serif;
  color: var(--text);
  background: linear-gradient(160deg, var(--bg), var(--bg2)) fixed;
  min-height: 100dvh;
}

button { font: inherit; color: inherit; cursor: pointer; border: 0; background: none; touch-action: manipulation; }

.screen {
  width: 100%;
  max-width: 520px;
  margin: 0 auto;
  padding: max(16px, env(safe-area-inset-top)) 16px max(24px, env(safe-area-inset-bottom));
  display: flex;
  flex-direction: column;
  gap: 16px;
  min-height: 100dvh;
}
.screen[hidden] { display: none; }
/* Vergrößerung bei ignoriertem Viewport, siehe fitViewport() in index.html */
.fit .screen { zoom: var(--fit); width: auto; max-width: none; min-height: calc(100dvh / var(--fit)); }

.topbar { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.topbar h1 { font-size: 1.5rem; margin: 0; }

.icon-btn {
  width: 44px; height: 44px; border-radius: 14px;
  background: var(--card); box-shadow: var(--shadow);
  font-size: 1.25rem; flex-shrink: 0;
}

.card {
  background: var(--card);
  border-radius: var(--radius);
  padding: 16px;
  box-shadow: var(--shadow);
}
.card h2 { font-size: 1rem; margin: 0 0 12px; color: var(--muted); font-weight: 700; }
.card-head { display: flex; justify-content: space-between; align-items: baseline; }

.segmented { display: flex; gap: 8px; flex-wrap: wrap; }
.segmented button {
  flex: 1; min-width: 56px; padding: 12px 8px; border-radius: 14px;
  background: var(--bg); font-weight: 700; font-size: 1rem; line-height: 1.25;
  border: 2px solid transparent; transition: transform .1s;
}
.segmented button.active { background: var(--primary); color: #fff; }
.segmented button:active { transform: scale(.96); }

.chips { display: flex; flex-direction: column; gap: 8px; }
.chip {
  display: flex; justify-content: space-between; align-items: center;
  padding: 14px 16px; border-radius: 14px; background: var(--bg);
  font-weight: 700; border: 2px solid transparent; text-align: left;
}
.chip .count { color: var(--muted); font-weight: 600; font-size: .9rem; }
.chip.active { border-color: var(--primary); background: #ece9ff; }
.chip.active::before { content: "✓ "; color: var(--primary); }
.chip .name { flex: 1; min-width: 0; overflow-wrap: anywhere; }

.link-btn { color: var(--primary); font-weight: 700; padding: 8px; }
.link-btn.center { align-self: center; }

.big-btn {
  width: 100%; padding: 18px; border-radius: 18px;
  background: var(--primary); color: #fff;
  font-size: 1.3rem; font-weight: 800;
  box-shadow: 0 5px 0 var(--primary-dark);
  transition: transform .08s, box-shadow .08s;
}
.big-btn:active { transform: translateY(4px); box-shadow: 0 1px 0 var(--primary-dark); }
.big-btn.secondary { background: var(--card); color: var(--primary); box-shadow: 0 5px 0 var(--border); }
.big-btn[hidden] { display: none; }

.error { color: var(--bad); font-weight: 700; text-align: center; margin: 0; }
.muted { color: var(--muted); margin: 0 0 8px; }
.status { color: var(--muted); font-size: .85rem; font-weight: 600; text-align: center; margin: 0; }

/* Abfrage */
.progress { flex: 1; height: 14px; background: var(--card); border-radius: 99px; overflow: hidden; box-shadow: inset 0 1px 3px rgba(0,0,0,.08); }
.progress-bar { height: 100%; width: 0; background: linear-gradient(90deg, #a29bfe, var(--primary)); border-radius: 99px; transition: width .4s ease; }
.counter { font-weight: 800; color: var(--muted); min-width: 48px; text-align: right; }

.question-card {
  background: var(--card); border-radius: 24px; box-shadow: var(--shadow);
  padding: 28px 16px; text-align: center; margin-top: 8px;
  animation: pop-in .35s ease;
}
.hint { margin: 0 0 12px; color: var(--muted); font-weight: 700; }
.question-row { display: flex; align-items: center; justify-content: center; gap: 10px; flex-wrap: wrap; }
.question-word { font-size: 2rem; font-weight: 800; line-height: 1.2; overflow-wrap: anywhere; }

.speak-btn {
  width: 48px; height: 48px; border-radius: 50%;
  background: var(--bg); font-size: 1.4rem; flex-shrink: 0;
  transition: transform .1s;
}
.speak-btn:active { transform: scale(.9); }
.speak-btn.small { width: 38px; height: 38px; font-size: 1.1rem; }
.speak-btn[hidden] { display: none; }

.answers { display: flex; flex-direction: column; gap: 12px; }
.answer {
  width: 100%; padding: 18px 16px; border-radius: 18px;
  background: var(--card); border: 3px solid var(--border);
  font-size: 1.3rem; font-weight: 700; text-align: center; overflow-wrap: anywhere;
  box-shadow: 0 4px 0 var(--border);
  transition: transform .08s, background .2s, border-color .2s;
  animation: slide-up .3s ease both;
}
.answer:nth-child(2) { animation-delay: .05s; }
.answer:nth-child(3) { animation-delay: .1s; }
.answer:active:not(:disabled) { transform: translateY(3px); box-shadow: 0 1px 0 var(--border); }
.answer:disabled { cursor: default; }
.answer.correct {
  background: var(--good-bg); border-color: var(--good); color: #166534;
  box-shadow: 0 0 0 6px rgba(34,197,94,.25), 0 4px 0 var(--good);
  animation: glow 0.9s ease;
}
.answer.wrong {
  background: var(--bad-bg); border-color: var(--bad); color: #991b1b;
  box-shadow: 0 4px 0 var(--bad);
  animation: shake .45s ease;
}
.answer.dim { opacity: .45; }

.feedback {
  background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow);
  padding: 16px; text-align: center; animation: pop-in .3s ease;
}
.feedback[hidden] { display: none; }
.feedback-title { font-size: 1.4rem; font-weight: 800; margin: 0 0 6px; }
.feedback-title.good { color: var(--good); }
.feedback-title.bad { color: var(--bad); }
.feedback-solution { overflow-wrap: anywhere; margin: 0 0 14px; font-size: 1.1rem; display: flex; align-items: center; justify-content: center; gap: 8px; flex-wrap: wrap; }

/* Schreiben */
.mode-note { margin: 10px 0 0; font-size: .9rem; }
.spell[hidden] { display: none; }
.spell { display: flex; flex-direction: column; gap: 20px; }
.spell-word {
  background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow);
  padding: 20px 8px; display: flex; flex-wrap: wrap; justify-content: center; gap: 4px 14px;
  font-size: clamp(1.15rem, 6.2vw, 1.8rem); font-weight: 800;
}
.spell-chunk { display: flex; gap: 3px; }
.slot {
  width: .85em; text-align: center; line-height: 1.4;
  border-bottom: 3px solid var(--border);
}
.slot.given { width: auto; border-bottom-color: transparent; color: var(--muted); font-weight: 600; }
.slot.done { border-bottom-color: var(--good); color: var(--text); }
.slot.current { border-bottom-color: var(--primary); animation: blink 1s ease infinite; }
.slot.oops { animation: shake .45s ease; border-bottom-color: var(--bad); }

.letters { display: flex; gap: 12px; }
.letter {
  flex: 1; padding: 18px 0; border-radius: 18px;
  background: var(--card); border: 3px solid var(--border);
  font-size: 2rem; font-weight: 800; line-height: 1;
  box-shadow: 0 4px 0 var(--border);
  transition: transform .08s, opacity .2s;
  animation: slide-up .3s ease both;
}
.letter:active:not(:disabled) { transform: translateY(3px); box-shadow: 0 1px 0 var(--border); }
.letter.wrong { background: var(--bad-bg); border-color: var(--bad); color: #991b1b; box-shadow: 0 4px 0 var(--bad); opacity: .55; }

/* Ergebnis */
.result-card {
  background: var(--card); border-radius: 24px; box-shadow: var(--shadow);
  padding: 28px 16px; text-align: center; margin-top: 24px;
  animation: pop-in .5s ease;
}
.stars { font-size: 3rem; letter-spacing: 6px; }
.stars span { display: inline-block; animation: star-pop .5s ease both; }
.stars span:nth-child(2) { animation-delay: .25s; }
.stars span:nth-child(3) { animation-delay: .5s; }
.stars .off { filter: grayscale(1); opacity: .3; }
.result-score { font-size: 2.2rem; font-weight: 800; margin: 8px 0 4px; }
.result-text { font-size: 1.15rem; color: var(--muted); font-weight: 700; margin: 0; }

.wrong-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 8px; }
.wrong-list li {
  display: flex; align-items: center; gap: 8px;
  padding: 10px 12px; border-radius: 12px; background: var(--bad-bg);
}
.wrong-list .pair { flex: 1; min-width: 0; overflow-wrap: anywhere; }
.wrong-list .en { font-weight: 800; }
.wrong-list .de { color: var(--muted); }

/* Einstellungen */
.toggle { display: flex; align-items: center; gap: 12px; font-weight: 700; cursor: pointer; }
.toggle input { width: 24px; height: 24px; accent-color: var(--primary); }

#confetti { position: fixed; inset: 0; width: 100%; height: 100%; pointer-events: none; z-index: 50; }

@keyframes pop-in { from { transform: scale(.9); opacity: 0; } to { transform: scale(1); opacity: 1; } }
@keyframes slide-up { from { transform: translateY(16px); opacity: 0; } to { transform: none; opacity: 1; } }
@keyframes shake {
  0%, 100% { transform: translateX(0); }
  20% { transform: translateX(-10px); }
  40% { transform: translateX(10px); }
  60% { transform: translateX(-6px); }
  80% { transform: translateX(6px); }
}
@keyframes glow {
  0% { transform: scale(1); }
  35% { transform: scale(1.06); }
  100% { transform: scale(1); }
}
@keyframes blink { 50% { border-bottom-color: var(--border); } }
@keyframes star-pop { 0% { transform: scale(0) rotate(-30deg); } 70% { transform: scale(1.3) rotate(10deg); } 100% { transform: scale(1); } }

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