:root {
  --bg: #f4f3f7;
  --card: #fff;
  --ink: #1b1a22;
  --sub: #6b6878;
  --line: #e6e4ec;
  --accent: #6b2fa0;
  --ok: #17a34a;
  --radius: 14px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root { --bg: #121117; --card: #1d1b25; --ink: #f1eff7; --sub: #a29fb0; --line: #2d2a37; --accent: #c49bf0; color-scheme: dark; }
}
* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--ink); }
body { font: 15px/1.45 'Noto Sans Thai', system-ui, sans-serif; max-width: 680px; margin: 0 auto; min-height: 100vh; display: flex; flex-direction: column; }
button { font: inherit; color: inherit; background: none; border: 0; cursor: pointer; }
b { font-weight: 600; }

.top { position: sticky; top: 0; z-index: 500; background: var(--bg); padding: max(10px, env(safe-area-inset-top)) 14px 0; }
.top-row { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
h1 { font-size: 20px; margin: 0; letter-spacing: -.01em; }
.live { font-size: 12.5px; padding: 3px 10px 3px 20px; border-radius: 99px; background: var(--card); border: 1px solid var(--line); position: relative; color: var(--sub); white-space: nowrap; }
.live::before { content: ''; position: absolute; left: 8px; top: 50%; width: 7px; height: 7px; margin-top: -3.5px; border-radius: 50%; background: #aaa; }
.live.on { color: var(--ink); }
.live.on::before { background: var(--ok); box-shadow: 0 0 0 0 var(--ok); animation: pulse 2s infinite; }
@keyframes pulse { 0% { box-shadow: 0 0 0 0 rgba(23,163,74,.5); } 70% { box-shadow: 0 0 0 7px rgba(23,163,74,0); } 100% { box-shadow: 0 0 0 0 rgba(23,163,74,0); } }

.tabs { display: flex; gap: 4px; margin: 10px 0 0; border-bottom: 1px solid var(--line); }
.tabs button { flex: 1; padding: 10px 4px; font-weight: 500; color: var(--sub); border-bottom: 2.5px solid transparent; }
.tabs button.on { color: var(--ink); border-color: var(--accent); }

main { flex: 1; padding: 12px 12px 24px; }
.tab { display: none; }
.tab.on { display: block; }
.empty { color: var(--sub); text-align: center; padding: 40px 0; }
.foot { font-size: 11.5px; color: var(--sub); text-align: center; padding: 10px 16px max(16px, env(safe-area-inset-bottom)); }

.badge { display: inline-grid; place-items: center; min-width: 26px; height: 26px; padding: 0 6px; border-radius: 8px; background: var(--c); color: var(--t); font-weight: 700; font-size: 13px; line-height: 1; vertical-align: middle; }
.badge.big { min-width: 40px; height: 40px; border-radius: 11px; font-size: 17px; }

/* line cards */
.line-card { background: var(--card); border-radius: var(--radius); margin-bottom: 10px; border: 1px solid var(--line); cursor: pointer; overflow: hidden; }
.line-card:hover { border-color: color-mix(in srgb, var(--sub) 40%, var(--line)); }
.line-card header { display: flex; align-items: center; gap: 12px; padding: 12px 12px 8px; }
.lname { flex: 1; display: flex; flex-direction: column; line-height: 1.25; }
.lname span { font-size: 12.5px; color: var(--sub); }
.count { font-size: 12.5px; color: var(--ok); font-weight: 600; text-align: right; display: flex; flex-direction: column; }
.count small { color: var(--sub); font-weight: 400; }
.chev { color: var(--sub); font-size: 22px; line-height: 1; }
.buses { list-style: none; margin: 0; padding: 0 12px 10px; }
.bus { display: flex; align-items: center; gap: 10px; padding: 8px 0; border-top: 1px dashed var(--line); }
.bus.none { color: var(--sub); font-size: 13.5px; }
.bus.muted { opacity: .55; }
.bus-id { flex: none; font-size: 12px; font-weight: 600; min-width: 34px; text-align: center; padding: 2px 4px; border-radius: 6px; background: var(--bg); color: var(--sub); }
.bus-txt { flex: 1; display: flex; flex-direction: column; min-width: 0; }
.bus-txt .main { font-size: 14.5px; }
.bus-txt .sub { font-size: 12.5px; color: var(--sub); }
.eta { flex: none; font-weight: 700; font-size: 15px; color: var(--ok); white-space: nowrap; }
.eta.big { font-size: 19px; }

/* line detail */
.back { color: var(--accent); font-weight: 500; padding: 4px 0 10px; }
.line-head { display: flex; gap: 12px; align-items: center; margin-bottom: 8px; }
.line-head h2 { margin: 0; font-size: 19px; }
.line-head h2 span { font-size: 13px; color: var(--sub); font-weight: 400; }
.line-head p { margin: 2px 0 0; color: var(--sub); font-size: 13px; }
.warn { background: #fff4d6; color: #6b4b00; border-radius: 10px; padding: 8px 12px; font-size: 13px; }
@media (prefers-color-scheme: dark) { .warn { background: #3a2e0c; color: #f3d98a; } }
.note { font-size: 13px; color: var(--sub); }
.diagram { list-style: none; margin: 8px 0 16px; padding: 6px 0 6px 6px; background: var(--card); border-radius: var(--radius); border: 1px solid var(--line); }
.diagram li { position: relative; padding: 6px 12px 6px 34px; min-height: 34px; display: flex; flex-wrap: wrap; align-items: center; gap: 6px; }
.diagram li::before { content: ''; position: absolute; left: 17px; top: 0; bottom: 0; width: 4px; background: var(--c); opacity: .85; }
.diagram li:first-child::before { top: 50%; }
.diagram li.end::before { bottom: 50%; }
.diagram .dot { position: absolute; left: 12px; top: 50%; width: 14px; height: 14px; margin-top: -7px; border-radius: 50%; background: var(--card); border: 3px solid var(--c); z-index: 1; }
.diagram .stop.has .dot { background: var(--c); }
.diagram .sname { font-size: 14.5px; }
.diagram .sname small { color: var(--sub); }
.diagram .moving { min-height: 30px; }
.diagram .arrow { position: absolute; left: 10px; width: 18px; text-align: center; font-size: 12px; color: var(--c); background: var(--card); line-height: 1; z-index: 1; }
.chip { display: inline-flex; align-items: center; gap: 4px; padding: 3px 9px; border-radius: 99px; font-size: 12.5px; background: var(--bg); border: 1px solid var(--line); white-space: nowrap; }
.chip.live { background: color-mix(in srgb, var(--ok) 12%, var(--card)); border-color: color-mix(in srgb, var(--ok) 35%, var(--line)); white-space: normal; }
.chip.live b { color: var(--ok); }
.chip.muted { opacity: .6; }
.chip.sel { border-color: var(--accent); color: var(--accent); font-weight: 600; }
.ghost { border: 1px solid var(--line); background: var(--card); border-radius: 10px; padding: 8px 12px; font-size: 14px; white-space: nowrap; }

/* stop tab */
.stop-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 10px; }
.stop-head h2 { margin: 2px 0 4px; font-size: 20px; }
.stop-head p { margin: 0; display: flex; gap: 4px; flex-wrap: wrap; }
.star { font-size: 26px; color: var(--sub); line-height: 1; padding: 4px; }
.star.on { color: #e8a400; }
.arrivals { list-style: none; padding: 0; margin: 12px 0 18px; background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); }
.arr { display: flex; align-items: center; gap: 12px; padding: 12px; border-top: 1px solid var(--line); }
.arr:first-child { border-top: 0; }
.arr.none { opacity: .7; }
.arr-txt { flex: 1; display: flex; flex-direction: column; min-width: 0; }
.arr-txt small { color: var(--sub); font-size: 12.5px; }
.picker .chips, #map-filter { display: flex; gap: 6px; overflow-x: auto; padding-bottom: 8px; }
.search { display: flex; gap: 8px; margin-bottom: 8px; }
.search input { flex: 1; min-width: 0; font: inherit; padding: 9px 12px; border-radius: 10px; border: 1px solid var(--line); background: var(--card); color: var(--ink); }
.stops { list-style: none; padding: 0; margin: 0; background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); }
.stops li + li { border-top: 1px solid var(--line); }
.stops button { width: 100%; text-align: left; display: flex; justify-content: space-between; align-items: center; gap: 8px; padding: 10px 12px; }
.stops button.sel { background: color-mix(in srgb, var(--accent) 10%, transparent); }
.stops small { color: var(--sub); }
.mini { display: flex; gap: 3px; flex-wrap: wrap; justify-content: flex-end; }
.mini .badge { min-width: 20px; height: 20px; font-size: 11px; border-radius: 6px; padding: 0 4px; }

/* map */
#map { height: calc(100vh - 190px); min-height: 360px; border-radius: var(--radius); border: 1px solid var(--line); }
#map-filter .chip { padding: 2px; }
#map-filter .chip:first-child { padding: 3px 10px; }
.bm { width: 34px; height: 34px; border-radius: 50%; background: var(--c); color: var(--t); border: 2.5px solid #fff; box-shadow: 0 1px 4px rgba(0,0,0,.35); display: flex; flex-direction: column; align-items: center; justify-content: center; font: 700 12px/1 'Noto Sans Thai', sans-serif; text-align: center; }
.bm small { font-size: 8.5px; font-weight: 600; opacity: .85; line-height: 1; margin-top: 1px; }
.bm.dim { opacity: .5; }
.leaflet-popup-content { font-family: 'Noto Sans Thai', sans-serif; font-size: 13.5px; }
.eta.wait { color: var(--sub); font-weight: 600; font-size: 13px; }
