/* ============================================================
   Modal
   ============================================================ */

.modal {
    display: none;
    position: fixed;
    inset: 0;
    z-index: 200;
    background: rgba(0, 0, 0, 0.78);
    overflow-y: auto;
    backdrop-filter: blur(3px);
    -webkit-backdrop-filter: blur(3px);
}

/* Content box */
.modal-content {
    position: relative;
    background: var(--bg);
    border: 1px solid var(--border-bright);
    margin: 8dvh auto 4rem;
    padding: 0;
    width: min(820px, 92vw);
    font-weight: 200;
    animation: modal-in var(--t-slow) ease forwards;
}

@keyframes modal-in {
    from { opacity: 0; transform: translateY(14px); }
    to   { opacity: 1; transform: translateY(0); }
}

/* Top bar */
.modal-content::before {
    content: '— GALLERY VIEW';
    display: block;
    font-family: var(--font-mono);
    font-size: 9px;
    letter-spacing: 0.14em;
    color: var(--text-muted);
    padding: 8px 16px;
    border-bottom: 1px solid var(--border);
    background: var(--bg-secondary);
}

/* Title legend */
.modal-content legend {
    display: block;
    font-family: var(--font-mono);
    font-size: 11px;
    font-weight: 700;
    letter-spacing: 0.12em;
    text-transform: uppercase;
    padding: 8px 14px;
    border: 1px solid currentColor;
    background: var(--bg);
    margin-left: 16px;
}

/* Close button */
.close {
    position: absolute;
    top: 6px;
    right: 8px;
    z-index: 20;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 28px;
    height: 28px;
    border: 1px solid var(--border-bright);
    background: var(--bg-secondary);
    color: var(--text-dim);
    font-family: var(--font-mono);
    font-size: 14px;
    cursor: crosshair;
    float: none;
    transition: border-color var(--t-fast), color var(--t-fast), background var(--t-fast);
    user-select: none;
}

.close:hover {
    border-color: var(--accent);
    color: var(--accent);
    background: var(--accent-dim);
}

/* ── Gallery carousel ───────────────────────────── */

.modal-carousel {
    position: relative;   /* positioning context for overlay buttons */
    border-top: 1px solid var(--border);
    border-bottom: 1px solid var(--border);
    background: #000;
}

.modal-gallery {
    display: flex;
    flex-direction: row;
    overflow-x: scroll;
    scroll-behavior: smooth;
    scrollbar-width: none;
    /* no scroll-snap-type — snapping is handled manually like the hero */
}

.modal-gallery::-webkit-scrollbar { display: none; }

/* Each slide fills the gallery exactly */
.modal-gallery img,
.modal-gallery video {
    display: block;
    flex-shrink: 0;
    width: 100%;
    min-width: 100%;
    height: 420px;
    object-fit: contain;   /* contain so nothing is cropped in the modal view */
    background: #000;
    filter: none;
    border: none;
    cursor: grab;
    user-select: none;
    -webkit-user-drag: none;
}

.modal-gallery video {
    cursor: default;
}

/* Prev / Next overlaid on gallery */
.modal-prev,
.modal-next {
    position: absolute;
    top: 50%;
    transform: translateY(-50%);
    z-index: 10;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 40px;
    height: 64px;
    border: 1px solid var(--border-bright);
    background: rgba(10, 10, 10, 0.55);
    color: var(--text-dim);
    font-size: 12px;
    font-family: var(--font-mono);
    cursor: crosshair;
    opacity: 0;
    transition: opacity var(--t-med), border-color var(--t-fast), color var(--t-fast), background var(--t-fast);
    user-select: none;
    backdrop-filter: blur(4px);
    -webkit-backdrop-filter: blur(4px);
}

.modal-prev { left: 0;  border-left: none; }
.modal-next { right: 0; border-right: none; }

.modal-carousel:hover .modal-prev,
.modal-carousel:hover .modal-next { opacity: 1; }

.modal-prev:hover,
.modal-next:hover {
    border-color: var(--accent);
    color: var(--accent);
    background: rgba(10, 10, 10, 0.82);
}

.modal-prev:active,
.modal-next:active {
    background: var(--accent);
    color: var(--bg);
}

/* ── Dot indicators ─────────────────────────────── */

.gallery-anchors {
    display: flex;
    flex-direction: row;
    align-items: center;
    justify-content: center;
    gap: calc(var(--unit) * 1.5);
    padding: calc(var(--unit) * 1.5) 0;
    border-bottom: 1px solid var(--border);
}

.gallery-anchors a {
    display: block;
    width: 20px;
    height: 2px;
    background: var(--border-bright);
    text-indent: -9999px;
    transition: background var(--t-med), width var(--t-med);
    cursor: crosshair;
    text-decoration: none;
}

.gallery-anchors a.active-gallery-anchor {
    background: var(--accent);
    width: 32px;
}

/* ── Description ────────────────────────────────── */

.modal-content > p {
    font-family: var(--font-sans);
    font-size: 13px;
    font-weight: 200;
    line-height: 1.8;
    color: var(--text-dim);
    padding: calc(var(--unit) * 2) calc(var(--unit) * 2.5);
}

.modal-content p a {
    color: var(--accent);
    text-underline-offset: 3px;
}

/* Maximize button — top-right corner of carousel */
.modal-maximize {
    position: absolute;
    top: 8px;
    right: 8px;
    z-index: 12;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 28px;
    height: 28px;
    border: 1px solid var(--border-bright);
    background: rgba(10, 10, 10, 0.55);
    color: var(--text-dim);
    font-size: 11px;
    font-family: var(--font-mono);
    cursor: crosshair;
    opacity: 0;
    transition: opacity var(--t-med), border-color var(--t-fast), color var(--t-fast), background var(--t-fast);
    user-select: none;
    backdrop-filter: blur(4px);
    -webkit-backdrop-filter: blur(4px);
    line-height: 1;
}

.modal-carousel:hover .modal-maximize { opacity: 1; }

.modal-maximize:hover {
    border-color: var(--accent);
    color: var(--accent);
    background: rgba(10, 10, 10, 0.82);
}

.modal-maximize:active {
    background: var(--accent);
    color: var(--bg);
}

/* Mute button — bottom-right corner of carousel, fullscreen only */
.modal-mute {
    position: absolute;
    bottom: 16px;
    right: 16px;
    z-index: 12;
    display: none; /* shown via JS only in fullscreen */
    align-items: center;
    justify-content: center;
    width: 36px;
    height: 36px;
    border: 1px solid var(--border-bright);
    background: rgba(10, 10, 10, 0.65);
    color: var(--text-dim);
    font-size: 16px;
    font-family: var(--font-mono);
    cursor: crosshair;
    transition: border-color var(--t-fast), color var(--t-fast), background var(--t-fast);
    user-select: none;
    backdrop-filter: blur(4px);
    -webkit-backdrop-filter: blur(4px);
    line-height: 1;
}

.modal-mute:hover {
    border-color: var(--accent);
    color: var(--accent);
    background: rgba(10, 10, 10, 0.82);
}

.modal-mute:active {
    background: var(--accent);
    color: var(--bg);
}

/* ── Fullscreen overlay (injected into body, outside modal hierarchy) ── */

#gallery-fullscreen {
    display: none;
    position: fixed;
    inset: 0;
    z-index: 1000;
    background: #000;
    flex-direction: column;
}

#gallery-fullscreen.active {
    display: flex;
}

#gallery-fullscreen .modal-carousel {
    flex: 1;
    min-height: 0;
    border: none;
    position: relative;
}

#gallery-fullscreen .modal-gallery {
    height: 100%;
}

#gallery-fullscreen .modal-gallery img,
#gallery-fullscreen .modal-gallery video {
    height: 100dvh;
    object-fit: contain;
    background: #000;
}

#gallery-fullscreen .modal-prev,
#gallery-fullscreen .modal-next {
    opacity: 1;
    height: 96px;
}

#gallery-fullscreen .modal-maximize {
    opacity: 1;
    top: 16px;
    right: 16px;
    width: 36px;
    height: 36px;
    font-size: 14px;
    background: rgba(10, 10, 10, 0.75);
}

/* ── Mobile ─────────────────────────────────────── */

@media screen and (max-width: 768px) {
    .modal-content {
        margin: 0 auto;
        width: 100dvw;
        height: 100dvh;
        min-height: unset;
        border-left: none;
        border-right: none;
        animation: none;
        display: grid;
        /* ::before top bar | carousel (expands) | dots | description */
        grid-template-rows: auto 1fr auto auto;
    }

    /* Snap gallery on mobile */
    .modal-gallery {
        scroll-snap-type: x mandatory;
        height: 100%;
    }

    .modal-carousel {
        /* fills the 1fr row */
        min-height: 0;
        display: flex;
        align-items: center;
    }

    /* Slides fill carousel height */
    .modal-gallery img,
    .modal-gallery video {
        scroll-snap-align: start;
        height: 100%;
        min-height: 0;
        width: 100%;
        min-width: 100%;
        aspect-ratio: unset;
        object-fit: contain;
        background: #000;
    }

    .modal-prev,
    .modal-next {
        opacity: 1;
        width: 32px;
        height: 64px;
    }

    /* Maximize and mute always visible on mobile */
    .modal-maximize,
    .modal-mute {
        opacity: 1 !important;
    }

    /* Dots below gallery */
    .gallery-anchors {
        flex-shrink: 0;
        padding: calc(var(--unit) * 1.5) 0;
        justify-content: center;
        border-bottom: 1px solid var(--border);
    }

    /* Description at the bottom, fixed height */
    .modal-content > p {
        font-size: 13px;
        line-height: 1.6;
        padding: calc(var(--unit) * 2);
        overflow-y: auto;
        max-height: 22dvh;
    }
}
