:root {
  --bg: #eef1f7;
  --surface: #ffffff;
  --surface-alt: #f1f4fa;
  --text: #1b2536;
  --text-muted: #667085;
  --border: #dde2ee;
  --accent: #ff7a1a;
  --accent-hover: #e8690f;
  --accent-contrast: #ffffff;
  --correct: #1f9d55;
  --correct-bg: #e5f7ec;
  --incorrect: #d1393e;
  --incorrect-bg: #fbe8e8;
  --missed-bg: #fff6d9;
  --missed-border: #e0b400;
  --avatar-palette: #ff7a1a, #3a7dfa, #1fb579, #a855f7, #ef5a76, #17b3b3;
  --shadow: 0 2px 10px rgba(27, 37, 54, 0.06);
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #151d2c;
    --surface: #202b40;
    --surface-alt: #2a3650;
    --text: #f4f6fb;
    --text-muted: #99a3b8;
    --border: #33405c;
    --accent: #ff8a3d;
    --accent-hover: #ff9d5c;
    --accent-contrast: #1b2536;
    --correct: #3ec674;
    --correct-bg: #123322;
    --incorrect: #f2666b;
    --incorrect-bg: #3a1c1e;
    --missed-bg: #3a3419;
    --missed-border: #c9a400;
    --shadow: 0 4px 14px rgba(0, 0, 0, 0.35);
  }
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
}

#app {
  max-width: 560px;
  margin: 0 auto;
  padding: 1.5rem 1rem 6rem;
}

.app-header h1 {
  font-size: 1.4rem;
  font-weight: 700;
  margin: 0 0 1.5rem;
}

.view h2 {
  margin-top: 0;
  font-weight: 700;
}

/* ---- Fach-Karten ---- */
.card-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 0.7rem;
}

.subject-card {
  display: flex;
  align-items: center;
  gap: 0.9rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 18px;
  padding: 0.9rem 1.1rem;
  cursor: pointer;
  text-align: left;
  font-size: 1.05rem;
  font-weight: 600;
  color: var(--text);
  box-shadow: var(--shadow);
  min-height: 48px;
  transition: transform 0.12s ease, border-color 0.12s ease;
}

.subject-card:hover {
  border-color: var(--accent);
  transform: translateY(-1px);
}

.subject-avatar {
  flex: none;
  width: 42px;
  height: 42px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  color: #fff;
  font-size: 1.1rem;
}

/* ---- Themen-Zeilen ---- */
.checkbox-list {
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
  margin: 1rem 0;
}

.topic-row {
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 0.8rem 1rem;
  cursor: pointer;
  box-shadow: var(--shadow);
}

.topic-row-main {
  display: flex;
  align-items: center;
  gap: 0.7rem;
}

.topic-row-main input {
  width: 20px;
  height: 20px;
  accent-color: var(--accent);
  flex: none;
}

.topic-row-name {
  flex: 1;
  font-weight: 600;
}

.topic-mastery-text {
  font-size: 0.8rem;
  color: var(--text-muted);
  white-space: nowrap;
}

.topic-mastery-bar {
  height: 6px;
  border-radius: 3px;
  background: var(--surface-alt);
  overflow: hidden;
}

.topic-mastery-bar-fill {
  height: 100%;
  background: var(--accent);
  border-radius: 3px;
  transition: width 0.2s ease;
}

.select-all {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 0.6rem 0.8rem;
  cursor: pointer;
}

.actions-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  margin: 1rem 0;
  flex-wrap: wrap;
}

/* ---- Buttons ---- */
.primary-btn {
  background: var(--accent);
  color: var(--accent-contrast);
  border: none;
  border-radius: 14px;
  padding: 0.85rem 1.4rem;
  font-size: 1rem;
  font-weight: 700;
  cursor: pointer;
  min-height: 48px;
  width: 100%;
}

.primary-btn:hover:not(:disabled) {
  background: var(--accent-hover);
}

.primary-btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.link-btn {
  background: none;
  border: none;
  color: var(--text-muted);
  text-decoration: underline;
  cursor: pointer;
  font-size: 0.9rem;
  padding: 0;
}

.back-btn {
  display: block;
  margin-bottom: 0.75rem;
}

/* ---- Sticky Action-Bar (mobile-friendly) ---- */
.sticky-actions {
  position: sticky;
  bottom: 0;
  background: linear-gradient(to top, var(--bg) 60%, transparent);
  padding: 0.75rem 0 0.25rem;
  margin-top: 1rem;
}

/* ---- Quiz: Progress + Streak ---- */
.quiz-progress {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.6rem;
  flex-wrap: wrap;
  margin-bottom: 0.6rem;
}

.quiz-progress-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 0.9rem;
  color: var(--text-muted);
}

.streak-text {
  font-weight: 700;
  color: var(--accent);
}

.progress-bar {
  height: 8px;
  border-radius: 4px;
  background: var(--surface-alt);
  overflow: hidden;
  margin: 0.4rem 0 1rem;
}

.progress-bar-fill {
  height: 100%;
  background: var(--accent);
  border-radius: 4px;
  transition: width 0.25s ease;
}

/* ---- Antwort-Optionen ---- */
.options-list {
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
  margin: 1rem 0;
}

.option-item {
  display: flex;
  align-items: center;
  gap: 0.7rem;
  background: var(--surface);
  border: 2px solid var(--border);
  border-radius: 16px;
  padding: 0.7rem 0.9rem;
  cursor: pointer;
  min-height: 48px;
}

.option-item input {
  display: none;
}

.option-badge {
  flex: none;
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: var(--surface-alt);
  color: var(--text-muted);
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 0.9rem;
}

.option-item.selected {
  border-color: var(--accent);
}

.option-item.selected .option-badge {
  background: var(--accent);
  color: var(--accent-contrast);
}

.option-item.correct {
  background: var(--correct-bg);
  border-color: var(--correct);
}

.option-item.correct .option-badge {
  background: var(--correct);
  color: #fff;
}

.option-item.incorrect {
  background: var(--incorrect-bg);
  border-color: var(--incorrect);
}

.option-item.incorrect .option-badge {
  background: var(--incorrect);
  color: #fff;
}

.option-item.missed {
  background: var(--missed-bg);
  border-color: var(--missed-border);
}

.explanation {
  background: var(--surface);
  border-left: 4px solid var(--accent);
  padding: 0.7rem 1rem;
  border-radius: 8px;
  color: var(--text-muted);
}

.copy-feedback {
  color: var(--correct);
  font-size: 0.85rem;
}

.celebrate {
  font-size: 1.2rem;
}

/* ---- Ergebnis / Celebration ---- */
.result-card {
  background: var(--surface);
  border-radius: 20px;
  padding: 2rem 1.5rem;
  text-align: center;
  box-shadow: var(--shadow);
}

.result-emoji {
  font-size: 2.5rem;
}

.result-percentage {
  font-size: 3rem;
  font-weight: 800;
  color: var(--accent);
  margin: 0.2rem 0;
}

.result-message {
  font-weight: 700;
  font-size: 1.1rem;
}

.result-details {
  color: var(--text-muted);
  margin: 0.4rem 0;
}

[hidden] {
  display: none !important;
}
