:root {
  --bg: #f4f2ec;
  --surface: #ffffff;
  --surface-2: #f7f6f2;
  --ink: #1c2420;
  --ink-2: #56615b;
  --ink-3: #85908a;
  --line: #e2dfd6;
  --brand: #1f5f4a;
  --brand-ink: #ffffff;
  --brand-soft: #e3efe9;
  --accent: #c8553d;
  --warn-bg: #fff4dc;
  --warn-ink: #7a5300;
  --err: #b3261e;
  --shadow: 0 1px 2px rgba(20, 30, 25, .06), 0 4px 16px rgba(20, 30, 25, .06);
  --radius: 14px;

  --m-walk: #85908a;
  --m-bus: #d0402b;
  --m-rail: #1c3f94;
  --m-tube: #0019a8;
  --m-dlr: #00a4a7;
  --m-overground: #fa7b05;
  --m-elizabeth: #6950a1;
  --m-coach: #7a4f9e;
  --m-tram: #5fb526;
  --m-other: #56615b;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #111614;
    --surface: #1a211e;
    --surface-2: #202825;
    --ink: #e8ece9;
    --ink-2: #a9b3ad;
    --ink-3: #7c8781;
    --line: #2c3632;
    --brand: #4fae8a;
    --brand-ink: #0c1411;
    --brand-soft: #1f3a30;
    --accent: #e27a62;
    --warn-bg: #3a2f14;
    --warn-ink: #f2cf83;
    --err: #ff8a80;
    --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 4px 16px rgba(0, 0, 0, .25);
    --m-walk: #8d9892;
    --m-bus: #ef6a55;
    --m-rail: #7c9bf0;
    --m-tube: #6f86ff;
    --m-other: #a9b3ad;
  }
}
:root[data-theme="dark"] {
  --bg: #111614;
  --surface: #1a211e;
  --surface-2: #202825;
  --ink: #e8ece9;
  --ink-2: #a9b3ad;
  --ink-3: #7c8781;
  --line: #2c3632;
  --brand: #4fae8a;
  --brand-ink: #0c1411;
  --brand-soft: #1f3a30;
  --accent: #e27a62;
  --warn-bg: #3a2f14;
  --warn-ink: #f2cf83;
  --err: #ff8a80;
  --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 4px 16px rgba(0, 0, 0, .25);
  --m-walk: #8d9892;
  --m-bus: #ef6a55;
  --m-rail: #7c9bf0;
  --m-tube: #6f86ff;
  --m-other: #a9b3ad;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 16px/1.45 Inter, system-ui, -apple-system, "Segoe UI", sans-serif;
}
.wrap { max-width: 680px; margin: 0 auto; padding: 0 16px; }
/* Icon SVGs only; Leaflet's map layers need their own sizing and stroke attributes. */
svg:not(.leaflet-container svg) { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; flex: none; }

/* Header */
.top { padding: 28px 0 18px; }
.brand { margin: 0; font-size: 26px; font-weight: 700; letter-spacing: -.02em; display: flex; align-items: center; gap: 10px; }
.brand-mark {
  width: 26px; height: 26px; border-radius: 8px; background: var(--brand);
  background-image: repeating-linear-gradient(90deg, transparent 0 5px, rgba(255,255,255,.35) 5px 7px);
  box-shadow: inset 0 -6px 0 rgba(0,0,0,.15);
}
.tag { margin: 4px 0 0; color: var(--ink-2); }

/* Form */
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); }
.form { padding: 18px; position: relative; }
.field { margin: 0 0 14px; border: 0; padding: 0; min-width: 0; }
label, legend { display: block; font-size: 13px; font-weight: 600; color: var(--ink-2); margin: 0 0 6px; padding: 0; }
.combo { position: relative; display: flex; gap: 8px; }
input[type="text"], input[type="date"], input[type="time"] {
  width: 100%; min-width: 0; font: inherit; color: var(--ink);
  background: var(--surface-2); border: 1px solid var(--line); border-radius: 10px;
  padding: 12px 14px; outline: none;
}
input:focus { border-color: var(--brand); box-shadow: 0 0 0 3px var(--brand-soft); }
input::placeholder { color: var(--ink-3); }
.chip {
  flex: none; display: inline-flex; align-items: center; gap: 6px;
  font: inherit; font-size: 14px; font-weight: 600; color: var(--brand);
  background: var(--brand-soft); border: 0; border-radius: 10px; padding: 0 12px; cursor: pointer;
}
.chip.on { background: var(--brand); color: var(--brand-ink); }
.chip.busy svg { animation: spin 1s linear infinite; }
@media (max-width: 420px) { .chip span { display: none; } .chip { padding: 0 13px; } }
.hint { margin: 6px 0 0; font-size: 13px; color: var(--ink-2); min-height: 0; }
.hint:empty { display: none; }
.hint.err { color: var(--err); }

.label-row { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin: 0 0 6px; }
.label-row label { margin: 0; }
.swap {
  width: 30px; height: 30px; border-radius: 50%; display: grid; place-items: center; padding: 0;
  background: var(--surface); color: var(--ink-2); border: 1px solid var(--line); cursor: pointer;
}
.swap svg { width: 16px; height: 16px; }
.swap:hover { color: var(--brand); border-color: var(--brand); }

.suggest {
  position: absolute; left: 0; right: 0; top: calc(100% + 4px); z-index: 10;
  list-style: none; margin: 0; padding: 4px; max-height: 300px; overflow: auto;
  background: var(--surface); border: 1px solid var(--line); border-radius: 12px; box-shadow: var(--shadow);
}
.suggest li { padding: 9px 10px; border-radius: 8px; cursor: pointer; display: flex; gap: 10px; align-items: baseline; }
.suggest li[aria-selected="true"], .suggest li:hover { background: var(--surface-2); }
.suggest .s-name { font-weight: 600; }
.suggest .s-sub { color: var(--ink-3); font-size: 13px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.seg { display: grid; grid-template-columns: repeat(3, 1fr); background: var(--surface-2); border: 1px solid var(--line); border-radius: 10px; padding: 3px; }
.seg label { margin: 0; color: var(--ink); font-size: 14px; font-weight: 500; }
.seg input { position: absolute; opacity: 0; pointer-events: none; }
.seg span { display: block; text-align: center; padding: 8px 4px; border-radius: 8px; cursor: pointer; }
.seg input:checked + span { background: var(--surface); box-shadow: var(--shadow); font-weight: 600; color: var(--brand); }
.seg input:focus-visible + span { outline: 2px solid var(--brand); }
.datetime { display: grid; grid-template-columns: 1.4fr 1fr; gap: 8px; margin-top: 8px; }
.datetime[hidden] { display: none; }

.go {
  width: 100%; font: inherit; font-weight: 700; font-size: 17px;
  background: var(--brand); color: var(--brand-ink); border: 0; border-radius: 12px; padding: 14px; cursor: pointer;
}
.go:disabled { opacity: .6; cursor: progress; }
.error { color: var(--err); font-size: 14px; margin: 10px 0 0; }

/* Results */
#results { margin: 20px 0; }
.res-head { display: flex; justify-content: space-between; align-items: baseline; gap: 12px; margin: 0 2px 10px; }
.res-head h2 { font-size: 15px; margin: 0; font-weight: 600; color: var(--ink-2); }
.res-head h2 b { color: var(--ink); }
.pager { display: flex; justify-content: space-between; gap: 8px; margin: 12px 0; }
.pager button {
  font: inherit; font-size: 14px; font-weight: 600; color: var(--brand);
  background: transparent; border: 1px solid var(--line); border-radius: 10px; padding: 8px 14px; cursor: pointer;
}
.pager button:hover { border-color: var(--brand); }

.note { background: var(--warn-bg); color: var(--warn-ink); border-radius: 12px; padding: 12px 14px; font-size: 14px; margin: 0 0 12px; }
.empty { padding: 24px 18px; text-align: center; color: var(--ink-2); }

.journey { margin: 0 0 12px; overflow: hidden; }
.journey > summary { list-style: none; cursor: pointer; padding: 16px 18px; }
.journey > summary::-webkit-details-marker { display: none; }
.j-top { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; }
.j-times { font-size: 22px; font-weight: 700; letter-spacing: -.01em; font-variant-numeric: tabular-nums; }
.j-times .arrow { color: var(--ink-3); font-weight: 400; margin: 0 4px; }
.j-dur { font-weight: 600; white-space: nowrap; }
.j-meta { display: flex; flex-wrap: wrap; gap: 4px 12px; color: var(--ink-2); font-size: 13px; margin-top: 2px; }
.j-meta .late { color: var(--err); font-weight: 600; }
.j-meta .best { color: var(--brand); font-weight: 600; }
.j-leave { margin-top: 10px; font-size: 14px; }
.j-leave b { color: var(--accent); }

.strip { display: flex; gap: 3px; margin-top: 12px; height: 26px; }
.seg-bar {
  min-width: 26px; border-radius: 6px; color: #fff; font-size: 12px; font-weight: 700;
  display: flex; align-items: center; justify-content: center; gap: 3px; padding: 0 6px; overflow: hidden; white-space: nowrap;
}
.seg-bar svg { width: 14px; height: 14px; }
.seg-bar.walking { background: transparent; color: var(--m-walk); border: 1.5px dashed var(--m-walk); }

.legs { border-top: 1px solid var(--line); padding: 6px 18px 16px; }
.leg { display: grid; grid-template-columns: 52px 20px 1fr; column-gap: 10px; }
.leg-time { font-variant-numeric: tabular-nums; font-weight: 600; font-size: 14px; padding-top: 12px; }
.leg-rail { position: relative; }
.leg-rail::before { content: ""; position: absolute; left: 8px; top: 16px; bottom: -16px; width: 4px; border-radius: 2px; background: var(--c, var(--m-other)); }
.leg.walking .leg-rail::before { background: none; border-left: 3px dotted var(--m-walk); width: 0; left: 8.5px; }
.leg-rail::after { content: ""; position: absolute; left: 3px; top: 13px; width: 14px; height: 14px; border-radius: 50%; background: var(--surface); border: 3px solid var(--c, var(--m-other)); box-sizing: border-box; }
.leg-body { padding: 10px 0 14px; min-width: 0; }
.leg-from { font-weight: 600; }
.leg-what { display: flex; align-items: center; gap: 8px; margin-top: 4px; color: var(--ink-2); font-size: 14px; }
.badge { display: inline-flex; align-items: center; gap: 4px; color: #fff; background: var(--c, var(--m-other)); border-radius: 6px; padding: 2px 7px; font-size: 12px; font-weight: 700; }
.badge svg { width: 13px; height: 13px; }
.leg-stops { font-size: 13px; color: var(--ink-3); margin-top: 4px; }
.leg-stops summary { cursor: pointer; }
.leg-stops ol { margin: 6px 0 0; padding-left: 18px; }
.leg-alert { font-size: 13px; color: var(--warn-ink); background: var(--warn-bg); border-radius: 8px; padding: 6px 8px; margin-top: 6px; }
.leg.end .leg-rail::before { display: none; }
.leg.end .leg-body { padding-bottom: 0; }

.skeleton { height: 128px; margin: 0 0 12px; background: linear-gradient(90deg, var(--surface) 0%, var(--surface-2) 50%, var(--surface) 100%); background-size: 200% 100%; animation: shimmer 1.2s infinite; }

.foot { color: var(--ink-3); font-size: 12px; padding-bottom: 32px; }

@keyframes spin { to { transform: rotate(360deg); } }
@keyframes shimmer { to { background-position: -200% 0; } }
@media (prefers-reduced-motion: reduce) { .skeleton, .chip.busy svg { animation: none; } }

/* Map */
.layout { display: grid; grid-template-columns: minmax(0, 1fr); grid-template-areas: "form" "map" "results"; }
.form { grid-area: form; }
#results { grid-area: results; min-width: 0; }
.map-panel { grid-area: map; margin-top: 20px; overflow: hidden; display: flex; flex-direction: column; }
.map-panel[hidden] { display: none; }
#map { height: 300px; background: var(--surface-2); }
.live-bar { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 6px 12px; padding: 8px 14px; border-top: 1px solid var(--line); }
.live-bar:has(.live-status:empty):has(.alert-btn[hidden]) { display: none; }
.live-status { margin: 0; font-size: 13px; color: var(--ink-2); display: flex; align-items: center; gap: 8px; }
.live-status:empty { display: none; }
.alert-btn {
  font: inherit; font-size: 13px; font-weight: 600; color: var(--brand); background: var(--brand-soft);
  border: 0; border-radius: 999px; padding: 6px 12px; cursor: pointer;
}
.alert-btn.on { background: var(--brand); color: var(--brand-ink); }
.alert-banner { background: var(--accent); color: #fff; padding: 12px 14px; font-size: 14px; }
.alert-banner[hidden] { display: none; }
.alert-banner button { margin-left: 8px; font: inherit; font-weight: 700; background: #fff; color: var(--accent); border: 0; border-radius: 8px; padding: 3px 10px; cursor: pointer; }

.bus-card { padding: 12px 14px; border-top: 1px solid var(--line); font-size: 14px; }
.bus-card[hidden] { display: none; }
.bc-head { display: flex; align-items: center; gap: 10px; }
.bc-line { background: var(--m-bus); color: #fff; font-weight: 700; border-radius: 6px; padding: 3px 8px; }
.bc-dest { flex: 1; font-weight: 600; min-width: 0; }
.bc-dest small { display: block; font-weight: 400; color: var(--ink-3); font-size: 12px; }
.bc-x { font: inherit; font-size: 20px; line-height: 1; background: none; border: 0; color: var(--ink-3); cursor: pointer; padding: 2px 6px; }
.bc-eta { margin: 10px 0 2px; font-size: 16px; }
.bc-eta b { color: var(--accent); }
.bc-sub { margin: 2px 0 0; color: var(--ink-2); font-size: 13px; }
.bc-warn { margin: 10px 0 0; color: var(--warn-ink); background: var(--warn-bg); border-radius: 8px; padding: 8px 10px; }
.bc-note { margin: 8px 0 0; color: var(--ink-3); font-size: 12px; }
.live-dot { width: 8px; height: 8px; border-radius: 50%; background: #1faa59; box-shadow: 0 0 0 0 rgba(31, 170, 89, .5); animation: pulse 2s infinite; flex: none; }
.live-dot.off { background: var(--ink-3); animation: none; }

@media (min-width: 1000px) {
  body.has-map .wrap { max-width: 1180px; }
  body.has-map .layout {
    grid-template-columns: minmax(0, 560px) minmax(0, 1fr); column-gap: 24px;
    grid-template-areas: "form map" "results map"; grid-template-rows: auto 1fr;
  }
  body.has-map .map-panel { margin-top: 0; position: sticky; top: 16px; align-self: start; height: calc(100vh - 32px); }
  body.has-map #map { flex: 1; height: auto; }
}

.leaflet-container { font: inherit; }
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .leaflet-tile-pane { filter: invert(1) hue-rotate(180deg) brightness(.9) contrast(.9); }
}
:root[data-theme="dark"] .leaflet-tile-pane { filter: invert(1) hue-rotate(180deg) brightness(.9) contrast(.9); }
.leaflet-tooltip { font-size: 13px; border-radius: 8px; padding: 6px 9px; box-shadow: var(--shadow); }
.leaflet-tooltip span { color: #56615b; }
.rr-pt { border-radius: 50%; background: #fff; border: 3px solid #1c2420; box-sizing: border-box; }
.rr-pt-start { background: var(--brand); border-color: #fff; box-shadow: 0 0 0 2px var(--brand); }
.rr-pt-end { background: var(--accent); border-color: #fff; box-shadow: 0 0 0 2px var(--accent); }
.rr-bus { background: none; border: 0; }
.rr-bus span {
  position: relative; display: flex; align-items: center; gap: 3px; transform: translate(-50%, -50%); cursor: pointer;
  background: var(--m-bus); color: #fff; font-weight: 700; font-size: 11px; line-height: 1;
  padding: 4px 6px; border-radius: 6px; border: 2px solid #fff; box-shadow: 0 1px 4px rgba(0,0,0,.35); white-space: nowrap;
}
.rr-bus svg { width: 12px; height: 12px; fill: none; stroke: currentColor; stroke-width: 2.4; stroke-linecap: round; stroke-linejoin: round; flex: none; }
.rr-bus.sel span { background: var(--accent); transform: translate(-50%, -50%) scale(1.2); box-shadow: 0 0 0 3px rgba(200, 85, 61, .35), 0 1px 4px rgba(0,0,0,.35); }
.rr-bus.sel span::after { border-bottom-color: var(--accent); }
.rr-bus span::after {
  content: ""; position: absolute; left: 50%; top: 50%; width: 0; height: 0; margin: -5px 0 0 -4px;
  border: 4px solid transparent; border-bottom: 7px solid var(--m-bus);
  transform: rotate(var(--r)) translateY(-17px); transform-origin: 4px 5px;
}

.leg { border-radius: 10px; transition: background .12s; margin: 0 -8px; padding: 0 8px; cursor: pointer; }
.leg.hl { background: var(--brand-soft); }

@keyframes pulse { 70% { box-shadow: 0 0 0 7px rgba(31, 170, 89, 0); } 100% { box-shadow: 0 0 0 0 rgba(31, 170, 89, 0); } }
@media (prefers-reduced-motion: reduce) { .live-dot { animation: none; } }
