/* ══════════════════════════════════════════════════════════════
   SECTION 6 — CHAPTERS ("Your story, one chapter at a time")
   Centred title + subcopy, then a horizontal carousel of glass tiles,
   each holding a chapter badge + name. Edge tiles bleed off to signal
   scroll. Transparent — the fixed mesh shows through.
   ══════════════════════════════════════════════════════════════ */
.chapters {
  position: relative;
  z-index: 1;
  background: transparent;
  padding: clamp(50px, 8vh, 110px) 0 clamp(70px, 11vh, 150px);
  text-align: center;
}
.chapters-head { max-width: 760px; margin: 0 auto clamp(40px, 6vh, 72px); padding-inline: 24px; }
.chapters-title {
  font-size: clamp(30px, 4.4vw, 50px);
  font-weight: 800;
  letter-spacing: -0.02em;
  color: #ffffff;
}
.chapters-sub {
  margin-top: 16px;
  font-size: clamp(16px, 1.6vw, 20px);
  color: rgba(255,255,255,0.92);
}

/* — Never-ending marquee — the 30 tiles are rendered TWICE in one
   track; the track translates left by exactly half its width on a loop,
   so when it resets the duplicate half is already in place → seamless
   infinite scroll. Masked at both edges so tiles fade in/out. — */
.chapters-viewport {
  overflow: hidden;
  -webkit-mask-image: linear-gradient(90deg, transparent, #000 8%, #000 92%, transparent);
  mask-image: linear-gradient(90deg, transparent, #000 8%, #000 92%, transparent);
}
.chapters-track {
  display: flex;
  gap: 22px;
  width: max-content;
  padding-block: 8px 24px;
  animation: chapters-marquee 90s linear infinite;
}
.chapters-viewport:hover .chapters-track { animation-play-state: paused; }
@keyframes chapters-marquee {
  from { transform: translateX(0); }
  /* -50% of the full (doubled) track + half the gap so the seam aligns. */
  to   { transform: translateX(calc(-50% - 11px)); }
}
@media (prefers-reduced-motion: reduce) {
  .chapters-track { animation: none; }
  .chapters-viewport {
    overflow-x: auto;
    scrollbar-width: none;
  }
  .chapters-viewport::-webkit-scrollbar { display: none; }
}

/* — Chapter tile (a <button> using the shared .glass-card base) —
   Reset native button chrome so it still reads as a glass tile, but
   keep it a real button for keyboard + VoiceOver. — */
.chapter {
  flex: 0 0 auto;
  width: 200px;
  padding: 28px 20px 24px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 16px;
  /* button reset */
  border: 0;
  font-family: inherit;
  color: #ffffff;
  cursor: pointer;
  text-align: center;
  -webkit-appearance: none;
  appearance: none;
  transition: transform 0.25s ease, background 0.25s ease;
}
.chapter:hover { transform: translateY(-4px); background: rgba(255,255,255,0.22); }
.chapter:focus-visible {
  outline: 2px solid rgba(255,255,255,0.9);
  outline-offset: 3px;
}
.chapter img {
  width: 116px;
  height: 116px;
  object-fit: contain;
  filter: drop-shadow(0 12px 22px rgba(50,25,70,0.28));
  pointer-events: none;          /* clicks always resolve to the tile */
}
.chapter-name {
  font-size: 20px;
  font-weight: 700;
  color: #ffffff;
}

/* ══════════════════════════════════════════════════════════════
   CHAPTER DETAIL MODAL
   Centred glass dialog opened from a tile (js/chapters-modal.js).
   Fades + scales in; backdrop dims the page. While open, body gets
   .modal-open which freezes the marquee and locks page scroll.
   ══════════════════════════════════════════════════════════════ */
body.modal-open { overflow: hidden; }
body.modal-open .chapters-track { animation-play-state: paused; }

.chapter-modal {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  /* fade controlled by .is-open; [hidden] removes it from the flow */
  opacity: 0;
  transition: opacity 0.28s ease;
}
.chapter-modal[hidden] { display: none; }
.chapter-modal.is-open { opacity: 1; }

.chapter-modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(40, 20, 60, 0.55);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
}

.chapter-modal-card {
  position: relative;
  z-index: 1;
  width: min(440px, 100%);
  max-height: 88vh;
  overflow-y: auto;
  padding: 40px 36px 36px;
  text-align: center;
  /* slightly brighter than a tile so it lifts off the dimmed page */
  background: rgba(255,255,255,0.22);
  transform: scale(0.94);
  transition: transform 0.28s cubic-bezier(0.22, 1, 0.36, 1);
}
.chapter-modal.is-open .chapter-modal-card { transform: scale(1); }

.chapter-modal-close {
  position: absolute;
  top: 14px;
  right: 14px;
  width: 38px;
  height: 38px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: 0;
  border-radius: 999px;
  cursor: pointer;
  color: #ffffff;
  background: rgba(255,255,255,0.16);
  transition: background 0.2s ease;
}
.chapter-modal-close:hover { background: rgba(255,255,255,0.3); }
.chapter-modal-close:focus-visible {
  outline: 2px solid rgba(255,255,255,0.9);
  outline-offset: 2px;
}
.chapter-modal-close svg { width: 20px; height: 20px; }

.chapter-modal-badge {
  width: 148px;
  height: 148px;
  object-fit: contain;
  margin: 4px auto 18px;
  filter: drop-shadow(0 16px 30px rgba(50,25,70,0.34));
}
.chapter-modal-name {
  font-size: clamp(26px, 4vw, 32px);
  font-weight: 800;
  letter-spacing: -0.01em;
  color: #ffffff;
}
.chapter-modal-rank {
  margin-top: 6px;
  font-size: 14px;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: rgba(255,255,255,0.75);
}
.chapter-modal-blurb {
  margin-top: 18px;
  font-size: 17px;
  line-height: 1.55;
  color: rgba(255,255,255,0.95);
}
.chapter-modal-pill {
  display: inline-block;
  margin-top: 22px;
  padding: 8px 18px;
  border-radius: 999px;
  font-size: 14px;
  font-weight: 600;
  color: #ffffff;
  background: rgba(255,255,255,0.18);
  box-shadow: inset 0 0 0 1px rgba(255,255,255,0.3);
}

@media (prefers-reduced-motion: reduce) {
  .chapter-modal,
  .chapter-modal-card { transition: none; }
  .chapter:hover { transform: none; }
}
