:root {
  --ink: #1d2a30;
  --muted: #5d6b72;
  --brand: #1f4e5f;
  --accent: #2f7f9b;
  --paper: #f7f4ec;
  --card: #ffffff;
  --ocean: #d6e8f0;
  --land: #fbf8f1;
  --border: #6f7a7e;
  --other: #e7e3d9;
  --named: #46a86d;
  --selected: #f2b134;
  --missed: #f3cfc7;
  --wrong: #c8433a;
  --radius: 14px;
  --shadow: 0 6px 24px rgba(20, 40, 50, 0.16);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  color: var(--ink);
  -webkit-text-size-adjust: 100%;
}

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

html, body { margin: 0; height: 100%; }
body { background: var(--paper); }
body.playing { overflow: hidden; overscroll-behavior: none; }

button { font: inherit; cursor: pointer; border: 0; border-radius: 10px; }
button:disabled { opacity: 0.5; cursor: default; }
.primary { background: var(--accent); color: #fff; padding: 10px 18px; font-weight: 600; }
.primary:hover:not(:disabled) { background: var(--brand); }
.primary.big { font-size: 1.2rem; padding: 14px 40px; }
.secondary { background: #e9eef0; color: var(--ink); padding: 10px 18px; font-weight: 600; }
.icon-btn { background: transparent; color: inherit; font-size: 1.3rem; width: 40px; height: 40px; }
.text-btn { background: rgba(255, 255, 255, 0.16); color: #fff; padding: 6px 14px; font-weight: 600; }

/* ---------- Home ---------- */
.home { max-width: 860px; margin: 0 auto; padding: 32px 16px 24px; }
.brand h1 { margin: 0; font-size: clamp(2.4rem, 8vw, 3.6rem); color: var(--brand); letter-spacing: -0.02em; }
.brand h1 span { color: var(--accent); }
.brand p { margin: 6px 0 28px; color: var(--muted); font-size: 1.1rem; }
.game-list { display: grid; gap: 16px; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); }
.game-card {
  display: flex; flex-direction: column; gap: 6px; padding: 20px; min-height: 170px;
  background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow);
  color: inherit; text-decoration: none; transition: transform 0.12s;
}
a.game-card:hover { transform: translateY(-2px); }
.game-card h2 { margin: 0; font-size: 1.3rem; }
.game-card p { margin: 0; color: var(--muted); flex: 1; }
.card-foot { align-self: flex-start; background: var(--accent); color: #fff; padding: 6px 16px; border-radius: 999px; font-weight: 600; }
.card-best { color: var(--muted); font-size: 0.9rem; }
.game-card.soon { opacity: 0.6; }
.game-card.soon .card-foot { background: #b9c2c6; }
.credits { margin-top: 36px; color: var(--muted); font-size: 0.85rem; }
.credits a { color: inherit; }

/* ---------- Play screen ---------- */
.play { position: fixed; inset: 0; display: flex; flex-direction: column; background: var(--ocean); }
.topbar {
  display: flex; align-items: center; gap: 12px; padding: 6px 10px;
  padding-top: max(6px, env(safe-area-inset-top));
  background: var(--brand); color: #fff; z-index: 3;
}
.stat { font-size: 1.25rem; font-weight: 700; font-variant-numeric: tabular-nums; }
.stat small { font-weight: 400; opacity: 0.75; font-size: 0.9rem; }
.timer { margin-left: auto; }
.timer.low { color: #ffcf7a; animation: pulse 1s infinite; }
@keyframes pulse { 50% { opacity: 0.55; } }

.answer {
  position: absolute; top: calc(52px + env(safe-area-inset-top)); left: 50%; transform: translateX(-50%);
  width: min(520px, calc(100% - 24px)); display: flex; gap: 6px; padding: 6px;
  background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow); z-index: 4;
}
.answer input {
  flex: 1; min-width: 0; font-size: 17px; padding: 10px 12px;
  border: 2px solid #cfd8dc; border-radius: 10px; outline: none;
}
.answer input:focus { border-color: var(--accent); }
.answer input.wrong { border-color: var(--wrong); animation: shake 0.35s; }
@keyframes shake { 20%, 60% { transform: translateX(-6px); } 40%, 80% { transform: translateX(6px); } }

.toast {
  position: absolute; top: calc(118px + env(safe-area-inset-top)); left: 50%; transform: translateX(-50%);
  padding: 8px 16px; border-radius: 999px; font-weight: 600; z-index: 4; pointer-events: none;
  background: var(--ink); color: #fff; box-shadow: var(--shadow); white-space: nowrap;
}
.toast.good { background: var(--named); }

.map { position: relative; flex: 1; overflow: hidden; }
.world { display: block; width: 100%; height: 100%; touch-action: none; user-select: none; -webkit-user-select: none; }
.world path { vector-effect: non-scaling-stroke; }
.sphere { fill: var(--ocean); stroke: #b9d3de; stroke-width: 1; }
.other { fill: var(--other); stroke: #b8b2a5; stroke-width: 0.5; pointer-events: none; }
.country { cursor: pointer; }
path.country { fill: var(--land); stroke: var(--border); stroke-width: 0.6; stroke-linejoin: round; }
@media (hover: hover) { path.country:hover { fill: #efe7d3; } }
.marker .hit { fill: transparent; }
.marker .dot { fill: var(--land); stroke: var(--border); stroke-width: 1.2; vector-effect: non-scaling-stroke; }
path.country.named, .marker.named .dot { fill: var(--named); }
path.country.selected, .marker.selected .dot { fill: var(--selected); }
path.country.missed, .marker.missed .dot { fill: var(--missed); }

.zoom-controls {
  position: absolute; right: 12px; bottom: max(16px, env(safe-area-inset-bottom)); z-index: 2;
  display: flex; flex-direction: column; gap: 6px;
}
.zoom-controls button {
  width: 44px; height: 44px; font-size: 1.4rem; background: var(--card); color: var(--ink); box-shadow: var(--shadow);
}

/* ---------- Overlays (start card and results) ---------- */
.overlay {
  position: absolute; inset: 0; z-index: 5; display: grid; place-items: center; padding: 16px;
  background: rgba(20, 40, 50, 0.35); overflow-y: auto;
}
.card {
  background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow);
  padding: 24px; width: min(420px, 100%); text-align: center;
}
.card h2 { margin: 0 0 12px; color: var(--brand); }
.howto { text-align: left; margin: 0 auto 12px; padding-left: 22px; line-height: 1.6; max-width: 300px; }
.hint { color: var(--muted); font-size: 0.9rem; margin: 0 0 18px; }
.results { text-align: left; max-height: calc(100% - 8px); overflow-y: auto; }
.results h2 { text-align: center; }
.big-score { text-align: center; margin: 0; }
.big-score span { font-size: 3rem; font-weight: 800; color: var(--accent); }
.big-score small { color: var(--muted); }
.note { text-align: center; color: var(--muted); min-height: 1.2em; }
.name-form { display: grid; gap: 10px; margin-bottom: 8px; }
.name-form input { font-size: 17px; padding: 10px 12px; border: 2px solid #cfd8dc; border-radius: 10px; }
.turnstile { min-height: 65px; display: flex; justify-content: center; }
.error { color: var(--wrong); margin: 0; min-height: 1em; font-size: 0.9rem; }
.results h3 { margin: 16px 0 6px; }
.board { list-style: none; padding: 0; margin: 0; }
.board li { display: flex; gap: 10px; padding: 7px 10px; border-radius: 8px; }
.board li:nth-child(odd) { background: #f3f6f7; }
.board li.me { background: #fff1cf; font-weight: 700; }
.board li.empty { color: var(--muted); justify-content: center; }
.board .rank { width: 1.6em; color: var(--muted); text-align: right; }
.board .who { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.board .pts { font-weight: 700; font-variant-numeric: tabular-nums; }
.actions { display: flex; gap: 10px; margin-top: 18px; }
.actions button { flex: 1; }
