:root {
  --bg: #f6f5f1;
  --surface: #ffffff;
  --text: #1b1b1b;
  --muted: #6b6b6b;
  --border: #e2e0da;
  --accent: #0039a6;
  --accent-text: #ffffff;
  --link: #0039a6;
  --track: #9a9a9a;
  --dot: #2b2b2b;
  --dot-ring: #ffffff;
  --d0: #2e9e5b;
  --d1: #d9a400;
  --d2: #e8772e;
  --d3: #d43d3d;
  --win: #2e9e5b;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #121212;
    --surface: #1d1d1d;
    --text: #ececec;
    --muted: #9a9a9a;
    --border: #333;
    --accent: #4d84f0;
    --link: #8ab4ff;
    --track: #6b6b6b;
    --dot: #e6e6e6;
    --dot-ring: #121212;
  }
}

* { box-sizing: border-box; }

html, body { margin: 0; }

/* The page scrolls as a whole: the map has a fixed height and the panel below it can run offscreen. */
body {
  display: flex;
  flex-direction: column;
  min-height: 100svh;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.4 "Helvetica Neue", Helvetica, Arial, sans-serif;
}

button {
  font: inherit;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  border-radius: 999px;
  padding: 8px 16px;
  cursor: pointer;
}
button.primary {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--accent-text);
  font-weight: 600;
}
button:disabled { opacity: 0.4; cursor: default; }

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 16px;
  background: #000;
  color: #fff;
}
.brand { display: flex; align-items: center; gap: 10px; }
.logo {
  display: inline-grid;
  place-items: center;
  width: 28px; height: 28px;
  border-radius: 50%;
  background: #fff;
  color: #000;
  font-weight: 700;
}
.title { font-weight: 700; font-size: 18px; letter-spacing: -0.01em; }
.puzzle { color: #aaa; font-size: 14px; }
.topbar-actions { display: flex; gap: 8px; }
.icon-btn {
  width: 32px; height: 32px; padding: 0;
  background: transparent; color: #fff; border-color: #555;
}
.info-icon { font: italic 700 17px Georgia, "Times New Roman", serif; }

.prompt {
  padding: 10px 16px 12px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}
.prompt-label {
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--muted);
}
.prompt-target {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 4px 10px;
}
.target-name { font-size: 22px; font-weight: 700; letter-spacing: -0.01em; }

.bullets { display: inline-flex; flex-wrap: wrap; gap: 3px; }
.bullet {
  display: inline-grid;
  place-items: center;
  min-width: 22px; height: 22px;
  padding: 0 4px;
  border-radius: 11px;
  font-size: 13px;
  font-weight: 700;
  color: #fff;
}
.bullet.dark-text { color: #000; }
.bullet.small { min-width: 17px; height: 17px; font-size: 10px; border-radius: 9px; }

/* Sized from the viewport only, so guessing never changes the game area. Leaves room to see the panel below. */
#map {
  flex: none;
  height: max(260px, 100svh - 280px);
  background: var(--bg);
}
/* After the puzzle ends the map shrinks so there's more panel to grab and scroll. */
body.finished #map { height: calc(0.7 * max(260px, 100svh - 280px)); }
.leaflet-container { font: inherit; }

.panel {
  flex: 1 0 auto; /* fill to the bottom of the screen when content is short */
  display: flex;
  flex-direction: column;
  padding: 12px 16px calc(12px + env(safe-area-inset-bottom));
  background: var(--surface);
  border-top: 1px solid var(--border);
}
.status-row { display: flex; align-items: center; gap: 12px; }
.status { flex: 1; color: var(--muted); }
.status b { color: var(--text); }

.guesses {
  list-style: none;
  margin: 8px 0 0;
  padding: 0;
  display: grid;
  gap: 6px;
}
.guesses li {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 10px;
  border-radius: 8px;
  background: var(--bg);
}
.guesses .n { color: var(--muted); width: 1.2em; }
.guesses .name { flex: 1; min-width: 0; }
.guesses .dist { font-weight: 700; font-variant-numeric: tabular-nums; }

.swatch {
  display: inline-block;
  width: 12px; height: 12px;
  border-radius: 50%;
  flex: none;
}
.d0 { background: var(--d0); }
.d1 { background: var(--d1); }
.d2 { background: var(--d2); }
.d3 { background: var(--d3); }
.win { background: var(--win); }

.result { margin-top: 12px; text-align: center; }
.result-text { font-size: 17px; font-weight: 600; margin: 0 0 10px; }
.fun-fact {
  margin: 0 0 12px;
  padding: 10px 14px;
  border-radius: 8px;
  background: var(--bg);
  border-left: 4px solid var(--accent);
  text-align: left;
}
.fun-fact-label {
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--muted);
  margin-bottom: 2px;
}
.fun-fact p { margin: 0; }
.fun-fact-img {
  display: block;
  /* Scale down (never crop) to fit within the box width and 320px tall. */
  max-width: 100%;
  max-height: 320px;
  width: auto;
  height: auto;
  border-radius: 6px;
  margin: 0 auto 10px;
}
.fun-fact-img[hidden] { display: none; }

/* After the puzzle ends the result comes first, above the guess list. */
body.finished .result { order: -1; margin: 0 0 4px; }
.result-actions { display: flex; gap: 8px; justify-content: center; flex-wrap: wrap; }
.countdown { color: var(--muted); font-size: 13px; margin: 10px 0 0; }

/* Map labels for guessed stations */
.leaflet-tooltip.guess-label {
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 6px;
  box-shadow: 0 1px 4px rgba(0,0,0,0.2);
  font-size: 12px;
  font-weight: 600;
  padding: 2px 6px;
}
.leaflet-tooltip.guess-label::before { display: none; }
.leaflet-tooltip.guess-label.answer {
  background: var(--win);
  color: #fff;
  border-color: var(--win);
}

dialog {
  max-width: min(420px, calc(100vw - 32px));
  border: none;
  border-radius: 14px;
  padding: 20px 22px;
  background: var(--surface);
  color: var(--text);
  box-shadow: 0 10px 40px rgba(0,0,0,0.3);
}
dialog::backdrop { background: rgba(0,0,0,0.45); }
dialog h2 { margin: 0 0 8px; }
dialog form { text-align: right; margin-top: 12px; }
.legend { list-style: none; padding: 0; display: grid; gap: 4px; }
.legend li { display: flex; align-items: center; gap: 8px; }
.fine { color: var(--muted); font-size: 13px; }

.toast {
  position: fixed;
  left: 50%;
  bottom: 30%;
  transform: translateX(-50%);
  background: #000;
  color: #fff;
  padding: 8px 14px;
  border-radius: 8px;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s;
  z-index: 2000;
}
.toast.show { opacity: 0.9; }

a {
  color: var(--link);
  text-decoration: underline;
  text-decoration-thickness: 1px;
  text-underline-offset: 2px;
}
a:hover { text-decoration-thickness: 2px; }

.leaflet-control-attribution.leaflet-control {
  font-size: 10px;
  line-height: 1.3;
  background: color-mix(in srgb, var(--surface) 80%, transparent);
  color: var(--muted);
}
.leaflet-container .leaflet-control-attribution a { color: var(--link); }
