:root {
  --bg: #0b0d13;
  --surface: rgba(15, 18, 27, .88);
  --panel: #141826;
  --field: #11141d;
  --line: rgba(255, 255, 255, .1);
  --line-soft: rgba(255, 255, 255, .06);
  --text: #eef1f7;
  --muted: #8b93a8;
  --accent: #f0c24b;
  --accent-dim: rgba(240, 194, 75, .14);
  --success: #48d597;
  --danger: #ff6b6b;
  --tile: 56px;
  --gap: 8px;
}

* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; }
body {
  background: var(--bg);
  color: var(--text);
  font-family: Inter, system-ui, -apple-system, Segoe UI, Roboto, sans-serif;
  overflow-x: hidden;
  -webkit-font-smoothing: antialiased;
}

button, input { font: inherit; }
button { cursor: pointer; }

button:focus-visible,
input:focus-visible,
.tile:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 3px;
  box-shadow: 0 0 0 4px rgba(240, 194, 75, .18);
}

.app-bar {
  position: sticky;
  top: 0;
  z-index: 40;
  background: var(--surface);
  border-bottom: 1px solid var(--line);
  backdrop-filter: blur(14px);
}

.bar-inner {
  max-width: 1440px;
  margin: 0 auto;
  padding: 14px 20px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  flex-wrap: wrap;
}

.brand {
  color: var(--text);
  text-decoration: none;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.brand-name {
  font-family: "Space Grotesk", sans-serif;
  font-size: 1.22rem;
  font-weight: 700;
  letter-spacing: .04em;
}

.brand-name::first-letter { color: var(--accent); }
.brand-subtitle {
  color: var(--muted);
  font-size: .68rem;
  font-weight: 600;
  letter-spacing: .18em;
  text-transform: uppercase;
}

.view-tabs, .segmented, .answer-row, .score-row, .round-controls, .round-timer {
  display: flex;
  align-items: center;
  gap: 8px;
}

.tab, .segmented button, .secondary, .guess-form button, .round-action {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--field);
  color: var(--text);
  padding: 8px 12px;
}

.tab[aria-pressed="true"], .segmented button[aria-pressed="true"], .guess-form button[type="submit"], .start-round[aria-pressed="true"] {
  background: var(--accent-dim);
  border-color: rgba(240, 194, 75, .4);
  color: var(--accent);
  font-weight: 700;
}

.round-action:disabled {
  cursor: not-allowed;
  opacity: .48;
}

.app-shell {
  max-width: 1440px;
  margin: 0 auto;
  padding: 22px 20px 48px;
}

.view[hidden] { display: none; }
.quiz-layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 280px;
  gap: 18px;
  align-items: start;
}

.quiz-panel, .progress-panel, .detail-panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 18px;
}

.quiz-meta {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  flex-wrap: wrap;
}

.quiz-title {
  display: grid;
  gap: 5px;
  min-width: min(100%, 220px);
}

.quiz-context,
.game-scope {
  margin: 0;
  color: var(--muted);
  font-size: .86rem;
  line-height: 1.35;
}

.game-switch {
  flex-wrap: wrap;
}

h1, h2 { font-family: "Space Grotesk", sans-serif; margin: 0; }
h1 {
  font-size: 1.8rem;
  line-height: 1.08;
}
h2 { font-size: 1rem; }

@media (min-width: 720px) {
  h1 { font-size: 2.1rem; }
}

@media (min-width: 1100px) {
  h1 { font-size: 2.4rem; }
}

.score-row span {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 8px 10px;
  color: var(--muted);
}

.score-row b, .progress-panel b { color: var(--accent); }

.round-controls {
  flex-wrap: wrap;
}

.round-action {
  min-width: 86px;
  font-weight: 800;
}

.round-timer {
  min-height: 37px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 7px 10px;
  color: var(--muted);
  background: rgba(8, 10, 16, .56);
  white-space: nowrap;
}

.round-timer b {
  min-width: 2ch;
  color: var(--text);
  font-family: "Space Grotesk", Inter, system-ui, sans-serif;
  font-size: 1.1rem;
  text-align: center;
}

.round-timer.is-running {
  border-color: rgba(72, 213, 151, .36);
}

.round-timer.is-running b {
  color: var(--success);
}

.round-timer.is-warning {
  border-color: rgba(255, 107, 107, .48);
  background: rgba(255, 107, 107, .08);
}

.round-timer.is-warning b {
  color: var(--danger);
}

.world-cup-groups {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(42px, 1fr));
  gap: 6px;
  margin: 14px 0;
}

.world-cup-groups[hidden] { display: none; }

.world-cup-groups span {
  border: 1px solid var(--line-soft);
  border-radius: 7px;
  padding: 5px 6px;
  color: var(--muted);
  font-size: .74rem;
  font-weight: 700;
  text-align: center;
}

.flag-stage {
  margin: 18px 0;
  background: #080a10;
  border: 1px solid var(--line-soft);
  border-radius: 8px;
  min-height: 260px;
  display: grid;
  place-items: center;
}

.flag-stage img {
  width: min(640px, 100%);
  height: auto;
  aspect-ratio: 3 / 2;
  object-fit: contain;
}

.text-prompt {
  width: min(640px, 100%);
  min-height: 260px;
  display: grid;
  align-content: center;
  padding: 30px;
  color: var(--text);
  background:
    linear-gradient(135deg, rgba(240, 194, 75, .08), transparent 44%),
    #080a10;
  border: 1px solid var(--line-soft);
  border-radius: 6px;
  font-family: "Space Grotesk", Inter, system-ui, sans-serif;
  font-size: clamp(1.05rem, 1.4vw, 1.45rem);
  font-weight: 500;
  line-height: 1.42;
}

.text-prompt[hidden] { display: none; }

.image-fallback {
  display: grid;
  place-items: center;
  width: 100%;
  min-height: 100%;
  padding: 8px;
  color: var(--text);
  font-weight: 700;
  line-height: 1.18;
  letter-spacing: 0;
  text-align: center;
  overflow-wrap: anywhere;
}

.flag-stage .image-fallback {
  width: min(640px, 100%);
  aspect-ratio: 3 / 2;
  color: var(--muted);
  background: #080a10;
  border: 1px dashed var(--line-soft);
  border-radius: 6px;
}

.guess-form {
  display: grid;
  gap: 8px;
}

.guess-form label, .search-field span, .size-field span {
  color: var(--muted);
  font-size: .72rem;
  font-weight: 700;
  letter-spacing: .14em;
  text-transform: uppercase;
}

.answer-row input, .search-field input {
  min-width: 0;
  flex: 1;
  color: var(--text);
  background: var(--field);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px 12px;
}

.answer-row button {
  min-height: 44px;
}

.voice-controls, .voice-language {
  display: flex;
  align-items: center;
  gap: 8px;
}

.voice-controls[hidden] {
  display: none;
}

.voice-guess {
  min-width: 92px;
  font-weight: 800;
  touch-action: none;
  user-select: none;
}

.voice-language button {
  min-width: 48px;
  padding-inline: 10px;
  font-weight: 800;
}

.voice-language button[aria-pressed="true"] {
  background: rgba(72, 213, 151, .1);
  border-color: rgba(72, 213, 151, .42);
  color: var(--success);
}

.voice-guess.is-listening {
  border-color: rgba(72, 213, 151, .46);
  color: var(--success);
  background: rgba(72, 213, 151, .1);
}

.voice-status {
  min-height: 1.25em;
  color: var(--muted);
  margin: 0;
}

.voice-status[hidden] {
  display: none;
}

.feedback { min-height: 1.4em; color: var(--muted); margin: 0; }
.feedback.is-correct { color: var(--success); }
.feedback.is-wrong { color: var(--danger); }

.toolbar {
  display: flex;
  align-items: end;
  gap: 12px;
  flex-wrap: wrap;
  margin-bottom: 16px;
}

.search-field, .size-field {
  display: grid;
  gap: 5px;
}

.flag-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(var(--tile), 1fr));
  gap: var(--gap);
  align-items: start;
}

.region-head {
  grid-column: 1 / -1;
  display: flex;
  align-items: center;
  gap: 12px;
  margin: 18px 2px 6px;
}

.region-head h2 {
  font-size: .82rem;
  letter-spacing: .18em;
  text-transform: uppercase;
}

.region-head .rule {
  flex: 1;
  height: 1px;
  background: linear-gradient(90deg, var(--line), transparent);
}

.tile {
  position: relative;
  display: block;
  width: 100%;
  aspect-ratio: 3 / 2;
  padding: 0;
  background: var(--panel);
  border: 1px solid var(--line-soft);
  border-radius: 3px;
  overflow: hidden;
}

.tile img { width: 100%; height: 100%; object-fit: contain; display: block; }
.tile .image-fallback {
  height: 100%;
  font-size: .72rem;
}
.tile:hover {
  border-color: var(--accent);
  box-shadow: 0 0 0 1px rgba(240, 194, 75, .34), 0 8px 22px rgba(0, 0, 0, .28);
}

.tile:focus-visible { border-color: var(--accent); }

.learn-layout {
  display: grid;
  grid-template-columns: 280px minmax(0, 1fr);
  gap: 18px;
}

.detail-flag {
  width: min(420px, 100%);
  aspect-ratio: 3 / 2;
  object-fit: contain;
  background: #080a10;
  border: 1px solid var(--line-soft);
  border-radius: 6px;
}

.detail-panel .image-fallback {
  width: min(420px, 100%);
  aspect-ratio: 3 / 2;
  background: #080a10;
  border: 1px dashed var(--line-soft);
  border-radius: 6px;
}

.detail-description, .detail-visual {
  max-width: 780px;
  line-height: 1.58;
}

.detail-visual {
  color: var(--muted);
}

.fun-facts {
  display: grid;
  gap: 12px;
  max-width: 860px;
  margin-top: 8px;
  padding-top: 14px;
  border-top: 1px solid var(--line-soft);
}

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

.facts-header h3 {
  margin: 0;
  font-size: .88rem;
  letter-spacing: .12em;
  text-transform: uppercase;
}

.facts-list {
  display: grid;
  gap: 12px;
}

.fact-item {
  padding-top: 12px;
  border-top: 1px solid var(--line-soft);
}

.fact-item:first-child {
  padding-top: 0;
  border-top: 0;
}

.fact-item h4 {
  margin: 0 0 4px;
  font-size: .98rem;
}

.fact-item p {
  margin: 0;
  color: var(--muted);
  line-height: 1.52;
}

.muted, .empty { color: var(--muted); }

.tooltip {
  position: fixed;
  z-index: 60;
  pointer-events: none;
  background: #1b2030;
  border: 1px solid var(--line);
  padding: 5px 10px;
  border-radius: 7px;
  max-width: min(260px, calc(100vw - 24px));
  overflow-wrap: break-word;
  visibility: hidden;
}

.tooltip.show { visibility: visible; }

@media (max-width: 820px) {
  .app-shell { padding: 14px 12px 32px; }
  .quiz-panel, .progress-panel, .detail-panel { padding: 14px; }
  .quiz-layout, .learn-layout { grid-template-columns: 1fr; }
  .quiz-meta {
    align-items: stretch;
    gap: 10px;
  }
  .game-switch, .score-row, .round-controls { width: 100%; }
  .game-switch button, .score-row span, .round-action, .round-timer {
    flex: 1;
    justify-content: center;
    text-align: center;
  }
  .answer-row { flex-wrap: wrap; }
  .answer-row input { flex-basis: 100%; }
  .answer-row button {
    flex: 1 1 calc(50% - 8px);
    text-align: center;
  }
  .answer-row .voice-controls {
    flex-basis: 100%;
  }
  .answer-row .voice-guess {
    flex: 1;
    min-height: 64px;
    font-size: 1.08rem;
  }
  .voice-language button {
    flex: 1;
    min-height: 52px;
  }
  .flag-stage {
    min-height: 200px;
    margin: 12px 0;
  }
  .text-prompt {
    min-height: 200px;
    padding: 20px;
  }
}
