/* ═══════════════════════════════════════════════════════
   FILM · Sala de cine  (sección #caracteristicas)
   Reposo: pantalla negra flotando sobre el blanco de la landing.
   Play:   se apagan las luces de toda la página y la pantalla
           ilumina el polvo y el piso a su alrededor.
   JS: js/cine-film.js (estados en [data-state] + clases is-*)
═══════════════════════════════════════════════════════ */

.cine {
  /* Ancho que siempre cabe completo en la ventana (alto ≈ 76% del viewport) */
  --cine-w: min(1120px, 86vw, calc(78vh * 1.72));
  --cine-b: clamp(8px, 1.05vw, 15px);     /* grosor del bisel */
  --cine-r: clamp(14px, 1.7vw, 26px);     /* radio exterior */
  --cine-s: 1;                            /* escala en modo cine (JS) */
  --ease-dim: cubic-bezier(0.65, 0, 0.35, 1);
  position: relative;
  isolation: isolate;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: clamp(40px, 6vh, 64px);
  min-height: 100svh;
  padding: clamp(96px, 13vh, 150px) 0 clamp(84px, 11vh, 132px);
  overflow-x: clip;
  background: transparent;
  color: var(--ink);
}
@supports (height: 1svh) {
  .cine { --cine-w: min(1120px, 86vw, calc(78svh * 1.72)); }
}
/* Capas: página < luces (890) < sección elevada (895) < navbar (900) < modales (950).
   La navbar se desvanece con las luces y nunca queda tapada por la sección. */
.cine.is-raised { z-index: 895; }

/* ── Encabezado ─────────────────────────────────────── */
.cine-head {
  position: relative;
  z-index: 2;
  padding: 0 24px;
  text-align: center;
  transition:
    opacity 0.7s var(--ease-out),
    transform 1s var(--ease-out),
    filter 0.7s var(--ease-out);
}
.cine-kicker {
  font-size: 13px;
  font-weight: 600;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--ink-muted);
}

/* Revelado escalonado al entrar en vista */
.cine-head > *,
.cine-foot {
  opacity: 0;
  transform: translate3d(0, 22px, 0);
  filter: blur(8px);
  transition:
    opacity 0.9s var(--ease-out),
    transform 1.1s var(--ease-out),
    filter 0.9s var(--ease-out);
}
.cine.is-inview .cine-head > *,
.cine.is-inview .cine-foot {
  opacity: 1;
  transform: none;
  filter: none;
}
.cine.is-inview .cine-foot { transition-delay: 0.35s; }

/* ── Escenario (pantalla + luz que derrama) ─────────── */
.cine-stage {
  position: relative;
  z-index: 1;
  width: var(--cine-w);
  transform: scale(var(--cine-s));
  transition: transform 1.3s var(--ease-out);
}

.cine-screen {
  --tilt: 0;
  position: relative;
  transform-origin: 50% 100%;
  transform:
    perspective(1900px)
    translate3d(0, calc(var(--tilt) * 64px), 0)
    rotateX(calc(var(--tilt) * 24deg))
    scale(calc(1 - var(--tilt) * 0.08));
  will-change: transform;
}
.cine.is-dark .cine-screen { transition: transform 0.9s var(--ease-out); }

/* Bisel: negro profundo con filo de luz arriba, como un monitor de referencia */
.cine-bezel {
  position: relative;
  padding: var(--cine-b);
  border-radius: var(--cine-r);
  background:
    linear-gradient(180deg, #1d1d1f 0%, #0d0d0e 7%, #070708 48%, #030304 100%);
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.14),
    inset 0 0 0 1px rgba(255, 255, 255, 0.045),
    inset 0 -1px 0 rgba(0, 0, 0, 0.9),
    0 0 0 1px rgba(10, 10, 10, 0.92),
    0 1px 2px rgba(0, 0, 0, 0.16),
    0 22px 44px -16px rgba(0, 0, 0, 0.4),
    0 64px 120px -34px rgba(0, 0, 0, 0.55);
}
/* Reflejo especular del filo superior */
.cine-bezel::before {
  content: "";
  position: absolute;
  left: 8%;
  right: 8%;
  top: 0;
  height: 1px;
  background: linear-gradient(90deg, transparent, rgba(255, 255, 255, 0.34), transparent);
  pointer-events: none;
}

.cine-display {
  position: relative;
  aspect-ratio: 16 / 9;
  overflow: hidden;
  border-radius: max(6px, calc(var(--cine-r) - var(--cine-b) + 1px));
  background: #000;
  box-shadow: 0 0 0 1px #000;
  isolation: isolate;
  container-type: inline-size;
  transform: translateZ(0); /* Safari: recorte correcto del video con radio */
}
.cine-display > * { position: absolute; }

.cine-video {
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  background: #000;
  opacity: 0;
  transition: opacity 0.9s var(--ease-out), filter 0.6s var(--ease-out);
}
.cine.is-rolling .cine-video {
  opacity: 1;
  transition: opacity 0.22s linear, filter 0.6s var(--ease-out);
}
/* En pausa el cuadro se vuelve textura: los subtítulos quemados no compiten con la leyenda */
.cine.is-paused .cine-video { filter: brightness(0.26) grayscale(1) blur(7px); transform: scale(1.04); }

/* Sin controles nativos, en ningún navegador */
.cine-video::-webkit-media-controls,
.cine-video::-webkit-media-controls-enclosure,
.cine-video::-webkit-media-controls-panel,
.cine-video::-webkit-media-controls-overlay-play-button,
.cine-video::-webkit-media-controls-start-playback-button {
  display: none !important;
  opacity: 0 !important;
  -webkit-appearance: none;
}

/* Esfera de partículas (canvas) */
.cine-orb {
  left: 0;
  top: 0;
  transition: opacity 0.45s var(--ease-out);
}
.cine.is-rolling:not(.is-paused) .cine-orb { opacity: 0; }

/* Destello del clic: continúa en el destello del propio video */
.cine-flash {
  left: 50.08%;
  top: 48.6%;
  width: 44%;
  aspect-ratio: 1;
  opacity: 0;
  transform: translate(-50%, -50%) scale(0.25);
  background: radial-gradient(
    circle,
    #fff 0%,
    rgba(255, 255, 255, 0.96) 4%,
    rgba(255, 255, 255, 0.5) 11%,
    rgba(255, 255, 255, 0.16) 24%,
    rgba(255, 255, 255, 0.05) 40%,
    transparent 62%
  );
  pointer-events: none;
}

/* Destello anamórfico horizontal */
.cine-flare {
  left: -25%;
  right: -25%;
  top: 48.6%;
  height: 14%;
  opacity: 0;
  transform: translateY(-50%) scaleX(0.08);
  background:
    linear-gradient(90deg, transparent 6%, rgba(255, 255, 255, 0.9) 50%, transparent 94%) center / 100% 1px no-repeat,
    radial-gradient(50% 50% at 50% 50%, rgba(255, 255, 255, 0.55), rgba(255, 255, 255, 0.12) 34%, transparent 70%);
  pointer-events: none;
}

/* Carga a mitad de la película */
.cine-buffer {
  left: 50%;
  top: 50%;
  display: flex;
  gap: 7px;
  transform: translate(-50%, -50%);
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.3s var(--ease-out), visibility 0s linear 0.3s;
  pointer-events: none;
}
.cine-buffer i {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: #fff;
  animation: cineBuffer 1.1s var(--ease-dim) infinite;
}
.cine-buffer i:nth-child(2) { animation-delay: 0.14s; }
.cine-buffer i:nth-child(3) { animation-delay: 0.28s; }
.cine-buffer i { animation-play-state: paused; }
.cine.is-buffering .cine-buffer { opacity: 0.8; visibility: visible; transition-delay: 0s; }
.cine.is-buffering .cine-buffer i { animation-play-state: running; }
@keyframes cineBuffer {
  0%, 100% { opacity: 0.2; transform: scale(0.7); }
  45% { opacity: 1; transform: scale(1); }
}

/* Cursor pixelado: el mismo del video */
.cine-cursor {
  left: 0;
  top: 0;
  width: 20px;
  height: 38px;
  fill: #fff;
  shape-rendering: crispEdges;
  overflow: visible;
  transform-origin: 0 0;
  transform: translate3d(-200px, -200px, 0);
  filter:
    drop-shadow(0 0 2px rgba(255, 255, 255, 0.7))
    drop-shadow(0 0 16px rgba(255, 255, 255, 0.24));
  will-change: transform;
  pointer-events: none;
  transition: opacity 0.35s var(--ease-out);
}
.cine.is-rolling:not(.is-paused) .cine-cursor { opacity: 0; }
/* escritorio con el mouse lejos de la pantalla: solo existe el cursor del sistema */
.cine.cursor-away .cine-cursor { opacity: 0; transition: none; }

/* Leyenda con la tipografía y posición de los subtítulos del video */
.cine-caption {
  left: 0;
  right: 0;
  bottom: 9.4%;
  padding: 0 6%;
  font-size: 14px;
  font-size: max(11px, 1.6cqw);
  font-weight: 500;
  letter-spacing: 0.012em;
  line-height: 1.3;
  text-align: center;
  color: rgba(255, 255, 255, 0.94);
  pointer-events: none;
  animation: cineCaption 3.2s var(--ease-dim) infinite;
  transition: opacity 0.35s var(--ease-out);
}
@keyframes cineCaption {
  0%, 100% { opacity: 0.94; }
  50% { opacity: 0.5; }
}
.cine.is-rolling:not(.is-paused) .cine-caption,
.cine[data-state="arming"] .cine-caption {
  opacity: 0;
  animation: none;
}
/* sobre el cuadro pausado sí hace falta la sombra para separarla del video */
.cine.is-paused .cine-caption { text-shadow: 0 0 18px rgba(0, 0, 0, 0.9); }
.cine.is-loading .cine-caption {
  opacity: 0.9;
  animation: cineCaption 1.4s var(--ease-dim) infinite;
}

/* Brillo del cristal */
.cine-glass {
  inset: 0;
  background:
    linear-gradient(117deg, rgba(255, 255, 255, 0.075) 0%, rgba(255, 255, 255, 0.018) 24%, transparent 44%),
    radial-gradient(120% 80% at 50% 128%, rgba(255, 255, 255, 0.04), transparent 62%);
  pointer-events: none;
  transition: opacity 0.8s var(--ease-out);
}
.cine.is-rolling .cine-glass { opacity: 0.3; }

/* Toda la pantalla es el botón */
.cine-hit {
  inset: 0;
  z-index: 5;
  width: 100%;
  height: 100%;
  border-radius: inherit;
  background: transparent;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}
.cine-hit:focus { outline: none; }
.cine-hit:focus-visible {
  box-shadow:
    inset 0 0 0 2px rgba(255, 255, 255, 0.9),
    inset 0 0 0 5px rgba(0, 0, 0, 0.7);
}
/* adelantar/regresar con las flechas no enciende el marco (macOS lo activaba); Tab sí */
.cine.is-seek-keys .cine-hit:focus-visible { box-shadow: none; }
@media (hover: hover) and (pointer: fine) {
  .cine[data-state="idle"] .cine-hit,
  .cine[data-state="paused"] .cine-hit,
  .cine[data-state="arming"] .cine-hit { cursor: none; }
}
.cine.is-rolling:not(.is-paused) .cine-hit { cursor: default; }
.cine.hide-pointer .cine-hit { cursor: none; }

/* ── Luz que derrama la pantalla ────────────────────── */
.cine-halo {
  position: absolute;
  left: 50%;
  top: 50%;
  z-index: -1;
  /* 150% × 190% del escenario, dibujado a ¼ de resolución y ampliado ×4: un degradado
     tan suave se ve idéntico y la GPU rasteriza 16 veces menos píxeles al escalar la pantalla */
  width: 37.5%;
  height: 47.5%;
  transform: translate(-50%, -50%) scale(4);
  background: radial-gradient(
    closest-side,
    rgba(255, 255, 255, 0.2),
    rgba(255, 255, 255, 0.07) 42%,
    rgba(255, 255, 255, 0.02) 70%,
    transparent 100%
  );
  opacity: 0;
  pointer-events: none;
  will-change: opacity;
  transition: opacity 1.2s var(--ease-out);
}

/* Muestra del video a 64×36, ampliada y desenfocada (tipo "ambient mode").
   El canvas mide 1/4 y se escala ×4: el desenfoque cuesta 16 veces menos. */
.cine-ambient {
  position: absolute;
  inset: -14% -12%;
  z-index: -1;
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
  transition: opacity 1.4s var(--ease-out), visibility 0s linear 1.4s;
}
.cine-ambient canvas,
.cine-floor canvas {
  display: block;
  width: 25%;
  height: 25%;
  transform: scale(4);
  transform-origin: 0 0;
}
.cine-ambient canvas { filter: blur(15px) brightness(1.5) grayscale(1); }

/* Reflejo en el piso */
.cine-floor {
  position: absolute;
  left: 3%;
  right: 3%;
  top: 100%;
  height: 46%;
  margin-top: 14px;
  opacity: 0;
  transform: perspective(640px) rotateX(62deg);
  transform-origin: 50% 0;
  -webkit-mask-image: linear-gradient(180deg, #000 0%, rgba(0, 0, 0, 0.35) 42%, transparent 88%);
  mask-image: linear-gradient(180deg, #000 0%, rgba(0, 0, 0, 0.35) 42%, transparent 88%);
  visibility: hidden;
  pointer-events: none;
  transition: opacity 1.2s var(--ease-out), visibility 0s linear 1.2s;
}
.cine-floor canvas { filter: blur(5px) brightness(1.35) grayscale(1); }

/* Con ctx.filter (JS añade .cine-baked) el desenfoque, el brillo y la máscara ya vienen
   horneados en el canvas: sin filtros ni máscaras CSS que la GPU recalcule en cada cuadro.
   La luz ambiental se agranda 180px por lado para contener el derrame del desenfoque. */
.cine-baked .cine-ambient { inset: calc(-14% - 180px) calc(-12% - 180px); }
.cine-baked .cine-ambient canvas,
.cine-baked .cine-floor canvas {
  width: 100%;
  height: 100%;
  transform: none;
  filter: none;
}
.cine-baked .cine-floor {
  -webkit-mask-image: none;
  mask-image: none;
}

/* Chispas del clic: salen de los bordes de la pantalla y se apagan en ~1.5 s.
   Capa fija al viewport; las anima el compositor (transform + opacity). */
.cine-sparks {
  position: fixed;
  inset: 0;
  z-index: 0;
  overflow: hidden;
  pointer-events: none;
}
.cine-sparks i {
  position: absolute;
  left: 0;
  top: 0;
  border-radius: 2px;
  opacity: 0;
  transform-origin: 100% 50%; /* la cabeza de la chispa; la estela queda detrás */
  background: linear-gradient(90deg, rgba(255, 255, 255, 0), #fff);
}
/* ── Pie: duración / CTA al terminar ───────────────── */
.cine-foot {
  position: relative;
  z-index: 2;
  display: grid;
  place-items: center;
  min-height: 48px;
}
.cine-foot > * { grid-area: 1 / 1; }
.cine-after {
  display: flex;
  align-items: center;
  gap: 8px;
  opacity: 0;
  visibility: hidden;
  transform: translate3d(0, 10px, 0);
  transition:
    opacity 0.7s var(--ease-out),
    transform 0.9s var(--ease-out),
    visibility 0s linear 0.7s;
}
.cine.has-watched .cine-after {
  opacity: 1;
  visibility: visible;
  transform: none;
  transition-delay: 0.9s, 0.9s, 0s;
}
.cine-cta {
  padding: 13px 24px;
  border-radius: var(--r-pill, 9999px);
  background: var(--ink);
  color: var(--canvas);
  font-size: 14px;
  font-weight: 600;
  letter-spacing: -0.01em;
  transition: transform 0.25s var(--ease-out), background-color 0.25s var(--ease-out);
}
.cine-cta:hover { background: #262626; transform: translateY(-1px); }
.cine-cta:active { transform: scale(0.97); }
.cine-link {
  padding: 13px 14px;
  font-size: 14px;
  font-weight: 600;
  color: var(--ink);
}
.cine-link span {
  display: inline-block;
  transition: transform 0.25s var(--ease-out);
}
.cine-link:hover span { transform: translateX(3px); }
.cine-cta:focus-visible,
.cine-link:focus-visible {
  outline: 2px solid var(--ink);
  outline-offset: 3px;
}

/* ── Luces apagadas ─────────────────────────────────── */
.cine-lights {
  --ease-dim: cubic-bezier(0.65, 0, 0.35, 1);
  position: fixed;
  inset: -2px;
  z-index: 890;
  background: #030304;
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
  transition: opacity 1.25s var(--ease-dim), visibility 0s linear 1.25s;
}
.cine-lights.is-on {
  opacity: 1;
  visibility: visible;
  pointer-events: auto;
  /* se apaga como un dimmer: arranca de inmediato y aterriza suave */
  transition: opacity 1.4s cubic-bezier(0.3, 0, 0.2, 1), visibility 0s;
}
/* La navbar se desvanece con las luces. La clase va en la propia navbar: una clase en
   <html> (o color-scheme en la raíz) obligaba a recalcular y repintar toda la página
   en el primer cuadro del apagón. */
body.intro-done .nav.cine-nav-off {
  opacity: 0 !important;
  pointer-events: none !important;
}

.cine.is-dark .cine-head,
.cine.is-dark .cine-foot {
  opacity: 0;
  transform: translate3d(0, -8px, 0);
  filter: blur(6px);
  pointer-events: none;
  visibility: hidden;
  transition:
    opacity 0.28s var(--ease-out),
    transform 0.6s var(--ease-out),
    filter 0.28s var(--ease-out),
    visibility 0s linear 0.28s;
}
.cine.is-dark .cine-bezel {
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.2),
    inset 0 0 0 1px rgba(255, 255, 255, 0.06),
    inset 0 -1px 0 rgba(0, 0, 0, 0.9),
    0 0 0 1px rgba(255, 255, 255, 0.04),
    0 40px 90px -30px rgba(0, 0, 0, 0.9);
}
.cine.is-dark .cine-ambient { opacity: 0.9; visibility: visible; transition-delay: 0.5s, 0s; }
.cine.is-dark .cine-floor { opacity: 1; visibility: visible; transition-delay: 0.7s, 0s; }

/* ── Responsive ─────────────────────────────────────── */
@media (max-width: 760px) {
  .cine {
    --cine-w: min(calc(100vw - 32px), calc(78vh * 1.72));
    --cine-b: 6px;
    --cine-r: 14px;
    min-height: 0;
    gap: 32px;
    padding: 92px 0 76px;
  }
  @supports (height: 1svh) {
    .cine { --cine-w: min(calc(100vw - 32px), calc(78svh * 1.72)); }
  }
  .cine-kicker { font-size: 12px; }
  .cine-caption { font-size: max(10px, 2.4cqw); }
  .cine-after { flex-direction: column; gap: 2px; }
}

@media (forced-colors: active) {
  .cine-bezel,
  .cine-display { forced-color-adjust: none; }
  .cine-cursor { display: none; }
  .cine .cine-hit { cursor: pointer !important; }
  .cine-hit:focus-visible { outline: 3px solid CanvasText; outline-offset: -3px; }
}

@media (prefers-reduced-motion: reduce) {
  .cine-screen { transform: none !important; }
  .cine-stage { transition-duration: 0.01ms; }
  .cine-head > *,
  .cine-foot { transform: none; filter: none; }
  .cine-sparks { display: none; }
  .cine-caption { animation: none; }
  .cine-lights,
  .cine-lights.is-on { transition-duration: 0.45s; }
}
