:root {
  --bg: #0f1620;
  --bg-elev: #182233;
  --bg-elev2: #202d42;
  --fg: #eef2f7;
  --fg-dim: #9aa7b8;
  --accent: #ffb700;
  --accent2: #0f4c81;
  --ok: #2ecc71;
  --bad: #ff5b5b;
  --radius: 16px;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

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

html, body {
  height: 100%;
  margin: 0;
  background: var(--bg);
  color: var(--fg);
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, sans-serif;
  overscroll-behavior-y: none;
  -webkit-user-select: none;
  user-select: none;
}

#app {
  min-height: 100vh;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  padding-top: var(--safe-top);
  padding-bottom: var(--safe-bottom);
}

/* ---------- Top bar ---------- */
.topbar {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 14px 16px 10px;
  position: sticky;
  top: 0;
  background: linear-gradient(180deg, var(--bg) 70%, transparent);
  z-index: 5;
}
.topbar h1 {
  font-size: 17px;
  font-weight: 700;
  margin: 0;
  flex: 1;
  min-width: 0;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.topbar .icon-btn { flex-shrink: 0; }
.icon-btn {
  background: var(--bg-elev);
  border: none;
  color: var(--fg);
  width: 36px;
  height: 36px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 18px;
}
.icon-btn:active { background: var(--bg-elev2); }

/* ---------- Home ---------- */
.home-header {
  padding: 4px 20px 18px;
}
.home-header .title {
  font-size: 26px;
  font-weight: 800;
  letter-spacing: -0.3px;
}
.home-header .subtitle {
  color: var(--fg-dim);
  font-size: 14px;
  margin-top: 4px;
}
.stats-row {
  display: flex;
  gap: 10px;
  padding: 0 16px 14px;
}
.stat-card {
  flex: 1;
  background: var(--bg-elev);
  border-radius: var(--radius);
  padding: 12px 14px;
  text-align: center;
}
.stat-card .num { font-size: 22px; font-weight: 800; color: var(--accent); }
.stat-card .label { font-size: 11px; color: var(--fg-dim); margin-top: 2px; }

.cat-list {
  padding: 4px 16px 24px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  flex: 1;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}
.cat-card {
  background: var(--bg-elev);
  border-radius: var(--radius);
  padding: 14px 16px;
  display: flex;
  align-items: center;
  gap: 12px;
  border: 1px solid transparent;
}
.cat-card:active { background: var(--bg-elev2); }
.cat-card .emoji { font-size: 26px; width: 34px; text-align: center; }
.cat-card .info { flex: 1; min-width: 0; }
.cat-card .name { font-weight: 600; font-size: 15px; }
.cat-card .count { color: var(--fg-dim); font-size: 12px; margin-top: 2px; }
.cat-card .progress-bar {
  height: 4px;
  background: rgba(255,255,255,0.08);
  border-radius: 2px;
  margin-top: 6px;
  overflow: hidden;
}
.cat-card .progress-fill {
  height: 100%;
  background: var(--accent);
  border-radius: 2px;
}
.cat-card .pct { font-size: 13px; font-weight: 700; color: var(--fg-dim); min-width: 34px; text-align: right; }
.cat-card.done .pct { color: var(--ok); }

.all-btn {
  margin: 4px 16px 8px;
  background: linear-gradient(135deg, var(--accent2), #12689f);
  color: #fff;
  border: none;
  border-radius: var(--radius);
  padding: 16px;
  font-size: 16px;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
}
.all-btn:active { opacity: 0.85; }

.srs-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin: 0 16px 14px;
  background: var(--bg-elev);
  border-radius: 14px;
  padding: 12px 14px;
}
.srs-row label { font-size: 13px; color: var(--fg-dim); }
.srs-row select {
  background: var(--bg-elev2);
  color: var(--fg);
  border: none;
  border-radius: 10px;
  padding: 8px 10px;
  font-size: 14px;
  font-weight: 700;
}

.streak-badge {
  display: inline-block;
  margin-left: 8px;
  background: rgba(255, 183, 0, 0.15);
  color: var(--accent);
  border-radius: 8px;
  padding: 2px 8px;
  font-size: 11px;
  font-weight: 800;
}

.special-row {
  display: flex;
  gap: 10px;
  margin: 0 16px 12px;
}
.special-btn {
  flex: 1;
  background: var(--bg-elev);
  color: var(--fg);
  border: none;
  border-radius: 14px;
  padding: 12px 10px;
  font-size: 13.5px;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
}
.special-btn:active { background: var(--bg-elev2); }
.special-btn span {
  background: rgba(255,255,255,0.1);
  border-radius: 8px;
  padding: 1px 7px;
  font-size: 12px;
  color: var(--fg-dim);
}

.hidden-item {
  background: var(--bg-elev);
  border-radius: var(--radius);
  padding: 14px 16px;
  display: flex;
  align-items: center;
  gap: 12px;
}
.hidden-item .hidden-txt { flex: 1; font-size: 14px; line-height: 1.4; }
.restore-btn {
  background: var(--accent2);
  color: #fff;
  border: none;
  border-radius: 10px;
  padding: 9px 12px;
  font-size: 12.5px;
  font-weight: 700;
  white-space: nowrap;
}
.restore-btn:active { opacity: 0.8; }
.empty-hint {
  color: var(--fg-dim);
  text-align: center;
  padding: 40px 20px;
  font-size: 14px;
}

/* ---------- Quiz ---------- */
.quiz-wrap {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 0;
}
.progress-track {
  height: 5px;
  background: var(--bg-elev);
  margin: 0 16px;
  border-radius: 3px;
  overflow: hidden;
}
.progress-track-fill {
  height: 100%;
  background: var(--accent);
  transition: width 0.25s ease;
}
.quiz-scroll {
  flex: 1;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: 18px 16px 12px;
}
.q-meta {
  color: var(--fg-dim);
  font-size: 12px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.4px;
  margin-bottom: 8px;
}
.q-text {
  font-size: 19px;
  font-weight: 700;
  line-height: 1.35;
  margin-bottom: 6px;
}
.q-hint {
  color: var(--fg-dim);
  font-size: 12.5px;
  margin-bottom: 16px;
}
.q-img {
  display: block;
  width: 100%;
  height: auto;
  object-fit: contain;
  border-radius: 14px;
  margin: 4px 0 14px;
  background: var(--bg-elev);
}
.star-btn { font-size: 19px; color: var(--fg-dim); }
.star-btn.active { color: var(--accent); }
.opt {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  background: var(--bg-elev);
  border-radius: 14px;
  padding: 14px;
  margin-bottom: 10px;
  border: 2px solid transparent;
}
.opt:active { background: var(--bg-elev2); }
.opt .box {
  width: 24px;
  height: 24px;
  border-radius: 7px;
  border: 2px solid var(--fg-dim);
  flex-shrink: 0;
  margin-top: 1px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 15px;
  font-weight: 800;
}
.opt.selected .box {
  border-color: var(--accent);
  background: var(--accent);
  color: #1a1200;
}
.opt .txt { font-size: 15.5px; line-height: 1.4; padding-top: 1px; }

.opt.correct-answer {
  border-color: var(--ok);
  background: rgba(46, 204, 113, 0.12);
}
.opt.correct-answer .box {
  border-color: var(--ok);
  background: var(--ok);
  color: #06210f;
}
.opt.wrong-answer {
  border-color: var(--bad);
  background: rgba(255, 91, 91, 0.12);
}
.opt.wrong-answer .box {
  border-color: var(--bad);
  background: var(--bad);
  color: #2b0505;
}
.opt.missed-answer {
  border-color: var(--ok);
  border-style: dashed;
}

.match-list { display: flex; flex-direction: column; gap: 10px; }
.match-row {
  display: flex;
  align-items: center;
  gap: 12px;
  background: var(--bg-elev);
  border-radius: 14px;
  padding: 12px 14px;
  border: 2px solid transparent;
  flex-wrap: wrap;
}
.match-tag {
  flex-shrink: 0;
  width: 34px;
  height: 34px;
  border-radius: 9px;
  background: rgba(255, 183, 0, 0.15);
  color: var(--accent);
  font-weight: 800;
  font-size: 15px;
  display: flex;
  align-items: center;
  justify-content: center;
}
.match-select {
  flex: 1;
  min-width: 0;
  background: var(--bg-elev2);
  color: var(--fg);
  border: none;
  border-radius: 10px;
  padding: 10px;
  font-size: 14px;
}
.match-row-ok { border-color: var(--ok); background: rgba(46, 204, 113, 0.12); }
.match-row-bad { border-color: var(--bad); background: rgba(255, 91, 91, 0.12); }
.match-correct-hint { width: 100%; font-size: 12.5px; color: var(--ok); font-weight: 700; }

.explain-box {
  margin-top: 14px;
  background: var(--bg-elev);
  border-left: 4px solid var(--accent);
  border-radius: 12px;
  padding: 14px 16px;
  font-size: 14px;
  line-height: 1.5;
}
.explain-box .head {
  font-weight: 700;
  margin-bottom: 6px;
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 13px;
}
.explain-box.ok-head .head { color: var(--ok); }
.explain-box.bad-head .head { color: var(--bad); }
.explain-box .src {
  margin-top: 8px;
  color: var(--fg-dim);
  font-size: 11.5px;
  font-style: italic;
}

.quiz-footer {
  padding: 10px 16px calc(14px + var(--safe-bottom));
  background: linear-gradient(0deg, var(--bg) 60%, transparent);
}
.btn-primary {
  width: 100%;
  background: var(--accent);
  color: #1a1200;
  border: none;
  border-radius: 14px;
  padding: 16px;
  font-size: 16px;
  font-weight: 800;
  display: block;
}
.btn-primary:active { opacity: 0.85; }
.btn-primary:disabled { opacity: 0.35; }
.btn-primary.next { background: var(--ok); color: #06210f; }

/* ---------- Result ---------- */
.result-wrap {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 24px;
  text-align: center;
}
.result-ring {
  width: 150px;
  height: 150px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  background: conic-gradient(var(--accent) calc(var(--pct) * 1%), var(--bg-elev) 0);
  margin-bottom: 20px;
}
.result-ring .inner {
  width: 122px;
  height: 122px;
  border-radius: 50%;
  background: var(--bg);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
}
.result-ring .pctnum { font-size: 30px; font-weight: 800; }
.result-ring .pctlabel { font-size: 11px; color: var(--fg-dim); }
.result-title { font-size: 20px; font-weight: 800; margin-bottom: 6px; }
.result-sub { color: var(--fg-dim); font-size: 14px; margin-bottom: 26px; }
.result-actions { width: 100%; display: flex; flex-direction: column; gap: 10px; }
.btn-secondary {
  width: 100%;
  background: var(--bg-elev);
  color: var(--fg);
  border: none;
  border-radius: 14px;
  padding: 15px;
  font-size: 15px;
  font-weight: 700;
}
.btn-secondary:active { background: var(--bg-elev2); }

::-webkit-scrollbar { display: none; }

/* V13: fragebezogene Auflösung */
.solution-title{font-weight:800;margin:12px 0 6px;font-size:1.05rem}
.reason-list{display:grid;gap:10px;margin-top:14px}
.answer-reason{padding:12px 13px;border-radius:12px;border:1px solid rgba(255,255,255,.14);line-height:1.45}
.answer-reason strong{display:block;margin-bottom:5px}
.answer-reason.reason-ok{background:rgba(32,160,92,.10);border-color:rgba(54,190,112,.35)}
.answer-reason.reason-bad{background:rgba(205,63,63,.10);border-color:rgba(230,84,84,.38)}

/* V15: Bilder, die die Antwort verraten könnten, erscheinen erst nach dem Prüfen. */
.solution-image-wrap{margin:16px 0;padding:12px;border-radius:14px;background:rgba(255,255,255,.04);border:1px solid rgba(255,255,255,.10)}
.solution-image-label{font-size:.82rem;font-weight:700;opacity:.72;margin-bottom:8px}
.solution-image-wrap .q-img{margin:0;max-height:440px;object-fit:contain}
