:root {
  --bg: #f3f6fb;
  --card: #ffffff;
  --ink: #1c2433;
  --muted: #6b7689;
  --line: #e3e8f0;
  --soft: #eef1f7;
  --track: #dfe5ef;
  --accent: #2f6df0;
  --accent-dark: #1f55c8;
  --green: #2fb673;
  --green-bg: #e6f7ee;
  --red: #e0455a;
  --red-bg: #fdebed;
  --gold: #f0a500;
  --bar: #b9ccf6;
  --radius: 16px;
  --shadow: 0 6px 20px rgba(28, 36, 51, .08);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

/* Dunkles Design */
html[data-theme="dark"] {
  --bg: #0f141c;
  --card: #1a212e;
  --ink: #e7ecf3;
  --muted: #93a1b5;
  --line: #2a3444;
  --soft: #222c3b;
  --track: #2a3444;
  --accent: #5a8bf6;
  --accent-dark: #2f5fc8;
  --green: #2fc185;
  --green-bg: #11321f;
  --red: #ef5d72;
  --red-bg: #3a1820;
  --gold: #f0b84d;
  --bar: #2f4a7d;
  --shadow: 0 6px 20px rgba(0, 0, 0, .35);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body { margin: 0; height: 100%; }
body {
  background: var(--bg);
  color: var(--ink);
  display: flex;
  justify-content: center;
}

#app {
  width: 100%;
  max-width: 560px;
  min-height: 100vh;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  background: var(--bg);
  position: relative;
}

/* ---------- Topbar ---------- */
.topbar {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 14px 16px;
}
.topbar .btn-icon {
  background: var(--card);
  border: 1px solid var(--line);
  width: 40px; height: 40px;
  border-radius: 12px;
  font-size: 18px;
  cursor: pointer;
  flex: none;
}
.progress {
  flex: 1;
  height: 14px;
  background: var(--track);
  border-radius: 99px;
  overflow: hidden;
}
.progress > span {
  display: block;
  height: 100%;
  width: 0;
  background: var(--green);
  border-radius: 99px;
  transition: width .3s ease;
}
.hearts { font-size: 16px; flex: none; min-width: 54px; text-align: right; }

/* ---------- Generic screen ---------- */
.screen { flex: 1; padding: 8px 16px 110px; display: none; flex-direction: column; }
.screen.active { display: flex; }

h1 { font-size: 26px; margin: 8px 4px 2px; }
h2 { font-size: 20px; margin: 18px 4px 8px; }
.sub { color: var(--muted); margin: 0 4px 16px; font-size: 15px; }

/* ---------- Home cards ---------- */
.mode-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.mode-card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 18px 14px;
  cursor: pointer;
  text-align: left;
  box-shadow: var(--shadow);
  transition: transform .08s ease, border-color .15s;
  font: inherit;
  color: inherit;
}
.mode-card:active { transform: scale(.97); }
.mode-card .emoji { font-size: 28px; display: block; margin-bottom: 8px; }
.mode-card .title { font-weight: 700; font-size: 16px; }
.mode-card .desc { color: var(--muted); font-size: 13px; margin-top: 4px; }

/* ---------- Settings ---------- */
.settings { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 6px 16px; box-shadow: var(--shadow); }
.row { display: flex; align-items: center; justify-content: space-between; padding: 14px 0; border-bottom: 1px solid var(--line); gap: 12px; }
.row:last-child { border-bottom: none; }
.row label { font-weight: 600; }
.row .hint { color: var(--muted); font-size: 13px; font-weight: 400; }
.seg { display: inline-flex; background: var(--soft); border-radius: 10px; padding: 3px; }
.seg button { border: none; background: transparent; padding: 7px 12px; border-radius: 8px; font: inherit; font-weight: 600; color: var(--muted); cursor: pointer; }
.seg button.on { background: var(--card); color: var(--accent); box-shadow: 0 1px 3px rgba(0,0,0,.12); }
select { font: inherit; padding: 8px 10px; border-radius: 10px; border: 1px solid var(--line); background: var(--card); color: var(--ink); }
select option { background: var(--card); color: var(--ink); }
.switch { position: relative; width: 50px; height: 28px; flex: none; }
.switch input { opacity: 0; width: 0; height: 0; }
.slider { position: absolute; inset: 0; background: var(--track); border-radius: 99px; transition: .2s; cursor: pointer; }
.slider::before { content: ""; position: absolute; height: 22px; width: 22px; left: 3px; top: 3px; background: #fff; border-radius: 50%; transition: .2s; }
.switch input:checked + .slider { background: var(--green); }
.switch input:checked + .slider::before { transform: translateX(22px); }

/* ---------- Quiz ---------- */
.prompt-card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 28px 20px;
  text-align: center;
  box-shadow: var(--shadow);
  margin-bottom: 18px;
}
.prompt-lang { color: var(--muted); font-size: 13px; text-transform: uppercase; letter-spacing: .05em; }
.prompt-word { font-size: 32px; font-weight: 800; margin: 8px 0; line-height: 1.2; }
.prompt-sentence { color: var(--muted); font-size: 15px; font-style: italic; margin-top: 6px; }
.audio-btn {
  background: var(--accent);
  color: #fff; border: none;
  border-radius: 12px;
  padding: 10px 16px;
  font-size: 18px;
  cursor: pointer;
  display: inline-flex; align-items: center; gap: 8px;
  margin-top: 10px;
}
.audio-btn.small { padding: 6px 10px; font-size: 14px; background: var(--soft); color: var(--accent); }
.audio-btn:active { transform: scale(.95); }

.options { display: grid; gap: 12px; }
.opt {
  background: var(--card);
  border: 2px solid var(--line);
  border-radius: 14px;
  padding: 16px 18px;
  font: inherit; font-size: 17px; font-weight: 600;
  text-align: left; cursor: pointer; color: var(--ink);
  transition: border-color .1s, background .1s;
}
.opt:active { transform: scale(.99); }
.opt.correct { border-color: var(--green); background: var(--green-bg); }
.opt.wrong { border-color: var(--red); background: var(--red-bg); }
.opt:disabled { cursor: default; }

input.answer {
  width: 100%; font: inherit; font-size: 20px;
  padding: 16px; border: 2px solid var(--line);
  border-radius: 14px; background: var(--card); color: var(--ink);
}
input.answer::placeholder { color: var(--muted); }
input.answer:focus { outline: none; border-color: var(--accent); }

/* Flashcard */
.flash { cursor: pointer; }
.flash .reveal { margin-top: 16px; border-top: 1px dashed var(--line); padding-top: 16px; }
.flash .tap-hint { color: var(--muted); font-size: 14px; margin-top: 14px; }

/* Matching */
.match-cols { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.match-col { display: grid; gap: 10px; }
.match-item {
  background: var(--card); border: 2px solid var(--line);
  border-radius: 12px; padding: 14px 12px; cursor: pointer;
  font: inherit; font-weight: 600; font-size: 16px; color: var(--ink);
  text-align: center; min-height: 52px;
}
.match-item.sel { border-color: var(--accent); background: var(--soft); }
.match-item.done { opacity: .35; border-style: dashed; cursor: default; }
.match-item.bad { border-color: var(--red); background: var(--red-bg); animation: shake .3s; }
@keyframes shake { 0%,100%{transform:translateX(0)} 25%{transform:translateX(-5px)} 75%{transform:translateX(5px)} }

/* ---------- Bottom bar ---------- */
.bottombar {
  position: fixed; bottom: 0; left: 0; right: 0;
  display: flex; justify-content: center;
  background: linear-gradient(transparent, var(--bg) 30%);
  padding: 14px 16px calc(14px + env(safe-area-inset-bottom));
  pointer-events: none;
}
.bottombar .inner { width: 100%; max-width: 560px; pointer-events: auto; }
.feedback { border-radius: 14px 14px 0 0; margin: -14px -16px 12px; padding: 14px 16px; font-weight: 700; display: none; }
.feedback.ok { background: var(--green-bg); color: var(--green); display: block; }
.feedback.no { background: var(--red-bg); color: var(--red); display: block; }
.feedback .small { font-weight: 500; font-size: 14px; display: block; margin-top: 3px; color: var(--ink); }

.btn {
  width: 100%; border: none; border-radius: 14px;
  padding: 16px; font: inherit; font-size: 17px; font-weight: 800;
  cursor: pointer; color: #fff; background: var(--accent);
  box-shadow: 0 4px 0 var(--accent-dark);
}
.btn:active { transform: translateY(2px); box-shadow: 0 2px 0 var(--accent-dark); }
.btn.green { background: var(--green); box-shadow: 0 4px 0 #228a55; }
.btn.ghost { background: var(--card); color: var(--accent); border: 1px solid var(--line); box-shadow: none; }
.btn:disabled { background: var(--track); box-shadow: 0 4px 0 var(--line); color: var(--muted); cursor: default; }
.btn-row { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 10px; }
.btn-row .btn { font-size: 15px; padding: 14px 6px; }
.btn.rate-again { background: var(--red); box-shadow: 0 4px 0 #b53547; }
.btn.rate-good { background: var(--accent); box-shadow: 0 4px 0 var(--accent-dark); }
.btn.rate-easy { background: var(--green); box-shadow: 0 4px 0 #228a55; }

/* ---------- Result ---------- */
.result-card { background: var(--card); border-radius: var(--radius); padding: 28px; text-align: center; box-shadow: var(--shadow); }
.result-card .big { font-size: 52px; margin: 6px 0; }
.result-card .score { font-size: 22px; font-weight: 800; }
.stat-row { display: flex; justify-content: space-around; margin: 20px 0; }
.stat { text-align: center; }
.stat .n { font-size: 24px; font-weight: 800; }
.stat .l { color: var(--muted); font-size: 13px; }

.loading { text-align: center; color: var(--muted); margin-top: 40px; }
.tag { display: inline-block; background: var(--soft); color: var(--muted); border-radius: 8px; padding: 2px 8px; font-size: 12px; font-weight: 600; }

/* ---------- Lernen-Karte ---------- */
.learn-card {
  display: flex; align-items: center; justify-content: space-between;
  width: 100%; text-align: left; cursor: pointer; color: #fff;
  background: linear-gradient(135deg, var(--accent), #5a86f5);
  border: none; border-radius: var(--radius); padding: 22px 22px;
  box-shadow: 0 6px 18px rgba(47,109,240,.35); margin: 6px 0 12px; font: inherit;
}
.learn-card:active { transform: scale(.98); }
.lc-title { font-size: 22px; font-weight: 800; }
.lc-info { font-size: 14px; opacity: .92; margin-top: 4px; }
.lc-go { font-size: 26px; opacity: .9; }
.learn-card.empty { background: linear-gradient(135deg,#3fb27a,#56c98c); box-shadow: 0 6px 18px rgba(47,182,115,.3); }

.dash-link {
  display: flex; align-items: center; justify-content: space-between;
  width: 100%; background: var(--card); border: 1px solid var(--line);
  border-radius: 14px; padding: 16px 18px; cursor: pointer; font: inherit;
  font-weight: 700; color: var(--ink); box-shadow: var(--shadow); margin-bottom: 6px;
}
.dash-link span:last-child { color: var(--muted); font-size: 20px; }

/* ---------- Dashboard ---------- */
.dash-head { display: flex; align-items: center; gap: 10px; padding: 14px 0 6px; }
.dash-cards { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin-bottom: 18px; }
.dash-stat { background: var(--card); border: 1px solid var(--line); border-radius: 14px; padding: 16px; box-shadow: var(--shadow); }
.dash-stat .n { font-size: 28px; font-weight: 800; }
.dash-stat .l { color: var(--muted); font-size: 13px; margin-top: 2px; }
.dash-stat.hot .n { color: var(--gold); }
.dash-stat.due .n { color: var(--accent); }

.phase-list { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 8px 16px; box-shadow: var(--shadow); margin-bottom: 18px; }
.phase-row { display: flex; align-items: center; gap: 12px; padding: 10px 0; }
.phase-row .pl { width: 96px; flex: none; font-weight: 600; font-size: 14px; }
.phase-row .pl small { color: var(--muted); font-weight: 400; display: block; font-size: 11px; }
.phase-bar { flex: 1; height: 22px; background: var(--soft); border-radius: 8px; overflow: hidden; }
.phase-bar > span { display: block; height: 100%; border-radius: 8px; transition: width .4s; }
.phase-row .pc { width: 58px; text-align: right; font-weight: 700; font-variant-numeric: tabular-nums; }
.phase-row .pc small { display: block; font-weight: 500; font-size: 11px; color: var(--muted); }

/* Wissensentwicklung */
.trend-box { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; box-shadow: var(--shadow); margin-bottom: 18px; }
.trend-now { font-size: 28px; font-weight: 800; color: var(--accent); }
.trend-now span { font-size: 13px; font-weight: 500; color: var(--muted); }
.trend { display: flex; align-items: flex-end; gap: 4px; height: 96px; margin-top: 12px; }
.trend .bar { flex: 1; min-width: 6px; background: var(--bar); border-radius: 4px 4px 0 0; transition: height .4s; }
.trend .bar.today { background: var(--green); }
.trend-labels { display: flex; gap: 4px; margin-top: 4px; }
.trend-labels span { flex: 1; min-width: 6px; text-align: center; font-size: 10px; color: var(--muted); }
.ph-new > span { background: #c0c7d4; }
.ph-1 > span { background: #f0a500; } .ph-2 > span { background: #eeb84d; }
.ph-3 > span { background: #9bc34a; } .ph-4 > span { background: #5bb86a; }
.ph-5 > span { background: #3fb27a; } .ph-6 > span { background: #2f9e8f; }
.ph-done > span { background: var(--green); }

.diff-list { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 6px 16px; box-shadow: var(--shadow); margin-bottom: 18px; }
.diff-row { display: flex; justify-content: space-between; padding: 11px 0; border-bottom: 1px solid var(--line); }
.diff-row:last-child { border-bottom: none; }
.diff-row .de { font-weight: 600; } .diff-row .fr { color: var(--muted); }
.diff-row .badge { background: var(--red-bg); color: var(--red); border-radius: 8px; padding: 2px 8px; font-size: 12px; font-weight: 700; }

/* ---------- Buchstabensalat ---------- */
.built { min-height: 56px; display: flex; flex-wrap: wrap; gap: 6px; align-items: center; justify-content: center;
  background: var(--card); border: 2px dashed var(--line); border-radius: 14px; padding: 12px; margin-bottom: 14px; }
.built .ch { font-size: 22px; font-weight: 800; min-width: 26px; text-align: center; border-bottom: 3px solid var(--accent); }
.built .placeholder { color: var(--muted); font-weight: 500; font-size: 15px; }
.tiles { display: flex; flex-wrap: wrap; gap: 10px; justify-content: center; }
.tile { font: inherit; font-size: 22px; font-weight: 800; min-width: 48px; height: 52px;
  background: var(--card); border: 2px solid var(--line); border-radius: 12px; cursor: pointer; color: var(--ink); }
.tile:active { transform: scale(.92); }
.tile.used { visibility: hidden; }

/* ---------- Lückentext ---------- */
.cloze { font-size: 18px; line-height: 1.7; margin-top: 12px; }
.cloze .blank { display: inline-block; min-width: 70px; border-bottom: 3px solid var(--accent); vertical-align: middle; }
.cloze .filled { color: var(--green); font-weight: 800; border-bottom: 3px solid var(--green); padding: 0 4px; }

/* ---------- Offline-Audio (PWA) ---------- */
.btn-offline { font: inherit; font-weight: 600; padding: 8px 16px; border-radius: 10px; border: none;
  background: var(--accent); color: #fff; cursor: pointer; flex: none; }
.btn-offline:active { transform: scale(.96); }
.btn-offline:disabled { background: var(--soft); color: var(--muted); cursor: default; }
.offline-progress { padding: 4px 0 14px; }
.op-bar { height: 8px; background: var(--soft); border-radius: 99px; overflow: hidden; }
.op-bar > span { display: block; height: 100%; width: 0; background: var(--accent); border-radius: 99px; transition: width .25s ease; }
.op-text { color: var(--muted); font-size: 13px; margin-top: 6px; }
