:root {
  --bg: #f6f4ef;
  --panel: #ffffff;
  --ink: #1d1d1f;
  --muted: #6b6b70;
  --line: #d9d5cc;
  --accent: #c8102e;
  --accent-ink: #ffffff;
  --found: #1f7a4d;
  --missed: #b4541a;
  --radius: 10px;
  --water: #d8e6ee;
  --land: #e9e6df;
  --wales: #fbfaf7;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #16161a;
    --panel: #212126;
    --ink: #ececf0;
    --muted: #9a9aa3;
    --line: #3a3a42;
    --accent: #ff4d63;
    --accent-ink: #16161a;
    --found: #4cc38a;
    --missed: #f0995a;
    --water: #141c22;
    --land: #1c1c21;
    --wales: #26262c;
  }
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 16px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

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

.top { max-width: 960px; margin: 0 auto; padding: 32px 16px 20px; }
.top h1 { margin: 0; font-size: 2rem; letter-spacing: -0.02em; display: flex; align-items: center; gap: 0.4em; }
.logo { height: 1.25em; width: auto; flex: none; }
.tag { margin: 4px 0 0; color: var(--muted); }

.title-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; }
.lang-switch { display: inline-flex; border: 1px solid var(--line); border-radius: 999px; padding: 3px; background: var(--panel); }
.lang-switch button { border: 0; border-radius: 999px; padding: 6px 14px; font-size: 0.9rem; background: transparent; color: var(--muted); }
.lang-switch button[aria-pressed="true"] { background: var(--accent); color: var(--accent-ink); font-weight: 600; }
.muted { color: var(--muted); }

button {
  font: inherit; cursor: pointer; border-radius: var(--radius);
  padding: 10px 18px; border: 1px solid var(--line); background: var(--panel); color: var(--ink);
}
button:disabled { opacity: 0.45; cursor: default; }
button.primary { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); font-weight: 600; }
button.ghost { background: transparent; }

/* Picker */
.region-title { margin: 24px 0 10px; font-size: 0.8rem; text-transform: uppercase; letter-spacing: 0.08em; color: var(--muted); }
.line-list .cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 10px; }
.card {
  text-align: left; display: flex; flex-direction: column; gap: 4px;
  padding: 14px 16px; border-left: 4px solid var(--accent);
}
.card:hover { border-color: var(--accent); }
.card.done { border-left-color: var(--found); }
.card.done:hover { border-color: var(--found); }
.card strong { font-size: 1.05rem; }
.card span { font-size: 0.85rem; color: var(--muted); }

/* Game bar */
.bar { display: flex; align-items: center; gap: 16px; flex-wrap: wrap; padding: 8px 0 16px; }
.title-block { flex: 1; min-width: 180px; }
.title-block h2 { margin: 0; font-size: 1.4rem; }
.stats { display: flex; gap: 20px; }
.stat { font-size: 1.6rem; font-weight: 700; font-variant-numeric: tabular-nums; text-align: right; }
.stat small { display: block; font-size: 0.7rem; font-weight: 500; color: var(--muted); text-transform: uppercase; letter-spacing: 0.08em; }
.clock { min-width: 6.5ch; }

.controls { display: flex; gap: 10px; flex-wrap: wrap; }
#guess {
  flex: 1; min-width: 200px; font: inherit; font-size: 1.1rem; padding: 10px 14px;
  border-radius: var(--radius); border: 2px solid var(--line); background: var(--panel); color: var(--ink);
}
#guess:focus { outline: none; border-color: var(--accent); }
#guess.flash { animation: flash 0.35s; }
@keyframes flash { from { border-color: var(--found); background: color-mix(in srgb, var(--found) 15%, var(--panel)); } }

.message { min-height: 1.5em; margin: 12px 0; font-weight: 600; }
.message.win { color: var(--found); }

/* Route diagram */
.track { list-style: none; margin: 0; padding: 0; }
.track.cols { columns: 3 240px; column-gap: 24px; }

/* Branched lines: branches side by side, a fork, then the shared line.
   Track centre sits 14px into each column; the gap between columns is 24px. */
.branches { display: grid; grid-template-columns: repeat(var(--n, 2), 1fr); column-gap: 24px; align-items: end; }
.branch-name {
  margin: 0 0 6px; padding-left: 4px; font-size: 0.75rem; font-weight: 600;
  text-transform: uppercase; letter-spacing: 0.08em; color: var(--accent);
}
.track.feeds .stop:last-child::before { bottom: 0; }   /* branch runs on into the fork */
.track.joined .stop:first-child::before { top: 0; }    /* main line starts at the fork */
.fork {
  position: relative; height: 28px; margin-left: 12px;
  /* from the first branch's track to the last one's: (n−1) × (column + gap) + track width */
  width: calc((100% - (var(--n, 2) - 1) * 24px) / var(--n, 2) * (var(--n, 2) - 1) + (var(--n, 2) - 1) * 24px + 4px);
  border: 0 solid var(--accent); border-right-width: 4px; border-bottom-width: 4px;
  border-bottom-right-radius: 18px; opacity: 0.35;
}
.fork::before, .fork-drop {           /* left (and middle) branches continue straight down */
  content: ""; position: absolute; left: 0; top: 0; bottom: -4px; width: 4px; background: var(--accent);
}
.stop {
  break-inside: avoid; position: relative; display: flex; align-items: center; gap: 12px;
  min-height: 38px; padding-left: 4px;
}
/* the track */
.stop::before {
  content: ""; position: absolute; left: 12px; top: 0; bottom: 0; width: 4px;
  background: var(--accent); opacity: 0.35;
}
.stop:first-child::before { top: 50%; }
.stop:last-child::before { bottom: 50%; }
.dot {
  position: relative; z-index: 1; flex: none; width: 20px; height: 20px; border-radius: 50%;
  background: var(--panel); border: 4px solid var(--line);
}
.stop.terminus .dot { width: 20px; height: 20px; border-width: 5px; }
.name { color: var(--muted); font-variant-numeric: tabular-nums; }
.name .blank { letter-spacing: 0.08em; opacity: 0.6; }

.stop.found .dot { border-color: var(--found); background: var(--found); }
.stop.found .name { color: var(--ink); font-weight: 600; }
.stop.found.new .name { animation: pop 0.5s; }
@keyframes pop { from { color: var(--found); transform: translateX(6px); } }

/* first and last stops, shown from the start */
.stop.given .dot { border-color: var(--accent); background: var(--accent); }
.stop.given .name { color: var(--ink); font-weight: 700; }

.stop.missed .dot { border-color: var(--missed); }
.stop.missed .name { color: var(--missed); font-style: italic; }

/* Map ("every station" game) */
.map {
  position: relative; height: min(78vh, 900px); min-height: 360px;
  border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; background: var(--water);
}
.map-svg { display: block; width: 100%; height: 100%; touch-action: none; cursor: grab; user-select: none; }
.map-svg.dragging { cursor: grabbing; }
.map .england { fill: var(--land); }
.map .wales { fill: var(--wales); stroke: var(--line); stroke-width: 1px; vector-effect: non-scaling-stroke; }
.map .rails polyline {
  fill: none; stroke: var(--accent); stroke-opacity: 0.35; stroke-width: 2.5px;
  stroke-linejoin: round; stroke-linecap: round; vector-effect: non-scaling-stroke;
}
.map .dots circle { fill: var(--panel); stroke: var(--muted); stroke-width: 1.2px; vector-effect: non-scaling-stroke; }
.map .dots circle.found { fill: var(--found); stroke: var(--panel); }
.map .dots circle.missed { fill: var(--missed); stroke: var(--panel); }
.map .dots circle.new { animation: found-pulse 0.9s; }
@keyframes found-pulse { from { fill: var(--accent); stroke: var(--accent); stroke-width: 8px; } }
.map .labels { font-family: inherit; paint-order: stroke; stroke: var(--wales); stroke-linejoin: round; pointer-events: none; }
.map .labels text { fill: var(--ink); font-weight: 600; }
.map .labels text.missed { fill: var(--missed); font-style: italic; }
.map-controls { position: absolute; top: 10px; right: 10px; display: flex; flex-direction: column; gap: 6px; }
.map-controls button { width: 38px; height: 38px; padding: 0; font-size: 1.2rem; line-height: 1; box-shadow: 0 1px 3px rgb(0 0 0 / 0.15); }

@media (max-width: 520px) {
  .stats { width: 100%; justify-content: flex-start; }
  .stat { text-align: left; }
}
