/*
 * Sparks Type: Timeline
 * Vertical timeline with chapter headings, event cards, expand/collapse.
 * Used by: modern-middle-east, hunger-games-timeline, the-martian-timeline
 *
 * Structure:
 *   .tl (timeline container)
 *     .ch (chapter heading) → .chd (dot) + h2 + .ch-dates + .ch-overview
 *     .ev (event) → .ed (dot) + .cd (card)
 *       .cd → .cdy (date) + .ctt (title) + .cds (description)
 *             + .cex (expandable) → .exc (content) + .ctg (toggle)
 *             + .faction-tags → .faction-tag
 */

/* ══════════════════════════════════════
   Timeline Container
   ══════════════════════════════════════ */

.tl {
  position: relative;
  padding-left: 36px;
}

/* Vertical line */
.tl::before {
  content: '';
  position: absolute;
  left: 7px;
  top: 0;
  bottom: 0;
  width: 2px;
  background: linear-gradient(to bottom,
    rgba(var(--accent-primary-rgb), 0.5) 0%,
    rgba(57, 223, 170, 0.35) 40%,
    rgba(206, 147, 216, 0.35) 70%,
    rgba(var(--accent-primary-rgb), 0.25) 100%
  );
}

/* RTL mirroring */
body.lang-ar .tl,
body.lang-fa .tl { padding-left: 0; padding-right: 36px; }
body.lang-ar .tl::before,
body.lang-fa .tl::before { left: auto; right: 7px; }


/* ══════════════════════════════════════
   Chapter Heading
   ══════════════════════════════════════ */

/* .ph is a legacy alias used by hunger-games-timeline */
.ch, .ph {
  position: relative;
  margin: 48px 0 32px;
  scroll-margin-top: 80px;
}

.ch:first-child, .ph:first-child { margin-top: 0; }

/* Chapter dot on the timeline */
.chd, .phd {
  position: absolute;
  left: -36px;
  top: 50%;
  transform: translateY(-50%);
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--accent-primary) 30%, var(--accent-secondary) 100%);
  box-shadow: 0 0 12px rgba(var(--accent-primary-rgb), 0.5);
}

body.lang-ar .chd, body.lang-ar .phd,
body.lang-fa .chd, body.lang-fa .phd { left: auto; right: -36px; }

.ch h2, .ph h2 {
  font-size: 20px;
  font-weight: var(--font-weight-semibold);
  color: var(--white);
  letter-spacing: 0.3px;
  margin-bottom: 6px;
}

.ch-dates {
  font-size: var(--font-size-badge);
  font-weight: var(--font-weight-semibold);
  letter-spacing: 1.5px;
  text-transform: uppercase;
  color: var(--accent-primary);
  opacity: 0.7;
  margin-bottom: 8px;
}

.ch-overview {
  font-size: var(--font-size-small);
  color: var(--text-primary);
  margin-bottom: 20px;
  line-height: 1.6;
}


/* ══════════════════════════════════════
   Event Card
   ══════════════════════════════════════ */

/* Event fade-in: pure CSS sequential animation.
   Each event fades in with a staggered delay based on its position.
   No JavaScript needed — uses nth-child for sequencing. */
.ev {
  position: relative;
  margin-bottom: 16px;
  opacity: 0;
  transform: translateY(16px);
  animation: evFadeIn 0.5s ease forwards;
  animation-play-state: paused;
}

/* Start animations when events scroll into view (via CSS scroll-driven
   animation where supported, with JS .visible fallback) */
.ev.visible {
  animation-play-state: running;
}

/* Staggered delays — events appear in sequence, not all at once */
.ev:nth-child(1) { animation-delay: 0s; }
.ev:nth-child(2) { animation-delay: 0.08s; }
.ev:nth-child(3) { animation-delay: 0.16s; }
.ev:nth-child(4) { animation-delay: 0.24s; }
.ev:nth-child(5) { animation-delay: 0.32s; }
.ev:nth-child(6) { animation-delay: 0.4s; }
.ev:nth-child(7) { animation-delay: 0.48s; }
.ev:nth-child(8) { animation-delay: 0.56s; }
.ev:nth-child(9) { animation-delay: 0.64s; }
.ev:nth-child(10) { animation-delay: 0.72s; }
/* Events beyond 10 use max delay */
.ev:nth-child(n+11) { animation-delay: 0.8s; }

@keyframes evFadeIn {
  to { opacity: 1; transform: translateY(0); }
}

/* Event dot */
.ed {
  position: absolute;
  left: -33px;
  top: 20px;
  width: 10px;
  height: 10px;
  border-radius: 50%;
  border: 2px solid rgba(255, 255, 255, 0.2);
  transition: transform 0.3s, box-shadow 0.3s;
}

body.lang-ar .ed,
body.lang-fa .ed { left: auto; right: -33px; }

.ev:hover .ed {
  transform: scale(1.4);
}

/* Event card body */
.cd {
  background: rgba(8, 14, 16, 0.68);
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 12px;
  padding: 18px 22px;
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.04),
    0 2px 12px rgba(0, 0, 0, 0.25);
  transition: transform 0.35s cubic-bezier(0.25, 0.46, 0.45, 0.94),
              border-color 0.3s,
              box-shadow 0.35s cubic-bezier(0.25, 0.46, 0.45, 0.94),
              background 0.3s;
  position: relative;
  overflow: hidden;
}

.cd::before {
  content: '';
  position: absolute;
  inset: 0;
  background: linear-gradient(135deg, rgba(var(--accent-primary-rgb), 0) 0%, rgba(57, 223, 170, 0) 100%);
  border-radius: 12px;
  transition: background 0.4s;
  pointer-events: none;
}

.cd:hover {
  transform: translateX(6px) scale(1.01);
  border-color: rgba(var(--accent-primary-rgb), 0.3);
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.06),
    0 8px 32px rgba(var(--accent-primary-rgb), 0.12),
    0 2px 12px rgba(0, 0, 0, 0.3);
  background: rgba(8, 14, 16, 0.78);
}

body.lang-ar .cd:hover,
body.lang-fa .cd:hover { transform: translateX(-6px) scale(1.01); }

.cd:hover::before {
  background: linear-gradient(135deg, rgba(var(--accent-primary-rgb), 0.04) 0%, rgba(57, 223, 170, 0.02) 100%);
}

/* Event card content */
.cdy {
  font-size: var(--font-size-badge);
  font-weight: var(--font-weight-semibold);
  letter-spacing: 1.5px;
  text-transform: uppercase;
  color: var(--accent-primary);
  opacity: 0.7;
  margin-bottom: 4px;
}

.ctt {
  font-size: var(--font-size-body);
  font-weight: var(--font-weight-semibold);
  color: var(--white);
  margin-bottom: 6px;
  line-height: 1.4;
}

.cds {
  font-size: var(--font-size-small);
  color: var(--text-primary);
  line-height: 1.7;
  opacity: 0.88;
  margin-bottom: 8px;
}


/* ══════════════════════════════════════
   Expand/Collapse
   ══════════════════════════════════════ */

.cex {
  max-height: 0;
  overflow: hidden;
  transition: max-height 0.4s cubic-bezier(0.25, 0.46, 0.45, 0.94), opacity 0.3s;
  opacity: 0;
}

.cex.open { opacity: 1; }

.exc {
  padding-top: 12px;
  margin-top: 12px;
  border-top: 1px solid rgba(255, 255, 255, 0.06);
}

.exl {
  font-size: var(--font-size-badge);
  font-weight: var(--font-weight-semibold);
  letter-spacing: 1.5px;
  text-transform: uppercase;
  color: var(--accent-primary);
  opacity: 0.6;
  margin-bottom: 6px;
}

.ext {
  font-size: var(--font-size-small);
  color: var(--text-secondary);
  line-height: 1.8;
}

/* Toggle button */
.ctg {
  display: flex;
  align-items: center;
  gap: 4px;
  font-size: var(--font-size-badge);
  font-weight: var(--font-weight-medium);
  color: var(--accent-primary);
  opacity: 0.5;
  margin-top: 8px;
  cursor: pointer;
  transition: opacity 0.2s;
  user-select: none;
}

.ctg:hover { opacity: 0.9; }
.ctg svg { width: 12px; height: 12px; transition: transform 0.3s; }
.ctg.open svg { transform: rotate(180deg); }


/* ══════════════════════════════════════
   Faction Tags
   ══════════════════════════════════════ */

.faction-tags {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  margin-top: 8px;
}

.faction-tag {
  font-size: var(--font-size-badge);
  font-weight: var(--font-weight-semibold);
  padding: 4px 10px;
  border-radius: 12px;
  letter-spacing: 0.5px;
}


/* ══════════════════════════════════════
   Quote (in-timeline)
   ══════════════════════════════════════ */

.quote {
  border-left: 2px solid rgba(var(--accent-primary-rgb), 0.3);
  padding-left: 16px;
  margin: 12px 0;
  font-style: italic;
  font-size: var(--font-size-small);
  color: var(--text-secondary);
  line-height: 1.7;
}

body.lang-ar .quote,
body.lang-fa .quote {
  border-left: none;
  border-right: 2px solid rgba(var(--accent-primary-rgb), 0.3);
  padding-left: 0;
  padding-right: 16px;
}


/* ══════════════════════════════════════
   Timeline Divider
   ══════════════════════════════════════ */

.fl {
  width: 60px;
  height: 3px;
  background: linear-gradient(135deg, var(--accent-primary) 30%, var(--accent-secondary) 100%);
  border-radius: 2px;
  margin: 0 auto 16px;
}


/* ══════════════════════════════════════
   Mobile
   ══════════════════════════════════════ */

@media (max-width: 600px) {
  .tl { padding-left: 30px; }
  body.lang-ar .tl,
  body.lang-fa .tl { padding-left: 0; padding-right: 30px; }

  .ed { left: -27px; }
  body.lang-ar .ed,
  body.lang-fa .ed { left: auto; right: -27px; }

  .chd, .phd { left: -30px; }
  body.lang-ar .chd, body.lang-ar .phd,
  body.lang-fa .chd, body.lang-fa .phd { left: auto; right: -30px; }

  .cd { padding: 14px 16px; }
  .ctt { font-size: var(--font-size-small); }
  .cd:hover { transform: translateX(3px) scale(1.005); }
  body.lang-ar .cd:hover,
  body.lang-fa .cd:hover { transform: translateX(-3px) scale(1.005); }
}
