:root {
  --red: #d52b1e;
  --red-dark: #a8180d;
  --red-50: #fdf1f0;
  --red-100: #fbe1df;
  --ink: #1a1d29;
  --ink-soft: #3d4358;
  --muted: #66707f;
  --muted-light: #99a1ae;
  --border: #e6e8ee;
  --border-soft: #eef0f4;
  --surface: #ffffff;
  --bg: #f5f6f9;
  --ok: #15803d;
  --ok-bg: #eafaf0;
  --ok-border: #bfe8cf;
  --ko: #c1272d;
  --ko-bg: #fdefee;
  --shadow-xs: 0 1px 2px rgba(23, 26, 43, 0.05);
  --shadow-sm: 0 2px 8px rgba(23, 26, 43, 0.06);
  --shadow-md: 0 8px 24px rgba(23, 26, 43, 0.09);
  --shadow-lg: 0 16px 40px rgba(23, 26, 43, 0.14);
  --radius-sm: 10px;
  --radius-md: 14px;
  --radius-lg: 20px;
  --ease: cubic-bezier(0.2, 0.7, 0.3, 1);
}

* {
  box-sizing: border-box;
}

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

h1, h2, h3 {
  letter-spacing: -0.01em;
}

@media (prefers-reduced-motion: reduce) {
  * {
    animation-duration: 0.001ms !important;
    transition-duration: 0.001ms !important;
  }
}

/* ---------- Header ---------- */

.app-header {
  background: linear-gradient(155deg, var(--red) 0%, var(--red-dark) 100%);
  color: white;
  padding: 1.1rem 1.5rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  flex-wrap: wrap;
  box-shadow: 0 2px 16px rgba(168, 24, 13, 0.25);
  position: relative;
  z-index: 10;
}

.app-header h1 {
  margin: 0;
  font-size: 1.2rem;
  font-weight: 700;
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  flex-wrap: wrap;
}

.lang-switch {
  display: flex;
  border: 1px solid rgba(255, 255, 255, 0.5);
  border-radius: 999px;
  overflow: hidden;
  background: rgba(255, 255, 255, 0.08);
}

.btn-lang {
  background: transparent;
  color: white;
  border: none;
  padding: 0.4rem 0.85rem;
  font-size: 0.82rem;
  font-weight: 700;
  cursor: pointer;
  transition: background-color 0.15s var(--ease), color 0.15s var(--ease);
}

.btn-lang:hover {
  background: rgba(255, 255, 255, 0.18);
}

.btn-lang.active {
  background: white;
  color: var(--red-dark);
}

.btn-lang.active:hover {
  background: white;
}

.btn-header-restart {
  background: rgba(255, 255, 255, 0.08);
  color: white;
  border: 1px solid rgba(255, 255, 255, 0.5);
  white-space: nowrap;
  font-size: 0.9rem;
  padding: 0.45rem 0.9rem;
}

.btn-header-restart:hover {
  background: rgba(255, 255, 255, 0.2);
}

/* ---------- Tabs ---------- */

.tab-bar {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  display: flex;
  gap: 0.25rem;
  padding: 0 1rem;
  overflow-x: auto;
  box-shadow: var(--shadow-xs);
  position: sticky;
  top: 0;
  z-index: 5;
}

.tab-btn {
  background: transparent;
  border: none;
  border-bottom: 3px solid transparent;
  color: var(--muted);
  font-size: 0.95rem;
  font-weight: 600;
  padding: 0.85rem 0.9rem;
  cursor: pointer;
  white-space: nowrap;
  transition: color 0.15s var(--ease);
  position: relative;
}

.tab-btn:hover {
  color: var(--ink);
}

.tab-btn.active {
  color: var(--red);
  border-bottom-color: var(--red);
}

.screen-tab[hidden] {
  display: none;
}

/* ---------- Layout ---------- */

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

.screen {
  background: var(--surface);
  border: 1px solid var(--border-soft);
  border-radius: var(--radius-lg);
  padding: 1.75rem;
  box-shadow: var(--shadow-md);
  animation: rise 0.25s var(--ease);
}

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

.screen h2 {
  margin-top: 0;
  font-size: 1.4rem;
}

.screen > p {
  color: var(--ink-soft);
}

.feature-list {
  margin: 0 0 1.5rem;
  padding-left: 0;
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 0.55rem;
}

.feature-list li {
  position: relative;
  padding-left: 1.6rem;
  color: var(--ink-soft);
}

.feature-list li::before {
  content: "✓";
  position: absolute;
  left: 0;
  top: 0;
  color: var(--ok);
  font-weight: 700;
}

/* ---------- Buttons ---------- */

.btn {
  font-size: 1rem;
  font-weight: 600;
  padding: 0.65rem 1.3rem;
  border-radius: var(--radius-sm);
  border: 1px solid transparent;
  cursor: pointer;
  transition: background-color 0.15s var(--ease), border-color 0.15s var(--ease),
    box-shadow 0.15s var(--ease), transform 0.1s var(--ease);
}

.btn:active {
  transform: translateY(1px);
}

.btn-primary {
  background: var(--red);
  color: white;
  box-shadow: 0 2px 10px rgba(213, 43, 30, 0.28);
}

.btn-primary:hover {
  background: var(--red-dark);
  box-shadow: 0 4px 14px rgba(213, 43, 30, 0.34);
}

.btn-secondary {
  background: var(--surface);
  border-color: var(--border);
  color: var(--ink);
}

.btn-secondary:hover {
  border-color: var(--muted-light);
  background: var(--bg);
}

.btn:disabled {
  opacity: 0.45;
  cursor: not-allowed;
  box-shadow: none;
  transform: none;
}

.btn:focus-visible,
.btn-lang:focus-visible,
.tab-btn:focus-visible,
.province-select:focus-visible,
.choice-label input:focus-visible {
  outline: 2px solid var(--red);
  outline-offset: 2px;
}

/* ---------- Province picker ---------- */

.province-label {
  display: block;
  margin: 1.4rem 0 0.5rem;
  font-weight: 600;
  font-size: 0.95rem;
}

.province-select {
  display: block;
  width: 100%;
  max-width: 320px;
  font-size: 1rem;
  padding: 0.6rem 0.8rem;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  color: var(--ink);
  background: var(--surface);
  margin-bottom: 0.5rem;
  transition: border-color 0.15s var(--ease);
}

.province-select:hover {
  border-color: var(--muted-light);
}

.province-select + .hint {
  margin-top: 0;
  margin-bottom: 1.4rem;
}

/* ---------- Quiz progress/meta ---------- */

.progress-bar {
  height: 8px;
  background: var(--border-soft);
  border-radius: 999px;
  overflow: hidden;
  margin-bottom: 1.25rem;
}

.progress-fill {
  height: 100%;
  background: linear-gradient(90deg, var(--red) 0%, #ef5a4c 100%);
  width: 0%;
  border-radius: 999px;
  transition: width 0.3s var(--ease);
}

.question-meta {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 0.85rem;
  color: var(--muted);
  font-size: 0.88rem;
}

.badge {
  background: var(--red-50);
  color: var(--red-dark);
  border-radius: 999px;
  padding: 0.2rem 0.75rem;
  font-weight: 700;
  font-size: 0.82rem;
}

.hint {
  color: var(--muted);
  font-style: italic;
  margin-top: -0.5rem;
}

/* ---------- Choices ---------- */

.choices {
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
  margin: 1.1rem 0 1.6rem;
}

.choice-label {
  display: flex;
  align-items: flex-start;
  gap: 0.7rem;
  border: 1.5px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 0.8rem 1rem;
  cursor: pointer;
  transition: border-color 0.15s var(--ease), background-color 0.15s var(--ease),
    box-shadow 0.15s var(--ease);
}

.choice-label:hover {
  border-color: var(--red);
  box-shadow: var(--shadow-xs);
}

.choice-label:has(input:checked) {
  border-color: var(--red);
  background: var(--red-50);
}

.choice-label input {
  margin-top: 0.2rem;
  accent-color: var(--red);
  width: 1.05rem;
  height: 1.05rem;
  flex-shrink: 0;
}

/* ---------- Navigation buttons ---------- */

.nav-buttons {
  display: flex;
  gap: 0.6rem;
  flex-wrap: wrap;
}

/* ---------- Results ---------- */

.score-summary {
  font-size: 1.2rem;
  font-weight: 700;
  margin-bottom: 1.5rem;
}

.results-list {
  display: flex;
  flex-direction: column;
  gap: 1rem;
  margin-top: 1.5rem;
}

.result-item {
  border: 1px solid var(--border-soft);
  border-radius: var(--radius-md);
  padding: 1.1rem 1.2rem;
  background: var(--surface);
  box-shadow: var(--shadow-xs);
}

.result-item.correct {
  border-left: 4px solid var(--ok);
  background: linear-gradient(180deg, var(--ok-bg) 0%, var(--surface) 90px);
}

.result-item.incorrect {
  border-left: 4px solid var(--ko);
  background: linear-gradient(180deg, var(--ko-bg) 0%, var(--surface) 90px);
}

.result-item .result-status {
  font-weight: 700;
  font-size: 0.78rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.result-item.correct .result-status {
  color: var(--ok);
}

.result-item.incorrect .result-status {
  color: var(--ko);
}

.result-item h3 {
  font-size: 1.05rem;
  margin: 0.5rem 0 0.75rem;
}

.result-choice {
  padding: 0.35rem 0;
  color: var(--ink-soft);
}

.result-choice.is-correct {
  color: var(--ok);
  font-weight: 600;
}

.result-choice.is-wrong-selected {
  color: var(--ko);
  text-decoration: line-through;
}

.explanation {
  background: var(--bg);
  border-radius: var(--radius-sm);
  padding: 0.8rem 1rem;
  margin-top: 0.85rem;
  font-size: 0.95rem;
  color: var(--ink-soft);
}

.source {
  margin-top: 0.6rem;
  font-size: 0.85rem;
  color: var(--muted);
  font-style: italic;
}

.source-note {
  display: block;
  margin-top: 0.2rem;
  font-style: normal;
  font-size: 0.8rem;
  color: var(--muted-light);
}

/* ---------- Confirm overlay ---------- */

.overlay {
  position: fixed;
  inset: 0;
  background: rgba(20, 22, 33, 0.55);
  backdrop-filter: blur(2px);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
  z-index: 100;
}

.overlay[hidden] {
  display: none;
}

.overlay-card {
  background: var(--surface);
  border-radius: var(--radius-md);
  padding: 1.6rem;
  max-width: 360px;
  width: 100%;
  box-shadow: var(--shadow-lg);
  animation: pop 0.18s var(--ease);
}

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

.overlay-card p {
  margin-top: 0;
}
