:root {
  --bg: #F6F6F3;
  --surface: #FFFFFF;
  --surface-2: #EFEFEA;
  --seg: #E6E6E0;
  --line: #E8E8E2;
  --border: #DCDCD5;
  --text: #16181D;
  --muted: #5B606B;
  --faint: #8E929B;
  --accent: #1F4FD8;
  --accent-soft: #EAF0FF;
  --on-accent: #FFFFFF;
  --warn: #B45309;
  --warn-soft: #FFF6EB;
  --warn-line: #F0C99B;
  --shadow: 0 1px 2px rgba(0, 0, 0, .06), 0 4px 16px rgba(0, 0, 0, .04);
  --radius: 16px;
  --tabbar-h: 64px;
  --safe-b: env(safe-area-inset-bottom, 0px);
  color-scheme: light dark;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #111317;
    --surface: #1B1E24;
    --surface-2: #23272E;
    --seg: #262A31;
    --line: #2B2F36;
    --border: #353A43;
    --text: #EDEEF0;
    --muted: #A2A7B1;
    --faint: #7C818B;
    --accent: #7FA2FF;
    --accent-soft: #1E2A4A;
    --on-accent: #0D1530;
    --warn: #F2A659;
    --warn-soft: #2E2214;
    --warn-line: #6B4A22;
    --shadow: none;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--bg);
  color: var(--text);
  font: 400 15px/1.4 Inter, system-ui, -apple-system, "Segoe UI", sans-serif;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
}
a { color: var(--accent); }
button { font: inherit; color: inherit; cursor: pointer; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 6px; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

.app { max-width: 560px; margin: 0 auto; min-height: 100%; }
.view { padding: 0 16px calc(var(--tabbar-h) + var(--safe-b) + 24px); outline: none; }
.loading { color: var(--muted); padding: 40px 4px; }

/* ---------- Header ---------- */
.top { padding: max(20px, env(safe-area-inset-top)) 4px 14px; display: flex; justify-content: space-between; align-items: flex-end; gap: 12px; }
.top h1 { margin: 0; font-size: 28px; font-weight: 700; letter-spacing: -.02em; }
.eyebrow { font-size: 13px; color: var(--muted); font-weight: 500; }
.progress { display: flex; flex-direction: column; align-items: flex-end; gap: 6px; font-size: 12px; color: var(--muted); font-weight: 500; white-space: nowrap; }
.progress .bar { width: 96px; height: 4px; background: var(--seg); border-radius: 2px; overflow: hidden; }
.progress .bar i { display: block; height: 100%; background: var(--accent); }

.section-title { margin: 22px 4px 10px; font-size: 12px; font-weight: 600; color: var(--muted); text-transform: uppercase; letter-spacing: .06em; display: flex; justify-content: space-between; align-items: baseline; }
.section-title small { text-transform: none; letter-spacing: 0; font-weight: 500; font-size: 13px; }

/* ---------- Hero (next up) ---------- */
.hero { background: var(--accent); color: var(--on-accent); border-radius: 20px; padding: 18px; display: flex; flex-direction: column; gap: 14px; }
.hero-top { display: flex; justify-content: space-between; align-items: center; gap: 8px; }
.hero-when { font-size: 12px; font-weight: 600; letter-spacing: .06em; text-transform: uppercase; opacity: .9; }
.hero .pill { background: rgba(255, 255, 255, .2); color: inherit; }
.hero-route { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.hero-route .end { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.hero-route .end:last-child { align-items: flex-end; text-align: right; }
.hero-code { font-size: 34px; font-weight: 700; letter-spacing: -.02em; line-height: 1.05; }
.hero-sub { font-size: 13px; opacity: .88; }
.hero-title { font-size: 22px; font-weight: 700; letter-spacing: -.01em; }
.hero-arrow { width: 56px; height: 16px; flex-shrink: 0; stroke: currentColor; fill: none; stroke-width: 1.6; stroke-linecap: round; }
.hero-meta { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; padding-top: 12px; border-top: 1px solid rgba(255, 255, 255, .25); }
.hero-meta span { display: block; font-size: 11px; opacity: .8; }
.hero-meta b { font-size: 15px; font-weight: 600; }
.hero .btn-light { background: var(--surface); color: var(--accent); }
@media (prefers-color-scheme: dark) { .hero .btn-light { background: #0D1530; color: #CFDBFF; } }

.countdown { background: var(--surface); border-radius: 20px; padding: 22px 18px; box-shadow: var(--shadow); display: flex; flex-direction: column; gap: 4px; }
.countdown b { font-size: 44px; letter-spacing: -.03em; line-height: 1; }

/* ---------- Lists ---------- */
.list { background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow); overflow: hidden; }
.row { display: flex; gap: 14px; align-items: center; padding: 13px 16px; text-decoration: none; color: inherit; min-height: 56px; position: relative; }
.row + .row::before { content: ""; position: absolute; top: 0; right: 0; left: 16px; border-top: 1px solid var(--line); }
.list.timed .row + .row::before { left: 74px; }
.row.done { opacity: .45; }
.row.done .row-title { text-decoration: line-through; }
.row-time { width: 44px; flex-shrink: 0; font-size: 13px; font-weight: 600; font-variant-numeric: tabular-nums; }
.row-time.soft { color: var(--muted); font-weight: 500; font-size: 12px; }
.row-main { flex: 1; display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.row-title { font-size: 15px; font-weight: 500; }
.row-sub { font-size: 13px; color: var(--muted); }
.row-sub.warn { color: var(--warn); font-weight: 500; }
.chev { width: 18px; height: 18px; stroke: var(--faint); fill: none; stroke-width: 2; stroke-linecap: round; flex-shrink: 0; }
.empty { color: var(--muted); padding: 16px; font-size: 14px; }

.cards { display: flex; flex-direction: column; gap: 8px; }
.card { background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow); padding: 14px 16px; display: flex; gap: 14px; align-items: center; text-decoration: none; color: inherit; min-height: 64px; }
.card.past { opacity: .5; }
.card.next { box-shadow: inset 0 0 0 2px var(--accent); }
.card.pending { box-shadow: inset 0 0 0 1px var(--warn-line); }
.date-badge { width: 44px; flex-shrink: 0; display: flex; flex-direction: column; align-items: center; line-height: 1.1; }
.date-badge small { font-size: 11px; font-weight: 600; color: var(--muted); text-transform: uppercase; }
.date-badge b { font-size: 20px; }
.card.next .date-badge small, .card.next .date-badge b { color: var(--accent); }
.card-title { font-size: 16px; font-weight: 600; }

.pill { display: inline-block; font-size: 11px; font-weight: 600; padding: 3px 8px; border-radius: 999px; white-space: nowrap; background: var(--surface-2); color: var(--muted); }
.pill.warn { color: var(--warn); background: var(--warn-soft); box-shadow: inset 0 0 0 1px var(--warn-line); }
.pill.accent { color: var(--on-accent); background: var(--accent); }
.pill.ok { color: var(--accent); background: var(--accent-soft); }

.alert { display: flex; gap: 12px; align-items: center; background: var(--warn-soft); color: var(--text); border-radius: var(--radius); padding: 12px 16px; text-decoration: none; margin-top: 12px; box-shadow: inset 0 0 0 1px var(--warn-line); }
.alert b { color: var(--warn); }

/* ---------- Controls ---------- */
.seg { display: grid; grid-auto-flow: column; grid-auto-columns: minmax(0, 1fr); background: var(--seg); border-radius: 12px; padding: 3px; margin: 0 0 12px; }
.seg button, .seg a { border: 0; background: transparent; border-radius: 9px; padding: 9px 0; font-size: 13px; font-weight: 500; color: var(--muted); text-align: center; text-decoration: none; min-height: 38px; }
.seg [aria-selected="true"] { background: var(--surface); color: var(--text); font-weight: 600; box-shadow: 0 1px 2px rgba(0, 0, 0, .1); }

.chips { display: flex; gap: 8px; overflow-x: auto; padding: 2px 0 6px; margin: 0 -16px 8px; padding-inline: 16px; scrollbar-width: none; }
.chips::-webkit-scrollbar { display: none; }
.chip { border: 1px solid var(--border); background: var(--surface); color: var(--text); border-radius: 999px; padding: 8px 14px; font-size: 13px; font-weight: 500; white-space: nowrap; display: inline-flex; align-items: center; gap: 6px; min-height: 36px; }
.chip[aria-pressed="true"] { background: var(--text); color: var(--bg); border-color: var(--text); font-weight: 600; }
.chip .dot { width: 8px; height: 8px; border-radius: 50%; }

.toolbar { display: flex; justify-content: space-between; align-items: center; padding: 0 4px 8px; font-size: 13px; color: var(--muted); }
.link-btn { border: 0; background: none; color: var(--muted); font-weight: 600; font-size: 13px; padding: 10px 0; }

.btn { display: block; text-align: center; border: 1px solid var(--border); background: var(--surface); color: var(--text); font-weight: 600; font-size: 15px; padding: 13px; border-radius: 12px; text-decoration: none; min-height: 48px; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--on-accent); }
.btn-row { display: grid; grid-template-columns: repeat(auto-fit, minmax(0, 1fr)); gap: 10px; margin-top: 16px; }

.country-head { display: flex; justify-content: space-between; align-items: baseline; margin: 20px 4px 8px; }
.country-head h2 { margin: 0; font-size: 18px; font-weight: 700; display: flex; align-items: center; gap: 8px; }
.country-head h2 .dot { width: 10px; height: 10px; border-radius: 50%; }
.country-head span { font-size: 13px; color: var(--muted); }

/* ---------- Detail ---------- */
.back { display: inline-flex; align-items: center; gap: 4px; padding: max(14px, env(safe-area-inset-top)) 8px 10px 0; color: var(--accent); text-decoration: none; font-weight: 500; font-size: 15px; min-height: 44px; }
.back svg { width: 20px; height: 20px; stroke: currentColor; fill: none; stroke-width: 2; stroke-linecap: round; }
.ticket { background: var(--surface); border-radius: 20px; box-shadow: var(--shadow); overflow: hidden; }
.ticket-body { padding: 18px; display: flex; flex-direction: column; gap: 16px; }
.ticket-head { display: flex; justify-content: space-between; align-items: center; gap: 8px; font-weight: 600; font-size: 14px; }
.ticket-route { display: flex; justify-content: space-between; align-items: flex-end; gap: 8px; }
.ticket-route .end { display: flex; flex-direction: column; gap: 2px; }
.ticket-route .end:last-child { align-items: flex-end; text-align: right; }
.ticket-route .code { font-size: 40px; font-weight: 700; letter-spacing: -.03em; line-height: 1; }
.ticket-route .time { font-size: 22px; font-weight: 600; font-variant-numeric: tabular-nums; padding-top: 6px; }
.ticket-mid { display: flex; flex-direction: column; align-items: center; gap: 4px; padding-bottom: 34px; font-size: 12px; color: var(--muted); }
.ticket-mid svg { width: 64px; height: 12px; stroke: var(--faint); fill: none; stroke-width: 1.5; stroke-linecap: round; }
.ticket-grid { border-top: 1px dashed var(--border); display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; padding: 14px 18px; }
.kv span { display: block; font-size: 11px; color: var(--muted); }
.kv b { font-size: 15px; font-weight: 600; }
.code-box { background: var(--surface-2); margin: 0 12px 12px; border-radius: 12px; padding: 10px 10px 10px 14px; display: flex; justify-content: space-between; align-items: center; gap: 8px; }
.code-box span { display: block; font-size: 11px; color: var(--muted); }
.code-box b { font: 500 20px "JetBrains Mono", ui-monospace, monospace; letter-spacing: .06em; }
.icon-btn { border: 1px solid var(--border); background: var(--surface); border-radius: 10px; width: 44px; height: 44px; display: inline-flex; align-items: center; justify-content: center; flex-shrink: 0; }
.icon-btn svg { width: 18px; height: 18px; stroke: var(--text); fill: none; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.note { background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow); padding: 14px 16px; margin-top: 12px; font-size: 14px; color: var(--muted); }
.note b { color: var(--text); display: block; font-size: 15px; margin-bottom: 2px; }
.note.warn { background: var(--warn-soft); box-shadow: inset 0 0 0 1px var(--warn-line); }

/* ---------- Calendar ---------- */
.month { background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow); padding: 10px 6px 12px; }
.month h3 { margin: 4px 10px 8px; font-size: 15px; }
.wd, .grid7 { display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); text-align: center; }
.wd { font-size: 11px; font-weight: 600; color: var(--muted); padding-bottom: 4px; }
.grid7 { row-gap: 4px; }
.day { border: 0; background: none; padding: 4px 0 2px; display: flex; flex-direction: column; align-items: center; gap: 4px; min-height: 52px; }
.day .n { width: 30px; height: 30px; border-radius: 50%; display: flex; align-items: center; justify-content: center; font-size: 13px; font-weight: 600; font-variant-numeric: tabular-nums; }
.day.out .n { color: var(--faint); font-weight: 400; }
.day.today .n { background: var(--accent); color: var(--on-accent); }
.day[aria-pressed="true"] .n { box-shadow: 0 0 0 2px var(--text); }
.day .bar { width: 100%; height: 4px; }
.day .fl { width: 5px; height: 5px; border-radius: 50%; }
.legend { display: flex; flex-wrap: wrap; gap: 8px 14px; padding: 10px 10px 0; margin-top: 6px; border-top: 1px solid var(--line); font-size: 12px; color: var(--muted); }
.legend span { display: inline-flex; align-items: center; gap: 6px; }
.legend i { width: 14px; height: 4px; border-radius: 2px; }
.legend i.fl { width: 5px; height: 5px; border-radius: 50%; background: var(--text); }
.daynav { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 8px; }
.daynav h2 { margin: 0; font-size: 17px; text-align: center; flex: 1; }
.daynav h2 small { display: block; font-size: 13px; color: var(--muted); font-weight: 500; }
.daynav svg { width: 20px; height: 20px; stroke: var(--text); fill: none; stroke-width: 2; stroke-linecap: round; }
.week-day { margin-top: 14px; }
.week-day h3 { margin: 0 4px 8px; font-size: 13px; font-weight: 600; display: flex; gap: 8px; align-items: center; }
.week-day h3 .dot { width: 8px; height: 8px; border-radius: 50%; }
.week-day.is-today h3 { color: var(--accent); }

/* ---------- Map ---------- */
.map-wrap { position: fixed; inset: 0 0 calc(var(--tabbar-h) + var(--safe-b)) 0; }
#map { position: absolute; inset: 0; background: var(--surface-2); }
.map-filters { position: absolute; top: max(14px, env(safe-area-inset-top)); left: 12px; right: 12px; z-index: 500; display: flex; gap: 8px; overflow-x: auto; scrollbar-width: none; }
.map-filters .chip { box-shadow: 0 1px 4px rgba(0, 0, 0, .18); border-color: transparent; }
.sheet { position: absolute; left: 0; right: 0; bottom: 0; z-index: 600; background: var(--surface); border-radius: 20px 20px 0 0; box-shadow: 0 -4px 20px rgba(0, 0, 0, .12); padding: 8px 18px 16px; max-height: 38%; overflow-y: auto; max-width: 560px; margin: 0 auto; }
.sheet .grab { display: block; width: 36px; height: 4px; border-radius: 2px; background: var(--border); margin: 0 auto 10px; }
.sheet-head { display: flex; justify-content: space-between; align-items: center; gap: 12px; }
.sheet-head h2 { margin: 0; font-size: 20px; }
.sheet .list { box-shadow: none; margin-top: 10px; background: var(--surface-2); }
.city-label { background: none; border: 0; box-shadow: none; font: 600 12px Inter, sans-serif; color: #16181D; text-shadow: 0 0 3px #fff, 0 0 3px #fff, 0 0 3px #fff; padding: 0; }
.city-label::before { display: none; }
.leaflet-container { font-family: Inter, system-ui, sans-serif; }

/* ---------- Tab bar ---------- */
.tabbar { position: fixed; left: 0; right: 0; bottom: 0; z-index: 1000; display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); background: color-mix(in srgb, var(--surface) 92%, transparent); backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px); border-top: 1px solid var(--line); padding: 6px 8px calc(6px + var(--safe-b)); }
.tabbar a { display: flex; flex-direction: column; align-items: center; gap: 3px; padding: 6px 0; min-height: 52px; color: var(--muted); text-decoration: none; font-size: 11px; font-weight: 500; }
.tabbar svg { width: 22px; height: 22px; stroke: currentColor; fill: none; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.tabbar a[aria-current="page"] { color: var(--accent); font-weight: 600; }

.toast { position: fixed; left: 50%; bottom: calc(var(--tabbar-h) + var(--safe-b) + 16px); transform: translate(-50%, 20px); background: var(--text); color: var(--bg); padding: 10px 16px; border-radius: 999px; font-size: 14px; font-weight: 500; opacity: 0; pointer-events: none; transition: .2s; z-index: 2000; }
.toast.show { opacity: 1; transform: translate(-50%, 0); }

@media (prefers-reduced-motion: reduce) { * { transition: none !important; scroll-behavior: auto !important; } }
@media (min-width: 600px) { .top h1 { font-size: 32px; } }
