/* =====================================================================
   MY PHOTOGRAPHY  —  /photography/gallery.css
   Same family as Daily Picks and Live Earth: warm paper, serif type,
   museum-label red. The photos sit in justified rows (every row the same
   height, nothing cropped), which needs no JavaScript at all.
   ===================================================================== */

:root {
    --ph-ink: #1b1a17;
    --ph-muted: #6b665c;
    --ph-faint: #9a948a;
    --ph-accent: #8a2b1d;
    --ph-serif: "Iowan Old Style", "Palatino Linotype", Palatino, "Book Antiqua",
                Georgia, "Times New Roman", Times, serif;

    --row: 260px;   /* keep in step with ROW_DESKTOP in build_gallery.py */
    --gap: 6px;
}

.site-title,
.site-title:visited {
    color: inherit;
    text-decoration: none;
}

main.ph-main {
    display: block;
    grid-template-columns: none;
    width: 100%;
    max-width: 1600px;
    margin: 6px auto 0;
    font-family: var(--ph-serif);
    color: var(--ph-ink);
}

/* ---------------------------------------------------------------------
   Heading
   --------------------------------------------------------------------- */

.ph-hero {
    text-align: center;
    padding: 26px 0 30px;
}

main.ph-main .ph-kicker {
    margin: 0 0 6px;
    font-size: 0.8rem;
    letter-spacing: 0.32em;
    text-transform: uppercase;
    color: var(--ph-accent);
}

main.ph-main .ph-title {
    margin: 0;
    font-size: clamp(1.9rem, 4.2vw, 2.9rem);
    font-style: italic;
    line-height: 1.15;
}

main.ph-main .ph-intro,
main.ph-main .ph-elsewhere {
    max-width: 36em;
    margin: 12px auto 0;
    font-size: 1.02rem;
    line-height: 1.55;
    color: var(--ph-muted);
}

main.ph-main .ph-elsewhere {
    margin-top: 4px;
    font-size: 0.92rem;
}

.ph-elsewhere a { color: #1b1a17; text-underline-offset: 3px; }
.ph-elsewhere a:visited { color: #8a2b1d; }
.ph-elsewhere a:hover { text-decoration-color: currentColor; }

.ph-hero::after {
    content: "";
    display: block;
    width: 64px;
    height: 1px;
    margin: 24px auto 0;
    background: var(--ph-accent);
    opacity: 0.6;
}

/* ---------------------------------------------------------------------
   Justified rows
   Each photo's flex-grow and width are proportional to its shape (--r =
   width / height), so every photo in a row ends up the same height.
   --------------------------------------------------------------------- */

.ph-grid {
    display: flex;
    flex-wrap: wrap;
    gap: var(--gap);
}

.ph-grid::after {
    /* stops the last row from stretching huge */
    content: "";
    flex-grow: 999999;
}

.ph {
    position: relative;
    display: block;
    flex: calc(var(--r) * 1000) 1 calc(var(--r) * var(--row));
    aspect-ratio: var(--r);
    overflow: hidden;
    border-radius: 3px;
    background: var(--c, #e9e4da);  /* the photo's own colour while it loads */
    cursor: zoom-in;
    -webkit-tap-highlight-color: transparent;
}

.ph img {
    display: block;
    width: 100%;
    height: 100%;
    object-fit: cover;
    transition: transform 0.6s cubic-bezier(.2, .7, .2, 1), filter 0.3s ease;
}

.ph:hover img {
    transform: scale(1.03);
}

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

/* ---------------------------------------------------------------------
   Viewer (full screen)
   --------------------------------------------------------------------- */

.viewer {
    width: 100vw;
    height: 100vh;
    height: 100dvh;
    max-width: none;
    max-height: none;
    margin: 0;
    padding: 0;
    border: 0;
    background: #0f0e0c;
    color: #ece7dd;
    overflow: hidden;
    overscroll-behavior: contain;
}

.viewer::backdrop { background: #0f0e0c; }

.viewer[open] {
    display: flex;
    flex-direction: column;
    animation: viewer-in 0.2s ease;
}

@keyframes viewer-in {
    from { opacity: 0; }
    to   { opacity: 1; }
}

.viewer-stage {
    position: relative;
    flex: 1;
    min-height: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 56px 72px 8px;
    touch-action: pan-y pinch-zoom;
}

.viewer-img {
    max-width: 100%;
    max-height: 100%;
    object-fit: contain;
    user-select: none;
    -webkit-user-drag: none;
    transition: opacity 0.25s ease, transform 0.25s ease;
    background: var(--c, transparent);
}

.viewer-img.is-loading { opacity: 0.55; }
.viewer-img.is-swiping { transition: none; }

.viewer-bar {
    display: flex;
    align-items: flex-end;
    justify-content: space-between;
    gap: 16px;
    padding: 12px 24px 18px;
    padding-bottom: max(18px, env(safe-area-inset-bottom));
    font-family: var(--ph-serif);
}

.viewer-text { min-width: 0; }

.viewer-title {
    margin: 0;
    font-size: 1.15rem;
    font-style: italic;
    color: #f4efe4;
}

.viewer-caption {
    margin: 3px 0 0;
    max-width: 48em;
    font-size: 0.95rem;
    line-height: 1.5;
    color: #b9b2a5;
}
.viewer-caption:empty { display: none; }

.viewer-tools {
    display: flex;
    align-items: baseline;
    gap: 16px;
    flex: 0 0 auto;
    font-size: 0.88rem;
    color: #9a9387;
}

.viewer-count { font-variant-numeric: tabular-nums; }

.viewer-full {
    color: #d8d1c4;
    text-underline-offset: 3px;
}
.viewer-full:hover { color: #fff; }

.viewer-btn {
    position: absolute;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 48px;
    height: 48px;
    border: 0;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.08);
    color: #f4efe4;
    font-size: 2rem;
    line-height: 1;
    cursor: pointer;
    transition: background 0.15s ease;
}

.viewer-btn:hover { background: rgba(255, 255, 255, 0.18); }
.viewer-btn:focus-visible { outline: 2px solid #f4efe4; outline-offset: 2px; }

.viewer-close { top: 12px; right: 14px; font-size: 1.8rem; }
.viewer-prev  { left: 14px;  top: 50%; transform: translateY(-50%); }
.viewer-next  { right: 14px; top: 50%; transform: translateY(-50%); }

/* ---------------------------------------------------------------------
   Phones & tablets
   --------------------------------------------------------------------- */

@media (max-width: 700px) {
    :root {
        --row: 118px;   /* keep in step with ROW_PHONE in build_gallery.py */
        --gap: 4px;
    }

    .ph-hero { padding: 14px 0 22px; }

    /* On phones, keep every photo inside the screen: 2 per row at least */
    .ph { max-width: 100%; }

    .ph:hover img { transform: none; }

    .viewer-stage { padding: 52px 0 4px; }
    .viewer-prev, .viewer-next { display: none; }  /* swipe instead */
    .viewer-bar { padding: 10px 16px 14px; flex-direction: column; align-items: flex-start; gap: 6px; }
}

@media (prefers-reduced-motion: reduce) {
    .ph img, .viewer-img { transition: none; }
    .viewer[open] { animation: none; }
}
