/* Base system: tokens, layout, shared components. View-specific rules live in css/views/*.css.
   Direction: a quiet railway timetable. Paper-grey ground, ink text, serif headings,
   monospaced figures for every time and distance, three restrained accents. */

:root {
  --paper: #f3f1ec;
  --paper-2: #ebe8e1;
  --card: #fbfaf7;
  --ink: #1f2328;
  --ink-2: #4a5059;
  --ink-3: #7b818a;
  --rule: #d9d5cc;
  --rule-strong: #b9b3a6;

  --transit: #2f6f8f;      /* trains, transfers, routes */
  --transit-soft: #e3edf1;
  --match: #8a2f3a;        /* football */
  --match-soft: #f3e4e5;
  --got: #9c7b3c;          /* Game of Thrones */
  --got-soft: #f2ead9;
  --ok: #3d7a57;
  --ok-soft: #e2efe6;
  --warn: #a8641c;
  --warn-soft: #f6eadb;
  --bad: #a33a2e;
  --bad-soft: #f5e1de;
  --muted-soft: #ecebe7;

  --font-display: "Songti SC", "STSong", "Noto Serif SC", "Source Han Serif SC", "Noto Serif CJK SC", serif;
  --font-body: "PingFang SC", "Hiragino Sans GB", "Noto Sans SC", "Source Han Sans SC", "Microsoft YaHei", sans-serif;
  --font-figure: "SF Mono", "JetBrains Mono", "Menlo", "Consolas", ui-monospace, monospace;

  --r-s: 4px;
  --r-m: 8px;
  --r-l: 12px;
  --shadow: 0 1px 2px rgba(31, 35, 40, .06), 0 6px 18px rgba(31, 35, 40, .06);
  --panel-w: clamp(300px, 34vw, 440px);
  --topbar-h: auto;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --paper: #16181b; --paper-2: #1d2024; --card: #202328; --ink: #e8e6e1; --ink-2: #b8b5ae; --ink-3: #8b8984;
    --rule: #33373d; --rule-strong: #4a4f56;
    --transit: #7fb3cc; --transit-soft: #1f3540; --match: #d98a94; --match-soft: #3a2428; --got: #d2b071; --got-soft: #3a3121;
    --ok: #7fc39b; --ok-soft: #1f3529; --warn: #e0a560; --warn-soft: #3b2c1b; --bad: #ec8a7e; --bad-soft: #3d2320; --muted-soft: #2a2d31;
    --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 6px 18px rgba(0, 0, 0, .25);
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --paper: #16181b; --paper-2: #1d2024; --card: #202328; --ink: #e8e6e1; --ink-2: #b8b5ae; --ink-3: #8b8984;
  --rule: #33373d; --rule-strong: #4a4f56;
  --transit: #7fb3cc; --transit-soft: #1f3540; --match: #d98a94; --match-soft: #3a2428; --got: #d2b071; --got-soft: #3a3121;
  --ok: #7fc39b; --ok-soft: #1f3529; --warn: #e0a560; --warn-soft: #3b2c1b; --bad: #ec8a7e; --bad-soft: #3d2320; --muted-soft: #2a2d31;
  --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 6px 18px rgba(0, 0, 0, .25);
  color-scheme: dark;
}

*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--paper); color: var(--ink);
  font: 14px/1.55 var(--font-body); letter-spacing: .01em;
  background-image: radial-gradient(rgba(31, 35, 40, .035) 1px, transparent 1px);
  background-size: 18px 18px;
}
h1, h2, h3, h4 { font-family: var(--font-display); font-weight: 700; margin: 0; line-height: 1.3; letter-spacing: .02em; }
h2 { font-size: 20px; }
h3 { font-size: 16px; }
h4 { font-size: 14px; }
p { margin: .4em 0; }
a { color: var(--transit); text-underline-offset: 2px; }
a.ext::after { content: " ↗"; font-size: .85em; opacity: .7; }
button, input, select, textarea { font: inherit; color: inherit; }
:focus-visible { outline: 2px solid var(--transit); outline-offset: 2px; border-radius: 3px; }
.fig, time, .num { font-family: var(--font-figure); font-variant-numeric: tabular-nums; letter-spacing: 0; }
.muted { color: var(--ink-3); }
.small { font-size: 12px; }
.hidden { display: none !important; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.skip-link { position: absolute; left: -999px; top: 8px; background: var(--card); padding: 6px 10px; z-index: 2000; }
.skip-link:focus { left: 8px; }
.noscript { padding: 24px; }

/* ---------- top bar ---------- */
.topbar {
  display: grid; grid-template-columns: minmax(0, 1fr) auto auto; gap: 8px 12px; align-items: center;
  padding: 14px 20px 10px; border-bottom: 1px solid var(--rule); background: var(--card);
}
.topbar__title { display: flex; align-items: baseline; gap: 12px; flex-wrap: wrap; }
.topbar__title h1 { font-size: 22px; }
.topbar__dates { color: var(--ink-2); font-family: var(--font-figure); font-size: 13px; }
.topbar__meta { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; justify-content: flex-end; }
.routeline { grid-column: 1 / -1; display: flex; align-items: center; gap: 0; overflow-x: auto; padding: 4px 0 2px; scrollbar-width: thin; }
.routeline__stop { display: flex; flex-direction: column; align-items: center; min-width: 104px; position: relative; text-align: center; white-space: nowrap; }
.routeline__stop::before { content: ""; position: absolute; top: 9px; left: -50%; right: 50%; height: 3px; background: var(--transit); opacity: .55; }
.routeline__stop:first-child::before { display: none; }
.routeline__stop--day::before { background: repeating-linear-gradient(90deg, var(--transit) 0 5px, transparent 5px 9px); }
.routeline__dot { width: 20px; height: 20px; border-radius: 50%; border: 3px solid var(--transit); background: var(--card); z-index: 1; display: grid; place-items: center; font-size: 10px; font-weight: 700; color: var(--transit); }
.routeline__stop--day .routeline__dot { width: 14px; height: 14px; margin: 3px 0; border-width: 2px; }
.routeline__name { font-size: 13px; font-weight: 600; margin-top: 3px; }
.routeline__sub { font-size: 11px; color: var(--ink-3); font-family: var(--font-figure); }
.routeline__stop button { all: unset; cursor: pointer; display: contents; }

.chip {
  display: inline-flex; align-items: center; gap: 6px; padding: 3px 9px; border-radius: 999px;
  border: 1px solid var(--rule); background: var(--card); font-size: 12px; white-space: nowrap; color: var(--ink-2);
}
.chip--match { border-color: color-mix(in srgb, var(--match) 40%, var(--rule)); color: var(--match); background: var(--match-soft); }
.chip--got { border-color: color-mix(in srgb, var(--got) 40%, var(--rule)); color: var(--got); background: var(--got-soft); }
.chip--warn { color: var(--warn); background: var(--warn-soft); border-color: transparent; }
.chip--bad { color: var(--bad); background: var(--bad-soft); border-color: transparent; }
.chip--ok { color: var(--ok); background: var(--ok-soft); border-color: transparent; }
button.chip { cursor: pointer; }
button.chip:hover { border-color: var(--rule-strong); }

/* ---------- tabs ---------- */
.tabs {
  position: sticky; top: 0; z-index: 900; display: flex; gap: 2px; padding: 0 12px;
  background: color-mix(in srgb, var(--paper) 92%, transparent); backdrop-filter: blur(6px);
  border-bottom: 1px solid var(--rule); overflow-x: auto; scrollbar-width: none;
}
.tabs::-webkit-scrollbar { display: none; }
.tab {
  all: unset; cursor: pointer; padding: 10px 12px 9px; font-size: 14px; color: var(--ink-2); white-space: nowrap;
  border-bottom: 2px solid transparent; display: inline-flex; gap: 6px; align-items: center;
}
.tab:hover { color: var(--ink); }
.tab[aria-selected="true"] { color: var(--ink); border-bottom-color: var(--ink); font-weight: 600; }
.tab .count { font-family: var(--font-figure); font-size: 11px; padding: 0 6px; border-radius: 999px; background: var(--muted-soft); color: var(--ink-2); }
.tab .count--bad { background: var(--bad-soft); color: var(--bad); }
.tab:focus-visible { outline-offset: -2px; }

.notice-bar:empty { display: none; }
.notice-bar { padding: 8px 20px; display: grid; gap: 6px; }
.notice { padding: 8px 12px; border-radius: var(--r-m); background: var(--warn-soft); color: var(--warn); font-size: 13px; display: flex; gap: 10px; align-items: center; }
.notice--bad { background: var(--bad-soft); color: var(--bad); }
.notice button { margin-left: auto; }

/* ---------- workspace ---------- */
.workspace { display: grid; grid-template-columns: var(--panel-w) minmax(0, 1fr); min-height: calc(100vh - 140px); }
.panel { border-right: 1px solid var(--rule); padding: 16px 18px 40px; overflow-y: auto; max-height: calc(100vh - 44px); max-height: calc(100dvh - 44px); position: sticky; top: 44px; scrollbar-gutter: stable; overscroll-behavior: contain; }
.panel:focus { outline: none; }
.mapcol { min-width: 0; display: flex; flex-direction: column; }
.map-wrap { position: sticky; top: 44px; z-index: 1; height: min(64vh, 720px); height: min(64dvh, 720px); min-height: 380px; display: flex; flex-direction: column; border-bottom: 1px solid var(--rule); background: var(--paper-2); }
.map-head { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; padding: 8px 12px; background: var(--card); border-bottom: 1px solid var(--rule); min-height: 44px; }
.map-head h2 { font-size: 16px; margin-right: auto; }
.map { flex: 1; min-height: 0; }
.below-map { padding: 14px 18px 48px; background: var(--paper); position: relative; z-index: 2; }

@media (max-width: 599px), (max-width: 1024px) and (orientation: portrait) {
  /* phone order: map, then the view's content, then the table under the map */
  .workspace { display: flex; flex-direction: column; }
  .mapcol { display: contents; }
  .map-wrap { order: 1; }
  .panel { position: static; max-height: none; border-right: 0; order: 2; padding: 14px 16px 24px; }
  .below-map { order: 3; border-top: 1px solid var(--rule); }
  .map-wrap { position: relative; top: 0; height: 46vh; height: 46dvh; min-height: 280px; }
  .below-map { padding: 12px 16px 24px; }
}

/* ---------- generic pieces ---------- */
.section { margin: 0 0 20px; }
.section > h2, .section > h3 { margin-bottom: 8px; }
.section-head { display: flex; align-items: baseline; gap: 10px; flex-wrap: wrap; margin-bottom: 8px; }
.section-head h2, .section-head h3 { margin-right: auto; }
.card { background: var(--card); border: 1px solid var(--rule); border-radius: var(--r-l); padding: 12px 14px; }
.card + .card { margin-top: 10px; }
.card.is-active { border-color: var(--ink-2); box-shadow: var(--shadow); }
.card.is-hover { border-color: var(--transit); }
.stack { display: grid; gap: 10px; }
.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.spacer { flex: 1; }
.kv { display: grid; grid-template-columns: max-content 1fr; gap: 4px 12px; font-size: 13px; }
.kv dt { color: var(--ink-3); }
.kv dd { margin: 0; }
.lede { color: var(--ink-2); font-size: 13px; }
hr.rule { border: 0; border-top: 1px dashed var(--rule-strong); margin: 12px 0; }

.btn {
  display: inline-flex; align-items: center; gap: 6px; padding: 5px 11px; border-radius: var(--r-m);
  border: 1px solid var(--rule-strong); background: var(--card); cursor: pointer; font-size: 13px; line-height: 1.4; color: var(--ink);
}
.btn:hover { background: var(--paper-2); }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn--primary { background: var(--ink); color: var(--card); border-color: var(--ink); }
.btn--primary:hover { background: var(--ink-2); }
.btn--ghost { border-color: transparent; background: transparent; color: var(--ink-2); }
.btn--ghost:hover { background: var(--paper-2); color: var(--ink); }
.btn--danger { color: var(--bad); border-color: color-mix(in srgb, var(--bad) 40%, var(--rule)); }
.btn--small { padding: 2px 8px; font-size: 12px; }
.btn[aria-pressed="true"] { background: var(--ink); color: var(--card); border-color: var(--ink); }

.seg { display: inline-flex; border: 1px solid var(--rule-strong); border-radius: var(--r-m); overflow: hidden; }
.seg button { all: unset; cursor: pointer; padding: 4px 10px; font-size: 12px; color: var(--ink-2); border-right: 1px solid var(--rule); }
.seg button:last-child { border-right: 0; }
.seg button[aria-pressed="true"] { background: var(--ink); color: var(--card); }
.seg button:focus-visible { outline: 2px solid var(--transit); outline-offset: -2px; }

select.input, input.input, textarea.input {
  border: 1px solid var(--rule-strong); border-radius: var(--r-s); background: var(--card); padding: 4px 8px; font-size: 13px; min-width: 0;
}
input.input[type="time"] { font-family: var(--font-figure); }
textarea.input { width: 100%; min-height: 64px; resize: vertical; }
label.field { display: grid; gap: 3px; font-size: 12px; color: var(--ink-3); }

/* status pills: quiet outline, colour carries meaning, never shouting */
.pill {
  display: inline-flex; align-items: center; gap: 4px; padding: 0 6px; border-radius: 999px; font-size: 11px; line-height: 18px;
  border: 1px solid currentColor; white-space: nowrap; vertical-align: 1px; font-weight: 500;
}
.pill--official_confirmed, .pill--official_listed { color: var(--ok); }
.pill--third_party { color: var(--warn); }
.pill--assumption { color: var(--ink-3); border-style: dashed; }
.pill--unchecked { color: var(--bad); border-style: dotted; }
.pill__recheck { font-size: 10px; padding-left: 4px; border-left: 1px solid currentColor; opacity: .8; }
.pill--compact { padding: 0 4px; }
.fact__value { font-family: var(--font-figure); font-variant-numeric: tabular-nums; }
.fact--unknown .fact__value { color: var(--bad); font-family: var(--font-body); }
.fact-block { display: grid; gap: 2px; padding: 6px 0; border-top: 1px dashed var(--rule); }
.fact-block:first-child { border-top: 0; }
.fact-block__label { font-size: 12px; color: var(--ink-3); }
.fact-block__src summary { cursor: pointer; font-size: 12px; color: var(--ink-3); }
ul.sources { margin: 4px 0 0; padding-left: 18px; font-size: 12px; }
ul.sources li { margin: 2px 0; }

.badge-got { display: inline-flex; align-items: center; gap: 3px; font-size: 11px; color: var(--got); font-weight: 600; }
.badge-got::before { content: ""; width: 8px; height: 8px; border-radius: 50%; border: 2px solid var(--got); }
.badge-got--related::before { border-style: dashed; }
.badge-got--disputed { color: var(--ink-3); }
.badge-got--disputed::before { border-color: var(--ink-3); border-style: dotted; }
.badge-match { color: var(--match); font-weight: 600; font-size: 12px; }
.badge-removed { font-size: 11px; color: var(--bad); text-decoration: line-through; }

.sev { display: inline-block; width: 8px; height: 8px; border-radius: 50%; flex: none; margin-top: 6px; }
.sev--error { background: var(--bad); }
.sev--warn { background: var(--warn); }
.sev--info { background: var(--ink-3); }

/* ---------- distance table ---------- */
.dt-head { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; margin-bottom: 8px; }
.dt-head h3 { margin-right: auto; }
.dt-note { font-size: 12px; color: var(--ink-3); margin: 4px 0 10px; }
.dt-scroll { overflow-x: auto; border: 1px solid var(--rule); border-radius: var(--r-l); background: var(--card); }
table.dt { width: 100%; border-collapse: collapse; font-size: 13px; min-width: 720px; }
table.dt th { text-align: left; font-weight: 600; font-size: 12px; color: var(--ink-3); padding: 8px 10px; border-bottom: 1px solid var(--rule-strong); background: var(--paper-2); position: sticky; top: 0; }
table.dt td { padding: 7px 10px; border-bottom: 1px solid var(--rule); vertical-align: top; }
table.dt tr:last-child td { border-bottom: 0; }
table.dt tbody tr { cursor: pointer; }
table.dt tbody tr:hover, table.dt tbody tr.is-hover { background: var(--transit-soft); }
table.dt tbody tr.is-selected { background: color-mix(in srgb, var(--transit-soft) 60%, var(--card)); box-shadow: inset 3px 0 0 var(--transit); }
table.dt tbody tr.is-inroute td:first-child { box-shadow: inset 3px 0 0 var(--ink-2); }
table.dt .dt-dest { display: flex; gap: 8px; align-items: flex-start; }
table.dt .dt-dest strong { font-weight: 600; }
table.dt .dt-dist, table.dt .dt-time { white-space: nowrap; font-family: var(--font-figure); font-variant-numeric: tabular-nums; }
table.dt .dt-actions { white-space: nowrap; }
.cat-dot { width: 22px; height: 22px; border-radius: 6px; display: inline-grid; place-items: center; font-size: 11px; font-weight: 700; flex: none; background: var(--muted-soft); color: var(--ink-2); }

@media (max-width: 599px), (max-width: 1024px) and (orientation: portrait) {
  table.dt { min-width: 0; }
  table.dt thead { display: none; }
  table.dt, table.dt tbody, table.dt tr, table.dt td { display: block; }
  table.dt tr { padding: 8px 10px; border-bottom: 1px solid var(--rule); display: grid; grid-template-columns: 1fr auto; gap: 2px 10px; }
  table.dt td { border: 0; padding: 0; }
  table.dt td.dt-col-dest { grid-column: 1 / -1; }
  table.dt td.dt-col-advice, table.dt td.dt-col-actions { grid-column: 1 / -1; }
}

/* ---------- map markers ---------- */
.mk-wrap { background: none; border: 0; }
.mk {
  width: 26px; height: 26px; border-radius: 50%; display: grid; place-items: center; font-size: 12px; font-weight: 700;
  background: var(--card); color: var(--ink-2); border: 2px solid var(--ink-3); box-shadow: 0 1px 3px rgba(0, 0, 0, .25);
  transition: transform .12s ease, box-shadow .12s ease; font-family: var(--font-body); cursor: pointer;
}
.mk--station, .mk--bus-station { border-radius: 6px; border-color: var(--transit); color: var(--transit); }
.mk--transit { width: 20px; height: 20px; font-size: 10px; border-radius: 5px; border-color: var(--transit); color: var(--transit); opacity: .85; }
.mk--airport { border-radius: 6px; border-color: var(--transit); color: var(--card); background: var(--transit); }
.mk--stadium { border-color: var(--match); color: var(--card); background: var(--match); }
.mk--stay-area { border-style: dashed; border-color: var(--got); color: var(--got); }
.mk--got-core { box-shadow: 0 0 0 3px var(--got-soft), 0 0 0 5px var(--got); }
.mk--got-related { box-shadow: 0 0 0 3px var(--got-soft), 0 0 0 4px color-mix(in srgb, var(--got) 60%, transparent); }
.mk--ordered { background: var(--ink); color: var(--card); border-color: var(--ink); }
.mk--origin { background: var(--transit); color: var(--card); border-color: var(--transit); }
.mk--dim { opacity: .45; transform: scale(.82); }
.mk--off { opacity: .35; filter: grayscale(1); }
.mk.is-hover { transform: scale(1.25); z-index: 1000; }
.mk.is-selected { transform: scale(1.3); box-shadow: 0 0 0 3px var(--card), 0 0 0 6px var(--transit); }
.mk-label.leaflet-tooltip {
  background: color-mix(in srgb, var(--card) 88%, transparent); border: 0; box-shadow: none; padding: 0 4px; border-radius: 3px;
  font: 600 12px/1.4 var(--font-body); color: var(--ink);
}
.mk-label.leaflet-tooltip::before { display: none; }
.tip.leaflet-tooltip { font: 12px/1.4 var(--font-body); border-radius: 4px; }
.map-buttons a { font-size: 16px; line-height: 30px; text-decoration: none; color: var(--ink); background: var(--card); }
.leaflet-container { font-family: var(--font-body); background: var(--paper-2); }
.leaflet-control-attribution { font-size: 10px; }
.map-legend { position: absolute; left: 10px; bottom: 28px; z-index: 600; background: color-mix(in srgb, var(--card) 94%, transparent); border: 1px solid var(--rule); border-radius: var(--r-m); padding: 6px 10px; font-size: 11px; display: grid; gap: 3px; max-width: 260px; }
.map-legend i { display: inline-block; width: 22px; height: 0; border-top: 3px solid var(--transit); vertical-align: middle; margin-right: 6px; }
.map-legend i.dash { border-top-style: dashed; border-color: #5d5a8c; }
.map-legend i.dot { border-top-style: dotted; border-color: #7a6a55; }
.map-legend i.sch { border-top: 2px dashed #8a8f98; }

/* ---------- place card (over the map) ---------- */
.place-card {
  position: absolute; z-index: 1001; right: 12px; top: 56px; width: min(380px, calc(100% - 24px)); max-height: calc(100% - 70px); overflow-y: auto;
  background: var(--card); border: 1px solid var(--rule); border-radius: var(--r-l); box-shadow: var(--shadow); padding: 12px 14px 14px;
}
.map-wrap { position: sticky; }
.place-card__head { display: flex; gap: 8px; align-items: flex-start; }
.place-card__head h3 { margin-right: auto; }
.place-card__local { color: var(--ink-3); font-size: 12px; }
.place-card__actions { display: flex; gap: 6px; flex-wrap: wrap; margin: 10px 0 4px; }
.place-card .hours-table { width: 100%; font-size: 12px; border-collapse: collapse; }
.place-card .hours-table td { padding: 3px 0; border-bottom: 1px dashed var(--rule); vertical-align: top; }
@media (max-width: 599px), (max-width: 1024px) and (orientation: portrait) {
  .place-card { position: fixed; left: 0; right: 0; bottom: 0; top: auto; width: auto; max-height: 62vh; border-radius: var(--r-l) var(--r-l) 0 0; z-index: 1500; }
}

/* ---------- timeline (shared by day view and transport impact) ---------- */
.tl { list-style: none; margin: 0; padding: 0; position: relative; }
.tl::before { content: ""; position: absolute; left: 52px; top: 6px; bottom: 6px; width: 2px; background: var(--rule); }
.tl > li { display: grid; grid-template-columns: 44px 18px minmax(0, 1fr); gap: 0 6px; align-items: start; padding: 3px 0; position: relative; }
.tl__time { font-family: var(--font-figure); font-size: 12px; color: var(--ink-2); text-align: right; padding-top: 2px; }
.tl__dot { width: 12px; height: 12px; border-radius: 50%; background: var(--card); border: 2px solid var(--ink-3); margin: 4px 0 0 1px; z-index: 1; }
.tl__body { min-width: 0; }
.tl__title { font-weight: 600; }
.tl__sub { font-size: 12px; color: var(--ink-3); }
.tl > li.tl--travel .tl__dot { width: 6px; height: 6px; border: 0; background: var(--rule-strong); margin: 7px 0 0 4px; }
.tl > li.tl--travel .tl__body { font-size: 12px; color: var(--ink-3); font-family: var(--font-body); }
.tl > li.tl--train .tl__dot { border-color: var(--transit); background: var(--transit); border-radius: 3px; }
.tl > li.tl--event .tl__dot { border-color: var(--match); background: var(--match); }
.tl > li.tl--visit.is-got .tl__dot { border-color: var(--got); }
.tl > li.tl--deadline .tl__dot { border-color: var(--bad); }
.tl > li.is-off { opacity: .5; }
.tl > li.is-off .tl__title { text-decoration: line-through; }
.tl > li.is-hover .tl__body { color: var(--transit); }
.tl .issue { display: flex; gap: 6px; font-size: 12px; margin-top: 2px; }
.tl .issue--error { color: var(--bad); }
.tl .issue--warn { color: var(--warn); }
.tl .issue--info { color: var(--ink-3); }

/* reduced motion */
@media (prefers-reduced-motion: reduce) { * { transition: none !important; animation: none !important; } }

/* page-load reveal: one quiet staggered entrance */
@keyframes rise { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }
.reveal > * { animation: rise .35s ease both; }
.reveal > *:nth-child(2) { animation-delay: .04s; }
.reveal > *:nth-child(3) { animation-delay: .08s; }
.reveal > *:nth-child(4) { animation-delay: .12s; }
.reveal > *:nth-child(5) { animation-delay: .16s; }

/* settings popover in the top bar */
.settings { position: relative; }
.settings > summary { list-style: none; cursor: pointer; }
.settings > summary::-webkit-details-marker { display: none; }
.settings__body { position: absolute; right: 0; top: calc(100% + 6px); z-index: 1200; width: 280px; display: grid; gap: 8px; box-shadow: var(--shadow); }

.legend-toggle { position: relative; }
.legend-toggle > summary { list-style: none; cursor: pointer; }
.legend-toggle > summary::-webkit-details-marker { display: none; }
.legend-toggle .map-legend { position: absolute; right: 0; left: auto; top: calc(100% + 6px); bottom: auto; z-index: 1200; width: 240px; }

/* calmer basemap: desaturate tiles only (markers and routes keep full colour) */
.leaflet-tile-pane { filter: saturate(.45) contrast(.92) brightness(1.03); }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) .leaflet-tile-pane { filter: saturate(.3) brightness(.62) contrast(1.1); } }
:root[data-theme="dark"] .leaflet-tile-pane { filter: saturate(.3) brightness(.62) contrast(1.1); }

/* ---------- touch targets: phones and other coarse pointers ---------- */
@media (max-width: 599px), (max-width: 1024px) and (orientation: portrait), (pointer: coarse) {
  .btn, .btn--small, button.chip, label.chip, .seg button, .tab { min-height: 40px; }
  .tab { box-sizing: border-box; }
  .btn, .btn--small, .seg button { display: inline-flex; align-items: center; justify-content: center; }
  .seg button { padding-left: 12px; padding-right: 12px; }
  summary { min-height: 40px; padding-top: 8px; padding-bottom: 8px; box-sizing: border-box; cursor: pointer; }
  select.input, input.input:not([type="checkbox"]), select.input option { min-height: 40px; }
  input[type="checkbox"], input[type="radio"] { min-width: 20px; min-height: 20px; }
  table.dt td.dt-col-actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 6px; white-space: normal; }
  table.dt .dt-actions .btn { flex: 1 1 auto; min-width: 5.5em; }
  /* a whole checklist row is the tap target, not just the small box */
  .todo-item__check { min-height: 40px; align-items: center; padding: 4px 0; }
}

/* checklist rows: the label spans the full row on every screen size */
.todo-item__check { width: 100%; }

/* ---------- phones and tablets ---------- */
/* Compact header: title + settings on one row, chips in one swipeable strip below. */
@media (max-width: 1279px), (max-height: 600px) {
  .topbar { grid-template-columns: minmax(0, 1fr) auto; padding: 10px 16px 8px; gap: 6px 10px; }
  .topbar__title { gap: 2px 10px; }
  .topbar__title h1 { font-size: 18px; }
  .topbar__dates { font-size: 12px; }
  .topbar__meta { grid-column: 1 / -1; grid-row: 2; justify-content: flex-start; flex-wrap: nowrap; overflow-x: auto; scrollbar-width: none; margin: 0 -16px; padding: 0 16px 2px; -webkit-overflow-scrolling: touch; }
  .topbar__meta::-webkit-scrollbar { display: none; }
  .topbar__meta > * { flex: none; }
  .routeline { grid-row: 3; }
  .routeline__stop { min-width: 112px; }
}
/* Phones and short (landscape) screens: no room for the route strip; the overview has it. */
@media (max-width: 599px), (max-height: 500px) {
  .routeline { display: none; }
  .topbar__dates { display: block; width: 100%; }
}
/* Phones held sideways: map and content side by side, header kept to the essentials. */
@media (orientation: landscape) and (max-height: 500px) {
  :root { --panel-w: clamp(260px, 42vw, 380px); }
  .topbar { padding: 6px 12px; }
  .topbar__title h1 { font-size: 16px; }
  .topbar__dates { display: inline; width: auto; }
  .map-wrap { height: calc(100vh - 44px); height: calc(100dvh - 44px); min-height: 220px; }
  .map-head { padding: 4px 10px; min-height: 36px; }
  .map-head h2 { font-size: 14px; }
  .panel { padding: 10px 12px 24px; }
  .place-card { top: 44px; max-height: calc(100% - 52px); }
}

/* iOS: inputs under 16px make Safari zoom the page on focus. */
@media (pointer: coarse) {
  input, select, textarea, select.input, input.input, textarea.input { font-size: 16px; }
}
/* Touch: no grey tap flash, no double-tap zoom delay on controls. */
button, a, summary, label, .tab, .chip, .mk { -webkit-tap-highlight-color: transparent; touch-action: manipulation; }
/* Notch / home indicator on iPhone and iPad. */
body { padding-left: env(safe-area-inset-left); padding-right: env(safe-area-inset-right); }
.below-map { padding-bottom: calc(48px + env(safe-area-inset-bottom)); }
@media (max-width: 599px), (max-width: 1024px) and (orientation: portrait) {
  .place-card { padding-bottom: calc(14px + env(safe-area-inset-bottom)); }
  .settings__body { right: 0; left: auto; width: min(300px, calc(100vw - 32px)); }
}

/* Map header on small screens: one row, title truncates, the map keeps its height. */
@media (max-width: 599px), (max-width: 1024px) and (orientation: portrait), (max-height: 500px) {
  .map-head { flex-wrap: nowrap; gap: 6px; padding: 6px 10px; min-height: 40px; }
  .map-head h2 { flex: 1 1 auto; min-width: 0; font-size: 14px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
  .map-head .seg button { min-height: 34px; padding: 0 9px; font-size: 12px; white-space: nowrap; }
  .map-head .legend-toggle > summary { min-height: 34px; padding: 0 9px; display: inline-flex; align-items: center; }
  .days-mapctl { display: flex; align-items: center; gap: 6px; }
  .days-mapnote { display: none; }
}
@media (max-width: 599px), (max-width: 1024px) and (orientation: portrait) {
  .map-wrap { height: auto; min-height: 0; }
  .map { flex: none; height: 44vh; height: 44dvh; min-height: 240px; }
}
@media (max-width: 1024px) and (orientation: portrait) and (min-width: 600px) {
  .map { height: 50vh; height: 50dvh; max-height: 640px; }
}
/* Phones held sideways: keep the header to one line and the tabs low. */
@media (orientation: landscape) and (max-height: 500px) {
  .topbar__meta { display: none; }
  .tab { min-height: 36px; padding-top: 6px; padding-bottom: 6px; }
  .map-wrap { height: calc(100vh - 40px); height: calc(100dvh - 40px); }
}

/* ---------- device fit: layering, card, touch tables ---------- */
/* Single column: the map scrolls away with the page and sits above the content below it. */
@media (max-width: 599px), (max-width: 1024px) and (orientation: portrait) {
  .map-wrap { position: relative; top: auto; z-index: 3; }
  .place-card__head { position: sticky; top: -12px; padding-top: 12px; margin-top: -12px; background: var(--card); z-index: 1; }
}
/* An open place card lifts the whole map above the table under it (two-column layouts). */
.map-wrap:has(> .place-card:not([hidden])) { z-index: 3; }
/* Close button stays at the right whatever the title length. */
.place-card__head > div:first-child { flex: 1; min-width: 0; }
.map-head .days-mapctl { flex: none; }
/* Two-column touch layouts keep the table compact: actions in one row, buttons look like buttons. */
@media (pointer: coarse) and (orientation: landscape), (pointer: coarse) and (min-width: 1025px) {
  table.dt td.dt-col-actions { display: table-cell; white-space: nowrap; margin-top: 0; }
  table.dt .dt-actions .btn { min-width: 0; }
  table.dt .dt-actions .btn--ghost { border-color: var(--rule-strong); background: var(--card); color: var(--ink); }
}
/* Touch: small text links get a finger-sized hit area. */
@media (pointer: coarse) {
  a.ext, .sources a { display: inline-flex; align-items: center; min-height: 36px; }
  .ov-loc { display: inline-block; padding: 9px 0; }
}
/* Phones: slightly smaller markers so neighbouring places overlap less at the fitted zoom. */
@media (max-width: 599px), (orientation: landscape) and (max-height: 500px) {
  .mk { width: 22px; height: 22px; font-size: 11px; }
  .mk--transit { width: 18px; height: 18px; font-size: 9px; }
}
