/* ───────────────── Tokens ───────────────── */
:root {
  --bg: #ffffff;
  --fg: #1a1a1a;
  --muted: #8a8a8a;
  --line: #e9e9e9;
  --gutter: clamp(16px, 4.2vw, 70px);   /* page side margin + grid gap */
  --gap: clamp(14px, 4.2vw, 70px);
  --mono: "IBM Plex Mono", ui-monospace, SFMono-Regular, Menlo, monospace;
  --display: "Barlow Condensed", "Helvetica Neue", Arial, sans-serif;
  --ease: cubic-bezier(.2, .7, .1, 1);
  color-scheme: light;
}

*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
/* No "swipe between pages" (Mac trackpad, Safari/Chrome): two-finger swipes are
   for changing photo, and the page never scrolls sideways anyway. */
html, body, .lightbox { overscroll-behavior-x: none; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--fg);
  font: 400 14px/1.6 var(--mono);
  -webkit-font-smoothing: antialiased;
}
a { color: inherit; text-decoration: none; }
button { font: inherit; color: inherit; background: none; border: 0; padding: 0; cursor: pointer; }
.muted { color: var(--muted); }
[hidden] { display: none !important; }
:focus-visible { outline: 1px solid var(--fg); outline-offset: 4px; }

/* ───────────────── Header ───────────────── */
.site-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
  padding: clamp(24px, 4vw, 52px) var(--gutter) clamp(28px, 4.5vw, 64px);
}
.brand {
  font: 300 clamp(20px, 2vw, 25px)/1 var(--display);
  letter-spacing: .02em;
  text-transform: uppercase;
  color: var(--muted);
  transition: color .3s;
}
.brand:hover { color: var(--fg); }

.nav { display: flex; align-items: center; gap: clamp(20px, 5vw, 84px); }
#filters { display: contents; list-style: none; }
.nav-link {
  position: relative;
  font-size: 13.5px;
  letter-spacing: .01em;
  color: #444;
  transition: color .25s;
}
.nav-link::after {               /* hairline underline on active/hover */
  content: "";
  position: absolute; left: 0; right: 0; bottom: -3px;
  height: 1px; background: currentColor;
  transform: scaleX(0); transform-origin: left;
  transition: transform .35s var(--ease);
}
.nav-link:hover::after, .nav-link[aria-current="true"]::after { transform: scaleX(1); }
.nav-link[aria-current="true"] { color: var(--fg); }
.icon-link { display: inline-flex; color: var(--fg); margin-left: clamp(0px, 2vw, 32px); }

@media (max-width: 640px) {
  /* Same layout as desktop: name left, links right (they wrap, right-aligned, if many) */
  .site-header { align-items: center; gap: 16px; }
  .nav { gap: 8px 20px; flex-wrap: wrap; justify-content: flex-end; }
  .icon-link { margin-left: 0; }
}

/* ───────────────── Grid (masonry) ─────────────────
   JS splits photos into N columns, always adding the next photo to the
   shortest column, so reading order stays left→right like a feed.        */
main { padding: 0 var(--gutter); }
.grid { display: flex; align-items: flex-start; gap: var(--gap); }
.col { flex: 1 1 0; min-width: 0; display: flex; flex-direction: column; gap: var(--gap); }

.tile {
  display: block;
  width: 100%;
  position: relative;
  overflow: hidden;
  cursor: zoom-in;
  opacity: 0;
  transform: translateY(14px);
  animation: rise .9s var(--ease) forwards;
}
/* While the photo loads: its 24px preview, softly blurred (not blown-up pixels) */
.tile::before {
  content: ""; position: absolute; inset: 0;
  background: var(--ph) center / cover no-repeat;
  filter: blur(14px); transform: scale(1.12);
}
.tile img {
  position: relative;
  display: block;
  width: 100%;
  height: 100%;
  object-fit: cover;
  opacity: 0;
  transition: opacity .6s ease, transform 1.2s var(--ease);
}
.tile img.loaded { opacity: 1; }
.tile:hover img { transform: scale(1.015); }
@keyframes rise { to { opacity: 1; transform: none; } }

.empty { color: var(--muted); padding: 10vh 0; text-align: center; width: 100%; }

.site-footer {
  padding: clamp(60px, 10vw, 140px) var(--gutter) 40px;
  font-size: 12px;
  color: var(--muted);
}

/* ───────────────── Lightbox ───────────────── */
.lightbox {
  width: 100vw; height: 100dvh;
  max-width: none; max-height: none;
  margin: 0; padding: 0; border: 0;
  background: var(--bg);
  color: var(--fg);
  overflow: hidden;
}
.lightbox[open] { display: grid; grid-template-rows: auto 1fr; animation: fade .35s ease; }
.lightbox::backdrop { background: var(--bg); }
@keyframes fade { from { opacity: 0; } }

.lb-top {
  display: flex; justify-content: space-between; align-items: center;
  padding: 20px var(--gutter);
  font-size: 12.5px;
}
.lb-counter { color: var(--muted); font-variant-numeric: tabular-nums; }
.lb-btn { color: var(--fg); }
.lb-btn:hover { text-decoration: underline; text-underline-offset: 4px; }

.lb-figure {
  margin: 0;
  min-height: 0;
  display: grid;
  grid-template-rows: 1fr auto;
  padding: 0 var(--gutter) clamp(20px, 3vw, 36px);
  gap: clamp(16px, 2.2vw, 28px);
}
.lb-stage {
  position: relative;
  min-height: 0;
  display: grid;
  place-items: center;
  touch-action: none;             /* gestures (swipe, pinch, pan) handled in JS */
  container-type: size;           /* lets the photo size itself to this box */
  overflow: hidden;
  outline: none;
}
#lb-img {
  /* Fill the stage whatever the file's pixel size (a 2048px file on a 4K screen
     would otherwise stay small): as wide as possible within width and height. */
  width: min(100cqw, calc(100cqh * var(--ar, 1.5)));
  height: auto;
  aspect-ratio: var(--ar, 1.5);
  max-width: 100cqw;
  max-height: 100cqh;
  object-fit: contain;
  background-size: cover;
  user-select: none;
  -webkit-user-drag: none;
  transition: opacity .25s ease;
  transform-origin: 50% 50%;
  will-change: transform;
}
#lb-img.swapping { opacity: 0; }

/* Narrow edge strips act as prev/next (the photo itself opens full screen); arrows on hover */
.lb-nav {
  position: absolute; top: 0; bottom: 0; width: clamp(56px, 14%, 140px); z-index: 2;
  display: flex; align-items: center;
  font-size: 18px; color: var(--fg);
  opacity: 0; transition: opacity .3s;
}
.lb-prev { left: 0; justify-content: flex-start; cursor: w-resize; }
.lb-next { right: 0; justify-content: flex-end; cursor: e-resize; }
.lb-nav span { padding: 12px; background: rgb(255 255 255 / .8); }
.lb-stage:hover .lb-nav, .lb-nav:focus-visible { opacity: 1; }
.lb-nav[disabled] { visibility: hidden; }
@media (hover: none) { .lb-nav { display: none; } }  /* swipe on touch */

/* Details under the photo */
.lb-details {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 6px 40px;
  align-items: start;
  max-width: 1200px;
  width: 100%;
  margin: 0 auto;
  border-top: 1px solid var(--line);
  padding-top: 14px;
  font-size: 12.5px;
}
.lb-heading { display: flex; flex-wrap: wrap; align-items: baseline; gap: 4px 14px; }
.lb-heading h2 {
  margin: 0;
  font: 400 22px/1.1 var(--display);
  letter-spacing: .01em;
}
.lb-heading p { margin: 0; }
.lb-desc { grid-column: 1; margin: 2px 0 0; color: #555; max-width: 60ch; }
.lb-desc:empty { display: none; }

.lb-specs {
  grid-column: 2; grid-row: 1 / span 2;
  margin: 0;
  display: flex; flex-wrap: wrap; justify-content: flex-end;
  gap: 4px 22px;
  text-align: right;
}
.lb-specs div { display: flex; flex-direction: column; }
.lb-specs dt { font-size: 10.5px; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); }
.lb-specs dd { margin: 0; white-space: nowrap; }

@media (max-width: 760px) {
  .lb-details { grid-template-columns: 1fr; }
  .lb-specs { grid-column: 1; grid-row: auto; justify-content: flex-start; text-align: left; margin-top: 8px; gap: 8px 20px; }
}

/* Zoom from thumbnail → lightbox (View Transitions API, where supported) */
::view-transition-group(hero) { animation-duration: .45s; animation-timing-function: var(--ease); }
::view-transition-old(root), ::view-transition-new(root) { animation-duration: .3s; }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after, ::view-transition-group(*) { animation: none !important; transition: none !important; }
  .tile { opacity: 1; transform: none; }
}

/* Place → map link */
.place-link { color: inherit; text-decoration: underline; text-decoration-color: var(--line);
  text-underline-offset: 3px; transition: text-decoration-color .2s, color .2s; }
.place-link:hover { color: var(--fg); text-decoration-color: currentColor; }
.place-link::after { content: " ↗"; font-size: .85em; }

/* ───────────────── Immersive (full screen) ─────────────────
   White like the site, details hidden, the photo as large as possible
   with a thin white border around it. */
.lightbox.immersive .lb-top,
.lightbox.immersive .lb-details { display: none; }
.lightbox.immersive { grid-template-rows: 1fr; }
.lightbox.immersive .lb-figure {
  padding: clamp(8px, 1.5vw, 18px); gap: 0; grid-template-rows: 1fr; height: 100dvh;
  padding-top: max(clamp(8px, 1.5vw, 18px), env(safe-area-inset-top));
  padding-bottom: max(clamp(8px, 1.5vw, 18px), env(safe-area-inset-bottom));
}
.lightbox.immersive.zoomed .lb-stage { cursor: grab; }
.lightbox.immersive.zoomed .lb-stage:active { cursor: grabbing; }
.lightbox.zoomed .lb-nav { display: none; }

.lb-hint {
  position: absolute; left: 50%; bottom: 18px; transform: translateX(-50%);
  margin: 0; padding: 7px 14px; font-size: 12px; text-align: center;
  width: max-content; max-width: calc(100% - 32px); line-height: 1.4;
  background: rgb(255 255 255 / .88); color: var(--fg); border-radius: 999px;
  border: 1px solid var(--line); box-shadow: 0 2px 10px rgb(0 0 0 / .08);
  opacity: 0; pointer-events: none; transition: opacity .4s ease; z-index: 3;
}
.lb-hint.show { opacity: 1; }

/* Real fullscreen (where the browser allows it): the stage alone, white, thin border */
.lb-stage:fullscreen { background: var(--bg); width: 100vw; height: 100vh; box-sizing: border-box;
  padding: clamp(8px, 1.5vw, 18px); container-type: size; }
.lb-stage::backdrop { background: var(--bg); }

/* Desktop: magnifier only over the photo (outside it the stage shows ← / → cursors) */
#lb-img { cursor: zoom-in; }
.lightbox.zoomed #lb-img { cursor: grab; }
.lightbox.zoomed .lb-stage:active #lb-img { cursor: grabbing; }
.lightbox.immersive .lb-stage { cursor: default; }
/* Prev/next strips: clicking outside the photo does it now; keep them for keyboard focus only */
@media (hover: hover) {
  .lb-nav { pointer-events: none; opacity: 0 !important; }
  .lb-nav:focus-visible { opacity: 1 !important; }
}

/* Close button in full screen (top right, also inside real fullscreen) */
.lb-fs-close {
  position: absolute; top: max(12px, env(safe-area-inset-top)); right: 12px; z-index: 4;
  display: none; padding: 6px 12px; font: inherit; font-size: 12.5px; cursor: pointer;
  background: rgb(255 255 255 / .88); color: var(--fg);
  border: 1px solid var(--line); border-radius: 999px; box-shadow: 0 2px 10px rgb(0 0 0 / .08);
}
.lb-fs-close:hover { background: #fff; }
.lightbox.immersive .lb-fs-close { display: block; }
/* Desktop full screen: magnifier "−" on a zoomed photo (click = back to fit) */
@media (hover: hover) {
  .lightbox.immersive.zoomed #lb-img { cursor: zoom-out; }
  .lightbox.immersive.zoomed .lb-stage:active #lb-img { cursor: grabbing; }
}

/* The full-screen hint only exists in full screen */
.lightbox:not(.immersive) .lb-hint { display: none; }

/* Counter in full screen (top left, mirrors the Close button) */
.lb-fs-counter {
  position: absolute; top: max(12px, env(safe-area-inset-top)); left: 12px; z-index: 4;
  display: none; padding: 6px 12px; font-size: 12.5px; font-variant-numeric: tabular-nums;
  background: rgb(255 255 255 / .88); color: var(--muted);
  border: 1px solid var(--line); border-radius: 999px; box-shadow: 0 2px 10px rgb(0 0 0 / .08);
  pointer-events: none;
}
.lightbox.immersive .lb-fs-counter { display: block; }

.lb-actions { display: inline-flex; gap: 22px; }

/* Category menu for phones: the inline links don't fit next to Map / Contact */
.cat-menu { position: relative; display: none; }
.cat-toggle { font: inherit; font-size: 13.5px; background: none; border: 0; padding: 0; cursor: pointer; color: var(--fg); }
.cat-toggle::after { content: " ▾"; font-size: .85em; color: var(--muted); }
.cat-toggle[aria-expanded="true"]::after { content: " ▴"; }
.cat-pop {
  position: absolute; right: -12px; top: calc(100% + 10px); z-index: 20; min-width: 150px;
  list-style: none; margin: 0; padding: 6px 0; background: var(--bg);
  border: 1px solid var(--line); box-shadow: 0 10px 30px rgb(0 0 0 / .08);
}
.cat-pop .nav-link { display: block; padding: 9px 16px; }
.cat-pop .nav-link::after { display: none; }
.cat-pop .nav-link[aria-current="true"] { font-weight: 600; }
@media (max-width: 640px) {
  #filters { display: none !important; }
  .cat-menu:not([hidden]) { display: block; }
}

/* ───────────────── Album pages (/album/<key>/) ───────────────── */
.album-intro { padding: 0 var(--gutter) clamp(28px, 4vw, 56px); max-width: 900px; }
.album-title { font: 300 clamp(34px, 5vw, 60px)/1.02 var(--display); text-transform: uppercase; letter-spacing: .01em; margin: 0 0 14px; }
.album-desc { margin: 0 0 10px; max-width: 60ch; color: #444; white-space: pre-line; }
.album-desc:empty { display: none; }
.album-count { margin: 0; font-size: 12.5px; }
.album-cta { display: flex; flex-direction: column; align-items: center; gap: 14px; padding: clamp(48px, 8vw, 110px) var(--gutter) 10px; text-align: center; }
.album-cta p { margin: 0; font-size: 13px; }
.cta {
  display: inline-flex; align-items: center; gap: 10px; padding: 14px 26px;
  border: 1px solid var(--fg); background: var(--fg); color: var(--bg);
  font-size: 13.5px; letter-spacing: .02em; transition: background .25s, color .25s;
}
.cta:hover { background: var(--bg); color: var(--fg); }
.cta span { transition: transform .3s var(--ease); }
.cta:hover span { transform: translateX(4px); }
.album-cta + .site-footer { padding-top: 56px; text-align: center; }
