/* ====================================================================
   Scrollytelling — Inverted color scheme, fixed viz canvas, prose sections
   ==================================================================== */

/* --- Invert the color palette for the entire page --- */
.scrollytelling-page {
  --bg-color: #0c0c0c;
  --ink-color: #E2E0D6;
}

body.scrollytelling-page {
  background: var(--bg-color);
  color: var(--ink-color);
  display: block;
  margin: 0;
  padding: 0;
  overflow-x: hidden;
}

/* Scroll lock during loading */
body.scroll-locked {
  overflow: hidden;
}

/* Hide noise overlay on scrollytelling pages */
body.scrollytelling-page .noise-overlay {
  display: none;
}

/* --- Inverted header (full viewport title card) --- */
.scrolly-header {
  min-height: 100vh;
  background: var(--bg-color);
  color: var(--ink-color);
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
  padding: 60px 40px 80px;
  position: relative;
  z-index: 1;
}

/* Hero gradient: transparent top → opaque bottom for text readability */
.scrolly-header.has-hero {
  background: transparent;
}

.scrolly-header.has-hero::after {
  content: "";
  position: absolute;
  inset: 0;
  background: linear-gradient(
    to bottom,
    transparent 0%,
    transparent 30%,
    rgba(12, 12, 12, 0.6) 60%,
    var(--bg-color) 100%
  );
  pointer-events: none;
  z-index: -1;
}

.scrolly-brand {
  font-family: var(--font-main);
  font-weight: 900;
  font-size: 2rem;
  line-height: 0.85;
  letter-spacing: -0.05em;
  text-transform: uppercase;
  color: inherit;
  text-decoration: none;
  display: block;
  margin-bottom: 60px;
}

.scrolly-meta {
  max-width: 720px;
}

.scrolly-title {
  font-family: et-book, Palatino, "Palatino Linotype", "Palatino LT STD",
    "Book Antiqua", Georgia, serif;
  font-weight: 400;
  font-style: italic;
  font-size: 3rem;
  line-height: 1.1;
  margin: 12px 0 20px;
}

.scrolly-excerpt {
  font-family: et-book, Palatino, "Palatino Linotype", "Palatino LT STD",
    "Book Antiqua", Georgia, serif;
  font-size: 1.3rem;
  line-height: 1.5;
  opacity: 0.8;
  margin-bottom: 24px;
}

.scrolly-header .post-author {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-top: 16px;
}

.scrolly-header .post-author-avatar {
  filter: grayscale(100%) sepia(30%) contrast(1.1);
}

.scrolly-header .post-author-name {
  color: inherit;
}

/* --- Fixed viz canvas (always fullscreen behind content) --- */
#scrolly-canvas {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
  touch-action: auto !important;
  pointer-events: none;
  z-index: 0;
  opacity: 0;
  transition: opacity 0.8s ease;
}

#scrolly-canvas.visible {
  opacity: 1;
}

/* --- Scroll-driven video (replaces canvas for video mode) --- */
#scrolly-video,
#scrolly-hero-video {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
  object-fit: cover;
  pointer-events: none;
  z-index: 0;
  opacity: 0;
  transition: opacity 0.8s ease;
}

#scrolly-video.visible,
#scrolly-hero-video.visible {
  opacity: 1;
}

/* --- Scrolly container --- */
#scrolly-container {
  position: relative;
  width: 100%;
}

/* --- Scroll container --- */
#scrolly-scroll {
  position: relative;
}

/* --- Visual segment spacers (transparent, viz visible) --- */
.scrolly-segment {
  position: relative;
  pointer-events: none;
}

/* --- Floating prose card (over visual segments) --- */
.scrolly-prose-card {
  position: absolute;
  left: 0;
  right: 0;
  z-index: 6;
  padding: 28px 40px;
  background: var(--bg-color);
  color: var(--ink-color);
  pointer-events: auto;
}

.scrolly-prose-card-inner {
  max-width: 900px;
  margin: 0 auto;
}

/* --- Prose sections (opaque, inverted, Tufte-styled) --- */
.scrolly-prose-segment {
  background: var(--bg-color);
  color: var(--ink-color);
  position: relative;
  z-index: 2;
  padding: 28px 40px;
}

.scrolly-prose-inner {
  max-width: 900px;
  margin: 0 auto;
}

/* --- Tufte overrides for inverted colors --- */
.scrolly-prose-inner.tufte-content hr {
  border-top-color: rgba(226, 224, 214, 0.3);
}

.scrolly-prose-inner.tufte-content a:link,
.scrolly-prose-inner.tufte-content a:visited {
  color: inherit;
}

.scrolly-prose-inner.tufte-content .sidenote::after,
.scrolly-prose-inner.tufte-content .marginnote::after {
  border-bottom-color: var(--ink-color);
}

/* --- Progress bar --- */
.scrolly-progress {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  height: 2px;
  z-index: 10;
  transition: opacity 0.5s ease;
}

.scrolly-progress.done {
  opacity: 0;
  pointer-events: none;
}

.scrolly-progress-fill {
  width: 100%;
  height: 100%;
  background: var(--ink-color);
  transform: scaleX(0);
  transform-origin: left;
  transition: transform 0.3s ease-out;
}

/* --- Scroll indicator --- */
.scrolly-scroll-indicator {
  position: fixed;
  bottom: 32px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 10;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  opacity: 1;
  transition: opacity 0.5s ease;
  pointer-events: none;
}

.scrolly-scroll-indicator.hidden {
  opacity: 0;
}

.scrolly-scroll-indicator span {
  font-family: var(--font-main);
  font-size: 11px;
  color: var(--ink-color);
  letter-spacing: 0.05em;
  text-transform: uppercase;
}

.scrolly-scroll-indicator .arrow {
  width: 20px;
  height: 20px;
  border-left: 1px solid var(--ink-color);
  border-bottom: 1px solid var(--ink-color);
  transform: rotate(-45deg);
  animation: scrolly-bounce 2s ease infinite;
}

@keyframes scrolly-bounce {
  0%,
  20%,
  50%,
  80%,
  100% {
    transform: rotate(-45deg) translateY(0);
  }
  40% {
    transform: rotate(-45deg) translateY(6px);
  }
  60% {
    transform: rotate(-45deg) translateY(3px);
  }
}

/* --- Comments on scrolly pages --- */
.scrolly-comments {
  background: var(--bg-color);
  color: var(--ink-color);
  position: relative;
  z-index: 1;
  padding: 40px 40px 0;
  border-top: 1px solid rgba(226, 224, 214, 0.3);
}

/* Don't reset sidenote counter per-section — use one continuous count */
.scrolly-prose-inner.tufte-content,
.scrolly-prose-card-inner.tufte-content {
  counter-reset: none;
}

/* Hide comments and footer until viz is ready (prevents flash during load) */
.scroll-locked .scrolly-comments,
.scroll-locked .site-footer {
  display: none;
}

/* --- Footer on scrolly pages --- */
.scrollytelling-page .site-footer {
  background: var(--bg-color);
  color: var(--ink-color);
  border-top-color: var(--ink-color);
  position: relative;
  z-index: 1;
}

/* --- Responsive --- */
@media (max-width: 760px) {
  .scrolly-header {
    padding: 30px 20px 60px;
  }

  .scrolly-title {
    font-size: 2rem;
  }

  .scrolly-excerpt {
    font-size: 1.1rem;
  }

  .scrolly-prose-segment {
    padding: 20px 20px;
  }

  .scrolly-prose-inner.tufte-content p,
  .scrolly-prose-inner.tufte-content footer,
  .scrolly-prose-inner.tufte-content table,
  .scrolly-prose-inner.tufte-content hr {
    width: 100%;
  }

  .scrolly-prose-inner.tufte-content dl,
  .scrolly-prose-inner.tufte-content ol,
  .scrolly-prose-inner.tufte-content ul {
    width: 90%;
  }

  .scrolly-prose-inner.tufte-content figure {
    max-width: 90%;
  }

  .scrolly-prose-inner.tufte-content blockquote {
    width: auto;
  }
}

/* --- Inverted mark/highlight for dark background --- */
.scrolly-prose-inner.tufte-content mark,
.scrolly-prose-card-inner.tufte-content mark {
  background-color: rgba(226, 224, 214, 0.15);
  color: inherit;
}

/* --- Image overlay title --- */
.story-image-title {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  text-align: center;
  padding: 40px 20px;
  background: linear-gradient(to bottom, transparent, rgba(0, 0, 0, 0.7));
  font-family: et-book, Palatino, "Palatino Linotype", "Palatino LT STD",
    "Book Antiqua", Georgia, serif;
  font-style: italic;
  font-weight: 400;
  font-size: 2.5rem;
  color: #fff;
  opacity: 0;
  pointer-events: none;
}

@media (max-width: 760px) {
  .story-image-title {
    font-size: 1.6rem;
    padding: 30px 16px;
  }
}

/* --- Reduced motion --- */
@media (prefers-reduced-motion: reduce) {
  .scrolly-scroll-indicator .arrow {
    animation: none;
  }
}
