/* ===========================================================================
   Crystal Reef — Public Gallery
   Editorial "through our lens" bento gallery. Uses the site brand tokens
   (DM Sans / Crimson Text / Dancing Script; navy / turquoise / teal) so it
   reads as native to the rest of the site. All rules are scoped under
   .gallery-page to avoid leaking into other templates.
   =========================================================================== */

.gallery-page {
    --g-navy: var(--color-navy, #03235a);
    --g-turq: var(--color-turquoise, #40e0d0);
    --g-teal: var(--color-teal, #ddfcf9);
    --g-radius: 18px;
    --g-gap: 14px;
    background: #fff;
}

/* The hero reuses the shared .page-hero layout (see styles.css) so it matches
   every other page — no gallery-specific hero styles needed. */

/* ---- Filter chips ----------------------------------------------------- */
.gallery-filters {
    position: sticky;
    top: 0;
    z-index: 20;
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    gap: 0.5rem;
    padding: 1.1rem 1rem;
    background: rgba(255, 255, 255, 0.85);
    backdrop-filter: blur(10px);
    border-bottom: 1px solid rgba(3, 35, 90, 0.06);
}
.g-chip {
    font-family: 'DM Sans', sans-serif;
    font-size: 0.9rem;
    font-weight: 600;
    color: var(--g-navy);
    background: var(--g-teal);
    border: 1.5px solid transparent;
    border-radius: 999px;
    padding: 0.5rem 1.1rem;
    cursor: pointer;
    text-decoration: none;   /* chips are <a> links (server-side filter) */
    display: inline-flex;
    align-items: center;
    transition: transform 0.18s ease, background 0.18s ease,
                color 0.18s ease, border-color 0.18s ease;
}
.g-chip:hover { transform: translateY(-2px); border-color: var(--g-turq); }
.g-chip.is-active {
    background: var(--g-navy);
    color: #fff;
}
.g-chip .g-chip__count {
    opacity: 0.55;
    margin-left: 0.35rem;
    font-variant-numeric: tabular-nums;
}

/* ---- Bento grid -------------------------------------------------------
   Fixed number of square units across (same on every device — tiles just scale
   down on mobile), so a page packed into a perfect rectangle has an identical
   flush bottom on mobile and web. Each tile's exact position (grid-column/row)
   is computed server-side (gallery.layout) and set inline, so the rendered
   layout is precisely the rectangle we verified — no reliance on auto-flow.
   Tile shapes in units: landscape 3x2 (3:2), portrait 2x3 (2:3), square 2x2. */
.gallery-grid {
    --cols: 6;                     /* overridden inline from the view */
    --pad-x: 1rem;
    --cell: calc(
        (min(100vw, 1240px) - 2 * var(--pad-x) - (var(--cols) - 1) * var(--g-gap))
        / var(--cols));
    display: grid;
    grid-template-columns: repeat(var(--cols), var(--cell));
    grid-auto-rows: var(--cell);   /* square cells → tiles keep true ratios */
    gap: var(--g-gap);
    justify-content: center;
    max-width: 1240px;
    margin: 0 auto;
    padding: 2rem var(--pad-x) 4rem;
}
.g-tile {
    position: relative;
    overflow: hidden;
    border-radius: 0;   /* square-edged tiles */
    background: linear-gradient(110deg, #eef4f5 8%, #e2edef 18%, #eef4f5 33%);
    background-size: 200% 100%;
    cursor: zoom-in;
    box-shadow: 0 6px 20px -12px rgba(3, 35, 90, 0.4);
    /* grid-column / grid-row are set inline per tile by the template. */
}

/* Skeleton shimmer while the image loads (mirrors the service-gallery loading
   pattern used elsewhere on the site). Progressive enhancement: images are
   visible by default; the shimmer + fade only apply once JS marks a tile
   `is-loading`, so with JS disabled the photos simply show normally. */
.g-tile.is-loading { animation: g-shimmer 1.3s ease-in-out infinite; }
@keyframes g-shimmer {
    0%   { background-position: 200% 0; }
    100% { background-position: -200% 0; }
}

.g-tile__img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
    transition: transform 0.7s cubic-bezier(0.2, 0.7, 0.2, 1);
}
.g-tile.is-loading .g-tile__img { opacity: 0; transform: scale(1.04); }
.g-tile.is-loaded .g-tile__img {
    opacity: 1;
    transform: scale(1);
    transition: opacity 0.6s ease, transform 0.7s cubic-bezier(0.2, 0.7, 0.2, 1);
}
.g-tile:hover .g-tile__img { transform: scale(1.06); }

/* Grid tiles are pure images — title/location/photographer are revealed in the
   lightbox on click, keeping the wall clean. */
.g-tile.is-hidden { display: none; }

/* Empty state */
.gallery-empty {
    text-align: center;
    padding: 4rem 1rem 6rem;
    color: var(--g-navy);
    font-family: 'DM Sans', sans-serif;
}

/* ---- Pager ------------------------------------------------------------ */
.gallery-pager {
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 0.4rem;
    padding: 0 1rem 4rem;
    font-family: 'DM Sans', sans-serif;
}
.gallery-pager__num,
.gallery-pager__arrow {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 40px;
    height: 40px;
    padding: 0 0.5rem;
    border-radius: 999px;
    color: var(--g-navy);
    background: var(--g-teal);
    text-decoration: none;
    font-weight: 600;
    font-variant-numeric: tabular-nums;
    transition: transform 0.18s ease, background 0.18s ease, color 0.18s ease;
}
.gallery-pager__num:hover,
.gallery-pager__arrow:hover { transform: translateY(-2px); }
.gallery-pager__num.is-current {
    background: var(--g-navy);
    color: #fff;
    pointer-events: none;
}

/* ---- Lightbox --------------------------------------------------------- */
.g-lightbox {
    position: fixed;
    inset: 0;
    z-index: 1080;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: clamp(1rem, 4vw, 3rem);
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.28s ease, visibility 0.28s ease;
}
.g-lightbox.is-open { opacity: 1; visibility: visible; }
/* Own layer, so a swipe-down can fade the backdrop out from under the photo
   while the stage follows the finger. Opacity is driven inline by gallery.js. */
.g-lb-backdrop {
    position: absolute;
    inset: 0;
    background: rgba(2, 12, 30, 0.92);
    backdrop-filter: blur(6px);
}

/* The stage — photo + caption — is the element the drag gesture moves. */
.g-lb-stage {
    position: relative;
    z-index: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.9rem;
    width: min(1100px, 100%);
    max-height: 100%;
    transform: scale(0.96);
    transition: transform 0.28s cubic-bezier(0.2, 0.7, 0.2, 1);
}
.g-lightbox.is-open .g-lb-stage { transform: scale(1); }
/* While a finger is down the stage must track it exactly — no easing. */
.g-lightbox.is-dragging .g-lb-stage,
.g-lightbox.is-dragging .g-lb-backdrop { transition: none; }
/* Released past the dismiss threshold: fall away and fade. */
.g-lightbox.is-dismissing .g-lb-stage { transition: transform 0.22s ease-in; }
.g-lightbox.is-dismissing .g-lb-backdrop { transition: opacity 0.22s ease-in; }

.g-lb-swiper {
    width: 100%;
    min-height: 0;
    /* Swiper drives both axes itself; letting the browser claim vertical pans
       would steal the swipe-down gesture mid-drag on iOS. */
    touch-action: none;
}
.g-lb-swiper .swiper-slide {
    display: flex;
    align-items: center;
    justify-content: center;
}
.g-lightbox__img {
    max-width: 100%;
    max-height: 72vh;
    object-fit: contain;
    border-radius: 12px;
    box-shadow: 0 30px 80px -20px rgba(0, 0, 0, 0.7);
}
.g-lightbox__caption {
    color: #fff;
    text-align: center;
    font-family: 'DM Sans', sans-serif;
    max-width: 44rem;
}
.g-lightbox__caption .cap-title {
    font-family: 'Crimson Text', serif;
    font-size: 1.25rem;
    font-weight: 700;
}
.g-lightbox__caption .cap-desc {
    color: rgba(255, 255, 255, 0.86);
    font-size: 0.95rem;
    margin-top: 0.35rem;
    line-height: 1.4;
}
.g-lightbox__caption .cap-desc[hidden] { display: none; }
.g-lightbox__caption .cap-credit { color: rgba(255, 255, 255, 0.7); font-size: 0.9rem; margin-top: 0.4rem; }
.g-lightbox__caption .cap-credit a { color: var(--g-turq); text-decoration: none; }
.g-lightbox__caption .cap-credit a:hover { text-decoration: underline; }

.g-lb-btn {
    position: absolute;
    /* Above the stage. Without this the controls paint in DOM order, which put
       `prev` (declared before the photo) underneath it while `next` sat on top
       — the prev arrow was unclickable on mobile, where the photo is full width. */
    z-index: 2;
    top: 50%;
    transform: translateY(-50%);
    width: 48px;
    height: 48px;
    border-radius: 50%;
    border: none;
    background: rgba(255, 255, 255, 0.12);
    color: #fff;
    display: grid;
    place-items: center;
    cursor: pointer;
    transition: background 0.2s ease;
}
.g-lb-btn:hover { background: rgba(64, 224, 208, 0.35); }
.g-lb-prev { left: clamp(0.5rem, 2vw, 1.5rem); }
.g-lb-next { right: clamp(0.5rem, 2vw, 1.5rem); }
.g-lb-close { top: clamp(0.75rem, 2vw, 1.4rem); right: clamp(0.75rem, 2vw, 1.4rem); transform: none; }
.g-lb-counter {
    position: absolute;
    bottom: clamp(0.75rem, 2vw, 1.4rem);
    left: 50%;
    transform: translateX(-50%);
    color: rgba(255, 255, 255, 0.7);
    font-family: 'DM Sans', sans-serif;
    font-size: 0.85rem;
    font-variant-numeric: tabular-nums;
}

/* ---- Homepage snippet ------------------------------------------------- */
.gallery-snippet { padding: clamp(3rem, 7vw, 5rem) 0; background: var(--color-light, #f8f9fa); }
.gallery-snippet__head { text-align: center; margin-bottom: 2rem; padding: 0 1rem; }
.gallery-snippet__kicker {
    font-family: 'Dancing Script', cursive;
    font-size: clamp(1.4rem, 3.5vw, 2rem);
    color: var(--color-turquoise, #40e0d0);
}
.gallery-snippet__title {
    font-family: 'Crimson Text', serif;
    font-weight: 700;
    font-size: clamp(1.9rem, 5vw, 3rem);
    color: var(--color-navy, #03235a);
    margin: 0.1rem 0 0.5rem;
}
.gallery-snippet__sub {
    font-family: 'DM Sans', sans-serif;
    color: #55617a;
    max-width: 32rem;
    margin: 0 auto;
}
/* ---- Carousel --------------------------------------------------------- */
.gallery-carousel {
    position: relative;
    max-width: 1200px;
    margin: 0 auto;
    padding: 0 clamp(1rem, 5vw, 3.5rem);
}
.gallery-swiper {
    overflow: hidden;
    /* Generous vertical padding so the (softened) slide shadow fully fades
       inside the track before overflow:hidden clips it — otherwise the blur is
       sliced off into a hard horizontal line. Horizontal stays 0 so neighbours
       still peek. */
    padding: 1rem 0 3.25rem;
}
/* Fixed-width portrait cards; Swiper runs with slidesPerView:'auto' so how many
   show adapts to the viewport (centered card + peeking neighbours). */
.gallery-slide {
    width: clamp(230px, 68vw, 360px);
}
/* Depth effect only once Swiper is running (progressive enhancement: with no
   JS the slides render full-size and visible, not dimmed). */
.swiper-initialized .gallery-slide {
    transition: transform 0.5s ease, opacity 0.5s ease;
    transform: scale(0.9);
    opacity: 0.55;
}
.swiper-initialized .gallery-slide.swiper-slide-active {
    transform: scale(1);
    opacity: 1;
}
.gallery-slide__frame {
    position: relative;
    display: block;
    overflow: hidden;                 /* clips the parallaxing image */
    border-radius: 0;                 /* square-edged */
    aspect-ratio: 2 / 3;              /* portrait cards */
    background: linear-gradient(110deg, #dfe9ec 8%, #d2e0e3 18%, #dfe9ec 33%);
    background-size: 200% 100%;
    /* Soft, low-contrast lift — fully contained by the track's padding, so it
       fades to nothing rather than ending in a clipped line. */
    box-shadow: 0 14px 38px -18px rgba(3, 35, 90, 0.32);
    /* Not clickable — the carousel is a swipe preview; the CTA button is the
       only navigation. Inherit Swiper's grab/grabbing cursor. */
    cursor: inherit;
}
.gallery-slide.is-loading .gallery-slide__frame {
    animation: g-shimmer 1.3s ease-in-out infinite;
}
.gallery-slide__img {
    position: absolute;
    top: 0;
    left: -20%;
    width: 140%;                      /* oversized so the parallax drift never
                                         exposes a frame edge */
    height: 100%;
    object-fit: cover;
    transition: opacity 0.6s ease;
}
.gallery-slide.is-loading .gallery-slide__img { opacity: 0; }
.gallery-slide__meta {
    position: absolute;
    inset: auto 0 0 0;
    z-index: 2;
    padding: 2rem 1.4rem 1.2rem;
    background: linear-gradient(to top, rgba(2, 17, 44, 0.85), transparent);
    color: #fff;
    display: flex;
    flex-direction: column;
    gap: 0.15rem;
    transition: opacity 0.4s ease;
}
/* Only the focused slide shows its caption, once Swiper is active. */
.swiper-initialized .gallery-slide__meta { opacity: 0; }
.swiper-initialized .gallery-slide.swiper-slide-active .gallery-slide__meta { opacity: 1; }
.gallery-slide__title {
    font-family: 'Crimson Text', serif;
    font-size: 1.35rem;
    font-weight: 700;
    line-height: 1.1;
}
.gallery-slide__loc {
    font-family: 'DM Sans', sans-serif;
    font-size: 0.85rem;
    color: var(--color-turquoise, #40e0d0);
    display: inline-flex;
    align-items: center;
    gap: 0.35rem;
}

/* Nav arrows */
.gallery-nav {
    position: absolute;
    top: 50%;
    transform: translateY(-50%);
    z-index: 5;
    width: 48px;
    height: 48px;
    border-radius: 50%;
    border: none;
    background: #fff;
    color: var(--color-navy, #03235a);
    display: grid;
    place-items: center;
    cursor: pointer;
    box-shadow: 0 8px 22px -8px rgba(3, 35, 90, 0.5);
    transition: transform 0.2s ease, background 0.2s ease, color 0.2s ease;
}
.gallery-nav:hover {
    background: var(--color-navy, #03235a);
    color: #fff;
    transform: translateY(-50%) scale(1.06);
}
.gallery-nav--prev { left: clamp(-0.25rem, 1vw, 0.75rem); }
.gallery-nav--next { right: clamp(-0.25rem, 1vw, 0.75rem); }
.gallery-nav.swiper-button-disabled { opacity: 0; pointer-events: none; }

/* Dots */
.gallery-dots {
    display: flex;
    justify-content: center;
    gap: 0.5rem;
    margin-top: 0.25rem;   /* track already carries bottom padding for the shadow */
}
.gallery-dots .swiper-pagination-bullet {
    width: 8px;
    height: 8px;
    border-radius: 999px;
    background: #c3d0dc;
    opacity: 1;
    transition: width 0.3s ease, background 0.3s ease;
    cursor: pointer;
}
.gallery-dots .swiper-pagination-bullet-active {
    width: 26px;
    background: var(--color-turquoise, #40e0d0);
}

.gallery-snippet__cta { text-align: center; margin-top: 2.2rem; }
.btn-gallery {
    display: inline-flex;
    align-items: center;
    gap: 0.6rem;
    font-family: 'DM Sans', sans-serif;
    font-weight: 700;
    font-size: 1rem;
    color: #fff;
    background: var(--color-navy, #03235a);
    border: none;
    border-radius: 999px;
    padding: 0.85rem 1.8rem;
    text-decoration: none;
    transition: transform 0.2s ease, background 0.2s ease, box-shadow 0.2s ease;
    box-shadow: 0 10px 26px -12px rgba(3, 35, 90, 0.6);
}
.btn-gallery:hover {
    transform: translateY(-2px);
    background: #06316f;
    color: #fff;
}
.btn-gallery__arrow { transition: transform 0.2s ease; }
.btn-gallery:hover .btn-gallery__arrow { transform: translateX(4px); }

/* ---- Responsive -------------------------------------------------------
   The bento keeps the SAME column count on every device (so the flush bottom is
   identical); tiles just scale down. Heroes span the fixed columns too, so they
   need no special mobile handling. We only tighten gap + padding on phones. */
@media (max-width: 768px) {
    /* Carousel: arrows tuck to the corners */
    .gallery-nav { width: 42px; height: 42px; }
}
@media (max-width: 600px) {
    .gallery-grid { --g-gap: 8px; --pad-x: 0.75rem; }
}

/* ---- Motion preferences ----------------------------------------------- */
@media (prefers-reduced-motion: reduce) {
    .g-tile.is-loading,
    .gallery-slide.is-loading .gallery-slide__frame { animation: none; }
    .g-tile__img,
    .g-tile:hover .g-tile__img,
    .g-tile.is-loaded .g-tile__img,
    .g-lightbox, .g-lb-stage, .g-lb-backdrop,
    .btn-gallery, .g-chip,
    .gallery-slide, .gallery-slide__meta { transition: none; }
    .g-tile__img { opacity: 1; transform: none; }
    /* No shrink/fade of neighbours; JS also disables Swiper parallax. */
    .swiper-initialized .gallery-slide { transform: none; opacity: 1; }
}
