:root[data-theme="dark"] {
  --bg: #0f1720;
  --panel: #16212c;
  --panel-alt: #1c2b38;
  --border: #2a3b4a;
  --text: #e7edf2;
  --text-dim: #93a4b3;
  --accent: #4fb0e8;
  --accent-bg: #1c3444;
  --ok: #3ecf8e;
  --bad: #e8615c;
  --land: #2b3f4f;
  --land-hover: #3a5468;
  --land-done: #2d6b52;
  --sea: #2c6f8e;
  --sea-hover: #3c8bad;
  --sea-done: #2d6b52;
}

:root[data-theme="light"] {
  --bg: #f4f7fa;
  --panel: #ffffff;
  --panel-alt: #eef2f6;
  --border: #d7dee5;
  --text: #1c2733;
  --text-dim: #5b6b7a;
  --accent: #1f7fc1;
  --accent-bg: #dbeefb;
  --ok: #1f9d6b;
  --bad: #d1453b;
  --land: #c3d3e0;
  --land-hover: #a9c1d3;
  --land-done: #8fd0b0;
  --sea: #8fc2dd;
  --sea-hover: #6fa9cc;
  --sea-done: #8fd0b0;
}

:root[data-theme="ocean"] {
  --bg: #031a24;
  --panel: #062836;
  --panel-alt: #0a3648;
  --border: #0e4c63;
  --text: #dff6ff;
  --text-dim: #7fb9cf;
  --accent: #22d3ee;
  --accent-bg: #0d3a4a;
  --ok: #34e2a8;
  --bad: #ff6b6b;
  --land: #0f4d63;
  --land-hover: #146781;
  --land-done: #146b52;
  --sea: #0f6f8e;
  --sea-hover: #1490b5;
  --sea-done: #146b52;
}

:root[data-theme="sunset"] {
  --bg: #1a1224;
  --panel: #241a30;
  --panel-alt: #2e213c;
  --border: #453255;
  --text: #f5e9f7;
  --text-dim: #b79bc4;
  --accent: #ff8a5c;
  --accent-bg: #3a2a44;
  --ok: #6fe0a0;
  --bad: #ff5d7a;
  --land: #3a2a4a;
  --land-hover: #4a3660;
  --land-done: #2f6b52;
  --sea: #5a3a6a;
  --sea-hover: #714a85;
  --sea-done: #2f6b52;
}

:root,
:root[data-theme="world"] {
  --bg: #d8ecfa;
  --panel: #ffffff;
  --panel-alt: #eef7fc;
  --border: #b9dced;
  --text: #1c2b33;
  --text-dim: #5c7686;
  --accent: #1f8fc4;
  --accent-bg: #d3edf9;
  --ok: #2f9e5b;
  --bad: #d1453b;
  --land: #cfe8d0;
  --land-hover: #b7dab9;
  --land-done: #4caf6e;
  --sea: #a9d8ef;
  --sea-hover: #8cc6e3;
  --sea-done: #4caf6e;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: "Segoe UI", system-ui, sans-serif;
}

.screen { height: 100%; }
.screen.hidden { display: none !important; }

/* ---------- Setup screen ---------- */

#setup-screen {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  overflow-y: auto;
}

.setup-card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 28px 32px;
  max-width: 640px;
  width: 100%;
}

.setup-card h1 {
  margin: 0 0 4px;
  font-size: 26px;
}

.setup-sub {
  color: var(--text-dim);
  margin: 0 0 14px;
  font-size: 14px;
  line-height: 1.5;
}

.stat-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px 18px;
  list-style: none;
  margin: 0 0 22px;
  padding: 0;
}

.stat-row li {
  font-size: 12px;
  color: var(--text-dim);
}

.stat-row strong {
  color: var(--text);
  font-size: 14px;
  margin-right: 4px;
}

.setup-footer {
  margin: 16px 0 0;
  font-size: 11px;
  line-height: 1.5;
  color: var(--text-dim);
  text-align: center;
}

.theme-swatches {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.theme-swatch {
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--panel-alt);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 8px 12px;
  color: var(--text);
  cursor: pointer;
  font-size: 13px;
}

.theme-swatch:hover { border-color: var(--accent); }
.theme-swatch.active {
  border-color: var(--accent);
  box-shadow: 0 0 0 1px var(--accent);
}

.swatch-dot {
  width: 16px;
  height: 16px;
  border-radius: 50%;
  flex-shrink: 0;
  border: 1px solid rgba(255, 255, 255, 0.15);
}

.swatch-dark { background: linear-gradient(135deg, #0f1720 50%, #4fb0e8 50%); }
.swatch-light { background: linear-gradient(135deg, #f4f7fa 50%, #1f7fc1 50%); }
.swatch-ocean { background: linear-gradient(135deg, #031a24 50%, #22d3ee 50%); }
.swatch-sunset { background: linear-gradient(135deg, #1a1224 50%, #ff8a5c 50%); }
.swatch-world { background: linear-gradient(135deg, #d8ecfa 50%, #cfe8d0 50%); border-color: #b9dced; }

.setup-group { margin-bottom: 20px; }
.setup-group.disabled { opacity: 0.45; }

.setup-group h2 {
  font-size: 13px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--text-dim);
  margin: 0 0 10px;
  font-weight: 600;
}

.option-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: 10px;
}

.option-card {
  background: var(--panel-alt);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 14px 12px;
  text-align: left;
  color: var(--text);
  cursor: pointer;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.option-card strong { font-size: 14px; }
.option-card span { font-size: 12px; color: var(--text-dim); line-height: 1.35; }

.option-card:hover { border-color: var(--accent); }
.option-card.active {
  border-color: var(--accent);
  background: var(--accent-bg);
}

select {
  width: 100%;
  background: var(--panel-alt);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 9px 10px;
  font-size: 14px;
}

.start-btn {
  width: 100%;
  background: var(--accent);
  color: #06222f;
  border: none;
  border-radius: 10px;
  padding: 13px;
  font-size: 15px;
  font-weight: 700;
  cursor: pointer;
  margin-top: 6px;
}

.start-btn:hover { filter: brightness(1.05); }

@media (max-width: 560px) {
  .option-grid { grid-template-columns: 1fr; }
}

/* ---------- Play screen ---------- */

.topbar {
  display: flex;
  align-items: center;
  gap: 18px;
  padding: 10px 18px;
  background: var(--panel);
  border-bottom: 1px solid var(--border);
}

#home-btn {
  background: var(--panel-alt);
  color: var(--text);
  border: 1px solid var(--border);
  padding: 6px 12px;
  border-radius: 6px;
  cursor: pointer;
  font-size: 13px;
  white-space: nowrap;
}
#home-btn:hover { border-color: var(--accent); }

.topbar h1 {
  font-size: 16px;
  margin: 0;
  font-weight: 600;
  white-space: nowrap;
}

.zoom-controls {
  display: flex;
  gap: 4px;
  margin-left: auto;
}

.zoom-controls button {
  background: var(--panel-alt);
  color: var(--text);
  border: 1px solid var(--border);
  width: 30px;
  height: 30px;
  border-radius: 6px;
  cursor: pointer;
  font-size: 15px;
  line-height: 1;
}
#zoom-reset-btn { width: auto; padding: 0 10px; font-size: 12px; }
.zoom-controls button:hover { border-color: var(--accent); }

.theme-toggle-btn {
  background: var(--panel-alt);
  border: 1px solid var(--border);
  width: 30px;
  height: 30px;
  border-radius: 6px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
}
.theme-toggle-btn:hover { border-color: var(--accent); }
.theme-toggle-btn .swatch-dot {
  width: 15px;
  height: 15px;
  background: var(--accent);
  border-color: var(--border);
}

.score-panel {
  display: flex;
  align-items: center;
  gap: 12px;
}

#score {
  font-variant-numeric: tabular-nums;
  font-weight: 600;
  font-size: 15px;
  white-space: nowrap;
}

#reset-btn {
  background: var(--panel-alt);
  color: var(--text);
  border: 1px solid var(--border);
  padding: 6px 12px;
  border-radius: 6px;
  cursor: pointer;
  font-size: 13px;
  white-space: nowrap;
}

#reset-btn:hover { border-color: var(--accent); }

.layout {
  display: grid;
  grid-template-columns: 1fr 260px;
  height: calc(100% - 53px);
}

.map-pane {
  padding: 14px;
  overflow: hidden;
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
}

#map-container {
  width: 100%;
  height: 100%;
  max-width: 1400px;
  cursor: grab;
  touch-action: none;
}

#map-container.panning { cursor: grabbing; }

#map-container svg {
  width: 100%;
  height: 100%;
  display: block;
}

#map-container path {
  fill: var(--land);
  stroke: #0c1620;
  stroke-width: 0.5;
  transition: fill 0.15s ease;
}

#map-container path.drop-hover {
  fill: var(--land-hover);
}

#map-container path.solved {
  fill: var(--land-done);
}

#map-container path.flash-bad,
#map-container circle.flash-bad {
  fill: var(--bad) !important;
}

#seas-layer {
  display: none;
}

#seas-layer circle {
  fill: var(--sea);
  fill-opacity: 0.55;
  stroke: #0c1620;
  stroke-width: 0.75;
  transition: fill 0.15s ease;
}

#seas-layer circle.drop-hover { fill: var(--sea-hover); }
#seas-layer circle.solved { fill: var(--sea-done); fill-opacity: 0.85; }

/* Seas activity: dim + disable the country layer, show sea markers */
#map-container.activity-seas #countries-layer path {
  fill: var(--panel-alt);
  pointer-events: none;
}

/* Both seas-based activities show the sea markers */
#map-container.activity-seas #seas-layer,
#map-container.activity-continents-seas #seas-layer {
  display: block;
}

/* Continents & Seas: countries stay interactive (they're the continent
   drop targets), so no dimming — just show the sea markers alongside. */

.bank-pane {
  background: var(--panel);
  border-left: 1px solid var(--border);
  padding: 12px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.bank-hint {
  color: var(--text-dim);
  font-size: 12px;
  margin: 2px 0 4px;
}

.bank {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.chip {
  background: var(--panel-alt);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 7px 10px;
  cursor: grab;
  font-size: 13px;
  display: flex;
  align-items: center;
  gap: 8px;
  user-select: none;
  touch-action: none;
  -webkit-touch-callout: none;
}

.chip:active { cursor: grabbing; }

.chip.dragging { opacity: 0.4; }

.chip img {
  width: 24px;
  height: 18px;
  object-fit: cover;
  border-radius: 2px;
  flex-shrink: 0;
}

/* Floating copy of a chip that follows the pointer during a drag (see
   startDrag/moveDrag in app.js) — same look as a normal chip, just
   positioned at the pointer instead of in the bank list. */
.drag-ghost {
  position: fixed;
  top: 0;
  left: 0;
  z-index: 1000;
  pointer-events: none;
  opacity: 0.95;
  box-shadow: 0 6px 18px rgba(0, 0, 0, 0.35);
  transform: translate(-50%, -50%);
}

.toast {
  position: fixed;
  bottom: 20px;
  left: 50%;
  transform: translateX(-50%) translateY(20px);
  background: var(--panel-alt);
  border: 1px solid var(--border);
  padding: 10px 20px;
  border-radius: 8px;
  font-size: 14px;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s ease, transform 0.2s ease;
}

.toast.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

.toast.win {
  border-color: var(--ok);
}

@media (max-width: 900px) {
  .layout { grid-template-columns: 1fr; grid-template-rows: 1fr auto; }
  .bank-pane { border-left: none; border-top: 1px solid var(--border); max-height: 40vh; }
  .bank { flex-direction: row; flex-wrap: wrap; }
  .topbar { flex-wrap: wrap; row-gap: 8px; }
  .zoom-controls { margin-left: 0; }
}
