:root {
  --table: #12382b;
  --table-2: #0c2a20;
  --board: #f4efe0;
  --board-line: #1c1c1c;
  --ink: #1d1d1b;
  --muted: #6c675b;
  --accent: #c8102e;
  --accent-ink: #fff;
  --card: #fffdf6;
  --radius: 10px;
  --shadow: 0 10px 30px rgba(0,0,0,.25);
  --serif: "Iowan Old Style", "Palatino Linotype", Palatino, Georgia, serif;
  --sans: system-ui, -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}
* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  font-family: var(--sans);
  color: var(--ink);
  background: radial-gradient(1200px 800px at 50% 0%, #1b4a39 0%, var(--table) 45%, var(--table-2) 100%) fixed;
  min-height: 100vh;
}
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
a { color: inherit; }
.hidden { display: none !important; }

/* ---------- login ---------- */
.login-wrap { min-height: 100vh; display: grid; place-items: center; padding: 24px; }
.login-card {
  width: min(420px, 100%); background: var(--board); border: 3px solid var(--board-line);
  border-radius: 6px; box-shadow: var(--shadow); overflow: hidden;
}
.login-card .band { height: 18px; display: grid; grid-template-columns: repeat(8, 1fr); border-bottom: 3px solid var(--board-line); }
.login-card .inner { padding: 28px 28px 30px; }
.login-card h1 { font-family: var(--serif); font-size: 2rem; margin: 0 0 4px; letter-spacing: .02em; text-transform: uppercase; }
.login-card p { margin: 0 0 22px; color: var(--muted); }
.field { display: grid; gap: 6px; margin-bottom: 14px; }
.field label { font-size: .85rem; font-weight: 600; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); }
.field input, .field select, .field textarea {
  width: 100%; padding: 11px 12px; border: 2px solid #cfc6ad; background: #fff; border-radius: 6px;
}
.field input:focus, .field select:focus, .field textarea:focus { outline: none; border-color: var(--ink); }
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  padding: 11px 18px; border-radius: 6px; border: 2px solid var(--ink); background: var(--ink); color: #fff;
  font-weight: 700; letter-spacing: .02em; text-decoration: none;
}
.btn:hover { filter: brightness(1.15); }
.btn.red { background: var(--accent); border-color: var(--accent); }
.btn.ghost { background: transparent; color: var(--ink); }
.btn.small { padding: 6px 10px; font-size: .85rem; }
.btn.block { width: 100%; }
.btn:disabled { opacity: .5; cursor: default; }
.error { color: var(--accent); font-weight: 600; min-height: 1.3em; margin: 8px 0 0; }

/* ---------- top bar ---------- */
.topbar {
  display: flex; align-items: center; gap: 16px; flex-wrap: wrap;
  padding: 14px clamp(12px, 3vw, 28px); color: #f4efe0;
}
.brand { font-family: var(--serif); font-size: 1.5rem; font-weight: 700; letter-spacing: .04em; text-transform: uppercase; margin-right: auto; }
.tabs { display: flex; gap: 4px; background: rgba(255,255,255,.08); padding: 4px; border-radius: 999px; }
.tabs button { border: 0; background: transparent; color: #e9e3cf; padding: 8px 16px; border-radius: 999px; font-weight: 600; }
.tabs button[aria-selected="true"] { background: var(--board); color: var(--ink); }
.whoami { display: flex; align-items: center; gap: 10px; font-size: .9rem; }
.whoami button { background: transparent; border: 1px solid rgba(255,255,255,.35); color: #f4efe0; border-radius: 999px; padding: 6px 12px; }
.dot { width: 12px; height: 12px; border-radius: 50%; display: inline-block; flex: none; border: 2px solid rgba(255,255,255,.7); }

main { padding: 0 clamp(8px, 3vw, 28px) 40px; }

/* ---------- board ---------- */
.board-scroll { overflow-x: auto; padding-bottom: 8px; }
.board {
  --size: min(96vw, calc(100vh - 110px), 1000px);
  position: relative;
  width: max(var(--size), 640px); aspect-ratio: 1; margin: 0 auto;
  display: grid;
  grid-template-columns: 1.55fr repeat(9, 1fr) 1.55fr;
  grid-template-rows: 1.55fr repeat(9, 1fr) 1.55fr;
  background: var(--board); border: 3px solid var(--board-line);
  box-shadow: var(--shadow);
  container-type: inline-size;
}
.tile {
  position: relative; border: 1px solid var(--board-line); background: var(--board);
  padding: 0; overflow: hidden; display: flex; text-align: center;
  font-size: max(1.05cqw, 8px); line-height: 1.15;
  transition: transform .12s ease, box-shadow .12s ease;
}
.tile:hover, .tile:focus-visible { z-index: 3; transform: scale(1.06); box-shadow: 0 6px 18px rgba(0,0,0,.35); outline: none; }
.tile .band { flex: none; background: var(--c); }
.tile .label { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; padding: 4px 3px; gap: 2px; position: relative; z-index: 1; }
.tile .name { font-weight: 700; text-transform: uppercase; letter-spacing: .02em; word-break: break-word; hyphens: auto; }
.tile .sub { font-size: .85em; color: var(--muted); }
.tile .count { font-size: .9em; font-weight: 600; color: var(--muted); }
.tile.station .label::before { content: "🚂"; font-size: 1.6em; line-height: 1; }
.tile.landmark .label::before { content: "★"; font-size: 1.5em; line-height: 1; color: #8b7d55; }

/* band orientation per side */
.tile.side-bottom { flex-direction: column; } .tile.side-bottom .band { height: 22%; border-bottom: 1px solid var(--board-line); }
.tile.side-top    { flex-direction: column-reverse; } .tile.side-top .band { height: 22%; border-top: 1px solid var(--board-line); }
.tile.side-left   { flex-direction: row-reverse; } .tile.side-left .band { width: 22%; border-left: 1px solid var(--board-line); }
.tile.side-right  { flex-direction: row; } .tile.side-right .band { width: 22%; border-right: 1px solid var(--board-line); }
.tile.station .band, .tile.landmark .band { display: none; }
.tile.corner { background: #ece4cc; }
.tile.corner .band { display: none; }
.tile.corner .name { font-family: var(--serif); font-size: 1.35em; }

/* visited tiles show their latest photo */
.tile.visited .cover { position: absolute; inset: 0; background: center/cover no-repeat; opacity: .9; }
.tile.visited .label { background: linear-gradient(to top, rgba(0,0,0,.72), rgba(0,0,0,.15) 60%, transparent); color: #fff; justify-content: flex-end; }
.tile.visited .sub, .tile.visited .count { color: #f1ead3; }
.tile.visited.station .label::before, .tile.visited.landmark .label::before { content: none; }
.tile .badge {
  position: absolute; top: 3px; right: 3px; z-index: 2; min-width: 1.9em; height: 1.9em; padding: 0 .4em;
  border-radius: 999px; background: var(--accent); color: #fff; font-weight: 800; font-size: .95em;
  display: grid; place-items: center; border: 2px solid #fff; box-shadow: 0 1px 4px rgba(0,0,0,.4);
}
.tile .visitors { position: absolute; left: 3px; top: 3px; z-index: 2; display: flex; gap: 2px; }
.tile .visitors .dot { width: .9em; height: .9em; border-width: 1px; }

/* centre */
.centre {
  grid-area: 2 / 2 / 11 / 11; display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 2.2cqw; padding: 3cqw; text-align: center; border: 1px solid var(--board-line);
  position: relative; z-index: 5; pointer-events: none;
}
.centre > * { pointer-events: auto; }
.centre .title {
  font-family: var(--serif); font-weight: 800; text-transform: uppercase; letter-spacing: .06em;
  font-size: 6.4cqw; line-height: .95; color: #fff; background: var(--accent);
  padding: 1.6cqw 3.2cqw; border: .45cqw solid var(--board-line); transform: rotate(-8deg);
  box-shadow: .6cqw .6cqw 0 var(--board-line);
}
.centre .progress { width: min(60cqw, 100%); font-size: max(1.5cqw, 11px); font-weight: 700; }
.bar { height: max(1.1cqw, 8px); border-radius: 999px; background: #ddd3b6; overflow: hidden; margin-top: .6cqw; border: 1px solid var(--board-line); }
.bar > i { display: block; height: 100%; background: var(--accent); width: 0; transition: width .6s ease; }
.centre .actions { display: flex; gap: 1cqw; flex-wrap: wrap; justify-content: center; }
.centre .btn { font-size: max(1.4cqw, 11px); padding: max(.9cqw, 7px) max(1.8cqw, 12px); }
.legend { display: flex; gap: 1.2cqw; flex-wrap: wrap; justify-content: center; font-size: max(1.25cqw, 10px); }
.legend span { display: inline-flex; align-items: center; gap: .5cqw; }
.legend .dot { border-color: #fff; box-shadow: 0 0 0 1px var(--board-line); }
.strip { display: flex; gap: .8cqw; }
.strip img { width: 7cqw; height: 7cqw; object-fit: cover; border: 2px solid var(--board-line); border-radius: 4px; cursor: pointer; background: #ddd; }

/* route overlay */
.route { position: absolute; inset: 0; width: 100%; height: 100%; pointer-events: none; z-index: 4; }
.route path { fill: none; stroke: var(--accent); stroke-width: .45cqw; stroke-linecap: round; stroke-linejoin: round; stroke-dasharray: 1.4cqw 1cqw; animation: march 1.2s linear infinite; filter: drop-shadow(0 1px 1px rgba(0,0,0,.45)); }
.route circle { fill: #fff; stroke: var(--accent); stroke-width: .3cqw; }
.route text { font: 800 1.15cqw var(--sans); fill: var(--accent); text-anchor: middle; dominant-baseline: central; }
@keyframes march { to { stroke-dashoffset: -2.4cqw; } }

/* ---------- panels ---------- */
.panel { background: var(--board); border: 3px solid var(--board-line); border-radius: 6px; box-shadow: var(--shadow); max-width: 1200px; margin: 0 auto; }
.panel-head { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; padding: 14px 16px; border-bottom: 2px solid var(--board-line); }
.panel-head h2 { font-family: var(--serif); text-transform: uppercase; letter-spacing: .04em; margin: 0 auto 0 0; font-size: 1.35rem; }
.panel-head select { padding: 7px 10px; border: 2px solid #cfc6ad; border-radius: 6px; background: #fff; }

.journey { display: grid; grid-template-columns: minmax(0, 1.6fr) minmax(280px, 1fr); min-height: 70vh; }
#map { min-height: 70vh; border-right: 2px solid var(--board-line); background: #dfe7e2; }
.timeline { overflow-y: auto; max-height: 78vh; padding: 8px 0; }
.day { font-family: var(--serif); font-weight: 700; padding: 12px 16px 4px; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); font-size: .9rem; }
.step { display: grid; grid-template-columns: 34px 64px 1fr; gap: 10px; align-items: center; padding: 8px 16px; cursor: pointer; border-left: 4px solid transparent; }
.step:hover, .step.active { background: #ebe3c8; border-left-color: var(--accent); }
.step .n { width: 30px; height: 30px; border-radius: 50%; background: var(--accent); color: #fff; font-weight: 800; display: grid; place-items: center; font-size: .85rem; }
.step img { width: 64px; height: 64px; object-fit: cover; border-radius: 6px; border: 2px solid var(--board-line); }
.step .t { font-size: .9rem; } .step .t b { display: block; } .step .t small { color: var(--muted); }
.empty { padding: 40px 20px; text-align: center; color: var(--muted); }

.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); gap: 14px; padding: 16px; }
.card { background: var(--card); border: 2px solid var(--board-line); border-radius: 8px; overflow: hidden; cursor: pointer; display: flex; flex-direction: column; transition: transform .12s ease; }
.card:hover { transform: translateY(-3px); }
.card .band { height: 8px; }
.card img { width: 100%; aspect-ratio: 1; object-fit: cover; display: block; background: #ddd; }
.card .meta { padding: 8px 10px; font-size: .85rem; }
.card .meta b { display: block; font-size: .9rem; }
.card .meta small { color: var(--muted); display: flex; align-items: center; gap: 6px; }

/* ---------- dialogs ---------- */
dialog { border: 3px solid var(--board-line); border-radius: 8px; padding: 0; background: var(--board); width: min(760px, 96vw); max-height: 92vh; box-shadow: var(--shadow); }
dialog::backdrop { background: rgba(5,20,14,.72); }
.dlg-head { display: flex; align-items: stretch; border-bottom: 3px solid var(--board-line); }
.dlg-head .band { width: 14px; flex: none; }
.dlg-head .txt { padding: 14px 16px; flex: 1; }
.dlg-head h3 { margin: 0; font-family: var(--serif); text-transform: uppercase; letter-spacing: .03em; font-size: 1.4rem; }
.dlg-head small { color: var(--muted); }
.dlg-head .x { border: 0; background: transparent; font-size: 1.6rem; padding: 0 16px; }
.dlg-body { padding: 16px; overflow-y: auto; max-height: calc(92vh - 80px); }
.dlg-body .grid { padding: 0; margin-top: 14px; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); }
.row { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; }
.preview { width: 100%; max-height: 300px; object-fit: contain; background: #e8e0c6; border-radius: 6px; border: 2px dashed #cfc6ad; margin-bottom: 12px; }
.notes { font-size: .9rem; background: #fff; border: 1px solid #ddd3b6; border-radius: 6px; padding: 10px 12px; margin-bottom: 12px; display: grid; gap: 4px; }
.ok { color: #1d7a3e; font-weight: 600; } .warn { color: #a2650a; font-weight: 600; }

.lightbox { width: min(1100px, 98vw); }
.lb { display: grid; grid-template-columns: minmax(0, 1fr) 300px; }
.lb-img { background: #111; display: grid; place-items: center; min-height: 50vh; position: relative; }
.lb-img img { max-width: 100%; max-height: 82vh; display: block; }
.lb-img .nav { position: absolute; top: 50%; transform: translateY(-50%); background: rgba(255,255,255,.85); border: 0; width: 42px; height: 42px; border-radius: 50%; font-size: 1.3rem; }
.lb-img .prev { left: 10px; } .lb-img .next { right: 10px; }
.lb-side { padding: 16px; display: grid; gap: 12px; align-content: start; font-size: .92rem; overflow-y: auto; max-height: 86vh; }
.lb-side h3 { margin: 0; font-family: var(--serif); text-transform: uppercase; font-size: 1.25rem; }
.lb-side dl { margin: 0; display: grid; grid-template-columns: auto 1fr; gap: 6px 10px; }
.lb-side dt { color: var(--muted); font-weight: 600; } .lb-side dd { margin: 0; }
.pill { display: inline-block; padding: 2px 8px; border-radius: 999px; font-size: .78rem; font-weight: 700; background: #e1f3e6; color: #1d7a3e; }
.pill.grey { background: #ece6d2; color: var(--muted); }

.toast { position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%); background: var(--ink); color: #fff; padding: 12px 18px; border-radius: 8px; box-shadow: var(--shadow); z-index: 1000; font-weight: 600; }

.leaflet-container { font-family: var(--sans); }
.num-marker { background: var(--accent); color: #fff; border: 2px solid #fff; border-radius: 50%; display: grid !important; place-items: center; font-weight: 800; font-size: 12px; box-shadow: 0 1px 4px rgba(0,0,0,.5); }
.sq-marker { border: 2px solid #1c1c1c; border-radius: 3px; }

.fab { display: none; position: fixed; right: 18px; bottom: 18px; z-index: 50; width: 62px; height: 62px; border-radius: 50%;
  border: 3px solid #fff; background: var(--accent); color: #fff; font-size: 1.6rem; box-shadow: var(--shadow); }
@media (max-width: 700px) { .fab { display: block; } .topbar { gap: 10px; } }

@media (max-width: 820px) {
  .journey { grid-template-columns: 1fr; }
  #map { min-height: 55vh; border-right: 0; border-bottom: 2px solid var(--board-line); }
  .lb { grid-template-columns: 1fr; }
  .brand { font-size: 1.2rem; width: 100%; }
}
