:root {
    --bg: #f5efe4;
    --panel: rgba(255, 255, 255, 0.96);
    --panel-border: rgba(34, 34, 34, 0.12);
    --ink: #171717;
    --muted: #5b5b5b;
    --victoria: #0098d8;
    --active-line: #0098d8;
    --good: #0e9f6e;
    --warn: #d97706;
    --bad: #b91c1c;
    --shadow: 0 20px 60px rgba(23, 23, 23, 0.12);
    --map-grid:
        linear-gradient(180deg, rgba(255, 255, 255, 0.99), rgba(255, 255, 255, 0.99)),
        linear-gradient(90deg, rgba(39, 116, 174, 0.05) 1px, transparent 1px),
        linear-gradient(0deg, rgba(39, 116, 174, 0.05) 1px, transparent 1px);
}

* {
    box-sizing: border-box;
}

body {
    margin: 0;
    min-height: 100vh;
    font-family: 'Space Grotesk', sans-serif;
    color: var(--ink);
    background:
        radial-gradient(circle at top left, rgba(0, 152, 216, 0.18), transparent 28%),
        radial-gradient(circle at 85% 15%, rgba(249, 115, 22, 0.12), transparent 22%),
        linear-gradient(180deg, #fff8ee 0%, #f5efe4 40%, #eee4d5 100%);
}

.shell {
    width: min(1400px, calc(100vw - 32px));
    margin: 0 auto;
    padding: 24px 0 32px;
}

.topbar,
.status-strip,
.footer {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
}

.eyebrow {
    margin: 0 0 4px;
    text-transform: uppercase;
    letter-spacing: 0.12em;
    font-size: 0.75rem;
    color: var(--muted);
}

h1,
h2,
p {
    margin: 0;
}

h1 {
    font-size: clamp(2rem, 4vw, 3.5rem);
    line-height: 0.95;
}

h2 {
    font-size: 1rem;
    margin-bottom: 12px;
}

.controls {
    display: flex;
    align-items: end;
    gap: 12px;
}

.control {
    display: flex;
    flex-direction: column;
    gap: 8px;
    font-size: 0.875rem;
    color: var(--muted);
}

.control select,
.control input {
    border: 1px solid var(--panel-border);
    border-radius: 14px;
    padding: 10px 14px;
    background: rgba(255, 255, 255, 0.72);
    font: inherit;
}

.line-picker {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    max-width: 320px;
}

.line-chip {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 9px 12px;
    border-radius: 999px;
    border: 1px solid rgba(23, 23, 23, 0.08);
    background: rgba(255, 255, 255, 0.72);
    color: var(--ink);
    cursor: pointer;
    user-select: none;
    transition: transform 150ms ease, box-shadow 150ms ease, border-color 150ms ease;
}

.line-chip:hover {
    transform: translateY(-1px);
    box-shadow: 0 8px 20px rgba(23, 23, 23, 0.08);
}

.line-chip-input {
    position: absolute;
    opacity: 0;
    pointer-events: none;
}

.line-chip-swatch {
    width: 10px;
    height: 10px;
    border-radius: 50%;
    background: var(--line-chip-color, var(--active-line));
    box-shadow: 0 0 0 3px rgba(255, 255, 255, 0.9);
}

.line-chip-input:checked + .line-chip-swatch {
    box-shadow: 0 0 0 3px rgba(255, 255, 255, 0.92), 0 0 0 6px color-mix(in srgb, var(--line-chip-color, var(--active-line)) 32%, transparent);
}

.line-chip:has(.line-chip-input:checked) {
    border-color: color-mix(in srgb, var(--line-chip-color, var(--active-line)) 44%, rgba(23, 23, 23, 0.08));
    background: color-mix(in srgb, var(--line-chip-color, var(--active-line)) 14%, rgba(255, 255, 255, 0.78));
}

.control-toggle {
    align-items: center;
}

.status-strip {
    margin: 18px 0 18px;
    padding: 14px 18px;
    border: 1px solid var(--panel-border);
    border-radius: 22px;
    background: var(--panel);
    backdrop-filter: blur(14px);
    box-shadow: var(--shadow);
}

.status-chips {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
}

.status-chip {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 8px 12px;
    border-radius: 999px;
    font-size: 0.875rem;
    background: rgba(255, 255, 255, 0.72);
    border: 1px solid rgba(23, 23, 23, 0.08);
}

.status-dot {
    width: 10px;
    height: 10px;
    border-radius: 50%;
}

.freshness {
    text-align: right;
    font-size: 0.875rem;
    color: var(--muted);
}

.source-mode {
    display: inline-block;
    margin-left: 8px;
    padding: 4px 8px;
    border-radius: 999px;
    font-family: 'IBM Plex Mono', monospace;
    font-size: 0.75rem;
    background: rgba(23, 23, 23, 0.06);
}

.layout {
    display: grid;
    grid-template-columns: minmax(0, 1fr) 320px;
    gap: 20px;
}

.map-panel,
.detail-panel {
    min-width: 0;
}

.map-frame,
.card {
    position: relative;
    border: 1px solid var(--panel-border);
    border-radius: 28px;
    background: var(--panel);
    backdrop-filter: blur(14px);
    box-shadow: var(--shadow);
    overflow: hidden;
}

.map-frame {
    min-height: 76vh;
    display: grid;
}

#tube-map {
    display: block;
    width: 100%;
    height: min(78vh, 1200px);
    touch-action: none;
    background: var(--map-grid);
    background-size: auto, 140px 140px, 140px 140px;
}

.map-frame > #tube-map,
.map-frame > .geo-map {
    grid-area: 1 / 1;
}

.geo-map {
    width: 100%;
    height: min(78vh, 1200px);
    position: relative;
}

.geo-map::after {
    content: '';
    position: absolute;
    inset: 0;
    pointer-events: none;
    background:
        linear-gradient(180deg, rgba(248, 246, 232, 0.22), rgba(232, 247, 233, 0.18)),
        radial-gradient(circle at 50% 45%, rgba(210, 244, 228, 0.16), transparent 42%);
    mix-blend-mode: multiply;
    opacity: 0.95;
    z-index: 350;
}

.leaflet-container {
    background: #e6efe2;
    font-family: 'Space Grotesk', sans-serif;
}

.geo-map-shell .leaflet-tile-pane {
    filter: saturate(0.58) sepia(0.14) hue-rotate(-10deg) brightness(1.04) contrast(0.92);
    opacity: 0.82;
}

.geo-map-shell .leaflet-overlay-pane,
.geo-map-shell .leaflet-marker-pane,
.geo-map-shell .leaflet-tooltip-pane,
.geo-map-shell .leaflet-control-container,
.geo-map-shell .leaflet-attribution-flag {
    position: relative;
    z-index: 400;
}

.geo-map-shell .leaflet-control-zoom {
    border: 0;
    box-shadow: 0 10px 26px rgba(23, 23, 23, 0.14);
}

.geo-map-shell .leaflet-control-zoom a {
    border: 0;
    color: #2f3d4c;
    background: rgba(255, 255, 255, 0.86);
    backdrop-filter: blur(8px);
}

.leaflet-tooltip {
    border: 0;
    border-radius: 999px;
    box-shadow: 0 8px 22px rgba(23, 23, 23, 0.12);
    font-family: 'IBM Plex Mono', monospace;
    font-size: 0.72rem;
    padding: 6px 10px;
    background: rgba(255, 255, 255, 0.82);
    color: #25364f;
    backdrop-filter: blur(8px);
}

.warning-banner {
    position: absolute;
    top: 18px;
    right: 18px;
    padding: 10px 14px;
    border-radius: 999px;
    background: rgba(217, 119, 6, 0.92);
    color: #fff;
    font-size: 0.875rem;
}

.hidden {
    display: none !important;
}

.detail-panel {
    display: flex;
    flex-direction: column;
    gap: 16px;
}

.card {
    padding: 20px;
}

.detail-content {
    display: grid;
    gap: 12px;
    font-size: 0.95rem;
}

.detail-grid {
    display: grid;
    gap: 8px;
}

.detail-grid strong,
.footer,
.mono {
    font-family: 'IBM Plex Mono', monospace;
}

.debug-note {
    font-family: 'IBM Plex Mono', monospace;
    font-size: 0.8rem;
    color: var(--muted);
}

.legend {
    padding-left: 18px;
    margin: 0;
    display: grid;
    gap: 10px;
}

.legend-swatch {
    display: inline-block;
    width: 16px;
    height: 16px;
    margin-right: 8px;
    vertical-align: text-bottom;
    border-radius: 50%;
}

.legend-swatch-line {
    border-radius: 999px;
    background: var(--active-line);
}

.legend-swatch-train {
    background: #fff;
    border: 3px solid var(--active-line);
}

.legend-swatch-station {
    background: #fff;
    border: 2px solid #171717;
}

.footer {
    margin-top: 18px;
    font-size: 0.8rem;
    color: var(--muted);
}

.map-line {
    fill: none;
    stroke: var(--active-line);
    stroke-width: 14;
    stroke-linejoin: round;
    stroke-linecap: round;
}

.map-line-shadow {
    fill: none;
    stroke: rgba(255, 255, 255, 0.98);
    stroke-width: 24;
    stroke-linejoin: round;
    stroke-linecap: round;
}

.station-node {
    fill: #fff;
    stroke: #1f2937;
    stroke-width: 3.5;
    cursor: pointer;
}

.station-node.is-selected {
    stroke: #f97316;
    stroke-width: 5.5;
}

.station-interchange.is-selected {
    stroke: #f97316;
}

.station-tick {
    stroke: #1f2937;
    stroke-width: 5;
    stroke-linecap: round;
    pointer-events: none;
}

.station-tick.is-selected {
    stroke: #f97316;
    stroke-width: 6.5;
}

.station-hit-area {
    fill: transparent;
    cursor: pointer;
}

.station-label {
    font-size: 14px;
    fill: #22356f;
    font-weight: 500;
    letter-spacing: 0.01em;
    paint-order: stroke;
    stroke: rgba(255, 255, 255, 0.98);
    stroke-width: 4px;
    stroke-linejoin: round;
}

.train-group.is-selected .train-halo {
    opacity: 1;
    animation: pulse-ring 1.4s ease-in-out infinite;
}

.train-hit-area {
    fill: transparent;
    cursor: pointer;
}

.train-halo {
    fill: rgba(0, 152, 216, 0.18);
    stroke: rgba(0, 152, 216, 0.34);
    stroke-width: 3;
}

.train-marker {
    fill: #ffffff;
    stroke: #0b7fb6;
    stroke-width: 6;
    filter: drop-shadow(0 8px 14px rgba(0, 0, 0, 0.22));
    cursor: pointer;
    transition: opacity 300ms ease;
}

.train-marker.is-selected {
    stroke: #f97316;
    stroke-width: 6;
}

.train-nose {
    fill: #0b7fb6;
    pointer-events: none;
}

.train-nose.is-selected {
    fill: #f97316;
}

.train-arrow {
    fill: #0b7fb6;
    pointer-events: none;
}

.train-arrow.is-selected {
    fill: #f97316;
}

.train-marker.debug-low {
    opacity: 0.45;
}

.train-label {
    fill: #111827;
    font-family: 'IBM Plex Mono', monospace;
    font-size: 10px;
    font-weight: 700;
    pointer-events: none;
    paint-order: stroke;
    stroke: rgba(255, 251, 245, 0.98);
    stroke-width: 3px;
    stroke-linejoin: round;
}

.geo-train-icon-wrapper {
    background: transparent;
    border: 0;
}

.geo-train-icon {
    width: 28px;
    height: 16px;
    border-radius: 8px;
    background: rgba(255, 255, 255, 0.92);
    border: 3px solid color-mix(in srgb, var(--train-color) 78%, white);
    box-shadow: 0 6px 16px rgba(23, 23, 23, 0.16);
    position: relative;
    backdrop-filter: blur(6px);
}

.geo-train-core {
    position: absolute;
    left: 7px;
    top: 4px;
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: color-mix(in srgb, var(--train-color) 78%, white);
    opacity: 0.9;
}

.geo-train-nose {
    position: absolute;
    right: -6px;
    top: 2px;
    width: 0;
    height: 0;
    border-top: 5px solid transparent;
    border-bottom: 5px solid transparent;
    border-left: 6px solid color-mix(in srgb, var(--train-color) 82%, white);
}

.geo-train-arrow {
    position: absolute;
    left: 12px;
    top: 3px;
    width: 0;
    height: 0;
    border-top: 5px solid transparent;
    border-bottom: 5px solid transparent;
    border-left: 8px solid color-mix(in srgb, var(--train-color) 82%, white);
}

.geo-train-icon.is-selected {
    border-color: #f97316;
}

.geo-train-icon.is-selected .geo-train-core {
    background: #f97316;
}

.geo-train-icon.is-selected .geo-train-nose,
.geo-train-icon.is-selected .geo-train-arrow {
    border-left-color: #f97316;
}

@keyframes pulse-ring {
    0% {
        transform: scale(0.92);
        opacity: 0.55;
    }

    50% {
        transform: scale(1.06);
        opacity: 1;
    }

    100% {
        transform: scale(0.92);
        opacity: 0.55;
    }
}

@media (max-width: 980px) {
    .layout {
        grid-template-columns: 1fr;
    }

    .topbar,
    .status-strip,
    .footer {
        flex-direction: column;
        align-items: stretch;
    }

    .controls {
        justify-content: space-between;
    }

    #tube-map {
        height: 68vh;
    }
}
