/*
 * Gallery v3 — proper photographer's portfolio.
 *
 * Justified-rows layout (Flickr-style) computed in JS so every row hits
 * a target height while photos keep their natural aspect ratios.
 *
 * Lightbox with shared-element FLIP transition (photo flies from grid
 * position into the lightbox center), thumbnail filmstrip, crossfade
 * between photos, swipe + keyboard nav, blur-up loading.
 */

.pp-gx {
    max-width: 1400px;
    margin: 0 auto;
    padding: 4.5rem 1.5rem 7rem 1.5rem;
}

.pp-gx__head {
    display: flex;
    align-items: baseline;
    justify-content: space-between;
    margin-bottom: 2.6rem;
    gap: 1rem;
    padding: 0 .5rem;
}
.pp-gx__head h4 { margin: 0; color: var(--pp-tide); }
.pp-gx__count {
    font-family: var(--pp-display);
    font-style: italic;
    color: var(--pp-orchid);
    font-size: 1.15rem;
    font-variant-numeric: tabular-nums;
}

/* ---- justified-rows grid -------------------------------------- */

.pp-gx__grid {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    transition: opacity .35s ease;
}
.pp-gx__grid[data-state="loading"] { opacity: 0; }
.pp-gx__grid[data-state="ready"]   { opacity: 1; }

.pp-gx__item {
    position: relative;
    margin: 0;
    padding: 0;
    border: 0;
    background: var(--pp-shore);
    cursor: zoom-in;
    overflow: hidden;
    flex: 0 0 auto;
    /* width + height are set by JS layoutJustifiedRows() */
    transform: translateZ(0);          /* own compositing layer */
    -webkit-tap-highlight-color: transparent;
    transition: transform .35s cubic-bezier(.2, .8, .2, 1);
}

/* blur-up: the small thumb sits behind, the preview fades in over it */
.pp-gx__placeholder {
    position: absolute;
    inset: 0;
    background: linear-gradient(135deg, var(--pp-shore) 0%, var(--pp-plum) 100%);
    opacity: .55;
}
.pp-gx__img {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    object-fit: cover;
    opacity: 0;
    /* More pronounced reveal: rises ~22px and zooms from 1.06 → 1.
     * Combined with the per-item delay in JS the cascade reads clearly. */
    transform: scale(1.06) translateY(22px);
    transition: opacity .85s cubic-bezier(.2, .8, .2, 1),
                transform 1.05s cubic-bezier(.2, .8, .2, 1),
                filter .4s ease;
    filter: saturate(.94);
}
.pp-gx__item.is-loaded .pp-gx__img {
    opacity: 1;
    transform: scale(1) translateY(0);
}
.pp-gx__item:hover {
    transform: translateY(-2px);
    z-index: 1;
    box-shadow: 0 20px 40px -22px rgba(31, 27, 38, .35);
}
.pp-gx__item:hover .pp-gx__img {
    filter: saturate(1.08);
    transform: scale(1.04);
}
.pp-gx__item:focus-visible {
    outline: 2px solid var(--pp-plum);
    outline-offset: 3px;
    z-index: 1;
}

/* hover caption — small plum tint w/ "View" eyebrow */
.pp-gx__item::after {
    content: "Open";
    position: absolute;
    left: 0; right: 0; bottom: 0;
    padding: .9rem 1rem;
    color: var(--pp-bone);
    font-family: var(--pp-body);
    font-size: .66rem;
    text-transform: uppercase;
    letter-spacing: .34em;
    font-weight: 500;
    background: linear-gradient(to top, rgba(31, 27, 38, .7) 0%, rgba(31, 27, 38, 0) 100%);
    transform: translateY(100%);
    opacity: 0;
    transition: transform .35s cubic-bezier(.2, .8, .2, 1), opacity .25s ease;
    pointer-events: none;
}
.pp-gx__item:hover::after,
.pp-gx__item:focus-visible::after {
    transform: translateY(0);
    opacity: 1;
}

/* hide grid item that's currently flying into the lightbox */
.pp-gx__item.is-flying { opacity: 0; pointer-events: none; }

@media (max-width: 720px) {
    .pp-gx { padding: 3rem 1rem 5rem 1rem; }
    .pp-gx__head { margin-bottom: 1.6rem; }
    .pp-gx__grid { gap: 6px; }
    .pp-gx__item::after { font-size: .58rem; letter-spacing: .28em; padding: .7rem .8rem; }
}

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

.pp-lb {
    position: fixed;
    inset: 0;
    z-index: 200;
    display: flex;
    flex-direction: column;
    align-items: stretch;
    justify-content: center;
    background: rgba(15, 12, 22, 0);
    backdrop-filter: blur(0px);
    -webkit-backdrop-filter: blur(0px);
    opacity: 0;
    pointer-events: none;
    transition: opacity .35s ease, background-color .35s ease, backdrop-filter .35s ease;
}
.pp-lb[data-open="true"] {
    opacity: 1;
    pointer-events: auto;
    background: rgba(15, 12, 22, .93);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
}

.pp-lb__chrome {
    position: fixed;
    top: 0; left: 0; right: 0;
    padding: 1.2rem 1.5rem;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    z-index: 3;
    pointer-events: none;          /* so background still receives clicks */
}
.pp-lb__chrome > * { pointer-events: auto; }

.pp-lb__icon {
    background: rgba(251, 246, 238, .08);
    border: 1px solid rgba(251, 246, 238, .25);
    color: var(--pp-bone);
    width: 44px;
    height: 44px;
    border-radius: 50%;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background-color .2s ease, border-color .2s ease, color .2s ease, transform .2s ease;
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
    text-decoration: none;
}
.pp-lb__icon:hover {
    background: rgba(229, 194, 192, .26);
    border-color: var(--pp-tearose);
    color: var(--pp-tearose);
    transform: scale(1.06);
}

.pp-lb__counter {
    color: var(--pp-tearose);
    font-family: var(--pp-display);
    font-style: italic;
    font-size: 1.1rem;
    letter-spacing: .03em;
    opacity: .92;
    text-align: center;
    flex: 1;
    margin: 0 .4rem;
    font-variant-numeric: tabular-nums;
    pointer-events: none;
}

.pp-lb__stage {
    flex: 1;
    min-height: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    position: relative;
    padding: 5rem clamp(1rem, 6vw, 5rem) 9rem clamp(1rem, 6vw, 5rem);
}

.pp-lb__nav {
    position: absolute;
    top: 50%;
    transform: translateY(-50%);
    width: 52px; height: 52px;
    border-radius: 50%;
    background: rgba(251, 246, 238, .08);
    border: 1px solid rgba(251, 246, 238, .25);
    color: var(--pp-bone);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
    transition: background-color .2s ease, border-color .2s ease, transform .2s ease, opacity .2s ease;
    z-index: 2;
}
.pp-lb__nav:hover {
    background: rgba(229, 194, 192, .26);
    border-color: var(--pp-tearose);
    color: var(--pp-tearose);
    transform: translateY(-50%) scale(1.06);
}
.pp-lb__prev { left: clamp(.6rem, 2.5vw, 2rem); }
.pp-lb__next { right: clamp(.6rem, 2.5vw, 2rem); }

.pp-lb__frame {
    position: relative;
    max-width: 100%;
    max-height: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
}
.pp-lb__img {
    max-width: min(1200px, 100%);
    max-height: 100%;
    width: auto;
    height: auto;
    object-fit: contain;
    box-shadow: 0 40px 100px -30px rgba(0, 0, 0, .7);
    user-select: none;
    transition: opacity .35s ease, transform .45s cubic-bezier(.2, .8, .2, 1);
}
.pp-lb__img--ghost {
    position: absolute;
    inset: 0;
    margin: auto;
    opacity: 0;
    pointer-events: none;
}
/* While FLIP-ing into position, the static img is hidden so the flying clone reads as the photo */
.pp-lb[data-flying="true"] .pp-lb__img { opacity: 0; }

.pp-lb__caption {
    position: fixed;
    left: 50%;
    transform: translateX(-50%);
    bottom: 6.5rem;
    color: var(--pp-tearose);
    font-family: var(--pp-display);
    font-style: italic;
    font-size: .95rem;
    text-align: center;
    max-width: min(560px, 80%);
    opacity: .9;
    line-height: 1.5;
    pointer-events: none;
    z-index: 2;
}

/* Filmstrip */
.pp-lb__filmstrip {
    position: fixed;
    left: 0; right: 0; bottom: 0;
    padding: .8rem clamp(.6rem, 3vw, 1.6rem);
    display: flex;
    gap: 6px;
    overflow-x: auto;
    overflow-y: hidden;
    scrollbar-width: none;
    background: linear-gradient(to top, rgba(0,0,0,.5) 0%, rgba(0,0,0,0) 100%);
    z-index: 2;
    scroll-behavior: smooth;
}
.pp-lb__filmstrip::-webkit-scrollbar { display: none; }

.pp-lb__film {
    background: none;
    border: 0;
    padding: 0;
    cursor: pointer;
    flex: 0 0 auto;
    width: 64px;
    height: 64px;
    border-radius: 4px;
    overflow: hidden;
    position: relative;
    opacity: .45;
    transform: scale(.95);
    transition: opacity .25s ease, transform .25s ease, box-shadow .25s ease;
    outline: none;
}
.pp-lb__film img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
}
.pp-lb__film:hover {
    opacity: .85;
    transform: scale(1);
}
.pp-lb__film[aria-selected="true"] {
    opacity: 1;
    transform: scale(1);
    box-shadow: 0 0 0 2px var(--pp-tearose);
}

/* FLIP transition: the flying clone */
.pp-lb__flying {
    position: fixed;
    z-index: 250;
    object-fit: cover;
    border-radius: 0;
    box-shadow: 0 30px 80px -20px rgba(0, 0, 0, .45);
    pointer-events: none;
    will-change: transform, width, height, opacity;
    transition: transform 420ms cubic-bezier(.32, .72, 0, 1),
                width    420ms cubic-bezier(.32, .72, 0, 1),
                height   420ms cubic-bezier(.32, .72, 0, 1),
                opacity  300ms ease;
}

/* Lock body scroll while lightbox open (relies on pp-no-scroll utility) */

@media (max-width: 720px) {
    .pp-lb__chrome { padding: .7rem .8rem; }
    .pp-lb__stage { padding: 4rem .6rem 8rem .6rem; }
    .pp-lb__icon, .pp-lb__nav { width: 40px; height: 40px; }
    .pp-lb__prev { left: .4rem; }
    .pp-lb__next { right: .4rem; }
    .pp-lb__counter { font-size: .95rem; }
    .pp-lb__film { width: 54px; height: 54px; }
    .pp-lb__caption { bottom: 5.5rem; font-size: .85rem; }
}

@media (prefers-reduced-motion: reduce) {
    .pp-gx__item, .pp-gx__img, .pp-lb, .pp-lb__img, .pp-lb__nav,
    .pp-lb__icon, .pp-lb__film, .pp-lb__flying {
        transition: none !important;
        animation: none !important;
    }
}
