/*
 * Project gallery (Phase 9, simplified Phase 17.34).
 *
 * Two layouts only — Full and Half — chosen by the administrator. Every image
 * spans the full content width (YODEZEEN): Full is one per row, Half is two per
 * row on desktop and one per row on mobile. No crop derivatives are generated;
 * any cropping is presentation-only, done here with object-fit / overflow.
 *
 * Numbers come from config through ProjectGallery::cssVariables() (printed once on
 * the .gallery element), except the 768/769px breakpoint, which a media query
 * cannot read from a custom property — keep it in step with `gallery_mobile_max`.
 */

.gallery {
    display: grid;
    grid-template-columns: 1fr;
    column-gap: var(--gallery-gap, 12px);
    row-gap: 8px;
    width: 100%; /* full-bleed — the page provides the side margin */
}

.gallery__item {
    position: relative;
    margin: 0;
    overflow: hidden; /* any crop happens here, never in the file */
}

/* "View more photos" (project-gallery.js): images past the initial count are in
   the HTML but hidden until revealed. */
.gallery__item[hidden] { display: none; }

.gallery__item picture,
.gallery__item img {
    display: block;
    width: 100%;
}

/* Default everywhere, and the only behaviour on mobile: the whole frame. */
.gallery__item img {
    height: auto;
}

/* The "+" full-image control — bottom-right of a Full image. Hidden by default
   EVERYWHERE (Phase 17.36): a Full image is only CSS-cropped on desktop, so the
   control has no purpose on mobile and must never show there. It is revealed only
   by the desktop rule below, and only once project-viewer.js (desktop-gated) has
   cleared the `hidden` attribute on an actually-cropped image. `display:none` here
   also fixes the old cascade bug where an author `display:flex` overrode the UA
   `[hidden]` rule, leaving the button visible on mobile where the script never runs. */
.gallery__zoom {
    position: absolute;
    right: 1.5rem;
    bottom: 1.5rem;
    z-index: 2;
    width: 3rem;
    height: 3rem;
    display: none;
    align-items: center;
    justify-content: center;
    background: rgba(255, 255, 255, .22);
    color: #fff;
    border: 0;
    border-radius: 50%;
    font-size: 1.5rem;
    font-weight: 300;
    line-height: 1;
    cursor: pointer;
    backdrop-filter: blur(2px);
    transition: background .2s ease;
}
.gallery__zoom:hover { background: rgba(255, 255, 255, .38); }

/* The reveal button — centred under the gallery, in the global pill style (Phase
   17.37): same shape, size token and inverting hover as .btn-cta, but kept a
   centred block (margin auto) rather than an inline button. */
.gallery-more {
    /* The shared filled pill (Phase 17.49d, matches site.css `.cta-pill`), but kept
       a centred block rather than an inline button. */
    display: block;
    margin: 24px auto 0;
    /* Matches the shared pill (Phase 17.49i). */
    padding: .6rem 1rem;
    background: #d3d3d3;
    border: 0;
    color: #151515;
    border-radius: 999px;
    font: inherit;
    font-size: .75rem;
    line-height: 1;
    font-weight: 500;
    letter-spacing: 0;
    text-transform: uppercase;
    white-space: nowrap;
    cursor: pointer;
    transition: background .2s ease, color .2s ease;
}
.gallery-more:hover { background: #151515; color: #d3d3d3; }
.gallery-more:focus-visible { outline: 2px solid #151515; outline-offset: 3px; }

/* Desktop: two columns. A Full image spans the row and is capped at `--full-max-h`
   (the excess is clipped by overflow; the "+" opens the whole image). Two
   consecutive Half images share one row via .gallery__pair. */
@media (min-width: 769px) {
    /* Full-bleed (Phase 17.35): the gallery spans the whole browser width,
       ignoring the article's padding (YODEZEEN); only the Description stays
       centred. */
    .gallery {
        grid-template-columns: 1fr 1fr;
        width: 100vw;
        margin-left: calc(50% - 50vw);
    }

    .gallery__item--full {
        grid-column: 1 / -1;
        max-height: var(--full-max-h, 100rem);
        /* Symmetric crop (Phase 17.37): a Full image taller than the cap is
           centred and clipped equally top and bottom, not bottom-only. The image
           keeps its natural ratio (width:100%, height:auto), so the "+" detection
           and the viewer's original still work. */
        display: flex;
        align-items: center;
        justify-content: center;
    }

    /* Desktop only: show the "+" once project-viewer.js clears `hidden` on a
       cropped Full image. Gated by this media query, so a button left visible
       after a desktop→mobile resize still disappears at the mobile width. */
    .gallery__zoom:not([hidden]) { display: flex; }

    /* A lone Half (no consecutive Half neighbour) keeps its column, natural ratio. */
    .gallery__item--half img {
        height: auto;
    }

    /* Two Half images in one full-width row. The row height is the SHORTER image's
       displayed height (`--pair-h`, measured by project-viewer.js); both images
       cover-fill, so the taller is CSS-cropped — never a generated crop. */
    .gallery__pair {
        grid-column: 1 / -1;
        display: grid;
        grid-template-columns: 1fr 1fr;
        column-gap: var(--gallery-gap, 0.75rem);
    }
    .gallery__pair .gallery__item {
        height: var(--pair-h, auto);
    }
    .gallery__pair .gallery__item img {
        width: 100%;
        height: 100%;
        object-fit: cover;
        object-position: center;
    }
}

/*
 * Portrait-mobile fullscreen crop (Phase 17.26) — the ONE place project images are
 * cropped, and only here. On a portrait phone or tablet (coarse pointer), each
 * cropped render fills the screen (`object-fit: cover`), with `--mobile-crop`
 * choosing the visible band. Proportional `--fit` portraits are the one exception:
 * they stay whole (natural ratio), excluded via :not(.gallery__item--fit). Placed
 * last so it wins over the desktop two-column rules on a portrait tablet.
 */
@media (orientation: portrait) and (pointer: coarse) {
    .gallery { grid-template-columns: 1fr; row-gap: clamp(6px, 1vw, 10px); }
    .gallery__item--full { grid-column: auto; display: block; }
    /* A Half/Half pair stacks on mobile with the SAME vertical gap as the gallery's
       own row-gap, so the two portraits don't merge into one (Phase 17). The gap is
       on the pair, never a margin on the images — height/crop/object-fit unchanged. */
    .gallery__pair { grid-column: auto; display: flex; flex-direction: column; gap: clamp(6px, 1vw, 10px); }

    .gallery__item--fit img { height: auto; }

    .gallery__item:not(.gallery__item--fit) picture {
        display: block;
        height: var(--gallery-mobile-h, 72svh);
        aspect-ratio: auto;
    }
    .gallery__item:not(.gallery__item--fit) img {
        width: 100%;
        height: 100%;
        margin: 0;
        object-fit: cover;
        object-position: var(--mobile-crop, center);
    }

    .project-hero__media img {
        object-position: var(--mobile-crop, center);
    }
}
