.map-page {
    --map-bg: #0c141a;
    --map-ink: #e9f3f8;
    --map-muted: rgba(233, 243, 248, 0.65);
    --map-panel: rgba(12, 18, 22, 0.84);
    --map-border: rgba(255, 255, 255, 0.12);
    --map-accent: #41d0ff;
    --map-accent-2: #d8ff57;
    --map-warning: #ffd47a;
    --map-shadow: 0 28px 70px rgba(0, 0, 0, 0.45);
    font-family: "IBM Plex Sans", sans-serif;
    color: var(--map-ink);
    position: relative;
    z-index: 0;
    background: var(--map-bg);
    border-radius: 18px;
    padding: 12px 0 24px;
}

.map-page::before {
    content: "";
    position: absolute;
    inset: 0;
    border-radius: 18px;
    background: radial-gradient(900px circle at 20% -10%, rgba(58, 117, 148, 0.45), transparent 60%),
        radial-gradient(800px circle at 90% 0%, rgba(34, 78, 92, 0.5), transparent 50%);
    pointer-events: none;
    z-index: -1;
}

.map-header {
    display: flex;
    flex-wrap: wrap;
    align-items: flex-end;
    justify-content: space-between;
    gap: 16px;
    margin-bottom: 18px;
}

.map-headline h1 {
    font-family: "Space Grotesk", sans-serif;
    font-size: clamp(2rem, 4vw, 3.2rem);
    letter-spacing: -0.02em;
    margin-bottom: 8px;
}

.map-eyebrow {
    text-transform: uppercase;
    letter-spacing: 0.28em;
    font-size: 0.7rem;
    color: var(--map-accent);
    margin-bottom: 12px;
    font-weight: 600;
}

.map-subtitle {
    color: var(--map-muted);
    max-width: 520px;
}

.map-meta {
    display: flex;
    gap: 10px;
    flex-wrap: wrap;
}

.map-pill {
    border: 1px solid var(--map-border);
    padding: 6px 12px;
    border-radius: 999px;
    font-size: 0.8rem;
    letter-spacing: 0.04em;
    text-transform: uppercase;
    background: rgba(10, 14, 18, 0.5);
}

.map-wrap {
    position: relative;
    width: 100vw;
    margin-left: calc(50% - 50vw);
    margin-right: calc(50% - 50vw);
    /* Expand the map to reach the footer area while still being bounded */
    height: clamp(420px, calc(100vh - 160px), 860px);
    border-radius: 28px;
    overflow: hidden;
    background: #0a1116;
    box-shadow: var(--map-shadow);
    border: 1px solid rgba(255, 255, 255, 0.08);
    opacity: 0.96;
    transition: opacity 0.6s ease;
}

.map-wrap.is-ready {
    opacity: 1;
}

.map-canvas {
    height: 100%;
    width: 100%;
}

.map-panel {
    position: absolute;
    top: 18px;
    right: 18px;
    width: min(280px, 82vw);
    display: flex;
    flex-direction: column;
    gap: 14px;
    background: var(--map-panel);
    border: 1px solid var(--map-border);
    border-radius: 18px;
    padding: 16px;
    backdrop-filter: blur(10px);
    box-shadow: 0 12px 30px rgba(0, 0, 0, 0.35);
    z-index: 2200; /* ensure controls appear above Leaflet map panes */
}

.map-panel-section h2 {
    font-size: 0.9rem;
    text-transform: uppercase;
    letter-spacing: 0.18em;
    color: var(--map-accent);
    margin-bottom: 10px;
}

.layer-toggle {
    display: flex;
    align-items: center;
    gap: 10px;
    font-size: 0.95rem;
    color: var(--map-ink);
    margin-bottom: 8px;
}

.layer-toggle input {
    accent-color: var(--map-accent);
    width: 16px;
    height: 16px;
}

.layer-toggle.is-disabled {
    opacity: 0.45;
}

.range-control {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    font-size: 0.85rem;
    color: var(--map-muted);
    margin-bottom: 8px;
}

.range-control input {
    flex: 1;
    accent-color: var(--map-accent-2);
}

.map-status {
    font-size: 0.8rem;
    color: var(--map-warning);
    line-height: 1.4;
    display: none;
}

.map-status.is-visible {
    display: block;
}

.map-legend {
    position: absolute;
    left: 18px;
    bottom: 18px;
    background: rgba(10, 14, 18, 0.82);
    border: 1px solid var(--map-border);
    border-radius: 16px;
    padding: 12px 14px;
    backdrop-filter: blur(10px);
    min-width: 180px;
    z-index: 2200; /* keep legend above map tiles/overlays */
}

.time-rail {
    position: absolute;
    left: 18px;
    right: 18px;
    bottom: 18px;
    background: linear-gradient(180deg, rgba(10,14,18,0.9), rgba(10,14,18,0.75));
    border: 1px solid var(--map-border);
    border-radius: 14px;
    padding: 12px 14px;
    backdrop-filter: blur(8px);
    box-shadow: 0 18px 46px rgba(0, 0, 0, 0.45);
    z-index: 2300; /* above controls but below any modal UI */
}

.time-rail-head {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 12px;
    margin-bottom: 10px;
}

.time-rail-label {
    font-size: 0.85rem;
    text-transform: uppercase;
    letter-spacing: 0.18em;
    color: var(--map-accent-2);
    margin-bottom: 6px;
    font-weight: 600;
}

.time-rail-note {
    font-size: 0.82rem;
    color: var(--map-muted);
}

.time-rail-value {
    font-family: "Space Grotesk", sans-serif;
    font-size: 0.95rem;
    color: var(--map-ink);
    text-align: right;
    white-space: nowrap;
}

.time-rail input[type="range"] {
    width: 100%;
    accent-color: var(--map-accent);
}

.time-rail input[type="range"]:disabled {
    opacity: 0.55;
}

.legend-title {
    font-size: 0.85rem;
    text-transform: uppercase;
    letter-spacing: 0.18em;
    color: var(--map-accent);
    margin-bottom: 10px;
}

.legend-grid {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 8px;
    font-size: 0.8rem;
    color: var(--map-muted);
}

.legend-item {
    display: flex;
    align-items: center;
    gap: 6px;
}

.legend-swatch {
    width: 16px;
    height: 16px;
    border-radius: 4px;
    border: 1px solid rgba(255, 255, 255, 0.2);
    display: inline-block;
}

.bortle-1 {
    background: transparent;
    border: 1px dashed rgba(255, 255, 255, 0.5);
}

.bortle-2 { background: #a6dfff; }
.bortle-3 { background: #2e8bff; }
.bortle-4 { background: #3cc86a; }
.bortle-5 { background: #ffd84d; }
.bortle-6 { background: #ff9f2e; }
.bortle-7 { background: #ff4d4d; }
.bortle-8 { background: #ffffff; }
.bortle-9 { background: #000000; }

.leaflet-tile.bortle-layer {
    filter: saturate(1.15) contrast(1.05);
}

@media (max-width: 900px) {
    .map-header {
        align-items: flex-start;
    }

    .map-wrap {
        height: clamp(420px, calc(100vh - 160px), 720px);
    }

    .map-panel {
        top: auto;
        bottom: 18px;
        right: 50%;
        transform: translateX(50%);
        width: min(320px, 88vw);
    }

    .map-legend {
        left: 18px;
        top: 18px;
        bottom: auto;
    }

    .time-rail-head {
        flex-direction: column;
    }

    .time-rail-value {
        text-align: left;
    }
}

@media (max-width: 640px) {
    .map-headline h1 {
        font-size: clamp(1.8rem, 7vw, 2.6rem);
    }

    .legend-grid {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }
}

body.night-mode .map-page {
    --map-bg: #050709;
    --map-panel: rgba(6, 10, 12, 0.92);
    --map-border: rgba(120, 150, 170, 0.2);
    --map-muted: rgba(233, 243, 248, 0.7);
}
