:root {
  --bg: #0f1620;
  --panel: #1a2533;
  --panel-light: #233044;
  --accent: #4fd1c5;
  --accent-dark: #2ca39a;
  --text: #eef3f8;
  --text-dim: #9fb0c2;
  --muted: #7c8da0;
  --correct: #4ade80;
  --incorrect: #f87171;
  --highlight: #f6ad55;
  --ocean: #101820;

  /* Land outside the region is context; land inside is the playing field. */
  --land-context: #1a222d;
  --land: #3c4d61;
  --land-lit: #8be7db;      /* land the circles have claimed */
  --claim: #4fd1c5;         /* the circles themselves */
}

* { 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: 1040px;
  margin: 0 auto;
  padding: 20px;
  min-height: 100vh;
}

.screen { display: none; }
.screen.active { display: block; }

h1 {
  text-align: center;
  font-size: 2.2rem;
  margin-bottom: 4px;
  letter-spacing: 1px;
}

.subtitle {
  text-align: center;
  color: var(--text-dim);
  margin: 0 auto 28px;
  max-width: 640px;
  line-height: 1.5;
}

/* ---------- 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(3, 1fr);
  gap: 12px;
}
.options-grid.four { grid-template-columns: repeat(4, 1fr); }
.options-grid.three { grid-template-columns: repeat(3, 1fr); }
.options-grid.two { grid-template-columns: repeat(2, 1fr); }

.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);
}

.opt-title { font-weight: 700; font-size: 1.05rem; }
.opt-desc { font-size: 0.82rem; color: var(--text-dim); line-height: 1.35; }

.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; }
.primary-btn.hidden { display: none; }

.primary-btn.compact {
  width: auto;
  margin: 0;
  padding: 12px 26px;
  font-size: 1rem;
  flex-shrink: 0;
}

.button-row {
  display: flex;
  gap: 12px;
  justify-content: center;
  flex-wrap: wrap;
}
.button-row .primary-btn { width: auto; padding: 14px 30px; }

.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); }

.text-btn {
  background: none;
  border: none;
  color: var(--text-dim);
  cursor: pointer;
  font-size: 0.9rem;
  padding: 4px 6px;
}
.text-btn:hover { color: var(--text); }

/* ---------- How it works ---------- */

.filter-dropdown {
  border: 1px solid var(--panel-light);
  border-radius: 8px;
  margin-top: 20px;
  background: var(--panel);
}

.filter-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;
}
.filter-summary::-webkit-details-marker { display: none; }
.filter-summary::before {
  content: "\25B8";
  display: inline-block;
  margin-right: 8px;
  transition: transform 0.2s;
}
details.filter-dropdown[open] > .filter-summary::before { transform: rotate(90deg); }
.filter-summary:hover { color: var(--text); }

.filter-body { padding: 0 16px 12px; }
.filter-body p {
  font-size: 0.9rem;
  color: var(--text-dim);
  line-height: 1.55;
  margin: 0 0 10px;
}
.filter-body p.src-note { font-size: 0.78rem; opacity: 0.7; margin-bottom: 0; }
.filter-body strong { color: var(--text); }

/* ---------- Game header ---------- */

.game-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 8px;
}

.hud { display: flex; gap: 24px; }

.stat { display: flex; flex-direction: column; line-height: 1.15; }
.stat-val {
  font-size: 1.35rem;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}
#coverage-pct { color: var(--accent); }
.stat-lbl {
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 1px;
  color: var(--muted);
}

/* ---------- Progress ---------- */

.progress-wrap { margin-bottom: 10px; }

.progress-track {
  position: relative;
  height: 8px;
  border-radius: 4px;
  background: var(--panel);
  overflow: hidden;
}

.progress-fill {
  height: 100%;
  width: 0;
  background: linear-gradient(90deg, var(--accent-dark), var(--land-lit));
  transition: width 0.5s ease;
}

/* The ceiling notch: coverage if every city in the region were named. */
.progress-ceiling {
  position: absolute;
  top: -2px;
  bottom: -2px;
  width: 2px;
  background: var(--highlight);
  opacity: 0.85;
}

.progress-note {
  display: block;
  margin-top: 4px;
  font-size: 0.75rem;
  color: var(--muted);
}

/* ---------- Map ---------- */

.map-wrap {
  position: relative;
  background: var(--ocean);
  border-radius: 12px;
  overflow: hidden;
  border: 1px solid #233044;
}

#map-canvas {
  display: block;
  width: 100%;
  height: 60vh;
  min-height: 340px;
  max-height: 640px;
  touch-action: none;
  cursor: grab;
}
#map-canvas:active { cursor: grabbing; }

.map-controls {
  position: absolute;
  top: 10px;
  right: 10px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.map-btn {
  width: 30px;
  height: 30px;
  border-radius: 6px;
  background: rgba(26, 37, 51, 0.9);
  border: 1px solid var(--panel-light);
  color: var(--text-dim);
  font-size: 1rem;
  line-height: 1;
  cursor: pointer;
  transition: color 0.15s, border-color 0.15s;
}
.map-btn.wide { width: 30px; font-size: 0.7rem; font-weight: 700; }
.map-btn:hover { color: var(--accent); border-color: var(--accent); }

.map-tooltip {
  position: absolute;
  pointer-events: none;
  background: rgba(15, 22, 32, 0.95);
  border: 1px solid var(--panel-light);
  border-radius: 6px;
  padding: 5px 9px;
  font-size: 0.78rem;
  color: var(--text);
  white-space: nowrap;
  transform: translate(-50%, -140%);
  z-index: 5;
}
.map-tooltip.hidden { display: none; }
.map-tooltip .tt-sub { color: var(--text-dim); }

/* ---------- Satellite mode ----------
   The imagery, the fog over it and the colour revealed inside the circles are
   all painted onto the canvas by app.js; only the page furniture is styled
   here. */

.sat-credit {
  position: absolute;
  right: 8px;
  bottom: 6px;
  padding: 2px 7px;
  border-radius: 4px;
  background: rgba(0, 0, 0, 0.45);
  color: rgba(255, 255, 255, 0.72);
  font-size: 0.64rem;
  pointer-events: none;
}
.sat-credit.hidden { display: none; }

/* ---------- Population counter ---------- */

.pop-counter {
  position: absolute;
  left: 50%;
  bottom: 12px;
  transform: translateX(-50%);
  min-width: 230px;
  padding: 8px 16px 10px;
  border-radius: 12px;
  background: rgba(15, 22, 32, 0.92);
  border: 1px solid color-mix(in srgb, var(--highlight) 45%, transparent);
  text-align: center;
  pointer-events: none;
  transition: opacity 0.45s, transform 0.45s;
}
.pop-counter.hidden { opacity: 0; transform: translate(-50%, 8px); }

.pc-top {
  display: flex;
  justify-content: center;
  align-items: baseline;
  gap: 8px;
  white-space: nowrap;
}
.pc-name { font-weight: 700; font-size: 0.85rem; }
.pc-note { color: var(--muted); font-size: 0.72rem; }

.pc-num {
  font-size: 1.6rem;
  font-weight: 800;
  line-height: 1.2;
  color: var(--highlight);
  font-variant-numeric: tabular-nums;
}
.pop-counter.done .pc-num { color: var(--correct); }
.pop-counter.short .pc-num { color: var(--text-dim); }

.pc-bar {
  height: 4px;
  margin-top: 4px;
  border-radius: 2px;
  background: var(--panel-light);
  overflow: hidden;
}
.pc-fill { height: 100%; width: 0; background: var(--highlight); }
.pop-counter.done .pc-fill { background: var(--correct); }

.tile-warning {
  position: absolute;
  top: 10px;
  left: 50%;
  transform: translateX(-50%);
  padding: 6px 14px;
  border-radius: 20px;
  background: rgba(15, 22, 32, 0.92);
  border: 1px solid var(--incorrect);
  color: var(--incorrect);
  font-size: 0.8rem;
  pointer-events: none;
}
.tile-warning.hidden { display: none; }

/* ---------- Guess bar ---------- */

.guess-bar {
  display: flex;
  gap: 10px;
  margin-top: 12px;
  align-items: stretch;
}

.combo { position: relative; flex: 1; }

#city-input {
  width: 100%;
  padding: 12px 14px;
  font-size: 1rem;
  font-family: inherit;
  border-radius: 10px;
  border: 2px solid var(--panel-light);
  background: var(--panel);
  color: var(--text);
  outline: none;
  transition: border-color 0.15s;
}
#city-input::placeholder { color: var(--muted); }
#city-input:focus { border-color: var(--accent); }

/* Airdrop armed: the input is the thing that changes meaning, so it is the
   thing that changes colour. */
body.airdrop-armed #city-input { border-color: var(--highlight); }
body.airdrop-armed #city-input::placeholder { color: #b98b4a; }

.suggest {
  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;
  max-height: 260px;
  overflow-y: auto;
  z-index: 20;
  box-shadow: 0 -8px 24px rgba(0, 0, 0, 0.45);
}
.suggest.hidden { display: none; }

/* Every row looks the same: nothing here hints at what is in reach. */
.suggest li {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 10px;
  padding: 8px 10px;
  border-radius: 6px;
  cursor: pointer;
  font-size: 0.92rem;
}
.suggest li.active, .suggest li:hover { background: var(--panel-light); }

.sug-name { font-weight: 600; }
.sug-country { color: var(--text-dim); font-weight: 400; font-size: 0.85em; }
.sug-meta {
  color: var(--muted);
  font-size: 0.78rem;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}
.suggest li.active .sug-meta { color: var(--text-dim); }

.feedback {
  min-height: 1.3em;
  margin: 8px 2px 0;
  font-size: 0.88rem;
  color: var(--text-dim);
}
.feedback.good { color: var(--correct); }
.feedback.bad { color: var(--incorrect); }
.feedback.note { color: var(--highlight); }

/* ---------- Tools ---------- */

.tool-row {
  display: flex;
  gap: 10px;
  align-items: center;
  margin-top: 8px;
  flex-wrap: wrap;
}

.tool-btn {
  background: var(--panel);
  border: 1px solid var(--panel-light);
  border-radius: 8px;
  color: var(--text-dim);
  cursor: pointer;
  font-size: 0.85rem;
  font-family: inherit;
  padding: 7px 12px;
  transition: border-color 0.15s, color 0.15s;
}
.tool-btn:hover:not(:disabled) { border-color: var(--accent); color: var(--text); }
.tool-btn:disabled { opacity: 0.35; cursor: not-allowed; }
.tool-btn.right { margin-left: auto; }
.tool-btn.armed { border-color: var(--highlight); color: var(--highlight); }

.budget-chip {
  font-size: 0.8rem;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}
.budget-chip.hidden { display: none; }
.budget-chip.low { color: var(--highlight); }

/* ---------- Log ---------- */

.log-wrap { margin-top: 18px; }

.log-title {
  font-size: 0.85rem;
  color: var(--text-dim);
  text-transform: uppercase;
  letter-spacing: 1.5px;
  margin: 0 0 8px;
}
.log-note { text-transform: none; letter-spacing: normal; color: var(--muted); font-weight: 400; }

.city-log {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  max-height: 132px;
  overflow-y: auto;
}

.log-pill {
  background: var(--panel);
  border: 1px solid var(--panel-light);
  border-radius: 20px;
  padding: 4px 11px;
  font-size: 0.8rem;
  display: inline-flex;
  gap: 7px;
  align-items: baseline;
  cursor: pointer;
}
.log-pill:hover { border-color: var(--accent); }
.log-pill .lp-gain {
  color: var(--accent);
  font-variant-numeric: tabular-nums;
  font-size: 0.9em;
}
.log-pill.airdrop { border-color: color-mix(in srgb, var(--highlight) 45%, transparent); }

/* A city entirely inside ground you already held — it happened, but it did
   nothing, and the list should say so at a glance. */
.log-pill.barren { opacity: 0.5; }
.log-pill.barren .lp-gain { color: var(--muted); }

/* ---------- Results ---------- */

.final-score {
  text-align: center;
  font-size: 1.5rem;
  font-weight: 700;
  color: var(--accent);
  margin-bottom: 18px;
}

.final-stats {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 12px;
  max-width: 720px;
  margin: 0 auto 26px;
}

.fs-cell {
  background: var(--panel);
  border-radius: 10px;
  padding: 14px 10px;
  text-align: center;
}
.fs-val {
  display: block;
  font-size: 1.3rem;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}
.fs-lbl {
  display: block;
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 1px;
  color: var(--muted);
  margin-top: 3px;
}

.round-breakdown {
  max-width: 560px;
  margin: 0 auto 22px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.breakdown-row {
  display: grid;
  grid-template-columns: auto 1fr auto;
  gap: 12px;
  align-items: center;
  background: var(--panel);
  border-radius: 8px;
  padding: 8px 14px;
  font-size: 0.9rem;
}
.breakdown-row .bd-rank { color: var(--muted); font-variant-numeric: tabular-nums; }
.breakdown-row .bd-name { font-weight: 600; }
.breakdown-row .bd-name span { color: var(--text-dim); font-weight: 400; font-size: 0.85em; }
.breakdown-row .bd-gain { color: var(--accent); font-weight: 700; font-variant-numeric: tabular-nums; }
.breakdown-row .bd-pop { color: var(--text-dim); font-weight: 600; font-variant-numeric: tabular-nums; }

/* A missed city that was inside the circles: one you could have had. */
.breakdown-row .bd-tag {
  font-style: normal;
  font-size: 0.72em;
  font-weight: 700;
  color: var(--highlight);
  border: 1px solid color-mix(in srgb, var(--highlight) 45%, transparent);
  border-radius: 10px;
  padding: 1px 6px;
  margin-left: 4px;
  white-space: nowrap;
}

/* ---------- 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); } }

@media (max-width: 760px) {
  .options-grid, .options-grid.four, .options-grid.three, .options-grid.two {
    grid-template-columns: repeat(2, 1fr);
  }
  .final-stats { grid-template-columns: repeat(2, 1fr); }
}

@media (max-width: 600px) {
  .pop-counter { min-width: 0; padding: 6px 12px 8px; }
  .pc-num { font-size: 1.3rem; }
  .pc-note { display: none; }
  #app { padding: 14px; }
  h1 { font-size: 1.6rem; }
  .hud { gap: 14px; }
  .stat-val { font-size: 1.1rem; }
  #map-svg { height: 44vh; }
  .options-grid, .options-grid.four, .options-grid.three { grid-template-columns: 1fr; }
  .primary-btn.compact { padding: 12px 18px; }
}
