/*
 * "Our Happy Clients" — polaroids taped to a white wall.
 *
 * Scoped to #gallery and .g-lightbox so it cannot reach the rest of the page.
 *
 * A uniform grid, not masonry. Nic's reference is an even wall of prints, and
 * even spacing is also what makes the tilt read as hand-placed rather than
 * broken: ragged column heights plus rotation looks like a layout bug.
 *
 * Each card is three pieces — the tape, the white frame, and the photo window
 * inside it. The tape carries the caption and overhangs the top of the frame,
 * so the frame cannot be the element with overflow:hidden; the photo window
 * inside it is.
 *
 * The tilt is a custom property set per card by gallery.js from the photo's
 * id, so it is the same every time the page loads instead of reshuffling.
 */

#gallery {
    /* The wall and the frames are the only colours of the gallery's own: they
       are the look Nic asked for, paper on a white wall. Everything a visitor
       can click or read comes from the site's palette, so the gallery cannot
       drift away from the rest of the page. The accent was sage green until
       2026-12-05; Nic wanted one palette, and it is the site's. */
    --g-wall:        #fcfcfb;
    --g-frame:       #ffffff;
    --g-accent:      var(--primary-color, #6d85a6);
    --g-accent-dark: #566b8a;   /* hover and focus: the accent, darkened */
    --g-accent-tint: #eef1f6;
    --g-ink:         var(--dark-gray, #333);
    --g-muted:       #666;      /* the site's secondary text */
    --g-line:        #e3e7ec;

    /* A wall, not a flat fill: a touch of light at the top stops the white
       reading as "no background" and gives the shadows something to fall on. */
    background:
        radial-gradient(120% 60% at 50% -10%, #ffffff 0%, var(--g-wall) 60%),
        var(--g-wall);
    padding: 5rem 1.5rem 5.5rem;
}

/* ------------------------------------------------------------------ head */

.g-head {
    max-width: 680px;
    margin: 0 auto 2.8rem;
    text-align: center;
}

.g-paw {
    display: block;
    margin: 0 auto .7rem;
    width: 26px;
    height: 26px;
    opacity: .45;
}

/* The heading matches the site's other section titles. index.html also gives
   it .section-title, but the values are repeated here on purpose: this file
   can reach the server without index.html, and a heading with no rule at all
   falls back to the browser's black 2em default. The gap below is the
   gallery's own, because .g-head owns the space down to the filters. */
#gallery .g-head h2 {
    margin: 0 0 .7rem;
    color: var(--primary-color);
    font-size: 2.5rem;
}

.g-head p {
    margin: 0;
    color: var(--dark-gray, #333);
    font-size: 1.05rem;
    line-height: 1.65;
}

/* --------------------------------------------------------------- filters */

.g-filters {
    display: flex;
    justify-content: center;
    flex-wrap: wrap;
    gap: .5rem;
    max-width: 1180px;
    margin: 0 auto 3rem;
}

.g-filter {
    flex: 0 0 auto;
    padding: .5rem 1.1rem;
    border: 1px solid var(--g-line);
    border-radius: 999px;
    background: #fff;
    color: var(--g-muted);
    font: inherit;
    font-size: .93rem;
    cursor: pointer;
    transition: background .22s ease, color .22s ease, border-color .22s ease;
}

.g-filter:hover { border-color: var(--g-accent); color: var(--g-accent-dark); }

.g-filter[aria-pressed="true"] {
    background: var(--g-accent);
    border-color: var(--g-accent);
    color: #fff;
}

.g-filter:focus-visible { outline: 3px solid var(--g-accent-dark); outline-offset: 2px; }

/* On a phone the filters scroll sideways rather than stacking into a block
   that pushes the photographs off the first screen. */
@media (max-width: 640px) {
    .g-filters {
        flex-wrap: nowrap;
        overflow-x: auto;
        justify-content: flex-start;
        padding-bottom: .4rem;
        scrollbar-width: none;
        -webkit-overflow-scrolling: touch;
    }
    .g-filters::-webkit-scrollbar { display: none; }
}

/* ------------------------------------------------------------------ wall */

.g-grid {
    display: grid;
    grid-template-columns: repeat(var(--g-cols, 2), minmax(0, 1fr));
    /* dense so a double-width print backfills the gap it would leave */
    grid-auto-flow: row dense;
    /* Roomy on purpose: the tape overhangs the top of every frame and the
       tilt pushes corners outward, so tight gutters would have them touch. */
    gap: 3.2rem 1.8rem;
    max-width: 1180px;
    margin: 0 auto;
}

/* Two columns is the phone layout, not the fallback. The threshold sits at
   330px because 375px is an iPhone SE and 390px an iPhone 14 -- a breakpoint
   anywhere above those puts every phone on a single very long column. */
@media (min-width:  330px) { .g-grid { --g-cols: 2; } }
@media (min-width:  860px) { .g-grid { --g-cols: 3; gap: 3.4rem 2.2rem; } }
@media (min-width: 1180px) { .g-grid { --g-cols: 4; } }
@media (max-width:  329px) { .g-grid { --g-cols: 1; } }

/* -------------------------------------------------------------- one print */

.g-card {
    --tilt: 0deg;              /* gallery.js overwrites this per photo */

    position: relative;
    display: block;
    width: 100%;
    padding: 0;
    border: 0;
    background: none;
    cursor: pointer;
    transform: rotate(var(--tilt));
    transition: transform .3s cubic-bezier(.2, .7, .3, 1), filter .3s ease;
}

.g-card:hover,
.g-card:focus-visible {
    /* Straightens and lifts, as though you had picked it off the wall. */
    transform: rotate(calc(var(--tilt) * 0.2)) translateY(-6px) scale(1.025);
    z-index: 2;
}

.g-card:focus-visible { outline: none; }
.g-card:focus-visible .g-frame { outline: 3px solid var(--g-accent-dark); outline-offset: 4px; }

/* the white border of the print */
.g-frame {
    display: flex;
    flex-direction: column;
    height: 100%;
    padding: 11px 11px 34px;
    background: var(--g-frame);
    border-radius: 2px;
    box-shadow:
        0 1px 2px rgba(40, 36, 28, .10),
        0 10px 22px -6px rgba(40, 36, 28, .22);
    transition: box-shadow .3s ease;
}

.g-card:hover .g-frame,
.g-card:focus-visible .g-frame {
    box-shadow:
        0 2px 4px rgba(40, 36, 28, .12),
        0 22px 40px -10px rgba(40, 36, 28, .30);
}

/* the window the photograph sits in — this is what clips, not the frame,
   because the tape has to be allowed to hang over the top edge */
.g-shot {
    flex: 1 1 auto;
    display: block;
    aspect-ratio: 4 / 3;
    overflow: hidden;
    background: #ece7dd;
}

.g-card img {
    width: 100%;
    height: 100%;
    display: block;
    object-fit: cover;
    opacity: 0;
    transition: opacity .5s ease;
}

.g-card img.is-loaded { opacity: 1; }

/* A big print takes two columns and two rows.
 *
 * Its height is set in pixels by gallery.js, from the measured height of an
 * ordinary print. Left to itself the photo has no height to size against --
 * `aspect-ratio: auto` means "as tall as the picture" -- so it grew past its
 * two rows and dragged the whole row down with it. */
.g-card.is-featured { grid-column: span 2; grid-row: span 2; }
.g-card.is-featured .g-frame { height: 100%; }
.g-card.is-featured .g-shot { aspect-ratio: auto; height: 100%; min-height: 0; }

@media (max-width: 329px) {
    /* One column: there is no "twice as wide", so it is an ordinary print. */
    .g-card.is-featured { grid-column: span 1; grid-row: span 1; height: auto !important; }
    .g-card.is-featured .g-shot { aspect-ratio: 4 / 3; height: auto; }
}

/* ------------------------------------------------------------------ tape */

.g-tape {
    position: absolute;
    top: -13px;
    left: 50%;
    z-index: 3;
    max-width: 82%;
    padding: .3rem .95rem .32rem;

    /* Washi tape: translucent, so the frame and the wall show through it,
       with the ends a shade darker the way a torn strip bunches up. */
    background:
        linear-gradient(90deg,
            rgba(214, 206, 186, .62) 0%,
            rgba(238, 233, 219, .52) 14%,
            rgba(238, 233, 219, .52) 86%,
            rgba(214, 206, 186, .62) 100%);
    box-shadow: 0 1px 2px rgba(40, 36, 28, .12);

    color: #55513f;
    font-family: 'Bradley Hand', 'Segoe Script', 'Ink Free', 'Marker Felt', cursive;
    font-size: .92rem;
    line-height: 1.25;
    text-align: center;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;

    /* Counter-rotated against the print, so the tape looks stuck on by hand
       rather than printed as part of the card. */
    transform: translateX(-50%) rotate(calc(var(--tilt) * -1.6));
    transform-origin: center;
    pointer-events: none;
}

/* A print with nothing written on it still gets a strip, just a short one. */
.g-tape.is-blank { width: 86px; padding: .42rem 0; }

/* On a phone a print is about 150px wide, and one line of tape turns most
   captions into "Found the w...". Two lines, then clip. */
@media (max-width: 640px) {
    .g-tape {
        display: -webkit-box;
        -webkit-line-clamp: 2;
        line-clamp: 2;
        -webkit-box-orient: vertical;
        white-space: normal;
        max-width: 90%;
        padding: .26rem .55rem .28rem;
        font-size: .82rem;
        line-height: 1.2;
    }
    .g-tape.is-blank { display: block; width: 64px; }
}

/* ------------------------------------------------------- load more, states */

.g-more-wrap { text-align: center; margin-top: 3.4rem; }

.g-more {
    padding: .8rem 1.9rem;
    border: 1px solid var(--g-accent);
    border-radius: 999px;
    background: transparent;
    color: var(--g-accent-dark);
    font: inherit;
    font-size: .98rem;
    cursor: pointer;
    transition: background .22s ease, color .22s ease;
}

.g-more:hover { background: var(--g-accent); color: #fff; }
.g-more[disabled] { opacity: .55; cursor: default; }
.g-more:focus-visible { outline: 3px solid var(--g-accent-dark); outline-offset: 3px; }

.g-note {
    max-width: 1180px;
    margin: 0 auto;
    text-align: center;
    color: var(--g-muted);
    font-size: .98rem;
    padding: 2rem 0;
}

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

.g-lightbox {
    position: fixed;
    inset: 0;
    z-index: 9000;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: clamp(.8rem, 4vw, 3rem);
    background: rgba(26, 24, 19, .88);
    -webkit-backdrop-filter: blur(7px);
    backdrop-filter: blur(7px);
    opacity: 0;
    visibility: hidden;

    /* visibility is NOT transitioned alongside opacity. A transitioned
       discrete property flips half way through, so the dialog stayed
       visibility:hidden for the first 125ms -- long enough that focusing the
       close button silently did nothing and a keyboard user was left on the
       page behind. Here it flips at once on open, and only waits for the
       fade on the way out. */
    transition: opacity .25s ease, visibility 0s linear .25s;
}

.g-lightbox.is-open {
    opacity: 1;
    visibility: visible;
    transition: opacity .25s ease, visibility 0s linear 0s;
}

.g-figure {
    position: relative;
    margin: 0;
    max-width: min(1100px, 100%);
    max-height: 100%;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: .9rem;
}

.g-figure img {
    max-width: 100%;
    max-height: 76vh;
    display: block;
    border-radius: 10px;
    object-fit: contain;
    background: rgba(255, 255, 255, .04);
}

.g-figcaption {
    color: #f3efe6;
    text-align: center;
    max-width: 44rem;
    font-size: .98rem;
    line-height: 1.55;
}

.g-figcaption .g-name { display: block; font-weight: 600; font-size: 1.1rem; }
.g-figcaption .g-sub  { display: block; opacity: .78; margin-top: .25rem; }

.g-count {
    position: absolute;
    top: clamp(.6rem, 2.5vw, 1.4rem);
    left: clamp(.8rem, 3vw, 1.8rem);
    color: rgba(255, 255, 255, .8);
    font-size: .9rem;
    letter-spacing: .02em;
}

.g-nav, .g-close {
    position: absolute;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 48px;
    height: 48px;
    border: 0;
    border-radius: 50%;
    background: rgba(255, 255, 255, .12);
    color: #fff;
    font-size: 1.5rem;
    line-height: 1;
    cursor: pointer;
    transition: background .2s ease;
}

.g-nav:hover, .g-close:hover { background: rgba(255, 255, 255, .26); }
.g-nav:focus-visible, .g-close:focus-visible { outline: 3px solid #fff; outline-offset: 2px; }

.g-prev  { left:  clamp(.5rem, 2.5vw, 1.6rem); top: 50%; transform: translateY(-50%); }
.g-next  { right: clamp(.5rem, 2.5vw, 1.6rem); top: 50%; transform: translateY(-50%); }
.g-close { right: clamp(.8rem, 3vw, 1.8rem);   top: clamp(.6rem, 2.5vw, 1.4rem); }

@media (max-width: 560px) {
    .g-prev { left: .5rem;  top: auto; bottom: .8rem; transform: none; }
    .g-next { right: .5rem; top: auto; bottom: .8rem; transform: none; }
    .g-figure img { max-height: 62vh; }
}

/* Set while the lightbox is open so the page behind it does not scroll. */
body.g-locked { overflow: hidden; }

/* ------------------------------------------------------------------- CTA */

.g-cta {
    max-width: 620px;
    margin: 4.6rem auto 0;
    padding: 2.3rem 1.6rem;
    text-align: center;
    background: var(--g-accent-tint);
    border-radius: 18px;
}

#gallery .g-cta h3 {
    margin: 0 0 .5rem;
    color: var(--g-ink);
    font-size: 1.4rem;
    font-weight: 600;
}

.g-cta p { margin: 0 0 1.3rem; color: var(--g-muted); }

.g-cta a {
    display: inline-block;
    padding: .85rem 2rem;
    border-radius: 999px;
    background: var(--primary-color, #6d85a6);
    color: #fff;
    text-decoration: none;
    font-weight: 600;
    transition: transform .2s ease, filter .2s ease;
}

.g-cta a:hover { filter: brightness(1.08); transform: translateY(-1px); }
.g-cta a:focus-visible { outline: 3px solid var(--g-accent-dark); outline-offset: 3px; }

/* ------------------------------------------------------- reduced motion */

@media (prefers-reduced-motion: reduce) {
    #gallery *, .g-lightbox * {
        transition: none !important;
        animation: none !important;
    }
    .g-card img { opacity: 1; }
    /* The tilt stays: it is how the wall looks, not an animation. Only the
       lift on hover goes. */
    .g-card:hover, .g-card:focus-visible { transform: rotate(var(--tilt)); }
}
