/* Gallery: filter chips, a column layout that keeps every photograph's own shape, and the enlarged view. */

@layer pages {
    .gallery__bar {
        display: grid;
        gap: var(--space-lg);
        margin-bottom: var(--space-xl);
    }

    .gallery__intro {
        max-width: 40rem;
    }

    .gallery__filters {
        display: flex;
        flex-wrap: wrap;
        gap: var(--space-xs);
    }

    .chip {
        min-height: 2.75rem;
        padding: 0.5rem var(--space-md);
        font-weight: 500;
        color: var(--navy);
        background: var(--white);
        border: 1px solid #8c867f;
        cursor: pointer;
        transition: color var(--steady) var(--ease), background-color var(--steady) var(--ease), border-color var(--steady) var(--ease);
    }

    .chip:hover {
        border-color: var(--navy);
    }

    .chip[aria-pressed="true"] {
        color: var(--white);
        background: var(--navy);
        border-color: var(--navy);
    }

    .gallery__grid {
        columns: 2;
        column-gap: 0.625rem;
    }

    .gallery__item {
        margin-bottom: 0.625rem;
        break-inside: avoid;
    }

    .gallery__item[hidden] {
        display: none;
    }

    .gallery__link {
        position: relative;
        display: block;
        overflow: hidden;
        background: var(--linen);
    }

    .gallery__link img {
        width: 100%;
        transition: transform var(--slow) var(--ease-out);
    }

    .gallery__link::after {
        content: "";
        position: absolute;
        inset: 0;
        background: rgb(18 15 32 / 0);
        transition: background-color var(--steady) var(--ease);
    }

    .gallery__link:hover img {
        transform: scale(1.05);
    }

    .gallery__link:hover::after {
        background: rgb(18 15 32 / 0.22);
    }

    @media (min-width: 40rem) {
        .gallery__grid {
            columns: 3;
            column-gap: 0.875rem;
        }

        .gallery__item {
            margin-bottom: 0.875rem;
        }
    }

    @media (min-width: 68rem) {
        .gallery__grid {
            columns: 4;
        }

        .gallery__bar {
            grid-template-columns: minmax(18rem, 0.75fr) minmax(0, 2.25fr);
            align-items: end;
        }
    }

    /* ---------- Enlarged view ---------- */

    .lightbox {
        width: 100vw;
        height: 100dvh;
        padding: clamp(3.5rem, 6vw, 4.5rem) clamp(0.75rem, 6vw, 5.5rem);
        color: var(--white);
        background: rgb(18 15 32 / 0.97);
    }

    .lightbox[open] {
        display: grid;
        grid-template-rows: minmax(0, 1fr) auto;
        gap: var(--space-sm);
        place-items: center;
    }

    .lightbox::backdrop {
        background: var(--navy);
    }

    .lightbox__figure {
        display: grid;
        grid-template-rows: minmax(0, 1fr) auto;
        gap: var(--space-md);
        justify-items: center;
        height: 100%;
        min-height: 0;
    }

    .lightbox__figure img {
        max-width: 100%;
        max-height: 100%;
        min-height: 0;
        object-fit: contain;
        box-shadow: var(--shadow-deep);
    }

    .lightbox__figure figcaption {
        max-width: 40rem;
        text-align: center;
    }

    .lightbox__count {
        font-size: var(--text-sm);
        color: var(--sand-pale);
    }

    .lightbox__button {
        position: absolute;
        display: grid;
        place-items: center;
        width: 2.75rem;
        height: 2.75rem;
        color: var(--white);
        background: var(--sand);
        border: 0;
        cursor: pointer;
        transition: color var(--steady) var(--ease), background-color var(--steady) var(--ease);
    }

    .lightbox__button:hover {
        color: var(--navy);
        background: var(--white);
    }

    .lightbox__button--close {
        top: var(--space-sm);
        right: var(--space-sm);
    }

    .lightbox__button--previous,
    .lightbox__button--next {
        bottom: var(--space-sm);
    }

    .lightbox__button--previous {
        left: var(--space-sm);
    }

    .lightbox__button--next {
        right: var(--space-sm);
    }

    @media (min-width: 48rem) {
        .lightbox__button--previous,
        .lightbox__button--next {
            top: 50%;
            bottom: auto;
            translate: 0 -50%;
        }

        .lightbox__button--previous {
            left: var(--space-md);
        }

        .lightbox__button--next {
            right: var(--space-md);
        }
    }
}
