/* File: css/project-gallery.css */

/* When a project has no narrative, let the sidebar use the full width */
.cs-grid:not(:has(.cs-narrative)) {
    grid-template-columns: 1fr;
}

.cs-gallery {
    padding-block: 3rem;

    > h2 {
        margin-bottom: 1.5rem;
    }
}

.cs-gallery-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(min(100%, 16rem), 1fr));
    gap: 1rem;
    margin: 0;
    padding: 0;
    list-style: none;
}

.cs-gallery-item {
    display: block;
    width: 100%;
    padding: 0;
    overflow: hidden;
    cursor: zoom-in;
    border: 1px solid var(--border, rgba(255, 255, 255, 0.1));
    border-radius: 14px;
    background: var(--bg-secondary, #1a202c);

    img {
        display: block;
        width: 100%;
        aspect-ratio: 4 / 3;
        object-fit: cover;
        transition: transform 0.35s ease;
    }

    &:hover img,
    &:focus-visible img {
        transform: scale(1.04);
    }

    &:focus-visible {
        outline: 3px solid var(--accent, #0ea5e9);
        outline-offset: 3px;
    }
}

/* Lightbox */
.cs-lightbox {
    width: 100vw;
    max-width: none;
    height: 100dvh;
    max-height: none;
    margin: 0;
    padding: 0;
    border: 0;
    color: #fff;
    background: rgba(0, 0, 0, 0.92);

    &[open] {
        box-sizing: border-box;
        display: grid;
        grid-template-columns: auto 1fr auto;
        align-items: center;
        gap: 1rem;
        padding: 1rem;
    }

    &::backdrop {
        background: rgba(0, 0, 0, 0.6);
    }

    .lb-figure {
        display: grid;
        place-items: center;
        min-width: 0;
        margin: 0;
    }

    .lb-img {
        max-width: 100%;
        max-height: calc(100dvh - 6rem);
        object-fit: contain;
        border-radius: 8px;
    }

    .lb-counter {
        margin-top: 0.75rem;
        font-size: 0.9rem;
        opacity: 0.8;
    }

    .lb-btn {
        display: grid;
        place-items: center;
        width: 3rem;
        height: 3rem;
        padding: 0;
        font-size: 1.75rem;
        line-height: 1;
        color: #fff;
        cursor: pointer;
        border: 1px solid rgba(255, 255, 255, 0.25);
        border-radius: 50%;
        background: rgba(255, 255, 255, 0.08);
        transition: background-color 0.2s;

        &:hover {
            background: rgba(255, 255, 255, 0.2);
        }

        &:focus-visible {
            outline: 3px solid var(--accent, #0ea5e9);
            outline-offset: 2px;
        }
    }

    .lb-close {
        position: absolute;
        top: 1rem;
        right: 1rem;
    }

    &.is-single .lb-prev,
    &.is-single .lb-next {
        visibility: hidden;
    }
}

@media (max-width: 640px) {
    .cs-lightbox[open] {
        grid-template-columns: 1fr;
        grid-template-rows: 1fr auto;

        .lb-figure {
            grid-row: 1;
        }

        .lb-prev,
        .lb-next {
            grid-row: 2;
        }

        .lb-prev {
            justify-self: start;
        }

        .lb-next {
            justify-self: end;
        }
    }
}

@media (prefers-reduced-motion: reduce) {
    .cs-gallery-item img {
        transition: none;
    }

    .cs-gallery-item:hover img,
    .cs-gallery-item:focus-visible img {
        transform: none;
    }
}