/* === Reset & base === */
*, *::before, *::after { box-sizing: border-box; }
html, body { margin: 0; padding: 0; height: 100%; }

:root {
  --bg: #f4f7fb;
  --surface: #ffffff;
  --primary: #1a4d7a;
  --primary-dark: #143a5c;
  --primary-light: #e8f1fa;
  --accent: #2a8b5a;
  --accent-light: #e6f4ed;
  --danger: #c93535;
  --danger-light: #fbeaea;
  --warn: #c47b08;
  --text: #1a2a3a;
  --text-soft: #5a6a7a;
  --border: #d8e1ea;
  --shadow: 0 2px 12px rgba(20, 50, 90, 0.08);
  --radius: 14px;
  --radius-lg: 20px;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", system-ui, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 17px;
  line-height: 1.5;
  -webkit-tap-highlight-color: transparent;
}

#app {
  max-width: 720px;
  margin: 0 auto;
  min-height: 100vh;
  padding: 20px 16px 40px;
}

/* === Screen system === */
.screen { display: none; }
.screen.active { display: block; animation: fadeIn 200ms ease-out; }

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

.hidden { display: none !important; }

/* === Headers === */
.home-header {
  text-align: center;
  padding: 24px 0 32px;
}
.home-header h1 {
  font-size: 32px;
  margin: 0 0 4px;
  color: var(--primary);
  font-weight: 800;
  letter-spacing: -0.5px;
}
.home-header .subtitle {
  margin: 0;
  color: var(--text-soft);
  font-size: 17px;
}

.quiz-header {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 0 24px;
}
.quiz-header h2 {
  margin: 0;
  font-size: 22px;
  color: var(--primary);
}

.btn-back {
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--primary);
  font-size: 22px;
  width: 44px;
  height: 44px;
  border-radius: 50%;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}
.btn-back:active { transform: scale(0.95); }

/* === Stats card === */
.stats-card {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  background: var(--surface);
  border-radius: var(--radius-lg);
  padding: 18px 12px;
  box-shadow: var(--shadow);
  margin-bottom: 28px;
}
.stat { text-align: center; }
.stat-value {
  font-size: 26px;
  font-weight: 800;
  color: var(--primary);
  line-height: 1;
}
.stat-label {
  font-size: 12px;
  color: var(--text-soft);
  margin-top: 6px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

/* === Mode buttons === */
.mode-buttons {
  display: grid;
  gap: 14px;
}

.btn {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 18px 20px;
  border: none;
  border-radius: var(--radius-lg);
  cursor: pointer;
  font-family: inherit;
  font-size: 17px;
  text-align: left;
  width: 100%;
  transition: transform 100ms ease, box-shadow 200ms;
  -webkit-tap-highlight-color: transparent;
}
.btn:active { transform: scale(0.98); }

.btn-primary {
  background: var(--primary);
  color: white;
  box-shadow: var(--shadow);
}
.btn-primary:hover { background: var(--primary-dark); }

.btn-secondary {
  background: var(--surface);
  color: var(--primary);
  border: 1px solid var(--border);
}

.btn-icon {
  font-size: 28px;
  flex-shrink: 0;
}
.btn-text {
  display: flex;
  flex-direction: column;
  gap: 2px;
  flex: 1;
}
.btn-text strong { font-size: 18px; font-weight: 700; }
.btn-text small { font-size: 13px; opacity: 0.85; font-weight: 400; }

.reset-row {
  text-align: center;
  margin-top: 32px;
}
.btn-link {
  background: none;
  border: none;
  color: var(--text-soft);
  text-decoration: underline;
  cursor: pointer;
  font-size: 14px;
  padding: 8px;
}

/* === Category list === */
.category-list {
  display: grid;
  gap: 12px;
}
.category-item {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px 18px;
  cursor: pointer;
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-family: inherit;
  font-size: 16px;
  text-align: left;
  width: 100%;
  color: var(--text);
}
.category-item:active { transform: scale(0.98); }
.category-item .cat-name { font-weight: 600; }
.category-item .cat-count {
  background: var(--primary-light);
  color: var(--primary);
  font-size: 13px;
  font-weight: 700;
  padding: 4px 10px;
  border-radius: 10px;
}

/* === Quiz === */
.progress-bar {
  flex: 1;
  height: 8px;
  background: var(--border);
  border-radius: 4px;
  overflow: hidden;
}
.progress-fill {
  height: 100%;
  background: var(--accent);
  transition: width 300ms ease;
  width: 0%;
}
.progress-text {
  font-size: 14px;
  color: var(--text-soft);
  font-weight: 600;
  min-width: 50px;
  text-align: right;
}

.quiz-content {
  background: var(--surface);
  border-radius: var(--radius-lg);
  padding: 22px;
  box-shadow: var(--shadow);
}

.category-tag {
  display: inline-block;
  background: var(--primary-light);
  color: var(--primary);
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  padding: 5px 10px;
  border-radius: 8px;
  margin-bottom: 16px;
}

.question-row {
  display: flex;
  gap: 12px;
  align-items: flex-start;
  margin-bottom: 24px;
}
.question {
  font-size: 22px;
  font-weight: 700;
  margin: 0;
  flex: 1;
  line-height: 1.35;
}

.btn-tts {
  background: var(--primary-light);
  border: none;
  color: var(--primary);
  font-size: 22px;
  width: 44px;
  height: 44px;
  border-radius: 12px;
  cursor: pointer;
  flex-shrink: 0;
}
.btn-tts.active {
  background: var(--accent);
  color: white;
}

.choices {
  display: grid;
  gap: 10px;
}
.choice {
  background: var(--surface);
  border: 2px solid var(--border);
  border-radius: var(--radius);
  padding: 16px 18px;
  cursor: pointer;
  font-family: inherit;
  font-size: 17px;
  text-align: left;
  display: flex;
  align-items: center;
  gap: 12px;
  color: var(--text);
  transition: all 150ms;
  -webkit-tap-highlight-color: transparent;
}
.choice:hover { border-color: var(--primary); background: var(--primary-light); }
.choice:active { transform: scale(0.99); }
.choice.disabled { pointer-events: none; }
.choice .choice-letter {
  background: var(--primary-light);
  color: var(--primary);
  width: 32px;
  height: 32px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  flex-shrink: 0;
  transition: all 150ms;
}
.choice.correct {
  border-color: var(--accent);
  background: var(--accent-light);
}
.choice.correct .choice-letter {
  background: var(--accent);
  color: white;
}
.choice.wrong {
  border-color: var(--danger);
  background: var(--danger-light);
}
.choice.wrong .choice-letter {
  background: var(--danger);
  color: white;
}

/* === Feedback === */
.feedback {
  margin-top: 24px;
  padding: 18px;
  border-radius: var(--radius);
  background: var(--bg);
  border-left: 4px solid var(--primary);
  animation: fadeIn 250ms ease-out;
}
.feedback.is-correct { border-left-color: var(--accent); background: var(--accent-light); }
.feedback.is-wrong { border-left-color: var(--danger); background: var(--danger-light); }

.feedback-icon { font-size: 32px; margin-bottom: 6px; }
.feedback-text {
  font-size: 18px;
  font-weight: 700;
  margin-bottom: 8px;
}
.explanation { font-size: 16px; line-height: 1.5; color: var(--text); }

.ai-explanation {
  margin-top: 14px;
  padding-top: 14px;
  border-top: 1px solid var(--border);
}
.ai-loading {
  font-size: 14px;
  color: var(--text-soft);
  font-style: italic;
}
.ai-content {
  font-size: 16px;
  line-height: 1.6;
  white-space: pre-wrap;
}
.ai-content strong { color: var(--primary); }

.feedback-actions {
  display: grid;
  gap: 10px;
  margin-top: 18px;
}
.feedback-actions .btn {
  padding: 14px 16px;
  font-size: 16px;
  justify-content: center;
}

/* === Results === */
.results-content {
  background: var(--surface);
  border-radius: var(--radius-lg);
  padding: 32px 24px;
  box-shadow: var(--shadow);
  text-align: center;
  margin-top: 40px;
}
.results-icon { font-size: 64px; margin-bottom: 12px; }
.results-content h2 {
  font-size: 26px;
  margin: 0 0 24px;
  color: var(--primary);
}
.results-score { margin: 24px 0; }
.score-big {
  font-size: 64px;
  font-weight: 800;
  line-height: 1;
  color: var(--primary);
}
.score-big.pass { color: var(--accent); }
.score-big.fail { color: var(--danger); }
.score-text {
  font-size: 16px;
  color: var(--text-soft);
  margin-top: 6px;
}
.results-detail {
  background: var(--bg);
  border-radius: var(--radius);
  padding: 16px;
  margin: 20px 0;
  font-size: 15px;
  text-align: left;
}
.results-actions {
  display: grid;
  gap: 10px;
  margin-top: 24px;
}

/* === Mobile-first tweaks === */
@media (min-width: 600px) {
  body { font-size: 18px; }
  .home-header h1 { font-size: 38px; }
  .question { font-size: 24px; }
}

/* === Tap-target safety === */
button, .choice {
  min-height: 48px;
}

/* Smooth scroll */
html { scroll-behavior: smooth; }
