/* ============================================================
   STORY CHAPTERS — cinematic documentary navigation
   ============================================================ */

.story-chapter {
  scroll-margin-top: calc(var(--nav-h) + 48px);
}

/* —— Reading progress —— */
.story-chapters-progress {
  position:       fixed;
  top:            0;
  left:           0;
  right:          0;
  height:         1px;
  z-index:        600;
  background:     var(--border);
  pointer-events: none;
  opacity:        0;
  transition:     opacity 0.5s ease;
}

.story-chapters-shell.is-visible .story-chapters-progress { opacity: 1; }
.story-chapters-shell.is-fading .story-chapters-progress { opacity: 0; }

.story-chapters-progress-fill {
  height:           100%;
  width:            0%;
  background:       rgba(255, 255, 255, 0.32);
  transform-origin: left center;
  transition:       width 0.12s linear;
}

/* —— Cinema HUD (animated chapter title) —— */
.story-chapters-cinema {
  position:        fixed;
  top:             var(--nav-h);
  left:            50%;
  transform:       translateX(-50%);
  z-index:         550;
  width:           min(560px, calc(100vw - var(--gutter) * 2));
  padding:         14px 0 10px;
  text-align:      center;
  pointer-events:  none;
  opacity:         0;
  visibility:      hidden;
  transition:      opacity 0.5s ease, visibility 0.5s ease, transform 0.5s ease;
}

.story-chapters-cinema.is-touch {
  pointer-events: auto;
  cursor:         pointer;
}

.story-chapters-shell.is-visible .story-chapters-cinema {
  opacity:    1;
  visibility: visible;
}

.story-chapters-shell.is-fading .story-chapters-cinema {
  opacity:    0;
  visibility: hidden;
  transform:  translateX(-50%) translateY(-6px);
}

.story-chapters-cinema-ey {
  font-size:       8px;
  letter-spacing:  0.34em;
  text-transform:  uppercase;
  color:           var(--dim);
  margin-bottom:   8px;
}

.story-chapters-cinema-main {
  display:         flex;
  align-items:     baseline;
  justify-content: center;
  flex-wrap:       wrap;
  gap:             8px 14px;
  margin-bottom:   6px;
}

.story-chapters-cinema-num,
.story-chapters-cinema-total {
  font-size:            10px;
  letter-spacing:       0.14em;
  color:                var(--dim);
  font-variant-numeric: tabular-nums;
}

.story-chapters-cinema-sep {
  font-size:  9px;
  color:      rgba(255, 255, 255, 0.15);
}

.story-chapters-cinema-title {
  flex:           1 1 100%;
  font-family:    var(--serif);
  font-size:      clamp(18px, 2.4vw, 26px);
  font-weight:    400;
  font-style:     italic;
  line-height:    1.15;
  letter-spacing: -0.01em;
  color:          var(--white);
  transition:     opacity 0.28s ease, transform 0.28s ease;
}

.story-chapters-cinema-title.is-exiting {
  opacity:   0;
  transform: translateY(6px);
}

.story-chapters-cinema-title.is-entering {
  opacity:   0;
  transform: translateY(-6px);
}

.story-chapters-cinema-meta {
  font-size:       9px;
  letter-spacing:  0.16em;
  text-transform:  uppercase;
  color:           var(--dim);
}

.story-chapters-meta-dot {
  margin: 0 8px;
  opacity: 0.4;
}

/* —— Chapter intro flash —— */
.story-chapter-intro {
  position:        fixed;
  inset:           0;
  z-index:         580;
  display:         flex;
  flex-direction:  column;
  align-items:     center;
  justify-content: center;
  gap:             16px;
  background:      rgba(8, 8, 8, 0.72);
  backdrop-filter: blur(12px);
  pointer-events:  none;
  opacity:         0;
  visibility:      hidden;
}

.story-chapter-intro.is-playing {
  animation: story-chapter-intro 1.6s ease forwards;
}

@keyframes story-chapter-intro {
  0%   { opacity: 0; visibility: hidden; }
  12%  { opacity: 1; visibility: visible; }
  72%  { opacity: 1; visibility: visible; }
  100% { opacity: 0; visibility: hidden; }
}

.story-chapter-intro-num {
  font-size:       11px;
  letter-spacing:  0.4em;
  text-transform:  uppercase;
  color:           var(--dim);
}

.story-chapter-intro-title {
  font-family:    var(--serif);
  font-size:      clamp(32px, 6vw, 56px);
  font-weight:    400;
  font-style:     italic;
  letter-spacing: -0.02em;
  color:          var(--white);
  text-align:     center;
  max-width:      min(720px, 88vw);
  padding:        0 var(--gutter-sm);
  line-height:    1.05;
}

/* —— Desktop rail —— */
.story-chapters-rail {
  position:   fixed;
  left:       max(16px, calc((100vw - 1200px) / 2 - 220px));
  top:        50%;
  transform:  translateY(-50%);
  z-index:    450;
  width:      196px;
  opacity:    0;
  visibility: hidden;
  transition: opacity 0.55s ease, visibility 0.55s ease;
  pointer-events: none;
}

.story-chapters-shell.is-visible .story-chapters-rail {
  opacity:        1;
  visibility:     visible;
  pointer-events: auto;
}

.story-chapters-shell.is-fading .story-chapters-rail {
  opacity:        0;
  visibility:     hidden;
  pointer-events: none;
}

.story-chapters-rail-head {
  display:         flex;
  align-items:     baseline;
  justify-content: space-between;
  margin-bottom:   16px;
  padding-right:   4px;
}

.story-chapters-ey {
  font-size:       8px;
  letter-spacing:  0.32em;
  text-transform:  uppercase;
  color:           var(--dim);
}

.story-chapters-rail-time {
  font-size:            8px;
  letter-spacing:       0.12em;
  color:                rgba(255, 255, 255, 0.22);
  font-variant-numeric: tabular-nums;
}

/* Progress markers track */
.story-chapters-track {
  position:      relative;
  height:        calc(100% - 8px);
  min-height:    120px;
  max-height:    220px;
  margin-bottom: 18px;
  padding-left:  2px;
  --track-fill: 0%;
}

.story-chapters-track::before {
  content:    '';
  position:   absolute;
  left:       3px;
  top:        0;
  bottom:     0;
  width:      1px;
  background: var(--border);
}

.story-chapters-track::after {
  content:    '';
  position:   absolute;
  left:       3px;
  top:        0;
  width:      1px;
  height:     var(--track-fill);
  background: rgba(255, 255, 255, 0.28);
  transition: height 0.45s ease;
}

.story-chapters-marker {
  position:   absolute;
  left:       0;
  width:      14px;
  height:     14px;
  padding:    0;
  border:     none;
  background: none;
  cursor:     pointer;
  transform:  translateY(-50%);
}

.story-chapters-marker-dot {
  display:       block;
  width:         7px;
  height:        7px;
  border-radius: 50%;
  background:    rgba(255, 255, 255, 0.14);
  border:        0.5px solid rgba(255, 255, 255, 0.12);
  transition:    transform 0.3s ease, background 0.3s ease, border-color 0.3s ease;
}

.story-chapters-marker.is-active .story-chapters-marker-dot {
  transform:    scale(1.35);
  background:   rgba(255, 255, 255, 0.55);
  border-color: rgba(255, 255, 255, 0.35);
}

.story-chapters-marker.is-complete .story-chapters-marker-dot {
  background:   rgba(255, 255, 255, 0.35);
  border-color: rgba(255, 255, 255, 0.25);
}

.story-chapters-marker:hover .story-chapters-marker-dot,
.story-chapters-marker:focus-visible .story-chapters-marker-dot {
  background: rgba(255, 255, 255, 0.45);
}

.story-chapters-marker:focus-visible {
  outline: none;
}

/* Chapter list */
.story-chapters-list {
  list-style:     none;
  display:        flex;
  flex-direction: column;
  gap:            0;
}

.story-chapters-link {
  display:         flex;
  align-items:     center;
  gap:             10px;
  width:           100%;
  padding:         7px 0;
  font-size:       10px;
  line-height:     1.35;
  color:           var(--dim);
  border:          none;
  background:      none;
  text-align:      left;
  cursor:          pointer;
  font-family:     var(--sans);
  transition:      color 0.25s ease;
  position:        relative;
}

.story-chapters-link-body {
  flex:    1;
  min-width: 0;
}

.story-chapters-link-top {
  display:     flex;
  align-items: baseline;
  gap:         8px;
}

.story-chapters-link:hover,
.story-chapters-link:focus-visible {
  color: var(--white);
  outline: none;
}

.story-chapters-link.is-active {
  color: var(--white);
}

.story-chapters-num {
  flex-shrink:          0;
  font-size:            9px;
  letter-spacing:       0.1em;
  color:                rgba(255, 255, 255, 0.2);
  font-variant-numeric: tabular-nums;
}

.story-chapters-link.is-active .story-chapters-num {
  color: var(--dim);
}

.story-chapters-label {
  display:     block;
  line-height: 1.3;
}

.story-chapters-link-time {
  display:     block;
  margin-top:  2px;
  font-size:   8px;
  letter-spacing: 0.08em;
  color:       rgba(255, 255, 255, 0.18);
}

.story-chapters-link.is-active .story-chapters-link-time {
  color: rgba(255, 255, 255, 0.28);
}

.story-chapters-check {
  flex-shrink: 0;
  width:       10px;
  height:      10px;
  border:      0.5px solid rgba(255, 255, 255, 0.12);
  border-radius: 50%;
  opacity:     0.35;
  transition:  opacity 0.3s, background 0.3s, border-color 0.3s;
}

.story-chapters-link.is-complete .story-chapters-check {
  opacity:        1;
  background:     rgba(255, 255, 255, 0.12);
  border-color:   rgba(255, 255, 255, 0.28);
  box-shadow:     inset 0 0 0 2px var(--black);
  background-image: linear-gradient(135deg, transparent 45%, rgba(255,255,255,0.5) 46%, rgba(255,255,255,0.5) 54%, transparent 55%);
}

/* —— Mobile —— */
.story-chapters-trigger {
  display:         none;
  position:        fixed;
  bottom:          max(20px, env(safe-area-inset-bottom, 20px));
  right:           max(var(--gutter-sm), env(safe-area-inset-right, 0px));
  z-index:         480;
  align-items:     center;
  gap:             10px;
  padding:         14px 18px;
  min-height:      44px;
  font-family:     var(--sans);
  font-size:       9px;
  letter-spacing:  0.22em;
  text-transform:  uppercase;
  color:           var(--white);
  background:      rgba(8, 8, 8, 0.92);
  border:          0.5px solid var(--border);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  cursor:          pointer;
  touch-action:    manipulation;
  -webkit-tap-highlight-color: transparent;
  opacity:         0;
  visibility:      hidden;
  pointer-events:  none;
  transition:      opacity 0.45s ease, visibility 0.45s ease, border-color 0.2s;
}

.story-chapters-trigger-num {
  font-size:            10px;
  letter-spacing:       0.1em;
  color:                var(--dim);
  font-variant-numeric: tabular-nums;
}

.story-chapters-shell.is-visible .story-chapters-trigger {
  opacity:        1;
  visibility:     visible;
  pointer-events: auto;
}

.story-chapters-shell.is-fading .story-chapters-trigger {
  opacity:        0;
  visibility:     hidden;
  pointer-events: none;
}

.story-chapters-drawer {
  display:         none;
  position:        fixed;
  inset:           auto 0 0 0;
  z-index:         490;
  max-height:      min(82dvh, 640px);
  padding:         24px var(--gutter-sm) calc(24px + env(safe-area-inset-bottom));
  background:      rgba(8, 8, 8, 0.97);
  border-top:      0.5px solid var(--border);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  transform:       translate3d(0, 100%, 0);
  transition:      transform 0.42s cubic-bezier(0.22, 1, 0.36, 1);
  -webkit-overflow-scrolling: touch;
}

.story-chapters-drawer.is-open {
  transform: translate3d(0, 0, 0);
}

.story-chapters-drawer-head {
  display:               grid;
  grid-template-columns: 1fr auto;
  align-items:           baseline;
  gap:                   4px 16px;
  margin-bottom:         20px;
}

.story-chapters-drawer-title {
  font-family:    var(--serif);
  font-size:      22px;
  font-weight:    400;
  letter-spacing: -0.02em;
}

.story-chapters-drawer-title em {
  font-style: italic;
  color:      var(--dim);
}

.story-chapters-drawer-meta {
  grid-column: 1;
  font-size:   9px;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color:       var(--dim);
}

.story-chapters-close {
  grid-row:       1 / span 2;
  grid-column:    2;
  align-self:     center;
  padding:        8px;
  font-size:      9px;
  letter-spacing: 0.2em;
  text-transform: uppercase;
  color:          var(--dim);
  background:     none;
  border:         none;
  cursor:         pointer;
  font-family:    inherit;
}

.story-chapters-drawer .story-chapters-list {
  overflow-y:      auto;
  max-height:      calc(82vh - 100px);
  scrollbar-width: none;
}

.story-chapters-drawer .story-chapters-list::-webkit-scrollbar {
  display: none;
}

.story-chapters-drawer .story-chapters-link {
  padding:       14px 0;
  min-height:    44px;
  font-size:     11px;
  border-bottom: 0.5px solid var(--border);
  gap:           14px;
}

.story-chapters-thumb {
  flex-shrink: 0;
  width:       52px;
  height:      64px;
  overflow:    hidden;
  background:  #111;
}

.story-chapters-thumb img {
  width:      100%;
  height:     100%;
  object-fit: cover;
}

.story-chapters-backdrop {
  display:        none;
  position:       fixed;
  inset:          0;
  z-index:        485;
  background:     rgba(0, 0, 0, 0.55);
  opacity:        0;
  transition:     opacity 0.35s ease;
  border:         none;
  cursor:         pointer;
  pointer-events: none;
  touch-action:   manipulation;
}

.story-chapters-backdrop.is-open {
  display:        block;
  opacity:        1;
  pointer-events: auto;
}

@media (max-width: 1100px) {
  .story-chapter {
    scroll-margin-top: calc(var(--nav-h) + 64px);
  }

  .story-chapters-rail {
    display: none !important;
  }

  .story-chapters-cinema {
    left:            0;
    right:           0;
    width:           100%;
    max-width:       none;
    transform:       none;
    padding:         11px var(--gutter-sm);
    text-align:      left;
    background:      rgba(8, 8, 8, 0.92);
    border-bottom:   0.5px solid var(--border);
    -webkit-backdrop-filter: blur(14px);
    backdrop-filter: blur(14px);
  }

  .story-chapters-shell.is-fading .story-chapters-cinema {
    transform: none;
  }

  .story-chapters-cinema-ey,
  .story-chapters-cinema-meta {
    display: none;
  }

  .story-chapters-cinema-main {
    justify-content: flex-start;
    flex-wrap:       nowrap;
    gap:             10px;
    margin-bottom:   0;
  }

  .story-chapters-cinema-title {
    flex:          1 1 auto;
    min-width:     0;
    font-size:     14px;
    white-space:   nowrap;
    overflow:      hidden;
    text-overflow: ellipsis;
  }

  .story-chapters-trigger {
    display: flex;
  }

  .story-chapters-drawer {
    display: block;
  }
}

@media (max-width: 600px) {
  .story-chapter-intro-title {
    font-size: clamp(26px, 8vw, 40px);
  }
}

@media (prefers-reduced-motion: reduce) {
  .story-chapters-progress-fill,
  .story-chapters-cinema-title,
  .story-chapters-marker-dot,
  .story-chapters-track::after {
    transition: none;
  }

  .story-chapter-intro.is-playing {
    animation: none;
    opacity:   0;
  }

  .story-chapters-drawer,
  .story-chapters-rail,
  .story-chapters-trigger,
  .story-chapters-progress,
  .story-chapters-cinema {
    transition: none;
  }
}
