/* ==========================================================================
   Flag Guesser
   Design system: neutral surfaces, one accent, quiet borders, tabular numerals.
   ========================================================================== */

:root {
  --bg: #0e0f12;
  --surface: #16181d;
  --surface-2: #1c1f25;
  --surface-3: #242830;
  --border: rgba(255, 255, 255, 0.08);
  --border-strong: rgba(255, 255, 255, 0.16);
  --text: #f3f4f6;
  --text-2: #c9cdd4;
  --muted: #8a919c;
  --primary: #f3f4f6;
  --primary-ink: #0e0f12;
  --accent: #6ea3ff;
  --accent-ink: #0b1220;
  --accent-soft: rgba(110, 163, 255, 0.12);
  --good: #3fcf8e;
  --good-soft: rgba(63, 207, 142, 0.18);
  --bad: #f0716a;
  --bad-soft: rgba(240, 113, 106, 0.18);
  --danger: #e5484d;
  --radius: 12px;
  --radius-sm: 10px;
  --radius-xs: 8px;
  --shadow: 0 16px 40px rgba(0, 0, 0, 0.45);
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.3);
  --focus: 0 0 0 2px var(--bg), 0 0 0 4px var(--accent);
  --font: "Inter", "Segoe UI", system-ui, -apple-system, Roboto, "Helvetica Neue", sans-serif;
  --mono: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  --ease: cubic-bezier(0.2, 0.8, 0.2, 1);
  color-scheme: dark;
}

[data-theme="light"] {
  --bg: #f6f7f9;
  --surface: #ffffff;
  --surface-2: #f3f4f6;
  --surface-3: #e9ebef;
  --border: rgba(17, 24, 39, 0.08);
  --border-strong: rgba(17, 24, 39, 0.16);
  --text: #111418;
  --text-2: #3d434c;
  --muted: #667085;
  --primary: #111418;
  --primary-ink: #ffffff;
  --accent: #1a56db;
  --accent-ink: #ffffff;
  --accent-soft: rgba(26, 86, 219, 0.08);
  --good: #15803d;
  --good-soft: rgba(21, 128, 61, 0.1);
  --bad: #b42318;
  --bad-soft: rgba(180, 35, 24, 0.09);
  --danger: #d92d20;
  --shadow: 0 16px 40px rgba(17, 24, 39, 0.12);
  --shadow-sm: 0 1px 2px rgba(17, 24, 39, 0.06);
  --focus: 0 0 0 2px var(--bg), 0 0 0 4px var(--accent);
  color-scheme: light;
}

@media (prefers-color-scheme: light) {
  :root:not([data-theme="dark"]) {
    --bg: #f6f7f9;
    --surface: #ffffff;
    --surface-2: #f3f4f6;
    --surface-3: #e9ebef;
    --border: rgba(17, 24, 39, 0.08);
    --border-strong: rgba(17, 24, 39, 0.16);
    --text: #111418;
    --text-2: #3d434c;
    --muted: #667085;
    --primary: #111418;
    --primary-ink: #ffffff;
    --accent: #1a56db;
    --accent-ink: #ffffff;
    --accent-soft: rgba(26, 86, 219, 0.08);
    --good: #15803d;
    --good-soft: rgba(21, 128, 61, 0.1);
    --bad: #b42318;
    --bad-soft: rgba(180, 35, 24, 0.09);
    --danger: #d92d20;
    --shadow: 0 16px 40px rgba(17, 24, 39, 0.12);
    --shadow-sm: 0 1px 2px rgba(17, 24, 39, 0.06);
    --focus: 0 0 0 2px var(--bg), 0 0 0 4px var(--accent);
    color-scheme: light;
  }
}

/* Base ------------------------------------------------------------------- */

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

html {
  -webkit-text-size-adjust: 100%;
}

body {
  margin: 0;
  min-height: 100dvh;
  font-family: var(--font);
  font-size: 15px;
  line-height: 1.5;
  color: var(--text);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  font-feature-settings: "cv11", "ss01";
  display: flex;
  flex-direction: column;
}

h1,
h2,
h3 {
  margin: 0;
  line-height: 1.2;
  letter-spacing: -0.015em;
}

p {
  margin: 0;
}

button,
input,
select {
  font: inherit;
  color: inherit;
}

button {
  cursor: pointer;
}

kbd {
  display: inline-grid;
  place-items: center;
  min-width: 1.6em;
  height: 1.6em;
  padding: 0 0.4em;
  border-radius: 5px;
  border: 1px solid var(--border-strong);
  background: var(--surface-2);
  font-family: var(--font);
  font-size: 0.72em;
  font-weight: 600;
  line-height: 1;
  color: var(--muted);
}

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

[tabindex="-1"]:focus {
  outline: none;
  box-shadow: none;
}

[hidden] {
  display: none !important;
}

.container {
  width: 100%;
  max-width: 920px;
  margin: 0 auto;
  padding-inline: clamp(16px, 4vw, 32px);
}

.skip-link {
  position: absolute;
  top: -100px;
  left: 16px;
  padding: 8px 12px;
  border-radius: var(--radius-xs);
  background: var(--primary);
  color: var(--primary-ink);
  z-index: 100;
}

.skip-link:focus {
  top: 12px;
}

/* Top bar ---------------------------------------------------------------- */

.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border);
}

.topbar__inner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  min-height: 60px;
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  padding: 6px 8px 6px 4px;
  border: 0;
  border-radius: var(--radius-xs);
  background: transparent;
  font-weight: 600;
  font-size: 0.95rem;
  letter-spacing: -0.01em;
}

.brand__icon {
  width: 24px;
  height: 24px;
  color: var(--text);
}

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

@media (max-width: 520px) {
  .brand__name {
    display: none;
  }
}

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

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  height: 40px;
  padding: 0 16px;
  border-radius: var(--radius-xs);
  border: 1px solid var(--border-strong);
  background: var(--surface);
  color: var(--text);
  font-weight: 500;
  font-size: 0.9rem;
  line-height: 1;
  text-decoration: none;
  white-space: nowrap;
  transition: background 0.15s, border-color 0.15s, color 0.15s, opacity 0.15s;
}

.btn:hover:not(:disabled) {
  background: var(--surface-2);
}

.btn:active:not(:disabled) {
  background: var(--surface-3);
}

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

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

.btn--primary:hover:not(:disabled) {
  background: color-mix(in srgb, var(--primary) 88%, var(--bg));
  border-color: color-mix(in srgb, var(--primary) 88%, var(--bg));
}

.btn--primary:active:not(:disabled) {
  background: color-mix(in srgb, var(--primary) 80%, var(--bg));
}

.btn--ghost {
  background: transparent;
  border-color: transparent;
  color: var(--text-2);
}

.btn--ghost:hover:not(:disabled) {
  background: var(--surface-2);
  color: var(--text);
}

.btn--danger {
  color: var(--bad);
}

.btn--danger:hover:not(:disabled) {
  background: var(--bad-soft);
  color: var(--bad);
}

.btn--danger-solid {
  background: var(--danger);
  border-color: var(--danger);
  color: #fff;
}

.btn--danger-solid:hover:not(:disabled) {
  background: color-mix(in srgb, var(--danger) 88%, black);
}

.btn--lg {
  height: 46px;
  padding: 0 22px;
  font-size: 0.95rem;
}

.btn--sm {
  height: 34px;
  padding: 0 12px;
  font-size: 0.85rem;
}

.btn--icon {
  width: 36px;
  height: 36px;
  padding: 0;
  background: transparent;
  border-color: transparent;
  color: var(--text-2);
}

.btn--icon:hover:not(:disabled) {
  color: var(--text);
}

.btn--icon svg {
  width: 18px;
  height: 18px;
}

.btn--primary kbd {
  background: rgba(127, 127, 127, 0.18);
  border-color: transparent;
  color: inherit;
  opacity: 0.85;
}

.pill {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 20px;
  height: 20px;
  padding: 0 6px;
  border-radius: 6px;
  background: var(--surface-3);
  color: var(--text);
  font-size: 0.72rem;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}

/* Screens ---------------------------------------------------------------- */

main {
  flex: 1;
  padding-top: clamp(28px, 6vw, 56px);
  padding-bottom: 56px;
}

.screen {
  animation: fade-up 0.35s var(--ease) both;
}

@keyframes fade-up {
  from {
    opacity: 0;
    transform: translateY(6px);
  }
  to {
    opacity: 1;
    transform: none;
  }
}

.eyebrow {
  margin-bottom: 12px;
  font-size: 0.75rem;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted);
}

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

.hero {
  text-align: center;
  max-width: 620px;
  margin: 0 auto clamp(28px, 5vw, 44px);
}

.hero__title {
  font-size: clamp(1.9rem, 4.5vw, 2.75rem);
  font-weight: 700;
  letter-spacing: -0.03em;
}

.hero__lead {
  margin-top: 12px;
  font-size: 1rem;
  color: var(--muted);
}

.setup {
  padding: clamp(18px, 3vw, 28px);
  border-radius: var(--radius);
  background: var(--surface);
  border: 1px solid var(--border);
  box-shadow: var(--shadow-sm);
}

.setup__group {
  margin: 0 0 22px;
  padding: 0;
  border: 0;
  min-width: 0;
}

.setup__label {
  display: block;
  margin-bottom: 10px;
  padding: 0;
  font-size: 0.75rem;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--muted);
}

.setup__row {
  display: grid;
  grid-template-columns: 1.4fr 1fr;
  gap: 20px;
}

@media (max-width: 640px) {
  .setup__row {
    grid-template-columns: 1fr;
  }
}

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

@media (max-width: 720px) {
  .mode-grid {
    grid-template-columns: 1fr;
  }
}

.mode-card {
  position: relative;
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 16px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--bg);
  cursor: pointer;
  transition: border-color 0.15s, background 0.15s, box-shadow 0.15s;
}

.mode-card:hover {
  border-color: var(--border-strong);
}

.mode-card input {
  position: absolute;
  opacity: 0;
  width: 1px;
  height: 1px;
  pointer-events: none;
}

.mode-card:has(input:checked) {
  border-color: var(--accent);
  background: var(--accent-soft);
  box-shadow: inset 0 0 0 1px var(--accent);
}

.mode-card:has(input:focus-visible) {
  box-shadow: var(--focus);
}

.mode-card__icon {
  width: 34px;
  height: 34px;
  display: grid;
  place-items: center;
  border-radius: 8px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  color: var(--text-2);
}

.mode-card:has(input:checked) .mode-card__icon {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--accent-ink);
}

.mode-card__icon svg {
  width: 18px;
  height: 18px;
}

.mode-card__name {
  font-weight: 600;
  font-size: 0.98rem;
  letter-spacing: -0.01em;
}

.mode-card__desc {
  font-size: 0.85rem;
  line-height: 1.45;
  color: var(--muted);
}

/* Round length picker (shown for modes with a fixed number of flags). */

.rounds {
  margin-top: 16px;
  padding-top: 16px;
  border-top: 1px solid var(--border);
}

.rounds__row {
  display: grid;
  grid-template-columns: minmax(0, 360px) auto;
  align-items: center;
  gap: 12px;
}

@media (max-width: 560px) {
  .rounds__row {
    grid-template-columns: 1fr;
  }
}

.rounds__custom {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  animation: fade-up 0.2s var(--ease);
}

.rounds__custom-label {
  font-size: 0.85rem;
  color: var(--muted);
}

.input.rounds__custom-input {
  width: 96px;
  text-align: center;
  font-variant-numeric: tabular-nums;
}

.segmented.segmented--3 {
  grid-template-columns: repeat(3, 1fr);
}

.segmented {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  padding: 3px;
  border-radius: var(--radius-xs);
  background: var(--surface-2);
  border: 1px solid var(--border);
}

.segmented label {
  position: relative;
  cursor: pointer;
}

.segmented input {
  position: absolute;
  opacity: 0;
  width: 1px;
  height: 1px;
  pointer-events: none;
}

.segmented span {
  display: block;
  padding: 8px 6px;
  border-radius: 6px;
  text-align: center;
  font-size: 0.88rem;
  font-weight: 500;
  color: var(--muted);
  transition: background 0.15s, color 0.15s, box-shadow 0.15s;
}

.segmented label:hover span {
  color: var(--text);
}

.segmented input:checked + span {
  background: var(--surface);
  color: var(--text);
  box-shadow: var(--shadow-sm), 0 0 0 1px var(--border);
}

.segmented input:focus-visible + span {
  box-shadow: var(--focus);
}

.select,
.input {
  width: 100%;
  height: 40px;
  padding: 0 12px;
  border-radius: var(--radius-xs);
  border: 1px solid var(--border-strong);
  background: var(--bg);
  color: var(--text);
  transition: border-color 0.15s;
}

.select:hover,
.input:hover {
  border-color: color-mix(in srgb, var(--border-strong) 60%, var(--muted));
}

.select:focus-visible,
.input:focus-visible {
  border-color: var(--accent);
  box-shadow: none;
}

.select {
  appearance: none;
  -webkit-appearance: none;
  padding-right: 36px;
  background-image:
    linear-gradient(45deg, transparent 50%, var(--muted) 50%),
    linear-gradient(135deg, var(--muted) 50%, transparent 50%);
  background-position: calc(100% - 18px) 55%, calc(100% - 13px) 55%;
  background-size: 5px 5px;
  background-repeat: no-repeat;
}

.setup__footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  flex-wrap: wrap;
  margin-top: 4px;
  padding-top: 20px;
  border-top: 1px solid var(--border);
}

.setup__hint {
  color: var(--muted);
  font-size: 0.9rem;
}

.setup__hint.is-warning {
  color: var(--bad);
}

.setup__tip {
  margin-top: 16px;
  font-size: 0.82rem;
  color: var(--muted);
}

@media (hover: none) and (pointer: coarse) {
  .setup__tip {
    display: none;
  }
}

/* Stat rows: one bordered container, hairline dividers via grid gap. */

.stats-strip {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 1px;
  margin-top: 16px;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: var(--border);
  overflow: hidden;
}

@media (max-width: 640px) {
  .stats-strip {
    grid-template-columns: repeat(2, 1fr);
  }
}

.stat {
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding: 16px 18px;
  background: var(--surface);
}

.stat__value {
  font-size: 1.4rem;
  font-weight: 600;
  letter-spacing: -0.02em;
  font-variant-numeric: tabular-nums;
}

.stat__label {
  font-size: 0.78rem;
  color: var(--muted);
}

/* Game HUD --------------------------------------------------------------- */

.hud {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 12px 16px;
  border-radius: var(--radius);
  background: var(--surface);
  border: 1px solid var(--border);
}

.hud__meta {
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.hud__mode {
  font-weight: 600;
  font-size: 0.95rem;
}

.hud__sub {
  font-size: 0.78rem;
  color: var(--muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.hud__stats {
  display: flex;
  align-items: center;
  gap: clamp(12px, 3vw, 28px);
}

.hud__stat {
  display: flex;
  flex-direction: column;
  align-items: center;
  min-width: 48px;
}

.hud__label {
  font-size: 0.68rem;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--muted);
}

.hud__value {
  font-size: 1.15rem;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  letter-spacing: -0.01em;
}

.hud__value.is-bump {
  animation: bump 0.3s var(--ease);
}

@keyframes bump {
  0% { transform: scale(1); }
  40% { transform: scale(1.18); }
  100% { transform: scale(1); }
}

.lives {
  display: inline-flex;
  gap: 3px;
}

.heart {
  color: var(--bad);
  font-size: 1.1rem;
  line-height: 1;
  transition: opacity 0.3s, transform 0.3s var(--ease);
}

.heart::before {
  content: "\2665";
}

.heart.is-lost {
  opacity: 0.2;
  transform: scale(0.8);
}

.clock.is-low {
  color: var(--bad);
}

.clock.is-hit {
  animation: shake 0.4s var(--ease);
  color: var(--bad);
}

@media (max-width: 560px) {
  .hud {
    flex-wrap: wrap;
  }
  .hud__meta {
    order: 1;
    flex: 1;
  }
  .hud__stats {
    order: 3;
    width: 100%;
    justify-content: space-between;
    padding-top: 10px;
    border-top: 1px solid var(--border);
  }
  .hud .btn--icon {
    order: 2;
  }
}

.timer {
  height: 4px;
  margin: 12px 0 0;
  border-radius: 999px;
  background: var(--surface-3);
  overflow: hidden;
}

.timer__fill {
  height: 100%;
  width: 100%;
  border-radius: inherit;
  background: var(--accent);
  transform-origin: left center;
  transform: scaleX(1);
}

.timer.is-low .timer__fill {
  background: var(--bad);
}

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

.quiz {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 14px;
  margin-top: 20px;
}

.quiz__prompt {
  font-size: 1rem;
  font-weight: 500;
  color: var(--muted);
  text-align: center;
}

.flag-card {
  position: relative;
  width: min(100%, 460px);
  aspect-ratio: 3 / 2;
  margin: 0;
  padding: 14px;
  display: grid;
  place-items: center;
  border-radius: var(--radius);
  background: var(--surface);
  border: 1px solid var(--border);
  overflow: hidden;
}

.flag-card__img {
  max-width: 100%;
  max-height: 100%;
  width: auto;
  height: auto;
  object-fit: contain;
  border-radius: 4px;
  box-shadow: 0 0 0 1px var(--border-strong), 0 8px 24px rgba(0, 0, 0, 0.25);
  transition: opacity 0.2s;
  animation: flag-in 0.3s var(--ease);
}

@keyframes flag-in {
  from {
    opacity: 0;
    transform: scale(0.97);
  }
  to {
    opacity: 1;
    transform: none;
  }
}

.flag-card.is-loading .flag-card__img {
  opacity: 0;
}

.flag-card.is-loading::after {
  content: "";
  position: absolute;
  inset: 16px;
  border-radius: 6px;
  background: linear-gradient(100deg, var(--surface-2) 30%, var(--surface-3) 50%, var(--surface-2) 70%);
  background-size: 200% 100%;
  animation: shimmer 1.2s linear infinite;
}

@keyframes shimmer {
  from { background-position: 200% 0; }
  to { background-position: -200% 0; }
}

.flag-card__fallback {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  text-align: center;
  color: var(--muted);
  z-index: 1;
}

.flag-card__fallback-actions {
  display: flex;
  gap: 8px;
}

.flag-card__hint {
  position: absolute;
  left: 50%;
  bottom: 12px;
  transform: translateX(-50%);
  padding: 6px 12px;
  border-radius: var(--radius-xs);
  background: var(--primary);
  color: var(--primary-ink);
  font-size: 0.82rem;
  font-weight: 500;
  white-space: nowrap;
  animation: fade-up 0.25s var(--ease);
}

.options {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 10px;
  width: min(100%, 640px);
}

@media (max-width: 520px) {
  .options {
    grid-template-columns: 1fr;
  }
}

.option {
  display: flex;
  align-items: center;
  gap: 12px;
  min-height: 56px;
  padding: 12px 14px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--surface);
  text-align: left;
  font-weight: 500;
  font-size: 0.95rem;
  transition: background 0.15s, border-color 0.15s, color 0.15s, opacity 0.2s;
}

.option:hover:not(:disabled) {
  background: var(--surface-2);
  border-color: var(--border-strong);
}

.option:active:not(:disabled) {
  background: var(--surface-3);
}

.option:disabled {
  cursor: default;
}

.option kbd {
  flex: none;
  min-width: 22px;
  height: 22px;
  font-size: 0.72rem;
}

@media (hover: none) and (pointer: coarse) {
  .option kbd {
    display: none;
  }
}

.option__text {
  flex: 1;
}

.option.is-correct {
  background: var(--good-soft);
  border-color: var(--good);
  color: var(--text);
  animation: pop 0.4s var(--ease);
}

.option.is-correct kbd {
  background: var(--good);
  border-color: var(--good);
  color: #fff;
}

.option.is-wrong {
  background: var(--bad-soft);
  border-color: var(--bad);
  color: var(--text);
  animation: shake 0.4s var(--ease);
}

.option.is-wrong kbd {
  background: var(--bad);
  border-color: var(--bad);
  color: #fff;
}

.option.is-removed {
  opacity: 0.3;
  text-decoration: line-through;
}

.option:disabled:not(.is-correct):not(.is-wrong):not(.is-removed) {
  opacity: 0.55;
}

@keyframes pop {
  0% { transform: scale(1); }
  45% { transform: scale(1.03); }
  100% { transform: scale(1); }
}

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

.lifelines {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  justify-content: center;
}

.feedback {
  min-height: 1.6em;
  font-weight: 500;
  font-size: 0.95rem;
  text-align: center;
}

.feedback.is-good {
  color: var(--good);
}

.feedback.is-bad {
  color: var(--bad);
}

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

.results {
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  gap: 12px;
}

.results__title {
  font-size: 1rem;
  font-weight: 500;
  color: var(--muted);
}

.results__score {
  font-size: clamp(3rem, 10vw, 4.75rem);
  font-weight: 700;
  letter-spacing: -0.045em;
  line-height: 1;
  font-variant-numeric: tabular-nums;
  color: var(--text);
}

.results__setup {
  color: var(--muted);
  font-size: 0.9rem;
}

.results__badge {
  padding: 5px 12px;
  border-radius: 6px;
  background: var(--accent-soft);
  border: 1px solid color-mix(in srgb, var(--accent) 40%, transparent);
  color: var(--accent);
  font-weight: 600;
  font-size: 0.82rem;
}

.stats-grid {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 1px;
  width: 100%;
  margin-top: 12px;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: var(--border);
  overflow: hidden;
}

@media (max-width: 720px) {
  .stats-grid {
    grid-template-columns: repeat(3, 1fr);
  }
}

@media (max-width: 460px) {
  .stats-grid {
    grid-template-columns: repeat(2, 1fr);
  }
}

.stats-grid .stat {
  align-items: center;
  text-align: center;
}

.results__actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 8px;
  margin-top: 12px;
}

.missed {
  width: 100%;
  margin-top: 28px;
  padding: 20px;
  border-radius: var(--radius);
  background: var(--surface);
  border: 1px solid var(--border);
  text-align: left;
}

.missed__title {
  margin-bottom: 14px;
  font-size: 0.95rem;
  font-weight: 600;
}

.missed__list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 8px;
}

.missed__item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 12px;
  border-radius: var(--radius-xs);
  background: var(--bg);
  border: 1px solid var(--border);
}

.missed__flag {
  width: 44px;
  height: 30px;
  object-fit: contain;
  border-radius: 3px;
  box-shadow: 0 0 0 1px var(--border-strong);
  background: var(--surface-3);
  flex: none;
}

.missed__name {
  display: block;
  font-weight: 500;
  font-size: 0.9rem;
  line-height: 1.25;
}

.missed__capital {
  display: block;
  font-size: 0.78rem;
  color: var(--muted);
}

.missed__empty {
  color: var(--good);
  font-weight: 500;
}

/* Leaderboard ------------------------------------------------------------ */

.board__head {
  margin-bottom: 20px;
}

.board__title {
  font-size: clamp(1.5rem, 4vw, 2rem);
  font-weight: 700;
  letter-spacing: -0.025em;
}

.board__note {
  color: var(--muted);
  margin-top: 4px;
}

.tabs {
  display: inline-flex;
  padding: 3px;
  margin-bottom: 16px;
  border-radius: var(--radius-xs);
  background: var(--surface-2);
  border: 1px solid var(--border);
}

.tabs [role="tab"] {
  padding: 7px 16px;
  border: 0;
  border-radius: 6px;
  background: transparent;
  color: var(--muted);
  font-weight: 500;
  font-size: 0.88rem;
  transition: background 0.15s, color 0.15s;
}

.tabs [role="tab"]:hover {
  color: var(--text);
}

.tabs [role="tab"][aria-selected="true"] {
  background: var(--surface);
  color: var(--text);
  box-shadow: var(--shadow-sm), 0 0 0 1px var(--border);
}

.table-wrap {
  overflow-x: auto;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: var(--surface);
}

.board {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.9rem;
}

.board th,
.board td {
  padding: 12px 14px;
  text-align: left;
  white-space: nowrap;
  border-bottom: 1px solid var(--border);
}

.board th {
  font-size: 0.72rem;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--muted);
  font-weight: 600;
  background: var(--surface-2);
}

.board tbody tr:last-child td {
  border-bottom: 0;
}

.board td:nth-child(3) {
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}

.board td:nth-child(4),
.board td:nth-child(5),
.board td:nth-child(7) {
  color: var(--text-2);
  font-variant-numeric: tabular-nums;
}

.board tr.is-you td {
  background: var(--accent-soft);
}

.board__rank {
  display: inline-grid;
  place-items: center;
  width: 26px;
  height: 26px;
  border-radius: 6px;
  background: var(--surface-3);
  font-weight: 600;
  font-size: 0.8rem;
  font-variant-numeric: tabular-nums;
}

.board__rank.is-gold {
  background: var(--primary);
  color: var(--primary-ink);
}

.board__empty {
  padding: 28px 16px;
  text-align: center;
  color: var(--muted);
}

.board__actions {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  flex-wrap: wrap;
  margin-top: 18px;
}

/* Dialogs ---------------------------------------------------------------- */

.dialog {
  width: min(92vw, 440px);
  padding: 24px;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--text);
  box-shadow: var(--shadow);
}

.dialog--wide {
  width: min(92vw, 560px);
}

.dialog::backdrop {
  background: rgba(0, 0, 0, 0.55);
  backdrop-filter: blur(4px);
}

.dialog[open] {
  animation: dialog-in 0.2s var(--ease);
}

@keyframes dialog-in {
  from {
    opacity: 0;
    transform: translateY(8px) scale(0.985);
  }
  to {
    opacity: 1;
    transform: none;
  }
}

.dialog__title {
  font-size: 1.2rem;
  font-weight: 600;
  letter-spacing: -0.02em;
  margin-bottom: 6px;
}

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

.dialog__actions {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 8px;
  flex-wrap: wrap;
  margin-top: 22px;
}

.dialog__actions--stack {
  flex-direction: column;
  align-items: stretch;
}

.dialog__actions--stack .btn {
  width: 100%;
}

.dialog__spacer {
  flex: 1;
}

.settings {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

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

.field--row {
  flex-direction: row;
  align-items: center;
  justify-content: space-between;
}

.field__label {
  font-weight: 500;
  font-size: 0.9rem;
}

.field__help {
  font-size: 0.8rem;
  color: var(--muted);
}

.switch {
  position: relative;
  display: inline-block;
  width: 40px;
  height: 24px;
}

.switch input {
  position: absolute;
  inset: 0;
  opacity: 0;
  margin: 0;
  cursor: pointer;
  z-index: 1;
}

.switch__track {
  position: absolute;
  inset: 0;
  border-radius: 999px;
  background: var(--surface-3);
  border: 1px solid var(--border-strong);
  transition: background 0.2s, border-color 0.2s;
}

.switch__track::after {
  content: "";
  position: absolute;
  top: 2px;
  left: 2px;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: var(--text);
  box-shadow: var(--shadow-sm);
  transition: transform 0.2s var(--ease), background 0.2s;
}

.switch input:checked + .switch__track {
  background: var(--accent);
  border-color: var(--accent);
}

.switch input:checked + .switch__track::after {
  transform: translateX(16px);
  background: #fff;
}

.switch input:focus-visible + .switch__track {
  box-shadow: var(--focus);
}

.help {
  display: flex;
  flex-direction: column;
  gap: 10px;
  color: var(--text-2);
  font-size: 0.92rem;
}

.help h3 {
  margin-top: 8px;
  font-size: 0.75rem;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--muted);
}

.help ul {
  margin: 0;
  padding-left: 20px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

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

.help__keys {
  list-style: none;
  padding-left: 0 !important;
}

/* Toast and footer ------------------------------------------------------- */

.toast {
  position: fixed;
  left: 50%;
  bottom: 24px;
  z-index: 50;
  max-width: min(92vw, 420px);
  padding: 10px 16px;
  border-radius: var(--radius-xs);
  background: var(--primary);
  color: var(--primary-ink);
  box-shadow: var(--shadow);
  font-weight: 500;
  font-size: 0.9rem;
  text-align: center;
  opacity: 0;
  transform: translate(-50%, 8px);
  transition: opacity 0.2s, transform 0.2s var(--ease);
}

.toast.is-visible {
  opacity: 1;
  transform: translate(-50%, 0);
}

.toast[data-kind="error"] {
  background: var(--danger);
  color: #fff;
}

.footer {
  padding-top: 20px;
  padding-bottom: 28px;
  border-top: 1px solid var(--border);
  font-size: 0.82rem;
  color: var(--muted);
  text-align: center;
}

.footer a {
  color: var(--text-2);
  text-decoration: none;
  border-bottom: 1px solid var(--border-strong);
}

.footer a:hover {
  color: var(--text);
}

/* Motion preferences ----------------------------------------------------- */

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.001ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.001ms !important;
  }
}
