/* ---------------------------------------------------------------
   James Fassbender — Photography
   Paper-white gallery, warm ink, generous margins. No dependencies.
   --------------------------------------------------------------- */

:root {
  --paper:      #faf9f6;
  --paper-sunk: #f2f0eb;
  --ink:        #1a1815;
  --ink-soft:   #57524a;
  --ink-faint:  #8d867b;
  --rule:       #e0dcd3;
  --accent:     #9a5b32;

  --serif: "Iowan Old Style", "Palatino Linotype", Palatino, "Book Antiqua", Georgia, serif;
  --sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Inter, Roboto, "Helvetica Neue", Arial, sans-serif;

  --gap: 12px;
  --edge: clamp(1.25rem, 4vw, 3.5rem);
  --measure: 1680px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --paper:      #12110f;
    --paper-sunk: #1b1a17;
    --ink:        #eae7e0;
    --ink-soft:   #a8a299;
    --ink-faint:  #736d64;
    --rule:       #2b2925;
    --accent:     #cf9a6c;
  }
}

*, *::before, *::after { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font-family: var(--sans);
  font-size: 16px;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

a { color: inherit; text-decoration-color: var(--rule); text-underline-offset: 3px; }
a:hover { text-decoration-color: var(--accent); }

.wrap {
  max-width: var(--measure);
  margin-inline: auto;
  padding-inline: var(--edge);
}

.skip {
  position: absolute;
  left: -9999px;
}
.skip:focus {
  left: var(--edge); top: 1rem;
  z-index: 100;
  background: var(--ink); color: var(--paper);
  padding: .6rem 1rem; border-radius: 3px;
}

/* ---------- masthead ---------- */

.masthead {
  padding-block: clamp(3.5rem, 9vh, 7rem) clamp(2.5rem, 6vh, 4.5rem);
}

.wordmark {
  margin: 0;
  font-family: var(--serif);
  font-weight: 400;
  font-size: clamp(2.1rem, 6.2vw, 4.1rem);
  line-height: 1;
  letter-spacing: -0.02em;
}

.tagline {
  margin: clamp(.9rem, 2vw, 1.4rem) 0 0;
  max-width: 34ch;
  color: var(--ink-soft);
  font-size: clamp(.95rem, 1.4vw, 1.075rem);
  font-style: italic;
  font-family: var(--serif);
}

/* ---------- gallery ---------- */

/* Row gap is larger than the column gap: the caption sits under each
   photograph, and needs air beneath it before the next row begins. */
.gallery { display: flex; flex-direction: column; gap: clamp(28px, 3vw, 42px); }

/* Full rows fill the width exactly, so centring only affects rows that the
   layout deliberately capped (a short final row, or one clipped to the
   viewport height) — those sit centred instead of stranded on the left. */
.gallery-row {
  display: flex;
  gap: var(--gap);
  justify-content: center;
  align-items: flex-start;
}

.tile {
  margin: 0;
  cursor: zoom-in;
  /* width is written by gallery.js; height comes from frame + caption */
}

/* The frame holds the photograph at its exact aspect ratio. The caption is a
   sibling below it, never an overlay. */
.tile-frame {
  position: relative;
  overflow: hidden;
  background: var(--tile-bg, var(--paper-sunk));
  border-radius: 2px;
}

/* `contain`, never `cover`. The layout already sizes every frame to the
   photograph's exact aspect ratio, so this changes nothing visually — it is a
   guarantee that no rounding error anywhere can ever crop an edge. */
.tile-frame img {
  display: block;
  width: 100%; height: 100%;
  object-fit: contain;
  opacity: 0;
  transition: opacity .7s ease;
}
.tile-frame img.is-loaded { opacity: 1; }

/* Blur-up placeholder: the 20px LQIP from the manifest, scaled up behind. */
.tile-frame::before {
  content: "";
  position: absolute; inset: -6%;
  background-image: var(--lqip);
  background-size: cover;
  background-position: center;
  filter: blur(14px) saturate(1.15);
  transform: scale(1.04);
  transition: opacity .6s ease .05s;
}
.tile-frame.is-ready::before { opacity: 0; }

/* ---- caption ----------------------------------------------------------
   These numbers are load-bearing: 10 + 18 + 15 = 43px, which is CAP_H in
   gallery.js. The layout reserves exactly that much under every photograph,
   so both lines must stay single-line and fixed in px. Change one, change
   the other, or rows will go ragged.
   --------------------------------------------------------------------- */
.tile-cap {
  padding-top: 10px;
  min-width: 0;
}
.cap-date, .cap-meta {
  display: block;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.cap-date {
  font-family: var(--serif);
  font-size: 13px;
  line-height: 18px;
  color: var(--ink);
}
.cap-meta {
  font-size: 10.5px;
  line-height: 15px;
  letter-spacing: .085em;
  text-transform: uppercase;
  color: var(--ink-faint);
}

@media (hover: hover) {
  .tile-frame { transition: transform .4s cubic-bezier(.2,.7,.2,1), box-shadow .4s ease; }
  .tile:hover .tile-frame {
    transform: translateY(-3px);
    box-shadow: 0 12px 28px rgba(0,0,0,.16);
  }
  .tile:hover .cap-date { color: var(--accent); }
}

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

.noscript {
  color: var(--ink-soft);
  max-width: 46ch;
  font-family: var(--serif);
  font-style: italic;
}

/* ---------- colophon ---------- */

.colophon {
  padding-block: clamp(3.5rem, 9vh, 6.5rem) clamp(2.5rem, 6vh, 4rem);
  color: var(--ink-soft);
  font-size: .9rem;
}
.colophon p { margin: .35rem 0; }
.rule {
  height: 1px;
  background: var(--rule);
  margin: 0 0 1.75rem !important;
}
.fine { color: var(--ink-faint); font-size: .82rem; }

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

.lightbox {
  position: fixed; inset: 0;
  /* dvh, not vh: on phones `100vh` (and `inset:0`) resolve against the *large*
     viewport, so a tall photograph sized to it hides behind the browser chrome.
     The vh line is the fallback for engines without dvh. */
  height: 100vh;
  height: 100dvh;
  overflow: hidden;
  z-index: 50;
  background: color-mix(in srgb, var(--paper) 92%, #000);
  -webkit-backdrop-filter: blur(22px);
  backdrop-filter: blur(22px);
  opacity: 0;
  transition: opacity .28s ease;
}
.lightbox[hidden] { display: none; }
.lightbox.is-open { opacity: 1; }

@supports not (background: color-mix(in srgb, red, blue)) {
  .lightbox { background: rgba(10,10,9,.94); }
}

/* Absolutely positioned against the fixed lightbox, so its content box is a
   definite size with no percentage chain to resolve. */
.lb-stage {
  position: absolute;
  inset: 0;
  padding: clamp(1rem, 4vw, 3rem) clamp(1rem, 7vw, 5.5rem) clamp(5.5rem, 12vh, 7rem);
  display: flex;
  align-items: center;
  justify-content: center;
  touch-action: pan-y;
}

/* The image box fills the stage's content box exactly, and `contain` fits the
   photograph inside it. This is the guarantee: the box can never be smaller
   than the photograph needs, so no edge can ever be clipped — least of all on
   a portrait, which is the orientation that runs out of height first.
   No shadow or background here: they would frame the *box*, not the photo,
   drawing bars beside a portrait. */
.lb-img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: contain;
  object-position: center;
  opacity: 0;
  transform: scale(.985);
  transition: opacity .3s ease, transform .3s cubic-bezier(.2,.7,.2,1);
}
.lb-img.is-shown { opacity: 1; transform: none; }
/* The bridging image is the grid's own cached copy, so it is shown as-is —
   blurring it would make it look worse than it is. It sharpens on swap. */
.lb-img.is-provisional { filter: none; }

.lb-caption {
  position: absolute;
  left: 0; right: 0; bottom: 0;
  padding: 1rem clamp(1rem, 5vw, 2.5rem) clamp(1.1rem, 3vh, 1.9rem);
  text-align: center;
  pointer-events: none;
}
.lb-title {
  margin: 0;
  font-family: var(--serif);
  font-weight: 400;
  font-size: clamp(1.05rem, 2.2vw, 1.45rem);
  letter-spacing: -0.005em;
}
.lb-meta {
  margin: .3rem 0 0;
  color: var(--ink-soft);
  font-size: .78rem;
  letter-spacing: .07em;
  text-transform: uppercase;
}

.lb-count {
  position: absolute;
  top: clamp(1rem, 3vh, 1.75rem);
  left: clamp(1rem, 5vw, 2.5rem);
  margin: 0;
  color: var(--ink-faint);
  font-size: .78rem;
  letter-spacing: .12em;
  font-variant-numeric: tabular-nums;
}

.lb-btn {
  position: absolute;
  display: grid; place-items: center;
  width: 46px; height: 46px;
  padding: 0;
  border: 0; border-radius: 50%;
  background: transparent;
  color: var(--ink-soft);
  cursor: pointer;
  transition: color .2s ease, background .2s ease, opacity .2s ease;
}
.lb-btn svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 1.5; }
.lb-btn:hover { color: var(--ink); background: color-mix(in srgb, var(--ink) 10%, transparent); }
.lb-btn:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.lb-btn[disabled] { opacity: .22; cursor: default; }

.lb-close { top: clamp(.5rem, 2vh, 1.4rem); right: clamp(.5rem, 3vw, 1.4rem); }
.lb-prev  { left:  clamp(.25rem, 1.5vw, 1.25rem); top: 50%; transform: translateY(-50%); }
.lb-next  { right: clamp(.25rem, 1.5vw, 1.25rem); top: 50%; transform: translateY(-50%); }

body.is-locked { overflow: hidden; }

@media (max-width: 600px) {
  .lb-prev, .lb-next { top: auto; bottom: .35rem; transform: none; }
  .lb-prev { left: 25%; }
  .lb-next { right: 25%; }
  .lb-caption { padding-bottom: 3.6rem; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: .01ms !important;
    transition-duration: .01ms !important;
  }
  .tile:hover .tile-frame { transform: none; }
}

@media print {
  .lightbox, .skip { display: none !important; }
}
