:root {
  --bg: #eef4f6;
  --ink: #17313c;
  --muted: #5b7380;
  --card: #ffffff;
  --accent: #1f6f8b;
  --accent-dark: #164e61;
  --correct: #1f8a5b;
  --wrong: #c4453c;
  --shadow: 0 12px 28px rgba(23, 49, 60, 0.1);
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-left: env(safe-area-inset-left, 0px);
  --safe-right: env(safe-area-inset-right, 0px);
  --pad: clamp(10px, 1.6vh, 22px);
  --gap: clamp(8px, 1.2vh, 16px);
  --title: clamp(28px, 4.2vw + 1.2vh, 48px);
  --name: clamp(22px, 3.2vw + 1vh, 40px);
  --ui: clamp(15px, 1.6vw + 0.6vh, 22px);
  --speak: clamp(44px, 7vw, 64px);
}

* {
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

html,
body {
  margin: 0;
  width: 100%;
  height: 100%;
  overflow: hidden;
  background: var(--bg);
  color: var(--ink);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  -webkit-user-select: none;
  user-select: none;
}

body {
  position: fixed;
  inset: 0;
}

.app,
.screen {
  width: 100%;
  height: 100%;
}

.screen {
  display: none;
  padding: calc(var(--pad) + var(--safe-top)) calc(clamp(12px, 3vw, 28px) + var(--safe-right))
    calc(var(--pad) + var(--safe-bottom)) calc(clamp(12px, 3vw, 28px) + var(--safe-left));
}

.screen[hidden] {
  display: none !important;
}

.screen.is-active {
  display: flex;
  flex-direction: column;
}

#quiz-screen.is-active {
  display: grid;
  grid-template-rows: auto auto minmax(0, 1fr);
  gap: var(--gap);
  height: 100%;
  min-height: 0;
}

.start-card,
.result-card {
  margin: auto;
  width: min(640px, 100%);
  max-height: 100%;
  overflow: auto;
  background: var(--card);
  border-radius: clamp(20px, 3vw, 32px);
  box-shadow: var(--shadow);
  padding: clamp(20px, 4vh, 44px) clamp(16px, 4vw, 36px);
  text-align: center;
}

.eyebrow {
  margin: 0 0 8px;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  font-size: clamp(11px, 1.4vw, 13px);
  font-weight: 700;
  color: var(--accent);
}

h1,
h2 {
  margin: 0;
  font-weight: 700;
  letter-spacing: -0.03em;
}

h1 {
  font-size: var(--title);
}

.lead,
.offline-status,
.prompt-label,
.mode-chip,
.score,
.feedback,
.flag-caption,
.mode-sub {
  line-height: 1.3;
}

.lead {
  margin: 12px 0 0;
  color: var(--muted);
  font-size: clamp(16px, 2.2vw, 22px);
}

.offline-status {
  margin: 12px 0 0;
  color: var(--accent-dark);
  font-size: clamp(13px, 1.8vw, 16px);
  font-weight: 600;
}

.mode-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: clamp(10px, 2vw, 18px);
  margin-top: clamp(18px, 3vh, 32px);
}

.mode-btn,
.primary-btn,
.speak-btn {
  appearance: none;
  border: 0;
  cursor: pointer;
  font: inherit;
}

.mode-btn,
.primary-btn {
  min-height: clamp(72px, 12vh, 108px);
  border-radius: 20px;
  background: var(--accent);
  color: #fff;
  box-shadow: 0 10px 24px rgba(31, 111, 139, 0.28);
}

.mode-btn:nth-child(2) {
  background: var(--accent-dark);
}

.mode-title,
.mode-sub {
  display: block;
}

.mode-title {
  font-size: clamp(20px, 3vw, 28px);
  font-weight: 700;
}

.mode-sub {
  margin-top: 4px;
  font-size: clamp(13px, 1.8vw, 16px);
  opacity: 0.86;
}

.mode-btn:active,
.primary-btn:active,
.flag-btn:active,
.speak-btn:active {
  transform: scale(0.97);
}

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

.mode-chip,
.score {
  margin: 0;
  font-size: var(--ui);
  font-weight: 700;
}

.mode-chip {
  color: var(--accent);
}

.prompt {
  text-align: center;
  min-width: 0;
}

.prompt-label {
  margin: 0;
  color: var(--muted);
  font-size: clamp(14px, 2vw, 18px);
  font-weight: 600;
}

.country-row {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: clamp(8px, 2vw, 14px);
  margin-top: 4px;
}

#country-name {
  font-size: var(--name);
  line-height: 1.15;
  max-width: min(16ch, 100%);
}

.speak-btn {
  width: var(--speak);
  height: var(--speak);
  flex: 0 0 var(--speak);
  border-radius: 50%;
  background: var(--accent);
  color: #fff;
  font-size: calc(var(--speak) * 0.42);
  box-shadow: 0 8px 18px rgba(31, 111, 139, 0.28);
}

.speak-btn.is-speaking {
  background: var(--accent-dark);
}

.feedback {
  min-height: 1.3em;
  margin: 4px 0 0;
  font-size: clamp(15px, 2vw, 20px);
  font-weight: 700;
}

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

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

.flag-options {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  grid-template-rows: repeat(2, minmax(0, 1fr));
  gap: var(--gap);
  min-height: 0;
  height: 100%;
  width: min(100%, 980px);
  margin: 0 auto;
}

.flag-btn {
  display: grid;
  grid-template-rows: minmax(0, 1fr) auto;
  place-items: center;
  min-width: 0;
  min-height: 0;
  height: 100%;
  width: 100%;
  padding: clamp(6px, 1.2vw, 14px);
  border-radius: clamp(14px, 2vw, 22px);
  border: 3px solid transparent;
  background: #fff;
  box-shadow: var(--shadow);
  cursor: pointer;
}

.flag-btn img {
  display: block;
  width: 100%;
  height: 100%;
  max-width: 100%;
  max-height: 100%;
  min-width: 0;
  min-height: 0;
  object-fit: contain;
  object-position: center;
  border-radius: 6px;
}

.flag-caption {
  display: none;
  margin-top: 4px;
  font-size: clamp(12px, 1.7vw, 17px);
  font-weight: 700;
  color: var(--ink);
  text-align: center;
}

.flag-btn.is-revealed .flag-caption {
  display: block;
}

.flag-btn.is-correct {
  background: #e8f7ef;
  border-color: var(--correct);
}

.flag-btn.is-wrong {
  background: #fdeeee;
  border-color: var(--wrong);
}

.flag-btn.is-disabled {
  pointer-events: none;
}

.result-score {
  margin: 12px 0 6px;
  font-size: clamp(40px, 8vw, 72px);
  font-weight: 800;
  letter-spacing: -0.04em;
}

.primary-btn {
  width: 100%;
  margin-top: clamp(16px, 3vh, 28px);
  font-size: clamp(20px, 3vw, 28px);
  font-weight: 700;
}

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

@media (orientation: landscape) and (min-width: 700px) {
  #quiz-screen.is-active {
    grid-template-columns: minmax(200px, 0.8fr) minmax(0, 1.25fr);
    grid-template-rows: auto minmax(0, 1fr);
    column-gap: clamp(12px, 2.5vw, 28px);
  }

  .quiz-bar {
    grid-column: 1 / -1;
  }

  .prompt {
    align-self: center;
  }

  .flag-options {
    grid-column: 2;
    grid-row: 2;
    width: 100%;
  }
}

@media (orientation: landscape) and (max-height: 520px) {
  :root {
    --pad: 8px;
    --gap: 8px;
    --name: clamp(20px, 3.4vw, 28px);
    --speak: 44px;
  }

  .feedback {
    min-height: 0;
    font-size: 14px;
  }
}
