:root {
  --bg: #ffffff;
  --ink: #111111;
  --ink-soft: #6e6e6e;
  --gutter: 24px;
  --gap: var(--gap-desktop, 48px);
  --max: 1440px;
  --header-h: 88px;
  --ease: cubic-bezier(0.22, 1, 0.36, 1);
  --mono: "IBM Plex Mono", ui-monospace, "SF Mono", Menlo, monospace;
  --sans: -apple-system, BlinkMacSystemFont, "Inter", "Helvetica Neue", Helvetica, Arial, sans-serif;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--sans);
  font-size: 14px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}
body.no-scroll { overflow: hidden; }
a { color: inherit; text-decoration: none; }
img { display: block; max-width: 100%; }

/* Header ------------------------------------------------------- */
.site-header {
  height: var(--header-h);
  display: flex;
  align-items: center;
  padding: 0 var(--gutter);
  max-width: var(--max);
  margin: 0 auto;
}
.wordmark {
  font-family: var(--mono);
  font-size: 15px;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  font-weight: 400;
}

/* Feed --------------------------------------------------------- */
main { padding: 8px 0 0; }
.feed {
  display: grid;
  grid-template-columns: repeat(var(--cols, 2), minmax(0, 1fr));
  gap: var(--gap);
  padding: 0 var(--gutter);
  max-width: var(--max);
  margin: 0 auto;
  align-items: start;
}
.col { display: flex; flex-direction: column; gap: var(--gap); min-width: 0; }

.tile {
  display: block;
  width: 100%;
  cursor: zoom-in;
  -webkit-tap-highlight-color: transparent;
  /* Off-screen tiles are skipped for rendering, so a long feed does not hold every decoded
     bitmap at once (Safari on iPhone is the one that suffers). The aspect-ratio set inline
     keeps each tile's height while it is skipped; the intrinsic size is only a fallback. */
  content-visibility: auto;
  contain-intrinsic-size: auto 300px;
}
.tile img { width: 100%; height: auto; }
.tile img, .lb-img {
  -webkit-touch-callout: none;   /* no long-press save sheet on iOS */
  -webkit-user-drag: none;
  user-select: none;
}
.tile img { pointer-events: none; }  /* the link takes the click; the image is not a right-click target */

/* Footer ------------------------------------------------------- */
.site-footer {
  max-width: var(--max);
  margin: 0 auto;
  padding: 96px var(--gutter) 40px;
  color: var(--ink-soft);
  font-family: var(--mono);
  font-size: 11px;
  letter-spacing: 0.08em;
}

/* Lightbox ----------------------------------------------------- */
.lightbox {
  position: fixed;
  inset: 0;
  z-index: 50;
  background: var(--bg);
  opacity: 0;
  transition: opacity 260ms var(--ease);
}
.lightbox.open { opacity: 1; }
.lightbox[hidden] { display: none; }

.lb-stage {
  position: absolute;
  inset: 0;
  margin: 0;
  /* The photo never touches the arrow zones: side padding is at least as wide as the arrow band. */
  padding: var(--lb-pad-y, 64px) var(--lb-pad-x, clamp(96px, 12vw, 180px));
  display: flex;
  align-items: center;
  justify-content: center;
  flex-direction: column;
  gap: 14px;
  pointer-events: none;
}
.lb-img {
  max-width: 100%;
  max-height: 100%;
  width: auto;
  height: auto;
  object-fit: contain;
  pointer-events: auto;
  opacity: 0;
  transition: opacity 320ms var(--ease);
  user-select: none;
  -webkit-user-drag: none;
}
.lb-img.ready { opacity: 1; }
.lb-caption {
  font-size: 13px;
  color: var(--ink-soft);
  text-align: center;
  max-width: 60ch;
  pointer-events: auto;
}

.lb-close,
.lb-zone {
  appearance: none;
  border: 0;
  background: transparent;
  -webkit-tap-highlight-color: transparent;  /* iOS paints the whole half-screen button grey on tap otherwise */
  touch-action: manipulation;
  color: var(--ink);
  padding: 0;
  margin: 0;
  cursor: pointer;
}
.lb-close {
  position: absolute;
  top: 22px;
  right: 22px;
  width: 44px;
  height: 44px;
  display: grid;
  place-items: center;
  z-index: 3;
  opacity: 0.55;
  transition: opacity 200ms var(--ease);
}
.lb-close:hover, .lb-close:focus-visible { opacity: 1; }

.lb-zone {
  position: absolute;
  top: 0;
  bottom: 0;
  width: 50%;
  display: flex;
  align-items: center;
  z-index: 2;
  color: var(--ink);
}
.lb-prev { left: 0; justify-content: flex-start; padding-left: 28px; cursor: default; }
.lb-next { right: 0; justify-content: flex-end; padding-right: 28px; cursor: default; }
.lb-zone svg {
  opacity: 0;
  transform: translateX(0);
  transition: opacity 320ms var(--ease), transform 320ms var(--ease);
}
.lb-prev svg { transform: translateX(6px); }
.lb-next svg { transform: translateX(-6px); }
@media (hover: hover) and (pointer: fine) {
  .lb-zone:hover svg, .lb-zone:focus-visible svg { opacity: 0.6; transform: translateX(0); }
}
/* Touch devices: no arrows at all, swipe does the work. */
@media (hover: none), (pointer: coarse) {
  .lb-zone svg { display: none; }
  .lb-zone { cursor: default; }
}

/* Responsive --------------------------------------------------- */
@media (max-width: 767px) {
  :root {
    --gutter: 0px;
    --gap: 6px;
    --header-h: 72px;
    --lb-pad-x: 0px;
    --lb-pad-y: 72px;
  }
  .site-header { padding: 0 20px; }
  .wordmark { font-size: 13px; }
  .feed { --cols: 1; }
  .site-footer { padding: 64px 20px 32px; }
  .lb-close { top: 14px; right: 14px; }
  /* No entrance animation on phones: a loaded photo appears the instant it scrolls in.
     (body[class] outranks the body.opt-entrance-* rules further down.) */
  body[class] .feed .tile { opacity: 1; transform: none; transition: none; }
}

@media (prefers-reduced-motion: reduce) {
  .tile, .lightbox, .lb-img, .lb-zone svg { transition: none; }
  .tile { transform: none; }
}

/* =====================================================================
   Options. Each block is one switchable behavior; body carries the class.
   ===================================================================== */

/* --- Placeholder while a photo loads --------------------------------- */
.tile { background-size: cover; background-position: center; }
body.opt-ph-gray  .tile { background-color: #f2f2f2; background-image: none; }
body.opt-ph-color .tile { background-color: var(--tile-color, #f2f2f2); background-image: none; }
body.opt-ph-blur  .tile { background-color: var(--tile-color, #f2f2f2); background-image: var(--tile-lqip); }

/* --- Entrance --------------------------------------------------------- */
body.opt-entrance-none   .tile { opacity: 1; transform: none; }
body.opt-entrance-fade   .tile { opacity: 0; transform: none; transition: opacity 1100ms var(--ease); }
body.opt-entrance-fadeup .tile { opacity: 0; transform: translateY(14px); transition: opacity 700ms var(--ease), transform 700ms var(--ease); }
body.opt-entrance-blurup .tile { opacity: 1; transform: none; }
body.opt-entrance-fade   .tile.in,
body.opt-entrance-fadeup .tile.in { opacity: 1; transform: none; }

/* Blur-up resolves the photo out of its own blurred preview. */
body.opt-entrance-blurup .tile img { opacity: 0; filter: blur(14px); transform: scale(1.03); transition: opacity 500ms var(--ease), filter 700ms var(--ease), transform 700ms var(--ease); }
body.opt-entrance-blurup .tile.loaded.in img { opacity: 1; filter: blur(0); transform: none; }
body.opt-entrance-blurup .tile { background-image: var(--tile-lqip); background-color: var(--tile-color); }

body.opt-stagger .tile { transition-delay: calc(var(--i, 0) * 70ms); }

/* --- Thumbnail hover -------------------------------------------------- */
@media (hover: hover) and (pointer: fine) {
  body.opt-hover-lift .tile { transition: opacity 700ms var(--ease), transform 420ms var(--ease), box-shadow 420ms var(--ease); }
  body.opt-hover-lift .tile.in:hover { transform: translateY(-4px); box-shadow: 0 18px 40px -18px rgba(0,0,0,0.28); }

  body.opt-hover-zoom .tile { overflow: hidden; }
  body.opt-hover-zoom .tile img { transition: transform 180ms cubic-bezier(0.4, 0, 0.2, 1); }
  body.opt-hover-zoom .tile:hover img { transform: scale(1.02); }

  /* Subtractive: the rest of the feed steps back. */
  body.opt-hover-dim .feed:hover .tile.in { opacity: 0.32; transition: opacity 320ms var(--ease); }
  body.opt-hover-dim .feed .tile.in:hover { opacity: 1; }
}

/* --- Header ----------------------------------------------------------- */
body.opt-header-sticky .site-header,
body.opt-header-autohide .site-header {
  position: fixed;
  top: 0; left: 0; right: 0;
  background: var(--bg);
  z-index: 20;
  transition: transform 380ms var(--ease);
}
body.opt-header-sticky main,
body.opt-header-autohide main { padding-top: var(--header-h); }
body.opt-header-autohide .site-header.hidden { transform: translateY(-100%); }

/* --- Scroll progress -------------------------------------------------- */
.scroll-progress {
  position: fixed;
  top: 0; left: 0; right: 0;
  height: 1px;
  background: var(--ink);
  transform: scaleX(0);
  transform-origin: 0 50%;
  z-index: 40;
  display: none;
}
body.opt-progress .scroll-progress { display: block; }

/* --- Lightbox open variants ------------------------------------------- */
.lightbox.open-scale .lb-img { transition: opacity 320ms var(--ease), transform 420ms var(--ease); transform: scale(0.965); }
.lightbox.open-scale.open .lb-img.ready { transform: none; }
.lb-img.morphing { opacity: 1; will-change: transform; }
.tile.is-source img { opacity: 0; }

/* --- Lightbox swap variants ------------------------------------------- */
.lb-img.swap-drift { transition: opacity 300ms var(--ease), transform 300ms var(--ease); }

/* --- Lightbox counter -------------------------------------------------- */
.lb-count {
  position: absolute;
  left: 28px;
  bottom: 24px;
  font-family: var(--mono);
  font-size: 11px;
  letter-spacing: 0.14em;
  color: var(--ink-soft);
  z-index: 3;
  display: none;
  pointer-events: none;
}
body.opt-meta-counter .lb-count { display: block; }
@media (max-width: 767px) {
  .lb-count { left: 20px; bottom: 18px; }
}

@media (prefers-reduced-motion: reduce) {
  .tile, .tile img, .lb-img, .site-header { transition: none !important; }
  body.opt-entrance-fade .tile, body.opt-entrance-fadeup .tile { opacity: 1; transform: none; }
  body.opt-entrance-blurup .tile img { opacity: 1; filter: none; transform: none; }
}

/* --- Column rhythm ----------------------------------------------------- */
@media (min-width: 768px) {
  body.opt-rhythm-offset .col:nth-child(even) { margin-top: 88px; }
}

/* --- Feed width -------------------------------------------------------- */
body.opt-width-1440 { --max: 1440px; }
body.opt-width-1200 { --max: 1200px; }
body.opt-width-full { --max: 100%; }

/* --- Wordmark position ------------------------------------------------- */
body.opt-wordmark-center .site-header { justify-content: center; }

/* --- Lightbox ground --------------------------------------------------- */
body.opt-lbbg-cream .lightbox { background: #faf8f4; }
body.opt-lbbg-dark  .lightbox { background: #0e0e0e; }        /* near-black, so a true black in the photo still separates */
body.opt-lbbg-dark  .lightbox .lb-close,
body.opt-lbbg-dark  .lightbox .lb-zone { color: #f4f4f4; }
body.opt-lbbg-dark  .lightbox .lb-count,
body.opt-lbbg-dark  .lightbox .lb-caption { color: #8f8f8f; }


/* A narrow desktop window still has a mouse, so the arrows still show. Tie the
   photo's side padding to the pointer type so an arrow never sits on the photo. */
@media (max-width: 767px) and (hover: hover) and (pointer: fine) {
  .lb-stage { padding: 64px 74px; }
}
