/* =====================================================================
   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;   /* only used before gallery.js lays out the rows exactly */
    --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 {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    align-items: end;
    column-gap: 32px;
    padding: 10px 0 18px;
    margin-bottom: 14px;
    border-bottom: 1px solid #e4dfd5;
    text-align: left;
}
.ph-hero > * { grid-column: 1; animation: ph-in 0.7s cubic-bezier(.2, .7, .2, 1) both; }
.ph-hero > :nth-child(2) { animation-delay: 0.06s; }
.ph-hero > :nth-child(3) { animation-delay: 0.12s; }
.ph-hero > .ph-elsewhere { grid-column: 2; grid-row: 1 / span 3; align-self: end; text-align: right; animation-delay: 0.18s; }
@keyframes ph-in { from { opacity: 0; transform: translateX(-8px); } }

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

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

main.ph-main .ph-intro,
main.ph-main .ph-elsewhere {
    max-width: 40em;
    margin: 6px 0 0;
    font-size: 0.95rem;
    line-height: 1.5;
    color: var(--ph-muted);
}

main.ph-main .ph-elsewhere {
    font-size: 0.88rem;
    max-width: 22em;
}

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

/* ---------------------------------------------------------------------
   Topic buttons (All, Best, my categories)
   --------------------------------------------------------------------- */

.ph-filters {
    display: flex;
    flex-wrap: wrap;
    justify-content: flex-start;
    gap: 6px;
    margin: 0 0 6px;
    animation: ph-in 0.7s cubic-bezier(.2, .7, .2, 1) 0.2s both;
}
.ph-filter {
    padding: 7px 15px;
    border: 1px solid #e4dfd5;
    border-radius: 999px;
    background: #fff;
    color: var(--ph-ink);
    font: 0.95rem/1 var(--ph-serif);
    cursor: pointer;
    transition: background 0.25s ease, color 0.25s ease, border-color 0.25s ease;
}
.ph-filter span { margin-left: 3px; font-size: 0.78rem; color: var(--ph-faint); }
.ph-filter:hover { border-color: var(--ph-ink); }
.ph-filter[aria-pressed="true"] { background: var(--ph-ink); border-color: var(--ph-ink); color: #fff; }
.ph-filter[aria-pressed="true"] span { color: rgba(255, 255, 255, 0.6); }
.ph-filter:focus-visible { outline: 2px solid var(--ph-accent); outline-offset: 2px; }
main.ph-main .ph-filter-note {
    min-height: 1.2em;
    margin: 2px 0 10px;
    text-align: left;
    font-size: 0.95rem;
    font-style: italic;
    color: var(--ph-muted);
}
.ph-grid { transition: opacity 0.25s ease; }
main.ph-main .ph-status {
    flex: 1 1 100%;
    margin: 40px 0 60px;
    text-align: center;
    font-style: italic;
    color: var(--ph-muted);
}
.ph-grid.is-changing { opacity: 0; transition: none; }

/* ---------------------------------------------------------------------
   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;
}

/* once gallery.js has worked out each photo's exact size */
.ph-grid.is-laid-out .ph { flex: none; aspect-ratio: auto; max-width: none; }

.ph img {
    display: block;
    width: 100%;
    height: 100%;
    object-fit: cover;
    opacity: 0;
    transition: transform 0.6s cubic-bezier(.2, .7, .2, 1), filter 0.3s ease, opacity 0.6s ease;
}
.ph.is-loaded img, .ph img[src^="data:"] { opacity: 1; }
.no-js .ph img { opacity: 1; }

/* rising gently into view while scrolling */
.ph.will-rise { opacity: 0; transform: translateY(14px); transition: opacity 0.7s ease, transform 0.7s cubic-bezier(.2, .7, .2, 1); }
.ph.will-rise.is-in { opacity: 1; transform: none; }

/* the title on hover */
.ph-cap {
    position: absolute;
    left: 0; right: 0; bottom: 0;
    padding: 28px 12px 9px;
    background: linear-gradient(to top, rgba(15, 12, 8, 0.62), transparent);
    color: #fff;
    font: italic 0.95rem/1.25 var(--ph-serif);
    opacity: 0;
    transform: translateY(6px);
    transition: opacity 0.35s ease, transform 0.35s ease;
    pointer-events: none;
}
.ph-cap small { display: block; margin-top: 2px; font: normal 0.75rem var(--ph-serif); opacity: 0.8; }
.ph:hover .ph-cap, .ph:focus-visible .ph-cap { opacity: 1; transform: none; }
@media (hover: none) { .ph-cap { display: none; } }

.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-exif {
    margin: 4px 0 0;
    font: 0.78rem/1.4 ui-monospace, "SF Mono", Menlo, Consolas, monospace;
    letter-spacing: 0.02em;
    color: #8a8377;
}
.viewer-exif: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-share {
    padding: 5px 13px;
    border: 1px solid rgba(255, 255, 255, 0.22);
    border-radius: 999px;
    background: transparent;
    color: #d8d1c4;
    font: inherit;
    cursor: pointer;
    transition: background 0.2s ease, color 0.2s ease;
}
.viewer-share:hover { background: rgba(255, 255, 255, 0.1); color: #fff; }
.viewer-share:focus-visible { outline: 2px solid #f4efe4; outline-offset: 2px; }

.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 { grid-template-columns: 1fr; padding: 4px 0 14px; }
    .ph-hero > .ph-elsewhere { grid-column: 1; grid-row: auto; text-align: left; max-width: none; }

    /* 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; }
    .ph-hero > *, .ph-filters { animation: none; }
    .viewer[open] { animation: none; }
}
