:root {
  --bg-0: #0b1020;
  --bg-1: #111831;
  --ink: #e8edff;
  --muted: #8a94bb;
  --accent: #5eead4;
  --accent-2: #fb7185;
  --correct: #34d399;
  --wrong: #f87171;
  --ocean: #091227;
  --land: #8494c6;
  --land-edge: #0c1a3a;
  --focus: #ff3d88;
  --focus-glow: 255, 61, 136;
  --panel-bg: rgba(17, 24, 49, 0.82);
  --panel-border: rgba(255, 255, 255, 0.1);
}

* { box-sizing: border-box; }

html, body { margin: 0; height: 100%; }
body {
  background:
    radial-gradient(1200px 800px at 20% -10%, #1a2550 0%, transparent 60%),
    radial-gradient(1000px 700px at 110% 110%, #1d2e66 0%, transparent 60%),
    var(--bg-0);
  color: var(--ink);
  font-family: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto,
    "Helvetica Neue", Arial, "Apple Color Emoji", "Segoe UI Emoji";
  -webkit-font-smoothing: antialiased;
  letter-spacing: 0.01em;
  overflow: hidden;
}

/* Hidden attribute must win over specific display rules set on IDs. */
[hidden] { display: none !important; }

#app {
  height: 100dvh;
  display: flex;
  flex-direction: column;
  padding: 12px clamp(12px, 2.5vw, 24px);
  gap: 12px;
}

.topbar {
  flex: none;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}
.topbar h1 {
  margin: 0;
  font-size: clamp(18px, 2.5vw, 24px);
  font-weight: 650;
  letter-spacing: -0.01em;
}

.stats { display: flex; gap: 8px; }
.stat {
  display: inline-flex;
  align-items: baseline;
  gap: 8px;
  padding: 6px 12px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid rgba(255, 255, 255, 0.08);
  font-variant-numeric: tabular-nums;
  font-size: 14px;
}
.stat .label {
  color: var(--muted);
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

/* Stage — fills remaining height, holds map + overlays */
#stage {
  flex: 1 1 auto;
  min-height: 0;
  position: relative;
  border-radius: 18px;
  background:
    radial-gradient(1200px 700px at 50% 30%, #0d1a3a 0%, transparent 70%),
    var(--ocean);
  border: 1px solid rgba(255, 255, 255, 0.06);
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.03),
    0 20px 60px -30px rgba(0, 0, 0, 0.6);
  overflow: hidden;
}

#map {
  display: block;
  width: 100%;
  height: 100%;
}

/* Map styling */
.country {
  fill: var(--land);
  stroke: var(--land-edge);
  stroke-width: 0.9;
  stroke-linejoin: round;
  shape-rendering: geometricPrecision;
  vector-effect: non-scaling-stroke;
  transition: fill 300ms ease, opacity 300ms ease;
}
/* Active country: same dark border as its neighbours, stands out via a
   big, neon glow rather than a different stroke. Keeping the stroke
   identical keeps country edges clean and consistent. */
.country.active {
  fill: var(--focus);
  animation: country-pulse 1.4s ease-in-out infinite;
}
.country.reveal {
  fill: var(--correct);
  animation: none;
  filter:
    brightness(1.15) saturate(1.2)
    drop-shadow(0 0 2px rgba(167, 243, 208, 0.9))
    drop-shadow(0 0 6px rgba(52, 211, 153, 0.8));
}
.country.dimmed {
  opacity: 0.92;
}

/* Keep the glow tight so it hugs the country outline instead of bleeding out
   into a circular blob on small countries. The country itself brightens and
   saturates at the pulse peak so the pulse reads as the shape glowing. */
@keyframes country-pulse {
  0%, 100% {
    filter:
      brightness(1) saturate(1)
      drop-shadow(0 0 1px rgba(var(--focus-glow), 0.9))
      drop-shadow(0 0 3px rgba(var(--focus-glow), 0.7));
  }
  50% {
    filter:
      brightness(1.2) saturate(1.35)
      drop-shadow(0 0 1px rgba(255, 255, 255, 0.95))
      drop-shadow(0 0 4px rgba(var(--focus-glow), 1))
      drop-shadow(0 0 9px rgba(var(--focus-glow), 0.85));
  }
}

@media (prefers-reduced-motion: reduce) {
  .country.active {
    animation: none;
    filter:
      brightness(1.15) saturate(1.3)
      drop-shadow(0 0 2px rgba(255, 255, 255, 0.9))
      drop-shadow(0 0 6px rgba(var(--focus-glow), 0.95));
  }
}

/* Overlay panels (start, game-over, loading, HUD) */
.overlay-panel {
  position: absolute;
  background: var(--panel-bg);
  border: 1px solid var(--panel-border);
  border-radius: 14px;
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.06),
    0 20px 50px -20px rgba(0, 0, 0, 0.55);
  padding: clamp(14px, 2vw, 22px);
  color: var(--ink);
}

.overlay-center {
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: calc(100% - 24px);
  max-width: 460px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 14px;
  text-align: center;
}
.overlay-center h2 { margin: 0; font-size: 22px; }
.overlay-center p { margin: 0; color: var(--muted); line-height: 1.5; max-width: 40ch; }
.overlay-center p strong { color: var(--ink); }
.overlay-center p.hint { font-size: 13px; opacity: 0.8; }

.difficulty {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  justify-content: center;
}
.difficulty .btn-primary { min-width: 92px; }

/* HUD at the bottom during play — compact, flag feels prominent */
.overlay-bottom {
  left: 50%;
  bottom: 16px;
  transform: translateX(-50%);
  width: calc(100% - 24px);
  max-width: 680px;
  padding: 10px 12px;
  display: grid;
  grid-template-columns: auto 1fr auto auto;
  align-items: center;
  gap: 12px;
}
.overlay-bottom .flag {
  font-size: clamp(48px, 9vw, 64px);
  line-height: 1;
  filter: drop-shadow(0 4px 10px rgba(0, 0, 0, 0.55));
  user-select: none;
  padding: 0 2px 0 4px;
}
/* Flatten the inner form — its children become grid items of .overlay-bottom
   so flag, input, and buttons share one baseline with consistent gaps. */
.overlay-bottom .guess-row {
  display: contents;
}
.overlay-bottom input[type="text"] {
  width: 100%;
  min-width: 0;
}
.overlay-bottom .feedback {
  grid-column: 1 / -1;
  margin: 0;
  text-align: left;
  padding-left: 2px;
  /* Reserve the line height so the panel height doesn't jump when a
     feedback message appears after a guess. */
  min-height: 1.3em;
  font-size: 13px;
  line-height: 1.3;
  color: var(--muted);
}

input[type="text"] {
  min-width: 0;
  background: rgba(255, 255, 255, 0.06);
  color: var(--ink);
  border: 1px solid rgba(255, 255, 255, 0.14);
  border-radius: 10px;
  padding: 10px 12px;
  font-size: 15px;
  outline: none;
  transition: border-color 150ms, box-shadow 150ms, background 150ms;
}
input[type="text"]:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(94, 234, 212, 0.18);
  background: rgba(255, 255, 255, 0.08);
}

.btn-primary, .btn-ghost {
  border-radius: 10px;
  padding: 10px 14px;
  font-size: 14px;
  font-weight: 600;
  border: 1px solid transparent;
  cursor: pointer;
  white-space: nowrap;
  transition: transform 80ms, background 120ms, border-color 120ms, color 120ms;
}
.btn-primary { background: var(--accent); color: #06201b; }
.btn-primary:hover { background: #7ff0dc; }
.btn-primary:active { transform: translateY(1px); }
.btn-ghost {
  background: transparent;
  color: var(--muted);
  border-color: rgba(255, 255, 255, 0.14);
}
.btn-ghost:hover { color: var(--ink); border-color: rgba(255, 255, 255, 0.24); }

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

/* Narrow screens: flag + input on one row, Guess on next row, Skip right-aligned. */
@media (max-width: 520px) {
  .overlay-bottom {
    grid-template-columns: auto 1fr;
    gap: 10px;
  }
  .overlay-bottom #btn-submit {
    grid-column: 1 / -1;
  }
  .overlay-bottom #btn-skip {
    grid-column: 1 / -1;
    justify-self: end;
  }
}

/* Very short viewports: shrink flag so bottom HUD doesn't crowd the map. */
@media (max-height: 560px) {
  .overlay-bottom .flag { font-size: 40px; }
  .overlay-bottom { padding: 8px 10px; }
}
