:root {
  --bg: #0f172a;
  --surface: #1e293b;
  --surface2: #334155;
  --accent: #6366f1;
  --accent-hover: #4f46e5;
  --text: #f1f5f9;
  --text-muted: #94a3b8;
  --green: #22c55e;
  --red: #ef4444;
  --orange: #f97316;
  --gold: #f59e0b;
  --border: #334155;
  --radius: 12px;
}

* {
  box-sizing: border-box;
}

html, body {
  margin: 0;
  padding: 0;
}

body {
  background: var(--bg);
  color: var(--text);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

.container {
  max-width: 900px;
  margin: 0 auto;
  padding: 24px 16px 64px;
}

/* ---------- Home page ---------- */

.page-header {
  text-align: center;
  margin-bottom: 32px;
}

.page-header h1 {
  font-size: 2rem;
  margin: 0 0 8px;
}

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

.cards-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 16px;
}

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  transition: transform 150ms ease, border-color 150ms ease;
}

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

.card.highlight {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(99, 102, 241, 0.35);
  transition: box-shadow 200ms ease, border-color 200ms ease;
}

.card.final-card {
  border-color: var(--gold);
  background: linear-gradient(160deg, var(--surface) 0%, #2a2310 100%);
}

.card h2 {
  margin: 0 0 4px;
  font-size: 1.25rem;
}

.card.final-card h2 {
  color: var(--gold);
}

.card .range {
  color: var(--text-muted);
  font-size: 0.9rem;
  margin: 0 0 16px;
}

.card-buttons {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.mode-btn {
  flex: 1;
  min-width: 70px;
  min-height: 44px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface2);
  color: var(--text);
  font-size: 0.9rem;
  font-weight: 600;
  cursor: pointer;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: background-color 150ms ease, color 150ms ease;
}

.mode-btn:hover,
.mode-btn:focus-visible {
  background: var(--accent-hover);
  color: #fff;
}

.mode-btn.mode-normal:hover { background: var(--green); }
.mode-btn.mode-medium:hover { background: var(--orange); }
.mode-btn.mode-hard:hover { background: var(--red); }

/* ---------- Quiz page ---------- */

.quiz-header {
  margin-bottom: 24px;
}

.back-link {
  color: var(--text-muted);
  text-decoration: none;
  font-size: 0.9rem;
  display: inline-block;
  margin-bottom: 12px;
}

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

.quiz-title-row {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
}

.quiz-title-row h1 {
  margin: 0;
  font-size: 1.5rem;
}

.mode-badge {
  display: inline-block;
  padding: 4px 12px;
  border-radius: 999px;
  font-size: 0.8rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: #0f172a;
}

.mode-badge.normal { background: var(--green); }
.mode-badge.medium { background: var(--orange); }
.mode-badge.hard { background: var(--red); }

.progress-label {
  color: var(--text-muted);
  font-size: 0.9rem;
  margin: 12px 0 6px;
}

.progress-bar-track {
  width: 100%;
  height: 6px;
  border-radius: 3px;
  background: var(--surface2);
  overflow: hidden;
}

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

/* ---------- Question card ---------- */

.question-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 24px;
}

.question-number {
  color: var(--accent);
  font-weight: 700;
  font-size: 0.9rem;
  margin: 0 0 8px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.question-text {
  font-size: 1.25rem;
  margin: 0 0 24px;
}

.answers {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.answer-btn {
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
  min-height: 52px;
  padding: 12px 16px;
  text-align: left;
  background: var(--surface2);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 10px;
  font-size: 1rem;
  cursor: pointer;
  transition: background-color 150ms ease, border-color 150ms ease, opacity 150ms ease;
}

.answer-btn:hover:not(:disabled),
.answer-btn:focus-visible:not(:disabled) {
  background: var(--accent);
  border-color: var(--accent-hover);
}

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

.answer-btn.selected {
  background: var(--accent);
  border-color: var(--accent-hover);
}

.answer-label {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 28px;
  height: 28px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.08);
  font-weight: 700;
  font-size: 0.85rem;
  flex-shrink: 0;
}

.answer-btn.correct {
  background: var(--green);
  border-color: var(--green);
  color: #052e16;
}

.answer-btn.wrong {
  background: var(--red);
  border-color: var(--red);
  color: #450a0a;
}

.answer-btn.faded {
  opacity: 0.4;
}

/* ---------- Result page ---------- */

.result-summary {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 24px;
  text-align: center;
  margin-bottom: 24px;
}

.result-score {
  font-size: 2rem;
  font-weight: 800;
  margin: 0 0 8px;
}

.result-breakdown {
  color: var(--text-muted);
  font-size: 1rem;
  margin: 0;
}

.result-breakdown .correct-count {
  color: var(--green);
  font-weight: 700;
}

.result-breakdown .wrong-count {
  color: var(--red);
  font-weight: 700;
}

.review-list {
  display: flex;
  flex-direction: column;
  gap: 16px;
  margin-bottom: 24px;
}

.review-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
}

.review-question {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 12px;
  margin: 0 0 16px;
  font-size: 1.05rem;
}

.review-variants {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.review-variant {
  padding: 10px 14px;
  border-radius: 8px;
  background: var(--surface2);
  border: 1px solid var(--border);
  font-size: 0.95rem;
}

.review-variant.correct {
  background: var(--green);
  color: #052e16;
  border-color: var(--green);
}

.review-variant.wrong {
  background: var(--red);
  color: #450a0a;
  border-color: var(--red);
}

.result-actions {
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
}

.result-actions button {
  flex: 1;
  min-width: 140px;
  min-height: 52px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--surface2);
  color: var(--text);
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
  transition: background-color 150ms ease;
}

.result-actions button:hover {
  background: var(--accent-hover);
  border-color: var(--accent-hover);
}

/* ---------- Loading spinner ---------- */

.loading-spinner {
  width: 40px;
  height: 40px;
  margin: 80px auto;
  border: 4px solid var(--surface2);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 800ms linear infinite;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

/* ---------- Misc ---------- */

.error-message {
  text-align: center;
  color: var(--text-muted);
  padding: 60px 16px;
}
