* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; overflow: hidden; }
body {
  background: var(--map-land); color: var(--text); font-family: var(--font); font-size: var(--fs-body);
  line-height: var(--lh-body); font-variant-numeric: tabular-nums; word-break: keep-all; overflow-wrap: anywhere;
  -webkit-text-size-adjust: 100%; -webkit-font-smoothing: antialiased;
}
button { font: inherit; color: inherit; background: none; border: 0; padding: 0; cursor: pointer; text-align: inherit; }
button:focus-visible { outline: 2px solid var(--bus-text); outline-offset: 2px; }
p, h1, h2, dl, dd { margin: 0; }
a { color: inherit; text-underline-offset: 3px; }
[hidden] { display: none !important; }

/* 지도 */
#map { position: fixed; inset: 0; background: var(--map-land); }
.leaflet-container { font: inherit; }
.leaflet-control-attribution {
  background: none !important; color: var(--map-label) !important; font-size: 10px !important; padding: 0 var(--sp-2) !important;
}
.leaflet-control-attribution a { color: inherit !important; text-decoration: none; }
.m { position: absolute; white-space: nowrap; transform: translate(-50%, -50%); line-height: 1.2; }
.m-text {
  font-size: 11px; font-weight: var(--fw-medium); color: var(--map-label); text-align: center;
  text-shadow: 0 0 3px var(--map-halo), 0 0 3px var(--map-halo), 0 0 3px var(--map-halo), 0 0 3px var(--map-halo);
}
.m-text.venue { font-size: 13px; font-weight: var(--fw-heavy); color: var(--text); }
.m-text.road { transform: translate(-50%, -50%) rotate(-57deg); letter-spacing: 2px; }
.m-start { width: 18px; height: 18px; border-radius: 50%; background: var(--walk); border: 5px solid var(--walk-case); box-shadow: 0 0 0 2px var(--walk); }
.m-start + .m-text, .m-from { font-size: 12px; font-weight: var(--fw-bold); color: var(--text); }
.m-exit {
  min-width: 16px; height: 16px; padding: 0 3px; border-radius: 4px; font-size: 10px; font-weight: var(--fw-bold); line-height: 16px; text-align: center;
  background: var(--map-halo); color: var(--map-label); border: 1px solid var(--map-label); line-height: 14px;
}
.m-exit.on { background: var(--walk); color: var(--walk-case); border-color: var(--walk); }
.m-dot { width: 14px; height: 14px; border-radius: 50%; background: var(--bus); border: 3px solid #fff; }
.m-dot.off { width: 10px; height: 10px; background: var(--map-halo); border: 2px solid var(--map-label); }
.m-tag { border-radius: var(--r-badge); padding: 5px 8px; font-size: 13px; font-weight: var(--fw-bold); }
.m-tag.on { background: var(--bus); color: var(--bus-on); }
.m-tag.on b { font-size: 16px; font-weight: var(--fw-heavy); }
.m-tag.plain { background: var(--btn-bg); color: var(--btn-text); }
.m-tag.off { font-size: 11px; font-weight: var(--fw-medium); background: var(--map-halo); color: var(--map-label); border: 1px solid var(--map-road-a); padding: 2px 6px; }
.at-r { transform: translate(14px, -50%); }
.at-l { transform: translate(calc(-100% - 14px), -50%); }
.at-b { transform: translate(-50%, 14px); }
.at-bl { transform: translate(calc(-100% - 15px), -32%); }
.at-t { transform: translate(-50%, calc(-100% - 14px)); }

/* 맨 위: 기준 시각 */
.top {
  position: fixed; z-index: 1000; left: var(--gutter); right: var(--gutter); top: max(var(--sp-3), env(safe-area-inset-top));
  display: flex; justify-content: space-between; align-items: center; min-height: var(--tap); padding: 0 var(--sp-4);
  background: var(--bg); border-radius: var(--r-btn); font-size: var(--fs-sub);
}
.clock { display: flex; gap: var(--sp-2); align-items: center; font-weight: var(--fw-bold); }
.clock b { font-size: var(--fs-note); padding: 2px 6px; border-radius: 4px; background: var(--surface-2); color: var(--text); }
.live { color: var(--text-2); min-height: var(--tap); font-weight: var(--fw-medium); }

/* 바텀시트 */
.sheet {
  position: fixed; z-index: 1001; left: 0; right: 0; bottom: 0; max-height: 66dvh; min-height: 0; display: flex; flex-direction: column;
  background: var(--bg); border-radius: var(--r-sheet) var(--r-sheet) 0 0; transition: transform .28s cubic-bezier(.2,.8,.2,1);
}
.sheet.drag { transition: none; }
.grip { height: 22px; flex: none; width: 100%; touch-action: none; display: grid; place-items: center; position: relative; }
.grip::after { content: ""; position: absolute; inset: -22px 0 -4px; }
.grip::before { content: ""; width: 40px; height: 4px; border-radius: 2px; background: var(--text-3); opacity: .6; }
.scroll { overflow-y: auto; overscroll-behavior: contain; padding: 0 var(--sp-2); }
.event { display: flex; justify-content: space-between; align-items: center; gap: var(--sp-3); padding: 0 var(--sp-2); font-size: var(--fs-sub); color: var(--text-2); }
.event p { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.event b { color: var(--text); font-weight: var(--fw-bold); }
.event button { flex: none; color: var(--text); font-weight: var(--fw-medium); min-height: 40px; display: flex; align-items: center; text-decoration: underline; text-underline-offset: 3px; }
h1:focus { outline: none; }
h1 { font-size: var(--fs-title); font-weight: var(--fw-heavy); line-height: var(--lh-tight); letter-spacing: -.02em; padding: 0 var(--sp-2) var(--sp-2); }

.row {
  display: grid; grid-template-columns: 1fr auto; column-gap: var(--sp-3); align-items: center; width: 100%;
  padding: 6px var(--sp-2); border-radius: var(--r-row); border: 2px solid transparent; position: relative;
}
.row:not(.on) + .row:not(.on)::before { content: ""; position: absolute; left: var(--sp-2); right: var(--sp-2); top: -2px; border-top: 1px solid var(--line); }
.row.on { border-color: var(--line-strong); background: var(--surface); }
.who { min-width: 0; }
.name { display: flex; align-items: center; flex-wrap: wrap; gap: 6px; font-size: 18px; font-weight: var(--fw-bold); letter-spacing: -.02em; }
.sub { display: block; margin-top: 2px; font-size: var(--fs-sub); color: var(--text-2); }
.sub b { color: var(--text); font-weight: var(--fw-bold); }
.badge { display: inline-block; font-size: 15px; font-weight: var(--fw-heavy); line-height: 22px; padding: 0 7px; border-radius: var(--r-badge); background: var(--bus); color: var(--bus-on); letter-spacing: 0; }
.badge.s5, .badge.s9 { min-width: 24px; padding: 0; text-align: center; border-radius: 12px; line-height: 24px; font-size: 16px; }
.badge.s5 { background: var(--line5); color: var(--line5-on); }
.badge.s9 { background: var(--line9); color: var(--line9-on); }
.num { text-align: right; line-height: 1; white-space: nowrap; }
.num .n { font-size: 28px; font-weight: var(--fw-heavy); letter-spacing: -.03em; }
.num .u { font-size: var(--fs-sub); font-weight: var(--fw-bold); margin-left: 1px; }
.num .t { display: block; margin-top: 4px; line-height: 1.35; font-size: var(--fs-note); color: var(--text-2); }
.num.walk .n, .num.walk .u { color: var(--text-2); font-weight: var(--fw-bold); }
.row.on .num .n { font-size: var(--fs-eta); }
.row.on .num .u { font-size: 18px; }
.num .ok { color: var(--bus-text); font-weight: var(--fw-bold); }
.num .hurry { color: var(--text); font-weight: var(--fw-bold); text-decoration: underline; text-underline-offset: 3px; }

/* 구간 막대 (도보 → 기다림 → 버스) */
.bar { grid-column: 1 / -1; display: flex; gap: 2px; margin-top: 10px; height: 26px; font-size: 13px; font-weight: var(--fw-bold); }
.bar i { font-style: normal; display: grid; place-items: center; min-width: 0; white-space: nowrap; overflow: hidden; padding: 0 var(--sp-2); }
.bar i:first-child { border-radius: var(--r-badge) 0 0 var(--r-badge); }
.bar i:last-child { border-radius: 0 var(--r-badge) var(--r-badge) 0; }
.miss1 { grid-column: 1 / -1; margin-top: 6px; font-size: var(--fs-note); color: var(--text-2); }
.miss1 b { color: var(--text); font-weight: var(--fw-bold); }
.bar .w { background: var(--surface-2); color: var(--text); }
.bar .g { border: 1px dashed var(--text-3); color: var(--text-2); font-weight: var(--fw-medium); }
.bar .b { background: var(--bus); color: var(--bus-on); flex: 1 0 auto; }
.bar .l5 { background: var(--line5); color: var(--line5-on); flex: 0 0 64px; }
.bar .l9 { background: var(--line9); color: var(--line9-on); flex: 0 0 64px; }
.foot { padding: var(--sp-2) var(--sp-2) var(--sp-3); font-size: var(--fs-note); color: var(--text-3); }

.cta { flex: none; padding: var(--sp-3) var(--gutter) max(var(--sp-3), env(safe-area-inset-bottom)); border-top: 1px solid var(--line); }
.cta button {
  display: block; width: 100%; height: var(--cta-h); border-radius: var(--r-btn); background: var(--btn-bg); color: var(--btn-text);
  font-size: var(--fs-cta); font-weight: var(--fw-bold); text-align: center;
}
.cta button:active { opacity: .85; }

/* 탑승 위치 · 공연 · 출차 화면 */
.sheet[data-view="home"] { max-height: 68dvh; }
.sheet[data-view="event"], .sheet[data-view="car"] { max-height: 78dvh; }
.pad { padding: var(--sp-3) var(--sp-2); }
.back { min-height: 40px; padding: 0 var(--sp-2); font-size: var(--fs-sub); font-weight: var(--fw-medium); color: var(--text-2); }
h1.route { display: flex; align-items: center; gap: var(--sp-2); padding-bottom: var(--sp-1); }
h1.route .badge { font-size: 18px; line-height: 28px; padding: 0 var(--sp-2); }
h1.route .badge.s5, h1.route .badge.s9 { min-width: 28px; padding: 0; border-radius: 14px; font-size: 18px; }
.block { padding: var(--sp-3) var(--sp-2); border-top: 1px solid var(--line); }
.block:first-of-type, .block.first { border-top: 0; padding-top: var(--sp-1); }
h2 { font-size: var(--fs-body); font-weight: var(--fw-bold); line-height: var(--lh-tight); margin-bottom: var(--sp-3); }
.note { font-size: var(--fs-sub); color: var(--text-2); margin-top: var(--sp-2); }
.note b { color: var(--text); font-weight: var(--fw-bold); }
.small { font-size: var(--fs-note); color: var(--text-3); margin-top: var(--sp-2); }

/* 도착까지 남은 분 */
.etas { display: flex; align-items: flex-end; gap: var(--sp-6); }
.eta { line-height: 1; }
.eta .k { display: block; font-size: var(--fs-note); color: var(--text-2); margin-bottom: 6px; }
.eta .n { font-size: 28px; font-weight: var(--fw-heavy); letter-spacing: -.03em; }
.eta .u { font-size: var(--fs-sub); font-weight: var(--fw-bold); margin-left: 1px; }
.eta .v { display: block; margin-top: 6px; font-size: var(--fs-sub); font-weight: var(--fw-bold); color: var(--text-2); }
.eta.on .n { font-size: 56px; }
.eta.on .u { font-size: 20px; }
.eta .v.ok { color: var(--bus-text); }
.eta .v.hurry { color: var(--text); text-decoration: underline; text-underline-offset: 3px; }
.eta.miss .n, .eta.miss .u { color: var(--text-3); text-decoration: line-through; text-decoration-thickness: 2px; }
.etas + .bar, .bar + .small { margin-top: var(--sp-3); }
.state { font-size: 28px; font-weight: var(--fw-heavy); line-height: var(--lh-tight); letter-spacing: -.02em; }
.links { display: flex; flex-wrap: wrap; gap: 0 var(--sp-4); margin-top: var(--sp-1); font-size: var(--fs-sub); }
.links a, .links button { min-height: var(--tap); display: inline-flex; align-items: center; text-decoration: underline; text-underline-offset: 3px; font-weight: var(--fw-medium); }

/* 길 어느 쪽에 서나 */
.road { display: block; width: 100%; max-width: 400px; margin: 0 auto; height: auto; }
.road text { font-family: var(--font); font-size: 13px; fill: var(--text-2); }
.road .rd { fill: var(--surface-2); }
.road .side { font-size: 14px; font-weight: 700; fill: var(--text); }
.road .mid { stroke: var(--text-3); stroke-width: 2; stroke-dasharray: 10 8; }
.road .zebra { stroke: var(--text-2); stroke-width: 5; }
.road .pw { fill: none; stroke: var(--walk); stroke-width: 5; stroke-linecap: round; stroke-linejoin: round; stroke-dasharray: .1 9; }
.road .plate { fill: var(--bus); }
.road .plate-t { font-size: 21px; font-weight: 800; fill: var(--bus-on); text-anchor: middle; }
.road .off { fill: none; stroke: var(--text-3); stroke-width: 1.5; stroke-dasharray: 4 4; }
.road .off-t { font-size: 16px; font-weight: 500; fill: var(--text-3); text-anchor: middle; }
.road .on-t { font-weight: 700; fill: var(--text); }
.road .ex { fill: var(--surface); stroke: var(--line); }
.road .ex-t { font-size: 11px; text-anchor: middle; }
.road .ex.on { fill: var(--btn-bg); stroke: var(--btn-bg); }
.road .ex-t.on { fill: var(--btn-text); font-weight: 700; }
.road .go { fill: none; stroke: var(--bus-text); stroke-width: 6; stroke-linecap: round; stroke-linejoin: round; }
.road .go.off { stroke: var(--text-3); stroke-width: 3; stroke-dasharray: none; opacity: .7; }
.road .bus { fill: var(--bus); }
.road .glass { fill: var(--bus-on); opacity: .85; }
.road .bus-t { font-size: 12px; font-weight: 800; fill: var(--bus-on); text-anchor: middle; }
.road .me { fill: var(--text); }
.road .sm { font-size: 11px; text-anchor: middle; }

/* 정류소 표지에서 확인할 것 */
.kv { display: grid; grid-template-columns: auto 1fr; gap: var(--sp-2) var(--sp-4); align-items: baseline; }
.kv dt { font-size: var(--fs-sub); color: var(--text-2); }
.kv dd { font-size: 22px; font-weight: var(--fw-heavy); line-height: var(--lh-tight); letter-spacing: -.02em; }
.kv dd small { font-size: var(--fs-sub); font-weight: var(--fw-medium); color: var(--text-2); letter-spacing: 0; }
.kv.sm dd { font-size: var(--fs-body); font-weight: var(--fw-bold); letter-spacing: 0; }

.chips { display: flex; flex-wrap: wrap; gap: var(--sp-2); }
.chips button { min-height: 40px; padding: 0 14px; border-radius: 20px; background: var(--surface); border: 1px solid var(--line); font-size: var(--fs-sub); font-weight: var(--fw-medium); }
.chips button[aria-pressed="true"] { background: var(--btn-bg); color: var(--btn-text); border-color: var(--btn-bg); font-weight: var(--fw-bold); }
.goto { display: flex; justify-content: space-between; align-items: center; gap: var(--sp-3); width: 100%; min-height: 56px; padding: var(--sp-2); border-top: 1px solid var(--line); margin-top: -1px; }
.goto b { font-weight: var(--fw-bold); }
.goto span { color: var(--text-2); font-size: var(--fs-sub); }
.ev { display: block; width: 100%; padding: var(--sp-4) var(--sp-3); border-radius: var(--r-row); border: 2px solid var(--line-strong); background: var(--surface); margin-bottom: var(--sp-3); }
.ev.no { border: 1px dashed var(--line); background: none; color: var(--text-2); }
.ev b { display: block; font-size: 18px; font-weight: var(--fw-bold); }
.ev i { font-style: normal; display: block; font-size: var(--fs-sub); color: var(--text-2); margin-top: 2px; }
details { margin-top: var(--sp-3); font-size: var(--fs-sub); color: var(--text-2); }
summary { min-height: var(--tap); display: flex; align-items: center; cursor: pointer; }
details p { font-size: var(--fs-note); margin-bottom: var(--sp-2); color: var(--text-3); }

/* 출차 그래프 */
.chart { position: relative; margin-top: var(--sp-3); }
.chart svg { display: block; width: 100%; height: auto; touch-action: pan-y; }
.chart text { font-family: var(--font); font-size: 11px; fill: var(--text-2); }
.chart .grid { stroke: var(--line); }
.chart .b { fill: var(--text-3); }
.chart .b.hi { fill: var(--text); }
.chart .cmp { stroke: var(--bus-text); stroke-width: 2; fill: none; }
.chart .mk { stroke: var(--text-2); stroke-dasharray: 3 3; }
.tip { position: absolute; display: none; transform: translate(-50%, 0); pointer-events: none; white-space: nowrap; padding: 4px 8px; border-radius: var(--r-badge); background: var(--btn-bg); color: var(--btn-text); font-size: 13px; font-weight: var(--fw-bold); }
.legend { display: flex; flex-wrap: wrap; gap: var(--sp-1) var(--sp-4); font-size: var(--fs-note); color: var(--text-2); margin-top: var(--sp-3); }
.legend i { display: inline-block; width: 12px; height: 12px; margin-right: 6px; background: var(--text-3); vertical-align: -1px; }
.legend i.c { height: 3px; background: var(--bus-text); vertical-align: 3px; }
table { width: 100%; border-collapse: collapse; font-size: var(--fs-sub); }
th, td { padding: 6px 0; text-align: right; border-bottom: 1px solid var(--line); font-weight: var(--fw-regular); }
th:first-child, td:first-child { text-align: left; }

@media (min-width: 768px) {
  .sheet, .top { left: var(--sp-6); right: auto; width: 400px; }
  .sheet, .sheet[data-view] { bottom: var(--sp-6); border-radius: var(--r-sheet); max-height: calc(100dvh - 108px); }
}
@media (prefers-reduced-motion: reduce) { .sheet { transition: none; } }
