/* La versión interior comparte la secuencia de portada; su imagen y estilos son propios.
   El estado inicial es legible incluso sin animaciones o en pantallas pequeñas. */
body:not(.es-portada) .cierre::before,
body:not(.es-portada) .cierre .cierre__texto > *,
body:not(.es-portada) .cierre .canales li,
body:not(.es-portada) .cierre .canales li > *,
body:not(.es-portada) .cierre .canales li::before { animation: none; }

@property --luz {
  syntax: "<number>";
  inherits: true;
  initial-value: 1;
}

body:not(.es-portada) .cierre {
  position: relative;
  isolation: isolate;
}

body:not(.es-portada) .cierre::before,
body:not(.es-portada) .cierre::after {
  content: "";
  position: absolute;
  inset: 0;
  z-index: -1;
  pointer-events: none;
}

/* Fotografía ilustrativa ya usada en el blog (tema «Primer contacto»): manos, sin rostros ni marcas. */
body:not(.es-portada) .cierre::before {
  background: url("/recursos/medios/contacto-manos-interiores-1200.webp") 72% 38% / cover no-repeat;
  opacity: 0.42;
}

body:not(.es-portada) .cierre::after {
  background:
    radial-gradient(46% 58% at 76% 60%, rgb(131 220 200 / calc(var(--luz) * 0.17)), transparent 72%),
    linear-gradient(100deg, rgb(8 13 16 / 0.92) 0%, rgb(10 30 29 / 0.84) 46%, rgb(20 65 58 / 0.52) 100%);
}

/* Cada canal: un nodo y un trazo aguamarina sobre su línea. */
body:not(.es-portada) .cierre .canales li {
  position: relative;
}

body:not(.es-portada) .cierre .canales li::before,
body:not(.es-portada) .cierre .canales li::after {
  content: "";
  position: absolute;
  pointer-events: none;
}

body:not(.es-portada) .cierre .canales li::before {
  inset-block-start: -1px;
  inset-inline: 0;
  block-size: 1px;
  background: linear-gradient(to right, var(--agua), rgb(131 220 200 / 0) 74%);
  transform-origin: left;
}

body:not(.es-portada) .cierre .canales li::after {
  inset-block-start: -0.25rem;
  inset-inline-start: -0.21875rem;
  inline-size: 0.4375rem;
  aspect-ratio: 1;
  border-radius: 50%;
  background: var(--agua);
  box-shadow: 0 0 0 0.25rem rgb(131 220 200 / 0.16), 0 0 1rem rgb(131 220 200 / 0.6);
}

/* Escena fija. La sección mide una pantalla más un tramo; imagen, velo y contenido quedan pegados mientras se
   recorre. Nada captura la rueda ni el teclado; el avance es el scroll y se puede volver atrás.
   Orden: la imagen emerge y el titular sube al entrar → pausa → texto → botón → la línea sale del rótulo →
   baja por el raíl y enciende Llamada, WhatsApp y Correo → sube la luz → pausa → suelta hacia el pie.
   portada.js anota la geometría de la línea (--sx, --sy, --rx, --rt, --rb, --k1…3) y añade .cierre--fluye si el
   contenido no cabe. Con foco de teclado dentro, todo se muestra de una vez. */

@media (prefers-reduced-motion: no-preference) and (scripting: enabled) {
  @supports ((animation-timeline: view()) and (animation-range: 0% 100%)) {
    @media (min-width: 60rem) and (min-height: 40rem) {
      body:not(.es-portada) .cierre:not(.cierre--fluye) {
        --tramo: 220svh;
        display: grid;
        grid-template: minmax(0, 1fr) / minmax(0, 1fr);
        align-content: normal;
        /* Solo recorta la fotografía, que se mueve a escala; el contenido cabe siempre (lo garantiza portada.js). */
        overflow: clip;
        block-size: calc(100svh + var(--tramo));
        min-block-size: 0;
        padding-block: 0;
        background: var(--negro);
        view-timeline: --cont block;
        animation: cierre-luz linear both;
        animation-timeline: --cont;
        animation-range: contain 66% contain 82%;
      }

      body:not(.es-portada) .cierre:not(.cierre--fluye)::before,
      body:not(.es-portada) .cierre:not(.cierre--fluye)::after,
      body:not(.es-portada) .cierre:not(.cierre--fluye) > .cierre__rejilla {
        position: sticky;
        inset: 0 auto auto;
        grid-area: 1 / 1;
        align-self: start;
        block-size: 100svh;
      }

      body:not(.es-portada) .cierre:not(.cierre--fluye)::before,
      body:not(.es-portada) .cierre:not(.cierre--fluye)::after {
        z-index: 0;
        inline-size: 100%;
      }

      body:not(.es-portada) .cierre:not(.cierre--fluye)::before {
        opacity: 1;
        animation: cierre-imagen linear both;
        animation-timeline: --cont;
        animation-range: entry 0% contain 100%;
      }

      body:not(.es-portada) .cierre:not(.cierre--fluye) > .cierre__rejilla {
        z-index: 1;
        align-content: safe center;
        padding-block: clamp(2.5rem, 5svh, 4.5rem);
      }

      /* La línea: del rótulo al raíl, y el raíl hasta el último canal. */
      body:not(.es-portada) .cierre:not(.cierre--fluye) > .cierre__rejilla::before,
      body:not(.es-portada) .cierre:not(.cierre--fluye) > .cierre__rejilla::after {
        content: "";
        position: absolute;
        pointer-events: none;
        animation-timing-function: linear;
        animation-fill-mode: both;
        animation-timeline: --cont;
      }

      body:not(.es-portada) .cierre:not(.cierre--fluye) > .cierre__rejilla::before {
        inset-block-start: var(--sy, -10rem);
        inset-inline-start: calc(var(--sx, 0px) + 1rem);
        inline-size: calc(var(--rx, 0px) - var(--sx, 0px) - 1rem);
        block-size: 1px;
        background: linear-gradient(to right, rgb(131 220 200 / 0), var(--agua) 30%);
        transform-origin: left;
        animation-name: cierre-traza-x;
        animation-range: contain 22% contain 34%;
      }

      body:not(.es-portada) .cierre:not(.cierre--fluye) > .cierre__rejilla::after {
        inset-block-start: var(--rt, -10rem);
        inset-inline-start: var(--rx, 0px);
        inline-size: 1px;
        block-size: calc(var(--rb, 0px) - var(--rt, 0px));
        background: var(--agua);
        box-shadow: 0 0 0.75rem rgb(131 220 200 / 0.55);
        transform-origin: top;
        animation-name: cierre-traza-y;
        animation-range: contain 34% contain 62%;
      }

      /* Texto por capas. */
      body:not(.es-portada) .cierre:not(.cierre--fluye) .cierre__texto {
        animation: none;
      }

      body:not(.es-portada) .cierre:not(.cierre--fluye) .cierre__texto > * {
        animation-name: cierre-sube;
        animation-timing-function: linear;
        animation-fill-mode: both;
        animation-timeline: --cont;
      }

      body:not(.es-portada) .cierre:not(.cierre--fluye) .cierre__texto > .antetitulo { animation-range: entry 25% entry 80%; }
      body:not(.es-portada) .cierre:not(.cierre--fluye) .cierre__texto > h2 { animation-range: entry 40% entry 100%; }
      body:not(.es-portada) .cierre:not(.cierre--fluye) .cierre__texto > .entrada { animation-range: contain 6% contain 14%; }
      body:not(.es-portada) .cierre:not(.cierre--fluye) .cierre__texto > .acciones { animation-range: contain 12% contain 20%; }

      body:not(.es-portada) .cierre:not(.cierre--fluye) .boton--primario {
        box-shadow:
          0 0 0 calc(var(--luz) * 0.375rem) rgb(131 220 200 / 0.2),
          0 0 calc(var(--luz) * 3.5rem) rgb(131 220 200 / calc(var(--luz) * 0.45));
      }

      /* El texto de cada canal se separa del raíl. */
      body:not(.es-portada) .cierre:not(.cierre--fluye) .canales li {
        padding-inline-start: 1.5rem;
      }

      /* Canales: cada uno empieza cuando el raíl llega a su altura (--k, de 0 a 1 a lo largo del raíl). */
      body:not(.es-portada) .cierre:not(.cierre--fluye) .canales li:nth-child(1) { --k: var(--k1, 0.12); }
      body:not(.es-portada) .cierre:not(.cierre--fluye) .canales li:nth-child(2) { --k: var(--k2, 0.56); }
      body:not(.es-portada) .cierre:not(.cierre--fluye) .canales li:nth-child(3) { --k: var(--k3, 1); }

      body:not(.es-portada) .cierre:not(.cierre--fluye) .canales li,
      body:not(.es-portada) .cierre:not(.cierre--fluye) .canales li::before,
      body:not(.es-portada) .cierre:not(.cierre--fluye) .canales li::after,
      body:not(.es-portada) .cierre:not(.cierre--fluye) .canales li > * {
        --a: calc(34% + var(--k) * 28%);
        animation-timing-function: linear;
        animation-fill-mode: both;
        animation-timeline: --cont;
        animation-range: contain var(--a) contain calc(var(--a) + 7%);
      }

      body:not(.es-portada) .cierre:not(.cierre--fluye) .canales li { animation-name: cierre-borde; }
      body:not(.es-portada) .cierre:not(.cierre--fluye) .canales li::before { animation-name: cierre-traza-x; }
      body:not(.es-portada) .cierre:not(.cierre--fluye) .canales li::after { animation-name: cierre-nodo; animation-range: contain calc(var(--a) - 2%) contain calc(var(--a) + 3%); }
      body:not(.es-portada) .cierre:not(.cierre--fluye) .canales li > * { animation-name: cierre-entra; animation-range: contain calc(var(--a) + 1%) contain calc(var(--a) + 10%); }

      /* Teclado: nada enfocable queda invisible. */
      body:not(.es-portada) .cierre:has(:focus-visible):not(.cierre--fluye),
      body:not(.es-portada) .cierre:has(:focus-visible):not(.cierre--fluye) > .cierre__rejilla::before,
      body:not(.es-portada) .cierre:has(:focus-visible):not(.cierre--fluye) > .cierre__rejilla::after,
      body:not(.es-portada) .cierre:has(:focus-visible):not(.cierre--fluye) .cierre__texto > *,
      body:not(.es-portada) .cierre:has(:focus-visible):not(.cierre--fluye) .canales li,
      body:not(.es-portada) .cierre:has(:focus-visible):not(.cierre--fluye) .canales li::before,
      body:not(.es-portada) .cierre:has(:focus-visible):not(.cierre--fluye) .canales li::after,
      body:not(.es-portada) .cierre:has(:focus-visible):not(.cierre--fluye) .canales li > * {
        animation-name: none;
      }
    }
  }
}

@keyframes cierre-luz {
  from { --luz: 0; }
}

@keyframes cierre-imagen {
  0% { opacity: 0; scale: 1.34; translate: 5% 3%; }
  31% { opacity: 1; scale: 1.22; translate: 2% 0; }
  50% { opacity: 0.9; scale: 1.15; translate: 0.5% 0; }
  72% { opacity: 0.62; scale: 1.09; translate: 0 0; }
  100% { opacity: 0.44; scale: 1.04; translate: -1% -1%; }
}

@keyframes cierre-sube {
  from { opacity: 0; translate: 0 3.5rem; }
}

@keyframes cierre-entra {
  from { opacity: 0; translate: 3rem 0; }
}

@keyframes cierre-traza-x {
  from { scale: 0 1; }
}

@keyframes cierre-traza-y {
  from { scale: 1 0; }
}

@keyframes cierre-nodo {
  from { opacity: 0; scale: 0; }
}

@keyframes cierre-borde {
  from { border-color: transparent; }
}
