:root {
  color-scheme: dark;
  --bg: #07101d;
  --bg-deep: #040a13;
  --surface: rgba(13, 27, 45, 0.84);
  --surface-solid: #0d1b2d;
  --surface-2: rgba(22, 42, 65, 0.74);
  --surface-3: #162a41;
  --border: rgba(155, 189, 224, 0.18);
  --border-strong: rgba(167, 207, 245, 0.32);
  --text: #f6f9fc;
  --text-soft: #c2cfdd;
  --muted: #8295aa;
  --accent: #67e8f9;
  --accent-strong: #22d3ee;
  --accent-ink: #03232b;
  --gold: #f8d66d;
  --gold-strong: #f5bd38;
  --green: #64e6a4;
  --green-strong: #20c77a;
  --red: #ff7a8a;
  --red-strong: #f14f66;
  --purple: #b4a0ff;
  --ocean-1: #0b1e36;
  --ocean-2: #0b2637;
  --land: #27405a;
  --land-hover: #365873;
  --territory: #1b3047;
  --graticule: rgba(135, 181, 218, 0.11);
  --shadow: 0 24px 70px rgba(0, 0, 0, 0.34);
  --shadow-soft: 0 14px 35px rgba(0, 0, 0, 0.2);
  --radius-xl: 28px;
  --radius-lg: 20px;
  --radius-md: 14px;
  --radius-sm: 10px;
  --topbar-height: 76px;
  --max-width: 1680px;
  --focus: 0 0 0 3px rgba(103, 232, 249, 0.28);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

html[data-theme="light"] {
  color-scheme: light;
  --bg: #eef5f7;
  --bg-deep: #dce9ee;
  --surface: rgba(255, 255, 255, 0.88);
  --surface-solid: #ffffff;
  --surface-2: rgba(237, 246, 249, 0.9);
  --surface-3: #e2eef2;
  --border: rgba(47, 88, 111, 0.15);
  --border-strong: rgba(47, 88, 111, 0.28);
  --text: #102331;
  --text-soft: #3b5465;
  --muted: #6c8190;
  --accent: #0e9fb8;
  --accent-strong: #067f97;
  --accent-ink: #ffffff;
  --gold: #d99c11;
  --gold-strong: #b77c00;
  --green: #189d65;
  --green-strong: #0c8150;
  --red: #d94259;
  --red-strong: #ba2f44;
  --purple: #7864d4;
  --ocean-1: #d7edf3;
  --ocean-2: #c8e7e8;
  --land: #8cafb4;
  --land-hover: #719ba1;
  --territory: #b5cdd0;
  --graticule: rgba(48, 91, 110, 0.13);
  --shadow: 0 24px 70px rgba(36, 71, 86, 0.16);
  --shadow-soft: 0 14px 35px rgba(36, 71, 86, 0.12);
  --focus: 0 0 0 3px rgba(14, 159, 184, 0.24);
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

html {
  min-height: 100%;
  background: var(--bg-deep);
  scroll-behavior: smooth;
}

body {
  min-height: 100vh;
  margin: 0;
  overflow-x: hidden;
  background:
    radial-gradient(circle at 15% 10%, rgba(34, 211, 238, 0.08), transparent 34rem),
    radial-gradient(circle at 85% 82%, rgba(180, 160, 255, 0.08), transparent 34rem),
    linear-gradient(145deg, var(--bg-deep), var(--bg));
  color: var(--text);
  -webkit-font-smoothing: antialiased;
}

button, input, select { font: inherit; }
button { color: inherit; }
button, label, summary, select { -webkit-tap-highlight-color: transparent; }

button:focus-visible,
input:focus-visible,
select:focus-visible,
summary:focus-visible,
[tabindex]:focus-visible {
  outline: none;
  box-shadow: var(--focus);
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.48;
}

.sr-only {
  position: absolute !important;
  width: 1px !important;
  height: 1px !important;
  padding: 0 !important;
  margin: -1px !important;
  overflow: hidden !important;
  clip: rect(0, 0, 0, 0) !important;
  white-space: nowrap !important;
  border: 0 !important;
}

.skip-link {
  position: fixed;
  z-index: 1000;
  left: 16px;
  top: 12px;
  transform: translateY(-150%);
  border-radius: 10px;
  background: var(--surface-solid);
  color: var(--text);
  padding: 10px 14px;
  text-decoration: none;
  box-shadow: var(--shadow-soft);
}

.skip-link:focus { transform: translateY(0); }

.ambient {
  position: fixed;
  z-index: -1;
  width: 38rem;
  height: 38rem;
  border-radius: 50%;
  filter: blur(85px);
  pointer-events: none;
  opacity: 0.18;
}

.ambient-one {
  top: -18rem;
  left: -12rem;
  background: var(--accent-strong);
}

.ambient-two {
  right: -16rem;
  bottom: -20rem;
  background: var(--purple);
}

.topbar {
  position: sticky;
  z-index: 50;
  top: 0;
  display: grid;
  grid-template-columns: minmax(230px, 1fr) auto minmax(230px, 1fr);
  align-items: center;
  min-height: var(--topbar-height);
  padding: 10px clamp(16px, 3vw, 44px);
  border-bottom: 1px solid var(--border);
  background: color-mix(in srgb, var(--bg) 78%, transparent);
  backdrop-filter: blur(20px) saturate(145%);
}

.brand {
  display: inline-flex;
  align-items: center;
  justify-self: start;
  gap: 11px;
  min-width: 0;
  border: 0;
  background: transparent;
  cursor: pointer;
  text-align: left;
  padding: 4px;
  border-radius: 13px;
}

.brand-mark {
  display: grid;
  flex: 0 0 auto;
  width: 42px;
  height: 42px;
  place-items: center;
  border: 1px solid rgba(103, 232, 249, 0.36);
  border-radius: 14px;
  background: linear-gradient(145deg, rgba(103, 232, 249, 0.2), rgba(180, 160, 255, 0.12));
  box-shadow: inset 0 0 20px rgba(103, 232, 249, 0.09);
}

.brand-mark svg {
  width: 29px;
  fill: none;
  stroke: var(--accent);
  stroke-width: 1.6;
}

.brand strong,
.brand small { display: block; }
.brand strong { font-size: 1.03rem; letter-spacing: -0.02em; }
.brand small { margin-top: 1px; color: var(--muted); font-size: 0.72rem; }

.primary-nav {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 4px;
  padding: 4px;
  border: 1px solid var(--border);
  border-radius: 14px;
  background: var(--surface-2);
}

.nav-button {
  min-width: 78px;
  border: 0;
  border-radius: 10px;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  padding: 9px 14px;
  font-size: 0.87rem;
  font-weight: 750;
  transition: 160ms ease;
}

.nav-button:hover { color: var(--text); }
.nav-button.is-active {
  background: var(--surface-solid);
  color: var(--text);
  box-shadow: var(--shadow-soft);
}

.top-actions {
  display: flex;
  align-items: center;
  justify-self: end;
  gap: 7px;
}

.icon-button,
.map-tool,
.modal-close,
.star-button {
  display: inline-grid;
  place-items: center;
  border: 1px solid var(--border);
  background: var(--surface-2);
  cursor: pointer;
  transition: 150ms ease;
}

.icon-button {
  width: 38px;
  height: 38px;
  border-radius: 12px;
}

.icon-button:hover,
.map-tool:hover,
.modal-close:hover,
.star-button:hover {
  border-color: var(--border-strong);
  background: var(--surface-3);
  transform: translateY(-1px);
}

.icon-button svg {
  width: 19px;
  height: 19px;
  fill: none;
  stroke: currentColor;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-width: 1.8;
}

.icon-sound-off,
.icon-sun { display: none; }
body.is-muted .icon-sound-on { display: none; }
body.is-muted .icon-sound-off { display: block; }
html[data-theme="light"] .icon-moon { display: none; }
html[data-theme="light"] .icon-sun { display: block; }

.run-pill {
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 38px;
  padding: 7px 12px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--surface-2);
  color: var(--muted);
  font-size: 0.75rem;
}
.run-pill strong { color: var(--accent); font-size: 0.92rem; }

.app-shell {
  width: min(var(--max-width), 100%);
  margin: 0 auto;
  padding: clamp(14px, 2vw, 30px) clamp(12px, 2.4vw, 40px) 38px;
}

.game-layout {
  display: grid;
  grid-template-columns: minmax(300px, 370px) minmax(0, 1fr);
  gap: clamp(14px, 1.8vw, 26px);
  min-height: calc(100vh - var(--topbar-height) - 68px);
}

.glass-card {
  border: 1px solid var(--border);
  background: linear-gradient(155deg, var(--surface), color-mix(in srgb, var(--surface-solid) 80%, transparent));
  box-shadow: var(--shadow);
  backdrop-filter: blur(18px) saturate(120%);
}

.mission-panel {
  position: relative;
  align-self: stretch;
  min-height: 680px;
  overflow: hidden;
  border-radius: var(--radius-xl);
  padding: clamp(20px, 2vw, 30px);
}

.mission-panel::before {
  position: absolute;
  top: -8rem;
  right: -8rem;
  width: 18rem;
  height: 18rem;
  border-radius: 50%;
  background: radial-gradient(circle, rgba(103, 232, 249, 0.1), transparent 65%);
  content: "";
  pointer-events: none;
}

.mission-topline,
.section-head,
.footer-copy,
.accuracy-row,
.map-toolbar,
.study-country-head,
.country-card-head,
.setup-footer,
.modal-head,
.rank-card > div,
.mastery-overview > div,
.mastery-block > div,
.missed-section > div:first-child {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.eyebrow-chip {
  display: inline-flex;
  align-items: center;
  width: max-content;
  border: 1px solid rgba(103, 232, 249, 0.24);
  border-radius: 999px;
  background: rgba(103, 232, 249, 0.1);
  color: var(--accent);
  padding: 6px 10px;
  font-size: 0.7rem;
  font-weight: 850;
  letter-spacing: 0.09em;
  text-transform: uppercase;
}

.text-button {
  border: 0;
  border-radius: 8px;
  background: transparent;
  color: var(--accent);
  cursor: pointer;
  padding: 5px 2px;
  font-size: 0.79rem;
  font-weight: 750;
}
.text-button:hover { text-decoration: underline; text-underline-offset: 3px; }

.score-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 7px;
  margin-top: 18px;
}

.score-grid > div {
  min-width: 0;
  padding: 10px 8px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--surface-2);
  text-align: center;
}

.score-grid span,
.score-grid strong { display: block; }
.score-grid span { color: var(--muted); font-size: 0.63rem; letter-spacing: 0.03em; text-transform: uppercase; }
.score-grid strong { margin-top: 4px; overflow: hidden; text-overflow: ellipsis; font-size: 0.92rem; }

.mission-copy { margin-top: clamp(30px, 5vh, 54px); }
.mission-kicker,
.modal-eyebrow {
  margin: 0 0 10px;
  color: var(--accent);
  font-size: 0.76rem;
  font-weight: 850;
  letter-spacing: 0.11em;
  text-transform: uppercase;
}

.mission-copy h1,
.study-intro h1 {
  margin: 0;
  font-size: clamp(1.65rem, 2.5vw, 2.55rem);
  line-height: 1.03;
  letter-spacing: -0.055em;
}

.mission-copy > p:last-child,
.study-intro p {
  margin: 15px 0 0;
  color: var(--text-soft);
  font-size: 0.93rem;
  line-height: 1.6;
}

.flag-prompt {
  display: none;
  width: max-content;
  margin: 3px 0 16px;
  font-size: clamp(4rem, 7vw, 6rem);
  line-height: 1;
  filter: drop-shadow(0 12px 20px rgba(0,0,0,.18));
}
.flag-prompt.is-visible { display: block; animation: flag-in 320ms ease both; }

.reverse-form,
.study-search { margin-top: 22px; }
.reverse-form label,
.study-search label {
  display: block;
  margin-bottom: 8px;
  color: var(--text-soft);
  font-size: 0.76rem;
  font-weight: 750;
}

.input-row {
  display: flex;
  align-items: stretch;
  gap: 8px;
}

input[type="text"],
input[list],
select {
  min-width: 0;
  width: 100%;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--surface-2);
  color: var(--text);
  padding: 12px 13px;
}

input::placeholder { color: color-mix(in srgb, var(--muted) 78%, transparent); }
select option { background: var(--surface-solid); color: var(--text); }

.keyboard-answer {
  margin-top: 14px;
  border-top: 1px solid var(--border);
  border-bottom: 1px solid var(--border);
  padding: 10px 0;
}
.keyboard-answer summary {
  color: var(--muted);
  cursor: pointer;
  font-size: 0.74rem;
  user-select: none;
}
.keyboard-answer[open] summary { margin-bottom: 10px; color: var(--text-soft); }

.primary-button,
.secondary-button,
.ghost-button,
.danger-button {
  border-radius: 12px;
  cursor: pointer;
  font-weight: 800;
  transition: transform 150ms ease, filter 150ms ease, border-color 150ms ease, background 150ms ease;
}

.primary-button:hover,
.secondary-button:hover,
.ghost-button:hover,
.danger-button:hover { transform: translateY(-1px); filter: brightness(1.04); }
.primary-button:active,
.secondary-button:active,
.ghost-button:active,
.danger-button:active { transform: translateY(0); }

.primary-button {
  border: 1px solid color-mix(in srgb, var(--accent-strong) 70%, white);
  background: linear-gradient(135deg, var(--accent), var(--accent-strong));
  color: var(--accent-ink);
  padding: 12px 16px;
  box-shadow: 0 10px 24px rgba(34, 211, 238, 0.15);
}

.secondary-button {
  border: 1px solid var(--border-strong);
  background: var(--surface-2);
  color: var(--text);
  padding: 11px 15px;
}

.ghost-button {
  border: 1px solid transparent;
  background: transparent;
  color: var(--muted);
  padding: 11px 14px;
}
.ghost-button:hover { border-color: var(--border); color: var(--text); }

.danger-button {
  border: 1px solid rgba(255, 122, 138, 0.35);
  background: rgba(255, 122, 138, 0.09);
  color: var(--red);
  padding: 11px 15px;
}

.compact { padding: 10px 13px; border-radius: 11px; white-space: nowrap; }
.large { min-height: 52px; padding-inline: 24px; }

.mission-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 19px;
}
.mission-actions .secondary-button { flex: 1; }
.mission-actions small { margin-left: 5px; color: var(--muted); font-size: 0.66rem; }

.hint-box {
  margin-top: 13px;
  border: 1px solid rgba(248, 214, 109, 0.26);
  border-radius: 13px;
  background: rgba(248, 214, 109, 0.08);
  padding: 12px 13px;
  animation: slide-in 220ms ease both;
}
.hint-box strong { color: var(--gold); font-size: 0.72rem; text-transform: uppercase; letter-spacing: .08em; }
.hint-box p { margin: 5px 0 0; color: var(--text-soft); font-size: 0.82rem; line-height: 1.45; }

.feedback {
  display: grid;
  grid-template-columns: 9px minmax(0, 1fr);
  align-items: start;
  gap: 9px;
  min-height: 47px;
  margin-top: 15px;
  border: 1px solid var(--border);
  border-radius: 13px;
  background: color-mix(in srgb, var(--surface-2) 82%, transparent);
  padding: 12px;
}
.feedback-icon {
  width: 8px;
  height: 8px;
  margin-top: 5px;
  border-radius: 50%;
  background: var(--muted);
  box-shadow: 0 0 0 4px color-mix(in srgb, var(--muted) 15%, transparent);
}
.feedback p { margin: 0; color: var(--text-soft); font-size: 0.81rem; line-height: 1.45; }
.feedback.is-correct { border-color: rgba(100, 230, 164, 0.3); background: rgba(100, 230, 164, 0.07); }
.feedback.is-correct .feedback-icon { background: var(--green); box-shadow: 0 0 0 4px rgba(100, 230, 164, 0.14); }
.feedback.is-wrong { border-color: rgba(255, 122, 138, 0.3); background: rgba(255, 122, 138, 0.07); }
.feedback.is-wrong .feedback-icon { background: var(--red); box-shadow: 0 0 0 4px rgba(255, 122, 138, 0.14); }
.feedback.is-info .feedback-icon { background: var(--accent); box-shadow: 0 0 0 4px rgba(103, 232, 249, 0.14); }

.accuracy-row {
  margin-top: 16px;
  color: var(--muted);
  font-size: 0.72rem;
}
.accuracy-row .meter { flex: 1; }
.accuracy-row strong { min-width: 38px; color: var(--text-soft); text-align: right; }

.meter {
  height: 6px;
  overflow: hidden;
  border-radius: 999px;
  background: var(--surface-3);
}
.meter > span {
  display: block;
  width: 0;
  height: 100%;
  border-radius: inherit;
  background: linear-gradient(90deg, var(--accent-strong), var(--green));
  transition: width 350ms ease;
}
.meter.large { height: 8px; }
.meter.extra-large { height: 12px; }

.country-card {
  margin-top: 20px;
  border: 1px solid var(--border);
  border-radius: 18px;
  background: linear-gradient(145deg, var(--surface-2), color-mix(in srgb, var(--surface-3) 55%, transparent));
  padding: 16px;
  animation: card-in 300ms ease both;
}
.country-card-head { justify-content: flex-start; }
.country-flag { font-size: 2.5rem; line-height: 1; }
.country-card-head p,
.study-country-head p { margin: 0 0 3px; color: var(--muted); font-size: 0.68rem; text-transform: uppercase; letter-spacing: .08em; }
.country-card-head h2,
.study-country-head h2 { margin: 0; font-size: 1.08rem; line-height: 1.15; letter-spacing: -0.025em; }

.country-facts,
.study-facts {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin: 14px 0 0;
}
.country-facts div,
.study-facts div {
  min-width: 0;
  border-top: 1px solid var(--border);
  padding-top: 9px;
}
.country-facts dt,
.study-facts dt { color: var(--muted); font-size: 0.64rem; text-transform: uppercase; letter-spacing: .05em; }
.country-facts dd,
.study-facts dd { margin: 4px 0 0; color: var(--text-soft); font-size: 0.77rem; line-height: 1.35; }
.capital-note { margin: 12px 0 0; color: var(--muted); font-size: 0.71rem; line-height: 1.45; }
.capital-note::before { content: "Note: "; color: var(--gold); font-weight: 800; }

.map-card {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
  min-width: 0;
  min-height: 680px;
  overflow: hidden;
  border-radius: var(--radius-xl);
}

.map-toolbar {
  padding: 16px 18px 13px;
  border-bottom: 1px solid var(--border);
}
.map-toolbar > div:first-child {
  display: grid;
  grid-template-columns: auto auto;
  justify-content: start;
  align-items: center;
  column-gap: 8px;
}
.map-toolbar strong { font-size: 0.85rem; }
.map-toolbar small { grid-column: 2; margin-top: 2px; color: var(--muted); font-size: 0.68rem; }
.map-status-dot {
  grid-row: 1 / span 2;
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: var(--muted);
  box-shadow: 0 0 0 4px color-mix(in srgb, var(--muted) 13%, transparent);
}
.map-status-dot.is-live { background: var(--green); box-shadow: 0 0 0 4px rgba(100, 230, 164, 0.13); }
.map-status-dot.is-study { background: var(--accent); box-shadow: 0 0 0 4px rgba(103, 232, 249, 0.13); }
.map-tools { display: flex; gap: 5px; }
.map-tool { width: 34px; height: 34px; border-radius: 10px; color: var(--text-soft); font-size: 1.05rem; }

.map-stage {
  position: relative;
  min-height: 560px;
  overflow: hidden;
  background:
    radial-gradient(circle at 50% 48%, rgba(103, 232, 249, 0.055), transparent 32rem),
    var(--ocean-1);
  isolation: isolate;
}

#worldMap {
  display: block;
  width: 100%;
  height: 100%;
  min-height: 560px;
  touch-action: none;
  cursor: grab;
  user-select: none;
}
#worldMap.is-dragging { cursor: grabbing; }
#worldMap.is-keyboard-focused { box-shadow: inset var(--focus); }

.ocean { fill: url(#oceanGradient); }
.ocean-stop-one { stop-color: var(--ocean-1); }
.ocean-stop-two { stop-color: var(--ocean-2); }

#mapViewport { transform-origin: 0 0; transition: transform 340ms cubic-bezier(.22,.8,.2,1); }
#worldMap.is-dragging #mapViewport,
#worldMap.is-pinching #mapViewport { transition: none; }

.graticule {
  fill: none;
  stroke: var(--graticule);
  stroke-width: 0.7;
  vector-effect: non-scaling-stroke;
  pointer-events: none;
}

.country,
.territory {
  vector-effect: non-scaling-stroke;
  stroke-linejoin: round;
  transition: fill 160ms ease, opacity 160ms ease, stroke 160ms ease, filter 160ms ease;
}

.country {
  fill: var(--land);
  stroke: color-mix(in srgb, var(--ocean-1) 78%, var(--text));
  stroke-width: 0.8;
  cursor: pointer;
}
.country:hover { fill: var(--land-hover); stroke: color-mix(in srgb, var(--accent) 48%, var(--ocean-1)); }
.country:focus-visible { outline: none; fill: var(--land-hover); stroke: var(--accent); stroke-width: 2; }
.territory { fill: var(--territory); stroke: color-mix(in srgb, var(--ocean-1) 85%, var(--text)); stroke-width: .7; }

.country.is-dimmed,
.country-marker.is-dimmed { opacity: 0.14; }
.country.is-solved { fill: color-mix(in srgb, var(--green-strong) 74%, var(--land)); }
.country.is-correct { fill: var(--green); stroke: color-mix(in srgb, var(--green) 75%, white); stroke-width: 1.8; filter: url(#countryGlow); }
.country.is-wrong { fill: var(--red); stroke: var(--red); stroke-width: 1.8; animation: wrong-pulse 420ms ease; }
.country.is-target { fill: var(--gold); stroke: color-mix(in srgb, var(--gold) 80%, white); stroke-width: 2; filter: url(#countryGlow); animation: target-pulse 1s ease-in-out infinite; }
.country.is-neighbor { fill: color-mix(in srgb, var(--purple) 65%, var(--land)); }
.country.is-selected-study { fill: var(--accent); stroke: color-mix(in srgb, var(--accent) 80%, white); stroke-width: 2; filter: url(#countryGlow); }
.country.is-favorite-study { stroke: var(--gold); stroke-width: 1.7; }

.country-marker {
  cursor: pointer;
  transition: opacity 150ms ease;
}
.marker-hit { fill: transparent; pointer-events: all; }
.marker-dot {
  fill: var(--gold);
  stroke: color-mix(in srgb, var(--gold) 78%, white);
  stroke-width: 1.4;
  vector-effect: non-scaling-stroke;
  filter: drop-shadow(0 0 4px rgba(248, 214, 109, 0.45));
  pointer-events: none;
}
.marker-ring {
  fill: none;
  stroke: rgba(248, 214, 109, 0.26);
  stroke-width: 1.2;
  vector-effect: non-scaling-stroke;
  pointer-events: none;
}
.country-marker:hover .marker-dot { fill: #fff2b4; }
.country-marker.is-solved .marker-dot { fill: var(--green); stroke: var(--green); }
.country-marker.is-correct .marker-dot,
.country-marker.is-selected-study .marker-dot { fill: var(--accent); stroke: white; }
.country-marker.is-wrong .marker-dot { fill: var(--red); stroke: var(--red); }
.country-marker.is-target .marker-dot { fill: var(--gold); stroke: white; animation: marker-pulse 850ms ease-in-out infinite; }
.country-marker.is-target .marker-ring { stroke: var(--gold); animation: ring-pulse 850ms ease-out infinite; }
.country-marker.is-neighbor .marker-dot { fill: var(--purple); }

.map-tooltip {
  position: absolute;
  z-index: 20;
  max-width: 220px;
  pointer-events: none;
  transform: translate(12px, 12px);
  border: 1px solid var(--border-strong);
  border-radius: 10px;
  background: color-mix(in srgb, var(--surface-solid) 92%, transparent);
  color: var(--text);
  padding: 8px 10px;
  box-shadow: var(--shadow-soft);
  backdrop-filter: blur(12px);
  font-size: 0.73rem;
}

.map-callout {
  position: absolute;
  z-index: 15;
  left: 18px;
  top: 18px;
  display: flex;
  align-items: center;
  gap: 10px;
  max-width: 300px;
  border: 1px solid var(--border-strong);
  border-radius: 14px;
  background: color-mix(in srgb, var(--surface-solid) 88%, transparent);
  padding: 10px 12px;
  box-shadow: var(--shadow-soft);
  backdrop-filter: blur(14px);
  animation: slide-in 250ms ease both;
}
.map-callout > span { font-size: 1.8rem; }
.map-callout strong,
.map-callout small { display: block; }
.map-callout strong { font-size: 0.83rem; }
.map-callout small { margin-top: 2px; color: var(--muted); font-size: 0.67rem; }

.tiny-country-note {
  position: absolute;
  z-index: 11;
  left: 50%;
  bottom: 45px;
  transform: translateX(-50%);
  width: max-content;
  max-width: calc(100% - 32px);
  border: 1px solid rgba(248, 214, 109, 0.25);
  border-radius: 999px;
  background: color-mix(in srgb, var(--surface-solid) 87%, transparent);
  color: var(--text-soft);
  padding: 7px 11px;
  box-shadow: var(--shadow-soft);
  backdrop-filter: blur(12px);
  font-size: 0.67rem;
}
.tiny-country-note span { color: var(--gold); font-size: 1rem; vertical-align: -1px; }

.map-legend {
  position: absolute;
  z-index: 10;
  right: 15px;
  bottom: 13px;
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 10px;
  color: var(--muted);
  font-size: 0.62rem;
  pointer-events: none;
}
.map-legend span { display: flex; align-items: center; gap: 5px; }
.map-legend i { display: inline-block; width: 8px; height: 8px; border-radius: 3px; }
.legend-current { background: var(--gold); }
.legend-correct { background: var(--green); }
.legend-marker { border-radius: 50% !important; background: var(--gold); box-shadow: 0 0 0 2px rgba(248, 214, 109, 0.2); }

.map-footer { padding: 12px 18px 14px; border-top: 1px solid var(--border); }
.progress-track { height: 7px; overflow: hidden; border-radius: 999px; background: var(--surface-3); }
.progress-track span { display: block; width: 0; height: 100%; border-radius: inherit; background: linear-gradient(90deg, var(--accent-strong), var(--green)); transition: width 300ms ease; }
.footer-copy { margin-top: 8px; color: var(--muted); font-size: 0.68rem; }

.study-panel { position: relative; z-index: 1; }
.study-intro { margin-top: 30px; }
.filter-pills { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 14px; }
.filter-pills button {
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--surface-2);
  color: var(--muted);
  cursor: pointer;
  padding: 7px 10px;
  font-size: 0.68rem;
  font-weight: 750;
}
.filter-pills button:hover { color: var(--text); }
.filter-pills button.is-active { border-color: rgba(103, 232, 249, 0.4); background: rgba(103, 232, 249, 0.1); color: var(--accent); }

.study-country {
  min-height: 325px;
  margin-top: 18px;
  border: 1px solid var(--border);
  border-radius: 18px;
  background: var(--surface-2);
  padding: 17px;
}
.study-placeholder {
  display: grid;
  min-height: 290px;
  place-items: center;
  align-content: center;
  gap: 12px;
  color: var(--muted);
  text-align: center;
}
.study-placeholder span { font-size: 2.8rem; color: var(--accent); opacity: .75; }
.study-placeholder p { max-width: 220px; margin: 0; font-size: .82rem; line-height: 1.5; }
.study-country-head { justify-content: flex-start; }
.study-flag { font-size: 3.1rem; line-height: 1; }
.study-country-head .star-button { margin-left: auto; }
.star-button { width: 36px; height: 36px; border-radius: 11px; color: var(--gold); font-size: 1.3rem; }
.star-button.is-favorite { background: rgba(248,214,109,.12); }
.study-facts { margin-top: 16px; }
.mastery-block { margin-top: 17px; border-top: 1px solid var(--border); padding-top: 14px; }
.mastery-block > div:first-child { margin-bottom: 8px; color: var(--muted); font-size: .7rem; }
.mastery-block strong { color: var(--text-soft); }
.mastery-block p { margin: 8px 0 0; color: var(--muted); font-size: .7rem; line-height: 1.45; }
.study-actions { display: flex; gap: 8px; margin-top: 15px; }
.study-actions > * { flex: 1; }

.modal {
  width: min(980px, calc(100% - 28px));
  max-height: calc(100vh - 32px);
  overflow: auto;
  border: 1px solid var(--border-strong);
  border-radius: 25px;
  background: color-mix(in srgb, var(--surface-solid) 96%, transparent);
  color: var(--text);
  padding: clamp(20px, 3vw, 34px);
  box-shadow: 0 30px 100px rgba(0,0,0,.48);
  backdrop-filter: blur(26px) saturate(140%);
}
.modal::backdrop { background: rgba(2, 7, 13, 0.72); backdrop-filter: blur(9px); }
.modal[open] { animation: modal-in 220ms ease both; }
.modal-head { align-items: flex-start; }
.modal-head h2 { margin: 0; font-size: clamp(1.55rem, 3vw, 2.4rem); letter-spacing: -.045em; line-height: 1.05; }
.modal-head p:last-child { max-width: 680px; margin: 10px 0 0; color: var(--text-soft); font-size: .86rem; line-height: 1.55; }
.modal-close { flex: 0 0 auto; width: 38px; height: 38px; border-radius: 12px; color: var(--muted); font-size: 1.5rem; }

.setup-modal { width: min(1120px, calc(100% - 28px)); }
.setup-modal fieldset { min-width: 0; margin: 25px 0 0; border: 0; padding: 0; }
.setup-modal legend { margin-bottom: 10px; color: var(--text-soft); font-size: .75rem; font-weight: 850; letter-spacing: .05em; text-transform: uppercase; }
.mode-grid { display: grid; grid-template-columns: repeat(6, minmax(0, 1fr)); gap: 9px; }
.mode-card { position: relative; display: grid; min-height: 145px; align-content: start; border: 1px solid var(--border); border-radius: 16px; background: var(--surface-2); cursor: pointer; padding: 15px; transition: 160ms ease; }
.mode-card:hover { transform: translateY(-2px); border-color: var(--border-strong); }
.mode-card input { position: absolute; opacity: 0; pointer-events: none; }
.mode-card:has(input:checked) { border-color: rgba(103,232,249,.55); background: linear-gradient(145deg, rgba(103,232,249,.12), var(--surface-2)); box-shadow: inset 0 0 0 1px rgba(103,232,249,.12); }
.mode-card:has(input:checked)::after { position: absolute; top: 10px; right: 10px; display: grid; width: 20px; height: 20px; place-items: center; border-radius: 50%; background: var(--accent); color: var(--accent-ink); content: "✓"; font-size: .7rem; font-weight: 900; }
.mode-symbol { display: grid; width: 42px; height: 42px; place-items: center; margin-bottom: 14px; border: 1px solid var(--border); border-radius: 12px; background: var(--surface-solid); color: var(--accent); font-size: 1.15rem; font-weight: 900; }
.mode-card strong { font-size: .91rem; }
.mode-card small { margin-top: 6px; color: var(--muted); font-size: .7rem; line-height: 1.42; }
.featured-mode .mode-symbol { color: var(--gold); }

.setup-columns { display: grid; grid-template-columns: 1.4fr 1fr; gap: 18px; }
.setup-columns.three { grid-template-columns: 1fr 1.3fr 1fr; }
.segmented { display: flex; padding: 4px; border: 1px solid var(--border); border-radius: 13px; background: var(--surface-2); }
.segmented.wrap { flex-wrap: wrap; gap: 3px; }
.segmented label { flex: 1; min-width: max-content; cursor: pointer; }
.segmented input { position: absolute; opacity: 0; pointer-events: none; }
.segmented span { display: grid; min-height: 36px; place-items: center; border-radius: 9px; color: var(--muted); padding: 7px 10px; font-size: .7rem; font-weight: 800; text-align: center; transition: 150ms ease; }
.segmented input:checked + span { background: var(--surface-solid); color: var(--text); box-shadow: var(--shadow-soft); }
.segmented.stacked { display: grid; gap: 4px; }
.segmented.stacked label { min-width: 0; }
.segmented.stacked span { display: block; min-height: 0; padding: 9px 11px; text-align: left; }
.segmented.stacked strong,
.segmented.stacked small { display: block; }
.segmented.stacked strong { font-size: .76rem; }
.segmented.stacked small { margin-top: 2px; color: var(--muted); font-size: .64rem; font-weight: 500; }
.set-note { display: grid; min-height: 45px; align-content: center; border: 1px solid var(--border); border-radius: 13px; background: var(--surface-2); padding: 9px 12px; }
.set-note strong { color: var(--gold); font-size: .76rem; }
.set-note small { margin-top: 2px; color: var(--muted); font-size: .63rem; line-height: 1.35; }
.setup-footer { margin-top: 28px; padding-top: 20px; border-top: 1px solid var(--border); }
.results-modal { width: min(760px, calc(100% - 28px)); position: relative; overflow: hidden; }
.results-burst { position: absolute; right: -45px; top: -70px; color: var(--gold); font-size: 12rem; opacity: .055; transform: rotate(18deg); pointer-events: none; }
.results-grid,
.stats-overview { display: grid; grid-template-columns: repeat(4, 1fr); gap: 9px; margin-top: 25px; }
.results-grid > div,
.stats-overview > div { border: 1px solid var(--border); border-radius: 14px; background: var(--surface-2); padding: 13px; }
.results-grid span,
.results-grid strong,
.stats-overview span,
.stats-overview strong { display: block; }
.results-grid span,
.stats-overview span { color: var(--muted); font-size: .66rem; }
.results-grid strong,
.stats-overview strong { margin-top: 6px; font-size: 1.2rem; }
.rank-card { margin-top: 15px; border: 1px solid rgba(103,232,249,.24); border-radius: 15px; background: rgba(103,232,249,.07); padding: 14px; }
.rank-card span { color: var(--muted); font-size: .67rem; }
.rank-card strong { color: var(--accent); font-size: .93rem; }
.rank-card p { margin: 7px 0 0; color: var(--text-soft); font-size: .77rem; line-height: 1.45; }
.missed-section { margin-top: 20px; }
.missed-section h3 { margin: 0; font-size: .88rem; }
.missed-section > div:first-child span { color: var(--muted); font-size: .7rem; }
.chip-list { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 10px; }
.chip-list button,
.chip-list span { border: 1px solid var(--border); border-radius: 999px; background: var(--surface-2); color: var(--text-soft); padding: 6px 9px; font-size: .68rem; }
.chip-list button { cursor: pointer; }
.results-actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 24px; }

.stats-modal { width: min(1000px, calc(100% - 28px)); }
.stats-overview { grid-template-columns: repeat(6, 1fr); }
.stats-overview strong { font-size: 1.05rem; }
.mastery-overview { margin-top: 15px; border: 1px solid var(--border); border-radius: 15px; background: var(--surface-2); padding: 14px; }
.mastery-overview h3 { margin: 0; font-size: .82rem; }
.mastery-overview > div:first-child strong { color: var(--accent); }
.mastery-overview p { margin: 9px 0 0; color: var(--muted); font-size: .7rem; }
.stats-columns { display: grid; grid-template-columns: 1.1fr 1fr; gap: 22px; margin-top: 24px; }
.section-head h3 { margin: 0; font-size: .9rem; }
.section-head > span { color: var(--muted); font-size: .7rem; }
.weak-list { display: grid; gap: 7px; margin-top: 10px; }
.weak-item { display: grid; grid-template-columns: auto minmax(0,1fr) auto; align-items: center; gap: 9px; border: 1px solid var(--border); border-radius: 12px; background: var(--surface-2); padding: 9px; }
.weak-item .flag { font-size: 1.35rem; }
.weak-item strong,
.weak-item small { display: block; }
.weak-item strong { font-size: .74rem; }
.weak-item small { margin-top: 2px; color: var(--muted); font-size: .63rem; }
.weak-item button { border: 0; background: transparent; color: var(--accent); cursor: pointer; font-size: .68rem; font-weight: 800; }
.empty-state { border: 1px dashed var(--border-strong); border-radius: 13px; color: var(--muted); padding: 18px; text-align: center; font-size: .74rem; line-height: 1.45; }
.achievement-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-top: 10px; }
.achievement { display: grid; grid-template-columns: auto 1fr; gap: 9px; border: 1px solid var(--border); border-radius: 12px; background: var(--surface-2); padding: 10px; opacity: .46; }
.achievement.is-unlocked { border-color: rgba(248,214,109,.26); background: rgba(248,214,109,.07); opacity: 1; }
.achievement-icon { display: grid; width: 31px; height: 31px; place-items: center; border-radius: 9px; background: var(--surface-solid); color: var(--gold); }
.achievement strong,
.achievement small { display: block; }
.achievement strong { font-size: .7rem; }
.achievement small { margin-top: 3px; color: var(--muted); font-size: .61rem; line-height: 1.35; }
.data-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 24px; padding-top: 18px; border-top: 1px solid var(--border); }

.help-modal { width: min(600px, calc(100% - 28px)); }
.shortcut-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 9px; margin-top: 23px; }
.shortcut-grid > div { display: grid; grid-template-columns: 42px 1fr; align-items: center; gap: 9px; border: 1px solid var(--border); border-radius: 12px; background: var(--surface-2); padding: 9px; }
kbd { display: grid; min-width: 32px; height: 30px; place-items: center; border: 1px solid var(--border-strong); border-bottom-width: 3px; border-radius: 8px; background: var(--surface-solid); color: var(--text); font-family: inherit; font-size: .72rem; font-weight: 850; }
.shortcut-grid span { color: var(--text-soft); font-size: .73rem; }
.help-note { margin: 16px 0 0; color: var(--muted); font-size: .72rem; line-height: 1.5; }

.toast-region { position: fixed; z-index: 200; right: 20px; bottom: 20px; display: grid; gap: 8px; width: min(360px, calc(100% - 40px)); pointer-events: none; }
.toast { border: 1px solid var(--border-strong); border-radius: 13px; background: color-mix(in srgb, var(--surface-solid) 94%, transparent); color: var(--text-soft); padding: 11px 13px; box-shadow: var(--shadow); backdrop-filter: blur(18px); font-size: .75rem; line-height: 1.4; animation: toast-in 250ms ease both; }
.toast.is-achievement { border-color: rgba(248,214,109,.35); color: var(--gold); }
.toast.is-error { border-color: rgba(255,122,138,.35); color: var(--red); }
.toast.is-leaving { animation: toast-out 220ms ease both; }

#confettiCanvas { position: fixed; z-index: 190; inset: 0; width: 100%; height: 100%; pointer-events: none; }

body.is-study .map-legend .legend-current { background: var(--accent); }
body.is-study .map-legend span:first-child::after { content: ""; }
body.is-study .mission-panel { min-height: 760px; }
body.has-active-game .map-status-dot { background: var(--green); }

@keyframes modal-in { from { opacity: 0; transform: translateY(10px) scale(.985); } to { opacity: 1; transform: none; } }
@keyframes flag-in { from { opacity: 0; transform: translateY(7px) scale(.92); } to { opacity: 1; transform: none; } }
@keyframes card-in { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }
@keyframes slide-in { from { opacity: 0; transform: translateY(-4px); } to { opacity: 1; transform: none; } }
@keyframes wrong-pulse { 0%,100% { filter: none; } 50% { filter: brightness(1.3); } }
@keyframes target-pulse { 0%,100% { filter: url(#countryGlow); opacity: 1; } 50% { filter: url(#countryGlow); opacity: .72; } }
@keyframes marker-pulse { 0%,100% { opacity: 1; } 50% { opacity: .45; } }
@keyframes ring-pulse { 0% { opacity: 1; transform: scale(.8); transform-origin: center; } 100% { opacity: 0; transform: scale(1.8); transform-origin: center; } }
@keyframes toast-in { from { opacity: 0; transform: translateX(15px); } to { opacity: 1; transform: none; } }
@keyframes toast-out { to { opacity: 0; transform: translateX(15px); } }

@media (max-width: 1180px) {
  /* A backdrop-filter creates a containing block for fixed descendants in
     Chromium. Disable it here so the mobile nav actually anchors to the viewport. */
  .topbar { grid-template-columns: 1fr auto; backdrop-filter: none; background: color-mix(in srgb, var(--bg) 94%, transparent); }
  .primary-nav { position: fixed; z-index: 60; left: 50%; bottom: max(10px, env(safe-area-inset-bottom)); transform: translateX(-50%); box-shadow: var(--shadow); }
  .game-layout { grid-template-columns: minmax(280px, 340px) minmax(0, 1fr); }
  .score-grid { grid-template-columns: 1fr 1fr; }
  .mode-grid { grid-template-columns: repeat(3, 1fr); }
  .stats-overview { grid-template-columns: repeat(3, 1fr); }
  body { padding-bottom: 72px; }
}

@media (max-width: 900px) {
  .topbar { padding-inline: 14px; }
  .brand small { display: none; }
  .run-pill { display: none !important; }
  .game-layout { grid-template-columns: 1fr; }
  .mission-panel { min-height: auto; }
  .map-card { min-height: 640px; }
  .map-stage, #worldMap { min-height: 520px; }
  .mission-copy { margin-top: 26px; }
  .mission-copy h1, .study-intro h1 { font-size: clamp(1.65rem, 6vw, 2.3rem); }
  .country-card { display: grid; grid-template-columns: 1fr; }
  .setup-columns, .setup-columns.three { grid-template-columns: 1fr; gap: 0; }
  .stats-columns { grid-template-columns: 1fr; }
  .setup-footer { align-items: stretch; flex-direction: column; }
  .setup-footer .primary-button { width: 100%; }
}

@media (max-width: 640px) {
  :root { --topbar-height: 64px; }
  .topbar { min-height: 64px; }
  .brand-mark { width: 36px; height: 36px; border-radius: 11px; }
  .brand-mark svg { width: 25px; }
  .brand strong { font-size: .91rem; }
  .top-actions { gap: 4px; }
  .icon-button { width: 35px; height: 35px; border-radius: 10px; }
  .desktop-only { display: none !important; }
  .app-shell { padding: 10px 8px 28px; }
  .game-layout { gap: 10px; }
  .mission-panel, .map-card { border-radius: 20px; }
  .mission-panel { padding: 18px; }
  .map-card { min-height: 420px; }
  .map-stage, #worldMap { min-height: 300px; }
  .map-toolbar { padding: 12px; }
  .map-toolbar small { display: none; }
  .map-footer { padding: 10px 12px 12px; }
  .map-legend { display: none; }
  .map-callout { left: 10px; top: 10px; max-width: calc(100% - 20px); }
  .score-grid { grid-template-columns: repeat(4, 1fr); }
  .score-grid > div { padding: 8px 4px; }
  .score-grid span { font-size: .55rem; }
  .score-grid strong { font-size: .78rem; }
  .mission-copy { margin-top: 24px; }
  .mission-copy > p:last-child { font-size: .85rem; }
  .mission-actions { align-items: stretch; }
  .country-facts, .study-facts { gap: 8px; }
  .study-actions { flex-direction: column; }
  .modal { width: calc(100% - 16px); max-height: calc(100vh - 16px); border-radius: 20px; padding: 18px; }
  .modal-head h2 { font-size: 1.6rem; }
  .modal-head p:last-child { font-size: .78rem; }
  .mode-grid { grid-template-columns: 1fr 1fr; }
  .mode-card { min-height: 126px; padding: 12px; }
  .mode-symbol { width: 36px; height: 36px; margin-bottom: 10px; }
  .featured-mode { grid-column: 1 / -1; min-height: 108px; }
  .segmented.wrap label { min-width: 30%; }
  .results-grid, .stats-overview { grid-template-columns: 1fr 1fr; }
  .results-actions > * { flex: 1 1 45%; }
  .achievement-grid { grid-template-columns: 1fr; }
  .shortcut-grid { grid-template-columns: 1fr; }
  .data-actions { flex-direction: column; }
  .data-actions > * { width: 100%; }
  .primary-nav { width: calc(100% - 28px); justify-content: center; }
  .nav-button { flex: 1; min-width: 0; }
}

@media (max-width: 420px) {
  .brand > span:last-child { display: none; }
  .mode-card { min-height: 132px; }
  .featured-mode { min-height: 108px; }
  .score-grid { grid-template-columns: 1fr 1fr; }
  .country-facts, .study-facts { grid-template-columns: 1fr; }
  .map-tools { gap: 3px; }
  .map-tool { width: 31px; height: 31px; }
  .input-row { flex-direction: column; }
  .keyboard-answer .input-row { flex-direction: row; }
}

@media (max-width: 350px) {
  .mode-grid { grid-template-columns: 1fr; }
  .featured-mode { grid-column: auto; }
}

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

/* --------------------------------------------------------------------------
   Classic layout, speed sprints, flags, accounts, and phone play
   -------------------------------------------------------------------------- */

:root {
  --flag-sprite-url: url("assets/flag-sprite.webp");
}

.account-button {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  min-height: 38px;
  max-width: 150px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--surface-2);
  color: var(--text-soft);
  cursor: pointer;
  padding: 7px 10px;
  font-size: .72rem;
  font-weight: 800;
}
.account-button:hover { border-color: var(--border-strong); background: var(--surface-3); }
.account-button.is-signed-in { border-color: rgba(100,230,164,.32); color: var(--green); }
.account-button svg { flex: 0 0 auto; width: 17px; height: 17px; fill: none; stroke: currentColor; stroke-width: 1.8; }
.account-button span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.mission-top-actions { display: flex; align-items: center; gap: 9px; }
.panel-toggle {
  display: grid;
  width: 31px;
  height: 31px;
  place-items: center;
  border: 1px solid var(--border);
  border-radius: 9px;
  background: var(--surface-2);
  color: var(--text-soft);
  cursor: pointer;
  font-size: 1.15rem;
  line-height: 1;
}
.panel-toggle:hover { border-color: var(--border-strong); background: var(--surface-3); color: var(--text); }

.flag-art {
  display: inline-block;
  flex: 0 0 auto;
  width: 48px;
  aspect-ratio: 4 / 3;
  overflow: hidden;
  border: 1px solid rgba(255,255,255,.18);
  border-radius: 5px;
  background-color: rgba(255,255,255,.06);
  background-image: var(--flag-sprite-url);
  background-repeat: no-repeat;
  background-size: 1400% 1500%;
  box-shadow: 0 5px 14px rgba(0,0,0,.2);
  vertical-align: middle;
}
.flag-art-inline { width: 22px; border-radius: 3px; box-shadow: none; }
.flag-prompt {
  width: auto;
  min-height: 0;
  margin: 4px 0 17px;
  filter: none;
}
.flag-prompt .flag-art {
  width: clamp(116px, 12vw, 178px);
  border-radius: 9px;
  box-shadow: 0 14px 30px rgba(0,0,0,.26);
}
.country-flag .flag-art { width: 52px; border-radius: 6px; }
.study-flag .flag-art { width: 68px; border-radius: 7px; }
.map-callout .flag-art { width: 38px; border-radius: 4px; }
.weak-item .flag-art { width: 34px; }

.sprint-badge {
  display: flex;
  align-items: center;
  gap: 9px;
  margin-top: 12px;
  border: 1px solid rgba(248,214,109,.27);
  border-radius: 12px;
  background: rgba(248,214,109,.075);
  color: var(--gold);
  padding: 8px 10px;
}
.sprint-badge > span { font-size: 1.05rem; }
.sprint-badge p,
.sprint-badge strong,
.sprint-badge small { display: block; margin: 0; }
.sprint-badge strong { font-size: .7rem; letter-spacing: .04em; text-transform: uppercase; }
.sprint-badge small { margin-top: 2px; color: var(--muted); font-size: .61rem; }

.spell-form { margin-top: 18px; }
.spell-form > label { display: block; margin-bottom: 8px; color: var(--text-soft); font-size: .76rem; font-weight: 750; }
.spell-progress-row { display: flex; justify-content: space-between; gap: 10px; margin: 11px 1px 7px; color: var(--muted); font-size: .68rem; }
.spell-progress-row strong { color: var(--accent); }
.spell-recent { display: flex; flex-wrap: wrap; gap: 5px; min-height: 28px; max-height: 78px; margin-top: 11px; overflow: hidden; }
.spell-recent span { display: inline-flex; align-items: center; gap: 5px; border: 1px solid var(--border); border-radius: 999px; background: var(--surface-2); color: var(--text-soft); padding: 4px 7px 4px 5px; font-size: .62rem; }

.sprint-choice {
  display: grid;
  grid-template-columns: auto auto minmax(0,1fr);
  align-items: center;
  gap: 10px;
  flex: 1;
  min-width: min(100%, 430px);
  border: 1px solid rgba(248,214,109,.25);
  border-radius: 14px;
  background: rgba(248,214,109,.065);
  cursor: pointer;
  padding: 11px 13px;
}
.sprint-choice input { width: 17px; height: 17px; accent-color: var(--gold); }
.sprint-choice-mark { color: var(--gold); }
.sprint-choice strong,
.sprint-choice small { display: block; }
.sprint-choice strong { color: var(--gold); font-size: .76rem; }
.sprint-choice small { margin-top: 3px; color: var(--muted); font-size: .64rem; line-height: 1.35; }
.setup-lock-note { margin: 14px 0 0; border-left: 3px solid var(--gold); border-radius: 0 9px 9px 0; background: rgba(248,214,109,.07); color: var(--text-soft); padding: 9px 11px; font-size: .7rem; line-height: 1.45; }
.setup-modal.has-locked-rules .setup-columns { opacity: .52; }
.spelling-mode { border-color: rgba(180,160,255,.24); }

.sprint-result-card { margin-top: 15px; border: 1px solid rgba(248,214,109,.26); border-radius: 16px; background: rgba(248,214,109,.07); padding: 14px; }
.sprint-result-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.sprint-result-head span,
.sprint-result-stats span { display: block; color: var(--muted); font-size: .64rem; }
.sprint-result-head strong { display: block; margin-top: 3px; color: var(--gold); font-size: 1.55rem; }
.sprint-result-mode { border: 1px solid rgba(248,214,109,.28); border-radius: 999px; color: var(--gold) !important; padding: 5px 8px; font-weight: 800; }
.sprint-result-stats { display: grid; grid-template-columns: repeat(3,1fr); gap: 7px; margin-top: 12px; }
.sprint-result-stats > div { border: 1px solid var(--border); border-radius: 10px; background: var(--surface-2); padding: 8px; }
.sprint-result-stats strong { display: block; margin-top: 4px; font-size: .82rem; }
.submission-status { min-height: 1.2em; margin: 11px 0 0; color: var(--muted); font-size: .68rem; line-height: 1.4; }
.submission-status.is-success { color: var(--green); }
.submission-status.is-error { color: var(--red); }

.leaderboard-modal { width: min(1040px, calc(100% - 28px)); }
.leaderboard-mode-tabs,
.account-tabs { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 20px; }
.leaderboard-mode-tabs button,
.account-tabs button { border: 1px solid var(--border); border-radius: 10px; background: var(--surface-2); color: var(--muted); cursor: pointer; padding: 8px 11px; font-size: .7rem; font-weight: 800; }
.leaderboard-mode-tabs button:hover,
.account-tabs button:hover { border-color: var(--border-strong); color: var(--text); }
.leaderboard-mode-tabs button.is-active,
.account-tabs button.is-active { border-color: rgba(103,232,249,.35); background: rgba(103,232,249,.1); color: var(--accent); }
.leaderboard-controls { display: grid; grid-template-columns: minmax(180px,1fr) auto auto auto; align-items: end; gap: 8px; margin-top: 14px; }
.leaderboard-controls label > span { display: block; margin: 0 0 6px 2px; color: var(--muted); font-size: .64rem; font-weight: 750; }
.leaderboard-controls input,
.account-modal input[type="email"],
.account-modal input[type="password"],
.account-modal input[type="text"] { width: 100%; border: 1px solid var(--border); border-radius: 11px; background: var(--surface-2); color: var(--text); padding: 10px 12px; }
.leaderboard-status { min-height: 1.2em; margin: 13px 2px 8px; color: var(--muted); font-size: .68rem; }
.leaderboard-table-wrap { max-height: min(48vh, 460px); overflow: auto; border: 1px solid var(--border); border-radius: 14px; background: color-mix(in srgb, var(--surface-2) 70%, transparent); }
.leaderboard-table { width: 100%; border-collapse: collapse; min-width: 660px; }
.leaderboard-table th { position: sticky; z-index: 1; top: 0; background: var(--surface-solid); color: var(--muted); text-align: left; font-size: .62rem; letter-spacing: .04em; text-transform: uppercase; }
.leaderboard-table th,
.leaderboard-table td { padding: 10px 12px; border-bottom: 1px solid var(--border); }
.leaderboard-table td { color: var(--text-soft); font-size: .72rem; }
.leaderboard-table td strong { color: var(--text); }
.leaderboard-table td small { display: inline-block; margin-left: 6px; border-radius: 999px; background: rgba(103,232,249,.12); color: var(--accent); padding: 2px 5px; font-size: .53rem; font-weight: 850; text-transform: uppercase; }
.leaderboard-table tr.is-player { background: rgba(103,232,249,.065); }
.leaderboard-table tbody tr:last-child td { border-bottom: 0; }
.empty-board { display: grid; gap: 4px; place-items: center; padding: 28px 14px; text-align: center; }
.empty-board span { color: var(--muted); }
.leaderboard-foot { display: flex; justify-content: space-between; gap: 12px; margin-top: 9px; color: var(--muted); font-size: .62rem; }

.account-modal { width: min(560px, calc(100% - 28px)); }
.account-form { display: grid; gap: 8px; margin-top: 16px; }
.account-form label,
.account-member > label { color: var(--text-soft); font-size: .7rem; font-weight: 750; }
.account-form .primary-button { margin-top: 4px; }
.account-reset-link { justify-self: start; }
.account-fine-print { margin: 3px 0 0; color: var(--muted); font-size: .65rem; }
.account-identity { display: flex; align-items: center; gap: 10px; margin: 20px 0 16px; border: 1px solid var(--border); border-radius: 13px; background: var(--surface-2); padding: 11px; }
.account-identity > span { display: grid; width: 34px; height: 34px; place-items: center; border-radius: 10px; background: rgba(103,232,249,.1); color: var(--accent); }
.account-identity small,
.account-identity strong { display: block; }
.account-identity small { color: var(--muted); font-size: .61rem; }
.account-identity strong { margin-top: 2px; font-size: .76rem; }
.account-sync-card { margin-top: 14px; border: 1px solid var(--border); border-radius: 13px; background: var(--surface-2); padding: 11px; }
.account-sync-card > div { display: flex; align-items: center; gap: 7px; }
.account-sync-card strong { font-size: .72rem; }
.account-sync-card p { margin: 6px 0 0; color: var(--muted); font-size: .66rem; line-height: 1.4; }
.account-sync-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--muted); }
.account-sync-dot.is-syncing { background: var(--gold); box-shadow: 0 0 0 4px rgba(248,214,109,.12); }
.account-sync-dot.is-synced { background: var(--green); box-shadow: 0 0 0 4px rgba(100,230,164,.12); }
.account-sync-dot.is-error { background: var(--red); box-shadow: 0 0 0 4px rgba(255,122,138,.12); }
.account-member-actions { display: flex; justify-content: space-between; gap: 8px; margin-top: 16px; }
.account-status { min-height: 1.2em; margin: 12px 0 0; color: var(--muted); font-size: .68rem; }
.account-status.is-error { color: var(--red); }
.account-status.is-success { color: var(--green); }

/* The game itself is a single fixed canvas: controls on the left, map on the right. */
body.has-active-game {
  height: 100dvh;
  min-height: 0;
  overflow: hidden;
  padding-bottom: 0;
}
body.has-active-game .topbar {
  height: var(--topbar-height);
  min-height: var(--topbar-height);
}
body.has-active-game .app-shell {
  height: calc(100dvh - var(--topbar-height));
  max-height: calc(100dvh - var(--topbar-height));
  padding: 12px clamp(10px, 1.6vw, 24px);
}
body.has-active-game .game-layout {
  height: 100%;
  min-height: 0;
  gap: clamp(10px, 1.2vw, 18px);
}
body.has-active-game .mission-panel,
body.has-active-game .map-card {
  height: 100%;
  min-height: 0;
}
body.has-active-game .mission-panel {
  padding: clamp(15px, 1.5vw, 22px);
}
body.has-active-game #gamePanel {
  display: flex;
  flex-direction: column;
  height: 100%;
  min-height: 0;
  overflow: hidden;
}
body.has-active-game .map-stage,
body.has-active-game #worldMap {
  min-height: 0;
}
body.has-active-game .mission-copy { margin-top: clamp(16px, 3.5vh, 34px); }
body.has-active-game .mission-copy > p:last-child { margin-top: 10px; line-height: 1.42; }
body.has-active-game .country-card { margin-top: 13px; }
body.has-active-game #worldMap { cursor: crosshair; }
body.has-active-game #worldMap.is-dragging { cursor: grabbing; }
body.has-spelling-game #worldMap { cursor: default; }

/* Never expose a country name through pointer hover during a live game. */
body.has-active-game .country:hover { fill: var(--land-hover); }
@media (hover: none), (pointer: coarse) {
  .country:hover { fill: var(--land); stroke: color-mix(in srgb, var(--ocean-1) 78%, var(--text)); }
  .country.is-solved:hover { fill: color-mix(in srgb, var(--green-strong) 74%, var(--land)); }
}

@media (max-height: 790px) and (min-width: 861px) {
  :root { --topbar-height: 64px; }
  body.has-active-game .score-grid { margin-top: 10px; }
  body.has-active-game .score-grid > div { padding: 7px 5px; }
  body.has-active-game .mission-copy { margin-top: 15px; }
  body.has-active-game .mission-copy h1 { font-size: clamp(1.42rem, 2.1vw, 2rem); }
  body.has-active-game .mission-copy > p:last-child { display: -webkit-box; overflow: hidden; -webkit-box-orient: vertical; -webkit-line-clamp: 2; font-size: .79rem; }
  body.has-active-game .flag-prompt { margin-bottom: 10px; }
  body.has-active-game .flag-prompt .flag-art { width: 108px; }
  body.has-active-game .keyboard-answer { margin-top: 8px; padding: 7px 0; }
  body.has-active-game .mission-actions { margin-top: 10px; }
  body.has-active-game .feedback { min-height: 42px; margin-top: 9px; padding: 9px; }
  body.has-active-game .accuracy-row { margin-top: 9px; }
  body.has-active-game .country-card { margin-top: 9px; padding: 10px; }
  body.has-active-game .country-facts { grid-template-columns: repeat(4, minmax(0,1fr)); gap: 6px; margin-top: 9px; }
  body.has-active-game .country-facts dd { font-size: .66rem; }
  body.has-active-game .capital-note { display: none; }
}

@media (max-height: 660px) and (min-width: 861px) {
  body.has-active-game .country-card { display: none !important; }
  body.has-active-game .keyboard-answer { display: none; }
  body.has-active-game .sprint-badge { margin-top: 7px; padding: 6px 8px; }
  body.has-active-game .map-toolbar { padding-block: 9px; }
  body.has-active-game .map-footer { padding-block: 7px; }
}

/* Phone portrait: the left control panel becomes a collapsible drawer over a full map. */
@media (max-width: 860px) {
  body.has-active-game .primary-nav { display: none; }
  body.has-active-game .topbar {
    grid-template-columns: minmax(0,1fr) auto;
    padding-inline: 10px;
  }
  body.has-active-game .top-actions { gap: 4px; }
  body.has-active-game .run-pill,
  body.has-active-game .account-button { display: none !important; }
  body.has-active-game .app-shell { padding: 8px; }
  body.has-active-game .game-layout { position: relative; display: block; }
  body.has-active-game .map-card { position: absolute; z-index: 1; inset: 0; width: 100%; }
  body.has-active-game .mission-panel {
    position: absolute;
    z-index: 20;
    top: 0;
    bottom: 0;
    left: 0;
    width: min(356px, calc(100vw - 58px));
    padding: 15px;
    transform: translateX(0);
    transition: transform 220ms ease;
    box-shadow: 18px 0 48px rgba(0,0,0,.34);
  }
  body.has-active-game .mission-panel.is-collapsed {
    overflow: visible;
    transform: translateX(calc(-100% - 14px));
    box-shadow: none;
    pointer-events: none;
  }
  body.has-active-game .mission-panel.is-collapsed .mission-topline { justify-content: flex-end; }
  body.has-active-game .mission-panel.is-collapsed .mission-topline > .eyebrow-chip,
  body.has-active-game .mission-panel.is-collapsed .mission-top-actions > .text-button { visibility: hidden; opacity: 0; pointer-events: none; }
  body.has-active-game .mission-panel.is-collapsed #gamePanel > :not(.mission-topline) { visibility: hidden; }
  body.has-active-game .mission-panel.is-collapsed .panel-toggle {
    position: absolute;
    z-index: 2;
    top: 14px;
    right: -64px;
    width: 42px;
    height: 42px;
    border-radius: 12px;
    background: color-mix(in srgb, var(--surface-solid) 94%, transparent);
    box-shadow: var(--shadow-soft);
    pointer-events: auto;
    transform: none;
  }
  body.has-active-game .map-stage,
  body.has-active-game #worldMap { min-height: 0; }
  body.has-active-game .map-toolbar { padding: 11px 12px 9px; }
  body.has-active-game .mission-panel.is-collapsed ~ .map-card .map-toolbar > div:first-child {
    min-width: 0;
    padding-left: 48px;
  }
  body.has-active-game .mission-panel.is-collapsed ~ .map-card .map-toolbar strong {
    max-width: min(44vw, 190px);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }
  body.has-active-game .map-footer { padding: 8px 11px 10px; }
  body.has-active-game .map-legend { right: 10px; bottom: 10px; }
  body.has-active-game .map-callout { right: 10px; left: auto; }
  .leaderboard-controls { grid-template-columns: 1fr 1fr; }
  .leaderboard-controls label { grid-column: 1 / -1; }
  .leaderboard-foot { flex-direction: column; }
}

@media (max-width: 640px) {
  .account-button span { display: none; }
  .account-button { width: 35px; padding: 0; justify-content: center; }
  .leaderboard-modal,
  .account-modal { width: calc(100% - 16px); }
  .leaderboard-mode-tabs { display: grid; grid-template-columns: repeat(3,1fr); }
  .leaderboard-mode-tabs button { min-width: 0; padding-inline: 6px; }
  .leaderboard-controls { grid-template-columns: 1fr 1fr; }
  .leaderboard-controls .compact { white-space: normal; }
  .sprint-choice { grid-template-columns: auto auto 1fr; }
  .setup-footer { gap: 10px; }
  .setup-footer .sprint-choice { width: 100%; }
  .sprint-result-stats { grid-template-columns: 1fr 1fr 1fr; }
  body.has-active-game .brand > span:last-child { display: block; }
  body.has-active-game .brand small { display: none; }
  body.has-active-game .brand strong { font-size: .82rem; }
  body.has-active-game .brand-mark { width: 34px; height: 34px; }
  body.has-active-game .icon-button { width: 34px; height: 34px; }
  body.has-active-game .mission-copy h1 { font-size: clamp(1.48rem, 7vw, 2rem); }
  body.has-active-game .mission-copy > p:last-child { font-size: .78rem; }
  body.has-active-game .score-grid { margin-top: 11px; }
  body.has-active-game .score-grid > div { padding: 7px 4px; }
  body.has-active-game .sprint-badge { margin-top: 8px; }
  body.has-active-game .map-toolbar small { display: block; max-width: 52vw; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  body.has-active-game .map-legend { display: flex; }
  body.has-active-game .map-legend span { font-size: .56rem; }
  body.has-active-game .map-legend i { width: 7px; height: 7px; }
}

@media (max-width: 430px) {
  body.has-active-game .top-actions #themeToggle,
  body.has-active-game .top-actions #helpButton { display: none; }
  body.has-active-game .mission-panel { width: min(342px, calc(100vw - 48px)); }
  body.has-active-game .mission-copy { margin-top: 17px; }
  body.has-active-game .keyboard-answer { display: none; }
  body.has-active-game .country-card { display: none !important; }
  body.has-active-game .feedback { margin-top: 10px; }
  body.has-active-game .accuracy-row { margin-top: 10px; }
  body.has-active-game .spell-recent { max-height: 55px; }
  .leaderboard-mode-tabs { grid-template-columns: 1fr 1fr; }
  .leaderboard-controls { grid-template-columns: 1fr; }
  .leaderboard-controls label { grid-column: auto; }
  .sprint-result-stats { grid-template-columns: 1fr; }
}

@media (max-height: 700px) and (max-width: 860px) {
  :root { --topbar-height: 58px; }
  body.has-active-game .topbar { padding-block: 5px; }
  body.has-active-game .mission-panel { padding: 12px; }
  body.has-active-game .score-grid { margin-top: 8px; }
  body.has-active-game .mission-copy { margin-top: 11px; }
  body.has-active-game .mission-copy h1 { font-size: 1.38rem; }
  body.has-active-game .mission-copy > p:last-child { display: -webkit-box; margin-top: 7px; overflow: hidden; -webkit-box-orient: vertical; -webkit-line-clamp: 2; }
  body.has-active-game .flag-prompt { margin-bottom: 8px; }
  body.has-active-game .flag-prompt .flag-art { width: 96px; }
  body.has-active-game .keyboard-answer,
  body.has-active-game .country-card { display: none !important; }
  body.has-active-game .mission-actions { margin-top: 8px; }
  body.has-active-game .feedback { min-height: 39px; margin-top: 8px; padding: 8px; }
  body.has-active-game .accuracy-row { margin-top: 8px; }
  body.has-active-game .sprint-badge { margin-top: 6px; padding: 5px 7px; }
  body.has-active-game .spell-form { margin-top: 10px; }
  body.has-active-game .spell-recent { max-height: 48px; margin-top: 7px; }
}

.mobile-current-prompt { display: none; }

@media (max-width: 860px) {
  body.has-active-game .mission-panel.is-collapsed ~ .map-card .mobile-current-prompt {
    position: absolute;
    z-index: 12;
    top: 10px;
    left: 58px;
    display: grid;
    grid-template-columns: auto minmax(0,1fr) auto;
    align-items: center;
    gap: 8px;
    width: min(270px, calc(100% - 70px));
    min-height: 54px;
    border: 1px solid var(--border-strong);
    border-radius: 13px;
    background: color-mix(in srgb, var(--surface-solid) 94%, transparent);
    color: var(--text);
    cursor: pointer;
    padding: 7px 9px;
    box-shadow: var(--shadow-soft);
    backdrop-filter: blur(14px);
    text-align: left;
  }
  .mobile-current-prompt > span:nth-child(2) { min-width: 0; }
  .mobile-current-prompt small,
  .mobile-current-prompt strong,
  .mobile-current-prompt em { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .mobile-current-prompt small { color: var(--accent); font-size: .54rem; font-style: normal; font-weight: 850; letter-spacing: .06em; text-transform: uppercase; }
  .mobile-current-prompt strong { margin-top: 1px; font-size: .76rem; }
  .mobile-current-prompt em { margin-top: 2px; color: var(--muted); font-size: .53rem; font-style: normal; }
  .mobile-prompt-flag .flag-art { width: 42px; border-radius: 5px; }
  .mobile-prompt-arrow { color: var(--accent); font-size: 1rem; }
}

/* --------------------------------------------------------------------------
   Classic polish pass: full-screen home, quiet competitive play, clean
   answer feedback. These rules intentionally sit last so they also override
   the compact modal styles used elsewhere in the app.
   -------------------------------------------------------------------------- */

/* The opening/setup experience is a true page, not a floating window. */
.setup-modal {
  position: fixed;
  inset: 0;
  width: 100dvw;
  height: 100dvh;
  max-width: none;
  max-height: none;
  margin: 0;
  overflow: auto;
  border: 0;
  border-radius: 0;
  background:
    radial-gradient(circle at 14% 9%, rgba(34, 211, 238, .12), transparent 30rem),
    radial-gradient(circle at 88% 88%, rgba(180, 160, 255, .1), transparent 34rem),
    linear-gradient(145deg, var(--bg-deep), var(--bg));
  padding: 0;
  box-shadow: none;
  backdrop-filter: none;
}
.setup-modal::backdrop {
  background: var(--bg-deep);
  backdrop-filter: none;
}
.setup-modal[open] { animation: setup-page-in 190ms ease both; }
.setup-modal > form {
  display: flex;
  width: min(1420px, 100%);
  min-height: 100%;
  margin: 0 auto;
  flex-direction: column;
  justify-content: center;
  padding: clamp(18px, 2.6vw, 40px) clamp(20px, 5vw, 76px);
}
.setup-page-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  margin-bottom: clamp(19px, 2.6vh, 30px);
  border-bottom: 1px solid var(--border);
  padding-bottom: 15px;
}
.setup-page-brand {
  display: inline-flex;
  align-items: center;
  gap: 11px;
}
.setup-page-brand > span:last-child,
.setup-page-brand strong,
.setup-page-brand small { display: block; }
.setup-page-brand strong { font-size: 1rem; letter-spacing: -.02em; }
.setup-page-brand small { margin-top: 1px; color: var(--muted); font-size: .67rem; }
.setup-page-bar > p {
  margin: 0;
  color: var(--muted);
  font-size: .72rem;
  font-weight: 760;
  letter-spacing: .03em;
}
.setup-modal .modal-head h2 { font-size: clamp(2rem, 4.1vw, 3.55rem); }
.setup-modal .modal-head p:last-child { max-width: 760px; font-size: .91rem; }
.setup-modal:not(.can-close) .modal-close { display: none; }
.setup-modal.can-close .modal-close {
  border: 1px solid var(--border);
  background: var(--surface-2);
}

/* Competitive is available in every mode but stays visually secondary. */
.sprint-choice {
  flex: 0 1 500px;
  min-width: 0;
  border: 0;
  border-radius: 0;
  background: transparent;
  padding: 4px 0;
  box-shadow: none;
}
.sprint-choice:hover { background: transparent; }
.sprint-choice:has(input:checked) { background: transparent; }
.sprint-choice input { accent-color: var(--accent-strong); }
.sprint-choice-mark,
.sprint-choice strong { color: var(--accent); }
.sprint-choice strong { font-size: .74rem; }
.sprint-choice small { font-size: .63rem; }
.setup-lock-note {
  border-left-color: var(--accent);
  background: rgba(103, 232, 249, .055);
}
.sprint-badge {
  gap: 7px;
  margin-top: 9px;
  border: 0;
  border-radius: 0;
  background: transparent;
  color: var(--accent);
  padding: 3px 0;
}
.sprint-badge > span { font-size: .9rem; }
.sprint-badge strong { color: var(--accent); font-size: .64rem; }
.sprint-badge small { font-size: .59rem; }
.sprint-result-card {
  border-color: var(--border);
  background: var(--surface-2);
}
.sprint-result-head strong,
.sprint-result-mode { color: var(--accent) !important; }
.sprint-result-mode { border-color: rgba(103, 232, 249, .3); }

/* No bordered answer card or floating rectangle appears after a live guess. */
body.has-active-game .map-callout,
body.has-active-game .country-card { display: none !important; }
body.has-active-game .feedback {
  min-height: 34px;
  margin-top: 12px;
  border: 0 !important;
  border-radius: 0;
  background: transparent !important;
  padding: 7px 1px;
}
body.has-active-game .feedback.is-correct,
body.has-active-game .feedback.is-wrong,
body.has-active-game .feedback.is-info {
  border-color: transparent !important;
  background: transparent !important;
}
body.has-active-game .feedback p { font-size: .78rem; }

@keyframes setup-page-in {
  from { opacity: 0; transform: scale(.995); }
  to { opacity: 1; transform: scale(1); }
}

@media (max-height: 820px) and (min-width: 901px) {
  .setup-modal > form { justify-content: flex-start; padding-block: 18px; }
  .setup-page-bar { margin-bottom: 13px; padding-bottom: 10px; }
  .setup-modal .modal-head h2 { font-size: clamp(2rem, 3.2vw, 2.8rem); }
  .setup-modal .modal-head p:last-child { margin-top: 6px; }
  .setup-modal fieldset { margin-top: 15px; }
  .mode-card { min-height: 118px; padding: 12px; }
  .mode-symbol { width: 36px; height: 36px; margin-bottom: 9px; }
  .mode-card small { margin-top: 4px; line-height: 1.3; }
  .setup-footer { margin-top: 17px; padding-top: 13px; }
}

@media (max-width: 900px) {
  .setup-modal > form {
    display: block;
    min-height: 100%;
    padding: max(18px, env(safe-area-inset-top)) 14px max(24px, env(safe-area-inset-bottom));
  }
  .setup-page-bar { margin-bottom: 18px; }
  .setup-page-bar > p { display: none; }
  .setup-modal .modal-head h2 { font-size: clamp(2rem, 10vw, 3rem); }
  .setup-modal .mode-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .setup-modal .mode-card { min-height: 132px; }
  .setup-footer { align-items: stretch; }
  .sprint-choice { flex-basis: auto; width: 100%; }
}

@media (max-width: 430px) {
  .setup-page-brand .brand-mark { width: 38px; height: 38px; }
  .setup-modal .mode-grid { gap: 7px; }
  .setup-modal .mode-card { min-height: 124px; border-radius: 14px; padding: 12px; }
  .setup-modal .mode-symbol { width: 36px; height: 36px; margin-bottom: 9px; }
  .setup-modal .mode-card strong { font-size: .84rem; }
  .setup-modal .mode-card small { font-size: .64rem; }
}

@media (prefers-reduced-motion: reduce) {
  .setup-modal[open] { animation: none; }
}

body.has-active-game .tiny-country-note,
body.has-active-game .map-tooltip,
body.has-active-game .map-callout,
body.has-active-game .country-card,
body.has-active-game .toast-region {
  display: none !important;
}

@media (max-width: 900px) {
  .setup-modal .featured-mode { grid-column: auto; min-height: 132px; }
}
@media (max-width: 430px) {
  .setup-modal .featured-mode { min-height: 124px; }
}

html:has(.setup-modal[open]),
body:has(.setup-modal[open]) {
  height: 100dvh;
  overflow: hidden !important;
  padding-bottom: 0 !important;
}

/* Pointer guesses never leave a rectangular browser focus frame on the map. */
#worldMap:focus,
#worldMap:focus-visible {
  outline: none !important;
  box-shadow: none !important;
}
.country:focus:not(:focus-visible),
.country-marker:focus:not(:focus-visible) {
  outline: none !important;
}

/* --------------------------------------------------------------------------
   Atlas Arcade 2.0 polish: precision map controls, fair starts, richer
   progress, installability, and responsive interaction refinements.
   -------------------------------------------------------------------------- */

.install-button svg {
  width: 19px;
  height: 19px;
  fill: none;
  stroke: currentColor;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-width: 1.8;
}

/* The map uses a precise, non-rectangular targeting cursor during click modes. */
.map-stage.is-targeting #worldMap { cursor: crosshair; }
.map-stage:not(.is-targeting) #worldMap { cursor: grab; }
.map-stage:not(.is-targeting) #worldMap.is-dragging,
.map-stage:not(.is-targeting) #worldMap.is-pinching,
#worldMap.is-dragging,
#worldMap.is-pinching { cursor: grabbing; }

.map-reticle {
  position: absolute;
  z-index: 18;
  top: 0;
  left: 0;
  width: 26px;
  height: 26px;
  margin: -13px 0 0 -13px;
  border-radius: 50%;
  pointer-events: none;
  filter: drop-shadow(0 2px 5px rgba(0, 0, 0, .7));
  transition: opacity 90ms ease, scale 90ms ease;
  will-change: transform;
}
.map-reticle::before,
.map-reticle::after {
  position: absolute;
  content: "";
  background: color-mix(in srgb, var(--accent) 92%, white);
  border-radius: 999px;
}
.map-reticle::before { top: 12px; left: 0; width: 26px; height: 2px; }
.map-reticle::after { top: 0; left: 12px; width: 2px; height: 26px; }
.map-reticle > span {
  position: absolute;
  z-index: 1;
  top: 10px;
  left: 10px;
  width: 6px;
  height: 6px;
  border: 2px solid var(--accent-ink);
  border-radius: 50%;
  background: var(--accent);
  box-shadow: 0 0 0 2px rgba(103, 232, 249, .25), 0 0 12px rgba(103, 232, 249, .7);
}
.map-reticle.is-pressed { scale: .78; opacity: .9; }

.map-zoom-readout {
  position: absolute;
  z-index: 8;
  left: 14px;
  bottom: 14px;
  min-width: 42px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: color-mix(in srgb, var(--surface-solid) 82%, transparent);
  color: var(--text-soft);
  padding: 5px 8px;
  box-shadow: var(--shadow-soft);
  backdrop-filter: blur(12px);
  font-size: .62rem;
  font-variant-numeric: tabular-nums;
  font-weight: 800;
  text-align: center;
  pointer-events: none;
}

.game-countdown {
  position: absolute;
  z-index: 30;
  inset: 0;
  display: grid;
  place-content: center;
  justify-items: center;
  background: radial-gradient(circle, rgba(8, 25, 42, .2), rgba(4, 10, 19, .72));
  backdrop-filter: blur(2px);
  pointer-events: none;
}
.game-countdown span {
  display: grid;
  min-width: 120px;
  min-height: 120px;
  place-items: center;
  border: 1px solid rgba(103, 232, 249, .38);
  border-radius: 50%;
  background: rgba(7, 20, 34, .88);
  color: var(--accent);
  box-shadow: 0 0 0 12px rgba(103, 232, 249, .06), 0 24px 70px rgba(0, 0, 0, .42);
  font-size: clamp(3.6rem, 8vw, 6.6rem);
  font-weight: 900;
  letter-spacing: -.07em;
  line-height: 1;
  font-variant-numeric: tabular-nums;
}
.game-countdown small {
  margin-top: 16px;
  color: var(--text-soft);
  font-size: .72rem;
  font-weight: 850;
  letter-spacing: .12em;
  text-transform: uppercase;
}
.game-countdown.is-pop span { animation: countdown-pop 420ms cubic-bezier(.2, .8, .2, 1); }
.map-stage.is-counting-down #worldMap { pointer-events: none; }

@keyframes countdown-pop {
  0% { opacity: .25; transform: scale(.72); }
  55% { opacity: 1; transform: scale(1.08); }
  100% { opacity: 1; transform: scale(1); }
}

.score-grid strong.is-pulsing,
.score-grid #timeStat.is-pulsing {
  animation: stat-pop 360ms cubic-bezier(.2, .85, .25, 1);
}
@keyframes stat-pop {
  0% { color: var(--text); transform: scale(1); }
  45% { color: var(--accent); transform: scale(1.12); }
  100% { color: var(--text); transform: scale(1); }
}

.sprint-badge small b {
  color: var(--text-soft);
  font-weight: 760;
}

.leaderboard-personal-best {
  display: grid;
  grid-template-columns: auto auto minmax(0, 1fr);
  align-items: center;
  gap: 10px;
  margin-top: 14px;
  border: 1px solid var(--border);
  border-radius: 13px;
  background: var(--surface-2);
  padding: 10px 12px;
}
.leaderboard-personal-best > span {
  color: var(--muted);
  font-size: .63rem;
  font-weight: 800;
  letter-spacing: .05em;
  text-transform: uppercase;
}
.leaderboard-personal-best > strong {
  color: var(--text);
  font-size: 1.1rem;
  font-variant-numeric: tabular-nums;
}
.leaderboard-personal-best > small {
  min-width: 0;
  color: var(--muted);
  font-size: .65rem;
  text-align: right;
}
.leaderboard-personal-best.has-record {
  border-color: rgba(103, 232, 249, .28);
  background: linear-gradient(90deg, rgba(103, 232, 249, .08), var(--surface-2));
}
.leaderboard-personal-best.has-record > strong { color: var(--accent); }

.mode-progress-section,
.recent-runs-section {
  margin-top: 20px;
}
.mode-progress-section .section-head,
.recent-runs-section .section-head { align-items: flex-end; }
.mode-progress-section .section-head p,
.recent-runs-section .section-head p {
  margin: 4px 0 0;
  color: var(--muted);
  font-size: .66rem;
}
.mode-progress-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 9px;
  margin-top: 10px;
}
.mode-progress-card {
  min-width: 0;
  border: 1px solid var(--border);
  border-radius: 14px;
  background: linear-gradient(145deg, var(--surface-2), color-mix(in srgb, var(--surface-solid) 70%, transparent));
  padding: 11px;
}
.mode-progress-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}
.mode-progress-head strong { font-size: .76rem; }
.mode-progress-head button {
  border: 0;
  background: transparent;
  color: var(--accent);
  cursor: pointer;
  padding: 2px;
  font-size: .62rem;
  font-weight: 800;
}
.mode-progress-values {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 6px;
  margin-top: 10px;
}
.mode-progress-values span { min-width: 0; }
.mode-progress-values b,
.mode-progress-values small { display: block; }
.mode-progress-values b {
  overflow: hidden;
  color: var(--text);
  font-size: .76rem;
  font-variant-numeric: tabular-nums;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.mode-progress-values small {
  margin-top: 2px;
  color: var(--muted);
  font-size: .53rem;
  text-transform: uppercase;
}
.recent-runs {
  display: grid;
  gap: 7px;
  margin-top: 10px;
}
.recent-run {
  display: grid;
  grid-template-columns: 112px minmax(0, 1fr) auto;
  align-items: center;
  gap: 10px;
  border-bottom: 1px solid var(--border);
  padding: 7px 2px 9px;
}
.recent-run:last-child { border-bottom: 0; }
.recent-run-mode {
  overflow: hidden;
  color: var(--text-soft);
  font-size: .68rem;
  font-weight: 800;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.recent-run div { min-width: 0; }
.recent-run strong,
.recent-run small { display: block; }
.recent-run strong { font-size: .72rem; }
.recent-run small { margin-top: 2px; color: var(--muted); font-size: .58rem; }
.recent-run time { color: var(--muted); font-size: .58rem; }

/* More tactile controls without changing the established visual language. */
.mode-card,
.segmented label span,
.primary-button,
.secondary-button,
.ghost-button,
.map-tool,
.nav-button {
  transition: transform 140ms ease, border-color 140ms ease, background-color 140ms ease, color 140ms ease, box-shadow 140ms ease;
}
.mode-card:hover { transform: translateY(-2px); }
.mode-card:active,
.primary-button:active,
.secondary-button:active,
.ghost-button:active,
.map-tool:active { transform: translateY(1px) scale(.985); }
.mode-card:has(input:checked) {
  box-shadow: inset 0 0 0 1px rgba(103, 232, 249, .12), 0 14px 34px rgba(0, 0, 0, .16);
}

/* Keep the fixed desktop game canvas crisp at common laptop heights. */
body.has-active-game .map-card,
body.has-active-game .mission-panel { box-shadow: 0 18px 55px rgba(0, 0, 0, .22); }
body.has-active-game .map-toolbar { background: color-mix(in srgb, var(--surface-solid) 82%, transparent); }
#mapViewport { transform-origin: 0 0; will-change: transform; }

@media (max-width: 860px) {
  .map-reticle { display: none !important; }
  .map-zoom-readout { left: 9px; bottom: 9px; padding: 4px 7px; font-size: .56rem; }
  .game-countdown span { min-width: 96px; min-height: 96px; }
  .game-countdown small { margin-top: 12px; font-size: .62rem; }
  .leaderboard-personal-best { grid-template-columns: auto 1fr; }
  .leaderboard-personal-best > small { grid-column: 1 / -1; text-align: left; }
  .mode-progress-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

@media (max-width: 560px) {
  .mode-progress-grid { grid-template-columns: 1fr; }
  .recent-run { grid-template-columns: 88px minmax(0, 1fr) auto; }
  .leaderboard-personal-best { margin-top: 10px; }
}

@media (hover: none), (pointer: coarse) {
  .mode-card:hover { transform: none; }
  .map-stage #worldMap { cursor: default; }
}

@media (prefers-reduced-motion: reduce) {
  .game-countdown.is-pop span,
  .score-grid strong.is-pulsing,
  .score-grid #timeStat.is-pulsing { animation: none; }
  .mode-card:hover { transform: none; }
}
