:root {
  --bg: #111111;
  --card: #1e1e1e;
  --line-sep: #3a3a3a;
  --text: #ffffff;
  --muted: #a8a8a8;
  --red: #e0222b;
  --red-hover: #c71d25;
  --blue: #4a8fdb;
  --green: #2fb34a;
  --surface-2: #262626;
  --hover: #2a2a2a;
  --selected: #33404f;
  --shadow: rgba(0, 0, 0, .5);
  --pill-bg: #1c2633;
  --pill-text: #9cc2ec;
  --error-bg: rgba(224, 34, 43, .15);
  --error-text: #ff8a8f;
  --map-bg: #1a1a1a;
  --chip-bg: rgba(20, 20, 20, .92);
  --chip-border: #444;
  --chip-text: #fff;
  --halo: rgba(0, 0, 0, .55);
  --radius: 14px;
  color-scheme: dark;
}

@media (prefers-color-scheme: light) {
  :root {
    --bg: #f2f2f5;
    --card: #ffffff;
    --line-sep: #e3e3e6;
    --text: #141414;
    --muted: #6b6b70;
    --red: #d81f28;
    --red-hover: #b9161e;
    --blue: #1f6fc5;
    --green: #1e8e3e;
    --surface-2: #ffffff;
    --hover: #ececef;
    --selected: #dde9f8;
    --shadow: rgba(0, 0, 0, .14);
    --pill-bg: #e1edfa;
    --pill-text: #1d5ea8;
    --error-bg: rgba(216, 31, 40, .08);
    --error-text: #b3141c;
    --map-bg: #e9e9ec;
    --chip-bg: rgba(255, 255, 255, .96);
    --chip-border: #d3d3d8;
    --chip-text: #141414;
    --halo: rgba(255, 255, 255, .9);
    color-scheme: light;
  }
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: "Open Sans", "Segoe UI", system-ui, -apple-system, Roboto, sans-serif;
  font-size: 16px;
  line-height: 1.35;
  -webkit-text-size-adjust: 100%;
}

.app {
  max-width: 520px;
  margin: 0 auto;
  padding: max(16px, env(safe-area-inset-top)) max(16px, env(safe-area-inset-right)) max(40px, env(safe-area-inset-bottom)) max(16px, env(safe-area-inset-left));
}

h1 { margin: 0; font-size: 1.6rem; font-weight: 700; }

.sr-only {
  position: absolute; width: 1px; height: 1px; overflow: hidden;
  clip: rect(0 0 0 0); white-space: nowrap;
}

.muted { color: var(--muted); }
.accent { color: var(--blue); display: inline-flex; }

.icon { width: 24px; height: 24px; flex: none; }
.icon-sm { width: 14px; height: 14px; }

.card {
  background: var(--card);
  border-radius: var(--radius);
  padding: 8px 20px 20px;
  margin-bottom: 18px;
}

.brand {
  display: flex; align-items: center; gap: 10px;
  padding: 12px 4px 22px;
}
.brand h1 { font-size: 1.5rem; letter-spacing: .02em; }
.brand-icon { width: 28px; height: 28px; display: block; }

.offline { padding: 20px; }
.offline h2 { margin: 4px 0 8px; font-size: 1.25rem; }
.offline p { margin: 0 0 18px; }
.offline .btn-primary { text-decoration: none; }

.search .field {
  display: flex; align-items: center; gap: 14px;
  min-height: 64px;
  border-bottom: 1px solid var(--line-sep);
}
.search .field:has(.suggest) { position: relative; }

.suggest {
  position: absolute; left: -8px; right: -8px; top: calc(100% - 4px);
  z-index: 10;
  margin: 0; padding: 6px 0;
  list-style: none;
  max-height: 320px; overflow-y: auto;
  background: var(--surface-2);
  border: 1px solid var(--line-sep);
  border-radius: 10px;
  box-shadow: 0 10px 24px var(--shadow);
}
.suggest li {
  padding: 11px 16px;
  font-size: 1.05rem;
  cursor: pointer;
}
.suggest li:hover, .suggest li[aria-selected="true"] { background: var(--selected); }

.search .btn-primary { margin-top: 20px; }

.search input {
  flex: 1; min-width: 0;
  background: transparent; border: 0; outline: 0;
  color: var(--text);
  font: inherit; font-size: 1.15rem;
  padding: 14px 0;
}
.search input::placeholder { color: var(--muted); }
.search input:focus-visible { box-shadow: inset 0 -2px 0 var(--blue); }

.dot { width: 22px; height: 22px; border-radius: 50%; flex: none; }
.dot-hollow { border: 2px solid var(--red); }
.dot-filled { background: var(--red); }

.swap {
  background: transparent; border: 0; padding: 8px;
  color: var(--blue); cursor: pointer; display: inline-flex;
  border-radius: 8px;
}
.swap:hover { background: var(--hover); }

.btn-primary {
  width: 100%;
  display: flex; align-items: center; justify-content: center; gap: 12px;
  background: var(--red); color: #fff;
  border: 0; border-radius: 10px;
  padding: 16px; font: inherit; font-size: 1.1rem; font-weight: 700;
  cursor: pointer;
}
.btn-primary:hover { background: var(--red-hover); }

.form-error {
  margin: 12px 0 4px; padding: 10px 12px;
  border-radius: 8px;
  background: var(--error-bg);
  border: 1px solid var(--red);
  color: var(--error-text);
}

.topbar {
  display: flex; align-items: center; gap: 18px;
  padding: 18px 0 8px;
}
.back { padding: 6px; margin-left: -6px; border-radius: 8px; }
.back:hover { background: var(--hover); }

.route-summary { margin: 4px 0 10px; }

.sort-pill {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 5px 12px; margin-bottom: 16px;
  border-radius: 999px;
  background: var(--pill-bg); color: var(--pill-text);
  font-size: .85rem;
  user-select: none;
}

.journey-head {
  display: flex; justify-content: space-between; align-items: center;
  padding: 14px 0;
  border-bottom: 1px solid var(--line-sep);
  font-size: 1.05rem;
}
.soon { color: var(--red); font-weight: 700; }
.later { color: var(--green); font-weight: 700; }

.leg { border-bottom: 1px solid var(--line-sep); }
.leg:last-child { border-bottom: 0; }

.leg-head {
  display: flex; align-items: center; gap: 12px;
  padding: 12px 0;
}
.leg-dir { text-transform: capitalize; font-size: .9rem; }
.mode-icon { width: 24px; height: 24px; color: var(--muted); flex: none; }

.badge {
  min-width: 36px; padding: 4px 8px;
  border-radius: 7px;
  background: var(--line);
  color: var(--line-text, #fff); font-weight: 700; text-align: center;
}

.timeline { padding: 2px 0 14px; }
.stop:first-child::before {
  content: "";
  position: absolute; left: 5px; top: 8px; bottom: -28px;
  width: 12px; border-radius: 6px;
  background: color-mix(in srgb, var(--line) 28%, transparent);
}

.stop {
  position: relative;
  display: grid;
  grid-template-columns: 22px 52px 1fr;
  align-items: start;
  gap: 6px;
  padding: 6px 0;
}
.tl-dot {
  width: 16px; height: 16px; margin: 4px 0 0 3px;
  border-radius: 50%; background: var(--line);
  position: relative; z-index: 1;
}
.time { color: var(--muted); font-weight: 700; padding-top: 1px; }
.stop-name { font-size: 1.15rem; }
.platform { color: var(--muted); font-size: .95rem; margin-left: 4px; }
.intermediate { color: var(--muted); font-style: italic; font-size: .95rem; margin-top: 2px; }
.status { font-size: .9rem; margin-top: 2px; }
.late { color: var(--red); }
.ontime { color: var(--green); }

.walk-row {
  display: flex; align-items: center; gap: 10px;
  padding: 10px 0;
  border-bottom: 1px solid var(--line-sep);
  font-size: .95rem;
}
.walk-row .mode-icon { width: 20px; height: 20px; }
.walk-detail { margin-left: auto; font-size: .85rem; }

.empty { padding: 20px; }

.journey-meta { display: inline-flex; align-items: center; gap: 10px; }
.map-link { padding: 4px; border-radius: 8px; }
.map-link:hover { background: var(--hover); }

.small { font-size: .85rem; }

.map-head {
  display: flex; align-items: baseline; gap: 12px;
  margin: 4px 0 12px;
}
.map-times { font-size: 1.2rem; font-weight: 700; }

.route-map {
  height: min(62vh, 560px);
  border-radius: var(--radius);
  overflow: hidden;
  background: var(--map-bg);
  margin-bottom: 18px;
}
.route-map.map-error {
  height: auto; padding: 18px;
  color: var(--muted);
}

.map-legs { padding: 6px 20px; }
.map-leg {
  display: flex; gap: 14px;
  padding: 12px 0;
  border-bottom: 1px solid var(--line-sep);
}
.map-leg:last-child { border-bottom: 0; }
.map-leg-icon { padding-top: 2px; }
.map-leg-body { display: grid; gap: 4px; min-width: 0; }
.map-leg-stops b { display: inline-block; min-width: 46px; color: var(--muted); }
.map-leg .badge { display: inline-block; }
.map-leg.walk .mode-icon { width: 22px; height: 22px; }

.mk { display: flex; align-items: center; gap: 8px; pointer-events: none; }
.mk-label {
  padding: 3px 9px;
  border-radius: 999px;
  background: var(--chip-bg);
  border: 1px solid var(--chip-border);
  color: var(--chip-text); font-size: .85rem; font-weight: 600;
  white-space: nowrap;
  box-shadow: 0 2px 8px var(--shadow);
}
.mk-start .mk-pin {
  width: 22px; height: 22px; border-radius: 50%;
  background: #fff;
  border: 6px solid var(--red);
  box-shadow: 0 0 0 3px var(--halo), 0 2px 8px var(--shadow);
}
.mk-end { align-items: flex-end; }
.mk-end .mk-pin {
  position: relative;
  width: 28px; height: 28px;
  margin-bottom: 6px;
  border-radius: 50% 50% 50% 0;
  background: var(--red);
  transform: rotate(-45deg);
  transform-origin: center;
  box-shadow: 0 0 0 3px var(--halo), 0 3px 10px var(--shadow);
}
.mk-end .mk-pin::after {
  content: "";
  position: absolute; inset: 9px;
  border-radius: 50%;
  background: #fff;
}
.mk-end .mk-label { margin-bottom: 8px; }

.stop-popup .maplibregl-popup-content {
  background: var(--chip-bg); color: var(--chip-text);
  padding: 5px 10px; border-radius: 8px;
  font: 600 .85rem/1.2 "Open Sans", "Segoe UI", system-ui, sans-serif;
}
.stop-popup .maplibregl-popup-tip { display: none; }
.maplibregl-ctrl-attrib { font-size: 11px; }

@media (min-width: 600px) {
  .app { padding-top: 32px; }
}

.switch {
  margin-left: auto;
  display: inline-flex; align-items: center; gap: 8px;
  cursor: pointer; user-select: none;
  font-size: .95rem;
}
.switch input { position: absolute; opacity: 0; width: 1px; height: 1px; }
.switch-track {
  position: relative;
  width: 40px; height: 24px; border-radius: 12px;
  background: var(--line-sep);
  transition: background .15s;
}
.switch-track::after {
  content: "";
  position: absolute; top: 3px; left: 3px;
  width: 18px; height: 18px; border-radius: 50%;
  background: #fff;
  box-shadow: 0 1px 3px rgba(0, 0, 0, .35);
  transition: transform .15s;
}
.switch input:checked + .switch-track { background: var(--green); }
.switch input:checked + .switch-track::after { transform: translateX(16px); }
.switch input:focus-visible + .switch-track { outline: 2px solid var(--blue); outline-offset: 2px; }

.live-status { margin: -4px 0 10px; }

.veh {
  position: relative;
  width: 30px; height: 30px;
  cursor: default;
}
.veh-num {
  position: absolute; inset: 3px;
  display: flex; align-items: center; justify-content: center;
  border-radius: 50%;
  background: var(--line);
  color: var(--line-text, #fff);
  font: 700 11px/1 "Open Sans", "Segoe UI", system-ui, sans-serif;
  border: 2px solid #fff;
  box-shadow: 0 1px 6px var(--shadow);
}
.veh-arrow {
  position: absolute; inset: 0;
  pointer-events: none;
}
.veh-arrow::before {
  content: "";
  position: absolute; left: 50%; top: -5px;
  transform: translateX(-50%);
  border-left: 6px solid transparent;
  border-right: 6px solid transparent;
  border-bottom: 8px solid var(--line);
}
.veh-delay {
  position: absolute; right: -10px; top: -8px;
  padding: 1px 4px;
  border-radius: 6px;
  background: var(--red); color: #fff;
  font: 700 10px/1.2 "Open Sans", "Segoe UI", system-ui, sans-serif;
}
.veh-delay[hidden], .veh-arrow[hidden] { display: none; }
