:root {
  --bg: #f6f4ff;
  --surface: #ffffff;
  --surface-2: #efecfb;
  --text: #1d1a2e;
  --muted: #6b6785;
  --line: #e2def3;
  --primary: #5b4bdb;
  --primary-2: #7a6cf0;
  --primary-ink: #ffffff;
  --good: #1f9d55;
  --good-bg: #e3f7ec;
  --warn: #c27c0e;
  --warn-bg: #fff3dc;
  --bad: #d64545;
  --bad-bg: #fde8e8;
  --fire: #ff7a1a;
  --gold: #f2b705;
  --shadow: 0 2px 0 rgba(29, 26, 46, .06), 0 8px 24px rgba(91, 75, 219, .08);
  --radius: 20px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #16141f;
    --surface: #221f30;
    --surface-2: #2b2740;
    --text: #f1effa;
    --muted: #a39fbd;
    --line: #37324f;
    --primary: #8a7dff;
    --primary-2: #a497ff;
    --primary-ink: #14121c;
    --good: #4ad38a;
    --good-bg: #173326;
    --warn: #f0b44c;
    --warn-bg: #3a2d14;
    --bad: #ff7b7b;
    --bad-bg: #3d1d22;
    --shadow: 0 2px 0 rgba(0, 0, 0, .25), 0 8px 24px rgba(0, 0, 0, .25);
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #16141f; --surface: #221f30; --surface-2: #2b2740; --text: #f1effa; --muted: #a39fbd;
  --line: #37324f; --primary: #8a7dff; --primary-2: #a497ff; --primary-ink: #14121c;
  --good: #4ad38a; --good-bg: #173326; --warn: #f0b44c; --warn-bg: #3a2d14; --bad: #ff7b7b; --bad-bg: #3d1d22;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: ui-rounded, "SF Pro Rounded", "Nunito", system-ui, -apple-system, "Segoe UI", sans-serif;
  font-size: 18px;
  line-height: 1.4;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
  min-height: 100vh;
  min-height: 100dvh;
}
main {
  max-width: 760px;
  margin: 0 auto;
  padding: calc(env(safe-area-inset-top) + 20px) 16px calc(env(safe-area-inset-bottom) + 32px);
}
button { font: inherit; color: inherit; cursor: pointer; }
h1, h2, h3 { margin: 0; line-height: 1.15; }
.muted { color: var(--muted); }
.row { display: flex; align-items: center; gap: 12px; }
.spacer { flex: 1; }
.hidden { display: none !important; }

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 10px;
  min-height: 56px; padding: 0 24px;
  border: 0; border-radius: 16px;
  background: var(--surface); color: var(--text);
  font-weight: 700; font-size: 19px;
  box-shadow: inset 0 -3px 0 rgba(0, 0, 0, .08), var(--shadow);
  transition: transform .08s ease;
}
.btn:active { transform: translateY(2px); }
.btn.primary { background: var(--primary); color: var(--primary-ink); box-shadow: inset 0 -4px 0 rgba(0, 0, 0, .18); }
.btn.big { min-height: 72px; font-size: 24px; border-radius: 22px; width: 100%; }
.btn.ghost { background: transparent; box-shadow: none; color: var(--muted); }
.btn.small { min-height: 44px; padding: 0 16px; font-size: 16px; border-radius: 12px; }
.icon-btn {
  width: 48px; height: 48px; border-radius: 14px; border: 0;
  background: var(--surface); box-shadow: var(--shadow);
  display: inline-grid; place-items: center; font-size: 22px; flex: none;
}
.icon-btn:active { transform: translateY(1px); }

/* ---------- Home ---------- */
.hello { margin: 4px 0 18px; }
.hello h1 { font-size: 34px; }
.hello p { margin: 6px 0 0; color: var(--muted); }
.stats {
  display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; margin-bottom: 16px;
}
.stat {
  background: var(--surface); border-radius: var(--radius); padding: 14px 16px;
  box-shadow: var(--shadow); min-width: 0;
}
.stat .val { font-size: 28px; font-weight: 800; display: flex; align-items: center; gap: 6px; }
.stat .lbl { font-size: 14px; color: var(--muted); }
.stat.fire .val { color: var(--fire); }
.stat.gold .val { color: var(--gold); }
.levelbar { height: 8px; background: var(--surface-2); border-radius: 99px; margin-top: 8px; overflow: hidden; }
.levelbar > i { display: block; height: 100%; background: linear-gradient(90deg, var(--primary), var(--primary-2)); border-radius: 99px; }

.goal {
  background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow);
  padding: 16px; display: flex; align-items: center; gap: 16px; margin-bottom: 16px;
}
.ring { width: 64px; height: 64px; flex: none; }
.ring circle { fill: none; stroke-width: 8; }
.ring .bg { stroke: var(--surface-2); }
.ring .fg { stroke: var(--good); stroke-linecap: round; transform: rotate(-90deg); transform-origin: center; transition: stroke-dashoffset .6s ease; }
.goal h3 { font-size: 19px; }
.goal p { margin: 2px 0 0; color: var(--muted); font-size: 16px; }

.start-card {
  background: linear-gradient(135deg, var(--primary), var(--primary-2));
  color: #fff; border-radius: 26px; padding: 22px; margin-bottom: 16px;
  box-shadow: 0 10px 30px rgba(91, 75, 219, .3);
}
.start-card h2 { font-size: 26px; }
.start-card p { margin: 6px 0 16px; opacity: .92; }
.start-card .btn.big { background: #fff; color: #3b2fb0; box-shadow: inset 0 -4px 0 rgba(0, 0, 0, .12); }
.chips-mini { display: flex; flex-wrap: wrap; gap: 8px; margin: -6px 0 16px; }
.chips-mini span { background: rgba(255, 255, 255, .18); padding: 4px 10px; border-radius: 99px; font-size: 15px; }

.modes { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; margin-bottom: 24px; }
.mode {
  border: 0; background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow);
  padding: 16px 12px; text-align: center; min-height: 112px;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 6px;
}
.mode .emo { font-size: 32px; }
.mode b { font-size: 17px; }
.mode small { color: var(--muted); font-size: 14px; }
.mode:active { transform: translateY(2px); }
.mode[disabled] { opacity: .45; }

.section-title { display: flex; align-items: baseline; justify-content: space-between; margin: 8px 4px 10px; }
.section-title h2 { font-size: 22px; }
.unit-label { font-size: 14px; font-weight: 800; letter-spacing: .06em; text-transform: uppercase; color: var(--muted); margin: 16px 4px 8px; }
.sec {
  width: 100%; border: 0; text-align: left;
  display: flex; align-items: center; gap: 14px;
  background: var(--surface); border-radius: 18px; box-shadow: var(--shadow);
  padding: 14px 16px; margin-bottom: 10px; min-height: 64px;
}
.sec .check {
  width: 30px; height: 30px; border-radius: 9px; flex: none;
  border: 2.5px solid var(--line); display: grid; place-items: center; font-size: 18px; color: transparent;
}
.sec.on .check { background: var(--primary); border-color: var(--primary); color: var(--primary-ink); }
.sec:not(.on) { opacity: .6; }
.sec .info { flex: 1; min-width: 0; }
.sec .info b { display: block; font-size: 18px; }
.sec .info small { color: var(--muted); font-size: 14px; }
.bar { height: 8px; background: var(--surface-2); border-radius: 99px; overflow: hidden; margin-top: 6px; }
.bar > i { display: block; height: 100%; background: var(--good); border-radius: 99px; }
.sec .pct { font-weight: 800; font-size: 16px; color: var(--muted); width: 48px; text-align: right; }

.footer-links { display: flex; justify-content: center; gap: 8px; margin-top: 24px; flex-wrap: wrap; }

/* ---------- Session ---------- */
.topbar { display: flex; align-items: center; gap: 12px; margin-bottom: 20px; }
.progress { flex: 1; height: 16px; background: var(--surface-2); border-radius: 99px; overflow: hidden; }
.progress > i { display: block; height: 100%; background: linear-gradient(90deg, var(--good), #5fd38d); border-radius: 99px; transition: width .35s ease; }
.combo { font-weight: 800; color: var(--fire); min-width: 56px; text-align: right; font-size: 18px; }

.card {
  background: var(--surface); border-radius: 26px; box-shadow: var(--shadow);
  padding: 28px 22px; text-align: center; margin-bottom: 18px; position: relative;
}
.card .kind { font-size: 15px; font-weight: 700; color: var(--muted); text-transform: uppercase; letter-spacing: .05em; }
.card .prompt { font-size: 34px; font-weight: 800; margin: 14px 0 6px; word-wrap: break-word; }
.card .prompt.long { font-size: 26px; }
.card .ipa { color: var(--muted); font-size: 17px; font-family: "Lucida Grande", "Gentium", "Charis SIL", "Doulos SIL", system-ui, sans-serif; }
.card .speak { margin-top: 12px; }
.badge-new {
  position: absolute; top: 14px; right: 14px; background: var(--gold); color: #3a2a00;
  font-weight: 800; font-size: 13px; padding: 4px 10px; border-radius: 99px;
}
.stars { font-size: 15px; letter-spacing: 2px; color: var(--gold); }
.stars .off { color: var(--line); }

.options { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.opt {
  border: 0; background: var(--surface); border-radius: 18px; box-shadow: inset 0 -4px 0 var(--line), var(--shadow);
  padding: 16px; min-height: 84px; font-size: 20px; font-weight: 700; line-height: 1.25;
}
.opt:active { transform: translateY(2px); }
.opt.right { background: var(--good-bg); color: var(--good); box-shadow: inset 0 0 0 3px var(--good); }
.opt.wrong { background: var(--bad-bg); color: var(--bad); box-shadow: inset 0 0 0 3px var(--bad); }
.opt.dim { opacity: .45; }

.answer-input {
  width: 100%; font: inherit; font-size: 28px; font-weight: 700; text-align: center;
  padding: 16px; border-radius: 18px; border: 3px solid var(--line);
  background: var(--surface); color: var(--text); outline: none;
}
.answer-input:focus { border-color: var(--primary); }
.answer-input.right { border-color: var(--good); background: var(--good-bg); }
.answer-input.almost { border-color: var(--warn); background: var(--warn-bg); }
.answer-input.wrong { border-color: var(--bad); background: var(--bad-bg); }
.type-actions { display: flex; gap: 12px; margin-top: 12px; }
.type-actions .btn { flex: 1; }
.hint { margin-top: 12px; font-size: 22px; letter-spacing: 3px; font-weight: 700; color: var(--primary); }
.hint.sentence { letter-spacing: 0; font-size: 18px; font-weight: 600; color: var(--muted); }

.feedback {
  border-radius: 22px; padding: 18px 20px; margin-top: 16px;
  animation: pop .25s ease;
}
.feedback.right { background: var(--good-bg); }
.feedback.almost { background: var(--warn-bg); }
.feedback.wrong { background: var(--bad-bg); }
.feedback h3 { font-size: 22px; margin-bottom: 6px; }
.feedback.right h3 { color: var(--good); }
.feedback.almost h3 { color: var(--warn); }
.feedback.wrong h3 { color: var(--bad); }
.feedback .solution { font-size: 22px; font-weight: 800; }
.feedback .de { color: var(--muted); }
.feedback .extra { margin-top: 8px; font-size: 16px; }
.feedback .extra .note { color: var(--bad); }
.feedback .extra .ex { font-style: italic; }
.next-wrap { margin-top: 16px; }

.intro .prompt { margin-bottom: 0; }
.intro .de-big { font-size: 24px; font-weight: 700; color: var(--primary); margin: 12px 0 4px; }
.intro .example { margin-top: 14px; font-style: italic; color: var(--muted); }
.intro .note { margin-top: 8px; color: var(--bad); font-size: 16px; }

.yourans { text-decoration: line-through; color: var(--bad); font-weight: 700; }

/* ---------- Summary ---------- */
.summary { text-align: center; }
.summary .trophy { font-size: 84px; margin: 12px 0 4px; animation: bounce 1s ease; }
.summary h1 { font-size: 32px; }
.summary .sub { color: var(--muted); margin: 6px 0 20px; }
.sum-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; margin-bottom: 18px; }
.sum-grid .stat { text-align: center; }
.sum-grid .val { justify-content: center; }
.list-card { background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow); padding: 16px 18px; text-align: left; margin-bottom: 14px; }
.list-card h3 { font-size: 18px; margin-bottom: 8px; }
.list-card ul { margin: 0; padding: 0; list-style: none; }
.list-card li { padding: 8px 0; border-top: 1px solid var(--line); display: flex; gap: 12px; align-items: center; }
.list-card li:first-child { border-top: 0; }
.list-card li b { flex: 1; }
.new-badge { display: flex; align-items: center; gap: 12px; }
.new-badge .emo { font-size: 36px; }

/* ---------- Word list ---------- */
.wl-head { display: flex; align-items: center; gap: 12px; margin-bottom: 16px; }
.wl-head h1 { font-size: 26px; flex: 1; }
.search {
  width: 100%; font: inherit; font-size: 18px; padding: 12px 16px; border-radius: 14px;
  border: 2px solid var(--line); background: var(--surface); color: var(--text); margin-bottom: 12px; outline: none;
}
.search:focus { border-color: var(--primary); }
.wl-sec { margin-bottom: 18px; }
.wl-sec h2 { font-size: 18px; margin: 14px 4px 8px; }
.wl-item {
  background: var(--surface); border-radius: 16px; box-shadow: var(--shadow);
  padding: 12px 14px; margin-bottom: 8px; display: flex; gap: 12px; align-items: center;
}
.wl-item .t { flex: 1; min-width: 0; }
.wl-item .en { font-weight: 800; font-size: 19px; }
.wl-item .de { color: var(--muted); font-size: 16px; }
.wl-item .more { font-size: 15px; margin-top: 6px; display: none; }
.wl-item.open .more { display: block; }
.wl-item .more .note { color: var(--bad); }

/* ---------- Flashcards ---------- */
.flash {
  perspective: 1200px; height: 340px; margin-bottom: 18px; cursor: pointer;
}
.flash-inner {
  position: relative; width: 100%; height: 100%; transition: transform .45s ease; transform-style: preserve-3d;
}
.flash.flipped .flash-inner { transform: rotateY(180deg); }
.flash-face {
  position: absolute; inset: 0; backface-visibility: hidden; -webkit-backface-visibility: hidden;
  background: var(--surface); border-radius: 26px; box-shadow: var(--shadow);
  display: flex; flex-direction: column; align-items: center; justify-content: center; padding: 24px; text-align: center;
}
.flash-face.back { transform: rotateY(180deg); background: var(--surface-2); }
.flash-face .big { font-size: 34px; font-weight: 800; }
.flash-face .tap { position: absolute; bottom: 16px; color: var(--muted); font-size: 15px; }
.flash-nav { display: flex; gap: 12px; }
.flash-nav .btn { flex: 1; }

/* ---------- Badges / Settings ---------- */
.badges { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 12px; }
.bdg { background: var(--surface); border-radius: 18px; box-shadow: var(--shadow); padding: 16px 12px; text-align: center; }
.bdg .emo { font-size: 40px; }
.bdg b { display: block; font-size: 16px; margin-top: 4px; }
.bdg small { color: var(--muted); font-size: 13px; }
.bdg.locked { opacity: .4; filter: grayscale(1); }
.setting { display: flex; align-items: center; gap: 12px; background: var(--surface); border-radius: 16px; padding: 14px 16px; margin-bottom: 10px; box-shadow: var(--shadow); }
.setting .t { flex: 1; }
.switch { width: 60px; height: 36px; border-radius: 99px; background: var(--line); border: 0; position: relative; flex: none; }
.switch::after { content: ""; position: absolute; top: 4px; left: 4px; width: 28px; height: 28px; border-radius: 50%; background: #fff; transition: left .2s; box-shadow: 0 1px 3px rgba(0,0,0,.2); }
.switch.on { background: var(--good); }
.switch.on::after { left: 28px; }

/* ---------- Toast / Confetti ---------- */
#toast {
  position: fixed; left: 50%; bottom: calc(env(safe-area-inset-bottom) + 24px); transform: translate(-50%, 140%);
  background: var(--text); color: var(--bg); padding: 14px 22px; border-radius: 16px; font-weight: 700;
  transition: transform .3s ease, opacity .3s ease; z-index: 20; opacity: 0; visibility: hidden; max-width: calc(100% - 32px); text-align: center;
}
#toast.show { transform: translate(-50%, 0); opacity: 1; visibility: visible; }
#confetti { position: fixed; inset: 0; width: 100%; height: 100%; pointer-events: none; z-index: 10; }

@keyframes pop { from { transform: scale(.96); opacity: 0; } to { transform: scale(1); opacity: 1; } }
@keyframes bounce { 0% { transform: scale(.3); } 60% { transform: scale(1.15); } 100% { transform: scale(1); } }
@keyframes shake { 0%, 100% { transform: translateX(0); } 25% { transform: translateX(-8px); } 75% { transform: translateX(8px); } }
.shake { animation: shake .3s ease; }

@media (max-width: 560px) {
  .stats, .modes, .sum-grid { gap: 8px; }
  .stat { padding: 12px; }
  .stat .val { font-size: 22px; }
  .options { grid-template-columns: 1fr; }
  .card .prompt { font-size: 28px; }
  .mode { min-height: 96px; padding: 12px 6px; }
  .mode small { display: none; }
}
@media (prefers-reduced-motion: reduce) {
  * { animation: none !important; transition: none !important; }
}

/* ---------- KI-Coach & Schreibvergleich ---------- */
.modes { grid-template-columns: repeat(4, 1fr); }
@media (max-width: 700px) { .modes { grid-template-columns: repeat(2, 1fr); } }
mark { border-radius: 6px; padding: 0 2px; font-weight: 800; }
mark.good { background: var(--good-bg); color: var(--good); box-shadow: inset 0 -2px 0 var(--good); }
mark.bad { background: var(--bad-bg); color: var(--bad); box-shadow: inset 0 -2px 0 var(--bad); }
.spell { margin: 8px 0; font-size: 22px; font-weight: 700; display: grid; gap: 4px; letter-spacing: .02em; }
.spell .muted { font-size: 15px; font-weight: 600; letter-spacing: 0; margin-right: 6px; }
.ai-note { margin-top: 8px; font-size: 16px; padding: 8px 12px; border-radius: 12px; background: var(--surface); }
.feedback.pending { background: var(--surface-2); color: var(--muted); font-weight: 700; }
.dots-anim::after { content: ""; display: inline-block; width: 1.2em; text-align: left; animation: dots 1.2s steps(4) infinite; }
@keyframes dots { 0% { content: ""; } 25% { content: "."; } 50% { content: ".."; } 75% { content: "..."; } }
.gap-sentence { font-size: 26px !important; line-height: 1.35; }
.gap-blank { display: inline-block; min-width: 3.5em; border-bottom: 4px solid var(--primary); color: transparent; }
.coach-bubble {
  display: flex; gap: 12px; align-items: flex-start; text-align: left;
  background: var(--surface); border-radius: 20px; box-shadow: var(--shadow); padding: 16px 18px; margin-bottom: 14px;
  border-left: 5px solid var(--primary); animation: pop .3s ease;
}
.coach-bubble.pending { color: var(--muted); font-weight: 700; }
.coach-bubble .coach-face { font-size: 34px; line-height: 1; }
.coach-bubble p { margin: 0; font-size: 18px; font-weight: 600; }
.story-btn { margin-bottom: 14px; background: linear-gradient(135deg, #ffd34d, #ffb020); color: #3a2a00; box-shadow: inset 0 -4px 0 rgba(0,0,0,.12); }
.story { text-align: left; }
.story h2 { font-size: 26px; margin-bottom: 4px; }
.story-line { display: flex; gap: 12px; align-items: flex-start; padding: 12px 0; border-top: 1px solid var(--line); cursor: pointer; }
.story-line .en { font-size: 21px; font-weight: 600; line-height: 1.4; }
.story-line .de { color: var(--muted); margin-top: 4px; }
.story .btn { margin-top: 12px; }
.sentence-input { font-size: 22px; text-align: left; resize: none; line-height: 1.35; }
.big-stars { font-size: 30px; letter-spacing: 4px; }
