/* ============================================================
   THINKING WITH YOUR EYES — photoessay styles
   Dark editorial theme · warm amber accents
   Sections: variables → base → nav → hero → chapters → photos
             → lightbox → footer → reveal animations → breakpoints
   ============================================================ */

/* ---------- CSS variables (theme) ---------- */
:root {
  --bg: #0d0b09;              /* near-black, warm */
  --bg-2: #14100c;            /* chapter alternate */
  --bg-3: #1a140e;
  --ink: #ece5da;             /* body text — warm off-white */
  --ink-dim: #a89e8f;         /* secondary text */
  --amber: #e8a33d;           /* primary accent */
  --amber-soft: #c9873a;
  --line: rgba(232, 163, 61, .25);

  --font-display: Georgia, 'Times New Roman', serif;
  --font-body: -apple-system, BlinkMacSystemFont, 'Segoe UI', Helvetica, Arial, sans-serif;

  --max-text: 42rem;
  --max-wide: 72rem;
  --gutter: clamp(1.25rem, 4vw, 3rem);

  --ease: cubic-bezier(.22, 1, .36, 1);
}

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

html { scroll-behavior: smooth; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font-body);
  font-size: 1.0625rem;
  line-height: 1.7;
  -webkit-font-smoothing: antialiased;
  overflow-x: hidden;
}

img { max-width: 100%; display: block; }

a { color: var(--amber); }

h1, h2, h3 {
  font-family: var(--font-display);
  font-weight: 700;
  line-height: 1.1;
  margin: 0;
}

/* Visible focus for keyboard users */
:focus-visible {
  outline: 2px solid var(--amber);
  outline-offset: 3px;
}

/* ============================================================
   NAV — fixed, minimal; hamburger below 768px
   ============================================================ */
.site-header {
  position: fixed;
  inset: 0 0 auto 0;
  z-index: 100;
  background: linear-gradient(rgba(13, 11, 9, .92), rgba(13, 11, 9, .75));
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--line);
}

.nav {
  max-width: var(--max-wide);
  margin: 0 auto;
  padding: .75rem var(--gutter);
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.nav__brand {
  font-family: var(--font-display);
  font-size: 1.15rem;
  color: var(--amber);
  text-decoration: none;
  letter-spacing: .04em;
}

.nav__menu {
  display: flex;
  gap: 1.75rem;
  list-style: none;
  margin: 0;
  padding: 0;
}

.nav__link {
  color: var(--ink);
  text-decoration: none;
  font-size: .85rem;
  letter-spacing: .12em;
  text-transform: uppercase;
  padding: .5rem 0;                 /* generous tap target */
  position: relative;
  transition: color .3s var(--ease);
}

/* Animated underline on hover/focus */
.nav__link::after {
  content: '';
  position: absolute;
  left: 0; right: 100%; bottom: 0;
  height: 2px;
  background: var(--amber);
  transition: right .35s var(--ease);
}
.nav__link:hover, .nav__link:focus-visible { color: var(--amber); }
.nav__link:hover::after, .nav__link:focus-visible::after { right: 0; }

/* Hamburger button — hidden on desktop */
.nav__toggle {
  display: none;
  flex-direction: column;
  justify-content: center;
  gap: 5px;
  width: 48px;
  height: 48px;
  padding: 12px;
  background: none;
  border: none;
  cursor: pointer;
}

.nav__toggle-bar {
  display: block;
  width: 100%;
  height: 2px;
  background: var(--ink);
  transition: transform .35s var(--ease), opacity .25s;
}

/* Hamburger → X when open */
.nav__toggle[aria-expanded="true"] .nav__toggle-bar:nth-child(1) { transform: translateY(7px) rotate(45deg); }
.nav__toggle[aria-expanded="true"] .nav__toggle-bar:nth-child(2) { opacity: 0; }
.nav__toggle[aria-expanded="true"] .nav__toggle-bar:nth-child(3) { transform: translateY(-7px) rotate(-45deg); }

/* ============================================================
   HERO — full screen, parallax background layer
   ============================================================ */
.hero {
  position: relative;
  min-height: 100svh;
  display: flex;
  align-items: center;
  justify-content: center;
  text-align: center;
  overflow: hidden;
  padding: 6rem var(--gutter) 4rem;
}

/* Background image is oversized so parallax translation never
   exposes edges. Moved only via transform (GPU-friendly). */
.hero__bg {
  position: absolute;
  inset: -12% 0;
  z-index: 0;
  will-change: transform;
}
.hero__img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  filter: brightness(.85) saturate(.9);
}

/* Dark scrim keeps hero text readable over the photo */
.hero__scrim {
  position: absolute;
  inset: 0;
  z-index: 1;
  background:
    radial-gradient(ellipse at center, rgba(13,11,9,.55) 0%, rgba(13,11,9,.88) 100%),
    linear-gradient(rgba(13,11,9,.35), rgba(13,11,9,.95));
}

/* Cinematic film-grain texture over the hero photo (static SVG noise,
   costs nothing at runtime) */
.hero::after {
  content: '';
  position: absolute;
  inset: 0;
  z-index: 1;
  pointer-events: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='240' height='240'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.85' numOctaves='2' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='240' height='240' filter='url(%23n)'/%3E%3C/svg%3E");
  background-repeat: repeat;
  background-size: 240px;
  opacity: .05;
}

.hero__content {
  position: relative;
  z-index: 2;
  max-width: var(--max-text);
}

.hero__kicker {
  color: var(--amber);
  text-transform: uppercase;
  letter-spacing: .25em;
  font-size: .75rem;
  margin: 0 0 1.25rem;
}

.hero__title {
  font-size: clamp(2.75rem, 9vw, 6rem);
  letter-spacing: -.01em;
  margin-bottom: 1.25rem;
}

.hero__subtitle {
  font-family: var(--font-display);
  font-style: italic;
  font-size: clamp(1.1rem, 2.4vw, 1.4rem);
  color: var(--ink-dim);
  margin: 0 0 1.75rem;
}

.hero__intro {
  font-size: 1rem;
  color: var(--ink);
  margin: 0 auto 2.25rem;
  max-width: 38rem;
}

.hero__cta {
  display: inline-block;
  padding: .85rem 1.9rem;
  border: 1px solid var(--amber);
  color: var(--amber);
  text-decoration: none;
  letter-spacing: .15em;
  text-transform: uppercase;
  font-size: .8rem;
  transition: background .3s var(--ease), color .3s var(--ease);
}
.hero__cta:hover, .hero__cta:focus-visible {
  background: var(--amber);
  color: var(--bg);
}

/* Initial state for the hero load-in animation — applied ONLY when JS
   is running (script.js adds .js to <html> as its first statement).
   Progressive enhancement: if JS is blocked or fails, nothing is hidden. */
.js .anim-hero {
  opacity: 0;
  transform: translateY(24px);
}

/* ============================================================
   CHAPTERS — each gets a subtly different background so
   scrolling feels like moving through “rooms” (JS crossfades
   body background between these tones as chapters enter).
   ============================================================ */
.chapter {
  padding: clamp(4rem, 10vw, 8rem) var(--gutter);
  max-width: var(--max-wide);
  margin: 0 auto;
}

.chapter__head {
  max-width: var(--max-text);
  margin: 0 auto clamp(3rem, 7vw, 5rem);
  text-align: center;
}

.chapter__number {
  color: var(--amber);
  letter-spacing: .3em;
  text-transform: uppercase;
  font-size: .75rem;
  margin: 0 0 .75rem;
}

.chapter__title {
  font-size: clamp(2rem, 5.5vw, 3.5rem);
  margin-bottom: 1rem;
}

.chapter__lede {
  color: var(--ink-dim);
  font-size: 1.1rem;
  margin: 0;
}

/* ============================================================
   PHOTOS — full-bleed, wide, two-column grid, asymmetric rows
   ============================================================ */
.photo {
  margin: 0 0 clamp(2.5rem, 6vw, 4.5rem);
  cursor: zoom-in;
}

.photo img {
  width: 100%;
  height: auto; /* override the height presentational hint from the
                   width/height attributes (kept for aspect-ratio/CLS) */
  border-radius: 3px;
  /* Hover transitions use transform/filter only — cheap to composite */
  transition: transform .6s var(--ease), filter .6s var(--ease);
}

.photo:hover img,
.photo:focus-visible img {
  transform: scale(1.015);
  filter: brightness(1.08);
}

.photo figcaption {
  margin-top: .8rem;
  font-size: .85rem;
  color: var(--ink-dim);
  line-height: 1.6;
  max-width: 46rem;
  border-left: 2px solid var(--amber-soft);
  padding-left: .8rem;
}

/* Full-bleed: escapes the chapter's max-width to span the viewport */
.photo--full {
  width: 100vw;
  margin-left: calc(50% - 50vw);
}
.photo--full img { border-radius: 0; }
.photo--full figcaption { padding-left: var(--gutter); margin-left: 0; border-left-width: 3px; }

/* Wide: full container width (inside max-width) */
.photo--wide { max-width: 60rem; margin-left: auto; margin-right: auto; }

/* Two-column grid */
.photo-grid--two {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: clamp(1.25rem, 3vw, 2.5rem);
  margin-bottom: clamp(2.5rem, 6vw, 4.5rem);
}
.photo-grid--two .photo { margin-bottom: 0; }

/* Asymmetric: photo beside a pull quote */
.photo-asym {
  display: grid;
  grid-template-columns: 3fr 2fr;
  gap: clamp(1.5rem, 4vw, 3rem);
  align-items: center;
  margin-bottom: clamp(2.5rem, 6vw, 4.5rem);
}
.photo-asym .photo { margin-bottom: 0; }
.photo-asym--flip { grid-template-columns: 2fr 3fr; }
.photo-asym--flip .photo { order: 2; }
.photo-asym--flip .pull-quote { order: 1; }

.pull-quote {
  margin: 0;
  padding: 0 1rem;
}
.pull-quote p {
  font-family: var(--font-display);
  font-style: italic;
  font-size: clamp(1.3rem, 2.6vw, 1.8rem);
  line-height: 1.4;
  color: var(--amber);
  margin: 0 0 .75rem;
}
.pull-quote cite {
  color: var(--ink-dim);
  font-size: .85rem;
  font-style: normal;
  letter-spacing: .05em;
}

/* ============================================================
   LIGHTBOX — modal photo viewer
   ============================================================ */
.lightbox {
  position: fixed;
  inset: 0;
  z-index: 200;
  display: flex;
  align-items: center;
  justify-content: center;
}
.lightbox[hidden] { display: none; }

.lightbox__backdrop {
  position: absolute;
  inset: 0;
  background: rgba(8, 6, 4, .94);
  cursor: zoom-out;
}

.lightbox__figure {
  position: relative;
  z-index: 1;
  margin: 0;
  max-width: min(92vw, 70rem);
  max-height: 88vh;
  display: flex;
  flex-direction: column;
  pointer-events: none;            /* clicks fall through to backdrop */
}

.lightbox__img {
  max-width: 100%;
  max-height: 74vh;
  object-fit: contain;
  margin: 0 auto;
  box-shadow: 0 24px 80px rgba(0, 0, 0, .7);
}

.lightbox__caption {
  color: var(--ink);
  font-size: .95rem;
  text-align: center;
  padding: 1rem 1.5rem 0;
  max-width: 44rem;
  margin: 0 auto;
}

/* Shared button styling — large, easy tap targets */
.lightbox__btn {
  position: absolute;
  z-index: 2;
  width: 52px;
  height: 52px;
  border: 1px solid var(--line);
  border-radius: 50%;
  background: rgba(20, 16, 12, .8);
  color: var(--ink);
  font-size: 1.6rem;
  line-height: 1;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background .25s var(--ease), color .25s var(--ease), transform .25s var(--ease);
}
.lightbox__btn:hover, .lightbox__btn:focus-visible {
  background: var(--amber);
  color: var(--bg);
  transform: scale(1.06);
}

.lightbox__btn--close { top: 1rem; right: 1rem; }
.lightbox__btn--prev  { left: 1rem;  top: 50%; transform: translateY(-50%); }
.lightbox__btn--next  { right: 1rem; top: 50%; transform: translateY(-50%); }
.lightbox__btn--prev:hover, .lightbox__btn--prev:focus-visible { transform: translateY(-50%) scale(1.06); }
.lightbox__btn--next:hover, .lightbox__btn--next:focus-visible { transform: translateY(-50%) scale(1.06); }

.lightbox__count {
  position: absolute;
  z-index: 2;
  bottom: 1rem;
  left: 50%;
  transform: translateX(-50%);
  color: var(--ink-dim);
  font-size: .8rem;
  letter-spacing: .15em;
  margin: 0;
}

/* ============================================================
   FOOTER
   ============================================================ */
.footer {
  border-top: 1px solid var(--line);
  background: var(--bg-2);
  padding: clamp(3rem, 8vw, 5rem) var(--gutter);
  text-align: center;
}
.footer__inner { max-width: var(--max-text); margin: 0 auto; }
.footer__title {
  font-size: 1.6rem;
  color: var(--amber);
  margin-bottom: 1rem;
}
.footer p { color: var(--ink-dim); }
.footer__meta { font-size: .8rem; letter-spacing: .1em; text-transform: uppercase; }
.footer__top {
  display: inline-block;
  margin-top: 1.5rem;
  color: var(--amber);
  text-decoration: none;
  letter-spacing: .12em;
  text-transform: uppercase;
  font-size: .8rem;
  padding: .5rem;                   /* tap target */
}
.footer__top:hover { text-decoration: underline; }

/* ============================================================
   SCROLL-REVEAL (baseline path) — hidden start state is gated
   behind .js (added by script.js), so content is NEVER invisible
   if JavaScript is blocked or fails. IntersectionObserver adds
   .is-visible as elements enter the viewport.
   Browsers with native scroll-driven animation support get the
   .scrolltl class instead and skip this path entirely (see the
   SCROLL-DRIVEN ANIMATIONS section at the bottom).
   transform + opacity only → no layout thrash.
   ============================================================ */
.js:not(.scrolltl) .reveal {
  opacity: 0;
  transform: translateY(36px);
  transition: opacity .9s var(--ease), transform .9s var(--ease);
}
.js:not(.scrolltl) .reveal.is-visible {
  opacity: 1;
  transform: none;
}

/* Body background is crossfaded between chapter tones by JS */
body { transition: background-color 1.2s ease; }

/* ============================================================
   RESPONSIVE BREAKPOINTS
   1024px → tighten asymmetric layouts
    768px → hamburger nav, stack two-column grids
    430px → typical phones · 375px → small phones
   ============================================================ */
@media (max-width: 1024px) {
  .photo-asym, .photo-asym--flip { grid-template-columns: 1fr 1fr; }
}

@media (max-width: 768px) {
  /* Hamburger appears; menu becomes a slide-down full-width panel */
  .nav__toggle { display: flex; }

  .nav__menu {
    position: fixed;
    top: 65px;                       /* below the header bar */
    left: 0; right: 0;
    flex-direction: column;
    gap: 0;
    background: rgba(13, 11, 9, .98);
    border-bottom: 1px solid var(--line);
    padding: .5rem 0 1rem;
    /* Hidden state: slide up + fade via transform/opacity */
    transform: translateY(-8px);
    opacity: 0;
    visibility: hidden;
    transition: transform .35s var(--ease), opacity .35s var(--ease), visibility .35s;
  }
  .nav__menu.is-open {
    transform: none;
    opacity: 1;
    visibility: visible;
  }
  .nav__link {
    display: block;
    padding: .9rem var(--gutter);    /* big, well-spaced tap targets */
    font-size: 1rem;
  }

  /* Stack grids & asymmetric rows */
  .photo-grid--two,
  .photo-asym,
  .photo-asym--flip { grid-template-columns: 1fr; }
  .photo-asym--flip .photo { order: 1; }
  .photo-asym--flip .pull-quote { order: 2; }
  .photo-grid--two .photo,
  .photo-asym .photo { margin-bottom: 1.5rem; }
  .pull-quote { padding: .5rem 0 1.5rem; text-align: center; }
}

@media (max-width: 430px) {
  body { font-size: 1rem; }
  .hero__intro { font-size: .95rem; }
  .lightbox__btn { width: 48px; height: 48px; }
  .lightbox__btn--prev { left: .4rem; }
  .lightbox__btn--next { right: .4rem; }
  .lightbox__caption { font-size: .85rem; padding: .75rem .75rem 0; }
}

@media (max-width: 375px) {
  .hero__title { font-size: 2.5rem; }
  .chapter { padding-left: 1rem; padding-right: 1rem; }
  .photo figcaption { font-size: .8rem; }
}

/* ============================================================
   SCROLL-DRIVEN ANIMATIONS (progressive enhancement)
   Native CSS animation-timeline — animations scrubbed directly by
   scroll position, running off the main thread. script.js adds
   .scrolltl to <html> only when the browser supports it AND the
   user hasn't asked for reduced motion; older browsers keep the
   IntersectionObserver reveal path above.
   ============================================================ */

/* Reading-progress bar (base style; scrubbed below, JS-driven on
   browsers without animation-timeline) */
.scroll-progress {
  position: fixed;
  top: 0; left: 0; right: 0;
  height: 3px;
  z-index: 101;
  background: linear-gradient(90deg, var(--amber-soft), var(--amber));
  transform-origin: 0 50%;
  transform: scaleX(0);
}

.scrolltl .scroll-progress {
  animation: progressGrow linear both;
  animation-timeline: scroll(root);
}
@keyframes progressGrow {
  from { transform: scaleX(0); }
  to   { transform: scaleX(1); }
}

/* Hero: background drifts downward and the headline block scrubs
   away (fade + rise) as the reader scrolls past — replaces the JS
   parallax on supporting browsers */
.scrolltl .hero__bg {
  animation: heroDrift linear both;
  animation-timeline: scroll(root);
  animation-range: 0px 100vh;
}
@keyframes heroDrift {
  to { transform: translateY(14%); }
}

.scrolltl .hero__content {
  animation: heroAway linear both;
  animation-timeline: scroll(root);
  animation-range: 20vh 90vh;
}
@keyframes heroAway {
  to { opacity: 0; transform: translateY(-50px) scale(.97); }
}

/* Scrubbed reveals — tied to each element's own journey through the
   viewport (view() timeline), so scrolling back re-plays them in
   reverse. Replaces the IO fade-in wholesale. */
.scrolltl .reveal {
  animation: scrubRise linear both;
  animation-timeline: view();
  animation-range: entry 8% entry 55%;
}
@keyframes scrubRise {
  from { opacity: 0; transform: translateY(56px); }
  to   { opacity: 1; transform: none; }
}

/* Grid pairs: the second photo trails with a hint of rotation */
.scrolltl .photo-grid--two .photo:nth-child(2) {
  animation-name: scrubRiseTilt;
  animation-range: entry 15% entry 70%;
}
@keyframes scrubRiseTilt {
  from { opacity: 0; transform: translateY(64px) rotate(1.2deg); }
  to   { opacity: 1; transform: none; }
}

/* Full-bleed photos: cinematic letterbox clip-reveal on the image
   itself (clip-path only, so the hover transform/filter stay free) */
.scrolltl .photo--full img {
  animation: clipReveal linear both;
  animation-timeline: view();
  animation-range: entry 0% entry 85%;
}
@keyframes clipReveal {
  from { clip-path: inset(12% 8%); }
  to   { clip-path: inset(0); }
}

/* Pull quotes slide in from the side opposite their photo */
.scrolltl .photo-asym .pull-quote {
  animation-name: scrubFromRight;
}
@keyframes scrubFromRight {
  from { opacity: 0; transform: translateX(48px); }
  to   { opacity: 1; transform: none; }
}
.scrolltl .photo-asym--flip .pull-quote {
  animation-name: scrubFromLeft;
}
@keyframes scrubFromLeft {
  from { opacity: 0; transform: translateX(-48px); }
  to   { opacity: 1; transform: none; }
}

/* ============================================================
   VIEW TRANSITIONS (progressive enhancement)
   The lightbox image carries view-transition-name: lightbox-photo
   (set by script.js), so opening morphs the clicked thumbnail into
   the full-size view and closing morphs it back. Browsers without
   the API simply open the lightbox instantly.
   ============================================================ */
@media (prefers-reduced-motion: no-preference) {
  ::view-transition-group(lightbox-photo),
  ::view-transition-old(lightbox-photo),
  ::view-transition-new(lightbox-photo) {
    animation-duration: .45s;
    animation-timing-function: cubic-bezier(.22, 1, .36, 1);
  }
  /* Keep snapshots filling the morphing group so aspect changes
     (portrait ↔ landscape) stay smooth */
  ::view-transition-old(lightbox-photo),
  ::view-transition-new(lightbox-photo) {
    height: 100%;
    object-fit: cover;
  }
  ::view-transition-old(root),
  ::view-transition-new(root) {
    animation-duration: .25s;
  }
}

/* ============================================================
   REDUCED MOTION — kill animations & parallax entirely
   ============================================================ */
@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
  *, *::before, *::after {
    animation-duration: .01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: .01ms !important;
  }
  .anim-hero, .reveal { opacity: 1 !important; transform: none !important; }
}
