.photography-page {
    color: #e8e8e8;
    --muted: #929292;
    animation: gallery-darken 1.6s ease-out both;
}

.photography-page::after {
    content: '';
    position: fixed;
    inset: 0;
    z-index: 100;
    background: #000;
    pointer-events: none;
    animation: gallery-curtain 1.65s ease-in-out both;
}

@keyframes gallery-darken {
    from { background-color: var(--page-bg); }
    to { background-color: var(--gallery-bg); }
}

@keyframes gallery-curtain {
    0%, 15% { opacity: 1; }
    100% { opacity: 0; visibility: hidden; }
}

.photography-page header {
    background: rgba(0, 0, 0, 0.88);
    border-bottom-color: #1b1b1b;
}

.photography-page .navbar {
    max-width: none;
    padding-inline: 32px;
}

.photography-page main {
    max-width: none;
    padding: 32px 32px 64px;
}

.photography-heading {
    animation: photography-enter 1.3s ease 0.35s both;
    display: flex;
    align-items: baseline;
    justify-content: space-between;
    gap: 24px;
    margin-bottom: 24px;
}

.photography-heading h1 {
    margin: 0;
    font-family: "Libre Baskerville", "Times New Roman", serif;
    font-size: clamp(1.35rem, 2vw, 1.8rem);
    font-weight: 400;
}

.photography-heading p,
.gallery-status {
    color: var(--muted);
    font-size: 0.85rem;
}

.photography-heading p { margin: 0; }
.gallery-status { padding: 64px 0; }

.photographs {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 20px;
    align-items: center;
}

.photograph { margin: 0; min-width: 0; }

.photograph:not(.is-ready),
.photograph:not(.in-view) { opacity: 0; }

.photograph.is-ready.in-view {
    animation: photography-enter 0.9s ease var(--entrance-delay, 0ms) both;
}

.photograph.opening-photo.is-ready.in-view {
    animation: photography-opening 1.65s cubic-bezier(0.16, 1, 0.3, 1) var(--opening-delay, 0.4s) both;
}

@keyframes photography-opening {
    from { opacity: 0; transform: translateY(48px) scale(0.9); }
    to { opacity: 1; transform: translateY(0) scale(1); }
}

/* Keyboard focus should never land on a visually hidden photograph. */
.photograph:focus-within { opacity: 1; animation: none !important; }

@keyframes photography-enter {
    from { opacity: 0; transform: translateY(14px); }
    to { opacity: 1; transform: translateY(0); }
}

.photograph button {
    display: block;
    padding: 0;
    border: 0;
    background: transparent;
    width: 100%;
    cursor: zoom-in;
    color: inherit;
}

.photograph img {
    --thumbnail-ratio: 1;
    display: block;
    /* Scale with the column: landscapes fill it, all orientations share a height. */
    width: calc(100% * var(--thumbnail-ratio) / 1.5);
    height: auto;
    aspect-ratio: var(--thumbnail-ratio);
    margin-inline: auto;
    object-fit: cover;
    object-position: center;
}

.photograph img[data-orientation="landscape"] { --thumbnail-ratio: 1.5; }
.photograph img[data-orientation="portrait"] { --thumbnail-ratio: 0.6666666667; }

/* Default gallery layout: portraits fill one column across two landscape rows. */
.photography-page main,
body.arranging main { container-type: inline-size; }

.photographs {
    --gallery-columns: 3;
    --gallery-gap: 20px;
    --gallery-row-height: calc((100cqw - (var(--gallery-columns) - 1) * var(--gallery-gap)) / var(--gallery-columns) / 1.5);
    grid-auto-rows: var(--gallery-row-height);
    align-items: stretch;
}

.photograph { min-height: 0; }
.photograph:has(img[data-orientation="portrait"]) { grid-row: span 2; }
.photograph > button { height: 100%; }
.photograph img {
    width: 100%;
    height: 100%;
    aspect-ratio: auto;
}
.photograph img[data-orientation="square"] {
    width: var(--gallery-row-height);
    max-width: 100%;
}

@media (max-width: 720px) {
    .photographs { --gallery-columns: 2; --gallery-gap: 12px; }
}

body.viewer-open { overflow: hidden; }

.photo-viewer {
    position: fixed;
    inset: 0;
    width: 100%;
    max-width: none;
    height: 100%;
    height: 100dvh;
    max-height: none;
    margin: 0;
    padding: 52px 32px 64px;
    border: 0;
    background: #000;
    color: #e8e8e8;
}

.photo-viewer[open] {
    display: flex;
    flex-direction: column;
    gap: 16px;
}

.photo-viewer::backdrop { background: #000; }
.photo-viewer { overscroll-behavior: contain; touch-action: pan-x pan-y; }
.photo-viewer.is-closing::backdrop { animation: viewer-dismiss-backdrop 240ms ease-out forwards; }
@keyframes viewer-dismiss-backdrop { to { opacity: 0; } }

.viewer-toolbar {
    transition: opacity 0.24s ease;
    position: absolute;
    left: 20px;
    right: 20px;
    display: flex;
    justify-content: space-between;
    pointer-events: none;
}

.viewer-toolbar { top: 8px; justify-content: flex-end; }
.controls-hidden .viewer-toolbar { opacity: 0; }
.photo-viewer.controls-hidden,
.photo-viewer.controls-hidden button { cursor: none; }

.photo-viewer button {
    pointer-events: auto;
    min-width: 44px;
    background: transparent;
    border: 0;
    padding: 10px 8px;
    min-height: 44px;
    color: #ddd;
    font: 1.5rem / 1 sans-serif;
    cursor: pointer;
}

.photo-viewer button:hover { color: #fff; }
.photo-viewer button:disabled { opacity: 0.3; cursor: default; }
#viewer-close span { font-size: 1.3rem; }
#viewer-info { color: rgba(255, 255, 255, 0.3); }
#viewer-info:hover,
#viewer-info:focus-visible,
#viewer-info[aria-expanded="true"] { color: #aaa; }
#viewer-info span {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 15px;
    height: 15px;
    border: 1px solid currentColor;
    border-radius: 50%;
    font: 12px / 1 Georgia, serif;
}
.viewer-toolbar { z-index: 1; }


.viewer-figure {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 16px;
    flex: 1 1 0;
    min-height: 0;
    margin: 0;
}

.viewer-figure img {
    display: block;
    min-height: 0;
    width: 100%;
    flex: 1 1 0;
    object-fit: contain;
    touch-action: pan-x pan-y;
    user-select: none;
    -webkit-user-drag: none;
}

.viewer-figure figcaption {
    flex: 0 1 auto;
    max-height: 20vh;
    overflow: auto;
    max-width: 800px;
    color: #aaa;
    font-size: 0.85rem;
    text-align: center;
    white-space: pre-wrap;
    overflow-wrap: anywhere;
}

.viewer-figure figcaption:empty { display: none; }
#viewer-error { text-align: center; color: #aaa; font-size: 0.85rem; }

@media (max-width: 720px) {
    .photography-page .navbar { padding-inline: 16px; }
    .photography-page main { padding: 24px 16px 48px; }
    .photography-heading { margin-bottom: 20px; }
    .photographs { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; }
    .photo-viewer { padding: 52px 16px 64px; }
}

@media (prefers-reduced-motion: reduce) {
    .photography-page,
    .photography-heading,
    .photograph.is-ready.in-view,
    .photograph.opening-photo.is-ready.in-view { animation: none; }
    .photography-page::after { display: none; }
    .photograph { opacity: 1 !important; }
    .viewer-toolbar { transition: none; }
}
