/* css/story.css — Estructura del recorrido v2 (scroll real + pins de ScrollTrigger) */

:root {
  --veil: #F56597;          /* color del velo (intro) */
  --scrollT: 0;             /* 0..1, lo escribe main.js */
}

/* Lenis (recomendado por la librería) */
html.lenis, html.lenis body { height: auto; }
.lenis.lenis-smooth { scroll-behavior: auto !important; }
.lenis.lenis-smooth [data-lenis-prevent] { overscroll-behavior: contain; }
.lenis.lenis-stopped { overflow: hidden; }

body { background: var(--veil); }
html.is-3d body { background: #111; }

/* Canvas 3D al fondo (lo crea __start__.js) */
#application-canvas {
  position: fixed;
  inset: 0;
  width: 100vw;
  height: 100vh;
  z-index: 0;
  pointer-events: auto;     /* recibe arrastre (órbita) y clics (domLink) */
}

/* Velo: tapa el canvas mientras carga; main.js lo desvanece al empezar el 3D */
#veil {
  position: fixed;
  inset: 0;
  background: var(--veil);
  z-index: 1;
  pointer-events: none;
}

/* El recorrido: deja pasar el ratón al canvas salvo en las tarjetas */
#story {
  position: relative;
  z-index: 3;
  pointer-events: none;
}
.travel-spacer { pointer-events: none; }

.stage {
  height: 100vh;
  width: 100%;
  box-sizing: border-box;
  display: flex;
  align-items: center;
  justify-content: flex-end;
  padding: 2rem 5vw;
  pointer-events: none;
}
@media (max-width: 768px) {
  .stage { justify-content: center; padding: 1rem; }
}

/* Tarjetas: entran al acercarse a su parada y salen al soltarse el pin */
.stage .section-content {
  pointer-events: auto;
  opacity: calc(var(--in, 1) * (1 - var(--out, 0)));
  transform: translateY(calc((1 - var(--in, 1)) * 40px - var(--out, 0) * 40px));
  transition: background .3s ease, box-shadow .3s ease;   /* nada de transiciones en opacity/transform: las pilota el scroll */
}
.stage .section-content:hover { transform: translateY(calc((1 - var(--in, 1)) * 40px - var(--out, 0) * 40px)); }

/* --- Intro: composición en profundidad ---------------------------------------------
   Orden (de atrás a delante): canvas 3D(0) · velo(1) · capas lejanas(2) · tarjeta(3)
   · red neuronal(4) · primer plano desenfocado(5) · barra de carga(6) · cabecera   */
.stage--intro {
  --orb: clamp(170px, 42vh, 360px);
  justify-content: center;
  perspective: 1100px;
}
.intro-stack {
  display: flex;
  flex-direction: column;
  align-items: center;
  transform-style: preserve-3d;
}
.orb-anchor {
  width: var(--orb);
  height: var(--orb);
  margin-bottom: calc(var(--orb) * -0.06);
  pointer-events: none;
}
.intro-card {
  width: min(90vw, 500px);
  max-width: none;
  text-align: left;
  padding: calc(1.4rem + var(--orb) * 0.06) 1.9rem 1.5rem;
  transform-origin: 50% 0%;
  will-change: transform, opacity;
}
.intro-card h1 { letter-spacing: -0.01em; font-size: clamp(1.7rem, 3.4vw, 2.35rem); line-height: 1.12; margin-bottom: .6rem; }
.stage .intro-card p { margin-bottom: 1rem; }
.intro-card .eyebrow {
  display: inline-block;
  font: 600 .78rem/1 var(--font-primary);
  letter-spacing: .12em;
  text-transform: uppercase;
  color: var(--primary-dark);
  margin-bottom: .9rem;
}
.intro-tips {
  margin: 0;
  padding: 0;
  list-style: none;
  display: grid;
  gap: .6rem;
  color: var(--text-secondary);
  line-height: 1.5;
}
.intro-tips li { padding-left: 1.4rem; position: relative; }
.intro-tips li::before {
  content: '';
  position: absolute;
  left: 0; top: .55em;
  width: .5rem; height: .5rem;
  border-radius: 50%;
  background: linear-gradient(135deg, #BE3C80, #9F5FF0 55%, #489FDF);
}

/* Capas de parallax (las mueve js/intro.js) */
.intro-fx {
  position: fixed;
  inset: 0;
  overflow: hidden;
  pointer-events: none;
}
#intro-back { z-index: 2; }
#intro-front { z-index: 5; }
.intro-fx .layer {
  position: absolute;
  inset: -12%;
  will-change: transform, opacity;
}
/* Bocetos de las escenas (js/intro.js): un canvas por boceto en su propia capa de parallax */
.sketch { position: absolute; opacity: .42; }
.sketch.is-done { animation: sketch-ink 1.1s ease-out; }
@keyframes sketch-ink { 35% { opacity: .78; } 100% { opacity: .42; } }
.sk-tip {
  position: absolute;
  left: -8px; top: -8px;
  width: 16px; height: 16px;
  border-radius: 50%;
  background: radial-gradient(circle, #fff 0 22%, rgba(255,255,255,.35) 42%, rgba(255,255,255,0) 70%);
  opacity: 0;
  transition: opacity .3s;
  pointer-events: none;
}
.blob {
  position: absolute;
  border-radius: 50%;
  filter: blur(48px);
  animation: blob-drift 18s ease-in-out infinite alternate;
}
.blob--a { left: 6%;  top: 8%;  width: 38vmax; height: 38vmax; background: radial-gradient(circle, rgba(240,216,255,.75), rgba(240,216,255,0) 68%); }
.blob--b { right: 4%; top: 28%; width: 34vmax; height: 34vmax; background: radial-gradient(circle, rgba(159,95,240,.42), rgba(159,95,240,0) 68%); animation-duration: 22s; }
.blob--c { left: 28%; bottom: 2%; width: 40vmax; height: 40vmax; background: radial-gradient(circle, rgba(72,159,223,.32), rgba(72,159,223,0) 68%); animation-duration: 26s; }
.blob--d { left: 52%; top: -6%; width: 26vmax; height: 26vmax; background: radial-gradient(circle, rgba(190,60,128,.45), rgba(190,60,128,0) 68%); animation-duration: 20s; }
@keyframes blob-drift {
  from { transform: translate3d(-3%, -2%, 0) scale(1); }
  to   { transform: translate3d(4%, 3%, 0) scale(1.12); }
}
.dot {
  position: absolute;
  border-radius: 50%;
  background: rgba(255, 255, 255, .75);
  box-shadow: 0 0 8px rgba(255, 255, 255, .6);
  animation: dot-float 9s ease-in-out infinite alternate;
}
@keyframes dot-float {
  from { transform: translate3d(0, 0, 0); opacity: .35; }
  to   { transform: translate3d(12px, -26px, 0); opacity: .9; }
}
.bokeh {
  position: absolute;
  border-radius: 50%;
  background: radial-gradient(circle at 35% 35%, rgba(255,255,255,.55), rgba(240,216,255,.18) 55%, rgba(240,216,255,0) 72%);
  filter: blur(5px);
}

/* Red neuronal (canvas a pantalla completa, por delante de la tarjeta) */
#orb-layer {
  position: fixed;
  inset: 0;
  z-index: 4;
  pointer-events: none;
}
#orb-canvas { width: 100%; height: 100%; display: block; }

/* Esfera clicable (explosión elástica) */
.orb-hit {
  position: absolute;
  left: 0; top: 0;
  padding: 0;
  border: 0;
  border-radius: 50%;
  background: transparent;
  pointer-events: auto;
  cursor: pointer;
  touch-action: pan-y;          /* en móvil: arrastre horizontal = girar la red; vertical = scroll */
  -webkit-tap-highlight-color: transparent;
}
.orb-hit.is-dragging { cursor: grabbing; }
.orb-hit:focus-visible { outline: 2px solid rgba(255,255,255,.8); outline-offset: 4px; }

/* Corte invisible (js/screen-cut.js): pantalla DOM que se convierte en la del portátil */
#screen-cut {
  position: fixed;
  inset: 0;
  z-index: 1;
  display: none;
  overflow: hidden;
  pointer-events: none;
}
#screen-cut .sc-bg { position: absolute; inset: 0; }
#screen-cut .sc-quad {
  position: absolute;
  left: 0; top: 0;
  width: 1920px;
  height: 1080px;
  transform-origin: 0 0;
  will-change: transform, opacity;
}
#screen-cut .sc-logo {
  position: absolute;
  inset: 0;
  -webkit-mask: url(../media/screen-logo-mask.png) 0 0 / 100% 100% no-repeat;
  mask: url(../media/screen-logo-mask.png) 0 0 / 100% 100% no-repeat;
}

@media (prefers-reduced-motion: reduce) {
  .blob, .dot { animation: none; }
}

/* Intro en móvil vertical: deja sitio a la cabecera y a la barra de carga */
@media (max-width: 600px) {
  .stage--intro { --orb: clamp(150px, 34vh, 260px); padding: 72px 12px 68px; }
  .intro-card { padding: calc(.9rem + var(--orb) * 0.1) 1.15rem 1.1rem; }
  .intro-card .eyebrow { margin-bottom: .5rem; font-size: .7rem; }
  .stage .intro-card h1 { font-size: 1.55rem; margin-bottom: .5rem; }
  .stage .intro-card p { font-size: .9rem; line-height: 1.5; margin-bottom: .8rem; }
  .intro-tips { gap: .3rem; font-size: .86rem; line-height: 1.4; }
}

/* --- Barra de carga --- */
#loading-hud {
  position: fixed;
  left: 50%;
  bottom: max(24px, env(safe-area-inset-bottom));
  transform: translateX(-50%);
  width: min(420px, calc(100vw - 32px));
  z-index: 6;
  color: #fff;
  font-family: var(--font-primary);
  pointer-events: none;
  transition: opacity .6s ease, transform .6s ease;
}
#loading-hud.is-hidden { opacity: 0; transform: translate(-50%, 12px); }

.loader-row {
  display: flex;
  justify-content: space-between;
  gap: 1rem;
  font-size: .85rem;
  font-weight: 600;
  margin-bottom: .5rem;
  text-shadow: 0 1px 2px rgba(0, 0, 0, .15);
}
.loader-pct { font-variant-numeric: tabular-nums; }
.loader-track {
  height: 6px;
  border-radius: 99px;
  background: rgba(255, 255, 255, .3);
  overflow: hidden;
}
.loader-fill {
  height: 100%;
  background: #fff;
  border-radius: inherit;
  transform-origin: left center;
  transform: scaleX(0);
}
.loader-wait {
  margin-top: .6rem;
  font-size: .8rem;
  text-align: center;
  opacity: 0;
  transition: opacity .4s ease;
}
#loading-hud.is-waiting .loader-wait { opacity: .9; }
#loading-hud.is-waiting .loader-track { animation: loader-pulse 1.2s ease-in-out infinite; }
#loading-hud.is-done .loader-wait { opacity: 0; }
#loading-hud.is-done .loader-label::after {
  content: ' ↓';
  display: inline-block;
  animation: loader-nudge 1.2s ease-in-out infinite;
}
@keyframes loader-pulse { 50% { background: rgba(255, 255, 255, .5); } }
@keyframes loader-nudge { 50% { transform: translateY(3px); } }

/* --- HUD de depuración (?debug=1) --- */
#debug-hud {
  position: fixed;
  top: 12px; left: 12px;
  z-index: 9999;
  max-width: 380px;
  padding: 10px 12px;
  border-radius: 10px;
  background: rgba(0, 0, 0, .7);
  color: #fff;
  font: 12px/1.5 ui-monospace, Consolas, monospace;
  pointer-events: none;
}

/* --- Táctil: el scroll manda --------------------------------------------------------
   El canvas 3D no recibe toques (sus listeners táctiles no pasivos frenan el scroll) y
   el cristal esmerilado (backdrop-filter sobre WebGL) se sustituye por un fondo más opaco,
   mucho más barato en móvil. */
@media (hover: none) and (pointer: coarse) {
  #application-canvas { pointer-events: none; touch-action: pan-y; }
  .stage .section-content {
    -webkit-backdrop-filter: none;
    backdrop-filter: none;
    background: rgba(250, 238, 246, 0.9);
  }
  .bokeh { filter: none; }
}

/* --- Menú en móvil ---------------------------------------------------------------------
   En style.css la lista se posicionaba respecto al <nav> (estrecho y a la derecha) y se
   salía de la pantalla; además, enlaces rosas sobre fondo rosa. Aquí se ancla a toda la
   cabecera y se le da estilo propio. */
@media (max-width: 768px) {
  .main-header nav { position: static; }
  .main-header nav ul {
    left: 0;
    right: 0;
    width: auto;
    top: calc(100% + 10px);
    padding: .5rem;
    border-radius: 22px;
    background: rgba(160, 40, 92, 0.96);
    border: 1px solid rgba(255, 255, 255, 0.14);
    box-shadow: 0 18px 40px rgba(16, 24, 32, 0.35);
    -webkit-backdrop-filter: none;
    backdrop-filter: none;
  }
  .main-header.mobile-menu-open nav ul { animation: menu-drop .28s cubic-bezier(.2,.8,.2,1); }
  .main-header nav li + li { border-top: 1px solid rgba(255, 255, 255, 0.12); }
  .main-header nav a {
    color: #fff;
    font-weight: 600;
    font-size: 1.05rem;
    padding: 14px 18px;
    border-radius: 14px;
  }
  .main-header nav a:hover,
  .main-header nav a:active { background: rgba(255, 255, 255, 0.12); padding-left: 18px; }
}
@keyframes menu-drop {
  from { opacity: 0; transform: translateY(-8px) scale(.98); }
  to   { opacity: 1; transform: none; }
}

/* --- Móvil estrecho: que el logo no se corte --- */
@media (max-width: 480px) {
  .header-content { padding: 8px 16px; }
  .header-logo { min-width: 0; flex: 1; }
  .header-logo img { height: auto !important; max-height: 32px; max-width: 100%; }
}

/* --- Pantallas bajas (móvil en horizontal) --- */
@media (max-height: 560px) {
  .main-header { top: 8px; }
  .header-content { padding: 6px 18px; }
  .header-logo img { height: 26px !important; }
  #desktop-menu-button { padding: .35rem .9rem; font-size: .8rem; }

  .stage { padding-top: 56px; padding-bottom: 52px; }
  .stage .section-content { padding: 1rem 1.25rem; }
  .stage .section-content h1, .stage .section-content h2 { font-size: 1.25rem; margin-bottom: .35rem; }
  .stage .section-content p { font-size: .85rem; line-height: 1.45; margin-bottom: .6rem; }
  .stage .section-button { padding: .45rem 1rem; font-size: .8rem; }

  .stage--intro { --orb: clamp(96px, 30vh, 150px); }
  .intro-card { padding-top: calc(1rem + var(--orb) * 0.1); }
  .intro-card .eyebrow { display: none; }
  .intro-tips { gap: .2rem; font-size: .82rem; line-height: 1.35; }

  #loading-hud { bottom: 8px; }
  .loader-row { font-size: .75rem; margin-bottom: .3rem; }
  .loader-track { height: 4px; }
  .loader-wait { display: none; }
}

@media (prefers-reduced-motion: reduce) {
  #loading-hud.is-waiting .loader-track,
  #loading-hud.is-done .loader-label::after { animation: none; }
}
