:root {
  --bg: #0f1724;
  --bg-soft: #151f33;
  --card: #1b2740;
  --card-hover: #223257;
  --text: #eef2ff;
  --muted: #9aa7c2;
  --primary: #4f7dff;
  --primary-hover: #6a91ff;
  --accent: #26d07c;
  --danger: #ff5a72;
  --warn: #ffb547;
  --border: #2a3657;
  --ring: rgba(79,125,255,0.35);
  --radius: 14px;
  --radius-sm: 10px;
  --shadow: 0 10px 30px rgba(0,0,0,.35);
  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}

@media (prefers-color-scheme: light) {
  :root:not([data-theme]) {
    --bg: #f4f6fb;
    --bg-soft: #eceff7;
    --card: #ffffff;
    --card-hover: #f5f7ff;
    --text: #0f1724;
    --muted: #5a6785;
    --border: #e1e5f0;
    --shadow: 0 6px 24px rgba(15,23,36,.08);
  }
}

:root[data-theme="light"] {
  --bg: #f4f6fb;
  --bg-soft: #eceff7;
  --card: #ffffff;
  --card-hover: #f5f7ff;
  --text: #0f1724;
  --muted: #5a6785;
  --border: #e1e5f0;
  --shadow: 0 6px 24px rgba(15,23,36,.08);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
}

body {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}

.app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 20px;
  gap: 12px;
  background: linear-gradient(180deg, rgba(79,125,255,.08), transparent);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 10;
  backdrop-filter: blur(8px);
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
}

.logo {
  font-size: 28px;
  line-height: 1;
  filter: drop-shadow(0 4px 8px rgba(79,125,255,.35));
}

.app-header h1 {
  font-size: 18px;
  margin: 0;
  letter-spacing: -0.01em;
}

.subtitle {
  font-size: 12px;
  color: var(--muted);
  margin: 2px 0 0 0;
}

.header-actions {
  display: flex;
  gap: 8px;
  align-items: center;
}

.user-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 4px 4px 12px;
  background: var(--bg-soft);
  border: 1px solid var(--border);
  border-radius: 999px;
  font-size: 13px;
  font-weight: 600;
}
.user-chip #userName { color: var(--text); }
.icon-btn {
  width: 26px;
  height: 26px;
  border-radius: 999px;
  border: none;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  font-size: 14px;
  display: grid;
  place-items: center;
}
.icon-btn:hover { background: var(--card-hover); color: var(--text); }

main {
  flex: 1;
  max-width: 820px;
  width: 100%;
  margin: 0 auto;
  padding: 20px;
}

.app-footer {
  padding: 16px 20px;
  text-align: center;
  color: var(--muted);
  border-top: 1px solid var(--border);
}

.screen {
  display: none;
  animation: fade .25s ease;
}
.screen.active { display: block; }

@keyframes fade {
  from { opacity: 0; transform: translateY(6px); }
  to   { opacity: 1; transform: translateY(0); }
}

.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 24px;
  box-shadow: var(--shadow);
}

.hero h2 {
  margin-top: 0;
  font-size: 22px;
  letter-spacing: -0.01em;
}

.hero p {
  color: var(--muted);
  line-height: 1.55;
}

/* Auth */
.auth-card { max-width: 420px; margin: 20px auto; }

.tabs {
  display: flex;
  gap: 6px;
  margin-bottom: 18px;
  border-bottom: 1px solid var(--border);
}
.tab {
  flex: 1;
  background: transparent;
  border: none;
  color: var(--muted);
  padding: 10px 0;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  border-bottom: 2px solid transparent;
  transition: color .15s, border-color .15s;
  font-family: inherit;
}
.tab.active {
  color: var(--text);
  border-bottom-color: var(--primary);
}

[hidden] { display: none !important; }

.auth-form {
  display: flex;
  flex-direction: column;
  gap: 14px;
}
.auth-form .field small { color: var(--muted); font-weight: 400; font-size: 11px; margin-left: 4px; }

.form-error {
  background: rgba(255,90,114,.12);
  color: var(--danger);
  border: 1px solid rgba(255,90,114,.35);
  border-radius: var(--radius-sm);
  padding: 10px 12px;
  font-size: 13px;
}

.form-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 14px;
  margin: 20px 0;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-size: 14px;
  color: var(--muted);
}

.field select,
.field input {
  appearance: none;
  -webkit-appearance: none;
  background: var(--bg-soft);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 12px 14px;
  font-size: 15px;
  font-family: inherit;
  outline: none;
  transition: border-color .15s, box-shadow .15s;
}

.field select:focus,
.field input:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px var(--ring);
}

.actions {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  margin-top: 8px;
}

.btn {
  appearance: none;
  border: 1px solid transparent;
  background: var(--card-hover);
  color: var(--text);
  padding: 12px 20px;
  border-radius: var(--radius-sm);
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
  font-family: inherit;
  transition: transform .08s, background .15s, border-color .15s, opacity .15s;
}

.btn:hover { background: var(--card-hover); }
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: .45; cursor: not-allowed; }

.btn-primary {
  background: var(--primary);
  color: #fff;
  border-color: transparent;
}
.btn-primary:hover { background: var(--primary-hover); }

.btn-ghost {
  background: transparent;
  border-color: var(--border);
  color: var(--text);
}
.btn-ghost:hover { background: var(--bg-soft); }

.stats {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
  margin-top: 24px;
}
.stat {
  background: var(--bg-soft);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 14px;
  text-align: center;
}
.stat strong { display: block; font-size: 20px; }
.stat span { color: var(--muted); font-size: 12px; }

.muted { color: var(--muted); }
.small { font-size: 12px; }

/* Quiz */
.quiz-top { margin-bottom: 16px; }
.progress {
  height: 8px;
  background: var(--bg-soft);
  border-radius: 999px;
  overflow: hidden;
  border: 1px solid var(--border);
}
.progress-bar {
  height: 100%;
  background: linear-gradient(90deg, var(--primary), var(--accent));
  width: 0%;
  transition: width .3s ease;
}

.quiz-meta {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-top: 10px;
  font-size: 13px;
  color: var(--muted);
}
.badge {
  background: var(--bg-soft);
  border: 1px solid var(--border);
  padding: 4px 10px;
  border-radius: 999px;
  font-size: 12px;
  text-transform: capitalize;
}

#questionText {
  margin: 0 0 20px;
  font-size: 19px;
  line-height: 1.45;
  letter-spacing: -0.01em;
}

.answers {
  list-style: none;
  margin: 0 0 16px;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.answer {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 14px 16px;
  background: var(--bg-soft);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  cursor: pointer;
  font-size: 15px;
  line-height: 1.4;
  transition: background .15s, border-color .15s, transform .08s;
  user-select: none;
}

.answer:hover { background: var(--card-hover); border-color: var(--primary); }
.answer:active { transform: translateY(1px); }

.answer.selected { border-color: var(--primary); background: var(--card-hover); }
.answer.correct { border-color: var(--accent); background: rgba(38, 208, 124, .12); }
.answer.wrong { border-color: var(--danger); background: rgba(255, 90, 114, .12); }
.answer.locked { cursor: default; }

.answer-marker {
  width: 26px;
  height: 26px;
  min-width: 26px;
  border-radius: 999px;
  background: var(--bg);
  border: 1px solid var(--border);
  display: grid;
  place-items: center;
  font-size: 12px;
  font-weight: 700;
  color: var(--muted);
}
.answer.correct .answer-marker { background: var(--accent); color: #fff; border-color: transparent; }
.answer.wrong .answer-marker { background: var(--danger); color: #fff; border-color: transparent; }

.quiz-footer {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  margin-top: 10px;
}

/* Celebration für „früher falsch, jetzt richtig" */
.cheer {
  display: flex;
  align-items: center;
  gap: 10px;
  margin: 12px 0 0;
  padding: 12px 14px;
  border-radius: var(--radius-sm);
  background: linear-gradient(135deg, rgba(38,208,124,.18), rgba(79,125,255,.18));
  border: 1px solid rgba(38,208,124,.45);
  color: var(--text);
  font-weight: 600;
  animation: cheer-pop 420ms cubic-bezier(.18,.9,.35,1.3);
}
.cheer-emoji {
  font-size: 24px;
  animation: cheer-wiggle 700ms ease-in-out;
  display: inline-block;
}
.cheer-text { font-size: 15px; line-height: 1.3; }

@keyframes cheer-pop {
  0%   { transform: scale(.85) translateY(6px); opacity: 0; }
  60%  { transform: scale(1.04) translateY(0);  opacity: 1; }
  100% { transform: scale(1)    translateY(0);  opacity: 1; }
}
@keyframes cheer-wiggle {
  0%, 100% { transform: rotate(0); }
  25%      { transform: rotate(-14deg) scale(1.1); }
  55%      { transform: rotate(12deg)  scale(1.1); }
  80%      { transform: rotate(-6deg); }
}

/* Theme-Toggle-Button */
.theme-toggle {
  font-size: 16px;
  line-height: 1;
}
:root[data-theme="light"] .theme-toggle,
:root:not([data-theme]) .theme-toggle { /* Standardanzeige */ }

/* Ergebnis */
.result-card { text-align: center; }
.score-ring {
  width: 160px;
  height: 160px;
  border-radius: 50%;
  margin: 16px auto 12px;
  background: conic-gradient(var(--accent) 0%, var(--bg-soft) 0%);
  display: grid;
  place-items: center;
  position: relative;
  transition: background 1s ease;
}
.score-ring::before {
  content: "";
  position: absolute;
  inset: 10px;
  background: var(--card);
  border-radius: 50%;
}
#scorePercent {
  position: relative;
  font-size: 32px;
  font-weight: 700;
  letter-spacing: -0.02em;
}

.score-detail { color: var(--muted); margin: 0 0 6px; }
.score-msg { font-weight: 600; margin: 6px 0 18px; }

.review-list {
  text-align: left;
  margin-top: 20px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.review-item {
  padding: 14px 16px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--bg-soft);
}
.review-item.correct { border-color: rgba(38,208,124,.5); }
.review-item.wrong { border-color: rgba(255,90,114,.55); }
.review-item.skipped { border-color: rgba(255,181,71,.55); }

.review-q { font-weight: 600; margin: 0 0 8px; }
.review-a { font-size: 14px; color: var(--muted); margin: 2px 0; }
.review-a.highlight-correct { color: var(--accent); }
.review-a.highlight-wrong { color: var(--danger); }

.review-tag {
  display: inline-block;
  font-size: 11px;
  padding: 2px 8px;
  border-radius: 999px;
  margin-left: 8px;
  vertical-align: middle;
}
.review-tag.correct { background: rgba(38,208,124,.18); color: var(--accent); }
.review-tag.wrong { background: rgba(255,90,114,.18); color: var(--danger); }
.review-tag.skipped { background: rgba(255,181,71,.18); color: var(--warn); }

/* History */
.row-between {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 10px;
}

.cat-summary {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 10px;
  margin-bottom: 18px;
}
.cat-summary .cat {
  background: var(--bg-soft);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 12px 14px;
}
.cat .cat-name { font-weight: 600; font-size: 13px; margin-bottom: 4px; }
.cat .cat-nums { font-size: 12px; color: var(--muted); }

.history-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.history-list li {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 6px 12px;
  padding: 10px 14px;
  background: var(--bg-soft);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 14px;
}
.history-list .hx-date { color: var(--muted); font-size: 12px; grid-column: 1 / -1; }
.history-list .hx-cat { font-weight: 600; }
.history-list .hx-score { font-weight: 700; }
.history-list .hx-score.good { color: var(--accent); }
.history-list .hx-score.mid  { color: var(--warn); }
.history-list .hx-score.low  { color: var(--danger); }

@media (max-width: 520px) {
  .app-header h1 { font-size: 16px; }
  main { padding: 14px; }
  .card { padding: 18px; }
  #questionText { font-size: 17px; }
  .stats { grid-template-columns: 1fr 1fr; }
  .header-actions .btn { display: none; }
}
