:root {
  --bg: #fafaf9;
  --surface: #ffffff;
  --text: #18181b;
  --text-muted: #71717a;
  --border: #e4e4e7;
  --border-strong: #d4d4d8;
  --accent: #18181b;
  --accent-text: #ffffff;
  --correct: #16a34a;
  --correct-bg: #f0fdf4;
  --incorrect: #dc2626;
  --incorrect-bg: #fef2f2;
  --selected: #f4f4f5;
  --radius: 10px;
  --radius-sm: 6px;
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.04), 0 1px 3px rgba(0, 0, 0, 0.06);
}

* {
  box-sizing: border-box;
}

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Inter", "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  font-size: 16px;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

main#app {
  max-width: 760px;
  margin: 0 auto;
  padding: 48px 24px 96px;
}

main#app:has(#quiz:not(.hidden)) {
  max-width: 1040px;
}

.view.hidden,
.hidden {
  display: none !important;
}

/* Setup */
.setup-header {
  text-align: center;
  margin-bottom: 32px;
}

.setup-header h1 {
  margin: 0 0 6px;
  font-size: 28px;
  font-weight: 600;
  letter-spacing: -0.02em;
  display: inline-flex;
  align-items: center;
  gap: 12px;
}

.title-logo {
  height: 1em;
  width: auto;
  display: block;
  flex-shrink: 0;
}

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

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

.field {
  margin-bottom: 20px;
}

.field-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
  margin-bottom: 20px;
}

.field-row .field {
  margin-bottom: 0;
}

.field-label {
  display: block;
  font-size: 13px;
  font-weight: 500;
  color: var(--text-muted);
  margin-bottom: 8px;
  letter-spacing: 0.01em;
}

.hint {
  margin: 8px 0 0;
  font-size: 13px;
  color: var(--text-muted);
}

select,
input[type="number"] {
  width: 100%;
  padding: 10px 12px;
  font-size: 15px;
  font-family: inherit;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  outline: none;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

select:focus,
input[type="number"]:focus {
  border-color: var(--text);
  box-shadow: 0 0 0 3px rgba(24, 24, 27, 0.08);
}

/* Segmented control */
.segmented {
  display: grid;
  grid-template-columns: 1fr 1fr;
  background: var(--bg);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  padding: 3px;
  gap: 3px;
}

.seg-btn {
  padding: 8px 12px;
  font-size: 14px;
  font-weight: 500;
  font-family: inherit;
  color: var(--text-muted);
  background: transparent;
  border: none;
  border-radius: 4px;
  cursor: pointer;
  transition: background 0.15s ease, color 0.15s ease;
}

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

.seg-btn.active {
  background: var(--surface);
  color: var(--text);
  box-shadow: var(--shadow);
}

.meta {
  font-size: 13px;
  color: var(--text-muted);
  margin: 4px 0 18px;
}

.meta #match-count,
.meta #attempt-total {
  color: var(--text);
  font-weight: 500;
}

.meta-sep {
  margin: 0 6px;
  color: var(--border-strong);
}

.checkbox-field {
  margin-bottom: 12px;
}

.checkbox {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 14px;
  color: var(--text);
  cursor: pointer;
  user-select: none;
}

.checkbox input[type="checkbox"] {
  width: 16px;
  height: 16px;
  accent-color: var(--accent);
  cursor: pointer;
}

.reset-btn {
  width: 100%;
  margin-top: 8px;
  font-size: 13px;
  padding: 8px;
}

/* Buttons */
button {
  font-family: inherit;
  cursor: pointer;
}

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

.primary {
  width: 100%;
  padding: 12px 16px;
  font-size: 15px;
  font-weight: 500;
  color: var(--accent-text);
  background: var(--accent);
  border: 1px solid var(--accent);
  border-radius: var(--radius-sm);
  transition: opacity 0.15s ease, transform 0.05s ease;
}

.primary:not(:disabled):hover {
  opacity: 0.9;
}

.primary:not(:disabled):active {
  transform: translateY(1px);
}

.secondary {
  padding: 10px 16px;
  font-size: 15px;
  font-weight: 500;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  transition: background 0.15s ease;
}

.secondary:not(:disabled):hover {
  background: var(--bg);
}

.ghost {
  padding: 6px 10px;
  font-size: 14px;
  color: var(--text-muted);
  background: transparent;
  border: none;
  border-radius: var(--radius-sm);
  transition: color 0.15s ease, background 0.15s ease;
}

.ghost:hover {
  color: var(--text);
  background: var(--surface);
}

.status {
  margin-top: 16px;
  font-size: 13px;
  color: var(--text-muted);
  text-align: center;
  min-height: 1em;
}

.status-link {
  color: inherit;
  font: inherit;
  text-decoration: underline;
  margin-left: 6px;
  transition: color 0.15s ease;
}

.status-link:hover {
  color: var(--text);
}

/* Quiz */
.quiz-header {
  display: flex;
  align-items: center;
  gap: 16px;
  margin-bottom: 24px;
}

.progress {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.progress-bar {
  height: 4px;
  background: var(--border);
  border-radius: 2px;
  overflow: hidden;
}

#progress-fill {
  height: 100%;
  background: var(--text);
  width: 0%;
  transition: width 0.3s ease;
}

.nav-row {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 6px;
  font-size: 13px;
  color: var(--text-muted);
  font-variant-numeric: tabular-nums;
}

.nav-btn {
  padding: 4px 10px;
  font-size: 14px;
  line-height: 1;
  font-family: inherit;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  transition: background 0.15s ease, border-color 0.15s ease, color 0.15s ease;
}

.nav-btn:not(:disabled):hover {
  background: var(--bg);
}

.nav-btn:disabled {
  color: var(--text-muted);
  background: var(--bg);
}

.jump {
  display: flex;
  align-items: center;
  gap: 4px;
}

#jump-input {
  width: 64px;
  padding: 4px 6px;
  font-size: 13px;
  text-align: right;
  font-variant-numeric: tabular-nums;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  outline: none;
}

#jump-input:focus {
  border-color: var(--text);
  box-shadow: 0 0 0 3px rgba(24, 24, 27, 0.08);
}

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

.question-card {
  padding: 32px;
}

.question-meta {
  font-size: 12px;
  color: var(--text-muted);
  margin-bottom: 12px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.question-meta .dot {
  margin: 0 6px;
}

.question-text {
  margin: 0 0 24px;
  font-size: 17px;
  font-weight: 400;
  line-height: 1.6;
  color: var(--text);
}

.choices {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-bottom: 24px;
}

.choice {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  width: 100%;
  text-align: left;
  padding: 14px 16px;
  font-size: 15px;
  line-height: 1.5;
  font-family: inherit;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  transition: background 0.15s ease, border-color 0.15s ease;
}

.choice:not(:disabled):hover {
  background: var(--bg);
}

.choice .letter {
  flex: 0 0 auto;
  font-weight: 600;
  color: var(--text-muted);
  min-width: 1.2em;
}

.choice.selected {
  background: var(--selected);
  border-color: var(--text);
}

.choice.selected .letter {
  color: var(--text);
}

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

.choice.correct .letter {
  color: var(--correct);
}

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

.choice.incorrect .letter {
  color: var(--incorrect);
}

.choice:disabled {
  cursor: default;
  opacity: 1;
}

/* Reveal */
.reveal {
  margin: 8px 0 24px;
  padding-top: 20px;
  border-top: 1px solid var(--border);
}

.reveal-summary {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 16px;
  font-size: 14px;
}

#reveal-status {
  font-weight: 600;
}

#reveal-status.correct {
  color: var(--correct);
}

#reveal-status.incorrect {
  color: var(--incorrect);
}

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

.reveal-correct strong {
  color: var(--text);
}

.reveal h3 {
  margin: 16px 0 6px;
  font-size: 13px;
  font-weight: 500;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.reveal p {
  margin: 0;
  font-size: 15px;
  line-height: 1.6;
}

.actions {
  display: flex;
  gap: 12px;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
}

.actions-right {
  display: flex;
  gap: 12px;
  margin-left: auto;
}

.actions .primary,
.actions .secondary {
  width: auto;
}

.correction-btn {
  font-size: 13px;
  padding: 8px 12px;
  color: var(--text-muted);
}

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

/* Correction modal */
.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.modal {
  position: fixed;
  inset: 0;
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
}

.modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.4);
}

.modal-panel {
  position: relative;
  z-index: 1;
  background: var(--surface);
  color: var(--text);
  border-radius: var(--radius);
  max-width: 480px;
  width: 100%;
  box-shadow: 0 10px 40px rgba(0, 0, 0, 0.18);
}

.modal-form {
  padding: 24px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.modal-title {
  margin: 0;
  font-size: 18px;
  font-weight: 600;
  letter-spacing: -0.01em;
}

.modal-sub {
  margin: 0;
  font-size: 13px;
  color: var(--text-muted);
}

.modal-options {
  border: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.radio {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  font-size: 14px;
  cursor: pointer;
  transition: background 0.15s ease, border-color 0.15s ease;
}

.radio:hover {
  background: var(--bg);
}

.radio input[type="radio"] {
  accent-color: var(--accent);
  margin: 0;
}

.radio:has(input:checked) {
  background: var(--selected);
  border-color: var(--text);
}

.modal-form textarea {
  width: 100%;
  padding: 10px 12px;
  font-family: inherit;
  font-size: 14px;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  resize: vertical;
  min-height: 64px;
  outline: none;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

.modal-form textarea:focus {
  border-color: var(--text);
  box-shadow: 0 0 0 3px rgba(24, 24, 27, 0.08);
}

.modal-status {
  margin: 0;
  font-size: 13px;
  min-height: 1em;
  color: var(--text-muted);
}

.modal-status.error {
  color: var(--incorrect);
}

.modal-status.success {
  color: var(--correct);
}

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

.modal-actions .primary,
.modal-actions .secondary {
  width: auto;
  padding: 8px 16px;
  font-size: 14px;
}

.skip-options {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.skip-option {
  padding: 12px 14px;
  text-align: left;
  font-size: 14px;
}

/* Quiz layout with sidebar */
.quiz-layout {
  display: grid;
  grid-template-columns: 1fr 240px;
  gap: 24px;
  align-items: start;
}

.sidebar {
  position: sticky;
  top: 24px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  box-shadow: var(--shadow);
}

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

.stat {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

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

.stat-value {
  font-size: 15px;
  font-weight: 500;
  color: var(--text);
  font-variant-numeric: tabular-nums;
}

.sidebar-legend {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  font-size: 11px;
  color: var(--text-muted);
  padding: 8px 0;
  border-top: 1px solid var(--border);
  border-bottom: 1px solid var(--border);
  margin-bottom: 12px;
}

.legend-dot {
  display: inline-block;
  width: 8px;
  height: 8px;
  border-radius: 2px;
  margin-right: 1px;
  margin-left: 4px;
}

.legend-dot:first-child {
  margin-left: 0;
}

.legend-correct {
  background: var(--correct);
}

.legend-incorrect {
  background: var(--incorrect);
}

.legend-current {
  background: var(--accent);
}

.question-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 6px;
  max-height: 420px;
  overflow-y: auto;
  overflow-x: hidden;
  padding-right: 4px;
}

.grid-cell {
  display: flex;
  align-items: center;
  justify-content: center;
  min-width: 0;
  height: 32px;
  font-size: 12px;
  font-variant-numeric: tabular-nums;
  font-family: inherit;
  color: var(--text-muted);
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 4px;
  cursor: pointer;
  transition: transform 0.08s ease, border-color 0.15s ease;
}

.grid-cell:hover {
  border-color: var(--text-muted);
}

.grid-cell.correct {
  background: var(--correct-bg);
  border-color: var(--correct);
  color: var(--correct);
  font-weight: 600;
}

.grid-cell.incorrect {
  background: var(--incorrect-bg);
  border-color: var(--incorrect);
  color: var(--incorrect);
  font-weight: 600;
}

.grid-cell.current {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
  color: var(--text);
}

@media (max-width: 880px) {
  main#app:has(#quiz:not(.hidden)) {
    max-width: 760px;
  }
  .quiz-layout {
    grid-template-columns: 1fr;
  }
  .sidebar {
    position: static;
    order: 2;
  }
  .question-grid {
    max-height: 240px;
  }
}

@media (max-width: 560px) {
  main#app {
    padding: 24px 16px 64px;
  }

  .card,
  .question-card {
    padding: 20px;
  }

  .field-row {
    grid-template-columns: 1fr;
  }

  .question-grid {
    grid-template-columns: repeat(6, minmax(0, 1fr));
  }
}
