:root {
  color-scheme: dark;
  --bg: #14171a;
  --fg: #edf0ec;
  --muted: #9aa39c;
  --border: #33372f;
  --panel-bg: #1e2220;
  --panel-hover: #282c29;
  --unvisited-fill: #262a26;
  --unvisited-stroke: #3c423c;
  --label-fill: #f2f2ee;
  --label-halo: rgba(10, 12, 10, 0.7);
}

:root[data-theme="light"] {
  color-scheme: light;
  --bg: #f7f6f3;
  --fg: #1f2320;
  --muted: #6b7268;
  --border: #d8d5cc;
  --panel-bg: #ffffff;
  --panel-hover: #eeeeee;
  --unvisited-fill: #e4e1d8;
  --unvisited-stroke: #b7b2a4;
  --label-fill: #222222;
  --label-halo: rgba(255, 255, 255, 0.75);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background: var(--bg);
  color: var(--fg);
  transition: background-color 0.15s ease, color 0.15s ease;
}

header {
  padding: 1.5rem 1.25rem 0.5rem;
  text-align: center;
}

header h1 {
  margin: 0 0 0.25rem;
  font-size: 1.6rem;
}

.subtitle {
  margin: 0;
  color: var(--muted);
  font-size: 0.95rem;
}

.controls {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: center;
  gap: 0.75rem;
  padding: 1rem;
}

.controls label {
  font-size: 0.9rem;
  color: var(--muted);
}

.controls select,
.controls button {
  font-size: 0.9rem;
  padding: 0.4rem 0.7rem;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: var(--panel-bg);
  color: var(--fg);
  cursor: pointer;
}

.controls button:hover {
  background: var(--panel-hover);
}

.seg-switch {
  display: inline-flex;
  border: 1px solid var(--border);
  border-radius: 6px;
  overflow: hidden;
  margin-left: 0.25rem;
}

.seg-switch button {
  border: none;
  border-radius: 0;
}

.seg-switch button:first-child {
  border-right: 1px solid var(--border);
}

.seg-switch button.active {
  background: var(--fg);
  color: var(--bg);
  cursor: default;
}

.seg-switch button.active:hover {
  background: var(--fg);
}

/* The Light/Dark buttons always look like their own theme, regardless of
   which theme is currently active, instead of inverting with --fg/--bg.
   A ring (in the current theme's contrasting --fg) keeps the active one
   visible even when its fill would otherwise blend into the page. */
#theme-light-btn.active,
#theme-light-btn.active:hover {
  background: #f7f6f3;
  color: #1f2320;
  box-shadow: inset 0 0 0 2px var(--fg);
}

#theme-dark-btn.active,
#theme-dark-btn.active:hover {
  background: #14171a;
  color: #edf0ec;
  box-shadow: inset 0 0 0 2px var(--fg);
}

.stat {
  font-size: 0.9rem;
  font-weight: 600;
  color: var(--fg);
  min-width: 9rem;
  text-align: center;
}

.legend {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 1.25rem;
  padding: 0 1rem 1rem;
  font-size: 0.85rem;
  color: var(--muted);
}

.legend-item {
  display: flex;
  align-items: center;
  gap: 0.4rem;
}

.legend-swatch {
  width: 0.85rem;
  height: 0.85rem;
  border-radius: 3px;
  flex: none;
}

main {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  align-items: flex-start;
  gap: 1.5rem;
  padding: 0 1rem 2rem;
}

#map-wrap {
  position: relative;
  width: 100%;
  max-width: 960px;
  flex: 1 1 640px;
}

#map {
  width: 100%;
  height: auto;
  display: block;
  background: transparent;
  transition: opacity 0.1s ease;
}

#map-wrap.loading #map {
  opacity: 0.35;
}

.state-path {
  fill: var(--unvisited-fill);
  stroke: var(--unvisited-stroke);
  stroke-width: 0.75;
  cursor: pointer;
  transition: fill 0.15s ease;
}

.state-path:hover {
  filter: brightness(0.92);
}

.state-path.selected {
  stroke: var(--fg);
  stroke-width: 2.25;
}

.region-label {
  font-size: 7px;
  font-weight: 600;
  fill: var(--label-fill);
  paint-order: stroke;
  stroke: var(--label-halo);
  stroke-width: 2.5px;
  stroke-linejoin: round;
  text-anchor: middle;
  dominant-baseline: middle;
  pointer-events: none;
  user-select: none;
}

.tooltip {
  position: absolute;
  pointer-events: none;
  background: rgba(20, 20, 20, 0.9);
  color: #fff;
  padding: 0.35rem 0.6rem;
  border-radius: 5px;
  font-size: 0.8rem;
  white-space: nowrap;
  transform: translate(-50%, -120%);
  z-index: 10;
}

.visited-list-section {
  flex: 0 1 220px;
  min-width: 180px;
}

.visited-list-section h2 {
  font-size: 1rem;
  color: var(--muted);
  font-weight: 600;
  margin: 0 0 0.75rem;
  text-align: left;
}

.visited-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.visited-list li {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  font-size: 0.9rem;
  color: var(--fg);
}

.visited-list-flag {
  font-size: 1.1rem;
  line-height: 1;
}

footer {
  text-align: center;
  padding: 1rem;
  font-size: 0.75rem;
  color: var(--muted);
}

footer a {
  color: var(--muted);
}
