/* ═══════════════════════════════════════════════════════════════════════════
   TABLE OF CONTENTS — Editorial Timeline Navigation
   ═══════════════════════════════════════════════════════════════════════════ */

.toc {
  --toc-width: 220px;
  --toc-gold: rgba(255, 217, 61, 0.92);
  --toc-gold-dim: rgba(255, 217, 61, 0.25);
  --toc-gold-glow: rgba(255, 217, 61, 0.15);
  --toc-text: rgba(245, 245, 245, 0.55);
  --toc-text-hover: rgba(245, 245, 245, 0.85);
  --toc-text-active: rgba(255, 217, 61, 0.92);
  --toc-bg: rgba(8, 12, 24, 0.65);
  --toc-line: rgba(255, 255, 255, 0.08);

  position: fixed;
  top: 50%;
  right: max(1.5rem, calc((100vw - 900px) / 2 - var(--toc-width) - 3rem));
  transform: translateY(-50%);
  width: var(--toc-width);
  max-height: 70vh;
  z-index: 100;

  opacity: 0;
  visibility: hidden;
  transition:
    opacity 0.4s cubic-bezier(0.16, 1, 0.3, 1),
    visibility 0.4s,
    transform 0.4s cubic-bezier(0.16, 1, 0.3, 1);
}

.toc--visible {
  opacity: 1;
  visibility: visible;
}

.toc--exiting {
  opacity: 0;
  transform: translateY(-50%) translateX(1rem);
}

/* Hide on smaller screens where there's no room */
@media (max-width: 1280px) {
  .toc {
    display: none;
  }
}

/* ─────────────────────────────────────────────────────────────────────────────
   Header
   ───────────────────────────────────────────────────────────────────────────── */

.toc__header {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  margin-bottom: 1.25rem;
  padding-bottom: 0.75rem;
  border-bottom: 1px solid var(--toc-line);
}

.toc__title {
  font-family: 'Inter', -apple-system, sans-serif;
  font-size: 0.65rem;
  font-weight: 600;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--toc-text);
  margin: 0;
}

.toc__progress-ring {
  width: 18px;
  height: 18px;
  margin-left: auto;
}

.toc__progress-ring circle {
  fill: none;
  stroke-width: 2;
  transform: rotate(-90deg);
  transform-origin: 50% 50%;
}

.toc__progress-ring .ring-bg {
  stroke: var(--toc-line);
}

.toc__progress-ring .ring-progress {
  stroke: var(--toc-gold);
  stroke-linecap: round;
  stroke-dasharray: 44;
  stroke-dashoffset: 44;
  transition: stroke-dashoffset 0.15s ease-out;
}

/* ─────────────────────────────────────────────────────────────────────────────
   Navigation List with Timeline
   ───────────────────────────────────────────────────────────────────────────── */

.toc__nav {
  position: relative;
  overflow-y: auto;
  overflow-x: hidden;
  max-height: calc(70vh - 4rem);
  scrollbar-width: none;
  -ms-overflow-style: none;
}

.toc__nav::-webkit-scrollbar {
  display: none;
}

.toc__list {
  list-style: none;
  margin: 0;
  padding: 0;
  position: relative;
}

/* Timeline track */
.toc__list::before {
  content: '';
  position: absolute;
  left: 5px;
  top: 0.5rem;
  bottom: 0.5rem;
  width: 1px;
  background: var(--toc-line);
}

/* Progress fill (animated via JS) */
.toc__progress-line {
  position: absolute;
  left: 5px;
  top: 0.5rem;
  width: 1px;
  height: 0;
  background: linear-gradient(
    180deg,
    var(--toc-gold) 0%,
    var(--toc-gold-dim) 100%
  );
  transition: height 0.25s cubic-bezier(0.16, 1, 0.3, 1);
  z-index: 1;
}

/* ─────────────────────────────────────────────────────────────────────────────
   Individual Items
   ───────────────────────────────────────────────────────────────────────────── */

.toc__item {
  position: relative;
  margin: 0;
  padding: 0;
}

.toc__link {
  display: flex;
  align-items: flex-start;
  gap: 0.75rem;
  padding: 0.4rem 0;
  padding-left: 1.25rem;
  text-decoration: none;
  color: var(--toc-text);
  font-family: 'Inter', -apple-system, sans-serif;
  font-size: 0.78rem;
  line-height: 1.4;
  transition:
    color 0.2s ease,
    transform 0.2s ease;
  position: relative;
}

/* Timeline dot */
.toc__link::before {
  content: '';
  position: absolute;
  left: 2px;
  top: 0.65rem;
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--toc-bg);
  border: 1.5px solid var(--toc-line);
  transition:
    border-color 0.25s ease,
    background 0.25s ease,
    box-shadow 0.25s ease,
    transform 0.25s cubic-bezier(0.34, 1.56, 0.64, 1);
  z-index: 2;
}

.toc__link:hover {
  color: var(--toc-text-hover);
}

.toc__link:hover::before {
  border-color: var(--toc-gold-dim);
  transform: scale(1.2);
}

/* H3 items — indented */
.toc__item--h3 .toc__link {
  padding-left: 1.75rem;
  font-size: 0.72rem;
  color: rgba(245, 245, 245, 0.4);
}

.toc__item--h3 .toc__link::before {
  width: 5px;
  height: 5px;
  left: 3px;
}

/* ─────────────────────────────────────────────────────────────────────────────
   Active State
   ───────────────────────────────────────────────────────────────────────────── */

.toc__item--active > .toc__link {
  color: var(--toc-text-active);
}

.toc__item--active > .toc__link::before {
  background: var(--toc-gold);
  border-color: var(--toc-gold);
  box-shadow: 0 0 8px var(--toc-gold-glow);
  transform: scale(1.3);
}

/* Passed items (scrolled past) */
.toc__item--passed > .toc__link::before {
  background: var(--toc-gold-dim);
  border-color: var(--toc-gold-dim);
}

/* ─────────────────────────────────────────────────────────────────────────────
   Subtle entrance animation for items
   ───────────────────────────────────────────────────────────────────────────── */

.toc--visible .toc__item {
  animation: tocItemReveal 0.4s cubic-bezier(0.16, 1, 0.3, 1) backwards;
}

.toc--visible .toc__item:nth-child(1) { animation-delay: 0.05s; }
.toc--visible .toc__item:nth-child(2) { animation-delay: 0.08s; }
.toc--visible .toc__item:nth-child(3) { animation-delay: 0.11s; }
.toc--visible .toc__item:nth-child(4) { animation-delay: 0.14s; }
.toc--visible .toc__item:nth-child(5) { animation-delay: 0.17s; }
.toc--visible .toc__item:nth-child(6) { animation-delay: 0.20s; }
.toc--visible .toc__item:nth-child(7) { animation-delay: 0.23s; }
.toc--visible .toc__item:nth-child(8) { animation-delay: 0.26s; }
.toc--visible .toc__item:nth-child(9) { animation-delay: 0.29s; }
.toc--visible .toc__item:nth-child(10) { animation-delay: 0.32s; }
.toc--visible .toc__item:nth-child(n+11) { animation-delay: 0.35s; }

@keyframes tocItemReveal {
  from {
    opacity: 0;
    transform: translateX(0.5rem);
  }
  to {
    opacity: 1;
    transform: translateX(0);
  }
}
