:root {
  --bg: #eaf4fb;
  --bg-2: #d7ebf8;
  --card: #ffffff;
  --ink: #15324a;
  --ink-soft: #4c6a82;
  --line: #c9dbe8;
  --brand: #2f7dd1;
  --brand-ink: #ffffff;
  --brand-dark: #1f5fa6;
  --sea: #bfe0f5;
  --land: #f3ead2;
  --land-stroke: #b9a985;
  --context: #e4e0d6;
  --target: #ff8a1f;
  --target-glow: rgba(255, 138, 31, 0.45);
  --good: #2fb36b;
  --good-soft: #d9f5e5;
  --bad: #e4483d;
  --bad-soft: #fde1de;
  --radius: 14px;
  --shadow: 0 6px 20px rgba(21, 50, 74, 0.12);
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0e1b26;
    --bg-2: #132636;
    --card: #182c3d;
    --ink: #e6f0f7;
    --ink-soft: #9fb6c7;
    --line: #2b465c;
    --brand: #4c9be8;
    --brand-dark: #77b4f0;
    --sea: #12324a;
    --land: #5b5442;
    --land-stroke: #8a8068;
    --context: #2b3438;
    --good-soft: #163a28;
    --bad-soft: #3e1d1b;
    --shadow: 0 6px 20px rgba(0, 0, 0, 0.35);
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: linear-gradient(180deg, var(--bg) 0%, var(--bg-2) 100%) fixed;
  color: var(--ink);
  font: 16px/1.45 ui-rounded, "SF Pro Rounded", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  min-height: 100vh;
}
[hidden] { display: none !important; }

#app {
  max-width: 1000px;
  margin: 0 auto;
  padding: 16px;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}
.screen { flex: 1; }

/* Start */
.hero { text-align: center; margin: 12px 0 18px; }
.hero h1 { font-size: clamp(2rem, 7vw, 3.2rem); margin: 0; letter-spacing: -0.02em; }
.hero h1 span { color: var(--brand); }
.tagline { color: var(--ink-soft); margin: 6px 0 0; }

.card {
  background: var(--card);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 20px;
}
.setup { max-width: 640px; margin: 0 auto; display: grid; gap: 18px; }

.field { display: grid; gap: 8px; border: 0; margin: 0; padding: 0; min-width: 0; }
.field-label { font-weight: 700; font-size: 0.95rem; padding: 0; }
input[type="text"], input[type="number"] {
  font: inherit;
  padding: 12px 14px;
  border: 2px solid var(--line);
  border-radius: 10px;
  background: var(--card);
  color: var(--ink);
  width: 100%;
}
input:focus-visible, button:focus-visible { outline: 3px solid var(--brand); outline-offset: 2px; }

.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip {
  font: inherit;
  border: 2px solid var(--line);
  background: var(--card);
  color: var(--ink);
  border-radius: 999px;
  padding: 8px 14px;
  cursor: pointer;
}
.chip[aria-checked="true"], .chip[aria-selected="true"] {
  background: var(--brand);
  border-color: var(--brand);
  color: var(--brand-ink);
}
.chip .count { opacity: 0.7; font-size: 0.85em; margin-left: 4px; }

.btn {
  font: inherit;
  font-weight: 700;
  border-radius: 12px;
  border: 2px solid transparent;
  padding: 10px 18px;
  cursor: pointer;
}
.btn-primary { background: var(--brand); color: var(--brand-ink); }
.btn-primary:hover { background: var(--brand-dark); }
.btn-ghost { background: transparent; color: var(--ink); border-color: var(--line); }
.btn-ghost:hover { border-color: var(--brand); }
.btn-big { font-size: 1.25rem; padding: 14px; }
.btn-small { padding: 6px 12px; font-size: 0.9rem; }
.row-buttons { display: flex; gap: 10px; justify-content: center; flex-wrap: wrap; }
.form-error { color: var(--bad); margin: -8px 0 0; min-height: 1.2em; text-align: center; }
.best-line { margin: 0; text-align: center; color: var(--ink-soft); min-height: 1.4em; }

/* Game */
.hud {
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--card);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 8px 12px;
}
.hud-item { flex: 1; text-align: center; min-width: 0; }
.hud-label { display: block; font-size: 0.72rem; text-transform: uppercase; letter-spacing: 0.06em; color: var(--ink-soft); }
.hud-value { font-size: 1.3rem; font-weight: 800; font-variant-numeric: tabular-nums; }
.hud-value.hot { color: var(--target); }

.qbar { height: 8px; background: var(--line); border-radius: 99px; margin: 10px 2px; overflow: hidden; }
.qbar-fill { height: 100%; width: 100%; background: var(--good); border-radius: 99px; transform-origin: left; }
.qbar-fill.warn { background: var(--target); }
.qbar-fill.danger { background: var(--bad); }

.map-wrap {
  position: relative;
  background: var(--sea);
  border-radius: var(--radius);
  overflow: hidden;
  box-shadow: var(--shadow);
}
#map { display: block; width: 100%; height: auto; max-height: 56vh; }
#map .country { fill: var(--land); stroke: var(--land-stroke); stroke-width: 0.5; vector-effect: non-scaling-stroke; transition: fill 0.25s; }
#map .country.context { fill: var(--context); }
#map .country.done { fill: var(--good); }
#map .country.target { fill: var(--target); animation: pulse 0.9s ease-in-out infinite alternate; }
#map .country.missed { fill: var(--bad); }
#map .locator { fill: none; stroke: var(--target); stroke-width: 3.5; animation: ring 0.8s ease-in-out infinite alternate; transform-box: fill-box; transform-origin: center; }
#map .locator-dot { fill: var(--target); stroke: #fff; stroke-width: 1.5; }
#map .locator-dot.done { fill: var(--good); }
#map .locator-dot.missed { fill: var(--bad); }
@keyframes pulse { from { opacity: 1; } to { opacity: 0.6; } }
@keyframes ring { from { transform: scale(0.6); opacity: 1; } to { transform: scale(1.25); opacity: 0.45; } }

.feedback {
  position: absolute;
  left: 50%;
  bottom: 12px;
  transform: translateX(-50%);
  background: var(--card);
  color: var(--ink);
  border-radius: 999px;
  padding: 6px 16px;
  font-weight: 700;
  box-shadow: var(--shadow);
  opacity: 0;
  transition: opacity 0.15s;
  white-space: nowrap;
  max-width: calc(100% - 24px);
  overflow: hidden;
  text-overflow: ellipsis;
}
.feedback.show { opacity: 1; }
.feedback.good { color: var(--good); }
.feedback.bad { color: var(--bad); }

.prompt { text-align: center; font-weight: 700; font-size: 1.1rem; margin: 14px 0 10px; }
.options { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.option {
  font: inherit;
  font-weight: 700;
  font-size: 1.05rem;
  min-height: 60px;
  padding: 10px;
  border-radius: 12px;
  border: 2px solid var(--line);
  background: var(--card);
  color: var(--ink);
  cursor: pointer;
  box-shadow: var(--shadow);
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  text-align: center;
}
.option:hover:not(:disabled) { border-color: var(--brand); }
.option:disabled { cursor: default; }
.option .key { font-size: 0.75rem; color: var(--ink-soft); border: 1px solid var(--line); border-radius: 6px; padding: 0 6px; }
.option.right { background: var(--good-soft); border-color: var(--good); }
.option.wrong { background: var(--bad-soft); border-color: var(--bad); }
.option.flag { padding: 8px; }
.option.flag .flag-box { height: clamp(44px, 10vh, 96px); aspect-ratio: 4 / 3; max-width: 34vw; display: flex; }
.option.flag img { width: 100%; height: 100%; object-fit: contain; border-radius: 4px; box-shadow: 0 0 0 1px rgba(0,0,0,0.15); }

/* End */
.end-card { max-width: 520px; margin: 40px auto; text-align: center; }
.end-card h2 { margin: 0 0 6px; font-size: 2rem; }
.end-score { font-size: 4rem; font-weight: 800; margin: 0; color: var(--brand); line-height: 1.1; }
.end-score small { font-size: 1.6rem; color: var(--ink-soft); }
.end-detail { color: var(--ink-soft); }
.end-best { font-weight: 700; color: var(--good); min-height: 1.4em; }

/* Dialogs */
dialog {
  border: 0;
  border-radius: var(--radius);
  padding: 0;
  background: var(--card);
  color: var(--ink);
  box-shadow: var(--shadow);
  width: min(560px, calc(100vw - 32px));
}
dialog::backdrop { background: rgba(10, 25, 40, 0.5); }
.dlg-body { padding: 20px; display: grid; gap: 14px; }
.dlg-body h2 { margin: 0; }
.check { display: flex; gap: 10px; align-items: center; }
.check input { width: 20px; height: 20px; }
.hint { color: var(--ink-soft); font-size: 0.9rem; margin: 0; }
.scores { width: 100%; border-collapse: collapse; font-variant-numeric: tabular-nums; }
.scores th, .scores td { text-align: left; padding: 6px 8px; border-bottom: 1px solid var(--line); }
.scores td:first-child, .scores th:first-child { width: 2em; color: var(--ink-soft); }
.scores tr.me td { font-weight: 700; }
.credits { margin: 0; padding-left: 20px; display: grid; gap: 6px; }
.credits a { color: var(--brand); }

.site-footer { margin-top: 20px; text-align: center; color: var(--ink-soft); font-size: 0.85rem; display: flex; gap: 14px; justify-content: center; flex-wrap: wrap; }
.link-button { font: inherit; background: none; border: 0; color: var(--brand); cursor: pointer; padding: 0; text-decoration: underline; }

/* Celebration */
.confetti { position: fixed; top: -12px; width: 10px; height: 14px; pointer-events: none; z-index: 50; animation: fall linear forwards; }
@keyframes fall { to { transform: translateY(105vh) rotate(720deg); } }

@media (max-width: 560px) {
  #app { padding: 12px; }
  .option { min-height: 54px; font-size: 0.95rem; }
  .option .key { display: none; }
  .hud-value { font-size: 1.1rem; }
  #map { max-height: 44vh; }
}

@media (prefers-reduced-motion: reduce) {
  #map .country.target, #map .locator { animation: none; }
  .confetti { display: none; }
}
