/* =====================================================================
   Base — tokens, type, grain, cursor, nav, transitions, lightbox
   ===================================================================== */

:root {
  /* paper (photography) */
  --paper: #eeeae2;
  --paper-2: #e4ded2;
  --ink: #171614;
  --ink-soft: #5c5850;
  --rule: rgba(23, 22, 20, 0.16);

  /* night (film) */
  --night: #0d0d0c;
  --night-2: #1a1917;
  --bone: #e9e4da;
  --bone-soft: #8f8a81;
  --rule-night: rgba(233, 228, 218, 0.14);

  /* the one accent: safelight red / date-stamp orange */
  --accent: #e0482b;
  --stamp: #ff8a3d;

  --serif: "Instrument Serif", "Times New Roman", serif;
  --sans: "Inter Tight", system-ui, -apple-system, sans-serif;
  --mono: "IBM Plex Mono", ui-monospace, Menlo, monospace;

  --ease: cubic-bezier(0.7, 0, 0.2, 1);
  --ease-out: cubic-bezier(0.16, 0.8, 0.12, 1);
  --gutter: clamp(16px, 4vw, 56px);
  --nav-h: 64px;
}

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

html { -webkit-text-size-adjust: 100%; }
html, body { overflow-x: clip; } /* nothing (tilted filmstrip, parallax) may widen the page */

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

body.theme-paper { background: var(--paper); color: var(--ink); --fg: var(--ink); --fg-soft: var(--ink-soft); --bg: var(--paper); --line: var(--rule); }
body.theme-night { background: var(--night); color: var(--bone); --fg: var(--bone); --fg-soft: var(--bone-soft); --bg: var(--night); --line: var(--rule-night); }

img, video { display: block; max-width: 100%; }
a { color: inherit; text-decoration: none; }
button { font: inherit; color: inherit; background: none; border: 0; padding: 0; cursor: pointer; }
h1, h2, h3, p, ol, ul, dl, dd, figure { margin: 0; padding: 0; }
ol, ul { list-style: none; }

::selection { background: var(--accent); color: var(--paper); }

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

.mono {
  font-family: var(--mono);
  font-size: 11px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  font-weight: 400;
}

.serif { font-family: var(--serif); font-weight: 400; }
em { font-style: italic; font-family: var(--serif); }

.visually-hidden {
  position: absolute !important;
  width: 1px; height: 1px;
  overflow: hidden; clip: rect(0 0 0 0);
  white-space: nowrap;
}

/* ---------- film grain (whole site) ---------- */
body::after {
  content: "";
  position: fixed;
  inset: -100%;
  z-index: 900;
  pointer-events: none;
  opacity: 0.07;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='220' height='220'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='.85' numOctaves='3' stitchTiles='stitch'/%3E%3CfeColorMatrix values='0 0 0 0 0  0 0 0 0 0  0 0 0 0 0  0 0 0 1.4 0'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)'/%3E%3C/svg%3E");
  animation: grain 0.9s steps(6) infinite;
}
body.theme-night::after { opacity: 0.06; filter: invert(1); }

@keyframes grain {
  0% { transform: translate(0, 0); }
  20% { transform: translate(-3%, 2%); }
  40% { transform: translate(2%, -4%); }
  60% { transform: translate(-4%, -1%); }
  80% { transform: translate(3%, 3%); }
  100% { transform: translate(-1%, 4%); }
}

/* ---------- custom cursor (fine pointers only, added by JS) ---------- */
.has-cursor, .has-cursor a, .has-cursor button { cursor: none; }

.cursor {
  position: fixed;
  left: 0; top: 0;
  z-index: 1000;
  pointer-events: none;
  mix-blend-mode: difference;
  color: #fff;
}
.cursor-dot,
.cursor-ring {
  position: fixed;
  left: 0; top: 0;
  border-radius: 50%;
  will-change: transform;
}
.cursor-dot { width: 6px; height: 6px; margin: -3px 0 0 -3px; background: #fff; }
.cursor-ring {
  width: 38px; height: 38px;
  margin: -19px 0 0 -19px;
  border: 1px solid #fff;
  display: grid;
  place-items: center;
  transition: width 0.45s var(--ease-out), height 0.45s var(--ease-out), margin 0.45s var(--ease-out), background-color 0.3s;
}
.cursor-label {
  font-family: var(--mono);
  font-size: 10px;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  opacity: 0;
  transition: opacity 0.2s;
  color: #000;
}
.cursor.is-label { mix-blend-mode: normal; }
.cursor.is-label .cursor-ring { width: 84px; height: 84px; margin: -42px 0 0 -42px; background: var(--accent); border-color: var(--accent); }
.cursor.is-label .cursor-label { color: #fff; }
.cursor.is-label .cursor-label { opacity: 1; transition-delay: 0.12s; }
.cursor.is-label .cursor-dot { opacity: 0; }
.cursor.is-link .cursor-ring { width: 56px; height: 56px; margin: -28px 0 0 -28px; }
.cursor.is-hidden { opacity: 0; }

/* ---------- navigation ---------- */
.nav {
  position: fixed;
  inset: 0 0 auto 0;
  z-index: 500;
  height: var(--nav-h);
  padding: 0 var(--gutter);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
  mix-blend-mode: difference;
  color: #fff;
}
.wordmark {
  font-family: var(--serif);
  font-size: 22px;
  letter-spacing: -0.01em;
  white-space: nowrap;
}
.wordmark em { font-style: italic; }
.nav-links { display: flex; gap: clamp(14px, 3vw, 36px); }
.nav-links a {
  font-family: var(--mono);
  font-size: 11px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  position: relative;
  padding: 4px 0;
}
.nav-links a::after {
  content: "";
  position: absolute;
  left: 0; right: 0; bottom: 0;
  height: 1px;
  background: currentColor;
  transform: scaleX(0);
  transform-origin: right;
  transition: transform 0.5s var(--ease);
}
.nav-links a:hover::after,
.nav-links a[aria-current="page"]::after { transform: scaleX(1); transform-origin: left; }

/* ---------- footer ---------- */
.foot {
  padding: 64px var(--gutter) 32px;
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: end;
  gap: 16px;
  border-top: 1px solid var(--line);
  margin-top: 120px;
}
.foot > :nth-child(2) { text-align: center; }
.foot > :last-child { text-align: right; }
.foot a { border-bottom: 1px solid var(--line); }
.foot a:hover { border-color: currentColor; }

@media (max-width: 700px) {
  .foot { grid-template-columns: 1fr; text-align: left; }
  .foot > :nth-child(2), .foot > :last-child { text-align: left; }
}

/* ---------- reveal on scroll ---------- */
.js [data-reveal] {
  opacity: 0;
  transform: translateY(28px);
  transition: opacity 1.1s var(--ease-out), transform 1.1s var(--ease-out);
  transition-delay: var(--d, 0s);
}
.js [data-reveal].is-in { opacity: 1; transform: none; }

/* a paper-coloured cover that lifts off the image (keeps the image itself
   unclipped so lazy-loading and observers still see it) */
.js [data-reveal="wipe"] { opacity: 1; transform: none; position: relative; }
.js [data-reveal="wipe"]::after {
  content: "";
  position: absolute;
  inset: -1px;
  background: var(--bg);
  transform-origin: top;
  transition: transform 1.3s var(--ease);
  transition-delay: var(--d, 0s);
  pointer-events: none;
}
.js [data-reveal="wipe"].is-in::after { transform: scaleY(0); }

/* split-letter headline animation */
.letters .ch {
  display: inline-block;
  transform: translateY(105%);
  transition: transform 1s var(--ease-out);
  transition-delay: calc(var(--i) * 40ms + var(--base, 0.15s));
}
.letters .ln {
  display: inline-block;
  overflow: hidden;
  vertical-align: top;
  /* room for italic overhang and descenders inside the mask */
  padding: 0 0.12em 0.24em 0;
  margin: 0 -0.12em -0.24em 0;
}
.letters.is-in .ch { transform: none; }

/* ---------- page transitions ---------- */
.curtain {
  position: fixed;
  inset: 0;
  z-index: 950;
  pointer-events: none;
}
.curtain::before,
.curtain::after {
  content: "";
  position: absolute;
  left: 0; right: 0;
  height: 50.5%;
  background: var(--ink);
  transform: scaleY(0);
}
.curtain::before { top: 0; transform-origin: top; }
.curtain::after { bottom: 0; transform-origin: bottom; }

/* leaving — shutter: blades close */
.curtain[data-state="shutter"]::before,
.curtain[data-state="shutter"]::after { transition: transform 0.55s var(--ease); transform: scaleY(1); }

/* leaving — film burn */
.curtain[data-state="burn"] {
  background: radial-gradient(circle at var(--bx, 50%) var(--by, 50%), #fff6d8 0%, #ffb547 12%, #e0482b 30%, #2b0b05 55%, #000 75%);
  background-size: 100% 100%;
  animation: burn-out 0.75s var(--ease) forwards;
}
@keyframes burn-out {
  0% { opacity: 0; clip-path: circle(0% at var(--bx, 50%) var(--by, 50%)); }
  35% { opacity: 1; }
  100% { opacity: 1; clip-path: circle(150% at var(--bx, 50%) var(--by, 50%)); }
}

/* leaving — plain fade */
.curtain[data-state="fade"] { background: var(--bg); animation: fade-in 0.45s ease forwards; }
@keyframes fade-in { from { opacity: 0; } to { opacity: 1; } }

/* arriving — set in <head> from sessionStorage, plays with no JS */
[data-enter="shutter"] .curtain::before,
[data-enter="shutter"] .curtain::after { transform: scaleY(1); animation: blade-open 0.8s 0.1s var(--ease) forwards; }
@keyframes blade-open { to { transform: scaleY(0); } }

[data-enter="burn"] .curtain { background: #000; animation: lights-up 0.9s 0.05s ease forwards; }
@keyframes lights-up { to { opacity: 0; } }

[data-enter="fade"] .curtain { background: var(--bg); animation: lights-up 0.5s ease forwards; }

/* ---------- broken image fallback (helps catch typos in content.js) ---------- */
img.is-missing {
  background: repeating-linear-gradient(45deg, transparent 0 10px, var(--line) 10px 11px);
  min-height: 160px;
  outline: 1px dashed var(--fg-soft);
}

/* ---------- toast ---------- */
.toast {
  position: fixed;
  left: 50%; bottom: 28px;
  z-index: 980;
  transform: translate(-50%, 140%);
  padding: 12px 18px;
  background: var(--fg);
  color: var(--bg);
  font-family: var(--mono);
  font-size: 11px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  transition: transform 0.5s var(--ease-out);
}
.toast.is-on { transform: translate(-50%, 0); }

/* ---------- lightbox ---------- */
.lb {
  position: fixed;
  inset: 0;
  z-index: 800;
  display: grid;
  grid-template-rows: auto 1fr auto;
  background: rgba(13, 13, 12, 0.97);
  color: var(--bone);
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.45s ease, visibility 0s 0.45s;
}
.lb.is-open { opacity: 1; visibility: visible; transition: opacity 0.45s ease; }

.lb-top, .lb-bottom {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 16px;
  padding: 18px var(--gutter);
}
.lb-stage {
  position: relative;
  display: grid;
  place-items: center;
  min-height: 0;
  padding: 0 var(--gutter);
}
.lb-img {
  max-width: 100%;
  max-height: calc(100svh - 150px);
  object-fit: contain;
  transition: opacity 0.35s ease, transform 0.5s var(--ease-out);
}
.lb-img.is-swapping { opacity: 0; transform: translateX(calc(var(--dir, 1) * 24px)); }
.lb-cap { font-family: var(--serif); font-size: 20px; }
.lb-exif { color: var(--bone-soft); }
.lb-nav { display: flex; gap: 28px; }
.lb button:hover { color: var(--stamp); }

/* Clickable halves of the stage for prev/next */
.lb-hit { position: absolute; top: 0; bottom: 0; width: 50%; }
.lb-hit.prev { left: 0; }
.lb-hit.next { right: 0; }

@media (max-width: 700px) {
  .lb-bottom { flex-direction: column; align-items: flex-start; }
}

/* ---------- reduced motion ---------- */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
    transition-delay: 0s !important;
  }
  body::after { animation: none; }
}
