/* 타고버스 — light first, dark follows the system. One brand blue; route colors come from the bus type. */
:root {
  color-scheme: light dark;
  --bg: #f6f7f9;
  --surface: #ffffff;
  --surface-2: #f2f4f6;
  --surface-3: #e9ecf0;
  --text: #191f28;
  --text-2: #4e5968;
  --text-3: #8b95a1;
  --line: #e5e8eb;
  --brand: #3182f6;
  --brand-soft: #e8f3ff;
  --live: #00b06b;
  --warn: #f08c00;
  --shadow: 0 6px 24px rgba(20, 30, 50, .12), 0 1px 3px rgba(20, 30, 50, .08);
  --shadow-sm: 0 2px 8px rgba(20, 30, 50, .12);
  --radius: 20px;
  --sheet-w: 392px;
  --gap: 16px;
  --route: #3182f6;
  font-family: "Pretendard Variable", Pretendard, -apple-system, BlinkMacSystemFont, "Apple SD Gothic Neo", "Malgun Gothic", system-ui, sans-serif;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #14161a;
    --surface: #1d2025;
    --surface-2: #262a30;
    --surface-3: #30353c;
    --text: #f2f4f6;
    --text-2: #b0b8c1;
    --text-3: #7e8794;
    --line: #2f343b;
    --brand: #4c9bff;
    --brand-soft: #1d3150;
    --live: #2fd08f;
    --shadow: 0 8px 28px rgba(0, 0, 0, .45), 0 1px 3px rgba(0, 0, 0, .4);
    --shadow-sm: 0 2px 10px rgba(0, 0, 0, .4);
  }
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body { background: var(--bg); color: var(--text); overflow: hidden; -webkit-font-smoothing: antialiased; font-size: 15px; line-height: 1.45; }
button, input, select { font: inherit; color: inherit; }
button { cursor: pointer; }
button:disabled { cursor: default; opacity: .4; }
svg { width: 20px; height: 20px; fill: currentColor; flex: none; }
:focus-visible { outline: 2px solid var(--brand); outline-offset: 2px; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
[hidden] { display: none !important; }

#map { position: fixed; inset: 0; }
.maplibregl-ctrl-group { border-radius: 12px !important; box-shadow: var(--shadow-sm) !important; background: var(--surface) !important; overflow: hidden; }
.maplibregl-ctrl-group button { width: 36px; height: 36px; }
.maplibregl-ctrl-attrib { font-size: 10px; background: color-mix(in srgb, var(--surface) 80%, transparent) !important; color: var(--text-3); border-radius: 8px 0 0 0; }
.maplibregl-ctrl-attrib a { color: var(--text-2); }
@media (prefers-color-scheme: dark) { .maplibregl-ctrl-group button .maplibregl-ctrl-icon { filter: invert(1); } }

/* Top bar */
.topbar { position: fixed; z-index: 4; top: var(--gap); left: var(--gap); display: flex; gap: 8px; align-items: center; width: var(--sheet-w); }
.brand { display: flex; align-items: center; gap: 8px; height: 48px; padding: 0 14px 0 8px; border-radius: 16px; background: var(--surface); box-shadow: var(--shadow-sm); color: var(--text); text-decoration: none; font-weight: 800; font-size: 17px; letter-spacing: -.02em; }
.brand-mark { display: grid; place-items: center; width: 32px; height: 32px; border-radius: 10px; background: var(--brand); color: #fff; }
.brand-mark svg { width: 19px; height: 19px; }
.city-picker { flex: 1; min-width: 0; position: relative; display: flex; align-items: center; height: 48px; border-radius: 16px; background: var(--surface); box-shadow: var(--shadow-sm); color: var(--text-2); }
.city-picker svg { position: absolute; left: 14px; width: 18px; height: 18px; color: var(--brand); pointer-events: none; }
.city-picker select { width: 100%; height: 100%; padding: 0 36px 0 40px; border: 0; border-radius: 16px; background: transparent; font-weight: 700; color: var(--text); appearance: none; text-overflow: ellipsis; }
.city-picker::after { content: ""; position: absolute; right: 16px; width: 8px; height: 8px; border-right: 2px solid var(--text-3); border-bottom: 2px solid var(--text-3); transform: translateY(-2px) rotate(45deg); pointer-events: none; }
.city-picker select option { background: var(--surface); color: var(--text); }

/* Sheet: floating panel on desktop, bottom sheet on phones */
.sheet { position: fixed; z-index: 3; top: calc(var(--gap) + 56px); left: var(--gap); bottom: var(--gap); width: var(--sheet-w); display: flex; flex-direction: column; background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow); overflow: hidden; }
.sheet-handle { display: none; }
.view { display: flex; flex-direction: column; min-height: 0; flex: 1; }
.view-head { padding: 18px 18px 12px; border-bottom: 1px solid var(--line); }
.view-body { flex: 1; min-height: 0; overflow: auto; padding: 6px 10px 16px; overscroll-behavior: contain; }
.sheet-foot { display: flex; justify-content: space-between; gap: 8px; padding: 10px 18px; border-top: 1px solid var(--line); font-size: 12px; color: var(--text-3); }
.sheet-foot a { color: var(--text-3); text-decoration: none; }
.sheet-foot a:hover { color: var(--text-2); }

.segmented { display: grid; grid-template-columns: 1fr 1fr; padding: 4px; border-radius: 12px; background: var(--surface-2); margin-bottom: 12px; }
.segmented button { height: 36px; border: 0; border-radius: 9px; background: transparent; color: var(--text-2); font-weight: 600; }
.segmented button[aria-selected="true"] { background: var(--surface); color: var(--text); box-shadow: var(--shadow-sm); }
@media (prefers-color-scheme: dark) { .segmented button[aria-selected="true"] { background: var(--surface-3); } }
.search { display: flex; align-items: center; gap: 8px; height: 48px; padding: 0 14px; border-radius: 14px; background: var(--surface-2); color: var(--text-3); }
.search:focus-within { box-shadow: inset 0 0 0 2px var(--brand); }
.search input { flex: 1; min-width: 0; border: 0; outline: 0; background: transparent; font-size: 16px; color: var(--text); }
.search input::placeholder { color: var(--text-3); }
.quick { display: flex; gap: 6px; margin-top: 12px; overflow-x: auto; scrollbar-width: none; }
.quick button { flex: none; height: 32px; padding: 0 12px; border: 1px solid var(--line); border-radius: 999px; background: var(--surface); color: var(--text-2); font-size: 13px; font-weight: 600; }
.quick button[aria-pressed="true"] { border-color: var(--brand); background: var(--brand-soft); color: var(--brand); }

.list-meta { display: flex; justify-content: space-between; padding: 10px 8px 6px; font-size: 13px; color: var(--text-3); font-weight: 600; }
.results { display: flex; flex-direction: column; }
.result { display: flex; align-items: center; gap: 12px; width: 100%; padding: 12px 8px; border: 0; border-radius: 12px; background: transparent; text-align: left; }
.result:hover { background: var(--surface-2); }
.result[aria-current="true"] { background: var(--brand-soft); }
.result-text { min-width: 0; display: flex; flex-direction: column; }
.result-text strong { font-size: 15px; font-weight: 700; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.result-text span { font-size: 13px; color: var(--text-3); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.pin { display: grid; place-items: center; width: 36px; height: 36px; flex: none; border-radius: 12px; background: var(--surface-2); color: var(--brand); }
.pin svg { width: 18px; height: 18px; }
.more { width: 100%; height: 44px; margin-top: 6px; border: 0; border-radius: 12px; background: var(--surface-2); color: var(--text-2); font-weight: 600; }
.empty { padding: 32px 16px; text-align: center; color: var(--text-3); font-size: 14px; }
.intro { padding: 8px 10px; color: var(--text-2); font-size: 14px; }
.intro p { margin: 0 0 10px; }
.intro strong { color: var(--text); }

.route-badge { display: inline-flex; align-items: center; justify-content: center; min-width: 52px; height: 28px; padding: 0 9px; border-radius: 8px; background: var(--route); color: #fff; font-weight: 800; font-size: 14px; letter-spacing: -.01em; white-space: nowrap; flex: none; }
.route-badge.big { min-width: 0; height: 36px; padding: 0 12px; font-size: 20px; border-radius: 10px; }
.type-chip { font-size: 13px; font-weight: 600; color: var(--route); }
.head-row { display: flex; align-items: center; gap: 10px; }
.icon-btn { display: grid; place-items: center; width: 36px; height: 36px; flex: none; margin-left: -8px; border: 0; border-radius: 10px; background: transparent; color: var(--text-2); }
.icon-btn:hover { background: var(--surface-2); }
.icon-btn.end { margin: 0 -8px 0 auto; }
.endpoints { margin: 10px 0 0; font-size: 17px; font-weight: 700; letter-spacing: -.02em; }
.stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin: 14px 0 0; }
.stats div { padding: 10px 12px; border-radius: 12px; background: var(--surface-2); }
.stats dt { font-size: 12px; color: var(--text-3); font-weight: 600; }
.stats dd { margin: 2px 0 0; font-size: 18px; font-weight: 800; font-variant-numeric: tabular-nums; }
.schedule { margin: 10px 0 0; font-size: 13px; color: var(--text-2); }
.route-page { margin-left: 4px; color: var(--brand); font-weight: 600; text-decoration: none; }
.route-page:hover { text-decoration: underline; }
.live { display: flex; align-items: center; gap: 6px; margin: 6px 0 0; font-size: 13px; color: var(--text-3); }
.live i { width: 8px; height: 8px; border-radius: 50%; background: var(--text-3); }
.live.on i { background: var(--live); box-shadow: 0 0 0 0 var(--live); animation: pulse 2s infinite; }
.live.on { color: var(--text-2); }
.live.wait i { background: var(--warn); }
@keyframes pulse { 0% { box-shadow: 0 0 0 0 color-mix(in srgb, var(--live) 60%, transparent); } 70% { box-shadow: 0 0 0 6px transparent; } 100% { box-shadow: 0 0 0 0 transparent; } }
.caption { margin: 12px 8px 0; font-size: 12px; color: var(--text-3); }

/* Stop timeline */
.timeline { list-style: none; margin: 4px 0 0; padding: 0; }
.timeline li { position: relative; }
.timeline li::before { content: ""; position: absolute; left: 21px; top: 0; bottom: 0; width: 4px; background: var(--route); opacity: .9; }
.timeline li:first-child::before { top: 50%; }
.timeline li:last-child::before { bottom: 50%; }
.stop-row { position: relative; display: flex; align-items: center; gap: 12px; width: 100%; min-height: 48px; padding: 8px 8px 8px 38px; border: 0; border-radius: 12px; background: transparent; text-align: left; }
.stop-row::before { content: ""; position: absolute; left: 16px; top: 50%; width: 14px; height: 14px; margin-top: -7px; border-radius: 50%; background: var(--surface); border: 3px solid var(--route); box-sizing: border-box; }
.stop-row:hover { background: var(--surface-2); }
.stop-row[aria-current="true"] { background: var(--brand-soft); }
.stop-row[aria-current="true"]::before { background: var(--route); }
.stop-row.has-bus::before { left: 12px; width: 22px; height: 22px; margin-top: -11px; border-width: 4px; box-shadow: 0 0 0 3px color-mix(in srgb, var(--route) 25%, transparent); }
.stop-row.has-bus .name { font-weight: 800; }
.stop-row .name { flex: 1; min-width: 0; font-size: 15px; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.stop-row .no { font-size: 12px; color: var(--text-3); font-variant-numeric: tabular-nums; }
.bus-here { display: inline-flex; align-items: center; gap: 3px; height: 24px; padding: 0 8px; border-radius: 999px; background: var(--route); color: #fff; font-size: 12px; font-weight: 700; white-space: nowrap; }
.bus-here svg { width: 14px; height: 14px; }
.timeline li.turn { padding: 6px 8px 6px 38px; font-size: 12px; color: var(--text-3); font-weight: 700; }
.timeline li.turn::before { background: repeating-linear-gradient(var(--route) 0 4px, transparent 4px 8px); }

/* Stop view */
.stop-title { min-width: 0; }
.stop-title h2 { margin: 0; font-size: 20px; font-weight: 800; letter-spacing: -.02em; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.stop-title span { font-size: 13px; color: var(--text-3); }
.section-label { margin: 14px 8px 6px; font-size: 13px; font-weight: 700; color: var(--text-3); }
.arrivals { display: flex; flex-direction: column; }
.arrival { display: flex; align-items: center; gap: 12px; width: 100%; padding: 12px 8px; border: 0; border-bottom: 1px solid var(--line); background: transparent; text-align: left; }
.arrival:last-child { border-bottom: 0; }
.arrival .meta { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.arrival .meta span { font-size: 13px; color: var(--text-3); }
.arrival .eta { font-size: 18px; font-weight: 800; color: var(--text); font-variant-numeric: tabular-nums; white-space: nowrap; }
.arrival .eta.soon { color: #e5484d; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; padding: 0 8px; }
.chips button { border: 0; padding: 0; background: none; }

/* Map tools */
.map-tools { position: fixed; z-index: 2; right: var(--gap); top: var(--gap); display: flex; gap: 8px; align-items: center; }
.tool { display: inline-flex; align-items: center; justify-content: center; gap: 6px; height: 44px; min-width: 44px; padding: 0 12px; border: 0; border-radius: 14px; background: var(--surface); box-shadow: var(--shadow-sm); color: var(--text-2); font-size: 14px; font-weight: 600; }
.tool:hover:not(:disabled) { color: var(--text); }
.tool.toggle { cursor: pointer; user-select: none; }
.tool.toggle input { accent-color: var(--brand); margin: 0; width: 16px; height: 16px; }
.maplibregl-ctrl-bottom-right { margin: 0 var(--gap) var(--gap) 0; }
.maplibregl-ctrl-bottom-right .maplibregl-ctrl { margin: 0 0 8px; }

/* Bus callouts: a card on a leader line that ends at the stop circle, like the stop timeline */
.callout { --lead: 30px; display: flex; flex-direction: column; align-items: center; padding: 0; border: 0; background: none; color: var(--text); cursor: pointer; }
.callout.tall { --lead: 64px; }
.callout:hover { z-index: 2; }
.callout-card { display: flex; align-items: center; gap: 6px; padding: 4px 9px 4px 4px; border: 2px solid var(--route); border-radius: 11px; background: var(--surface); box-shadow: 0 3px 10px rgba(0, 0, 0, .18); white-space: nowrap; }
.callout-card > svg { display: none; }
.callout-card .route-badge { min-width: 0; height: 22px; padding: 0 7px; font-size: 12px; border-radius: 7px; }
.callout-text { display: flex; flex-direction: column; align-items: flex-start; line-height: 1.15; text-align: left; }
.callout-text strong { font-size: 12px; font-weight: 800; font-variant-numeric: tabular-nums; }
.callout-text span { max-width: 112px; overflow: hidden; text-overflow: ellipsis; font-size: 11px; color: var(--text-2); }
.callout-line { width: 2px; height: var(--lead); background: var(--route); }
.callout:hover .callout-card { box-shadow: 0 0 0 3px color-mix(in srgb, var(--route) 30%, transparent), 0 3px 10px rgba(0, 0, 0, .2); }
.bus-compact .callout { --lead: 8px; }
.bus-compact .callout-card { padding: 3px; border-color: #fff; border-radius: 50%; background: var(--route); color: #fff; }
.bus-compact .callout-card > svg { display: block; width: 12px; height: 12px; }
.bus-compact .callout-card .route-badge, .bus-compact .callout-text { display: none; }

.toast { position: fixed; z-index: 6; left: 50%; bottom: 28px; transform: translateX(-50%); max-width: min(560px, calc(100% - 32px)); padding: 12px 16px; border-radius: 14px; background: #191f28; color: #fff; font-size: 14px; box-shadow: var(--shadow); }
@media (prefers-color-scheme: dark) { .toast { background: #f2f4f6; color: #191f28; } }

/* Phones: full-width bottom sheet with peek / full sizes */
@media (max-width: 720px) {
  :root { --gap: 12px; }
  .topbar { left: var(--gap); right: var(--gap); width: auto; top: calc(var(--gap) + env(safe-area-inset-top)); }
  .brand-name { display: none; }
  .brand { padding: 0 8px; }
  .map-tools { top: auto; right: var(--gap); bottom: calc(var(--sheet-h) + 12px); flex-direction: column; align-items: flex-end; transition: bottom .25s ease; }
  .map-tools { gap: 6px; }
  .map-tools .tool { height: 40px; min-width: 40px; border-radius: 12px; }
  .map-tools .tool.wide span { display: none; }
  .map-tools .tool.wide { padding: 0; width: 40px; }
  .map-tools #nation, .map-tools .toggle { display: none; }
  .sheet { --sheet-h: 38vh; top: auto; left: 0; right: 0; bottom: 0; width: auto; height: var(--sheet-h); border-radius: 22px 22px 0 0; padding-bottom: env(safe-area-inset-bottom); transition: height .25s ease; }
  .sheet[data-size="full"] { --sheet-h: calc(100dvh - 76px); }
  .sheet-handle { display: grid; place-items: center; height: 22px; border: 0; background: transparent; flex: none; }
  .sheet-handle span { width: 40px; height: 5px; border-radius: 3px; background: var(--surface-3); }
  .view-head { padding-top: 4px; }
  .quick { display: none; }
  .sheet-foot { display: none; }
  .maplibregl-ctrl-bottom-right { display: none; }
  .toast { bottom: calc(38vh + 16px); }
}
body:has(.sheet[data-size="peek"]) { --sheet-h: 38vh; }
body:has(.sheet[data-size="full"]) { --sheet-h: calc(100dvh - 76px); }
