/* ============================================================
   Living Memory — Editorial Gallery Chapter
   Refinement only: presentation, hierarchy, typography, craft.
   Architecture, markup and JS-driven classes are unchanged.
   ============================================================ */

#living-memory-scene {
  --memory-nav-surface: rgba(5, 4, 3, 0.9);
  --memory-nav-surface-hover: rgba(15, 13, 10, 0.94);
  --memory-nav-border: rgba(229, 196, 131, 0.42);
  --memory-nav-border-hover: rgba(229, 196, 131, 0.56);
  --memory-nav-glow: rgba(229, 196, 131, 0.12);
  --memory-nav-icon: #F3DCA2;
  --memory-title-foil-mid: #FFF4DF;

  /* Editorial rhythm — optical, not mechanical */
  --memory-rhythm-brand-art: clamp(0.875rem, 2.5vh, 1.375rem);
  --memory-rhythm-art-label: clamp(1.625rem, 4.5vh, 2.125rem);
  --memory-rhythm-label-title: 0.75rem;
  --memory-rhythm-title-divider: 0.875rem;
  --memory-rhythm-divider-quote: 1rem;
  --memory-rhythm-quote-dots: clamp(1.125rem, 2.75vh, 1.5rem);
}

@supports (background: color-mix(in srgb, black, white)) {
  #living-memory-scene {
    --memory-nav-surface: color-mix(in srgb, var(--color-bg-cinematic-black) 90%, transparent);
    --memory-nav-surface-hover: color-mix(in srgb, var(--color-bg-matte-black) 94%, transparent);
    --memory-nav-border: color-mix(in srgb, var(--color-accent-gold-light) 42%, transparent);
    --memory-nav-border-hover: color-mix(in srgb, var(--color-accent-gold-light) 56%, transparent);
    --memory-nav-glow: color-mix(in srgb, var(--color-accent-gold-light) 14%, transparent);
  }
}

/* Background — quiet atmosphere that lets the artwork lead */
#living-memory-scene .scene-bg img {
  filter: brightness(0.8) contrast(1.05) saturate(0.92);
}

.memory-vignette {
  position: absolute;
  inset: 0;
  background:
    radial-gradient(ellipse 92% 58% at 50% 34%, rgba(229, 196, 131, 0.06) 0%, transparent 60%),
    radial-gradient(circle at 50% 42%, transparent 30%, rgba(5, 4, 3, 0.34) 76%, rgba(5, 4, 3, 0.62) 100%);
}

/* ------------------------------------------------------------
   Layout — editorial vertical composition
   ------------------------------------------------------------ */
.memory-layout {
  position: relative;
  z-index: 2;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  justify-content: center;
  padding:
    calc(var(--safe-top) + 2.5rem) 0
    calc(var(--safe-bottom) + 1.5rem);
}

/* ------------------------------------------------------------
   Brand — the opening line of the chapter
   ------------------------------------------------------------ */
.memory-header {
  text-align: center;
  padding: 0 1rem;
  margin-bottom: var(--memory-rhythm-brand-art);
  flex-shrink: 0;
}

.memory-header span {
  font-family: var(--font-sans);
  font-size: 8px;
  letter-spacing: 0.45em;
  text-transform: uppercase;
  font-weight: 500;
  color: #F3DCA2;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.7rem;
  padding-left: 0.45em;
  text-shadow: 0 1px 6px rgba(0, 0, 0, 0.55);
}

/* Delicate hairlines flanking the brand line (direct child only) */
.memory-header > span::before,
.memory-header > span::after {
  content: '';
  width: 1.75rem;
  height: 1px;
  background: linear-gradient(to right, transparent, rgba(229, 196, 131, 0.45));
}

.memory-header > span::after {
  background: linear-gradient(to left, transparent, rgba(229, 196, 131, 0.45));
}

.memory-header .star {
  font-size: 7px;
  color: var(--color-accent-gold-light);
}

/* ------------------------------------------------------------
   Artwork — the hero element of the chapter
   ------------------------------------------------------------ */
.memory-viewport-wrap {
  position: relative;
  width: 100%;
  max-width: 460px;
  margin: 0 auto;
  padding-left: max(1.5rem, env(safe-area-inset-left, 0px));
  padding-right: max(1.5rem, env(safe-area-inset-right, 0px));
  flex-shrink: 0;
}

.memory-portal {
  position: relative;
  width: 100%;
  height: 52vh;
  max-height: 520px;
  margin: 0 auto;
}

.memory-glow {
  position: absolute;
  inset: -16px;
  border-radius: 48px;
  pointer-events: none;
  z-index: -1;
  opacity: 0.6;
  transition: background 0.5s ease;
}

.memory-card {
  position: absolute;
  inset: 0;
  border-radius: 40px;
  overflow: hidden;
  opacity: 0;
  transition: opacity 680ms cubic-bezier(0.22, 1, 0.36, 1);
  pointer-events: none;
}

.memory-card.is-active {
  opacity: 1;
  z-index: 10;
}

/* Premium champagne frame — depth, edge lighting, optical lift */
.memory-card__frame {
  position: absolute;
  inset: 0;
  border-radius: 40px;
  border: 1px solid rgba(229, 196, 131, 0.42);
  box-shadow:
    0 34px 64px -20px rgba(0, 0, 0, 0.85),
    0 10px 26px rgba(0, 0, 0, 0.55),
    inset 0 1px 0 rgba(255, 244, 223, 0.28);
  pointer-events: none;
  z-index: 30;
}

/* Inner hairline — double-line editorial frame */
.memory-card__frame::before {
  content: '';
  position: absolute;
  inset: 6px;
  border-radius: 34px;
  border: 1px solid rgba(229, 196, 131, 0.16);
  pointer-events: none;
}

/* Delicate champagne halo — separates artwork from background */
.memory-card__frame::after {
  content: '';
  position: absolute;
  inset: -1px;
  border-radius: 41px;
  box-shadow:
    0 0 0 1px rgba(229, 196, 131, 0.12),
    0 0 26px rgba(229, 196, 131, 0.1);
  pointer-events: none;
}

.memory-card img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

/* Soft edge vignette on the photo for depth (no tint, neutral) */
.memory-card__inset {
  position: absolute;
  inset: 0;
  border-radius: 40px;
  box-shadow: inset 0 0 40px rgba(5, 4, 3, 0.55);
  pointer-events: none;
  z-index: 10;
}

/* Gentle top & bottom framing — keeps the photo clean and gallery-like */
.memory-card__gradient {
  position: absolute;
  inset: 0;
  background: linear-gradient(to top,
    rgba(5, 4, 3, 0.55) 0%,
    transparent 32%,
    transparent 74%,
    rgba(5, 4, 3, 0.3) 100%);
  pointer-events: none;
  z-index: 10;
}

/* ------------------------------------------------------------
   Navigation — in-viewport gallery controls
   ------------------------------------------------------------ */
.memory-nav {
  position: absolute;
  top: 50%;
  transform: translate3d(0, -50%, 0);
  width: 3rem;
  height: 3rem;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  background: var(--memory-nav-surface);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  border: 1px solid var(--memory-nav-border);
  color: var(--memory-nav-icon);
  box-shadow:
    0 5px 16px rgba(5, 4, 3, 0.62),
    0 0 0 1px rgba(5, 4, 3, 0.48),
    inset 0 1px 0 rgba(255, 244, 223, 0.2);
  z-index: 40;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
  will-change: transform;
  transition:
    opacity var(--duration-medium) ease,
    background var(--duration-medium) var(--ease-out),
    border-color var(--duration-medium) var(--ease-out),
    box-shadow var(--duration-medium) var(--ease-out),
    transform var(--duration-fast) ease;
}

.memory-nav::before {
  content: '';
  position: absolute;
  inset: 0;
  border-radius: inherit;
  background: radial-gradient(circle at 50% 28%, rgba(255, 244, 223, 0.1) 0%, transparent 62%);
  pointer-events: none;
}

.memory-nav svg {
  position: relative;
  z-index: 1;
  flex-shrink: 0;
  opacity: 1;
}

@media (hover: hover) and (pointer: fine) {
  .memory-nav:hover {
    background: var(--memory-nav-surface-hover);
    border-color: var(--memory-nav-border-hover);
    box-shadow:
      0 7px 20px rgba(5, 4, 3, 0.66),
      0 0 8px var(--memory-nav-glow),
      inset 0 1px 0 rgba(255, 244, 223, 0.24);
  }
}

.memory-nav:active {
  transform: translate3d(0, -50%, 0) scale(0.94);
  border-color: var(--memory-nav-border-hover);
  box-shadow:
    0 4px 12px rgba(5, 4, 3, 0.5),
    inset 0 1px 0 rgba(255, 244, 223, 0.12);
}

.memory-nav:disabled {
  opacity: 0;
  pointer-events: none;
}

.memory-nav--prev { left: 0.625rem; }
.memory-nav--next { right: 0.625rem; }

@supports not (backdrop-filter: blur(8px)) {
  .memory-nav {
    background: rgba(5, 4, 3, 0.94);
  }
}

/* ------------------------------------------------------------
   Narrative — chapter, title, quote
   ------------------------------------------------------------ */
.memory-narrative {
  position: relative;
  width: 100%;
  max-width: 85vw;
  margin: var(--memory-rhythm-art-label) auto 0;
  min-height: 145px;
  text-align: center;
  flex-shrink: 0;
}

.memory-text {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  opacity: 0;
  transition: opacity 680ms cubic-bezier(0.22, 1, 0.36, 1);
  pointer-events: none;
}

.memory-text.is-active { opacity: 1; z-index: 10; }

.memory-chapter-label {
  font-family: var(--font-sans);
  font-size: 8px;
  letter-spacing: 0.42em;
  text-transform: uppercase;
  font-weight: 500;
  background: linear-gradient(110deg, #E5C483 0%, #FFF4DF 45%, #E5C483 100%);
  -webkit-background-clip: text;
  background-clip: text;
  -webkit-text-fill-color: transparent;
  color: transparent;
  padding-left: 0.42em;
  filter: drop-shadow(0 1px 4px rgba(0, 0, 0, 0.5));
  margin-bottom: var(--memory-rhythm-label-title);
}

.memory-chapter-title {
  font-family: var(--font-display);
  font-size: clamp(1.75rem, 6vw, 2.5rem);
  font-weight: 300;
  letter-spacing: 0.04em;
  line-height: 1.2;
  margin: 0 0 var(--memory-rhythm-title-divider);
  background: linear-gradient(
    110deg,
    var(--color-accent-gold-light) 0%,
    var(--memory-title-foil-mid) 24%,
    var(--color-accent-gold-dark) 50%,
    var(--memory-title-foil-mid) 76%,
    var(--color-accent-gold-light) 100%
  );
  background-size: 200% auto;
  -webkit-background-clip: text;
  background-clip: text;
  -webkit-text-fill-color: transparent;
  color: transparent;
  filter: drop-shadow(0 2px 12px rgba(5, 4, 3, 0.65));
  animation: foil-shimmer 18s linear infinite;
}

.memory-chapter-divider {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 1rem;
  width: 100%;
  max-width: 185px;
  margin-bottom: var(--memory-rhythm-divider-quote);
  color: var(--color-accent-gold-light);
  opacity: 0.85;
}

.memory-chapter-divider span {
  flex: 1;
  height: 1px;
  background: linear-gradient(to right, transparent, rgba(229, 196, 131, 0.4));
}

.memory-chapter-divider span:last-child {
  background: linear-gradient(to left, transparent, rgba(229, 196, 131, 0.4));
}

.memory-chapter-quote {
  font-family: var(--font-body);
  font-size: clamp(1.05rem, 3.5vw, 1.32rem);
  font-style: italic;
  color: #EDE5D6;
  line-height: 1.68;
  letter-spacing: 0.01em;
  max-width: 480px;
  margin: 0;
  text-shadow: 0 1px 8px rgba(5, 4, 3, 0.4);
}

.memory-chapter-quote .quote-mark { color: rgba(229, 196, 131, 0.65); }

/* ------------------------------------------------------------
   Footer — pagination dots or completion CTA
   ------------------------------------------------------------ */
.memory-footer {
  position: relative;
  display: flex;
  justify-content: center;
  align-items: center;
  min-height: 2.25rem;
  margin-top: var(--memory-rhythm-quote-dots);
  padding: 0.375rem 1rem 0;
  flex-shrink: 0;
}

.memory-pagination {
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 0.625rem;
  opacity: 1;
  transform: translate3d(0, 0, 0);
  pointer-events: auto;
  transition:
    opacity 480ms ease,
    transform 480ms cubic-bezier(0.22, 1, 0.36, 1);
}

.memory-pagination.is-replaced {
  opacity: 0;
  transform: translate3d(0, -6px, 0);
  pointer-events: none;
}

.memory-continue {
  position: absolute;
  inset: 0.375rem 1rem 0;
  display: flex;
  justify-content: center;
  align-items: center;
  opacity: 0;
  transform: translate3d(0, 8px, 0);
  pointer-events: none;
  transition:
    opacity 520ms ease,
    transform 520ms cubic-bezier(0.22, 1, 0.36, 1);
}

.memory-continue.is-visible {
  opacity: 1;
  transform: translate3d(0, 0, 0);
  pointer-events: auto;
}

.memory-continue__btn {
  padding: 0.6875rem 1.375rem;
  border-radius: 9999px;
  border: 1px solid rgba(229, 196, 131, 0.42);
  background: linear-gradient(180deg, rgba(229, 196, 131, 0.12) 0%, rgba(5, 4, 3, 0.92) 100%);
  font-family: var(--font-sans);
  font-size: 8px;
  font-weight: 600;
  letter-spacing: 0.22em;
  text-transform: uppercase;
  color: var(--color-accent-gold-light);
  box-shadow:
    0 6px 20px rgba(0, 0, 0, 0.32),
    0 2px 8px rgba(229, 196, 131, 0.08),
    inset 0 1px 0 rgba(255, 236, 200, 0.1);
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
  white-space: nowrap;
  transition:
    background 400ms ease,
    border-color 400ms ease,
    box-shadow 400ms ease,
    transform 150ms ease;
}

@media (hover: hover) and (pointer: fine) {
  .memory-continue__btn:hover {
    background: linear-gradient(180deg, rgba(229, 196, 131, 0.22) 0%, rgba(5, 4, 3, 0.94) 100%);
    border-color: rgba(229, 196, 131, 0.56);
    box-shadow:
      0 8px 24px rgba(0, 0, 0, 0.36),
      0 0 18px rgba(229, 196, 131, 0.14),
      inset 0 1px 0 rgba(255, 236, 200, 0.14);
  }
}

.memory-continue__btn:active {
  transform: scale(0.98);
}

.memory-dot {
  width: 6px;
  height: 6px;
  border-radius: 9999px;
  background: rgba(229, 196, 131, 0.28);
  transition: width 400ms var(--ease-out), background 300ms ease;
  cursor: pointer;
}

.memory-dot.is-active {
  width: 18px;
  background: var(--color-accent-gold-light);
  box-shadow: 0 0 8px rgba(229, 196, 131, 0.45);
}

/* ------------------------------------------------------------
   Scroll hint
   ------------------------------------------------------------ */
.memory-scroll-hint {
  position: absolute;
  bottom: calc(var(--safe-bottom) + 0.625rem);
  left: 50%;
  transform: translateX(-50%);
  width: 1.5rem;
  height: 1px;
  background: rgba(229, 196, 131, 0.8);
  border-radius: 1px;
  opacity: 0;
  transition: opacity 500ms ease;
}

.memory-scroll-hint.is-visible { opacity: 0.6; }

/* ------------------------------------------------------------
   Larger viewports
   ------------------------------------------------------------ */
@media (min-width: 768px) {
  .memory-nav {
    width: 3rem;
    height: 3rem;
  }

  .memory-nav--prev { left: 0.75rem; }
  .memory-nav--next { right: 0.75rem; }

  .memory-portal { height: 62vh; max-height: 580px; }
  .memory-header span { font-size: 9px; }
}

/* Short viewports — prevent vertical centering from clipping content */
@media (max-height: 700px) {
  .memory-layout {
    justify-content: flex-start;
    padding-top: calc(var(--safe-top) + 2rem);
  }
}

@media (prefers-reduced-motion: reduce) {
  .memory-chapter-title {
    animation: none;
    background-position: center;
  }

  .memory-pagination,
  .memory-continue {
    transition-duration: 0.01ms;
  }
}
