:root {
  --map-inactive: #e0e0e0;
  --map-active: #6699cc;
  --map-stroke: #ffffff;
  --map-ocean: #dbe9f4;
  --map-glow: #ffb020;
  --bg: #f7f7f5;
  --panel: #ffffff;
  --text: #1c1e21;
  --text-dim: #6b7178;
  --border: #dfe2e6;
  --accent: #2f6f9e;
  --accent-text: #ffffff;
  --radius: 10px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #16181c;
    --panel: #1f2227;
    --text: #eceef0;
    --text-dim: #9aa1a9;
    --border: #33373d;
    --accent: #5b9bd5;
    --accent-text: #0b1116;
  }
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.4;
}

.wrap {
  max-width: 980px;
  margin: 0 auto;
  padding: 16px 16px 48px;
}

header.app-header {
  text-align: center;
  padding: 8px 0 20px;
}

header.app-header h1 {
  font-size: 1.4rem;
  margin: 0 0 4px;
}

header.app-header p {
  margin: 0;
  color: var(--text-dim);
  font-size: 0.9rem;
}

.panel {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  margin-bottom: 16px;
}

.toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  align-items: flex-end;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 4px;
  font-size: 0.85rem;
  color: var(--text-dim);
}

.field input[type="text"] {
  font: inherit;
  color: var(--text);
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 8px 10px;
  min-width: 220px;
}

.field-title {
  flex: 1 1 220px;
}

.color-field {
  flex-direction: row;
  align-items: center;
  gap: 8px;
}

.color-field input[type="color"] {
  width: 36px;
  height: 36px;
  padding: 0;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: none;
  cursor: pointer;
}

h2.map-title {
  text-align: center;
  margin: 0 0 12px;
  font-size: 1.1rem;
  color: var(--text-dim);
}

h2.map-title:empty {
  display: none;
}

.map-frame {
  position: relative;
  background: var(--map-ocean);
  border-radius: var(--radius);
  padding: 8px;
  overflow: hidden;
}

#map {
  display: block;
  width: 100%;
  height: auto;
  cursor: grab;
  /* Let native single-finger scrolling pass through the page; pinch-zoom
     is claimed by JS instead of the browser (no "pinch-zoom" in the list). */
  touch-action: pan-x pan-y;
}

#map:active {
  cursor: grabbing;
}

#map path {
  fill: var(--map-inactive);
  stroke: var(--map-stroke);
  stroke-width: 0.6;
  cursor: pointer;
  transition: fill 120ms ease;
}

.zoom-controls {
  position: absolute;
  top: 20px;
  right: 20px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.zoom-controls button {
  width: 32px;
  height: 32px;
  padding: 0;
  line-height: 1;
  font-size: 1.1rem;
  background: var(--panel);
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.2);
}

.zoom-controls button:disabled {
  opacity: 0.4;
  cursor: default;
}

.zoom-controls button:disabled:hover {
  border-color: var(--border);
}

.map-tooltip {
  position: fixed;
  z-index: 20;
  pointer-events: none;
  background: rgba(20, 22, 26, 0.9);
  color: #fff;
  font-size: 0.82rem;
  font-weight: 600;
  padding: 5px 10px;
  border-radius: 6px;
  white-space: nowrap;
  opacity: 0;
  transform: translate(-50%, -100%) translateY(-10px);
  transition: opacity 100ms ease;
}

.map-tooltip.visible {
  opacity: 1;
}

/* A glow that hugs each shape's actual silhouette (drop-shadow follows the
   rendered alpha, not the bounding box) rather than a rectangular outline —
   works the same for a single <path> or a multi-island <g>.
   Scoped to *direct* children of #countries: without the `>` combinator,
   :hover's bubbling to ancestors would also match #countries itself (the
   group wrapping all 179 countries), putting the glow on the whole map. */
#countries > path:hover,
#countries > g:hover,
#countries > path:focus,
#countries > g:focus {
  outline: none;
  filter:
    drop-shadow(0 0 2px #fff)
    drop-shadow(0 0 4px var(--map-glow))
    drop-shadow(0 0 8px var(--map-glow));
}

#map path.active,
#map g.active path {
  fill: var(--map-active);
}

.chips {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 12px;
}

.chips:empty {
  display: none;
}

.chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 4px 6px 4px 12px;
  font-size: 0.85rem;
}

.chip button {
  border: none;
  background: none;
  color: var(--text-dim);
  font-size: 1rem;
  line-height: 1;
  cursor: pointer;
  padding: 4px 6px;
}

.chip button:hover {
  color: var(--text);
}

.stats {
  text-align: center;
  font-size: 0.95rem;
  color: var(--text-dim);
  margin-top: 12px;
}

.stats strong {
  color: var(--text);
}

.share-row {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.share-row input[type="text"] {
  flex: 1 1 260px;
  font: inherit;
  color: var(--text);
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 8px 10px;
}

button {
  font: inherit;
  border: 1px solid var(--border);
  background: var(--panel);
  color: var(--text);
  border-radius: 6px;
  padding: 8px 14px;
  cursor: pointer;
  touch-action: manipulation;
}

button:hover {
  border-color: var(--accent);
}

button.primary {
  background: var(--accent);
  color: var(--accent-text);
  border-color: var(--accent);
}

button.danger:hover {
  border-color: #c0392b;
  color: #c0392b;
}

.search-input {
  width: 100%;
  font: inherit;
  color: var(--text);
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 10px 12px;
  position: sticky;
  top: 0;
  margin-bottom: 8px;
}

.country-list {
  border-top: 1px solid var(--border);
}

.country-list details {
  border-bottom: 1px solid var(--border);
  padding: 6px 0;
}

.country-list summary {
  cursor: pointer;
  font-weight: 600;
  padding: 4px 2px;
}

/* Lives inside a continent's <summary>, so it's visible whether the
   details is open or closed — not a sibling of summary, which <details>
   would hide until expanded. */
.subregion-summary {
  display: block;
  margin-top: 2px;
  font-size: 0.82rem;
  font-weight: 400;
  color: var(--text-dim);
}

.subregion-group {
  margin-top: 10px;
}

.subregion-group:first-of-type {
  margin-top: 4px;
}

.subregion-heading {
  margin: 0 0 4px;
  padding: 0 2px;
  font-size: 0.78rem;
  font-weight: 600;
  color: var(--text-dim);
  text-transform: uppercase;
  letter-spacing: 0.02em;
}

.country-list ul {
  list-style: none;
  margin: 4px 0 0;
  padding: 0;
  columns: 2;
  column-gap: 12px;
}

@media (min-width: 600px) {
  .country-list ul {
    columns: 3;
  }
}

.country-list li {
  break-inside: avoid;
}

.country-list li[hidden] {
  display: none;
}

.country-list label {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 9px 2px;
  font-size: 0.92rem;
  cursor: pointer;
}

.country-list input[type="checkbox"] {
  width: 16px;
  height: 16px;
  flex: none;
}

footer.app-footer {
  text-align: center;
  font-size: 0.78rem;
  color: var(--text-dim);
  padding-top: 8px;
}

footer.app-footer a {
  color: inherit;
}
