:root {
    color-scheme: dark;
    --bg: #171b1e; --canvas-bg: #191e21; --panel: #14181b; --panel-2: #232a2e;
    --text: #e5e9e7; --muted: #98a6a8; --line: #333c40; --accent: #83c9b5;
    --fare-free: #73cbb8; --ok: #83c9b5; --danger: #ed9b8c; --shadow: rgba(0,0,0,.2);
    --sidebar-width: 280px;
}
body.light-theme {
    color-scheme: light;
    --bg: #f5f4f0; --canvas-bg: #f5f4f0; --panel: #fcfbf8; --panel-2: #eeede7;
    --text: #202c2c; --muted: #667472; --line: #dddfd7; --accent: #276953;
    --fare-free: #17816f; --ok: #276953; --danger: #a34233; --shadow: rgba(25,40,34,.08);
}
* { box-sizing: border-box; }
html, body { width: 100%; height: 100%; margin: 0; overflow: hidden; }
body { background: var(--bg); color: var(--text); font: 14px/1.5 "Segoe UI", "Microsoft YaHei", system-ui, sans-serif; -webkit-font-smoothing: antialiased; }
button, input, select { font: inherit; color: inherit; }
button, select, input { height: 36px; border: 1px solid var(--line); border-radius: 2px; background: var(--panel); padding: 0 12px; }
button { cursor: pointer; }
button:hover, select:hover { background: var(--panel-2); }
.segment-id-copy { height: auto; min-height: 28px; padding: 2px 7px; color: var(--accent); overflow-wrap: anywhere; text-align: left; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 3px; }
input::placeholder { color: var(--muted); }
.hidden { display: none !important; }
.app { width: 100%; height: 100dvh; display: flex; flex-direction: column; }
.topbar { min-height: 80px; padding: 16px 28px; display: flex; align-items: center; justify-content: space-between; gap: 24px; background: var(--panel); border-bottom: 1px solid var(--line); z-index: 10; }
.brand { display: flex; align-items: center; gap: 16px; min-width: 0; }
.mark { position: relative; font-size: 32px; font-weight: 800; line-height: 1; letter-spacing: -4px; padding-right: 4px; }
.mark span { display: block; height: 3px; background: var(--accent); margin-top: 5px; }
.title { font-size: 20px; font-weight: 650; letter-spacing: -.5px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 32vw; }
.subtitle { color: var(--muted); font-size: 11px; margin-top: 3px; letter-spacing: .4px; }
.toolbar { display: flex; align-items: center; gap: 20px; }
.search-box { position: relative; width: clamp(180px, 24vw, 320px); }
.search-box input { width: 100%; border-width: 0 0 1px; border-radius: 0; background: transparent; padding-left: 0; }
.search-results { position: absolute; top: calc(100% + 12px); right: 0; width: max(100%, 300px); max-height: 380px; overflow: auto; background: var(--panel); border: 1px solid var(--line); box-shadow: 0 12px 28px var(--shadow); }
.search-result { width: 100%; height: auto; min-height: 58px; display: grid; grid-template-columns: 16px minmax(0,1fr); grid-template-areas: "icon main" "icon meta"; column-gap: 12px; align-items: center; padding: 10px 16px; border: 0; border-bottom: 1px solid var(--line); border-radius: 0; text-align: left; }
.search-result.active { background: var(--panel-2); }
.search-swatch, .search-station-dot { grid-area: icon; width: 10px; height: 10px; }
.search-station-dot { border: 2px solid var(--muted); border-radius: 50%; }
.search-main { grid-area: main; font-weight: 600; }
.search-meta { grid-area: meta; font-size: 11px; color: var(--muted); }
.search-main, .search-meta { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.search-empty { padding: 20px; color: var(--muted); }
.select-wrap { display: flex; align-items: center; gap: 10px; font-size: 12px; color: var(--muted); }
.select-wrap select { max-width: 150px; color: var(--text); }
#themeToggle { font-size: 12px; }
.layout { flex: 1; min-height: 0; position: relative; display: grid; grid-template-columns: var(--sidebar-width) minmax(0,1fr); }
.layout.sidebar-collapsed { grid-template-columns: 0 minmax(0,1fr); }
.sidebar { display: flex; flex-direction: column; min-width: 0; overflow: auto; border-right: 1px solid var(--line); background: var(--panel); }
.sidebar-collapsed .sidebar { visibility: hidden; overflow: hidden; }
.panel { padding: 28px 20px; }
.panel-title { display: flex; justify-content: space-between; align-items: baseline; font-size: 15px; font-weight: 650; }
.index-count { font-size: 12px; font-weight: 400; font-variant-numeric: tabular-nums; color: var(--muted); }
.panel-caption { color: var(--muted); font-size: 11px; margin: 6px 0 22px; }
.line-filters { display: grid; }
.line-row { display: grid; grid-template-columns: 14px 4px minmax(0,1fr) auto; align-items: center; gap: 12px; min-height: 59px; border-top: 1px solid var(--line); cursor: pointer; }
.line-row:last-child { border-bottom: 1px solid var(--line); }
.line-row:hover { background: var(--panel-2); }
.line-row:has(input:not(:checked)) { opacity: .45; }
.line-row input { width: 13px; height: 13px; margin: 0; accent-color: var(--accent); }
.swatch { display: inline-block; flex: 0 0 auto; width: 4px; height: 14px; }
.line-row .swatch { height: 24px; }
.line-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 600; }
.line-id { display: none; }
.fare-badge { color: var(--muted); font-size: 10px; white-space: nowrap; font-weight: 400; }
.fare-free { color: var(--fare-free); }
.fare-paid { color: var(--danger); }
.sidebar-footer { margin-top: auto; padding: 20px; display: flex; align-items: center; gap: 8px; color: var(--muted); font-size: 10px; white-space: nowrap; }
.legend-station { width: 8px; height: 8px; border: 2px solid var(--muted); border-radius: 50%; }
.legend-train { width: 8px; height: 8px; background: var(--accent); border-radius: 50%; margin-left: 12px; }
.sidebar-edge-toggle { position: absolute; top: 50%; left: var(--sidebar-width); transform: translateY(-50%); width: 20px; height: 48px; padding: 0; border-left: 0; z-index: 5; color: var(--muted); font-size: 22px; }
.sidebar-collapsed .sidebar-edge-toggle { left: 0; }
.map-shell { position: relative; min-width: 0; min-height: 0; overflow: hidden; background: var(--canvas-bg); }
#mapCanvas, #trainCanvas { display: block; width: 100%; height: 100%; position: absolute; inset: 0; }
#mapCanvas { touch-action: none; cursor: grab; }
#mapCanvas:active { cursor: grabbing; }
#trainCanvas { pointer-events: none; }
.map-toolbar { position: absolute; top: 20px; left: 28px; right: 24px; display: flex; justify-content: space-between; pointer-events: none; gap: 10px; }
.map-toolbar button, .layer-controls { pointer-events: auto; }
.layer-controls { display: flex; background: var(--panel); border: 1px solid var(--line); }
.layer-toggle { border: 0; border-radius: 0; height: 32px; font-size: 12px; padding: 0 13px; }
.layer-toggle::before { content: ""; display: inline-block; width: 4px; height: 4px; background: var(--accent); vertical-align: middle; margin-right: 7px; }
.layer-toggle.is-off { color: var(--muted); }
.layer-toggle.is-off::before { background: var(--line); }
#fitButton { height: 34px; font-size: 12px; }
.map-footer { position: absolute; bottom: 0; left: 0; right: 0; min-height: 34px; display: flex; align-items: center; justify-content: space-between; gap: 16px; padding: 8px 24px; background: var(--panel); border-top: 1px solid var(--line); color: var(--muted); font-size: 10px; pointer-events: none; }
.status-pill { min-width: 0; }
.status-pill::before { content: ""; width: 5px; height: 5px; display: inline-block; margin-right: 8px; background: var(--ok); }
.status-pill[data-state="error"]::before { background: var(--danger); }
.zoom-hint { white-space: nowrap; }
.zoom-controls { position: absolute; bottom: 58px; right: 24px; display: grid; border: 1px solid var(--line); }
.zoom-controls button { border: 0; border-radius: 0; width: 34px; height: 34px; padding: 0; font-size: 20px; }
.zoom-controls button + button { border-top: 1px solid var(--line); }
.detail-popup { position: absolute; top: 72px; right: 24px; width: min(370px, calc(100% - 48px)); max-height: calc(100% - 132px); display: flex; overflow: hidden; background: var(--panel); border: 1px solid var(--line); box-shadow: 0 12px 32px var(--shadow); z-index: 4; }
.details-body { min-width: 0; width: 100%; overflow: auto; overscroll-behavior: contain; padding: 24px; font-size: 12px; line-height: 1.65; }
.details-body > * + * { margin-top: 12px; }
.detail-close { position: absolute; top: 12px; right: 12px; width: 28px; height: 28px; border: 0; padding: 0; color: var(--muted); font-size: 22px; }
.detail-heading { padding-right: 24px; font-size: 24px; font-weight: 650; letter-spacing: -.6px; line-height: 1.35; overflow-wrap: anywhere; }
.detail-heading .fare-badge { vertical-align: middle; }
.detail-sub, .muted { color: var(--muted); }
.color-code { font: 10px Consolas, monospace; margin-left: 6px; }
.detail-section-title { padding-top: 20px; font-weight: 650; font-size: 12px; }
.kv { display: grid; grid-template-columns: 64px minmax(0,1fr); gap: 12px; }
.kv > span:first-child, .relation-row > span:first-child { color: var(--muted); }
.kv > div { overflow-wrap: anywhere; }
.badge-list { display: flex; flex-wrap: wrap; gap: 4px 10px; }
.badge { display: inline-flex; align-items: center; gap: 6px; height: auto; min-height: 26px; padding: 1px 0; background: transparent; border: 0; font-size: 12px; text-align: left; }
.badge:hover { background: transparent; text-decoration: underline; text-underline-offset: 4px; }
.badge .fare-badge { display: none; }
.badge.pass { color: var(--muted); }
.platform-detail { border-top: 1px solid var(--line); padding: 18px 0; }
.platform-title { display: flex; justify-content: space-between; font-size: 14px; font-weight: 600; margin-bottom: 12px; }
.platform-number { border: 0; border-left: 3px solid var(--accent); border-radius: 0; padding: 0 0 0 9px; height: auto; background: transparent; font-weight: 600; }
.relation-row { display: grid; grid-template-columns: 4em minmax(0,1fr); gap: 8px; align-items: baseline; margin-top: 7px; }
.arrival { display: flex; flex-wrap: wrap; align-items: baseline; gap: 4px 12px; }
.arrival-distance { font-size: 14px; font-weight: 600; font-variant-numeric: tabular-nums; }
.arrival-note { font-size: 11px; color: var(--muted); }
.path-row { position: relative; display: grid; grid-template-columns: 25px minmax(0,1fr) auto; align-items: center; gap: 12px; padding: 12px 0; border-bottom: 1px solid var(--line); cursor: pointer; }
.path-row:hover { background: var(--panel-2); }
.path-index { font: 11px Consolas, monospace; color: var(--muted); }
.path-name { font-weight: 600; }
.path-sub { font-size: 10px; color: var(--muted); }
.status-tag { font-size: 10px; color: var(--accent); }
.status-tag.pass { color: var(--muted); }
.warning { color: var(--danger); }
@media (max-width: 1100px) {
    :root { --sidebar-width: 236px; }
    .topbar { padding: 14px 20px; }
    .toolbar { gap: 12px; }
    .panel { padding: 24px 16px; }
    .zoom-hint { display: none; }
}
@media (max-width: 720px) {
    .topbar { min-height: 0; padding: 12px 16px; gap: 12px; flex-wrap: wrap; }
    .brand { gap: 12px; }
    .title { max-width: 75vw; font-size: 18px; }
    .mark { font-size: 27px; }
    .toolbar { width: 100%; gap: 10px; }
    .search-box { flex: 1; width: auto; min-width: 80px; }
    .search-results { left: 0; right: auto; width: min(360px, calc(100vw - 32px)); }
    .select-wrap > span { display: none; }
    .select-wrap select { max-width: 96px; padding: 0 6px; }
    #themeToggle { padding: 0 8px; }
    .layout, .layout.sidebar-collapsed { grid-template-columns: minmax(0,1fr); }
    .sidebar { position: absolute; inset: 0 auto 0 0; width: min(260px, 80vw); z-index: 6; box-shadow: 8px 0 20px var(--shadow); }
    .sidebar-edge-toggle { left: min(260px, 80vw); z-index: 7; }
    .map-toolbar { top: 16px; left: 24px; right: 16px; }
    .detail-popup { top: auto; bottom: 48px; left: 16px; right: 16px; width: auto; max-height: min(58%, 460px); }
    .details-body { padding: 20px; }
    .map-footer { padding: 7px 16px; font-size: 10px; }
    .zoom-controls { right: 16px; bottom: 56px; }
    .map-shell:has(.detail-popup:not(.hidden)) .zoom-controls { display: none; }
}
@media (prefers-reduced-motion: reduce) { *, *::before, *::after { scroll-behavior: auto !important; } }
.line-row .line-name { height: auto; padding: 16px 0; border: 0; background: transparent; border-radius: 0; text-align: left; font-size: 13px; }
