/* =========================================================================
   Home — the map
   ========================================================================= */

.page-map {
    height: 100vh;
    height: 100dvh;
    overflow: hidden;
}

/* The map owns the viewport, so the footer does not belong on this page. */
.page-map .site-footer {
    display: none;
}

.home {
    position: relative;
    height: 100%;
}

.home-map {
    position: absolute;
    inset: 0;
}

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

/* Mapbox paints its own background; keep it in the page's key. */
.home-map .mapboxgl-canvas {
    outline: none;
}

.home-map-notice {
    position: absolute;
    top: calc(var(--header-h) + 1.5rem);
    left: 50%;
    transform: translateX(-50%);
    max-width: 32rem;
    margin: 0;
    padding: 0.875rem 1.25rem;
    border: 1px solid var(--c-yellow);
    border-radius: 4px;
    background: rgba(23, 23, 23, 0.92);
    color: var(--c-yellow);
    font-size: var(--fs-card);
    text-align: center;
}

/* --- Island insets ------------------------------------------------------ */

.home-insets {
    position: absolute;
    top: calc(var(--header-h) + 1rem);
    left: var(--edge);
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

.home-inset {
    position: relative;
    margin: 0;
}

/* Two stacked 3:2 frames, shrinking on short screens so they stay clear of
   the filter bar. Their map zoom follows the width (see insetZoom()). */
.home-inset-canvas {
    width: min(420px, 30vw, calc((100dvh - var(--header-h) - 320px) * 0.75));
    aspect-ratio: 3 / 2;
    border: 1px solid var(--c-rule);
    border-radius: 4px;
    overflow: hidden;
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.6);
    /* Keeps Mapbox's raised controls inside the frame, under the caption. */
    isolation: isolate;
}

/* Captions run along the frame's foot, just inside its 1px border, on a
   strip of the map's own sea colour laid over the Mapbox wordmark. */
.home-inset-label {
    position: absolute;
    right: 1px;
    bottom: 1px;
    left: 1px;
    z-index: 1;
    padding: 0.5rem;
    border-radius: 4px;
    background: var(--c-sea);
    color: var(--c-ink);
    font-size: calc(var(--fs-label) * 1.125);
    line-height: 1;
    text-transform: uppercase;
    pointer-events: none;
}

/* --- Markers ------------------------------------------------------------ */

.map-marker {
    width: 12px;
    height: 12px;
    border: 0;
    border-radius: 50%;
    background: var(--c-ink);
    cursor: pointer;
    transition: transform 0.12s ease, background-color 0.12s ease;
}

.map-marker:hover,
.map-marker.is-active {
    transform: scale(1.45);
    background: var(--c-yellow);
}

/* visibility, not opacity: Mapbox sets the marker's opacity inline. */
.map-marker.is-hidden {
    visibility: hidden;
}

/* --- Zoom --------------------------------------------------------------- */

.home-zoom {
    position: absolute;
    top: calc(var(--header-h) + 1rem);
    right: var(--edge);
    z-index: 10;
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.home-zoom[hidden] {
    display: none;
}

.home-zoom-button {
    width: 36px;
    height: 36px;
    border: 1px solid var(--c-rule);
    border-radius: 50%;
    background: rgba(23, 23, 23, 0.72);
    backdrop-filter: blur(6px);
    -webkit-backdrop-filter: blur(6px);
    color: var(--c-ink);
    font-size: var(--fs-body);
    line-height: 1;
    transition: border-color 0.12s ease, color 0.12s ease;
}

.home-zoom-button:hover,
.home-zoom-button:focus-visible {
    border-color: var(--c-yellow);
    color: var(--c-yellow);
}

/* --- Prison card -------------------------------------------------------- */

.prison-card {
    position: absolute;
    top: 50%;
    left: 50%;
    z-index: 20;
    width: 369px;
    max-width: calc(100vw - var(--page-margin) * 2);
    padding: 1.5rem 1.5rem 1.25rem;
    border: 1px solid var(--c-ink);
    border-radius: var(--radius-card);
    background: rgba(23, 23, 23, 0.55);
    backdrop-filter: blur(3px);
    -webkit-backdrop-filter: blur(3px);
    transform: translate(-50%, -50%);
    text-align: center;
}

.prison-card[hidden] {
    display: none;
}

.prison-card-close {
    position: absolute;
    top: 0.9rem;
    right: 0.9rem;
    width: 12px;
    height: 12px;
    color: var(--c-ink);
}

.prison-card-close svg {
    display: block;
    width: 100%;
    height: 100%;
}

.prison-card-title {
    margin: 0;
    font-size: var(--fs-card);
    font-weight: 500;
    line-height: 1.15;
    text-transform: uppercase;
}

.prison-card-plan {
    display: flex;
    align-items: center;
    justify-content: center;
    height: 153px;
    margin-block: 1.5rem;
}

.prison-card-plan .planta-empty {
    width: 153px;
    height: 153px;
}

.prison-card-plan img {
    max-width: 154px;
    max-height: 153px;
    object-fit: contain;
}

.prison-card-more {
    display: inline-block;
    font-size: var(--fs-card);
}

/* --- Filter bar --------------------------------------------------------- */

/* Full-width strip that darkens the map towards the bottom edge, so the bar
   (or, on phones, its toggle and the inset captions) reads over any basemap.
   Deliberately no z-index: that would make it a stacking context and trap
   the mobile sheet beneath the header. Only its contents take clicks. */
.home-filters {
    position: absolute;
    right: 0;
    bottom: 0;
    left: 0;
    padding: 6rem var(--edge) var(--edge);
    background: linear-gradient(
        to bottom,
        rgba(23, 23, 23, 0) 0%,
        rgba(23, 23, 23, 0.85) 30%,
        var(--c-ground) 55%
    );
    pointer-events: none;
}

/* Contains Mapbox's control z-indexes, so the strip above paints over the
   bottom-corner logo and attribution. */
.home-map-canvas {
    isolation: isolate;
}

.home-filters > * {
    pointer-events: auto;
}

/* Both of these belong to the mobile sheet only. */
.home-filters-toggle,
.filters-apply {
    display: none;
}

.filters {
    position: relative;
    z-index: 30;
    padding: 1rem;
    border: 1px solid var(--c-rule);
    border-radius: 2rem;
    background: rgba(23, 23, 23, 0.72);
    backdrop-filter: blur(6px);
    -webkit-backdrop-filter: blur(6px);
}

.filters-row {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 1rem;
}

/* Each dropdown is a <details>; the menu is absolutely positioned so opening
   one never reflows the bar. */
.filter {
    position: relative;
}

.filter-summary {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
    padding: 9px 12px;
    border: 1px solid var(--c-mint);
    border-radius: var(--radius-pill);
    color: var(--c-mint);
    font-size: calc(var(--fs-body) * 0.75);
    text-transform: uppercase;
    list-style: none;
    cursor: pointer;
    user-select: none;
}

.filter-summary::-webkit-details-marker {
    display: none;
}

.filter-derived .filter-summary {
    border-color: var(--c-yellow);
    color: var(--c-yellow);
}

.filter-caret {
    width: 0;
    height: 0;
    border-right: 5px solid transparent;
    border-bottom: 7px solid currentColor;
    border-left: 5px solid transparent;
}

.filter[open] .filter-caret {
    transform: rotate(180deg);
}

.filter.is-engaged .filter-summary {
    background: var(--c-mint);
    color: var(--c-ground);
}

.filter-derived.is-engaged .filter-summary {
    background: var(--c-yellow);
}

.filter-menu {
    position: absolute;
    bottom: calc(100% + 9px);
    left: 0;
    z-index: 10;
    min-width: 100%;
    max-height: 40vh;
    padding: 4px 10px;
    overflow-y: auto;
    border: 1px solid var(--c-mint);
    border-radius: 4px;
    background: rgba(35, 35, 35, 0.96);
    backdrop-filter: blur(6px);
    -webkit-backdrop-filter: blur(6px);
}

.filter-derived .filter-menu {
    border-color: var(--c-yellow);
}

.filter-option {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 4px 12px;
    border-radius: var(--radius-pill);
    color: var(--c-mint);
    font-size: var(--fs-body);
    white-space: nowrap;
    cursor: pointer;
}

.filter-derived .filter-option {
    color: var(--c-yellow);
}

.filter-option:hover,
.filter-option:focus-within {
    background: var(--c-veil);
}

.filter-option input {
    width: 0.9em;
    height: 0.9em;
    margin: 0;
    accent-color: currentColor;
    flex-shrink: 0;
}

.filter-option-label {
    flex: 1 1 auto;
}

.filter-option-count {
    opacity: 0.5;
    font-size: 0.8em;
    font-variant-numeric: tabular-nums;
}

.filters-clear {
    padding: 9px 1.875rem;
    border-radius: 30px;
    background: var(--c-grey);
    color: var(--c-ground);
    font-size: calc(var(--fs-body) * 0.75);
    text-transform: uppercase;
    /* Keeps its place after the last filter whether shown or not, so engaging
       a filter never reflows the bar. */
    visibility: hidden;
}

.filters-clear.is-active {
    visibility: visible;
}

.filters-status {
    margin: 0.875rem 0 0;
    font-size: var(--fs-card);
    opacity: 0.65;
}

.filters-status:empty {
    display: none;
}

/* --- Narrow: filters become a sheet ------------------------------------- */

@media (max-width: 900px) {
    /* Side by side along the bottom, half the width each. */
    .home-insets {
        top: auto;
        right: var(--edge);
        bottom: 5rem;
        left: var(--edge);
        z-index: 31;
        flex-direction: row;
        gap: 10px;
    }

    .home-inset {
        flex: 1 1 0;
        min-width: 0;
    }

    .home-inset-canvas {
        width: 100%;
    }

    .home-inset-label {
        font-size: calc(0.6875rem * 1.125);
    }

    /* Taller here, so the darkening also runs up behind the insets. */
    .home-filters {
        padding: 12rem var(--edge) 1rem;
        text-align: center;
    }

    .home-filters-toggle {
        display: inline-block;
        padding: 0.5rem 1rem 0;
        font-size: var(--fs-nav);
        text-transform: uppercase;
    }

    .filters {
        position: fixed;
        inset: 0;
        z-index: 60;
        display: flex;
        flex-direction: column;
        justify-content: center;
        padding: var(--header-h) var(--page-margin) 5rem;
        border: 0;
        border-radius: 0;
        background: var(--c-ground);
        text-align: left;
        visibility: hidden;
        opacity: 0;
        transition: opacity 0.18s ease, visibility 0.18s ease;
    }

    .filters.is-open {
        visibility: visible;
        opacity: 1;
    }

    .filters-row {
        flex-direction: column;
        gap: 0.5rem;
        max-height: 100%;
        overflow-y: auto;
    }

    .filter {
        width: 100%;
        max-width: 378px;
    }

    /* The 75% type is a desktop-bar size; the sheet keeps full-size targets. */
    .filter-summary,
    .filters-clear {
        font-size: var(--fs-body);
    }

    .filter-summary {
        justify-content: center;
    }

    /* In the sheet the menu pushes content rather than floating over it. */
    .filter-menu {
        position: static;
        max-height: none;
        margin-top: 0.5rem;
        background: none;
    }

    .filters-clear {
        margin: 0 0 0.5rem;
        background: none;
        color: var(--c-ink);
        order: -1;
    }

    .filters-apply {
        display: block;
        align-self: center;
        margin-top: 1rem;
        font-size: var(--fs-nav);
    }

    /* The bottom of the screen belongs to the insets now. */
    .prison-card {
        top: calc(var(--header-h) + 0.5rem);
        transform: translateX(-50%);
    }
}
