/* ============================================================
   Filmstrip collapse — homepage scroll morph (localhost prototype)
   Hero pinches into the CENTER cell of a 3×3 (or 5×3 when wide)
   contact sheet. JS toggles .is-wide on the stage; cell size is
   locked with --cell so the morph target stays a true square.
   Transform/opacity only; the live .is-hero cell is measured
   each frame during the pinch.
   ============================================================ */

.filmstrip-stage {
  position: relative;
  height: 420vh;
  background: #0e0e0e;
}

@media (min-width: 769px) {
  .filmstrip-stage { height: 465vh; }
}

.filmstrip-pin {
  position: sticky;
  top: 0;
  height: 100vh;
  overflow: hidden;
  background: #0e0e0e;
}

/* Fill the sticky viewport; first paint stays 100vh hero.
   Transparent bg + z-index above the sheet so the clipped photo
   sits ON TOP of the 3×3; shrinking clip reveals the ring, no ghosts. */
.filmstrip-pin .hero {
  position: absolute;
  inset: 0;
  height: 100%;
  min-height: 0;
  width: 100%;
  overflow: visible;
  z-index: 3;
  background: transparent !important;
}

.filmstrip-pin .hero-content,
.filmstrip-pin .hero-credit {
  z-index: 4;
}

/* Entrance 1.2s opacity transition would lag the scroll-linked fade */
.filmstrip-stage.is-pinching .hero-content,
.filmstrip-stage.is-pinching .hero-credit {
  transition: none !important;
}

.hero-clip {
  position: absolute;
  inset: 0;
  z-index: 1;
  overflow: hidden;
  pointer-events: none;
}

/* Once the pinch starts, let clicks pass through the full-size hero box.
   Docked: drop the hero below the sheet so center-cell captions/hover work. */
.filmstrip-stage.is-pinching .hero {
  pointer-events: none;
}

.filmstrip-pin:has(.filmstrip.is-docked) .hero {
  z-index: 1;
  pointer-events: none;
}

.hero-morph {
  position: absolute;
  inset: 0;
  transform-origin: center center;
  will-change: transform;
}

.filmstrip-stage:has(.filmstrip.is-docked) .hero-morph {
  transition: filter 560ms ease;
}

/* Dual vision leftover — keep it from fighting the pinch if markup returns */
.filmstrip-pin .hero-cad,
.filmstrip-pin .hero-cut,
.filmstrip-pin .hero-cad-hint {
  display: none !important;
}

.filmstrip {
  --gap: 2px;
  --budget-h: calc(100vh - 10rem);
  --budget-w: 92vw;
  /* 3×3: square mosaic limited by width or height, same vertical budget as before */
  --cell: calc((min(var(--budget-w), var(--budget-h)) - 2 * var(--gap)) / 3);
  position: absolute;
  inset: 0;
  z-index: 2;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.85rem;
  padding: 4.75rem clamp(1rem, 4vw, 2.5rem) 1.15rem;
  pointer-events: none;
  box-sizing: border-box;
}

/* Mosaic sized to the sticky 100vh pin — square 3×3, or 5×3 of the same cell */
.filmstrip-band,
.filmstrip-meta {
  width: calc(3 * var(--cell) + 2 * var(--gap));
  max-width: 100%;
  flex: 0 0 auto;
}

.filmstrip-grid {
  display: grid;
  grid-template-columns: repeat(3, var(--cell));
  grid-template-rows: repeat(3, var(--cell));
  gap: var(--gap);
  width: calc(3 * var(--cell) + 2 * var(--gap));
  background: #0e0e0e; /* gutters; center cell stays transparent so the clip reads as the photo */
  outline: 1px solid rgba(255, 255, 255, calc(0.12 * var(--sheet-line, 0)));
  outline-offset: 0;
  /* outline, not border: global border-box must not shrink the --cell lattice */
}

/* Wide: same height-fitted cell, two extra columns. JS sets .is-wide when
   5*cell + 4*gap fits in --budget-w without shrinking the cell. */
.filmstrip-stage.is-wide .filmstrip {
  --cell: calc((var(--budget-h) - 2 * var(--gap)) / 3);
}

.filmstrip-stage.is-wide .filmstrip-band,
.filmstrip-stage.is-wide .filmstrip-meta {
  width: calc(5 * var(--cell) + 4 * var(--gap));
  max-width: none;
}

.filmstrip-stage.is-wide .filmstrip-grid {
  grid-template-columns: repeat(5, var(--cell));
  grid-template-rows: repeat(3, var(--cell));
  width: calc(5 * var(--cell) + 4 * var(--gap));
}

/* Tall portrait: 3×5 of width-fitted cells filling the extra height */
.filmstrip-stage.is-tall .filmstrip {
  --budget-h: calc(100vh - 8.5rem);
  --cell: min(
    calc((var(--budget-w) - 2 * var(--gap)) / 3),
    calc((var(--budget-h) - 4 * var(--gap)) / 5)
  );
}
.filmstrip-stage.is-tall .filmstrip-band,
.filmstrip-stage.is-tall .filmstrip-meta {
  width: calc(3 * var(--cell) + 2 * var(--gap));
  max-width: 100%;
}
.filmstrip-stage.is-tall .filmstrip-grid {
  grid-template-columns: repeat(3, var(--cell));
  grid-template-rows: repeat(5, var(--cell));
  width: calc(3 * var(--cell) + 2 * var(--gap));
}

.filmstrip-frame {
  position: relative;
  display: block;
  min-width: 0;
  min-height: 0;
  width: 100%;
  height: 100%;
  overflow: hidden;
  background: #1a1a1a;
  opacity: 0;
  transform: scale(0.86);
  transform-origin: center center;
  will-change: transform, opacity;
  transition: filter 560ms ease;
}

.filmstrip-frame.is-hero {
  background: transparent;
  opacity: 1;
  transform: none;
  will-change: auto;
}

.filmstrip-frame img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
  transition: transform 200ms ease, filter 200ms ease, opacity 80ms linear;
}

/* Live clip shows through during the pinch; the cell <img> takes over when docked. */
.filmstrip-frame.is-hero img {
  opacity: 0;
}
.filmstrip.is-docked .filmstrip-frame.is-hero img {
  opacity: 1;
}
.filmstrip-pin:has(.filmstrip.is-docked) .hero-clip {
  opacity: 0;
  pointer-events: none;
}

.filmstrip.is-docked .filmstrip-frame:hover img {
  transform: scale(1.04);
  filter: brightness(1.08);
}

.filmstrip-frame .featured-caption {
  opacity: 0;
  transform: translateY(4px);
}

/* Docked: captions stay up on touch; hover still works on pointer devices */
.filmstrip.is-docked .filmstrip-frame .featured-caption {
  opacity: 1;
  transform: translateY(0);
}

@media (hover: hover) and (pointer: fine) {
  .filmstrip.is-docked .filmstrip-frame .featured-caption {
    opacity: 0;
    transform: translateY(4px);
  }
  .filmstrip.is-docked .filmstrip-frame:hover .featured-caption {
    opacity: 1;
    transform: translateY(0);
  }

  /* Spotlight waits for a real mouse move (.is-spot-ready), not a parked cursor. */
  .filmstrip.is-spot-ready .filmstrip-grid:has(.filmstrip-frame:hover) .filmstrip-frame:not(:hover) {
    filter: saturate(calc(1 - 0.6 * var(--spot, 0))) brightness(calc(1 - 0.48 * var(--spot, 0)));
  }

  .filmstrip-stage:has(.filmstrip.is-spot-ready .filmstrip-frame:hover):not(:has(.filmstrip-frame.is-hero:hover)) .hero-morph {
    filter: saturate(calc(1 - 0.6 * var(--spot, 0))) brightness(calc(1 - 0.48 * var(--spot, 0)));
    transition: filter 560ms ease;
  }
}

.filmstrip-meta {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 0.55rem;
  opacity: 0;
  pointer-events: none;
  transform: translate3d(0, 8px, 0);
}

.filmstrip-meta .section-label {
  margin-bottom: 0;
}

.filmstrip-gallery-link {
  font-size: 0.85rem;
  font-weight: 500;
  color: var(--accent-blue, #4A8FD4);
  letter-spacing: 0.02em;
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
  transition: gap 200ms ease, color 200ms ease;
}

.filmstrip-gallery-link:hover {
  gap: 0.6rem;
  color: var(--text, #f2f2f2);
}

.filmstrip.is-docked {
  pointer-events: none; /* frames/meta opt in */
}

.filmstrip.is-docked .filmstrip-frame,
.filmstrip.is-docked .filmstrip-meta {
  pointer-events: auto;
}

/* ── Mobile: tighter pad for a 3×5; smaller captions on small cells ── */
@media (max-width: 768px) {
  .filmstrip {
    padding: 4.5rem 0.7rem 0.8rem;
    gap: 0.5rem;
    justify-content: center;
  }
  .filmstrip-frame .featured-caption {
    padding: 0.7rem 0.28rem 0.22rem;
    -webkit-text-size-adjust: 100%;
    text-size-adjust: 100%;
  }
  .filmstrip .featured-title {
    font-size: 0.55rem;
    line-height: 1.2;
  }
  .filmstrip .featured-loc {
    font-size: 0.45rem;
    letter-spacing: 0.04em;
  }
}

/* ── Reduced motion: no pin, no morph ───────────────────────── */
@media (prefers-reduced-motion: reduce) {
  .filmstrip-stage {
    height: auto;
  }

  .filmstrip-pin {
    position: relative;
    height: auto;
    overflow: visible;
  }

  .filmstrip-pin .hero {
    position: relative;
    height: 100vh;
    min-height: 600px;
    z-index: auto;
    background: #0e0e0e !important;
    pointer-events: auto;
  }

  .hero-clip,
  .hero-morph {
    transform: none !important;
    clip-path: none !important;
    filter: none !important;
  }

  .filmstrip {
    position: relative;
    inset: auto;
    height: auto;
    padding: 2.5rem clamp(1.25rem, 5vw, 2.5rem) 3.5rem;
    pointer-events: auto;
  }

  .filmstrip-grid {
    outline-color: rgba(255, 255, 255, 0.12);
  }

  .filmstrip-frame,
  .filmstrip-frame.is-hero {
    opacity: 1 !important;
    transform: none !important;
  }

  .filmstrip-meta {
    opacity: 1 !important;
    transform: none !important;
    pointer-events: auto !important;
  }

  .filmstrip-frame .featured-caption {
    opacity: 1;
    transform: none;
  }
}

