/* =====================================================================
   RIA — LANDING 3D SCROLLYTELLING
   Apple-grade scroll-driven scene: a research paper floating in 3D
   space that tilts, opens, and highlights regions as the user scrolls,
   eventually morphing into the risk-score card.

   No WebGL / Three.js — pure CSS 3D + scroll-progress CSS variables
   set by landing-3d.js. The scene pins on a sticky track so the user
   stays in control of pace; nothing is hijacked.

   Layout per breakpoint:
     • >=900px : split — caption column (left) + pinned paper (right)
     • <900px  : stacked — paper above, caption below, shorter scroll

   Stages are read from --stage (0..6) and progress within from
   --progress (0..1). Selectors fire transitions on those CSS vars.
   ===================================================================== */

.scroll-scene {
  --progress: 0;
  --stage: 0;
  position: relative;
  height: 700vh;            /* 7 stages x 100vh of scroll budget */
  margin: 6rem 0 4rem;
  isolation: isolate;
  overflow-x: clip;
}

.scroll-scene-track {
  position: sticky;
  top: 0;
  height: 100vh;
  display: grid;
  grid-template-columns: minmax(320px, 1fr) minmax(320px, 1.05fr);
  gap: 3rem;
  align-items: center;
  padding: 0 clamp(1rem, 4vw, 4rem);
  perspective: 1600px;
  perspective-origin: 60% 45%;
}

@media (max-width: 899px) {
  .scroll-scene { height: 420vh; }
  .scroll-scene-track {
    grid-template-columns: 1fr;
    gap: 1.5rem;
    align-content: center;
  }
}

/* ── Left: scrolling captions ────────────────────────────────────────── */
.scroll-scene-text {
  position: relative;
  height: 100vh;
  display: flex;
  flex-direction: column;
  justify-content: center;
}
.scroll-panel {
  position: absolute;
  left: 0; right: 0;
  top: 50%;
  transform: translateY(-50%);
  opacity: 0;
  transition: opacity 0.45s cubic-bezier(0.16, 1, 0.3, 1),
              transform 0.55s cubic-bezier(0.16, 1, 0.3, 1);
  pointer-events: none;
}
.scroll-panel[data-stage="0"] { transform: translateY(calc(-50% + 18px)); }
.scroll-panel[data-stage="1"] { transform: translateY(calc(-50% + 18px)); }
.scroll-panel[data-stage="2"] { transform: translateY(calc(-50% + 18px)); }
.scroll-panel[data-stage="3"] { transform: translateY(calc(-50% + 18px)); }
.scroll-panel[data-stage="4"] { transform: translateY(calc(-50% + 18px)); }
.scroll-panel[data-stage="5"] { transform: translateY(calc(-50% + 18px)); }
.scroll-panel[data-stage="6"] { transform: translateY(calc(-50% + 18px)); }

/* Active panel by --stage */
.scroll-scene[style*="--stage: 0"] .scroll-panel[data-stage="0"],
.scroll-scene[style*="--stage:0"]   .scroll-panel[data-stage="0"],
.scroll-scene[style*="--stage: 1"] .scroll-panel[data-stage="1"],
.scroll-scene[style*="--stage:1"]   .scroll-panel[data-stage="1"],
.scroll-scene[style*="--stage: 2"] .scroll-panel[data-stage="2"],
.scroll-scene[style*="--stage:2"]   .scroll-panel[data-stage="2"],
.scroll-scene[style*="--stage: 3"] .scroll-panel[data-stage="3"],
.scroll-scene[style*="--stage:3"]   .scroll-panel[data-stage="3"],
.scroll-scene[style*="--stage: 4"] .scroll-panel[data-stage="4"],
.scroll-scene[style*="--stage:4"]   .scroll-panel[data-stage="4"],
.scroll-scene[style*="--stage: 5"] .scroll-panel[data-stage="5"],
.scroll-scene[style*="--stage:5"]   .scroll-panel[data-stage="5"],
.scroll-scene[style*="--stage: 6"] .scroll-panel[data-stage="6"],
.scroll-scene[style*="--stage:6"]   .scroll-panel[data-stage="6"] {
  opacity: 1;
  transform: translateY(-50%);
}

.scroll-eyebrow {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  font-family: var(--font-mono, ui-monospace, monospace);
  font-size: 0.72rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.18em;
  color: var(--text-muted);
  margin-bottom: 0.85rem;
}
.scroll-eyebrow .num {
  color: var(--accent-color, #22d3ee);
  font-weight: 700;
}
.scroll-panel h3 {
  font-family: var(--font-sans);
  font-size: clamp(1.7rem, 1.4vw + 1.2rem, 2.6rem);
  font-weight: 800;
  letter-spacing: -0.035em;
  line-height: 1.05;
  margin: 0 0 0.85rem;
  background: linear-gradient(180deg, #fff 0%, rgba(237,237,239,0.7) 100%);
  -webkit-background-clip: text;
          background-clip: text;
  -webkit-text-fill-color: transparent;
  max-width: 22ch;
}
.scroll-panel p {
  color: var(--text-secondary);
  font-size: 1.02rem;
  line-height: 1.55;
  margin: 0;
  max-width: 42ch;
  letter-spacing: -0.005em;
}
.scroll-panel .stat {
  display: inline-block;
  margin-top: 1rem;
  font-family: var(--font-mono, monospace);
  font-size: 0.85rem;
  color: var(--accent-color);
  background: rgba(34, 211, 238, 0.08);
  padding: 0.3rem 0.75rem;
  border-radius: 999px;
  border: 1px solid rgba(34, 211, 238, 0.2);
}

/* Stage progress dots */
.scroll-scene-progress {
  display: flex;
  gap: 0.4rem;
  margin-top: 1.3rem;
}
.scroll-scene-progress .dot {
  width: 22px;
  height: 3px;
  border-radius: 2px;
  background: rgba(255,255,255,0.15);
  transition: background 0.3s ease, transform 0.3s ease;
}
.scroll-scene[style*="--stage: 0"] .scroll-scene-progress .dot:nth-child(1),
.scroll-scene[style*="--stage:0"]  .scroll-scene-progress .dot:nth-child(1),
.scroll-scene[style*="--stage: 1"] .scroll-scene-progress .dot:nth-child(2),
.scroll-scene[style*="--stage:1"]  .scroll-scene-progress .dot:nth-child(2),
.scroll-scene[style*="--stage: 2"] .scroll-scene-progress .dot:nth-child(3),
.scroll-scene[style*="--stage:2"]  .scroll-scene-progress .dot:nth-child(3),
.scroll-scene[style*="--stage: 3"] .scroll-scene-progress .dot:nth-child(4),
.scroll-scene[style*="--stage:3"]  .scroll-scene-progress .dot:nth-child(4),
.scroll-scene[style*="--stage: 4"] .scroll-scene-progress .dot:nth-child(5),
.scroll-scene[style*="--stage:4"]  .scroll-scene-progress .dot:nth-child(5),
.scroll-scene[style*="--stage: 5"] .scroll-scene-progress .dot:nth-child(6),
.scroll-scene[style*="--stage:5"]  .scroll-scene-progress .dot:nth-child(6),
.scroll-scene[style*="--stage: 6"] .scroll-scene-progress .dot:nth-child(7),
.scroll-scene[style*="--stage:6"]  .scroll-scene-progress .dot:nth-child(7) {
  background: linear-gradient(90deg, var(--primary-color), var(--accent-color));
  transform: scaleX(1.4);
}

/* ── Right: pinned 3D paper scene ────────────────────────────────────── */
.scroll-scene-stage {
  position: relative;
  height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  transform-style: preserve-3d;
}

.paper-3d {
  position: relative;
  width: clamp(280px, 32vw, 460px);
  aspect-ratio: 0.74;
  transform-style: preserve-3d;
  transform:
    /* progress 0 → flat facing camera; 1 → tilted, lifted, slightly orbited */
    translateZ(calc(var(--progress) * 60px))
    translateY(calc((var(--progress) - 0.5) * -40px))
    rotateX(calc(var(--progress) * 14deg + 4deg))
    rotateY(calc(-12deg + var(--progress) * 32deg))
    rotateZ(calc((var(--progress) - 0.5) * -3deg));
  transition: transform 0.45s cubic-bezier(0.16, 1, 0.3, 1);
  will-change: transform;
}

.paper-3d::before {
  /* Soft floor shadow that grows with lift */
  content: "";
  position: absolute;
  left: 12%;
  right: 12%;
  bottom: -32px;
  height: 26px;
  background: radial-gradient(ellipse at center, rgba(0,0,0,0.55), transparent 70%);
  filter: blur(14px);
  opacity: calc(0.4 + var(--progress) * 0.4);
  transform: translateZ(-30px);
  pointer-events: none;
}

/* The page itself */
.paper-page {
  position: absolute;
  inset: 0;
  border-radius: 14px;
  background: linear-gradient(180deg, #f8f8f5 0%, #ececea 100%);
  box-shadow:
    0 30px 60px -20px rgba(0,0,0,0.6),
    0 12px 24px -12px rgba(0,0,0,0.4),
    inset 0 1px 0 rgba(255,255,255,0.8);
  overflow: hidden;
  transform-style: preserve-3d;
}
.paper-page::before {
  /* paper grain / subtle texture */
  content: "";
  position: absolute;
  inset: 0;
  background-image:
    repeating-linear-gradient(0deg,
      transparent 0px, transparent 13px,
      rgba(0,0,0,0.025) 13px, rgba(0,0,0,0.025) 14px);
  pointer-events: none;
}

/* Header strip with title + author lines */
.paper-content {
  position: absolute;
  inset: 8% 7%;
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
  color: #1a1a1a;
}
.paper-title {
  font-family: 'Inter', system-ui, sans-serif;
  font-weight: 800;
  font-size: clamp(0.9rem, 1.4vw, 1.18rem);
  letter-spacing: -0.025em;
  line-height: 1.15;
  color: #0a0a0a;
  margin-bottom: 0.4rem;
}
.paper-line {
  height: 6px;
  border-radius: 2px;
  background: rgba(10, 10, 10, 0.18);
}
.paper-line.short  { width: 55%; }
.paper-line.medium { width: 78%; }
.paper-line.full   { width: 100%; }
.paper-line.tiny   { width: 30%; }

.paper-section-label {
  font-family: ui-monospace, Menlo, monospace;
  font-size: 0.55rem;
  text-transform: uppercase;
  letter-spacing: 0.16em;
  color: rgba(10, 10, 10, 0.45);
  margin-top: 0.4rem;
  padding-bottom: 0.15rem;
  border-bottom: 1px solid rgba(10,10,10,0.1);
}

/* ── Highlight overlays — one per stage, scanning the page ───────────── */
.paper-highlight {
  position: absolute;
  left: 4%;
  right: 4%;
  border-radius: 8px;
  border: 2px solid;
  opacity: 0;
  transform: translateZ(20px) scale(0.96);
  transition: opacity 0.5s cubic-bezier(0.16, 1, 0.3, 1),
              transform 0.5s cubic-bezier(0.16, 1, 0.3, 1);
  pointer-events: none;
  display: flex;
  align-items: flex-end;
  padding: 0.4rem 0.7rem;
}
.paper-highlight .label {
  font-family: ui-monospace, Menlo, monospace;
  font-size: 0.6rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.12em;
  padding: 0.2rem 0.5rem;
  border-radius: 4px;
  color: #fff;
  white-space: nowrap;
}

.paper-highlight[data-on="1"] {
  /* Authorship region — top */
  top: 19%; height: 14%;
  border-color: #f87171;
  background: rgba(248,113,113,0.16);
  box-shadow: 0 0 30px rgba(248,113,113,0.45),
              inset 0 0 14px rgba(248,113,113,0.18);
}
.paper-highlight[data-on="1"] .label { background: #f87171; }

.paper-highlight[data-on="2"] {
  /* Funding region — middle */
  top: 38%; height: 14%;
  border-color: #fbbf24;
  background: rgba(251,191,36,0.16);
  box-shadow: 0 0 30px rgba(251,191,36,0.45),
              inset 0 0 14px rgba(251,191,36,0.18);
}
.paper-highlight[data-on="2"] .label { background: #f59e0b; }

.paper-highlight[data-on="3"] {
  /* Methodology region — lower-middle */
  top: 56%; height: 16%;
  border-color: #a78bfa;
  background: rgba(167,139,250,0.16);
  box-shadow: 0 0 30px rgba(167,139,250,0.45),
              inset 0 0 14px rgba(167,139,250,0.18);
}
.paper-highlight[data-on="3"] .label { background: #8b5cf6; }
.paper-highlight[data-on="4"] {
  top: 72%; height: 10%;
  border-color: #22d3ee;
  background: rgba(34,211,238,0.14);
  box-shadow: 0 0 30px rgba(34,211,238,0.38),
              inset 0 0 14px rgba(34,211,238,0.16);
}
.paper-highlight[data-on="4"] .label { background: #0891b2; }
.paper-highlight[data-on="5"] {
  top: 83%; height: 10%;
  border-color: #34d399;
  background: rgba(52,211,153,0.14);
  box-shadow: 0 0 30px rgba(52,211,153,0.34),
              inset 0 0 14px rgba(52,211,153,0.16);
}
.paper-highlight[data-on="5"] .label { background: #059669; }

/* Show highlight when its index ≤ current stage but only the
   active one keeps the scaled-up label. */
.scroll-scene[style*="--stage: 1"] .paper-highlight[data-on="1"],
.scroll-scene[style*="--stage:1"]  .paper-highlight[data-on="1"],
.scroll-scene[style*="--stage: 2"] .paper-highlight[data-on="1"],
.scroll-scene[style*="--stage:2"]  .paper-highlight[data-on="1"],
.scroll-scene[style*="--stage: 2"] .paper-highlight[data-on="2"],
.scroll-scene[style*="--stage:2"]  .paper-highlight[data-on="2"],
.scroll-scene[style*="--stage: 3"] .paper-highlight[data-on="1"],
.scroll-scene[style*="--stage:3"]  .paper-highlight[data-on="1"],
.scroll-scene[style*="--stage: 3"] .paper-highlight[data-on="2"],
.scroll-scene[style*="--stage:3"]  .paper-highlight[data-on="2"],
.scroll-scene[style*="--stage: 3"] .paper-highlight[data-on="3"],
.scroll-scene[style*="--stage:3"]  .paper-highlight[data-on="3"],
.scroll-scene[style*="--stage: 4"] .paper-highlight[data-on="1"],
.scroll-scene[style*="--stage:4"]  .paper-highlight[data-on="1"],
.scroll-scene[style*="--stage: 4"] .paper-highlight[data-on="2"],
.scroll-scene[style*="--stage:4"]  .paper-highlight[data-on="2"],
.scroll-scene[style*="--stage: 4"] .paper-highlight[data-on="3"],
.scroll-scene[style*="--stage:4"]  .paper-highlight[data-on="3"],
.scroll-scene[style*="--stage: 4"] .paper-highlight[data-on="4"],
.scroll-scene[style*="--stage:4"]  .paper-highlight[data-on="4"],
.scroll-scene[style*="--stage: 5"] .paper-highlight,
.scroll-scene[style*="--stage:5"]  .paper-highlight,
.scroll-scene[style*="--stage: 6"] .paper-highlight,
.scroll-scene[style*="--stage:6"]  .paper-highlight {
  opacity: 1;
  transform: translateZ(20px) scale(1);
}

/* ── Scan beam: a horizontal line that sweeps the page on stages 1-3 ─── */
.paper-scan {
  position: absolute;
  left: 0; right: 0;
  height: 80px;
  background: linear-gradient(180deg,
    rgba(34,211,238,0) 0%,
    rgba(34,211,238,0.15) 30%,
    rgba(167,139,250,0.4) 50%,
    rgba(34,211,238,0.15) 70%,
    rgba(34,211,238,0) 100%);
  filter: blur(2px);
  opacity: 0;
  pointer-events: none;
  top: calc(var(--progress) * 100% - 40px);
  transition: opacity 0.4s ease;
  mix-blend-mode: screen;
}
.scroll-scene[style*="--stage: 1"] .paper-scan,
.scroll-scene[style*="--stage:1"]  .paper-scan,
.scroll-scene[style*="--stage: 2"] .paper-scan,
.scroll-scene[style*="--stage:2"]  .paper-scan,
.scroll-scene[style*="--stage: 3"] .paper-scan,
.scroll-scene[style*="--stage:3"]  .paper-scan,
.scroll-scene[style*="--stage: 4"] .paper-scan,
.scroll-scene[style*="--stage:4"]  .paper-scan,
.scroll-scene[style*="--stage: 5"] .paper-scan,
.scroll-scene[style*="--stage:5"]  .paper-scan {
  opacity: 0.7;
}

/* ── Evidence console: grows as the investigation deepens ───────────── */
.evidence-console {
  position: absolute;
  right: -6%;
  top: 8%;
  width: min(240px, 42vw);
  padding: 0.85rem;
  border: 1px solid rgba(255,255,255,0.1);
  border-radius: 12px;
  background: rgba(9, 9, 13, 0.72);
  backdrop-filter: blur(18px);
  -webkit-backdrop-filter: blur(18px);
  box-shadow: 0 24px 60px -30px rgba(0,0,0,0.7);
  transform: translateZ(90px) translateX(18px);
  opacity: 0;
  transition: opacity 0.45s cubic-bezier(0.16, 1, 0.3, 1),
              transform 0.45s cubic-bezier(0.16, 1, 0.3, 1);
}
.console-head {
  display: flex;
  justify-content: space-between;
  gap: 1rem;
  color: var(--text-muted);
  font-family: ui-monospace, Menlo, monospace;
  font-size: 0.62rem;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  margin-bottom: 0.7rem;
}
.console-head strong { color: var(--success-color, #34d399); }
.console-row {
  display: flex;
  align-items: center;
  gap: 0.55rem;
  min-height: 32px;
  color: rgba(237,237,239,0.82);
  font-size: 0.78rem;
  border-top: 1px solid rgba(255,255,255,0.06);
  opacity: 0.28;
  transform: translateX(10px);
  transition: opacity 0.35s ease, transform 0.35s cubic-bezier(0.16, 1, 0.3, 1);
}
.console-row span {
  width: 7px;
  height: 7px;
  border-radius: 99px;
  background: currentColor;
  box-shadow: 0 0 12px currentColor;
}
.row-author { color: #f87171; }
.row-funding { color: #fbbf24; }
.row-method { color: #a78bfa; }
.row-venue { color: #22d3ee; }
.row-external { color: #34d399; }
.scroll-scene[style*="--stage: 1"] .evidence-console,
.scroll-scene[style*="--stage:1"]  .evidence-console,
.scroll-scene[style*="--stage: 2"] .evidence-console,
.scroll-scene[style*="--stage:2"]  .evidence-console,
.scroll-scene[style*="--stage: 3"] .evidence-console,
.scroll-scene[style*="--stage:3"]  .evidence-console,
.scroll-scene[style*="--stage: 4"] .evidence-console,
.scroll-scene[style*="--stage:4"]  .evidence-console,
.scroll-scene[style*="--stage: 5"] .evidence-console,
.scroll-scene[style*="--stage:5"]  .evidence-console,
.scroll-scene[style*="--stage: 6"] .evidence-console,
.scroll-scene[style*="--stage:6"]  .evidence-console {
  opacity: 1;
  transform: translateZ(90px) translateX(0);
}
.scroll-scene[style*="--stage: 1"] .row-author,
.scroll-scene[style*="--stage:1"]  .row-author,
.scroll-scene[style*="--stage: 2"] .row-author,
.scroll-scene[style*="--stage:2"]  .row-author,
.scroll-scene[style*="--stage: 2"] .row-funding,
.scroll-scene[style*="--stage:2"]  .row-funding,
.scroll-scene[style*="--stage: 3"] .row-author,
.scroll-scene[style*="--stage:3"]  .row-author,
.scroll-scene[style*="--stage: 3"] .row-funding,
.scroll-scene[style*="--stage:3"]  .row-funding,
.scroll-scene[style*="--stage: 3"] .row-method,
.scroll-scene[style*="--stage:3"]  .row-method,
.scroll-scene[style*="--stage: 4"] .console-row,
.scroll-scene[style*="--stage:4"]  .console-row,
.scroll-scene[style*="--stage: 5"] .console-row,
.scroll-scene[style*="--stage:5"]  .console-row,
.scroll-scene[style*="--stage: 6"] .console-row,
.scroll-scene[style*="--stage:6"]  .console-row {
  opacity: 1;
  transform: translateX(0);
}

/* ── Stage 4: the gauge that emerges in front of the paper ───────────── */
.paper-gauge {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0;
  transform: translateZ(70px) scale(0.6);
  transition: opacity 0.55s cubic-bezier(0.16, 1, 0.3, 1),
              transform 0.55s cubic-bezier(0.34, 1.56, 0.64, 1);
  pointer-events: none;
}
.paper-gauge .ring {
  width: 70%;
  aspect-ratio: 1;
  border-radius: 50%;
  background:
    conic-gradient(
      from -90deg,
      #ef4444 0deg,
      #f59e0b 110deg,
      #fbbf24 130deg,
      rgba(255,255,255,0.08) 130deg,
      rgba(255,255,255,0.08) 360deg
    );
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
  box-shadow:
    0 0 0 1px rgba(255,255,255,0.06),
    0 30px 60px -20px rgba(248,113,113,0.45);
}
.paper-gauge .ring::before {
  content: "";
  position: absolute;
  inset: 14%;
  border-radius: 50%;
  background: linear-gradient(180deg, #1a1a22 0%, #0e0e14 100%);
  border: 1px solid rgba(255,255,255,0.06);
}
.paper-gauge .num {
  position: relative;
  z-index: 1;
  font-family: var(--font-sans);
  font-size: clamp(2.4rem, 4vw, 4rem);
  font-weight: 800;
  letter-spacing: -0.04em;
  background: linear-gradient(180deg, #fff 0%, rgba(255,255,255,0.7) 100%);
  -webkit-background-clip: text;
          background-clip: text;
  -webkit-text-fill-color: transparent;
}
.paper-gauge .num::after {
  content: " / 100";
  font-size: 0.32em;
  color: var(--text-muted);
  font-weight: 500;
  letter-spacing: 0;
  -webkit-text-fill-color: var(--text-muted);
}
.paper-gauge .verdict {
  position: absolute;
  bottom: 8%;
  left: 0; right: 0;
  text-align: center;
  font-family: ui-monospace, Menlo, monospace;
  font-size: 0.7rem;
  font-weight: 700;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: #f87171;
}

.scroll-scene[style*="--stage: 6"] .paper-gauge,
.scroll-scene[style*="--stage:6"]  .paper-gauge {
  opacity: 1;
  transform: translateZ(70px) scale(1);
}
.scroll-scene[style*="--stage: 6"] .paper-page,
.scroll-scene[style*="--stage:6"]  .paper-page {
  opacity: 0.35;
  filter: blur(2px);
  transition: opacity 0.5s ease, filter 0.5s ease;
}

/* ── Ambient glow behind the paper, breathes with progress ───────────── */
.scroll-scene-glow {
  position: absolute;
  width: 120%;
  aspect-ratio: 1;
  left: -10%;
  top: 50%;
  transform: translateY(-50%);
  background: radial-gradient(circle,
    rgba(139,92,246, calc(0.18 + var(--progress) * 0.18)),
    transparent 60%);
  filter: blur(60px);
  z-index: -1;
  pointer-events: none;
  transition: background 0.4s ease;
}

/* ── Reduced motion ──────────────────────────────────────────────────── */
@media (prefers-reduced-motion: reduce) {
  .scroll-scene { height: auto; }
  .scroll-scene-track {
    position: static;
    height: auto;
    padding: 2rem;
  }
  .scroll-panel {
    position: static;
    opacity: 1 !important;
    transform: none !important;
    margin-bottom: 2rem;
  }
  .paper-3d {
    transform: none !important;
  }
  .paper-highlight,
  .evidence-console,
  .paper-gauge,
  .paper-scan {
    transition: none !important;
  }
}
