:root,
html[data-theme="dark"] {
    --bg: #07111f;
    --bg-2: #0b1b30;
    --panel: rgba(9, 18, 33, 0.82);
    --panel-strong: rgba(13, 27, 46, 0.94);
    --text: #eef6ff;
    --muted: #b7c8db;
    --line: rgba(185, 209, 236, 0.14);
    --accent: #6dd3ff;
    --accent-deep: #9d8dff;
    --accent-soft: rgba(109, 211, 255, 0.14);
    --shadow: 0 24px 70px rgba(0, 0, 0, 0.34);
    --input-bg: rgba(8, 16, 30, 0.92);
    --map-bg: #081525;
    --political-fill: rgba(109, 211, 255, 0.08);
    --political-line: rgba(109, 211, 255, 0.55);
    --province-line: rgba(255, 255, 255, 0.14);
    --station: #6dd3ff;
    --relay: #ffb86b;
    --gateway: #ff3b30;
    --route: rgba(255, 255, 255, 0.28);
    --grid: rgba(148, 181, 218, 0.08);
}

html[data-theme="light"] {
    --bg: #f5f1e8;
    --bg-2: #fffaf2;
    --panel: rgba(255, 252, 246, 0.86);
    --panel-strong: #fffaf1;
    --text: #1f2933;
    --muted: #52606d;
    --line: rgba(31, 41, 51, 0.12);
    --accent: #ff6b35;
    --accent-deep: #004e89;
    --accent-soft: rgba(255, 107, 53, 0.08);
    --shadow: 0 18px 50px rgba(0, 0, 0, 0.09);
    --input-bg: #fffdf8;
    --map-bg: #f2eadc;
    --political-fill: rgba(0, 78, 137, 0.07);
    --political-line: rgba(0, 118, 196, 0.48);
    --province-line: rgba(31, 41, 51, 0.18);
    --station: #0b6fa9;
    --relay: #b45f06;
    --gateway: #d7261b;
    --route: rgba(31, 41, 51, 0.32);
    --grid: rgba(0, 0, 0, 0.018);
}

* {
    box-sizing: border-box;
}

html,
body {
    margin: 0;
    min-height: 100%;
}

body {
    font-family: "Space Grotesk", sans-serif;
    color: var(--text);
    background:
        radial-gradient(circle at 15% 20%, rgba(141, 126, 255, 0.18), transparent 18%),
        radial-gradient(circle at 82% 12%, rgba(109, 211, 255, 0.14), transparent 20%),
        linear-gradient(180deg, var(--bg-2) 0%, var(--bg) 100%);
}

body::before {
    content: "";
    position: fixed;
    inset: 0;
    pointer-events: none;
    background-image: linear-gradient(var(--grid) 1px, transparent 1px), linear-gradient(90deg, var(--grid) 1px, transparent 1px);
    background-size: 24px 24px;
    mask-image: linear-gradient(180deg, rgba(0, 0, 0, 0.45), transparent 90%);
}

.map-page-shell {
    width: min(1680px, calc(100% - 16px));
    margin: 0 auto;
    padding: 12px 0 20px;
}

.hero-copy,
.hero-meta,
.panel,
.site-menu-card {
    background: var(--panel);
    border: 1px solid rgba(255, 255, 255, 0.35);
    border-radius: 28px;
    backdrop-filter: blur(14px);
    box-shadow: var(--shadow);
}

.eyebrow,
.panel-kicker,
.meta-label {
    margin: 0 0 10px;
    font-size: 0.78rem;
    letter-spacing: 0.16em;
    text-transform: uppercase;
    color: var(--accent-deep);
}

h1,
h2,
h3,
strong,
p {
    margin: 0;
}

.meta-card {
    padding: 16px 18px;
    border-radius: 22px;
    background: var(--panel-strong);
    border: 1px solid var(--line);
}

.meta-card-right {
    text-align: right;
}

.view-switch {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 6px;
    border-radius: 999px;
    border: 1px solid var(--line);
    background: var(--input-bg);
}

.view-switch-button {
    border: 0;
    border-radius: 999px;
    background: transparent;
    color: var(--muted);
    padding: 10px 14px;
    font: inherit;
    cursor: pointer;
}

.view-switch-button.is-active {
    background: var(--accent-soft);
    color: var(--text);
}

.map-layout {
    display: grid;
    grid-template-columns: minmax(0, 1fr) 290px;
    gap: 14px;
    align-items: start;
}

.panel {
    padding: 20px;
}

.map-panel {
    padding: 12px;
}

.map-toolbar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 14px;
    margin-bottom: 12px;
}

.map-toolbar-left {
    display: flex;
    align-items: center;
    gap: 12px;
}

.map-toolbar-meta {
    display: flex;
    align-items: center;
    gap: 12px;
    color: var(--muted);
    font-size: 0.9rem;
}

.back-button {
    display: inline-flex;
    align-items: center;
    min-height: 42px;
    padding: 0 16px;
    border-radius: 999px;
    border: 1px solid var(--line);
    background: var(--input-bg);
    color: var(--text);
    text-decoration: none;
}

.theme-chip {
    border: 1px solid var(--line);
    background: var(--input-bg);
    color: var(--text);
    border-radius: 999px;
    padding: 10px 14px;
    font: inherit;
    cursor: pointer;
}

.map-updated strong {
    color: var(--text);
}

.network-map {
    width: 100%;
    height: clamp(420px, 80vh, 1040px);
    border-radius: 22px;
    background: var(--map-bg);
    overflow: hidden;
}

.legend-panel {
    display: grid;
    align-content: start;
    gap: 18px;
    position: sticky;
    top: 12px;
}

.panel-header h2 {
    font-size: 1.45rem;
    letter-spacing: -0.04em;
}

.legend-group {
    display: grid;
    gap: 10px;
    color: var(--muted);
}

.legend-item {
    display: flex;
    align-items: center;
    gap: 10px;
    color: var(--text);
}

.legend-toggle {
    display: flex;
    align-items: center;
    gap: 10px;
    color: var(--text);
    cursor: pointer;
}

.legend-toggle input {
    accent-color: var(--accent);
}

.legend-dot {
    width: 14px;
    height: 14px;
    border-radius: 50%;
    display: inline-block;
}

.legend-dot-station {
    background: var(--station);
}

.legend-dot-relay {
    background: var(--relay);
}

.legend-dot-gateway {
    background: var(--gateway);
}

.legend-line {
    width: 18px;
    height: 0;
    border-top: 2px dashed var(--route);
    display: inline-block;
}

.stats-list {
    display: grid;
    gap: 8px;
}

.stats-item {
    display: flex;
    justify-content: space-between;
    gap: 12px;
    padding: 10px 12px;
    border-radius: 14px;
    background: var(--panel-strong);
    border: 1px solid var(--line);
}

.stats-item strong {
    color: var(--text);
}

.route-note code {
    font-family: "IBM Plex Mono", monospace;
}

.leaflet-container {
    font-family: "Space Grotesk", sans-serif;
    background: var(--map-bg);
    cursor: crosshair;
}

.leaflet-tooltip.station-label {
    border: 0;
    box-shadow: none;
    background: transparent;
    color: var(--text);
    font-size: 0.78rem;
    font-weight: 500;
    padding: 0;
    white-space: nowrap;
    cursor: pointer;
    user-select: none;
}

.leaflet-tooltip.station-label:active {
    cursor: grabbing;
}

.physical-view .leaflet-tooltip.station-label {
    color: #17212b;
    text-shadow:
        -1px -1px 0 rgba(255, 248, 230, 0.98),
        1px -1px 0 rgba(255, 248, 230, 0.98),
        -1px 1px 0 rgba(255, 248, 230, 0.98),
        1px 1px 0 rgba(255, 248, 230, 0.98),
        0 0 6px rgba(255, 248, 230, 0.55);
}

.leaflet-tooltip.region-cluster-tooltip {
    border: 1px solid rgba(255, 255, 255, 0.14);
    border-radius: 10px;
    background: rgba(8, 16, 30, 0.92);
    color: #f7fbff;
    box-shadow: 0 10px 24px rgba(0, 0, 0, 0.28);
    font-size: 0.82rem;
    font-weight: 600;
    padding: 8px 10px;
}

.leaflet-tooltip.region-cluster-tooltip::before {
    border-top-color: rgba(8, 16, 30, 0.92);
}

html[data-theme="light"] .leaflet-tooltip.station-label {
    color: #24323f;
    text-shadow:
        -1px -1px 0 rgba(255, 250, 242, 0.96),
        1px -1px 0 rgba(255, 250, 242, 0.96),
        -1px 1px 0 rgba(255, 250, 242, 0.96),
        1px 1px 0 rgba(255, 250, 242, 0.96);
}

html[data-theme="light"] .physical-view .leaflet-tooltip.station-label {
    color: #17212b;
    text-shadow:
        -1px -1px 0 rgba(255, 248, 230, 0.98),
        1px -1px 0 rgba(255, 248, 230, 0.98),
        -1px 1px 0 rgba(255, 248, 230, 0.98),
        1px 1px 0 rgba(255, 248, 230, 0.98),
        0 0 6px rgba(255, 248, 230, 0.55);
}

html[data-theme="light"] .leaflet-tooltip.region-cluster-tooltip {
    border-color: rgba(31, 41, 51, 0.12);
    background: rgba(255, 250, 242, 0.96);
    color: #1f2933;
    box-shadow: 0 8px 20px rgba(0, 0, 0, 0.12);
}

html[data-theme="light"] .leaflet-tooltip.region-cluster-tooltip::before {
    border-top-color: rgba(255, 250, 242, 0.96);
}

.physical-view .leaflet-tooltip.region-cluster-tooltip {
    background: rgba(3, 10, 18, 0.96);
    color: #ffe082;
    border-color: rgba(255, 211, 77, 0.28);
}

.physical-view .leaflet-tooltip.region-cluster-tooltip::before {
    border-top-color: rgba(3, 10, 18, 0.96);
}

html[data-theme="light"] .physical-view .leaflet-tooltip.region-cluster-tooltip {
    background: rgba(255, 248, 230, 0.98);
    color: #6b4a00;
    border-color: rgba(177, 121, 0, 0.18);
}

html[data-theme="light"] .physical-view .leaflet-tooltip.region-cluster-tooltip::before {
    border-top-color: rgba(255, 248, 230, 0.98);
}

.leaflet-popup-content {
    margin: 12px 14px;
    font-size: 0.92rem;
}

.popup-map-link {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    margin-top: 8px;
    padding: 4px 8px;
    border-radius: 999px;
    border: 1px solid color-mix(in srgb, var(--accent) 42%, transparent);
    background: color-mix(in srgb, var(--accent) 14%, var(--panel));
    color: var(--text);
    font-size: 0.75rem;
    font-weight: 700;
    text-decoration: none;
}

.popup-map-links {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
}

.popup-map-link:hover {
    background: color-mix(in srgb, var(--accent) 22%, var(--panel));
}

.leaflet-control-layers {
    border-radius: 16px;
    overflow: hidden;
}

.leaflet-control-attribution {
    font-size: 0.72rem;
}

.region-cluster-icon {
    background: transparent;
    border: 0;
}

.region-cluster {
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    background: color-mix(in srgb, var(--accent) 26%, var(--panel-strong));
    border: 1px solid color-mix(in srgb, var(--accent) 60%, transparent);
    box-shadow: 0 0 0 8px color-mix(in srgb, var(--accent) 10%, transparent);
    color: var(--text);
    font-weight: 700;
}

.region-cluster-count {
    font-size: 0.9rem;
    line-height: 1;
}

.province-label-icon {
    background: transparent;
    border: 0;
}

.province-label {
    color: #ffd34d;
    font-size: 0.68rem;
    font-weight: 700;
    letter-spacing: 0.06em;
    text-shadow: 0 0 6px rgba(0, 0, 0, 0.65);
    white-space: nowrap;
}

.physical-view .province-label {
    color: #ffd34d;
    text-shadow:
        -1px -1px 0 rgba(6, 16, 28, 0.95),
        1px -1px 0 rgba(6, 16, 28, 0.95),
        -1px 1px 0 rgba(6, 16, 28, 0.95),
        1px 1px 0 rgba(6, 16, 28, 0.95);
}

html[data-theme="light"] .province-label {
    color: #b17900;
    text-shadow:
        -1px -1px 0 rgba(255, 250, 242, 0.96),
        1px -1px 0 rgba(255, 250, 242, 0.96),
        -1px 1px 0 rgba(255, 250, 242, 0.96),
        1px 1px 0 rgba(255, 250, 242, 0.96);
}

html[data-theme="light"] .physical-view .province-label {
    color: #8a5a00;
    text-shadow:
        -1px -1px 0 rgba(245, 241, 232, 0.98),
        1px -1px 0 rgba(245, 241, 232, 0.98),
        -1px 1px 0 rgba(245, 241, 232, 0.98),
        1px 1px 0 rgba(245, 241, 232, 0.98);
}

.status-note {
    padding: 12px;
    border-radius: 14px;
    background: var(--panel-strong);
    border: 1px solid var(--line);
    color: var(--muted);
}

.site-footer {
    display: flex;
    flex-wrap: wrap;
    gap: 12px 18px;
    align-items: center;
    justify-content: center;
    padding: 14px 8px 4px;
    color: var(--muted);
    font-size: 0.82rem;
}

.site-footer a {
    color: var(--text);
    text-decoration: underline;
}

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

    .network-map {
        height: clamp(480px, 78vh, 980px);
    }

    .legend-panel {
        display: none;
    }
}

@media (max-width: 640px) {
    .map-page-shell {
        width: min(100% - 16px, 1540px);
        padding-top: 16px;
    }

    .map-toolbar {
        align-items: center;
        gap: 8px;
        flex-wrap: wrap;
    }

    .map-toolbar-left,
    .map-toolbar-meta {
        flex-direction: row;
        align-items: center;
        flex-wrap: wrap;
        gap: 8px;
    }

    .back-button,
    .theme-chip,
    .view-switch-button {
        min-height: 34px;
        padding: 0 10px;
        font-size: 0.84rem;
    }

    .view-switch {
        padding: 4px;
        gap: 4px;
    }

    .map-updated {
        font-size: 0.8rem;
    }

    .network-map {
        height: clamp(420px, 72vh, 820px);
    }

    .site-footer {
        justify-content: flex-start;
        font-size: 0.76rem;
    }
}

@media (max-height: 820px) {
    .network-map {
        height: clamp(360px, 68vh, 760px);
    }
}
