:root {
  --ocean: #e4f1fb;
  --ocean-edge: #c9dff0;
  --border: #8796a8;
  --ink: #1f2a37;
  --ink-soft: #5b6878;
  --panel: rgba(255, 255, 255, 0.94);
  --accent: #2f6fdb;
  --accent-dark: #2459b3;
  --guess: #e0484f;
  --actual: #1d9a5b;
  --shadow: 0 6px 24px rgba(31, 42, 55, 0.14);
  --radius: 14px;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  color: var(--ink);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  background: var(--ocean);
}

#app { position: fixed; inset: 0; }

.hidden { display: none !important; }

/* ---------- Map ---------- */
#map {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
  cursor: crosshair;
  touch-action: none;
  user-select: none;
}
#map.panning { cursor: grabbing; }

.sphere { fill: var(--ocean); stroke: var(--ocean-edge); stroke-width: 1.5; }
.graticule { fill: none; stroke: #d3e5f3; stroke-width: 0.6; }
.country { stroke: var(--border); stroke-width: 0.5; stroke-linejoin: round; }
.sphere, .graticule, .country, .guess-line { vector-effect: non-scaling-stroke; }

/* Overlay never intercepts clicks: the map underneath must receive both clicks
   of a double-click, even though the pin is (re)drawn right under the cursor. */
.guess-line, .marker, .marker-ring, .city-label { pointer-events: none; }

.guess-line {
  fill: none;
  stroke: var(--ink);
  stroke-width: 1.6;
  stroke-dasharray: 5 4;
  opacity: 0.75;
}
.marker { stroke: #fff; vector-effect: non-scaling-stroke; stroke-width: 2; }
.marker.guess { fill: var(--guess); }
.marker.actual { fill: var(--actual); }
.marker-ring { fill: none; stroke: var(--actual); stroke-width: 2; vector-effect: non-scaling-stroke; opacity: 0.6; }
.city-label {
  font-weight: 700;
  fill: var(--ink);
  paint-order: stroke;
  stroke: #fff;
  stroke-width: 3px;
  stroke-linejoin: round;
  pointer-events: none;
}

/* ---------- HUD ---------- */
#hud {
  position: absolute;
  top: 12px;
  left: 12px;
  right: 12px;
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: start;
  gap: 12px;
  pointer-events: none;
}
#hud > * { pointer-events: auto; }

.brand {
  font-weight: 800;
  font-size: 20px;
  letter-spacing: -0.02em;
  padding: 10px 14px;
  background: var(--panel);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  justify-self: start;
}
.brand span, h1 span { color: var(--accent); }

.prompt-card {
  background: var(--panel);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 10px 26px 12px;
  text-align: center;
  min-width: 280px;
}
.prompt-label {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.12em;
  color: var(--ink-soft);
}
.prompt-city { font-size: 26px; font-weight: 800; line-height: 1.2; }
#target-country { font-weight: 500; color: var(--ink-soft); font-size: 18px; }
#target-country:not(:empty)::before { content: ", "; }

.timer {
  margin-top: 8px;
  height: 6px;
  background: #e5eaf0;
  border-radius: 3px;
  overflow: hidden;
}
.timer-fill {
  height: 100%;
  width: 100%;
  background: var(--accent);
  transform-origin: left center;
}
.prompt-card.grace .timer-fill { background: var(--actual); }
.prompt-card.grace .prompt-label { color: var(--actual); font-weight: 700; }
.timer-fill.warn { background: #e8a33d; }
.timer-fill.danger { background: var(--guess); }

.stats {
  justify-self: end;
  display: flex;
  align-items: center;
  gap: 18px;
  background: var(--panel);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 8px 10px 8px 16px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}
.stats > div { display: flex; flex-direction: column; line-height: 1.15; }
.stat-label { font-size: 11px; font-weight: 500; text-transform: uppercase; letter-spacing: 0.08em; color: var(--ink-soft); }

/* ---------- Action bar ---------- */
#action-bar {
  position: absolute;
  left: 50%;
  bottom: 22px;
  transform: translateX(-50%);
  display: flex;
  align-items: center;
  gap: 16px;
  background: var(--panel);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 10px 10px 10px 20px;
  white-space: nowrap;
}
.hint { color: var(--ink-soft); }
.result { display: flex; align-items: baseline; gap: 14px; }
.result-distance { font-size: 18px; font-weight: 700; }
.result-time { font-size: 13px; color: var(--ink-soft); }
.result-time:empty { display: none; }
.result-points { font-size: 22px; font-weight: 800; color: var(--accent); font-variant-numeric: tabular-nums; }
.result-points.zero { color: var(--guess); }

/* ---------- Buttons ---------- */
button {
  font: inherit;
  border: none;
  cursor: pointer;
  border-radius: 10px;
}
button:disabled { opacity: 0.45; cursor: not-allowed; }
.primary {
  background: var(--accent);
  color: #fff;
  font-weight: 700;
  padding: 10px 20px;
}
.primary:not(:disabled):hover { background: var(--accent-dark); }
.primary.big { width: 100%; padding: 14px; font-size: 17px; margin-top: 8px; }
.ghost { background: #eef2f7; color: var(--ink); padding: 10px 18px; font-weight: 600; }
.ghost:hover { background: #e1e8f0; }
.ghost.small { padding: 6px 12px; font-size: 13px; }

#zoom-controls {
  position: absolute;
  right: 14px;
  bottom: 22px;
  display: flex;
  flex-direction: column;
  background: var(--panel);
  border-radius: 10px;
  box-shadow: var(--shadow);
  overflow: hidden;
}
#zoom-controls button {
  width: 38px;
  height: 38px;
  background: transparent;
  border-radius: 0;
  font-size: 20px;
  color: var(--ink);
}
#zoom-controls button:hover { background: #eef2f7; }
#zoom-controls button + button { border-top: 1px solid #e3e8ee; }

/* ---------- Overlays ---------- */
.overlay {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(228, 241, 251, 0.55);
  backdrop-filter: blur(3px);
  padding: 16px;
}
.panel {
  background: #fff;
  border-radius: 18px;
  box-shadow: var(--shadow);
  padding: 28px 30px;
  width: min(440px, 100%);
  max-height: 100%;
  overflow: auto;
}
.panel.wide { width: min(560px, 100%); }
h1 { margin: 0; font-size: 34px; letter-spacing: -0.03em; }
h2 { margin: 0 0 4px; font-size: 24px; }
.tagline { margin: 4px 0 22px; color: var(--ink-soft); }

.field { margin-bottom: 16px; }
.field-label { font-weight: 700; font-size: 14px; margin-bottom: 6px; }
.field-note { font-size: 12px; color: var(--ink-soft); margin-top: 5px; }
.segmented {
  display: flex;
  background: #eef2f7;
  border-radius: 10px;
  padding: 3px;
  gap: 3px;
}
.segmented button {
  flex: 1;
  padding: 8px 6px;
  background: transparent;
  border-radius: 8px;
  color: var(--ink-soft);
  font-weight: 600;
}
.segmented button.active { background: #fff; color: var(--ink); box-shadow: 0 1px 4px rgba(0,0,0,0.1); }

.toggle { display: flex; align-items: center; gap: 10px; margin: 4px 0 12px; cursor: pointer; }
.toggle input { width: 18px; height: 18px; accent-color: var(--accent); }

.best, .summary-best { text-align: center; color: var(--ink-soft); font-size: 14px; margin-top: 10px; min-height: 1em; }
.rules { font-size: 12px; color: var(--ink-soft); margin: 14px 0 0; text-align: center; }

.summary-total { font-size: 46px; font-weight: 800; color: var(--accent); font-variant-numeric: tabular-nums; }
.summary-total small { font-size: 20px; color: var(--ink-soft); font-weight: 600; }
.summary-best { text-align: left; margin: 0 0 14px; }
.table-wrap { max-height: 45vh; overflow: auto; border: 1px solid #eef2f7; border-radius: 10px; }
table { width: 100%; border-collapse: collapse; font-size: 14px; }
th, td { padding: 7px 10px; text-align: left; border-bottom: 1px solid #eef2f7; }
th { position: sticky; top: 0; background: #f7f9fb; font-size: 12px; text-transform: uppercase; letter-spacing: 0.06em; color: var(--ink-soft); }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
td .country-sub { color: var(--ink-soft); font-size: 12px; }
td.zero { color: var(--guess); }
.buttons { display: flex; gap: 10px; margin-top: 18px; }
.buttons .primary { flex: 1; }

/* ---------- Main menu ---------- */
.main-menu { text-align: center; }
.main-menu .tagline { margin-bottom: 28px; }

.play-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 14px;
  width: 100%;
  padding: 20px 24px;
  font-size: 28px;
  font-weight: 800;
  letter-spacing: 0.02em;
  color: #fff;
  border-radius: 16px;
  background: linear-gradient(135deg, #3b82f6 0%, #2f6fdb 45%, #1d9a5b 130%);
  box-shadow: 0 10px 28px rgba(47, 111, 219, 0.45), inset 0 -3px 0 rgba(0, 0, 0, 0.12);
  animation: play-pulse 2.2s ease-in-out infinite;
  transition: transform 0.15s ease, box-shadow 0.15s ease;
}
.play-btn:hover {
  transform: translateY(-2px) scale(1.02);
  box-shadow: 0 14px 34px rgba(47, 111, 219, 0.55), inset 0 -3px 0 rgba(0, 0, 0, 0.12);
}
.play-btn:active { transform: translateY(1px) scale(0.99); }
.play-btn:focus-visible { outline: 3px solid #9cc0ff; outline-offset: 3px; }
.play-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 42px;
  height: 42px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.22);
  font-size: 18px;
  padding-left: 3px;
}
@keyframes play-pulse {
  0%, 100% { box-shadow: 0 10px 28px rgba(47, 111, 219, 0.45), 0 0 0 0 rgba(47, 111, 219, 0.35), inset 0 -3px 0 rgba(0, 0, 0, 0.12); }
  50%      { box-shadow: 0 10px 28px rgba(47, 111, 219, 0.45), 0 0 0 12px rgba(47, 111, 219, 0), inset 0 -3px 0 rgba(0, 0, 0, 0.12); }
}
@media (prefers-reduced-motion: reduce) { .play-btn { animation: none; } }

.settings-summary { margin-top: 14px; font-size: 13px; color: var(--ink-soft); }
.options-btn { margin-top: 18px; }

.submenu-header { display: flex; align-items: center; gap: 12px; margin-bottom: 18px; }
.submenu-header h2 { margin: 0; }
.submenu-header .ghost.small { font-size: 18px; padding: 4px 12px; }
#options-menu .rules { margin-bottom: 4px; }

/* ---------- Small screens ---------- */
@media (max-width: 760px) {
  #hud { grid-template-columns: 1fr auto; top: 8px; left: 8px; right: 8px; }
  .brand { display: none; }
  .prompt-card { min-width: 0; padding: 8px 14px 10px; justify-self: stretch; }
  .prompt-city { font-size: 20px; }
  #target-country { font-size: 15px; }
  .stats { gap: 10px; padding: 6px 8px 6px 10px; }
  #action-bar { bottom: 12px; left: 8px; right: 60px; transform: none; padding: 8px 8px 8px 12px; white-space: normal; }
  #action-bar .primary { margin-left: auto; }
  .hint { font-size: 13px; }
  #zoom-controls { right: 8px; bottom: 12px; }
}
