:root {
  color-scheme: light dark;
  --bg: #f6f7f8; --card: #fff; --fg: #111827; --muted: #6b7280; --line: #e5e7eb;
  --accent: #0f766e; --sea: #16a34a; --sda: #d97706; --lsd: #dc2626;
  --warn-bg: #fef3c7; --warn-fg: #78350f;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0b0f14; --card: #151b23; --fg: #e5e7eb; --muted: #9ca3af; --line: #263040;
    --accent: #0f766e; --warn-bg: #422006; --warn-fg: #fde68a;
  }
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
body { margin: 0; font: 16px/1.4 system-ui, sans-serif; background: var(--bg); color: var(--fg); }
button:focus-visible, input:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

.bar {
  position: sticky; top: 0; z-index: 10; display: flex; gap: .75rem; align-items: center;
  padding: .75rem 1rem; padding-top: max(.75rem, env(safe-area-inset-top));
  background: var(--accent); color: #fff;
}
.bar h1 { margin: 0; font-size: 1.1rem; display: flex; align-items: center; gap: .4rem; }
.logo { display: block; }
#q { flex: 1; min-width: 0; min-height: 44px; padding: 0 .75rem; border: 0; border-radius: 10px; font: inherit; }

main { max-width: 40rem; margin: 0 auto; padding: 0 1rem 2rem; }
h2 { font-size: .85rem; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); margin: 1.25rem 0 .5rem; }
.note { color: var(--muted); }
.mascot-note { text-align: center; padding-top: 4.25rem; position: relative; }
.mascot-note::before { content: ''; position: absolute; top: .5rem; left: 50%; translate: -50% 0; width: 56px; height: 56px; background: url('/mascot.svg') center / contain no-repeat; }

.card { background: var(--card); border: 1px solid var(--line); border-radius: 14px; padding: .75rem 1rem; margin-top: .75rem; }
.card > header { display: flex; justify-content: space-between; gap: .5rem; }
.desc { margin: 0; font-size: 1.05rem; }
.meta, .age, .err { margin: .1rem 0 0; font-size: .85rem; color: var(--muted); }
.err { color: var(--lsd); }
.err:empty { display: none; }
.actions { display: flex; flex-shrink: 0; }
.actions button, .icon-btn {
  min-width: 44px; min-height: 44px; border: 0; border-radius: 10px;
  background: none; color: var(--fg); font-size: 1.2rem; cursor: pointer;
}

.services { list-style: none; margin: .5rem 0 0; padding: 0; }
.services li { display: grid; grid-template-columns: 3.5rem 1fr auto; align-items: start; padding: .4rem 0; border-top: 1px solid var(--line); }
.no { font-size: 1.15rem; }
.etas { align-items: start; display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: .5rem; }
.eta { align-content: flex-start; display: flex; flex-wrap: wrap; align-items: center; gap: .25rem; }
.services li.note { display: block; }
.services li.mascot-note { padding-top: 4.25rem; }
.eta strong { font-size: 1.15rem; }
.eta small { flex-basis: 100%; color: var(--muted); font-size: .75rem; }
.sched strong { color: var(--muted); }
.miss strong { opacity: .45; }
.tag { font-size: .7rem; border: 1px solid var(--line); border-radius: 4px; padding: 0 .2rem; }
.hint { grid-column: 2; color: var(--sea); font-size: .85rem; }
.dot { display: inline-block; width: .6rem; height: .6rem; border-radius: 50%; background: var(--muted); }
.dot.SEA { background: var(--sea); }
.dot.SDA { background: var(--sda); }
.dot.LSD { background: var(--lsd); }

.legend { max-width: 40rem; margin: 0 auto; padding: 1rem; font-size: .8rem; color: var(--muted); }
#results { display: grid; gap: .25rem; margin-top: 1rem; }
.hit {
  min-height: 44px; padding: .5rem .75rem; text-align: left; font: inherit; cursor: pointer;
  border: 1px solid var(--line); border-radius: 10px; background: var(--card); color: var(--fg);
}
#alerts { display: flex; gap: .5rem; align-items: start; padding: .5rem 1rem; background: var(--warn-bg); color: var(--warn-fg); }
#alerts ul { flex: 1; margin: 0; padding-left: 1rem; font-size: .9rem; }
#alerts .icon-btn { color: inherit; }
#toast {
  position: fixed; left: 50%; bottom: max(1rem, env(safe-area-inset-bottom)); translate: -50% 0;
  padding: .5rem 1rem; border-radius: 999px; background: var(--fg); color: var(--bg);
}

#map-dlg { width: 100vw; height: 100dvh; max-width: none; max-height: none; margin: 0; padding: 0; border: 0; background: var(--bg); color: var(--fg); }
#map-dlg[open] { display: flex; flex-direction: column; }
#map-dlg > header { display: flex; align-items: center; gap: .5rem; padding: .25rem .25rem .25rem 1rem; padding-top: max(.25rem, env(safe-area-inset-top)); }
#map-title { flex: 1; min-width: 0; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
#follow-info { margin: 0; padding: 0 1rem .5rem; font-size: .85rem; color: var(--muted); }
#map { flex: 1; }
.bus { transition: transform 1s linear; }
.zooming .bus { transition: none; }
.bus span {
  position: relative; display: inline-block; translate: -50% -50%; padding: .1rem .35rem; border-radius: 6px;
  background: var(--accent); color: #fff; font: 600 .8rem system-ui; white-space: nowrap; box-shadow: 0 1px 3px #0006;
}
.bus span::before { content: ''; position: absolute; inset: -12px; }
.bus.followed span { background: var(--lsd); outline: 2px solid #fff; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.om-logo { height: 20px; width: 20px; vertical-align: middle; }
.bell {
  min-width: 44px; min-height: 44px; border: 0; border-radius: 10px;
  background: none; font-size: 1.1rem; cursor: pointer; opacity: .4;
}
.bell.on { opacity: 1; background: var(--line); }
#watch-dlg {
  width: min(24rem, calc(100vw - 2rem)); padding: .5rem 1rem 1rem;
  border: 1px solid var(--line); border-radius: 14px; background: var(--card); color: var(--fg);
}
#watch-dlg::backdrop { background: #0006; }
#watch-dlg > header { display: flex; align-items: center; gap: .5rem; }
#watch-title { flex: 1; font-weight: 600; }
#watch-opts { display: grid; gap: .5rem; }
#svc-picker { display: flex; gap: .4rem; overflow-x: auto; padding: 0 1rem .4rem; }
#svc-picker:empty { display: none; }
.chip {
  min-width: 44px; min-height: 44px; padding: 0 .75rem; border: 1px solid var(--line); border-radius: 999px;
  background: var(--card); color: var(--fg); font: 600 .9rem system-ui; cursor: pointer; flex-shrink: 0;
}
.chip[aria-pressed="true"] { background: var(--accent); border-color: var(--accent); color: #fff; }
#route-info { margin: 0; padding: 0 1rem .5rem; font-size: .8rem; color: var(--muted); }
#route-info:empty { display: none; }
.bus .dir {
  position: absolute; left: 50%; top: 50%; width: 0; height: 0; pointer-events: none;
  border-left: 6px solid transparent; border-right: 6px solid transparent; border-bottom: 9px solid var(--accent);
  transform: translate(-50%, -50%) rotate(var(--deg, 0deg)) translateY(-22px);
}
.bus.followed .dir { border-bottom-color: var(--lsd); }
#places .chips { display: flex; gap: .4rem; flex-wrap: wrap; }
.addr { color: var(--muted); }
.results-head { margin: .75rem 0 .25rem; font-size: .8rem; color: var(--muted); text-transform: uppercase; letter-spacing: .05em; }
#trip-dlg { width: 100vw; height: 100dvh; max-width: none; max-height: none; margin: 0; padding: 0 0 1rem; border: 0; background: var(--bg); color: var(--fg); overflow-y: auto; }
#trip-dlg > header { display: flex; align-items: center; gap: .5rem; padding: .25rem .25rem .25rem 1rem; padding-top: max(.25rem, env(safe-area-inset-top)); }
#trip-title { flex: 1; font-weight: 600; }
.trip-form { display: grid; gap: .5rem; padding: 0 1rem; }
.trip-row { display: flex; gap: .5rem; align-items: center; }
.trip-end {
  flex: 1; min-width: 0; min-height: 44px; padding: .5rem .75rem; text-align: left; font: inherit; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
  border: 1px solid var(--line); border-radius: 10px; background: var(--card); color: var(--fg);
}
button.trip-end { cursor: pointer; }
#trip-from-q { width: 100%; min-height: 44px; padding: 0 .75rem; border: 1px solid var(--line); border-radius: 10px; font: inherit; background: var(--card); color: var(--fg); }
#trip-from-results { display: grid; gap: .25rem; margin-top: .25rem; }
.seg { display: flex; gap: .25rem; margin: 0; padding: 0; border: 0; }
.seg label { flex: 1; min-height: 44px; display: flex; align-items: center; justify-content: center; gap: .25rem; border: 1px solid var(--line); border-radius: 10px; background: var(--card); font-size: .85rem; cursor: pointer; }
.seg label:has(input:checked) { background: var(--accent); border-color: var(--accent); color: #fff; }
.seg input { position: absolute; opacity: 0; }
.seg label:has(input:focus-visible) { outline: 2px solid var(--accent); outline-offset: 2px; }
#trip-time input { flex: 1; min-height: 44px; padding: 0 .5rem; border: 1px solid var(--line); border-radius: 10px; font: inherit; background: var(--card); color: var(--fg); }
#trip-status { margin: .75rem 1rem 0; color: var(--muted); }
#trip-status:empty { display: none; }
#trip-results { list-style: none; margin: .5rem 0 0; padding: 0 1rem; display: grid; gap: .5rem; }
.trip-card { background: var(--card); border: 1px solid var(--line); border-radius: 14px; overflow: hidden; }
.trip-sum { display: grid; gap: .35rem; width: 100%; padding: .75rem 1rem; border: 0; background: none; color: var(--fg); font: inherit; text-align: left; cursor: pointer; }
.trip-top { display: flex; justify-content: space-between; gap: .5rem; }
.trip-legs { display: flex; flex-wrap: wrap; align-items: center; gap: .25rem; font-size: .85rem; }
.leg { padding: 0 .35rem; border-radius: 4px; background: var(--c, var(--accent)); color: #fff; font-weight: 600; }
.leg.walk { background: none; color: var(--muted); font-weight: 400; padding: 0; }
.sep { color: var(--muted); }
.trip-fare { font-size: .8rem; color: var(--muted); }
.trip-steps { padding: 0 1rem .75rem; border-top: 1px solid var(--line); }
.trip-steps ol { list-style: none; margin: .5rem 0; padding: 0; display: grid; gap: .35rem; font-size: .9rem; }
.live { color: var(--sea); font-weight: 600; }
.trip-credit { margin: 1rem; font-size: .75rem; color: var(--muted); }
#stop-hits, #place-hits { display: grid; gap: .25rem; }
#name-dlg { width: min(22rem, calc(100vw - 2rem)); padding: 1rem; border: 1px solid var(--line); border-radius: 14px; background: var(--card); color: var(--fg); }
#name-dlg::backdrop { background: #0006; }
#name-dlg form { display: grid; gap: .75rem; }
#name-title { font-weight: 600; }
#name-input { min-height: 44px; padding: 0 .75rem; border: 1px solid var(--line); border-radius: 10px; font: inherit; background: var(--bg); color: var(--fg); }
.name-actions { display: flex; flex-direction: row-reverse; gap: .5rem; } /* Save first in the DOM so Enter saves */
.name-actions button { min-height: 44px; padding: 0 1rem; border: 1px solid var(--line); border-radius: 10px; background: none; color: var(--fg); font: inherit; cursor: pointer; }
.name-actions .primary { background: var(--accent); border-color: var(--accent); color: #fff; }
