:root {
  --paper: #fbfaf8;
  --ink: #1b1a18;
  --muted: #8d867e;
  --rule: #e6e2dc;
  --gap: 10px;
  /* Space above and below the closing note. One value, used on both sides, so
     the two can never drift apart. */
  --endspace: clamp(44px, 8vh, 96px);
  --pad: clamp(16px, 4vw, 56px);
  --serif: "Cormorant Garamond", Garamond, Georgia, "Times New Roman", serif;
  --sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

* { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font-family: var(--sans);
  padding: 0 var(--pad);
  padding-top: env(safe-area-inset-top, 0px);
  /* Matches the note's padding above, and stands in for it when there is none. */
  padding-bottom: calc(var(--endspace) + env(safe-area-inset-bottom, 0px));
}

img { max-width: 100%; display: block; }
[hidden] { display: none !important; }

/* ---------- masthead ---------- */

.masthead {
  text-align: center;
  padding: clamp(56px, 12vh, 140px) 0 clamp(40px, 8vh, 88px);
}

/* With no title above it the subtitle is the whole masthead, and the deep band
   of space that set off a large serif name reads as a gap rather than as poise.
   A single small line wants about half that, so the photographs start sooner. */
.masthead-bare {
  padding: clamp(24px, 4.2vh, 48px) 0 clamp(20px, 3.4vh, 40px);
}

.masthead-bare .subtitle {
  margin: 0;
}

/* The caption is prose, not a label, so it drops the uppercase letterspacing
   that suits two words and reads as a line of text. Held to a narrow measure
   so it never stretches into a banner across a wide screen. */
.caption {
  margin: 0 auto;
  /* Wide enough that the sentence sits on one line on a desktop, while a phone
     still wraps it naturally rather than running it to the screen edges. */
  max-width: min(100%, 34em);
  font-family: var(--serif);
  font-style: italic;
  font-weight: 300;
  /* Small enough to read as an aside rather than a headline. Garamond has a
     short x-height, so it sets smaller than the figure suggests. */
  font-size: clamp(1rem, 1.5vw, 1.25rem);
  line-height: 1.6;
  letter-spacing: 0.015em;
  /* Softened well below the ink, but held at ~5:1 on the paper: it is the only
     prose on the page, so it has to stay comfortably readable. */
  color: #736b62;
}

.caption span {
  display: inline-block;
}

/* Set well clear of the final row so it reads as a closing note rather than a
   caption belonging to the last photograph. The body supplies the space below. */
.endnote {
  padding-top: var(--endspace);
  text-align: center;
}

.subtitle + .caption {
  margin-top: 0.85em;
}

.masthead h1 {
  font-family: var(--serif);
  font-weight: 300;
  font-size: clamp(2.4rem, 7vw, 4.5rem);
  line-height: 1.05;
  letter-spacing: 0.01em;
  margin: 0;
}

.subtitle {
  margin: 1.1em 0 0;
  font-size: 0.72rem;
  letter-spacing: 0.22em;
  text-transform: uppercase;
  color: var(--muted);
}

/* ---------- grid ---------- */

.grid {
  display: flex;
  flex-direction: column;
  gap: var(--gap);
  margin: 0 auto;
  max-width: 1800px;
}

.row {
  display: flex;
  gap: var(--gap);
}

.tile {
  position: relative;
  display: block;
  padding: 0;
  border: 0;
  cursor: zoom-in;
  overflow: hidden;
  background-color: var(--rule);
  background-size: cover;
  background-position: center;
  -webkit-tap-highlight-color: transparent;
}

.tile img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  opacity: 0;
  transition: opacity 0.6s ease;
}

.tile img.loaded { opacity: 1; }

/* A restrained hover: the photograph lifts slightly out of the paper. */
@media (hover: hover) and (pointer: fine) {
  .tile img { transition: opacity 0.6s ease, transform 0.9s cubic-bezier(.2,.7,.2,1); }
  .tile:hover img.loaded { transform: scale(1.025); }
}

.tile:focus-visible {
  outline: 2px solid var(--ink);
  outline-offset: 3px;
}

.empty {
  text-align: center;
  color: var(--muted);
  font-size: 0.85rem;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  padding: 18vh 0;
}

/* ---------- viewer ---------- */

.viewer {
  position: fixed;
  inset: 0;
  /* dvh tracks the mobile address bar as it slides away, so a photo fitted to
     the screen is never cropped by chrome that appears afterwards. */
  height: 100vh;
  height: 100dvh;
  z-index: 100;
  background: #0d0d0c;
  opacity: 0;
  transition: opacity 0.28s ease;
  overscroll-behavior: contain;
}

.viewer.open { opacity: 1; }

.viewer-stage {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  overflow: hidden;
  touch-action: none;
}

/* Width and height are set in script from each photo's true dimensions, so the
   frame is identical whichever rendition is loaded. No intrinsic sizing here. */
.viewer-img {
  display: block;
  max-width: none;
  max-height: none;
  user-select: none;
  -webkit-user-drag: none;
  transform-origin: 0 0;
}

.viewer-img.swapping { filter: blur(0); }

.viewer-spinner {
  position: absolute;
  width: 22px; height: 22px;
  border: 1.5px solid rgba(255,255,255,0.25);
  border-top-color: rgba(255,255,255,0.85);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

@keyframes spin { to { transform: rotate(360deg); } }

.viewer-chrome {
  position: absolute;
  inset: 0;
  pointer-events: none;
  opacity: 1;
  transition: opacity 0.3s ease;
}

.viewer-chrome.hidden { opacity: 0; }

.viewer-bar {
  position: absolute;
  left: 0; right: 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px clamp(12px, 3vw, 26px);
  color: rgba(255,255,255,0.72);
  font-size: 0.68rem;
  letter-spacing: 0.18em;
  text-transform: uppercase;
}

.viewer-bar-top {
  top: 0;
  padding-top: calc(14px + env(safe-area-inset-top, 0px));
  background: linear-gradient(to bottom, rgba(0,0,0,0.42), transparent);
}

.viewer-bar-bottom {
  bottom: 0;
  justify-content: center;
  padding-bottom: calc(14px + env(safe-area-inset-bottom, 0px));
}

.bar-actions { display: flex; gap: 4px; }

.iconbtn {
  pointer-events: auto;
  appearance: none;
  background: none;
  border: 0;
  padding: 9px;
  cursor: pointer;
  color: rgba(255,255,255,0.72);
  display: grid;
  place-items: center;
  border-radius: 50%;
  transition: color 0.2s ease, background-color 0.2s ease;
  -webkit-tap-highlight-color: transparent;
}

.iconbtn svg { width: 19px; height: 19px; fill: none; stroke: currentColor; stroke-width: 1.4; stroke-linecap: round; stroke-linejoin: round; }

.iconbtn:hover, .iconbtn:focus-visible { color: #fff; background: rgba(255,255,255,0.1); outline: none; }

.navbtn {
  pointer-events: auto;
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
  appearance: none;
  background: none;
  border: 0;
  cursor: pointer;
  color: rgba(255,255,255,0.6);
  padding: 22px 16px;
  transition: color 0.2s ease;
  -webkit-tap-highlight-color: transparent;
}

.navbtn svg { width: 26px; height: 26px; fill: none; stroke: currentColor; stroke-width: 1.2; stroke-linecap: round; stroke-linejoin: round; }
.navbtn:hover, .navbtn:focus-visible { color: #fff; outline: none; }
.navbtn[disabled] { opacity: 0.18; cursor: default; }
.navbtn-prev { left: max(2px, env(safe-area-inset-left, 0px)); }
.navbtn-next { right: max(2px, env(safe-area-inset-right, 0px)); }

.counter { font-variant-numeric: tabular-nums; }

.hint {
  color: rgba(255,255,255,0.45);
  font-size: 0.62rem;
  letter-spacing: 0.16em;
  transition: opacity 0.4s ease;
}

/* Touch devices get no hover affordances, so the side arrows would only
   cover the photograph — the swipe gesture replaces them. */
@media (hover: none) {
  .navbtn { display: none; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    transition-duration: 0.01ms !important;
  }
}
