:root {
  --bg: #0f1620;
  --panel: #1a2533;
  --panel-light: #233044;
  --accent: #4fd1c5;
  --accent-dark: #2ca39a;
  --text: #eef3f8;
  --text-dim: #9fb0c2;
  --correct: #4ade80;
  --incorrect: #f87171;
  --land: #3a4a5e;
  --land-stroke: #1a2533;
  --ocean: #101820;
  --you: #c084fc;
  --dot: #ef4444;
  --gold: #facc15;
  --silver: #cbd5e1;
  --bronze: #d97706;

  --diff-1: #4ade80;
  --diff-2: #facc15;
  --diff-3: #fb923c;
  --diff-4: #f87171;
}


* { box-sizing: border-box; }

html, body {
  margin: 0; padding: 0;
  height: 100%;
  font-family: 'Segoe UI', system-ui, -apple-system, sans-serif;
  background: var(--bg);
  color: var(--text);
}

#app {
  max-width: 1000px;
  margin: 0 auto;
  padding: 20px;
  min-height: 100vh;
}

.screen { display: none; }
.screen.active { display: block; }
.hidden { display: none !important; }

h1 {
  text-align: center;
  font-size: 2.2rem;
  margin-bottom: 4px;
  letter-spacing: 1px;
}

.subtitle {
  text-align: center;
  color: var(--text-dim);
  margin-top: 0;
  margin-bottom: 28px;
}

/* ---- Setup ---- */
.setup-group { margin-bottom: 24px; }

.setup-group h2 {
  font-size: 1.05rem;
  color: var(--text-dim);
  text-transform: uppercase;
  letter-spacing: 1.5px;
  margin-bottom: 10px;
  font-weight: 600;
}

.setup-group h2 .hint {
  text-transform: none;
  letter-spacing: normal;
  font-weight: 400;
  font-size: 0.85rem;
  opacity: 0.8;
}

.options-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 12px;
}

.option-btn {
  background: var(--panel);
  border: 2px solid transparent;
  border-radius: 10px;
  padding: 14px 16px;
  text-align: left;
  cursor: pointer;
  color: var(--text);
  display: flex;
  flex-direction: column;
  gap: 4px;
  transition: border-color 0.15s, background 0.15s, transform 0.1s;
}

.option-btn:hover { background: var(--panel-light); transform: translateY(-1px); }
.option-btn.selected { border-color: var(--accent); background: var(--panel-light); }

#difficulty-options .option-btn[data-difficulty="1"] { border-color: color-mix(in srgb, var(--diff-1) 35%, transparent); }
#difficulty-options .option-btn[data-difficulty="2"] { border-color: color-mix(in srgb, var(--diff-2) 35%, transparent); }
#difficulty-options .option-btn[data-difficulty="3"] { border-color: color-mix(in srgb, var(--diff-3) 35%, transparent); }
#difficulty-options .option-btn[data-difficulty="4"] { border-color: color-mix(in srgb, var(--diff-4) 35%, transparent); }
#difficulty-options .option-btn[data-difficulty="1"].selected { border-color: var(--diff-1); box-shadow: 0 0 0 1px var(--diff-1) inset; }
#difficulty-options .option-btn[data-difficulty="2"].selected { border-color: var(--diff-2); box-shadow: 0 0 0 1px var(--diff-2) inset; }
#difficulty-options .option-btn[data-difficulty="3"].selected { border-color: var(--diff-3); box-shadow: 0 0 0 1px var(--diff-3) inset; }
#difficulty-options .option-btn[data-difficulty="4"].selected { border-color: var(--diff-4); box-shadow: 0 0 0 1px var(--diff-4) inset; }

.opt-title { font-weight: 700; font-size: 1.05rem; }
.opt-desc { font-size: 0.82rem; color: var(--text-dim); }

.primary-btn {
  display: block;
  width: 100%;
  margin-top: 8px;
  padding: 14px;
  font-size: 1.1rem;
  font-weight: 700;
  border: none;
  border-radius: 10px;
  background: var(--accent);
  color: #06231f;
  cursor: pointer;
  transition: background 0.15s, opacity 0.15s;
}
.primary-btn:hover:not(:disabled) { background: var(--accent-dark); }
.primary-btn:disabled { opacity: 0.4; cursor: not-allowed; }

.back-link { text-align: center; margin-top: 16px; font-size: 0.9rem; }
.back-link a { color: var(--text-dim); text-decoration: none; }
.back-link a:hover { color: var(--accent); }

.how-to {
  border: 1px solid var(--panel-light);
  border-radius: 8px;
  margin: 20px auto 0;
  background: var(--panel);
  max-width: 520px;
  width: 100%;
  text-align: left;
}

.how-to-summary {
  display: block;
  padding: 10px 14px;
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--text-dim);
  text-transform: uppercase;
  letter-spacing: 1px;
  cursor: pointer;
  list-style: none;
  user-select: none;
}
.how-to-summary::-webkit-details-marker { display: none; }
.how-to-summary::before {
  content: "\25B8";
  display: inline-block;
  margin-right: 8px;
  transition: transform 0.2s;
}
details.how-to[open] > .how-to-summary::before { transform: rotate(90deg); }
.how-to-summary:hover { color: var(--text); }

.how-to-body { padding: 0 16px 12px; }
.how-to-body p {
  font-size: 0.9rem;
  color: var(--text-dim);
  line-height: 1.55;
  margin: 0 0 10px;
}
.how-to-body p:last-child { margin-bottom: 0; }
.how-to-body strong { color: var(--text); }

.text-btn {
  background: none; border: none;
  color: var(--text-dim); cursor: pointer;
  font-size: 0.95rem; text-decoration: underline;
}
.text-btn:hover { color: var(--text); }

/* ---- Game header ---- */
.game-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  margin-bottom: 8px;
}

.hud {
  display: flex;
  gap: 18px;
  font-weight: 600;
  color: var(--text-dim);
}

#score-counter { color: var(--accent); }

.prompt {
  text-align: center;
  margin-bottom: 8px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
}

.prompt-label {
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 2px;
  text-transform: uppercase;
  color: var(--text-dim);
}

.prompt-text { font-size: 1.15rem; font-weight: 700; }


/* ---- Map ---- */
.map-wrap {
  position: relative;
  width: 100%;
  height: min(560px, calc(100vh - 250px));
  min-height: 300px;
  border-radius: 12px;
  overflow: hidden;
  background: var(--ocean);
  box-shadow: 0 0 0 2px var(--panel-light), 0 10px 40px rgba(0, 0, 0, 0.5);
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
  cursor: grab;
}
.map-wrap:active { cursor: grabbing; }

#map-svg { position: absolute; inset: 0; width: 100%; height: 100%; display: block; }
#label-svg { position: absolute; inset: 0; width: 100%; height: 100%; display: block; pointer-events: none; }


.sphere { fill: var(--ocean); stroke: #2a3a4e; stroke-width: 1; }
.land { fill: var(--land); stroke: #5b6f86; stroke-width: 0.7; stroke-linejoin: round; }
.borders { fill: none; stroke: var(--land-stroke); stroke-width: 1; stroke-linejoin: round; }

.labels text {
  fill: var(--text-dim);
  font-weight: 600;
  text-anchor: middle;
  dominant-baseline: central;
  paint-order: stroke;
  stroke: rgba(10, 16, 24, 0.85);
  stroke-width: 3px;
  stroke-linejoin: round;
  pointer-events: none;
}

.zoom-btns {
  position: absolute; top: 10px; right: 10px;
  display: flex; flex-direction: column; gap: 6px;
}
.zoom-btns button {
  width: 34px; height: 34px;
  border-radius: 8px;
  border: 1px solid var(--panel-light);
  background: rgba(26, 37, 51, 0.9);
  color: var(--text);
  font-size: 1.2rem; line-height: 1;
  cursor: pointer;
}
.zoom-btns button:hover { border-color: var(--accent); }

.ahead-btn {
  position: absolute; right: 10px; bottom: 10px;
  padding: 7px 14px;
  border-radius: 999px;
  border: 1px solid var(--accent);
  background: rgba(26, 37, 51, 0.92);
  color: var(--accent);
  font-size: 0.85rem; font-weight: 700;
  cursor: pointer;
}
.ahead-btn:hover { background: var(--accent); color: #06231f; }

.scale-bar {
  position: absolute; left: 12px; bottom: 10px;
  display: flex; flex-direction: column; gap: 3px;
  font-size: 0.75rem; color: var(--text-dim);
  pointer-events: none;
}
.scale-line { height: 6px; border: 2px solid var(--text-dim); border-top: none; }

/* ---- Answer ---- */
.answer-form {
  display: flex;
  gap: 8px;
  margin: 14px auto 0;
  max-width: 640px;
}
.combo { position: relative; flex: 1; min-width: 0; margin-top: 8px; display: flex; }
.answer-form input {
  flex: 1; min-width: 0;
  padding: 12px 14px;
  font-size: 1.05rem;
  border-radius: 10px;
  border: 2px solid var(--panel-light);
  background: var(--panel);
  color: var(--text);
  outline: none;
}
.answer-form input:focus { border-color: var(--accent); }

/* Opens upward, over the map, so it never runs off the bottom of the screen. */
.suggestions {
  position: absolute;
  left: 0; right: 0; bottom: calc(100% + 6px);
  margin: 0; padding: 4px;
  list-style: none;
  background: var(--panel);
  border: 1px solid var(--panel-light);
  border-radius: 10px;
  box-shadow: 0 -8px 24px rgba(0, 0, 0, 0.45);
  z-index: 20;
}
.suggestions li {
  padding: 8px 12px;
  border-radius: 7px;
  cursor: pointer;
}
.suggestions li:hover, .suggestions li.active { background: var(--panel-light); color: var(--accent); }
.answer-form .primary-btn { width: auto; padding: 12px 22px; }
.answer-form.shake { animation: shake 0.35s; }
@keyframes shake {
  25% { transform: translateX(-6px); }
  75% { transform: translateX(6px); }
}

.ghost-btn {
  margin-top: 8px;
  background: var(--panel);
  border: 1px solid var(--panel-light);
  border-radius: 10px;
  color: var(--text-dim);
  cursor: pointer;
  padding: 0 14px;
  white-space: nowrap;
}
.ghost-btn:hover { color: var(--text); border-color: var(--incorrect); }

.answer-error {
  text-align: center;
  min-height: 1.3em;
  margin-top: 6px;
  color: var(--incorrect);
  font-size: 0.9rem;
}

/* ---- Result ---- */
.result-detail {
  max-width: 640px;
  margin: 6px auto 0;
  background: var(--panel);
  border-radius: 10px;
  padding: 14px 16px;
}
.result-headline { font-size: 1.25rem; font-weight: 800; margin-bottom: 6px; }
.result-headline.great { color: var(--correct); }
.result-headline.good  { color: #facc15; }
.result-headline.okay  { color: #fb923c; }
.result-headline.miss  { color: var(--incorrect); }

.result-facts {
  list-style: none;
  padding: 0; margin: 0 0 6px;
  color: var(--text-dim);
  font-size: 0.95rem;
  line-height: 1.7;
}
.result-facts strong { color: var(--text); }
.result-facts .badge {
  display: inline-block;
  min-width: 22px;
  padding: 0 6px;
  margin-right: 6px;
  border-radius: 999px;
  text-align: center;
  font-size: 0.78rem;
  font-weight: 800;
  color: #0f1620;
}
.result-facts .bok { background: var(--correct); }
.result-facts .bmiss { background: var(--incorrect); }
.result-facts .ord { color: var(--text-dim); font-size: 0.85rem; }
.result-facts .km { font-size: 0.85rem; }
.result-facts li.missed strong { color: var(--incorrect); }
.result-facts { columns: 2; column-gap: 24px; }
.result-facts li { break-inside: avoid; }

/* ---- Results screen ---- */
.final-score {
  text-align: center;
  font-size: 2rem;
  color: var(--accent);
  font-weight: 800;
  margin-bottom: 4px;
}
.final-avg { text-align: center; color: var(--text-dim); margin-top: 0; margin-bottom: 20px; }

.results-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin: 0 auto 20px;
  max-width: 640px;
}
.result-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
  background: var(--panel);
  border-radius: 8px;
  padding: 10px 14px;
}
.result-row .name-col { font-weight: 600; }
.result-row .diff-dot {
  display: inline-block;
  width: 8px; height: 8px;
  border-radius: 50%;
  margin-right: 8px;
  vertical-align: middle;
}
.result-row .dist-col { color: var(--text-dim); font-size: 0.88rem; margin-left: auto; text-align: right; }
.result-row .pts-col  { color: var(--accent); font-weight: 700; min-width: 56px; text-align: right; }

.results-actions {
  display: flex;
  gap: 12px;
  justify-content: center;
  max-width: 640px;
  margin: 0 auto;
}

/* ---- Loading ---- */
#loading-overlay {
  position: fixed; inset: 0;
  background: var(--bg);
  display: flex; flex-direction: column;
  align-items: center; justify-content: center;
  gap: 16px; color: var(--text-dim); z-index: 100;
}
#loading-overlay.hidden { display: none; }

.spinner {
  width: 40px; height: 40px;
  border: 4px solid var(--panel-light);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ---- Cross Country ---- */
/* The map group is scaled on zoom; keep line widths in screen pixels. */
.map path { vector-effect: non-scaling-stroke; }
.prompt-text .city-a, .prompt-text .city-b { color: var(--text); }
.prompt-text .arrow { color: var(--accent); margin: 0 6px; }

.fills path { fill-opacity: 0.32; stroke-width: 1; stroke-opacity: 0.8; }
.fills path.missed { fill: var(--incorrect); stroke: var(--incorrect); fill-opacity: 0.22; }

.route { fill: none; stroke: #ffffff; stroke-width: 2.5; stroke-dasharray: 7 5; stroke-linecap: round; opacity: 0.9; }
.lit { fill: none; stroke: #ffffff; stroke-width: 3; stroke-linecap: round; opacity: 0.95; }
.segs path { fill: none; stroke-width: 5; stroke-linecap: butt; }
.segs path.missed { stroke: var(--incorrect); }

.names text {
  font-size: 12.5px; font-weight: 700;
  text-anchor: middle; dominant-baseline: central;
  paint-order: stroke; stroke: rgba(10, 16, 24, 0.9); stroke-width: 3px; stroke-linejoin: round;
  pointer-events: none;
}
.names line { stroke-width: 1; opacity: 0.7; }
.names g.missed text { fill: var(--incorrect); }
.names g.missed line { stroke: var(--incorrect); }

.cities circle { fill: #fff; stroke: #0f1620; stroke-width: 2; }
.cities g.start circle { fill: var(--accent); }
.cities text {
  fill: #fff; font-size: 14px; font-weight: 800; dominant-baseline: central;
  paint-order: stroke; stroke: rgba(10, 16, 24, 0.95); stroke-width: 4px; stroke-linejoin: round;
  pointer-events: none;
}

.progress {
  display: flex; flex-wrap: wrap; align-items: center; justify-content: center;
  gap: 6px; margin: 12px auto 0; max-width: 760px;
}
.progress .count { font-weight: 800; color: var(--accent); margin-right: 6px; }
.progress .sep { color: var(--text-dim); }
.slot {
  min-width: 34px; padding: 3px 10px;
  border-radius: 999px; text-align: center;
  font-size: 0.85rem; font-weight: 700;
  background: var(--panel); color: var(--text-dim);
  border: 1px dashed var(--panel-light);
}
.slot.next { border: 1px solid var(--accent); color: var(--accent); }
.slot.found {
  color: var(--c); border: 1px solid var(--c);
  background: color-mix(in srgb, var(--c) 14%, var(--panel));
}
.slot.missed { color: var(--incorrect); border: 1px solid color-mix(in srgb, var(--incorrect) 50%, transparent); }

.progress .strikes { margin-left: 10px; letter-spacing: 3px; font-weight: 800; color: var(--panel-light); }
.progress .strikes .hit { color: var(--incorrect); }

.answer-error.soft { color: var(--gold); }
.wrong-list { display: flex; flex-wrap: wrap; justify-content: center; gap: 6px; }
.wrong-chip {
  font-size: 0.8rem; padding: 2px 9px; border-radius: 999px;
  color: var(--incorrect); background: color-mix(in srgb, var(--incorrect) 12%, var(--panel));
}

@media (max-width: 600px) {
  .result-facts { columns: 1; }
  #app { padding: 16px; }
  h1 { font-size: 1.7rem; }
  .options-grid { grid-template-columns: 1fr; }
  .map-wrap { height: min(460px, calc(100vh - 280px)); }
  .answer-form { flex-wrap: wrap; }
  .combo { flex-basis: 100%; }
  .answer-form .primary-btn { flex: 1; }
  .ghost-btn { padding: 12px 14px; }
  .result-row { flex-wrap: wrap; }
}

.zoom-btns, .ahead-btn { z-index: 2; }
