:root {
  --bg: #ffffff;
  --surface: #f5f6f8;
  --surface-2: #eceef2;
  --ink: #101828;
  --ink-2: #475467;
  --ink-3: #667085;
  --line: #e4e7ec;
  --brand: #005594;
  --brand-ink: #ffffff;
  --warn-bg: #fff6e0;
  --warn-ink: #6b4a00;
  --error: #c4320a;
  --ok: #067647;
  --mid: #b54708;
  --bad: #c4320a;
  --radius: 12px;
  --shadow: 0 1px 2px rgb(16 24 40 / 0.06), 0 8px 24px rgb(16 24 40 / 0.12);
  --ease: cubic-bezier(0.2, 0.8, 0.2, 1);
  --sheet-ease: cubic-bezier(0.32, 0.72, 0, 1);   /* iOS sheet curve: quick start, firm settle */
  --sidebar: 380px;
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  font-size: 15px;
  line-height: 1.4;
  color: var(--ink);
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body { display: flex; background: var(--bg); overflow: hidden; }
a { color: var(--brand); text-decoration: none; }
button { font: inherit; color: inherit; }
h1, h2, p { margin: 0; }

.visually-hidden {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}

/* ---------- sidebar ---------- */

#sidebar {
  position: relative;
  width: var(--sidebar);
  flex: none;
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: 16px 16px 12px;
  background: var(--bg);
  border-right: 1px solid var(--line);
  overflow-y: auto;
  overscroll-behavior: contain;
  z-index: 1000;
}

#sheet-handle { display: none; }

#progress {
  position: absolute;
  inset: 0 0 auto 0;
  height: 2px;
  overflow: hidden;
  opacity: 0;
  transition: opacity 0.2s;
}
#progress.on { opacity: 1; }
#progress::after {
  content: "";
  position: absolute;
  inset: 0;
  width: 40%;
  background: var(--brand);
  animation: progress 0.9s var(--ease) infinite;
}
@keyframes progress { from { transform: translateX(-100%); } to { transform: translateX(250%); } }

.brand { display: flex; align-items: center; gap: 8px; padding-bottom: 2px; }
.brand-link { display: flex; align-items: center; gap: 9px; color: var(--ink); }
.brand-mark { width: 28px; height: 28px; flex: none; }
.brand-mark circle { fill: var(--brand); }
.brand-mark path { fill: #fff; }
.brand-name { font-size: 1.15rem; font-weight: 750; letter-spacing: -0.02em; }
.pill {
  font-size: 11px;
  font-weight: 650;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--ink-3);
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 2px 7px;
}

#search input {
  width: 100%;
  font: inherit;
  font-size: 16px;   /* no zoom-on-focus on iOS */
  padding: 11px 12px 11px 38px;
  border: 1px solid transparent;
  border-radius: var(--radius);
  background: var(--surface) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23667085' stroke-width='2.2' stroke-linecap='round'%3E%3Ccircle cx='11' cy='11' r='7'/%3E%3Cpath d='m20 20-3.5-3.5'/%3E%3C/svg%3E") no-repeat 12px center / 17px;
  color: var(--ink);
  transition: background-color 0.15s, border-color 0.15s;
}
#search input:focus { outline: none; background-color: var(--bg); border-color: var(--brand); box-shadow: 0 0 0 3px rgb(0 85 148 / 0.12); }
#search input::placeholder { color: var(--ink-3); }

/* native <select>: a wheel picker on iOS, a bottom sheet on Android */
#route-select {
  width: 100%;
  font: inherit;
  font-size: 16px;
  font-weight: 600;
  padding: 11px 36px 11px 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--bg) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 12 8'%3E%3Cpath d='M1 1.5l5 5 5-5' fill='none' stroke='%23667085' stroke-width='2' stroke-linecap='round'/%3E%3C/svg%3E") no-repeat right 13px center / 12px 8px;
  color: var(--ink);
  appearance: none;
  cursor: pointer;
}
#route-select:focus { outline: none; border-color: var(--brand); box-shadow: 0 0 0 3px rgb(0 85 148 / 0.12); }

#status:empty { display: none; }
#status { font-size: 0.9rem; color: var(--ink-3); }
#status.error, .error { color: var(--error); }

#results { display: flex; flex-direction: column; gap: 12px; flex: 1; padding-top: 4px; }
.section {
  font-size: 0.72rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--ink-3);
  margin-top: 6px;
}
.hint { color: var(--ink-2); font-size: 0.92rem; }

.intro h1 { font-size: 1.35rem; font-weight: 750; letter-spacing: -0.02em; line-height: 1.2; }
.intro p { margin-top: 6px; color: var(--ink-2); font-size: 0.93rem; }

.badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 2.7em;
  height: 1.75em;
  padding: 0 7px;
  border-radius: 7px;
  background: var(--c);
  color: var(--t, #fff);
  font-weight: 750;
  font-size: 0.82rem;
  letter-spacing: -0.01em;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}
.badge.lg { font-size: 1.05rem; height: 2.1em; min-width: 3.2em; border-radius: 9px; }
.badge.dim { opacity: 0.55; }

.route-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(54px, 1fr)); gap: 6px; }
.route-grid a { display: flex; }
.route-grid .badge { width: 100%; height: 34px; transition: transform 0.12s var(--ease), filter 0.12s; }
.route-grid a:hover .badge { filter: brightness(1.12); transform: translateY(-1px); }
.route-grid a:active .badge { transform: scale(0.96); }
.route-grid a:focus-visible { outline: 2px solid var(--ink); outline-offset: 2px; border-radius: 8px; }

/* recents */
#recents[hidden] { display: none; }
.recents-head { display: flex; align-items: baseline; justify-content: space-between; }
.recents-head .section { margin-top: 0; }
.link-quiet { background: none; border: 0; padding: 2px 4px; font-size: 0.8rem; color: var(--ink-3); cursor: pointer; border-radius: 6px; }
.link-quiet:hover { color: var(--ink); background: var(--surface); }
.recents { list-style: none; margin: 6px 0 0; padding: 0; display: flex; flex-direction: column; gap: 2px; }
.recents a { display: flex; align-items: center; gap: 10px; padding: 7px 8px; margin: 0 -8px; border-radius: 10px; color: var(--ink); }
.recents a:hover { background: var(--surface); }
.recent-name { min-width: 0; display: flex; flex-direction: column; font-weight: 600; font-size: 0.92rem; line-height: 1.25; }
.recent-name small { font-weight: 400; color: var(--ink-3); font-size: 0.8rem; font-variant-numeric: tabular-nums; }
.stop-mark {
  flex: none; width: 2.7em; height: 1.75em; border-radius: 7px; background: var(--surface-2);
  display: grid; place-items: center; font-size: 0.82rem;
}
.stop-mark::after { content: ""; width: 10px; height: 10px; border-radius: 50%; border: 3px solid var(--brand); background: #fff; }

.suggestions { list-style: none; padding: 0; margin: 0; display: flex; flex-direction: column; gap: 4px; }
.suggestions a { display: flex; align-items: center; gap: 10px; padding: 8px; border-radius: 10px; color: var(--ink); }
.suggestions a:hover { background: var(--surface); }

/* ---------- route card ---------- */

.stop-head h1 { font-size: 1.25rem; font-weight: 750; letter-spacing: -0.015em; line-height: 1.2; }
.stop-head p { color: var(--ink-3); margin-top: 2px; font-variant-numeric: tabular-nums; }

.route { display: flex; flex-direction: column; gap: 8px; }
.route-head { display: flex; align-items: center; gap: 12px; }
.route-name { flex: 1; min-width: 0; }
.route-name h1, .route-name h2 { font-size: 1.08rem; font-weight: 700; letter-spacing: -0.01em; line-height: 1.25; }
.live { display: flex; align-items: center; gap: 6px; margin-top: 2px; color: var(--ink-3); font-size: 0.85rem; }
.dot {
  width: 7px; height: 7px; border-radius: 50%; background: #12b76a;
  box-shadow: 0 0 0 0 rgb(18 183 106 / 0.5);
  animation: pulse 2s infinite;
}
@keyframes pulse { 70% { box-shadow: 0 0 0 6px rgb(18 183 106 / 0); } 100% { box-shadow: 0 0 0 0 rgb(18 183 106 / 0); } }
.chip {
  font-size: 0.8rem; font-weight: 600; padding: 5px 10px; border-radius: 999px;
  background: var(--surface); color: var(--ink-2); white-space: nowrap;
}
.chip:hover { background: var(--surface-2); }

.dirs { display: flex; flex-direction: column; border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; }
.dirs details + details { border-top: 1px solid var(--line); }
.dirs summary {
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
  padding: 12px 14px; cursor: pointer; font-weight: 600; list-style: none;
}
.dirs summary::-webkit-details-marker { display: none; }
.dirs summary::after {
  content: ""; width: 8px; height: 8px; flex: none; margin-right: 3px;
  border-right: 2px solid var(--ink-3); border-bottom: 2px solid var(--ink-3);
  transform: rotate(45deg) translateY(-2px); transition: transform 0.2s var(--ease);
}
.dirs details[open] summary::after { transform: rotate(-135deg) translateY(-2px); }
.dirs summary:hover { background: var(--surface); }
.no-service { color: var(--mid); font-size: 0.85rem; padding: 0 14px 10px; }

/* stop list drawn as the route line */
ol.stops {
  list-style: none;
  margin: 0;
  padding: 4px 10px 10px 14px;
  max-height: 55vh;
  overflow-y: auto;
  overscroll-behavior: contain;
}
ol.stops li[data-stop] {
  position: relative;
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 36px;
  padding-left: 22px;
}
ol.stops li[data-stop]::before {           /* line */
  content: ""; position: absolute; left: 5px; top: 0; bottom: 0; width: 4px; background: var(--c);
}
ol.stops li[data-stop]:first-child::before { top: 50%; }
ol.stops li[data-stop]:last-child::before { bottom: 50%; }
ol.stops li[data-stop]::after {            /* stop dot */
  content: ""; position: absolute; left: 1px; top: 50%; width: 12px; height: 12px; margin-top: -6px;
  border-radius: 50%; background: #fff; border: 3px solid var(--c); box-sizing: border-box;
}
ol.stops button {
  flex: 1; min-width: 0; text-align: left; background: none; border: 0; padding: 6px 8px; margin-left: -8px;
  border-radius: 8px; cursor: pointer; font-size: 0.92rem; color: var(--ink);
}
ol.stops button:hover { background: var(--surface); }
.eta {
  flex: none;
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 2px 8px 2px 6px;
  border-radius: 999px;
  background: var(--c);
  color: #fff;
  font-size: 0.78rem;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}
.eta[hidden] { display: none; }
.eta svg { width: 13px; height: 13px; fill: currentColor; }

.alerts {
  background: var(--warn-bg);
  color: var(--warn-ink);
  border-radius: 10px;
  padding: 8px 11px;
  font-size: 0.85rem;
}
.alerts p { margin-top: 4px; }

/* skeletons */
.sk-rows { display: flex; flex-direction: column; gap: 9px; padding: 8px 0; }
.sk {
  height: 14px;
  border-radius: 6px;
  background: linear-gradient(90deg, var(--surface) 25%, var(--surface-2) 37%, var(--surface) 63%);
  background-size: 400% 100%;
  animation: shimmer 1.3s ease infinite;
}
.sk:nth-child(3n+2) { width: 82%; }
.sk:nth-child(3n) { width: 64%; }
@keyframes shimmer { from { background-position: 100% 50%; } to { background-position: 0 50%; } }
ol.stops > .sk-rows { padding: 8px 0 4px; }

#sidebar footer { font-size: 12px; color: var(--ink-3); padding-top: 12px; border-top: 1px solid var(--line); }
#sidebar footer a { color: inherit; text-decoration: underline; }

/* ---------- map ---------- */

#map { flex: 1; min-width: 0; height: 100%; background: #eef0f1; }
.basemap { filter: saturate(0.38) contrast(0.94) brightness(1.04); }

.leaflet-control-zoom { border: 0 !important; box-shadow: var(--shadow) !important; border-radius: 10px !important; overflow: hidden; }
.leaflet-control-zoom a { width: 36px !important; height: 36px !important; line-height: 36px !important; color: var(--ink) !important; border-color: var(--line) !important; }
.leaflet-control-attribution { font-size: 12px; background: rgb(255 255 255 / 0.8) !important; border-radius: 6px 0 0 0; }
.leaflet-tooltip { font: 600 12px/1.3 inherit; border: 0; border-radius: 8px; box-shadow: var(--shadow); padding: 5px 8px; }

.veh-icon { background: none; border: 0; }
.glide .veh-icon { transition: transform 1.6s linear; }
.veh { position: relative; width: 36px; height: 36px; transition: opacity 0.3s; }
.veh .arrow {
  position: absolute; inset: 0; width: 36px; height: 36px;
  fill: var(--c); stroke: #fff; stroke-width: 1.5; paint-order: stroke;
  transition: transform 0.6s var(--ease);
}
.veh .bus {
  position: absolute; left: 7px; top: 7px; width: 16px; height: 16px; padding: 3px;
  border-radius: 50%; background: var(--c); fill: #fff; border: 2px solid #fff;
  box-shadow: 0 1px 4px rgb(16 24 40 / 0.4); box-sizing: content-box;
  transition: transform 0.15s var(--ease);
}
.veh-icon:hover .bus { transform: scale(1.12); }
.veh.stale { opacity: 0.45; }

/* ---------- popups: arrival board ---------- */

.board-popup .leaflet-popup-content-wrapper { border-radius: 14px; box-shadow: var(--shadow); padding: 0; }
.board-popup .leaflet-popup-content { margin: 0; width: auto !important; min-width: 260px; font: inherit; font-size: 0.9rem; line-height: 1.35; }
.board-popup .leaflet-popup-close-button { top: 8px !important; right: 8px !important; width: 26px !important; height: 26px !important; font-size: 20px !important; color: var(--ink-3) !important; border-radius: 50%; }
.board-popup .leaflet-popup-close-button:hover { background: var(--surface); }
.popup-body { max-height: min(340px, 50vh); overflow-y: auto; padding: 14px 14px 10px; }
.leaflet-popup-content p { margin: 0; }   /* undo Leaflet's 1.3em paragraph margins */
.leaflet-popup-content p.board-label { margin-top: 8px; }
.leaflet-popup-content p.board-note { margin-top: 4px; }
.pop-head { padding-right: 24px; margin-bottom: 8px; }
.pop-title { font-weight: 700; font-size: 1rem; letter-spacing: -0.01em; display: flex; align-items: center; gap: 8px; }
.pop-sub { color: var(--ink-3); font-size: 0.8rem; margin-top: 2px; font-variant-numeric: tabular-nums; }
.updated.stale { color: var(--error); font-weight: 600; }

.board-group { padding: 8px 0; border-top: 1px solid var(--line); }
.board-route { display: flex; align-items: center; gap: 8px; color: var(--ink); font-weight: 650; }
.board-route:hover span { text-decoration: underline; }
.board { list-style: none; margin: 4px 0 0; padding: 0; }
.arr { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 5px 0; }
.arr + .arr { border-top: 1px dashed var(--line); }
.arr-info { color: var(--ink-2); font-size: 0.82rem; min-width: 0; }
.arr-time { flex: none; font-size: 1.25rem; font-weight: 750; letter-spacing: -0.02em; font-variant-numeric: tabular-nums; }
.arr-time small { font-size: 0.7rem; font-weight: 600; color: var(--ink-3); margin-left: 2px; letter-spacing: 0; }
.arr-time.none { color: var(--ink-3); font-weight: 500; }
.board-label { font-size: 0.72rem; font-weight: 700; text-transform: uppercase; letter-spacing: 0.08em; color: var(--ink-3); margin-top: 8px; }
.board-note { color: var(--ink-3); font-size: 0.82rem; padding-top: 8px; border-top: 1px solid var(--line); margin-top: 4px; line-height: 2; }
.board-empty { color: var(--ink-2); padding: 8px 0; border-top: 1px solid var(--line); }
.link { background: none; border: 0; padding: 0; color: var(--ink); font-weight: 600; cursor: pointer; text-align: left; }
.link:hover { text-decoration: underline; }
.sched { color: var(--ink-3); font-style: italic; }
.occ { font-weight: 650; }
.occ-seatsAvailable { color: var(--ok); }
.occ-standingAvailable { color: var(--mid); }
.occ-full { color: var(--bad); }

/* ---------- phones: full-screen map with a draggable bottom sheet ---------- */

@media (max-width: 760px) {
  body { display: block; }
  #map { position: fixed; inset: 0; height: auto; }

  body.sheet-min { --sheet: 152px; }
  body.sheet-half { --sheet: 46dvh; }
  body.sheet-full { --sheet: 92dvh; }

  /* the sheet is always full height and slides with transform, which the GPU
     animates without relayout; the bottom padding keeps the end of the list
     reachable above the screen edge at every size */
  #sidebar {
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    width: auto;
    height: 92dvh;
    padding: 22px 16px calc(92dvh - var(--sheet, 46dvh) + 12px + env(safe-area-inset-bottom));
    border-right: 0;
    border-radius: 18px 18px 0 0;
    box-shadow: 0 -4px 24px rgb(16 24 40 / 0.16);
    transform: translateY(calc(92dvh - var(--sheet, 46dvh)));
    transition: transform 0.42s var(--sheet-ease);
    will-change: transform;
  }
  #sidebar.dragging { transition: none; }

  #sheet-handle {
    display: block;
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 26px;
    padding: 0;
    border: 0;
    background: none;
    cursor: grab;
    touch-action: none;
  }
  #sheet-handle span { display: block; width: 38px; height: 5px; margin: 8px auto 0; border-radius: 3px; background: #d0d5dd; }
  .brand { touch-action: none; }

  .leaflet-bottom { transform: translateY(calc(-1 * var(--sheet, 46dvh))); transition: transform 0.42s var(--sheet-ease); }
  .leaflet-top { top: env(safe-area-inset-top); }
  .board-popup .leaflet-popup-content { min-width: 240px; }
}

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