/* ==========================================================================
   ARCHIVE — "Moments That Moved Us" (editorial stories)
   Section + full-screen story modal + image lightbox.
   Tokens come from css/hero.css (:root). Content data: js/stories-data.js.
   Controller: js/stories-modal.js.
   Blocks: .stories (section) · .sm / .sm-lightbox (modal + lightbox)
   ========================================================================== */

/* --------------------------------------------------------------------------
   1. Section shell
   -------------------------------------------------------------------------- */
.stories {
  position: relative;
  background-color: var(--color-bg);
  color: var(--color-text-main);
  padding: var(--space-3xl) var(--space-xl) calc(var(--space-3xl) + var(--space-lg));
  isolation: isolate;
}

/* Reuses Section 2's archival wallpaper, kept subtle and behind the content.
   (No overflow: hidden here — that would break the sticky left column.
   The iOS fix below uses clip-path instead, which does not affect sticky.) */
.stories::before {
  content: "";
  position: absolute;
  inset: 0;
  z-index: 0;
  pointer-events: none;
  background-image: url("../assets/images/wallpaper.webp");
  background-repeat: repeat-y;
  background-position: center center;
  background-size: max(100vw, calc(100vh * 2752 / 1536)) auto;
  background-attachment: fixed;
  opacity: 0.1;
}

/* iOS Safari (WebKit) deliberately ignores background-attachment: fixed —
   the wallpaper scrolls stuck to the content instead of holding still
   behind it (WebKit bug 275247). Emulate the fixed background there with
   a viewport-fixed pseudo clipped back to the section box via clip-path.
   Verified not to break the sticky left column (position: sticky still
   sticks at top: 20px with the section clipped). */
@supports (-webkit-touch-callout: none) {
  .stories {
    clip-path: inset(0);
  }

  .stories::before {
    position: fixed;
    background-attachment: scroll;
  }
}

/* Reduced motion: wallpaper anchored to the section so it scrolls with the
   content. Must follow the iOS block above to win the cascade there. */
@media (prefers-reduced-motion: reduce) {
  .stories::before {
    position: absolute;
    background-attachment: scroll;
  }
}

.stories__inner {
  max-width: 1360px;
  margin: 0 auto;
  width: 100%;
  position: relative;
  z-index: 1;
  display: grid;
  grid-template-columns: minmax(0, 5fr) minmax(0, 7fr);
  column-gap: clamp(32px, 5vw, 96px);
  align-items: start;
}

/* Left column — headline + description. Pins 20px from the top while the
   stack of cards scrolls past, then releases with the section bottom. */
.stories__aside {
  position: sticky;
  top: var(--stories-sticky-top, 20px);
  align-self: start;
}

/* --------------------------------------------------------------------------
   2. Section header (mirrors the disciplines header curtain reveal)
   -------------------------------------------------------------------------- */
.stories__header {
  display: flex;
  flex-direction: column;
  gap: var(--space-lg);
  margin-bottom: 0;
}

.stories__header .eyebrow {
  margin-bottom: 0;
}

.stories__heading {
  font-family: var(--font-display);
  font-size: clamp(2.5rem, 3.6vw, 3.5rem);
  font-weight: 800;
  line-height: 1;
  letter-spacing: -0.035em;
  color: var(--color-text-main);
  text-wrap: balance;
}

.stories__intro {
  font-family: var(--font-body);
  font-size: 1.125rem;
  font-weight: 400;
  line-height: 1.6;
  color: var(--color-text-muted);
  max-width: 42ch;
}

html.js .stories__header[data-reveal] {
  opacity: 1;
  transform: none;
}

html.js .stories__header .eyebrow,
html.js .stories__header .stories__heading,
html.js .stories__header .stories__intro {
  opacity: 0;
  transform: translateY(18px);
  clip-path: inset(0 0 100% 0);
  transition:
    opacity 800ms cubic-bezier(0.16, 1, 0.3, 1),
    transform 800ms cubic-bezier(0.16, 1, 0.3, 1),
    clip-path 800ms cubic-bezier(0.16, 1, 0.3, 1);
  will-change: opacity, transform;
}

html.js .stories__header .stories__heading { transition-delay: 80ms; }
html.js .stories__header .stories__intro { transition-delay: 160ms; }

html.js .stories__header.is-visible .eyebrow,
html.js .stories__header.is-visible .stories__heading,
html.js .stories__header.is-visible .stories__intro {
  opacity: 1;
  transform: none;
  clip-path: inset(0 0 0 0);
}

/* --------------------------------------------------------------------------
   3. Story stack — every card full-width, stacked vertically in the right column
   -------------------------------------------------------------------------- */
.stories__grid {
  display: flex;
  flex-direction: column;
  gap: var(--space-3xl);
  min-width: 0;
}

.story {
  position: relative;
  cursor: pointer;
}

/* All cards share one vertical composition: image above the copy. */
.story.is-feature,
.story.is-half {
  display: flex;
  flex-direction: column;
}

.story__body { margin-top: var(--space-md); }

/* --------------------------------------------------------------------------
   4. Preview media + placeholder
   -------------------------------------------------------------------------- */
.story__media {
  margin: 0;
}

.story__frame {
  position: relative;
  overflow: hidden;
  border-radius: var(--radius-image);
  background-color: var(--color-bg-subtle);
}

.story.is-feature .story__frame { aspect-ratio: 16 / 10; }
.story.is-half .story__frame { aspect-ratio: 3 / 2; }

.story__frame-img {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  object-position: top center;
  transition: transform 700ms cubic-bezier(0.16, 1, 0.3, 1);
}

.story:hover .story__frame-img {
  transform: scale(1.03);
}

.story:focus-within .story__frame-img {
  transform: scale(1.03);
}

/* Shared "archival image to be added" placeholder (also used in the modal) */
.arch-ph {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: var(--space-md);
  text-align: center;
  font-family: var(--font-mono);
  font-size: 0.6875rem;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: var(--color-text-dim);
  opacity: 0;
  pointer-events: none;
}

.story__frame.is-missing,
.sm__frame-media.is-missing {
  box-shadow: inset 0 0 0 1px var(--color-border-subtle);
}

.story__frame.is-missing .story__frame-img,
.sm__frame-media.is-missing .sm__frame-img {
  opacity: 0;
  visibility: hidden;
}

.story__frame.is-missing .arch-ph,
.sm__frame-media.is-missing .arch-ph {
  opacity: 1;
}

.story__credit {
  margin-top: var(--space-sm);
  font-family: var(--font-mono);
  font-size: 0.6875rem;
  letter-spacing: 0.04em;
  color: var(--color-text-dim);
}

/* --------------------------------------------------------------------------
   5. Preview copy
   -------------------------------------------------------------------------- */
.story__headline {
  font-family: var(--font-display);
  font-weight: 800;
  line-height: 1.04;
  letter-spacing: -0.03em;
  color: var(--color-text-main);
  text-wrap: balance;
  margin-bottom: var(--space-sm);
  transition: color var(--transition-fast);
}

.story.is-feature .story__headline { font-size: clamp(2rem, 3.4vw, 2.75rem); }
.story.is-half .story__headline { font-size: clamp(1.5rem, 2.2vw, 1.875rem); }

.story:hover .story__headline { color: var(--color-highlight); }

.story__teaser {
  font-family: var(--font-body);
  font-size: 1.0625rem;
  line-height: 1.6;
  color: var(--color-text-muted);
  max-width: 48ch;
  margin-bottom: var(--space-md);
}

.story__cta {
  position: relative;
  display: inline-flex;
  align-items: center;
  gap: var(--space-2xs);
  font-family: var(--font-body);
  font-size: 0.8125rem;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--color-text-main);
  padding-bottom: 3px;
  border-bottom: 1px solid var(--color-border-strong);
  transition: color var(--transition-fast), border-color var(--transition-fast);
}

/* Expand the hit area to a comfortable touch target without moving the rule. */
.story__cta::after {
  content: "";
  position: absolute;
  left: 0;
  right: 0;
  top: 50%;
  height: 44px;
  transform: translateY(-50%);
}

.story__cta-arrow {
  transition: transform var(--transition-smooth);
}

.story__cta:hover,
.story:hover .story__cta {
  color: var(--color-highlight);
  border-color: var(--color-highlight);
}

.story__cta:hover .story__cta-arrow,
.story:hover .story__cta-arrow {
  transform: translate(2px, -2px);
}

.story__cta:focus-visible {
  outline: 2px solid var(--color-text-main);
  outline-offset: 3px;
}

/* ==========================================================================
   6. Story modal (.sm) — near-full-screen, two columns (text | imagery)
   ========================================================================== */
.sm {
  position: fixed;
  inset: 0;
  z-index: 250;
  visibility: hidden;
  pointer-events: none;
  transition: visibility 0s linear 440ms;
}

.sm.is-open {
  visibility: visible;
  pointer-events: auto;
  transition-delay: 0s;
}

.sm__backdrop {
  position: absolute;
  inset: 0;
  background: rgba(20, 19, 18, 0.66);
  opacity: 0;
  transition: opacity 440ms cubic-bezier(0.16, 1, 0.3, 1);
}

.sm.is-open .sm__backdrop { opacity: 1; }

.sm__panel {
  position: absolute;
  top: 50%;
  left: 50%;
  width: min(1240px, 92vw);
  height: min(900px, 90vh);
  transform: translate(-50%, -46%);
  display: flex;
  flex-direction: column;
  background-color: var(--color-bg);
  border: 1px solid var(--color-border-subtle);
  border-radius: 2px;
  box-shadow: 0 40px 120px rgba(20, 19, 18, 0.35);
  overflow: hidden;
  opacity: 0;
  transition: opacity 440ms cubic-bezier(0.16, 1, 0.3, 1),
              transform 440ms cubic-bezier(0.16, 1, 0.3, 1);
  outline: none;
}

.sm.is-open .sm__panel {
  opacity: 1;
  transform: translate(-50%, -50%);
}

/* ---- Top bar (wordmark · label · close) ---- */
.sm__topbar {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-md);
  padding: var(--space-md) clamp(20px, 3vw, 40px);
  border-bottom: 1px solid var(--color-border-subtle);
  background-color: var(--color-bg);
}

.sm__topbar-left {
  display: flex;
  align-items: baseline;
  gap: var(--space-md);
  min-width: 0;
}

.sm__wordmark {
  font-family: var(--font-wordmark);
  font-size: 1.0625rem;
  font-weight: 300;
  letter-spacing: -0.01em;
  text-transform: uppercase;
  color: var(--color-text-main);
  white-space: nowrap;
}

.sm__label {
  font-family: var(--font-mono);
  font-size: 0.6875rem;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--color-text-dim);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.sm__close {
  flex: 0 0 auto;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 44px;
  height: 44px;
  border: 1px solid var(--color-border-subtle);
  border-radius: 2px;
  color: var(--color-text-main);
  transition: background-color var(--transition-fast), color var(--transition-fast), border-color var(--transition-fast);
}

.sm__close:hover {
  background-color: var(--color-text-main);
  border-color: var(--color-text-main);
  color: var(--color-accent-text);
}

.sm__close:focus-visible {
  outline: 2px solid var(--color-text-main);
  outline-offset: 2px;
}

.sm__close svg,
.sm-lightbox__close svg,
.sm-lightbox__nav svg {
  width: 16px;
  height: 16px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

/* ---- Scroll region ---- */
.sm__scroll {
  flex: 1 1 auto;
  overflow-y: auto;
  overflow-x: hidden;
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
}

.sm__grid {
  display: grid;
  grid-template-columns: minmax(0, 1.05fr) minmax(0, 0.95fr);
  align-items: start;
  min-height: 100%;
}

/* ---- Text column ---- */
.sm__text {
  padding: clamp(28px, 4vw, 64px);
}

.sm__headline {
  font-family: var(--font-display);
  font-size: clamp(1.9rem, 3.2vw, 2.75rem);
  font-weight: 800;
  line-height: 1.03;
  letter-spacing: -0.03em;
  color: var(--color-text-main);
  text-wrap: balance;
  margin-bottom: var(--space-lg);
}

.sm__prose p {
  font-family: var(--font-body);
  font-size: 1.0625rem;
  line-height: 1.75;
  color: var(--color-text-muted);
  max-width: 60ch;
  margin-bottom: var(--space-md);
}

.sm__prose p.sm__lede {
  font-size: 1.3125rem;
  line-height: 1.55;
  color: var(--color-text-main);
}

.sm__closing {
  margin-top: var(--space-lg);
  padding-top: var(--space-lg);
  border-top: 1px solid var(--color-border-strong);
  font-family: var(--font-display);
  font-size: clamp(1.25rem, 2vw, 1.625rem);
  font-weight: 700;
  line-height: 1.2;
  letter-spacing: -0.02em;
  color: var(--color-text-main);
  text-wrap: balance;
  max-width: 34ch;
}

.sm__sources {
  margin-top: var(--space-2xl);
}

.sm__sources-title {
  font-family: var(--font-mono);
  font-size: 0.6875rem;
  font-weight: 400;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: var(--color-text-dim);
  margin-bottom: var(--space-sm);
}

.sm__sources-label {
  font-family: var(--font-body);
  font-size: 1rem;
  line-height: 1.6;
  color: var(--color-text-muted);
  margin-bottom: var(--space-md);
}

.sm__sources-list {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: var(--space-xs);
}

.sm__source-link {
  display: inline-flex;
  align-items: center;
  gap: var(--space-xs);
  font-family: var(--font-body);
  font-size: 0.9375rem;
  color: var(--color-text-main);
  border-bottom: 1px solid var(--color-border-subtle);
  padding-bottom: 2px;
  transition: color var(--transition-fast), border-color var(--transition-fast);
}

.sm__source-link::after {
  content: "\2197";
  font-size: 0.8125rem;
  color: var(--color-text-dim);
  transition: transform var(--transition-smooth), color var(--transition-fast);
}

.sm__source-link:hover {
  color: var(--color-highlight);
  border-color: var(--color-highlight);
}

.sm__source-link:hover::after {
  color: var(--color-highlight);
  transform: translate(2px, -2px);
}

.sm__source-link:focus-visible {
  outline: 2px solid var(--color-text-main);
  outline-offset: 3px;
}

/* ---- Media column ---- */
.sm__media {
  padding: clamp(28px, 4vw, 64px);
  display: flex;
  flex-direction: column;
  gap: var(--space-2xl);
}

.sm__primary { margin: 0; }

.sm__support {
  display: flex;
  flex-direction: column;
  gap: var(--space-lg);
}

.sm__frame {
  display: block;
  width: 100%;
  text-align: left;
}

.sm__frame-media {
  position: relative;
  display: block;
  overflow: hidden;
  border-radius: var(--radius-image);
  background-color: var(--color-bg-card);
}

.sm__frame--primary .sm__frame-media { aspect-ratio: 3 / 2; }
.sm__frame--support .sm__frame-media { aspect-ratio: 4 / 5; }

.sm__frame-img {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  object-position: top center;
  transition: transform 700ms cubic-bezier(0.16, 1, 0.3, 1);
}

.sm__frame:hover .sm__frame-img,
.sm__frame:focus-visible .sm__frame-img {
  transform: scale(1.03);
}

.sm__frame:focus-visible {
  outline: 2px solid var(--color-text-main);
  outline-offset: 4px;
  border-radius: var(--radius-image);
}

.sm__frame-caption {
  display: block;
  margin-top: var(--space-sm);
  font-family: var(--font-mono);
  font-size: 0.75rem;
  letter-spacing: 0.03em;
  line-height: 1.5;
  color: var(--color-text-main);
}

/* ==========================================================================
   7. Story lightbox (.sm-lightbox) — sits above the modal
   ========================================================================== */
.sm-lightbox {
  position: fixed;
  inset: 0;
  z-index: 320;
  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;
}

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

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

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

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

.sm-lightbox__ph {
  display: flex;
  align-items: center;
  justify-content: center;
  width: min(70vw, 900px);
  height: 60vh;
  background-color: #1a1917;
  border: 1px dashed rgba(255, 255, 255, 0.28);
  border-radius: var(--radius-image);
  font-family: var(--font-mono);
  font-size: 0.75rem;
  letter-spacing: 0.2em;
  text-transform: uppercase;
  color: rgba(255, 255, 255, 0.6);
  text-align: center;
  padding: var(--space-lg);
}

.sm-lightbox__ph[hidden] { display: none; }

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

.sm-lightbox__count {
  margin-top: var(--space-xs);
  font-family: var(--font-mono);
  font-size: 0.6875rem;
  letter-spacing: 0.16em;
  color: rgba(255, 255, 255, 0.55);
}

.sm-lightbox__close,
.sm-lightbox__nav {
  position: absolute;
  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), opacity var(--transition-fast);
}

.sm-lightbox__close:hover,
.sm-lightbox__nav:hover {
  background-color: #ffffff;
  border-color: #ffffff;
  color: #141312;
}

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

/* Pointer users get no ring on controls we focus programmatically (story
   modal / lightbox open, and focus returned to the CTA on close). Keyboard
   users keep it — see js/input-modality.js. */
html.is-pointer .story__cta:focus-visible,
html.is-pointer .sm__close:focus-visible,
html.is-pointer .sm-lightbox__close:focus-visible,
html.is-pointer .sm-lightbox__nav:focus-visible {
  outline: none;
}

.sm-lightbox__close {
  top: clamp(16px, 4vw, 32px);
  right: clamp(16px, 4vw, 32px);
}

.sm-lightbox__nav {
  top: 50%;
  transform: translateY(-50%);
}

.sm-lightbox__nav--prev { left: clamp(12px, 3vw, 32px); }
.sm-lightbox__nav--next { right: clamp(12px, 3vw, 32px); }

.sm-lightbox__nav[hidden] { display: none; }

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

/* ==========================================================================
   9. Responsive
   ========================================================================== */
@media (max-width: 1024px) {
  .stories__inner {
    grid-template-columns: minmax(0, 1fr);
    column-gap: 0;
    row-gap: var(--space-2xl);
  }

  /* Single column: the header no longer needs to pin. */
  .stories__aside {
    position: static;
    top: auto;
  }

  .stories__intro { max-width: 60ch; }
}

@media (max-width: 820px) {
  .stories {
    padding-left: var(--space-lg);
    padding-right: var(--space-lg);
  }

  .stories__heading { font-size: 2.5rem; }

  /* Story modal becomes a full-screen single column */
  .sm__panel {
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    transform: none;
    border: none;
    border-radius: 0;
  }

  .sm.is-open .sm__panel { transform: none; }

  .sm__grid {
    grid-template-columns: minmax(0, 1fr);
  }

  .sm__topbar {
    padding: calc(var(--space-md) + env(safe-area-inset-top, 0px)) var(--space-lg) var(--space-md);
  }

  .sm__text { padding: var(--space-xl) var(--space-lg); }
  .sm__media { padding: var(--space-xl) var(--space-lg) calc(var(--space-2xl) + env(safe-area-inset-bottom, 0px)); }
}

@media (max-width: 640px) {
  .story.is-feature .story__frame,
  .story.is-half .story__frame { aspect-ratio: 3 / 2; }
}

@media (max-width: 480px) {
  .stories {
    padding-left: var(--space-md);
    padding-right: var(--space-md);
  }

  .stories__heading { font-size: 2rem; }

  .sm__wordmark { font-size: 0.95rem; }
  .sm-lightbox__img { max-height: 66vh; }
}

/* ==========================================================================
   10. Reduced motion
   ========================================================================== */
@media (prefers-reduced-motion: reduce) {
  .sm,
  .sm__backdrop,
  .sm__panel,
  .sm-lightbox {
    transition: none;
  }

  .story__frame-img,
  .sm__frame-img,
  .story__cta-arrow {
    transition: none;
  }

  .story:hover .story__frame-img,
  .story:focus-within .story__frame-img,
  .sm__frame:hover .sm__frame-img,
  .sm__frame:focus-visible .sm__frame-img {
    transform: none;
  }

  html.js .stories__header .eyebrow,
  html.js .stories__header .stories__heading,
  html.js .stories__header .stories__intro {
    opacity: 1;
    transform: none;
    clip-path: none;
    transition: none;
  }
}
