/* =========================================================
   Para Alejandra — estilos
   1. Tokens  2. Base  3. Capas fijas  4. Animaciones de texto
   5. Portada  6. Interfaz fija  7. Escenas  8. Botones
   9. Modo libre  10. Cursor  11. Pantallas pequeñas / accesibilidad
   ========================================================= */

/* 1. Tokens ------------------------------------------------ */
:root {
  color-scheme: dark;
  --black: #050505;
  --ink: #ebe6df;
  --soft: #b9b2a9;
  --dim: #7d7770;
  --line: rgba(235, 230, 223, .14);
  --serif: "Cormorant", "Cormorant Garamond", "Garamond", Georgia, serif;
  --sans: "Jost", "Futura", "Century Gothic", system-ui, sans-serif;
  --script: "Mrs Saint Delafield", "Snell Roundhand", cursive;
  --ease: cubic-bezier(.16, 1, .3, 1);
  --gutter: clamp(20px, 5vw, 72px);
}

/* 2. Base -------------------------------------------------- */
[hidden] { display: none !important; }
html { background: var(--black); }
html.locked { overflow: hidden; }
html.lenis, html.lenis body { height: auto; }
.lenis.lenis-smooth { scroll-behavior: auto !important; }
body {
  margin: 0; background: var(--black); color: var(--ink);
  font-family: var(--sans); font-weight: 300; -webkit-font-smoothing: antialiased;
}
::selection { background: var(--ink); color: var(--black); }
em { font-style: italic; }
.label {
  margin: 0; font-family: var(--sans); font-weight: 400; font-size: .64rem;
  letter-spacing: .42em; text-transform: uppercase; color: var(--dim);
}

/* 3. Capas fijas: 3D, grano, degradado de lectura ---------- */
#scene { position: fixed; inset: 0; width: 100%; height: 100%; display: block; pointer-events: none; }
html.free #scene { pointer-events: auto; touch-action: none; }
.grain {
  position: fixed; inset: -6%; width: 112%; height: 112%; pointer-events: none; z-index: 30;
  opacity: .05; animation: grain 1.2s steps(6) infinite; will-change: transform;
}
@keyframes grain {
  0% { transform: translate(0, 0); } 20% { transform: translate(-3%, 2%); } 40% { transform: translate(2%, -3%); }
  60% { transform: translate(-2%, -1%); } 80% { transform: translate(3%, 2%); } 100% { transform: translate(0, 0); }
}
.scrim {
  position: fixed; left: 0; right: 0; bottom: 0; height: 55vh; pointer-events: none; z-index: 1;
  background: linear-gradient(to top, rgba(5, 5, 5, .92), rgba(5, 5, 5, 0)); opacity: 0; transition: opacity 1.4s ease;
}
.fallback-note { position: fixed; left: 16px; right: 16px; bottom: 80px; text-align: center; z-index: 5; }

/* 4. Palabras que suben desde una máscara ------------------ */
.w { display: inline-block; overflow: hidden; vertical-align: top; padding-block: .08em .14em; margin-block: -.08em -.14em; }
.i {
  display: inline-block; transform: translate3d(0, 108%, 0);
  transition: transform .85s var(--ease); transition-delay: calc(var(--d) * 28ms + var(--base, 0ms));
}
.in .i, .i.in { transform: none; }
.out .i {
  transform: translate3d(0, -108%, 0); transition-duration: .55s;
  transition-timing-function: cubic-bezier(.5, 0, .75, 0); transition-delay: calc(var(--d) * 12ms);
}

/* 5. Portada ----------------------------------------------- */
#intro {
  position: fixed; inset: 0; z-index: 10;
  display: grid; place-items: center; align-content: center; text-align: center;
  padding-inline: var(--gutter);
  cursor: pointer; user-select: none; -webkit-user-select: none; -webkit-touch-callout: none; touch-action: none;
}
/* salida: más específica que la entrada (.intro-name .i) para no heredar sus 1.6 s */
#intro.leaving { opacity: 0; pointer-events: none; transition: opacity .4s ease .25s; }
#intro.leaving .i, #intro.leaving .intro-name .i {
  transform: translate3d(0, -108%, 0);
  transition: transform .45s cubic-bezier(.5, 0, .75, 0); transition-delay: calc(var(--d) * 8ms);
}
.intro-name {
  margin: 1.4rem 0 0; font-family: var(--serif); font-weight: 300; white-space: nowrap;
  font-size: clamp(3.6rem, 11vw, 9.5rem); line-height: .95;
  letter-spacing: calc(-.01em + var(--fill, 0) * .09em);   /* se abre mientras ella mantiene presionado */
  color: var(--ink); opacity: calc(1 - var(--fill, 0) * .45);
}
.intro-name .i { --base: 250ms; transition-duration: 1.6s; transition-delay: calc(var(--d) * 50ms + var(--base, 0ms)); }
#hold {
  --fill: 0;
  position: relative; width: 84px; height: 84px; margin-top: clamp(3rem, 9vh, 5.5rem);
  padding: 0; border: 0; border-radius: 50%; background: transparent; color: var(--ink); cursor: pointer;
  user-select: none; -webkit-user-select: none; -webkit-touch-callout: none; touch-action: none;
  opacity: 0; transition: opacity 1.4s ease 1.2s;
}
#intro.shown #hold { opacity: 1; }
#intro.leaving #hold { opacity: 0; transition: opacity .7s ease; }
#hold:focus-visible { outline: 1px solid var(--soft); outline-offset: 8px; }
#hold svg { position: absolute; inset: 0; width: 100%; height: 100%; transform: rotate(-90deg); overflow: visible; }
#hold circle { fill: none; stroke-width: 1; vector-effect: non-scaling-stroke; }
#hold .track { stroke: var(--line); }
#hold .prog { stroke: var(--ink); stroke-dasharray: 245; stroke-dashoffset: calc(245 * (1 - var(--fill))); }
#hold.loading .prog { stroke-dasharray: 34 211; stroke-dashoffset: 0; transform-origin: 50% 50%; animation: spin 1.6s linear infinite; stroke: var(--dim); }
@keyframes spin { to { transform: rotate(360deg); } }
#hold .core {
  position: absolute; left: 50%; top: 50%; width: 5px; height: 5px; margin: -2.5px; border-radius: 50%;
  background: var(--ink); transform: scale(calc(1 + var(--fill) * 2.2)); transition: transform .2s linear;
}
#hold.loading .core { opacity: .3; }
.hold-hint { margin-top: 1.6rem; min-height: 1em; opacity: 0; transition: opacity 1.4s ease 1.5s; }
.intro-foot {
  position: fixed; left: 0; right: 0; bottom: calc(env(safe-area-inset-bottom, 0px) + 26px);
  text-align: center; opacity: 0; transition: opacity 1.4s ease 2s;
}
#intro.shown .hold-hint { opacity: 1; }
#intro.shown .intro-foot { opacity: .8; }
#intro.leaving .hold-hint, #intro.leaving .intro-foot { opacity: 0; transition: opacity .6s ease; }

/* 6. Interfaz fija (monograma, sonido, contador) ------------ */
.hud { position: fixed; z-index: 20; pointer-events: none; opacity: 0; transition: opacity 1.6s ease; }
html.opened .hud { opacity: 1; }
html.outro .hud { opacity: 0; transition: opacity 2.2s ease; }
html.free .hud.br { opacity: 0; }
.hud.tl {
  top: calc(env(safe-area-inset-top, 0px) + 26px); left: var(--gutter);
  font-family: var(--serif); font-style: italic; font-size: 1.2rem; color: var(--soft); letter-spacing: .04em;
}
.hud.tr { top: calc(env(safe-area-inset-top, 0px) + 22px); right: var(--gutter); pointer-events: auto; }
.hud.br { bottom: calc(env(safe-area-inset-bottom, 0px) + 26px); right: var(--gutter); display: flex; align-items: center; gap: 1rem; color: var(--dim); }
.hud.br .count { font-family: var(--serif); font-size: 1rem; letter-spacing: .08em; color: var(--soft); font-variant-numeric: tabular-nums; }
.hud.br .track { position: relative; width: 64px; height: 1px; background: var(--line); }
.hud.br .track i { position: absolute; inset: 0; background: var(--soft); transform-origin: left; transform: scaleX(var(--p, 0)); }
#sound { background: none; border: 0; padding: .5rem 0; cursor: pointer; color: var(--dim); display: flex; align-items: center; gap: .8rem; }
#sound:hover, #sound:focus-visible { color: var(--ink); outline: none; }
#sound .bars { display: flex; align-items: flex-end; gap: 2px; height: 9px; }
#sound .bars i { width: 1px; height: 100%; background: currentColor; transform-origin: bottom; animation: eq 1.4s ease-in-out infinite; }
#sound .bars i:nth-child(2) { animation-delay: -.5s; }
#sound .bars i:nth-child(3) { animation-delay: -.9s; }
#sound[aria-pressed="false"] .bars i { animation: none; transform: scaleY(.15); }
@keyframes eq { 0%, 100% { transform: scaleY(.25); } 50% { transform: scaleY(1); } }

/* 7. Escenas ----------------------------------------------- */
/* overflow: clip evita que el desplazamiento de los textos estire la página */
#story { position: relative; z-index: 2; overflow: clip; transition: opacity .9s ease; }
html.free #story { opacity: 0; pointer-events: none; }
.ch {
  position: relative; min-height: 100vh; min-height: 100svh;
  display: flex; align-items: center; padding-inline: var(--gutter); pointer-events: none;
}
.ch.right { justify-content: flex-end; }
.ch.low { align-items: flex-end; padding-block: 0 15vh; }
.copy { position: relative; display: grid; gap: 1.5rem; width: min(28rem, 100%); will-change: transform, opacity; }
.copy .num { display: flex; align-items: center; gap: 1rem; }
.copy .num::before { content: ""; width: 36px; height: 1px; background: var(--dim); }
.copy h2 {
  margin: 0; font-family: var(--serif); font-weight: 300; font-size: clamp(2.5rem, 4.2vw, 4.1rem);
  line-height: 1; letter-spacing: -.012em; text-wrap: balance;
}
.copy h2 em { color: var(--soft); }
/* los textos son poemas: cada <br> es un verso */
.copy p.body {
  margin: 0; font-size: 1rem; line-height: 1.85; color: var(--soft); max-width: 25rem;
  opacity: 0; transform: translateY(12px);
  transition: opacity .8s ease .15s, transform .8s var(--ease) .15s;
}
.in .copy p.body { opacity: 1; transform: none; }
.hero .copy { width: min(30rem, 100%); }
.hero h2 { font-size: clamp(3.2rem, 6vw, 5.8rem); }

/* Telequinesis: cada letra se mueve sola (el JS le pone el transform) */
.tk-w { display: inline-block; white-space: nowrap; }
.tk-l { display: inline-block; opacity: 0; transition: opacity .6s ease; transition-delay: calc(var(--d) * 18ms); will-change: transform; }
.in .tk-l { opacity: 1; }

/* Firma y final de película */
.sign {
  margin: -.4rem 0 0; font-family: var(--script); font-size: clamp(3.4rem, 5.6vw, 4.6rem); line-height: 1.1; color: var(--ink);
  clip-path: inset(-20% 100% -20% 0); transition: clip-path 1.8s cubic-bezier(.65, 0, .35, 1) .4s;
}
.in .sign { clip-path: inset(-20% -10% -20% 0); }
html.outro .final .copy > :not(.sign) { opacity: 0 !important; transition: opacity 2.2s ease !important; }

/* 8. Botones (se llenan de abajo hacia arriba, con sonido de agua) */
.btn {
  pointer-events: auto; justify-self: start; position: relative; overflow: hidden; isolation: isolate;
  padding: 1.1rem 1.8rem; border-radius: 999px; border: 1px solid rgba(235, 230, 223, .35);
  background: transparent; color: var(--ink); cursor: pointer;
  font: 400 .62rem/1 var(--sans); letter-spacing: .34em; text-transform: uppercase;
  transition: color .7s var(--ease), border-color .7s ease;
}
.btn::before {
  content: ""; position: absolute; inset: -1px; z-index: -1; background: var(--ink);
  transform: translateY(102%); border-radius: 40% 40% 0 0 / 60% 60% 0 0;
  transition: transform 1.15s var(--ease), border-radius 1.15s var(--ease);
}
.btn:hover, .btn:focus-visible { color: var(--black); border-color: var(--ink); outline: none; }
.btn:hover::before, .btn:focus-visible::before { transform: none; border-radius: 0; }
.final .btn { margin-top: .4rem; opacity: 0; transition: opacity .8s ease 1s, color .7s var(--ease), border-color .7s ease; }
.final.in .btn { opacity: 1; }

/* 9. Modo libre -------------------------------------------- */
#free-ui {
  position: fixed; z-index: 15; left: 0; right: 0; bottom: calc(env(safe-area-inset-bottom, 0px) + 26px);
  display: flex; align-items: center; justify-content: space-between; gap: 1.2rem;
  padding-inline: var(--gutter); pointer-events: none;
}

/* 10. Cursor propio ---------------------------------------- */
.cursor { position: fixed; left: 0; top: 0; z-index: 40; pointer-events: none; mix-blend-mode: difference; opacity: 0; transition: opacity .5s ease; }
html.has-cursor .cursor { opacity: 1; }
html.has-cursor, html.has-cursor * { cursor: none !important; }
.cursor .dot { position: absolute; width: 4px; height: 4px; margin: -2px; border-radius: 50%; background: #fff; }
.cursor .ring {
  position: absolute; width: 34px; height: 34px; margin: -17px; border-radius: 50%; border: 1px solid rgba(255, 255, 255, .6);
  transition: width .6s var(--ease), height .6s var(--ease), margin .6s var(--ease), opacity .5s ease;
}
.cursor.big .ring { width: 70px; height: 70px; margin: -35px; }
.cursor.hide .ring { opacity: 0; }

/* 11. Pantallas pequeñas / accesibilidad ------------------- */
@media (max-width: 760px), (orientation: portrait) {
  .ch, .ch.right { align-items: flex-end; justify-content: flex-start; padding-block: 0 clamp(88px, 14svh, 140px); }
  .copy { gap: 1.1rem; }
  .copy h2 { font-size: clamp(2.2rem, 9.4vw, 2.8rem); }
  .hero { padding-block: 0 clamp(110px, 17svh, 160px); }
  .final { padding-block: 0 clamp(80px, 12svh, 120px); }
  .final .copy { gap: .85rem; }
  .final .copy h2 { font-size: clamp(2rem, 8.4vw, 2.5rem); }
  .final .sign { font-size: 3rem; }
  html.opened .scrim { opacity: 1; }
  html.free .scrim { opacity: 0; }
}
@media (max-width: 480px) {
  .label { letter-spacing: .3em; font-size: .6rem; }
}
@media (prefers-reduced-motion: reduce) {
  .grain, #sound .bars i, #hold.loading .prog { animation: none; }
  .i { transition-duration: .01s; }
}
