/*
 * GALLERY BLOCK - portfolio grid, masonry, albums, carousel + lightbox.
 *
 * Grid, masonry and album tiles are all .media-frame (components.css): a
 * clipped box that zooms its image on hover. This file only lays the tiles
 * out and styles the caption/album overlays. Carousel and lightbox markup
 * is driven by gallery.js and is unchanged.
 */

/* ---- Tile (shared by grid, masonry, albums) ---------------------------- */

.gallery-tile {
    padding: 0;
    border: none;
    cursor: zoom-in;
    transition: box-shadow var(--transition-slow);
}

.gallery-tile:hover,
.gallery-tile:focus-visible {
    box-shadow: var(--shadow-lifted);
}

/* Caption reveals on hover/focus over a bottom scrim, so the photo stays
   clean at rest but the text is always legible when it appears. */
.gallery-tile__caption {
    position: absolute;
    inset: auto 0 0 0;
    padding: var(--space-lg) var(--space-md) var(--space-sm);
    background: linear-gradient(to top, rgb(15 23 42 / 0.72), rgb(15 23 42 / 0));
    color: #fff;
    font-size: var(--fs-xs);
    line-height: var(--lh-snug);
    text-align: left;
    opacity: 0;
    transition: opacity var(--transition);
}

.gallery-tile:hover .gallery-tile__caption,
.gallery-tile:focus-visible .gallery-tile__caption {
    opacity: 1;
}

/* ---- Portfolio grid (classic_grid, the default) ------------------------
   Tight gaps and a strict 4:3 crop read as one composed wall of images
   rather than a list of thumbnails. auto-fill keeps every tile the same
   size even when a gallery has only a couple of photos (auto-fit would
   stretch two photos across the whole row). */

.gallery-grid {
    display: grid;
    gap: var(--space-sm);
    grid-template-columns: repeat(auto-fill, minmax(min(100%, 250px), 1fr));
}

/* ---- Masonry: natural proportions via CSS columns ---------------------- */

.gallery-masonry {
    column-count: 2;
    column-gap: var(--space-sm);
}

@media (min-width: 640px) {
    .gallery-masonry {
        column-count: 3;
    }
}

@media (min-width: 1024px) {
    .gallery-masonry {
        column-count: 4;
    }
}

.gallery-masonry .gallery-tile {
    margin-bottom: var(--space-sm);
    break-inside: avoid;
}

/* ---- carousel ----------------------------------------------------------- */

.gallery-carousel {
    position: relative;
}

.gallery-carousel__viewport {
    overflow: hidden;
    border-radius: var(--radius-md);
    touch-action: pan-y;
}

.gallery-carousel__track {
    display: flex;
    transition: transform 0.35s ease;
}

.gallery-carousel__slide {
    flex: 0 0 100%;
    min-width: 0;
}

.gallery-carousel__slide-btn {
    display: block;
    width: 100%;
    padding: 0;
    border: none;
    background: none;
    cursor: zoom-in;
}

.gallery-carousel__img {
    display: block;
    width: 100%;
    aspect-ratio: 16 / 10;
    object-fit: cover;
}

.gallery-carousel__caption {
    margin-top: var(--space-sm);
    font-size: var(--fs-xs);
    color: var(--text-muted);
    text-align: center;
}

.gallery-carousel__nav {
    position: absolute;
    top: 0;
    bottom: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 2.75rem;
    border: none;
    background: rgb(15 23 42 / 0.35);
    color: #fff;
    cursor: pointer;
    transition: background-color var(--transition);
}

.gallery-carousel__nav:hover {
    background: rgb(15 23 42 / 0.6);
}

.gallery-carousel__nav svg {
    width: 1.5rem;
    height: 1.5rem;
}

.gallery-carousel__nav--prev {
    left: 0;
    border-radius: var(--radius-md) 0 0 var(--radius-md);
}

.gallery-carousel__nav--next {
    right: 0;
    border-radius: 0 var(--radius-md) var(--radius-md) 0;
}

.gallery-carousel__thumbs {
    display: flex;
    gap: 0.5rem;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    margin-top: 0.75rem;
    padding-bottom: 0.25rem;
}

.gallery-carousel__thumb {
    flex: 0 0 auto;
    width: 4.5rem;
    height: 3.375rem;
    padding: 0;
    border: 2px solid transparent;
    border-radius: var(--radius-sm);
    overflow: hidden;
    opacity: 0.6;
    cursor: pointer;
    transition: opacity var(--transition), border-color var(--transition);
}

.gallery-carousel__thumb img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
}

.gallery-carousel__thumb:hover {
    opacity: 0.85;
}

.gallery-carousel__thumb.is-active {
    opacity: 1;
    border-color: var(--color-primary-strong);
}

/* ---- Albums ---------------------------------------------------------- */

.gallery-albums {
    display: grid;
    gap: var(--space-md);
    grid-template-columns: repeat(auto-fill, minmax(min(100%, 280px), 1fr));
}

.gallery-album__trigger {
    cursor: pointer;
}

.gallery-album__overlay {
    position: absolute;
    inset: 0;
    display: flex;
    flex-direction: column;
    justify-content: flex-end;
    padding: var(--space-md);
    background: linear-gradient(to top, rgb(15 23 42 / 0.72), rgb(15 23 42 / 0) 60%);
    color: #fff;
    text-align: left;
}

.gallery-album__name {
    font-family: var(--font-heading);
    font-size: var(--fs-h5);
    font-weight: 700;
    line-height: var(--lh-snug);
}

.gallery-album__count {
    margin-top: var(--space-xs);
    font-size: var(--fs-xs);
    opacity: 0.9;
}

/* ---- lightbox --------------------------------------------------------- */

.gallery-lightbox {
    position: fixed;
    inset: 0;
    z-index: 1000;
    display: flex;
    align-items: center;
    justify-content: center;
}

.gallery-lightbox[hidden] {
    display: none;
}

.gallery-lightbox__backdrop {
    position: absolute;
    inset: 0;
    background: rgb(15 23 42 / 0.92);
}

body.gallery-lightbox-open {
    overflow: hidden;
}

.gallery-lightbox__figure {
    position: relative;
    z-index: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    max-width: min(92vw, 1200px);
    max-height: 90vh;
    margin: 0;
    padding: 0 3.5rem;
}

.gallery-lightbox__img {
    display: block;
    max-width: 100%;
    max-height: 80vh;
    border-radius: var(--radius-sm);
    object-fit: contain;
}

.gallery-lightbox__caption {
    margin-top: 0.75rem;
    color: var(--bg-page);
    font-size: 0.9rem;
    text-align: center;
}

.gallery-lightbox__close,
.gallery-lightbox__nav {
    position: absolute;
    z-index: 2;
    display: flex;
    align-items: center;
    justify-content: center;
    min-width: 2.75rem;
    min-height: 2.75rem;
    border: none;
    border-radius: var(--radius-full);
    background: rgba(255, 255, 255, 0.12);
    color: #fff;
    font-size: 1.5rem;
    line-height: 1;
    cursor: pointer;
    transition: background-color var(--transition);
}

.gallery-lightbox__close:hover,
.gallery-lightbox__nav:hover {
    background: rgba(255, 255, 255, 0.25);
}

.gallery-lightbox__close {
    top: 1rem;
    right: 1rem;
}

.gallery-lightbox__nav {
    top: 50%;
    transform: translateY(-50%);
    font-size: 2rem;
}

.gallery-lightbox__nav--prev {
    left: 0.5rem;
}

.gallery-lightbox__nav--next {
    right: 0.5rem;
}

.gallery-lightbox__counter {
    position: absolute;
    bottom: 1rem;
    left: 50%;
    transform: translateX(-50%);
    color: var(--bg-page);
    font-size: 0.8rem;
    letter-spacing: 0.03em;
}

@media (max-width: 640px) {
    .gallery-lightbox__figure {
        padding: 0 2.75rem;
    }

    .gallery-lightbox__nav {
        min-width: 2.5rem;
        min-height: 2.5rem;
    }

    .gallery-carousel__nav {
        width: 2.25rem;
    }
}
