:root {
  --sea: #cfe4ec;
  --land: #f6f1e7;
  --land-hover: #ece3d0;
  --context: #e0dbd1;
  --border: #9b9384;
  --target: #f29e1f;
  --correct: #23a35c;
  --wrong: #d9443c;
  --ink: #1d2a30;
  --muted: #5d6b72;
  --accent: #0f5e6e;
  --accent-ink: #ffffff;
  --card: rgba(255, 255, 255, 0.96);
  --shadow: 0 6px 24px rgba(20, 40, 50, 0.18);
  --radius: 16px;
  --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);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  overscroll-behavior: none;
}

body {
  background: var(--sea);
  color: var(--ink);
  font: 16px/1.4 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  -webkit-tap-highlight-color: transparent;
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
}

button {
  font: inherit;
  color: inherit;
  cursor: pointer;
  touch-action: manipulation;
}

[hidden] { display: none !important; }

/* --- map ------------------------------------------------------------------ */

#map {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
  touch-action: none;
  cursor: grab;
}
#map:active { cursor: grabbing; }

#map path {
  stroke: var(--border);
  stroke-width: 0.8px;
  stroke-linejoin: round;
  vector-effect: non-scaling-stroke;
}
#map .context path { fill: var(--context); stroke: #b7b0a3; }
#map .countries path { fill: var(--land); transition: fill 0.2s; }
#map .countries path.target { fill: var(--target); stroke: #8a5408; stroke-width: 1.5px; }
#map .countries path.correct { fill: var(--correct); stroke: #0e5a31; stroke-width: 1.5px; }
#map .countries path.wrong { fill: var(--wrong); stroke: #7a1d18; stroke-width: 1.5px; }

@media (hover: hover) {
  #map .countries path:hover:not(.target):not(.correct):not(.wrong) { fill: var(--land-hover); }
}

/* Rings make tiny countries (Malta, Luxembourg) visible when marked. */
#map .rings circle {
  fill: none;
  stroke: transparent;
  stroke-width: 2.5px;
  vector-effect: non-scaling-stroke;
}
#map .rings circle.target { stroke: var(--target); }
#map .rings circle.correct { stroke: var(--correct); }
#map .rings circle.wrong { stroke: var(--wrong); }
#map .hits circle { fill: transparent; }

/* --- zoom buttons ------------------------------------------------------------ */

.zoom {
  position: fixed;
  right: calc(12px + var(--safe-right));
  top: 50%;
  transform: translateY(-50%);
  display: flex;
  flex-direction: column;
  gap: 8px;
  z-index: 2;
}
.zoom button {
  width: 44px;
  height: 44px;
  border: 0;
  border-radius: 12px;
  background: var(--card);
  box-shadow: var(--shadow);
  font-size: 22px;
  line-height: 1;
  display: grid;
  place-items: center;
}
.zoom svg, .icon-btn svg {
  width: 20px;
  height: 20px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2.2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

/* --- top bar ------------------------------------------------------------------ */

.bar {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  padding: calc(10px + var(--safe-top)) calc(12px + var(--safe-right)) 0 calc(12px + var(--safe-left));
  z-index: 3;
  pointer-events: none;
}
.bar-inner {
  pointer-events: auto;
  max-width: 640px;
  margin: 0 auto;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 14px 8px 8px;
  background: var(--card);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}
.icon-btn {
  flex: none;
  width: 40px;
  height: 40px;
  border: 0;
  border-radius: 10px;
  background: transparent;
  color: var(--muted);
  display: grid;
  place-items: center;
}
.icon-btn:hover { background: rgba(0, 0, 0, 0.05); }
.prompt {
  flex: 1;
  font-size: 18px;
  min-width: 0;
}
.prompt strong { font-weight: 700; }
.progress {
  flex: none;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
  font-size: 15px;
}

/* --- bottom panel --------------------------------------------------------------- */

.panel {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 3;
  padding: 0 calc(12px + var(--safe-right)) calc(12px + var(--safe-bottom)) calc(12px + var(--safe-left));
  pointer-events: none;
}
.panel > * {
  pointer-events: auto;
  max-width: 640px;
  margin-left: auto;
  margin-right: auto;
}
.choices {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin-bottom: 8px;
}
.choice {
  min-height: 56px;
  padding: 10px 12px;
  border: 2px solid transparent;
  border-radius: 14px;
  background: var(--card);
  box-shadow: var(--shadow);
  font-size: 16px;
  font-weight: 600;
}
.choice:not(:disabled):hover { border-color: var(--accent); }
.choice:disabled { cursor: default; color: #8a979d; background: #f3f5f6; }
.choice.correct { background: var(--correct); color: #fff; }
.choice.wrong { background: var(--wrong); color: #fff; }

.panel-row {
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 0;
}
.feedback:empty { display: none; }
.feedback {
  flex: 1;
  padding: 12px 16px;
  border-radius: 14px;
  background: var(--card);
  box-shadow: var(--shadow);
  font-weight: 600;
}
.feedback.good { color: var(--correct); }
.feedback.bad { color: var(--wrong); }

.btn {
  min-height: 48px;
  padding: 0 20px;
  border: 0;
  border-radius: 14px;
  background: #e9eef0;
  font-weight: 600;
}
.btn.primary { background: var(--accent); color: var(--accent-ink); }
.panel .btn { box-shadow: var(--shadow); }

/* --- menu and result sheets ---------------------------------------------------- */

.sheet {
  position: fixed;
  z-index: 4;
  left: 0;
  right: 0;
  bottom: 0;
  margin: 0 auto;
  max-width: 480px;
  padding: 22px 20px calc(20px + var(--safe-bottom));
  background: var(--card);
  border-radius: 22px 22px 0 0;
  box-shadow: 0 -6px 30px rgba(20, 40, 50, 0.2);
}
@media (min-width: 720px) and (min-height: 560px) {
  .sheet {
    left: calc(24px + var(--safe-left));
    right: auto;
    bottom: auto;
    top: 50%;
    transform: translateY(-50%);
    width: 380px;
    border-radius: 22px;
    padding-bottom: 22px;
    box-shadow: var(--shadow);
  }
}
.sheet h1, .sheet h2 { margin: 0; }
.sheet h1 { font-size: 30px; letter-spacing: -0.5px; color: var(--accent); }
.tagline { margin: 2px 0 16px; color: var(--muted); }

.mode {
  display: grid;
  width: 100%;
  text-align: left;
  gap: 2px;
  padding: 14px 16px;
  margin-top: 10px;
  border: 2px solid #e3e9eb;
  border-radius: 14px;
  background: #fff;
}
.mode:hover { border-color: var(--accent); }
.mode-title { font-size: 19px; font-weight: 700; }
.mode-hint { color: var(--muted); font-size: 15px; }
.mode-best:empty { display: none; }
.mode-best { color: var(--accent); font-size: 14px; font-weight: 600; }

.score { font-size: 22px; font-weight: 700; margin: 8px 0 4px; }
.mistakes-title { margin: 8px 0 4px; color: var(--muted); }
.mistakes {
  margin: 0 0 4px;
  padding: 0;
  list-style: none;
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}
.mistakes li {
  padding: 4px 10px;
  border-radius: 999px;
  background: #fbe3e1;
  color: #8f241e;
  font-size: 14px;
  font-weight: 600;
}
.row { display: flex; gap: 10px; margin-top: 16px; }
.row .btn { flex: 1; }

/* Hide everything until the map data has loaded. */
body:not(.ready) .zoom { visibility: hidden; }

/* Touch devices pinch to zoom; only the "show all" button is needed there. */
@media (hover: none) {
  #zoom-in, #zoom-out { display: none; }
}

#map .sea-stop { stop-color: var(--sea); }
