/* Tokens follow DESIGN.md. OKLCH only - no #000/#fff. Neutrals are tinted
   slightly toward the indigo brand hue (chroma ~0.02-0.03). */
:root {
  --bg: oklch(0.18 0.02 270);
  --bg-soft: oklch(0.21 0.022 270);
  --surface: oklch(0.235 0.025 270);
  --surface-2: oklch(0.27 0.028 270);
  --border: oklch(0.32 0.03 270);
  --text: oklch(0.97 0.004 270);
  --text-muted: oklch(0.7 0.01 270);
  --accent: oklch(0.65 0.16 280);
  --accent-strong: oklch(0.74 0.14 280);
  --accent-bg: oklch(0.27 0.04 280);
  --success: oklch(0.7 0.17 145);
  --success-bg: oklch(0.27 0.05 150);
  --error: oklch(0.65 0.21 25);
  --error-bg: oklch(0.28 0.07 25);
  --warning: oklch(0.78 0.16 75);
  --radius: 14px;
  --shadow: 0 10px 30px -10px oklch(0 0 0 / 0.45);
  --focus-ring: 0 0 0 3px oklch(0.65 0.16 280 / 0.45);
  --font: "Inter", -apple-system, BlinkMacSystemFont, "SF Pro Text",
    "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  --ease: cubic-bezier(0.22, 1, 0.36, 1); /* ease-out-quart */
}

* {
  box-sizing: border-box;
}

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

.hidden {
  display: none !important;
}

.muted {
  color: var(--text-muted);
}

.topbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 16px 28px;
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  background: var(--bg);
  z-index: 5;
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  font-weight: 600;
  letter-spacing: 0.01em;
}

.brand-mark {
  background: var(--accent-bg);
  color: var(--accent-strong);
  padding: 5px 10px;
  border-radius: 6px;
  font-size: 12px;
  letter-spacing: 0.06em;
  font-weight: 700;
  border: 1px solid oklch(0.65 0.16 280 / 0.3);
}

.brand-name {
  font-size: 15px;
  color: var(--text);
}

.session-stats {
  display: flex;
  gap: 22px;
  font-size: 14px;
  color: var(--text-muted);
}

.session-stats strong {
  color: var(--text);
  font-weight: 600;
}

#stat-percent {
  padding: 3px 10px;
  border-radius: 999px;
  background: var(--surface-2);
  color: var(--text);
  font-weight: 600;
  font-size: 13px;
}

main {
  max-width: 820px;
  margin: 48px auto 80px;
  padding: 0 24px;
}

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

.setup h1,
.results-screen h1,
#results-screen h1 {
  margin: 0 0 12px;
  font-size: 28px;
  letter-spacing: -0.01em;
}

.setup .lead {
  color: var(--text-muted);
  line-height: 1.5;
  margin-top: 0;
  margin-bottom: 28px;
}

.control {
  margin-bottom: 22px;
}

.control label {
  display: block;
  font-weight: 600;
  margin-bottom: 8px;
  font-size: 14px;
}

.slider-row {
  display: flex;
  align-items: center;
  gap: 16px;
  background: var(--surface-2);
  padding: 14px 18px;
  border-radius: 10px;
  border: 1px solid var(--border);
}

.slider-row input[type="range"] {
  flex: 1;
  accent-color: var(--accent);
}

.slider-row output {
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  background: var(--accent-bg);
  color: var(--accent-strong);
  padding: 4px 12px;
  border-radius: 8px;
  font-size: 14px;
  min-width: 38px;
  text-align: center;
  border: 1px solid oklch(0.65 0.16 280 / 0.3);
}

.checkbox {
  display: flex;
  align-items: center;
  gap: 10px;
  cursor: pointer;
  font-weight: 500;
  font-size: 14px;
}

button {
  font-family: inherit;
  font-size: 15px;
  cursor: pointer;
  border-radius: 10px;
  border: 1px solid transparent;
  padding: 12px 22px;
  font-weight: 600;
  min-height: 44px;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
  transition: background 0.15s var(--ease), border-color 0.15s var(--ease),
    color 0.15s var(--ease), opacity 0.15s var(--ease);
}

button:focus-visible {
  outline: none;
  box-shadow: var(--focus-ring);
}

button:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

button.primary {
  background: var(--accent);
  color: var(--text);
  border-color: var(--accent);
}

button.primary:not(:disabled):hover {
  background: var(--accent-strong);
  border-color: var(--accent-strong);
}

button.primary:not(:disabled):active {
  background: oklch(0.58 0.16 280);
}

button.ghost {
  background: transparent;
  color: var(--text-muted);
  border: 1px solid var(--border);
}

button.ghost:hover {
  color: var(--text);
  background: var(--surface-2);
  border-color: var(--accent-strong);
}

.question-meta {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  font-size: 13px;
  color: var(--text-muted);
  margin-bottom: 14px;
}

.question-text {
  font-size: 19px;
  line-height: 1.55;
  margin: 0 0 24px;
  font-weight: 500;
}

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

.option {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  padding: 14px 16px;
  border: 1px solid var(--border);
  background: var(--surface-2);
  border-radius: 10px;
  cursor: pointer;
  transition: border-color 0.15s, background 0.15s, transform 0.05s;
  text-align: left;
  width: 100%;
  color: var(--text);
  font-family: inherit;
  font-size: 15px;
  line-height: 1.45;
}

.option:hover:not(:disabled) {
  border-color: var(--accent-strong);
  background: oklch(0.29 0.035 275);
}

.option:focus-visible {
  outline: none;
  border-color: var(--accent-strong);
  box-shadow: var(--focus-ring);
}

.option:disabled {
  cursor: default;
}

.option .letter {
  flex: 0 0 28px;
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: var(--bg-soft);
  border: 1px solid var(--border);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 13px;
  color: var(--text-muted);
}

.option .text {
  flex: 1;
}

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

.option.correct .letter {
  background: var(--success);
  color: oklch(0.15 0.04 150);
  border-color: var(--success);
}

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

.option.incorrect .letter {
  background: var(--error);
  color: oklch(0.99 0.01 25);
  border-color: var(--error);
}

.option.dimmed {
  opacity: 0.55;
}

.option.selected {
  border-color: var(--accent-strong);
  background: var(--accent-bg);
}

.option.selected .letter {
  background: var(--accent);
  color: var(--text);
  border-color: var(--accent);
}

.option.missed {
  border-color: var(--warning);
  background: oklch(0.78 0.16 75 / 0.08);
}

.option.missed .letter {
  background: var(--warning);
  color: oklch(0.18 0.04 75);
  border-color: var(--warning);
}

.multi-hint {
  font-size: 13px;
  color: var(--accent-strong);
  font-weight: 600;
  background: var(--accent-bg);
  padding: 3px 10px;
  border-radius: 999px;
  margin-left: 6px;
  vertical-align: middle;
  white-space: nowrap;
}

.action-group {
  display: flex;
  gap: 10px;
}

.hint {
  display: block;
  font-size: 12px;
  color: var(--text-muted);
  font-weight: 400;
  margin-top: 2px;
}

.modal-overlay {
  position: fixed;
  inset: 0;
  background: oklch(0.1 0.02 270 / 0.78);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
  animation: fadeIn 0.15s var(--ease);
}

.modal {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 28px;
  max-width: 420px;
  width: calc(100% - 32px);
  animation: popIn 0.18s ease-out;
}

.modal h3 {
  margin: 0 0 10px;
  font-size: 20px;
  letter-spacing: -0.01em;
}

.modal-body {
  margin: 0 0 22px;
  color: var(--text-muted);
  line-height: 1.55;
  font-size: 14px;
}

.modal-actions {
  display: flex;
  gap: 10px;
  justify-content: flex-end;
}

@keyframes fadeIn {
  from {
    opacity: 0;
  }
  to {
    opacity: 1;
  }
}

@keyframes popIn {
  from {
    opacity: 0;
    transform: scale(0.96);
  }
  to {
    opacity: 1;
    transform: scale(1);
  }
}

.feedback {
  border-radius: 12px;
  padding: 18px 20px;
  margin-bottom: 24px;
  border: 1px solid var(--border);
  background: var(--surface-2);
  animation: slideIn 0.25s ease-out;
}

.feedback.correct {
  border-color: var(--success);
  background: oklch(0.27 0.05 150 / 0.35);
}

.feedback.incorrect {
  border-color: var(--error);
  background: oklch(0.28 0.07 25 / 0.35);
}

.feedback-header {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 10px;
}

.feedback-icon {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  color: var(--text);
  font-size: 16px;
}

.feedback.correct .feedback-icon {
  background: var(--success);
  color: oklch(0.15 0.04 150);
}

.feedback.incorrect .feedback-icon {
  background: var(--error);
  color: oklch(0.99 0.01 25);
}

.feedback-title {
  font-size: 17px;
  font-weight: 700;
}

.feedback-body h3 {
  margin: 6px 0 6px;
  font-size: 13px;
  text-transform: uppercase;
  letter-spacing: 0.07em;
  color: var(--text-muted);
  font-weight: 700;
}

.feedback-body p {
  margin: 0;
  line-height: 1.55;
  white-space: pre-wrap;
  font-size: 15px;
}

.quiz-actions {
  display: flex;
  justify-content: space-between;
  gap: 12px;
}

.quiz-actions.center {
  justify-content: center;
}

.results-eyebrow {
  display: inline-block;
  font-size: 12px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  font-weight: 700;
  color: var(--accent-strong);
  margin-bottom: 10px;
}

.results-headline {
  font-size: 28px;
  font-weight: 600;
  letter-spacing: -0.01em;
  margin: 0 0 18px;
  line-height: 1.25;
}

.results-headline span {
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}

.results-bar {
  height: 8px;
  border-radius: 999px;
  background: var(--surface-2);
  overflow: hidden;
  margin-bottom: 12px;
}

.results-bar-fill {
  height: 100%;
  width: 0%;
  background: var(--accent);
  border-radius: 999px;
  transition: width 600ms var(--ease);
}

.results-bar-fill.passing {
  background: var(--success);
}

.results-meta {
  display: flex;
  align-items: baseline;
  gap: 12px;
  margin: 0 0 28px;
  flex-wrap: wrap;
  color: var(--text-muted);
  font-size: 14px;
  line-height: 1.55;
}

.results-percent {
  font-size: 17px;
  font-weight: 700;
  color: var(--text);
  font-variant-numeric: tabular-nums;
}

.review {
  margin: 24px 0 8px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 12px;
}

.review summary {
  cursor: pointer;
  padding: 16px 20px;
  font-weight: 600;
  list-style: none;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
}

.review summary::-webkit-details-marker {
  display: none;
}

.review-summary-text {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  font-size: 15px;
}

.review-count {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 26px;
  height: 26px;
  padding: 0 8px;
  border-radius: 999px;
  background: var(--error);
  color: oklch(0.99 0.01 25);
  font-size: 13px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}

.review-chevron {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  border-radius: 8px;
  background: var(--bg-soft);
  color: var(--text-muted);
  font-size: 18px;
  font-weight: 700;
  transition: transform 0.2s ease;
}

.review[open] .review-chevron {
  transform: rotate(90deg);
  color: var(--text);
}

.missed-list {
  padding: 0 20px 16px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.missed-item {
  background: var(--bg-soft);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 16px 18px;
}

.missed-header {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  margin-bottom: 14px;
}

.missed-index {
  flex: 0 0 26px;
  width: 26px;
  height: 26px;
  border-radius: 50%;
  background: var(--error);
  color: oklch(0.99 0.01 25);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 12px;
  font-weight: 700;
  margin-top: 2px;
}

.missed-item h4 {
  margin: 0;
  font-size: 15px;
  line-height: 1.5;
  font-weight: 600;
  color: var(--text);
}

.answer-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin-bottom: 12px;
}

.answer-cell {
  border-radius: 10px;
  padding: 10px 12px;
  border: 1px solid var(--border);
}

.answer-cell.wrong-cell {
  background: var(--error-bg);
  border-color: oklch(0.65 0.21 25 / 0.4);
}

.answer-cell.right-cell {
  background: var(--success-bg);
  border-color: oklch(0.7 0.17 145 / 0.4);
}

.answer-label {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  font-weight: 700;
  color: var(--text-muted);
  margin-bottom: 6px;
}

.wrong-cell .answer-label {
  color: var(--error);
}

.right-cell .answer-label {
  color: var(--success);
}

.answer-value {
  font-size: 14px;
  line-height: 1.45;
  color: var(--text);
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.answer-letter {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 22px;
  height: 22px;
  border-radius: 6px;
  font-size: 12px;
  font-weight: 700;
  margin-right: 8px;
  vertical-align: -3px;
}

.answer-letter.wrong {
  background: var(--error);
  color: oklch(0.99 0.01 25);
}

.answer-letter.right {
  background: var(--success);
  color: oklch(0.15 0.04 150);
}

.why {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 12px 14px;
}

.why-label {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  font-weight: 700;
  color: var(--accent-strong);
  margin-bottom: 6px;
}

.why-text {
  font-size: 14px;
  line-height: 1.55;
  color: var(--text);
  white-space: pre-wrap;
}

.footer {
  text-align: center;
  color: var(--text-muted);
  font-size: 12px;
  padding: 24px;
}

@keyframes slideIn {
  from {
    opacity: 0;
    transform: translateY(-4px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@media (max-width: 640px) {
  .topbar {
    flex-direction: column;
    align-items: flex-start;
    gap: 8px;
    padding: 12px 16px;
  }
  .session-stats {
    gap: 14px;
    font-size: 13px;
    width: 100%;
    justify-content: space-between;
  }
  main {
    margin: 16px auto 60px;
    padding: 0 12px;
  }
  .card {
    padding: 20px;
    border-radius: 12px;
  }
  .question-text {
    font-size: 17px;
  }
  .score-row {
    flex-direction: column;
    gap: 14px;
  }
  .score-num {
    font-size: 36px;
  }

  /* Stack quiz action buttons vertically and make each one full width
     so they're easy to tap. End Quiz appears at the bottom. */
  .quiz-actions {
    flex-direction: column;
    gap: 10px;
  }
  .action-group {
    flex-direction: column;
    width: 100%;
    gap: 10px;
  }
  .quiz-actions button,
  .action-group button {
    width: 100%;
  }
  #quit-btn {
    margin-top: 4px;
  }

  /* Setup screen buttons full width too */
  #start-btn,
  #restart-btn {
    width: 100%;
  }

  /* Side-by-side answer columns become stacked - the labels are clearer
     and we don't need to fight tiny screens for horizontal space. */
  .answer-grid {
    grid-template-columns: 1fr;
  }

  .review summary {
    padding: 14px 16px;
  }
  .missed-list {
    padding: 0 16px 14px;
  }
  .missed-item {
    padding: 14px;
  }

  /* Modal: bigger targets, safer positioning above iOS keyboards */
  .modal {
    padding: 22px;
    border-radius: 16px;
  }
  .modal-actions {
    flex-direction: column-reverse;
    gap: 8px;
  }
  .modal-actions button {
    width: 100%;
  }

  .footer {
    padding: 18px 12px 28px;
  }
}

/* Extra safety for iOS notches / home indicator */
@supports (padding: max(0px)) {
  .topbar {
    padding-left: max(18px, env(safe-area-inset-left));
    padding-right: max(18px, env(safe-area-inset-right));
  }
  main {
    padding-left: max(12px, env(safe-area-inset-left));
    padding-right: max(12px, env(safe-area-inset-right));
  }
  .footer {
    padding-bottom: max(24px, env(safe-area-inset-bottom));
  }
}
