/* ===================================================================
   Gallery page — masonry grid + lightbox
   Loaded only by gallery.html, on top of the sitewide stylesheet.css.
   Tile shapes come from each photo's real pixel dimensions (baked into
   gallery-images.json by update-gallery.py), so nothing is ever cropped.
   =================================================================== */

.gallery-page {
    background-color: rgb(234, 234, 238);
    padding: 3em 2.5em 5em;
    min-height: 60vh;
}

.gallery-intro {
    text-align: center;
    max-width: 40em;
    margin: 0 auto 2.5em;
}

.gallery-intro h1 {
    text-align: center;
    font-size: 2.4em;
    font-weight: 300;
    letter-spacing: 0.04em;
    margin: 0 0 0.4em 0;
}

.gallery-intro p {
    margin: 0 auto;
    color: #5a5a60;
    font-size: 0.95em;
}

/* ===== Masonry grid =====
   CSS multi-column gives a true gapless masonry: each tile keeps its own
   height and the columns stay balanced, with no fixed-height cropping. */
.masonry {
    max-width: 1500px;
    margin: 0 auto;
    column-count: 4;
    column-gap: 1.1em;
}

.tile {
    break-inside: avoid;
    page-break-inside: avoid; /* older WebKit */
    margin: 0 0 1.1em 0;
    position: relative;
    overflow: hidden;
    border-radius: 3px;
    background-color: #dcdce1; /* holds the tile's shape while loading */
    cursor: zoom-in;
    display: block;
    width: 100%;
    padding: 0;
    border: none;
    -webkit-tap-highlight-color: transparent;
}

.tile img {
    display: block;
    width: 100%;
    height: auto; /* width/height attributes reserve the right space */
    opacity: 0;
    transition: opacity 0.5s ease, transform 0.5s ease;
}

.tile img.loaded {
    opacity: 1;
}

/* Hover treatment is desktop-only — on touch it would flash on every tap. */
@media (hover: hover) {
    .tile::after {
        content: "";
        position: absolute;
        inset: 0;
        background-color: rgba(0, 0, 0, 0.22);
        opacity: 0;
        transition: opacity 0.3s ease;
    }

    .tile:hover::after {
        opacity: 1;
    }

    .tile:hover img.loaded {
        transform: scale(1.04);
    }
}

.tile:focus-visible {
    outline: 2px solid #1e1e1e;
    outline-offset: 3px;
}

/* ===== Loading / empty states ===== */
.gallery-status {
    text-align: center;
    padding: 4em 1em;
    color: #66666e;
    font-weight: 300;
}

.spinner {
    width: 34px;
    height: 34px;
    margin: 0 auto 1.2em;
    border: 2px solid rgba(0, 0, 0, 0.12);
    border-top-color: #33333a;
    border-radius: 50%;
    animation: spin 0.9s linear infinite;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

@media (prefers-reduced-motion: reduce) {
    .spinner { animation-duration: 3s; }
    .tile img { transition: none; }
}

/* ===== Lightbox ===== */
.lightbox {
    position: fixed;
    inset: 0;
    z-index: 9999;
    background-color: #16161a;
    display: none;
    flex-direction: column;
    /* dvh tracks the real viewport once mobile browser chrome slides away */
    height: 100vh;
    height: 100dvh;
    padding-bottom: env(safe-area-inset-bottom);
    overscroll-behavior: contain;
}

.lightbox.open {
    display: flex;
}

.lightbox-bar {
    flex: 0 0 auto;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1em;
    padding: 0.9em 1.1em;
    padding-top: calc(0.9em + env(safe-area-inset-top));
    color: rgba(255, 255, 255, 0.85);
    font-size: 0.9em;
    letter-spacing: 0.06em;
}

.lightbox-close {
    appearance: none;
    background: none;
    border: none;
    color: inherit;
    font-size: 1.9em;
    line-height: 1;
    /* 44px keeps the tap target within reach of a thumb */
    min-width: 44px;
    min-height: 44px;
    cursor: pointer;
    padding: 0;
    -webkit-tap-highlight-color: transparent;
}

.lightbox-close:hover {
    color: #fff;
}

.lightbox-close:focus-visible,
.lightbox-arrow:focus-visible {
    outline: 2px solid rgba(255, 255, 255, 0.9);
    outline-offset: -2px;
}

.lightbox-stage {
    flex: 1 1 auto;
    position: relative;
    overflow: hidden;
    touch-action: pan-y; /* let the swipe handler own horizontal drags */
}

/* Three slides — previous, current, next — so a swipe reveals a real
   neighbouring photo rather than snapping after the fact. */
.lightbox-track {
    display: flex;
    width: 300%;
    height: 100%;
    transform: translate3d(-33.3333%, 0, 0);
}

.lightbox-track.animating {
    transition: transform 0.28s cubic-bezier(0.22, 0.61, 0.36, 1);
}

.lightbox-slide {
    width: 33.3333%;
    height: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0 0.6em;
}

.lightbox-slide img {
    max-width: 100%;
    max-height: 100%;
    object-fit: contain;
    user-select: none;
    -webkit-user-drag: none;
}

.lightbox-arrow {
    position: absolute;
    top: 50%;
    transform: translateY(-50%);
    appearance: none;
    border: none;
    background-color: rgba(255, 255, 255, 0.08);
    color: #fff;
    font-size: 1.5em;
    line-height: 1;
    width: 46px;
    height: 64px;
    cursor: pointer;
    transition: background-color 0.2s ease;
    /* The arrows sit over the photo, so they need to stay legible against a
       bright sky as well as a dark background. */
    text-shadow: 0 0 6px rgba(0, 0, 0, 0.85);
}

.lightbox-arrow:hover {
    background-color: rgba(255, 255, 255, 0.2);
}

.lightbox-prev { left: 0; border-radius: 0 4px 4px 0; }
.lightbox-next { right: 0; border-radius: 4px 0 0 4px; }

/* Stop the page behind the lightbox from scrolling under it */
body.lightbox-open {
    overflow: hidden;
}

/* ===== Responsive ===== */
@media screen and (max-width: 1200px) {
    .masonry { column-count: 3; }
}

@media screen and (max-width: 820px) {
    .masonry { column-count: 2; }
    .gallery-page { padding: 2.2em 1.2em 3.5em; }
}

/* One big column on phones — a portfolio photo shrunk into half a phone
   screen isn't worth showing. */
@media screen and (max-width: 560px) {
    .masonry {
        column-count: 1;
        column-gap: 0;
        max-width: 34em;
    }

    .tile { margin-bottom: 0.9em; }

    .gallery-page { padding: 1.6em 1em 3em; }

    .gallery-intro {
        margin-bottom: 1.6em;
    }

    .gallery-intro h1 { font-size: 1.7em; }

    /* Swiping is the primary control on touch, so the arrows shrink back
       to an unobtrusive hint rather than covering the photo. */
    .lightbox-arrow {
        width: 34px;
        height: 52px;
        font-size: 1.1em;
        background-color: rgba(255, 255, 255, 0.06);
    }

    .lightbox-slide { padding: 0 0.2em; }
}
