/* ==========================================================================
   ARCHIVE — "Across Generations" (era timeline)
   Pinned scroll section. The four era blocks (date / title / description) sit
   in a fixed left column while a single shared image stage on the right
   cross-fades to the active era as the visitor scrolls.

   js/timeline.js adds `.is-pinned` to the section only when the viewport is
   wide enough and motion is not reduced. Without it, the default styles below
   produce a simple stacked layout (text, then its image) — the mobile and
   reduced-motion fallback.

   Design tokens live in css/hero.css (:root); components here reuse them.
   ========================================================================== */

.timeline {
  position: relative;
  z-index: 0;
  background-color: var(--color-dark-bg);
  color: var(--color-dark-text-main);
  padding: var(--space-3xl) var(--space-xl) calc(var(--space-3xl) + var(--space-lg));

  /* Invert the shared tokens for this section only — everything inside
     (eyebrow, dates, credits, placeholders) follows automatically. */
  --color-text-main: var(--color-dark-text-main);
  --color-text-muted: var(--color-dark-text-muted);
  --color-text-dim: var(--color-dark-text-dim);
  --color-border-subtle: var(--color-dark-border);
  --color-bg-subtle: var(--color-dark-bg-subtle);
}

/* Animated dot field — sits behind the editorial content. */
.timeline__bg {
  position: absolute;
  inset: 0;
  z-index: 0;
  pointer-events: none;
}

.timeline__bg canvas {
  position: sticky;
  top: 0;
  display: block;
  width: 100%;
  height: 100vh;
  height: 100svh;
}

.timeline__inner {
  position: relative;
  z-index: 1;
  max-width: 1360px;
  margin: 0 auto;
  width: 100%;
}

/* --------------------------------------------------------------------------
   Intro — eyebrow, editorial headline, supporting description
   -------------------------------------------------------------------------- */
.timeline__intro {
  display: grid;
  grid-template-columns: repeat(12, 1fr);
  column-gap: var(--space-lg);
  row-gap: var(--space-lg);
  margin-bottom: var(--space-3xl);
}

.timeline__intro .eyebrow {
  grid-column: 1 / -1;
  margin-bottom: 0;
}

.timeline__heading {
  grid-column: 1 / 7;
  font-family: var(--font-display);
  font-size: 4rem;
  font-weight: 700;
  line-height: 1.02;
  letter-spacing: -0.02em;
  color: var(--color-text-main);
  max-width: 14ch;
  text-wrap: balance;
}

.timeline__desc {
  grid-column: 7 / 13;
  align-self: end;
  font-family: var(--font-body);
  font-size: 1.0625rem;
  font-weight: 400;
  line-height: 1.7;
  color: var(--color-text-muted);
  max-width: 52ch;
}

/* --------------------------------------------------------------------------
   Scrolly wrapper — the tall container that gives the pinned panel its
   scroll length. Default (fallback) is a plain, auto-height block.
   -------------------------------------------------------------------------- */
.timeline__scrolly {
  position: relative;
}

.timeline__sticky {
  position: relative;
}

.timeline__list {
  list-style: none;
  margin: 0;
  padding: 0;
}

/* --------------------------------------------------------------------------
   Era text — shared by both the pinned layout and the stacked fallback
   -------------------------------------------------------------------------- */
.era__date {
  font-family: var(--font-mono);
  font-size: 0.8125rem;
  line-height: 1.1;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: var(--color-text-dim);
  margin-bottom: var(--space-sm);
}

.era__title {
  font-family: var(--font-display);
  font-size: clamp(1.5rem, 2.6vw, 2rem);
  font-weight: 700;
  line-height: 1.05;
  letter-spacing: -0.02em;
  color: var(--color-text-main);
  margin-bottom: 0.35em;
}

.era__desc {
  font-family: var(--font-body);
  font-size: 1.0625rem;
  font-weight: 400;
  line-height: 1.7;
  color: var(--color-text-muted);
  max-width: 60ch;
}

/* --------------------------------------------------------------------------
   Era media — shared frame, credit and placeholder
   -------------------------------------------------------------------------- */
.era__media {
  margin: var(--space-md) 0 0;
}

.era__frame {
  position: relative;
  overflow: hidden;
  border-radius: var(--radius-image);
  background-color: var(--color-bg-subtle);
  aspect-ratio: 4 / 3;
}

.era__image {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: cover;
  object-position: top center;
}

/* The picture doubles as the control that enlarges it. Absolute so it fills
   the frame in both the pinned stage and the stacked fallback. */
.era__frame-btn {
  position: absolute;
  inset: 0;
  display: block;
  width: 100%;
  height: 100%;
  padding: 0;
  color: inherit;
}

/* Inset ring — the frame clips anything drawn outside it. */
.era__frame-btn:focus-visible {
  outline: 2px solid var(--color-text-main);
  outline-offset: -4px;
  border-radius: var(--radius-image);
}

/* Image attribution — required by the CC BY / CC BY-SA licences. */
.era__credit {
  margin-top: var(--space-xs);
  font-family: var(--font-mono);
  font-size: 0.6875rem;
  line-height: 1.5;
  letter-spacing: 0.03em;
  color: var(--color-text-dim);
  max-width: 46ch;
}

/* Deliberate placeholder when a referenced image file is missing */
.era__placeholder {
  position: absolute;
  inset: 0;
  display: none;
  align-items: center;
  justify-content: center;
  padding: var(--space-md);
  font-family: var(--font-mono);
  font-size: 0.75rem;
  line-height: 1.5;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  text-align: center;
  color: var(--color-text-dim);
}

.era__media.is-missing .era__image { display: none; }
.era__media.is-missing .era__placeholder { display: flex; }
.era__media.is-missing .era__frame-btn { display: none; }

/* --------------------------------------------------------------------------
   Stacked fallback spacing (mobile + reduced motion)
   -------------------------------------------------------------------------- */
.era + .era {
  margin-top: var(--space-2xl);
}

/* ==========================================================================
   Pinned mode (.is-pinned) — desktop only, added by js/timeline.js
   ========================================================================== */

.timeline.is-pinned .timeline__scrolly {
  height: calc(var(--era-count, 4) * 74vh);
}

.timeline.is-pinned .timeline__sticky {
  position: sticky;
  top: 0;
  height: 100vh;
  height: 100svh;
  display: flex;
  flex-direction: column;
  justify-content: center;
  padding-block: clamp(24px, 5vh, 64px);

  /* Two-column split: label column width, and the gap before the stage. */
  --labels-col: 46%;
  --stage-gap: clamp(32px, 5vw, 84px);
}

/* The <li> disappears from the box tree, so its body and media become direct
   children of the sticky panel and the two columns line up automatically. */
.timeline.is-pinned .era {
  display: contents;
}

.timeline.is-pinned .era + .era {
  margin-top: 0;
}

.timeline.is-pinned .era__media {
  margin: 0;
}

/* 24px between the four labels. Applied as a margin (not flex `gap`) because
   the labels are hoisted out of the `display: contents` <li> and Chrome does
   not apply flex gap across that boundary. */
.timeline.is-pinned .era + .era .era__body {
  margin-top: 24px;
}

.timeline.is-pinned .era__body {
  position: relative;
  width: var(--labels-col);
  padding-left: 20px;
  opacity: 0.45;
  transition: opacity 520ms cubic-bezier(0.16, 1, 0.3, 1);
}

/* Active accent marker — a slim green rule beside the active era. */
.timeline.is-pinned .era__body::before {
  content: "";
  position: absolute;
  left: 0;
  top: 0.35em;
  width: 2px;
  height: 0;
  background-color: var(--color-highlight-soft);
  opacity: 0;
  transition: height 520ms cubic-bezier(0.16, 1, 0.3, 1), opacity 320ms ease;
}

.timeline.is-pinned .era.is-active .era__body {
  opacity: 1;
}

.timeline.is-pinned .era.is-active .era__body::before {
  height: 1.7em;
  opacity: 1;
}

.timeline.is-pinned .era__date {
  margin-bottom: var(--space-xs);
  color: var(--color-dark-text-dim);
  transition: color 520ms ease;
}

.timeline.is-pinned .era.is-active .era__date {
  color: var(--color-highlight-soft);
}

.timeline.is-pinned .era__title {
  /* Scales with viewport height so the four labels always fit the panel. */
  font-size: clamp(1.5rem, 3.6vh, 2.5rem);
  margin-bottom: 0;
  color: var(--color-dark-text-muted);
  transition: color 520ms ease;
}

.timeline.is-pinned .era.is-active .era__title {
  color: var(--color-dark-text-main);
}

/* Inactive labels show only their date and title; the active label expands to
   reveal its description. Exactly one is open at a time, so the column height
   stays effectively constant and the panel always fits. */
.timeline.is-pinned .era__desc {
  font-size: clamp(0.95rem, 2.1vh, 1.125rem);
  line-height: 1.55;
  max-width: 46ch;
  color: var(--color-dark-text-muted);
  margin: 0.5em 0 0;
  max-height: 0;
  opacity: 0;
  overflow: hidden;
  transition: max-height 560ms cubic-bezier(0.16, 1, 0.3, 1),
              opacity 420ms ease;
}

.timeline.is-pinned .era.is-active .era__desc {
  max-height: 9em;
  opacity: 1;
}

/* Media stage — every era's figure is stacked in the same slot; only the
   active one is visible, so the image cross-fades as the visitor scrolls. */
.timeline.is-pinned .era__media {
  position: absolute;
  top: 50%;
  left: calc(var(--labels-col) + var(--stage-gap));
  right: 0;
  transform: translateY(-50%);
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
  transition: opacity 720ms cubic-bezier(0.4, 0, 0.2, 1), visibility 0s linear 720ms;
}

/* Only the active figure is visible and hit-testable — the other three share
   the same slot behind it, so they must not swallow the pointer. */
.timeline.is-pinned .era.is-active .era__media {
  opacity: 1;
  visibility: visible;
  pointer-events: auto;
  transition: opacity 720ms cubic-bezier(0.4, 0, 0.2, 1), visibility 0s;
}

.timeline.is-pinned .era__frame {
  aspect-ratio: 4 / 3;
  max-height: 58vh;
}

.timeline.is-pinned .era__image {
  transform: scale(1.06);
  transition: transform 1100ms cubic-bezier(0.16, 1, 0.3, 1);
}

.timeline.is-pinned .era.is-active .era__image {
  transform: scale(1);
}

/* ==========================================================================
   Era timeline lightbox (.tl-lightbox) — one era picture at full size
   ========================================================================== */
.tl-lightbox {
  position: fixed;
  inset: 0;
  z-index: 300;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: clamp(16px, 5vw, 64px);
  visibility: hidden;
  opacity: 0;
  pointer-events: none;
  transition: opacity 320ms cubic-bezier(0.16, 1, 0.3, 1), visibility 0s linear 320ms;
}

.tl-lightbox.is-open {
  visibility: visible;
  opacity: 1;
  pointer-events: auto;
  transition-delay: 0s;
}

.tl-lightbox__backdrop {
  position: absolute;
  inset: 0;
  background: rgba(13, 12, 11, 0.88);
}

.tl-lightbox__stage {
  position: relative;
  z-index: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  max-width: 1100px;
  max-height: 100%;
}

.tl-lightbox__img {
  display: block;
  max-width: 100%;
  max-height: 76vh;
  object-fit: contain;
  background-color: #1a1917;
  border-radius: var(--radius-image);
}

.tl-lightbox__caption {
  margin-top: var(--space-sm);
  max-width: 64ch;
  text-align: center;
  font-family: var(--font-mono);
  font-size: 0.75rem;
  line-height: 1.5;
  letter-spacing: 0.03em;
  color: rgba(255, 255, 255, 0.82);
}

.tl-lightbox__close {
  position: absolute;
  top: clamp(16px, 4vw, 32px);
  right: clamp(16px, 4vw, 32px);
  z-index: 2;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 44px;
  height: 44px;
  border: 1px solid rgba(255, 255, 255, 0.35);
  border-radius: 2px;
  color: #ffffff;
  background: rgba(255, 255, 255, 0.06);
  transition: background-color var(--transition-fast), color var(--transition-fast), border-color var(--transition-fast);
}

.tl-lightbox__close:hover {
  background-color: #ffffff;
  border-color: #ffffff;
  color: #141312;
}

.tl-lightbox__close:focus-visible {
  outline: 2px solid #ffffff;
  outline-offset: 2px;
}

.tl-lightbox__close svg {
  width: 16px;
  height: 16px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
}

/* Pointer users get no ring on controls we focus programmatically (lightbox
   open). Keyboard users keep it — see js/input-modality.js. */
html.is-pointer .tl-lightbox__close:focus-visible {
  outline: none;
}

/* Scroll lock (compensated so the page does not shift horizontally) */
html.tl-lightbox-open {
  overflow: hidden;
  padding-right: var(--tl-scrollbar-comp, 0);
}

/* --------------------------------------------------------------------------
   Responsive
   -------------------------------------------------------------------------- */
@media (max-width: 1024px) {
  .timeline__heading {
    font-size: 3.25rem;
  }
}

@media (max-width: 820px) {
  .timeline {
    padding: var(--space-2xl) var(--space-lg);
  }

  .timeline__intro {
    grid-template-columns: 1fr;
    row-gap: var(--space-sm);
    margin-bottom: var(--space-2xl);
  }

  .timeline__intro .eyebrow,
  .timeline__heading,
  .timeline__desc {
    grid-column: 1 / -1;
  }

  .timeline__heading {
    font-size: 2.25rem;
    max-width: none;
  }

  .timeline__desc {
    font-size: 1rem;
  }

  .era__title {
    font-size: 1.75rem;
  }
}

@media (max-width: 480px) {
  .timeline {
    padding: var(--space-xl) var(--space-md);
  }

  .timeline__heading {
    font-size: 1.875rem;
  }
}

@media (prefers-reduced-motion: reduce) {
  html.js [data-reveal] {
    opacity: 1;
    transform: none;
    transition: none;
  }

  .timeline.is-pinned .era__body,
  .timeline.is-pinned .era__body::before,
  .timeline.is-pinned .era__date,
  .timeline.is-pinned .era__title,
  .timeline.is-pinned .era__desc,
  .timeline.is-pinned .era__media,
  .timeline.is-pinned .era__image,
  .tl-lightbox {
    transition: none;
  }
}
