*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

:root {
  --purple: #534AB7;
  --purple-light: #EEEDFE;
  --purple-mid: #AFA9EC;
  --purple-dark: #3C3489;
  --green: #3B6D11;
  --green-light: #EAF3DE;
  --red: #A32D2D;
  --red-light: #FCEBEB;
  --amber: #854F0B;
  --amber-light: #FAEEDA;
  --gray-bg: #f5f5f3;
  --gray-border: rgba(0,0,0,0.12);
  --gray-border-hover: rgba(0,0,0,0.25);
  --text-primary: #1a1a18;
  --text-secondary: #6b6b67;
  --text-muted: #9a9a95;
  --white: #ffffff;
  --card-shadow: 0 1px 3px rgba(0,0,0,0.06);
  --radius-sm: 6px;
  --radius-md: 8px;
  --radius-lg: 12px;
  --radius-xl: 16px;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --gray-bg: #1e1e1c;
    --gray-border: rgba(255,255,255,0.12);
    --gray-border-hover: rgba(255,255,255,0.25);
    --text-primary: #f0ede8;
    --text-secondary: #a8a8a4;
    --text-muted: #6b6b67;
    --white: #2a2a28;
    --card-shadow: 0 1px 3px rgba(0,0,0,0.3);
    --purple-light: #26215C;
    --green-light: #173404;
    --red-light: #501313;
    --amber-light: #412402;
  }
}

:root[data-theme="dark"] {
  --gray-bg: #1e1e1c;
  --gray-border: rgba(255,255,255,0.12);
  --gray-border-hover: rgba(255,255,255,0.25);
  --text-primary: #f0ede8;
  --text-secondary: #a8a8a4;
  --text-muted: #6b6b67;
  --white: #2a2a28;
  --card-shadow: 0 1px 3px rgba(0,0,0,0.3);
  --purple-light: #26215C;
  --green-light: #173404;
  --red-light: #501313;
  --amber-light: #412402;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', system-ui, sans-serif;
  background: var(--gray-bg);
  color: var(--text-primary);
  min-height: 100vh;
  line-height: 1.5;
  transition: background 0.25s, color 0.25s;
}

#app {
  max-width: 760px;
  margin: 0 auto;
  padding: 2rem 1rem 4rem;
}

.fade-in {
  animation: fadeIn 0.35s ease;
}

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

@keyframes shake {
  0%, 100% { transform: translateX(0); }
  20%, 60% { transform: translateX(-4px); }
  40%, 80% { transform: translateX(4px); }
}

@keyframes pop {
  0%   { transform: scale(1); }
  50%  { transform: scale(1.02); }
  100% { transform: scale(1); }
}

.shake { animation: shake 0.4s ease; }
.pop   { animation: pop 0.3s ease; }

/* ─── TOP BAR ─── */
.top-actions {
  display: flex;
  justify-content: flex-end;
  margin-bottom: 0.75rem;
}

.icon-btn {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  border: 0.5px solid var(--gray-border);
  background: var(--white);
  color: var(--text-secondary);
  cursor: pointer;
  font-size: 16px;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.15s, border-color 0.15s, transform 0.15s;
}

.icon-btn:hover {
  background: var(--gray-bg);
  border-color: var(--purple);
  transform: scale(1.05);
}

/* ─── HEADER ─── */
.page-header {
  margin-bottom: 1.5rem;
}

.page-header h1 {
  font-size: 26px;
  font-weight: 700;
  color: var(--text-primary);
  margin-bottom: 6px;
  letter-spacing: -0.02em;
}

.page-header p {
  font-size: 14px;
  color: var(--text-secondary);
}

/* ─── STATS ─── */
.stats-row {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  margin-bottom: 1.5rem;
}

.stat-card {
  background: var(--white);
  border: 0.5px solid var(--gray-border);
  border-radius: var(--radius-lg);
  padding: 12px;
  text-align: center;
  box-shadow: var(--card-shadow);
}

.stat-card .stat-val {
  font-size: 20px;
  font-weight: 700;
  color: var(--purple);
}

.stat-card .stat-lbl {
  font-size: 11px;
  color: var(--text-secondary);
  margin-top: 2px;
}

/* ─── MODE TOGGLE ─── */
.mode-toggle {
  display: flex;
  gap: 6px;
  padding: 4px;
  background: var(--white);
  border: 0.5px solid var(--gray-border);
  border-radius: var(--radius-lg);
  margin-bottom: 1.25rem;
}

.mode-btn {
  flex: 1;
  padding: 10px 12px;
  border: none;
  border-radius: var(--radius-md);
  background: transparent;
  color: var(--text-secondary);
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition: background 0.15s, color 0.15s, box-shadow 0.15s;
}

.mode-btn:hover { color: var(--text-primary); }

.mode-btn.active {
  background: var(--purple-light);
  color: var(--purple);
  box-shadow: var(--card-shadow);
}

.mode-btn .mode-desc {
  display: block;
  font-size: 11px;
  font-weight: 400;
  opacity: 0.75;
  margin-top: 2px;
}

/* ─── MENU ─── */
.menu-start-btn {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  padding: 14px 20px;
  border: none;
  border-radius: var(--radius-lg);
  background: var(--purple);
  color: #fff;
  font-size: 15px;
  font-weight: 500;
  cursor: pointer;
  text-align: left;
  margin-bottom: 1.25rem;
  transition: background 0.15s, transform 0.15s, box-shadow 0.15s;
  box-shadow: 0 2px 8px rgba(83,74,183,0.25);
}

.menu-start-btn:hover {
  background: var(--purple-dark);
  transform: translateY(-1px);
  box-shadow: 0 4px 14px rgba(83,74,183,0.3);
}

.menu-start-btn:active { transform: translateY(0); }

.menu-start-btn .badge {
  margin-left: auto;
  font-size: 12px;
  opacity: 0.85;
  background: rgba(255,255,255,0.18);
  padding: 3px 10px;
  border-radius: 99px;
}

.section-label {
  font-size: 12px;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  margin-bottom: 10px;
}

.section-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 10px;
}

.section-btn {
  padding: 14px 16px;
  border: 0.5px solid var(--gray-border);
  border-radius: var(--radius-lg);
  background: var(--white);
  color: var(--text-primary);
  cursor: pointer;
  text-align: left;
  box-shadow: var(--card-shadow);
  transition: border-color 0.15s, box-shadow 0.15s, transform 0.15s;
}

.section-btn:hover {
  border-color: var(--purple);
  box-shadow: 0 4px 12px rgba(83,74,183,0.14);
  transform: translateY(-2px);
}

.section-btn:active { transform: translateY(0); }

.section-btn .s-title {
  font-size: 14px;
  font-weight: 500;
  margin-bottom: 4px;
}

.section-btn .s-count {
  font-size: 12px;
  color: var(--text-secondary);
}

.section-btn .s-progress {
  margin-top: 8px;
  height: 3px;
  background: var(--gray-border);
  border-radius: 99px;
  overflow: hidden;
}

.section-btn .s-progress-fill {
  height: 100%;
  background: var(--purple);
  border-radius: 99px;
  transition: width 0.4s ease;
}

/* ─── QUIZ ─── */
.quiz-topbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 12px;
  gap: 8px;
  flex-wrap: wrap;
}

.topbar-right {
  display: flex;
  align-items: center;
  gap: 8px;
}

.back-btn {
  background: none;
  border: none;
  color: var(--text-secondary);
  cursor: pointer;
  font-size: 13px;
  display: flex;
  align-items: center;
  gap: 5px;
  padding: 6px 0;
  transition: color 0.12s;
}

.back-btn:hover { color: var(--text-primary); }

.score-pill, .timer-pill, .streak-pill {
  font-size: 13px;
  color: var(--text-secondary);
  background: var(--white);
  border: 0.5px solid var(--gray-border);
  border-radius: 99px;
  padding: 4px 12px;
  white-space: nowrap;
}

.streak-pill {
  color: var(--amber);
  border-color: var(--amber);
  background: var(--amber-light);
}

.quiz-type-badge {
  font-size: 11px;
  font-weight: 500;
  color: var(--purple);
  background: var(--purple-light);
  border-radius: 99px;
  padding: 3px 10px;
}

.progress-wrap { margin-bottom: 1rem; }

.progress-bar-bg {
  background: var(--gray-border);
  border-radius: 99px;
  height: 6px;
  overflow: hidden;
}

.progress-bar-fill {
  background: linear-gradient(90deg, var(--purple), var(--purple-mid));
  border-radius: 99px;
  height: 6px;
  transition: width 0.4s ease;
}

.progress-segments {
  display: flex;
  gap: 3px;
  margin-top: 8px;
  flex-wrap: wrap;
}

.seg-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  border: none;
  padding: 0;
  cursor: pointer;
  background: var(--gray-border);
  transition: transform 0.12s, background 0.12s;
}

.seg-dot:hover { transform: scale(1.25); }
.seg-dot.current { background: var(--purple); transform: scale(1.2); }
.seg-dot.answered { background: var(--purple-mid); }
.seg-dot.ok { background: var(--green); }
.seg-dot.partial { background: var(--amber); }
.seg-dot.ko { background: var(--red); }

/* ─── QUESTION CARD ─── */
.question-card {
  background: var(--white);
  border: 0.5px solid var(--gray-border);
  border-radius: var(--radius-xl);
  padding: 1.5rem;
  box-shadow: var(--card-shadow);
  margin-bottom: 1rem;
}

.q-meta {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 10px;
  gap: 8px;
  flex-wrap: wrap;
}

.q-section-label {
  font-size: 11px;
  font-weight: 500;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.multi-badge {
  font-size: 11px;
  background: var(--purple-light);
  color: var(--purple);
  border-radius: 99px;
  padding: 3px 10px;
  font-weight: 500;
}

.q-text {
  font-size: 16px;
  font-weight: 500;
  color: var(--text-primary);
  line-height: 1.65;
  margin-bottom: 1.25rem;
}

.keyboard-hint {
  font-size: 11px;
  color: var(--text-muted);
  margin-bottom: 10px;
}

.keyboard-hint kbd {
  display: inline-block;
  padding: 1px 5px;
  border-radius: 4px;
  border: 0.5px solid var(--gray-border);
  background: var(--gray-bg);
  font-family: inherit;
  font-size: 10px;
}

/* ─── OPTIONS ─── */
.options {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.opt-btn {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  padding: 12px 14px;
  border: 0.5px solid var(--gray-border);
  border-radius: var(--radius-md);
  cursor: pointer;
  background: var(--gray-bg);
  text-align: left;
  font-size: 14px;
  color: var(--text-primary);
  line-height: 1.5;
  width: 100%;
  transition: background 0.12s, border-color 0.12s, transform 0.1s;
}

.opt-btn:hover:not(:disabled) {
  background: var(--white);
  border-color: var(--gray-border-hover);
  transform: translateX(2px);
}

.opt-btn:focus-visible {
  outline: 2px solid var(--purple);
  outline-offset: 2px;
}

.opt-btn .letter {
  font-size: 11px;
  font-weight: 600;
  color: var(--text-muted);
  min-width: 22px;
  height: 22px;
  border-radius: 50%;
  background: var(--gray-border);
  display: flex;
  align-items: center;
  justify-content: center;
  margin-top: 1px;
  flex-shrink: 0;
  transition: background 0.12s, color 0.12s, transform 0.12s;
}

.opt-btn.selected {
  border-color: var(--purple);
  background: var(--purple-light);
}

.opt-btn.selected .letter {
  background: var(--purple);
  color: #fff;
  transform: scale(1.1);
}

.opt-btn.correct {
  border-color: var(--green);
  background: var(--green-light);
}

.opt-btn.correct .letter {
  background: var(--green);
  color: #fff;
}

.opt-btn.wrong {
  border-color: var(--red);
  background: var(--red-light);
}

.opt-btn.wrong .letter {
  background: var(--red);
  color: #fff;
}

.opt-btn:disabled { cursor: default; }

/* ─── VALIDATE BUTTON ─── */
.validate-btn {
  margin-top: 14px;
  padding: 10px 22px;
  border-radius: var(--radius-md);
  border: none;
  background: var(--purple);
  color: #fff;
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  transition: background 0.15s, opacity 0.15s, transform 0.1s;
}

.validate-btn:hover:not(:disabled) {
  background: var(--purple-dark);
  transform: translateY(-1px);
}

.validate-btn:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

/* ─── FEEDBACK ─── */
.feedback {
  margin-top: 14px;
  font-size: 13px;
  padding: 12px 14px;
  border-radius: var(--radius-md);
  line-height: 1.6;
  border-left: 3px solid;
  animation: fadeIn 0.3s ease;
}

.feedback.ok {
  background: var(--green-light);
  color: var(--green);
  border-color: var(--green);
}

.feedback.partial {
  background: var(--amber-light);
  color: var(--amber);
  border-color: var(--amber);
}

.feedback.ko {
  background: var(--red-light);
  color: var(--red);
  border-color: var(--red);
}

.feedback strong {
  display: block;
  margin-bottom: 4px;
}

/* ─── NAV ─── */
.quiz-nav {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.nav-btn {
  padding: 9px 18px;
  border-radius: var(--radius-md);
  border: 0.5px solid var(--gray-border);
  background: var(--white);
  color: var(--text-primary);
  font-size: 14px;
  cursor: pointer;
  transition: background 0.12s, transform 0.1s;
  display: flex;
  align-items: center;
  gap: 6px;
}

.nav-btn:hover {
  background: var(--gray-bg);
  transform: translateY(-1px);
}

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

.nav-btn.primary:hover { background: var(--purple-dark); }

.nav-btn:disabled {
  opacity: 0.4;
  cursor: not-allowed;
  transform: none;
}

.nav-counter {
  font-size: 13px;
  color: var(--text-secondary);
  margin-left: auto;
}

/* ─── RESULTS ─── */
.results-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 1.5rem;
}

.score-card {
  background: var(--white);
  border: 0.5px solid var(--gray-border);
  border-radius: var(--radius-xl);
  padding: 2rem 1.5rem;
  text-align: center;
  box-shadow: var(--card-shadow);
  margin-bottom: 1.25rem;
}

.score-pct {
  font-size: 56px;
  font-weight: 700;
  color: var(--purple);
  line-height: 1;
}

.score-subtitle {
  font-size: 14px;
  color: var(--text-secondary);
  margin-top: 6px;
  margin-bottom: 1.5rem;
}

.score-message {
  font-size: 15px;
  font-weight: 500;
  color: var(--text-primary);
  margin-bottom: 1rem;
}

.score-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
}

.score-item {
  background: var(--gray-bg);
  border-radius: var(--radius-md);
  padding: 12px;
}

.score-item .val {
  font-size: 24px;
  font-weight: 600;
}

.score-item .lbl {
  font-size: 12px;
  color: var(--text-secondary);
  margin-top: 2px;
}

.val.green { color: var(--green); }
.val.red   { color: var(--red); }
.val.gray  { color: var(--text-secondary); }

.results-actions {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
}

.filter-bar {
  display: flex;
  gap: 6px;
  margin: 1.25rem 0 10px;
  flex-wrap: wrap;
}

.filter-btn {
  padding: 6px 12px;
  border-radius: 99px;
  border: 0.5px solid var(--gray-border);
  background: var(--white);
  font-size: 12px;
  cursor: pointer;
  color: var(--text-secondary);
  transition: background 0.12s, border-color 0.12s, color 0.12s;
}

.filter-btn:hover { border-color: var(--purple); color: var(--text-primary); }
.filter-btn.active {
  background: var(--purple-light);
  border-color: var(--purple);
  color: var(--purple);
  font-weight: 500;
}

/* ─── SECTION REVIEW ─── */
.review-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.review-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 14px;
  background: var(--white);
  border: 0.5px solid var(--gray-border);
  border-radius: var(--radius-md);
  cursor: pointer;
  text-align: left;
  font-size: 13px;
  color: var(--text-primary);
  transition: border-color 0.12s, transform 0.1s;
  width: 100%;
}

.review-item:hover {
  border-color: var(--purple);
  transform: translateX(3px);
}

.review-item.hidden { display: none; }

.dot {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  flex-shrink: 0;
}

.dot.ok     { background: var(--green); }
.dot.ko     { background: var(--red); }
.dot.partial { background: var(--amber); }
.dot.skip   { background: var(--text-muted); }

/* ─── CONFETTI ─── */
.confetti-piece {
  position: fixed;
  width: 8px;
  height: 8px;
  top: -10px;
  border-radius: 2px;
  pointer-events: none;
  z-index: 9999;
  animation: confettiFall linear forwards;
}

@keyframes confettiFall {
  to {
    transform: translateY(100vh) rotate(720deg);
    opacity: 0;
  }
}

@media (max-width: 480px) {
  #app { padding: 1.25rem 0.75rem 3rem; }
  .stats-row { grid-template-columns: 1fr; }
  .score-pct { font-size: 44px; }
  .mode-toggle { flex-direction: column; }
}
