/* ==========================================================================
   ZECSA · Vídeo (M3): reproductor de la película con fachada, capítulos, bucles ambientales y teaser.
   Marcado: app/templates/public/partials/reproductor.php · Comportamiento: assets/js/motion/video.js.
   Las páginas lo cargan con Page::start(['css' => ['motion/video.css']]). Solo tokens semánticos;
   el reproductor y los bucles viven siempre sobre «Nocturno» (basalto) para que el póster y el vídeo
   no dependan del tema. Movimiento decorativo solo con prefers-reduced-motion: no-preference.
   ========================================================================== */

@layer motion {
  /* ------------------------------------------------------------ Película */
  .reproductor--pelicula { aspect-ratio: auto; overflow: visible; background: none; border-radius: 0; color: var(--c-texto); }
  .reproductor__marco {
    position: relative; aspect-ratio: 16 / 9; overflow: hidden; isolation: isolate; container-type: inline-size;
    border-radius: var(--radio-m); background: var(--basalto); color: var(--niebla);
    box-shadow: 0 0 0 1px rgb(233 240 234 / 0.08), var(--sombra-3);
  }
  .reproductor__fachada { position: absolute; inset: 0; }
  .reproductor__fachada[hidden] { display: none; }
  .reproductor__poster-marco, .reproductor__poster { position: absolute; inset: 0; width: 100%; height: 100%; }
  .reproductor__poster { object-fit: cover; }
  .reproductor__fachada::after {
    content: ""; position: absolute; inset: 0; pointer-events: none; z-index: 1;
    background:
      radial-gradient(70% 60% at 50% 52%, rgb(12 19 16 / 0.05), rgb(12 19 16 / 0.5)),
      linear-gradient(to top, rgb(12 19 16 / 0.72), rgb(12 19 16 / 0) 46%);
  }
  /* Esquinas de cuaderno («Bitácora») sobre el póster. */
  .reproductor__esquinas {
    position: absolute; inset: clamp(10px, 3.2%, 28px); z-index: 2; pointer-events: none; color: rgb(233 240 234 / 0.55);
    --e: clamp(12px, 1.6vw, 24px);
    background:
      linear-gradient(currentColor, currentColor) top left / var(--e) 1px no-repeat,
      linear-gradient(currentColor, currentColor) top left / 1px var(--e) no-repeat,
      linear-gradient(currentColor, currentColor) top right / var(--e) 1px no-repeat,
      linear-gradient(currentColor, currentColor) top right / 1px var(--e) no-repeat,
      linear-gradient(currentColor, currentColor) bottom left / var(--e) 1px no-repeat,
      linear-gradient(currentColor, currentColor) bottom left / 1px var(--e) no-repeat,
      linear-gradient(currentColor, currentColor) bottom right / var(--e) 1px no-repeat,
      linear-gradient(currentColor, currentColor) bottom right / 1px var(--e) no-repeat;
  }
  .reproductor__sello {
    position: absolute; z-index: 2; top: calc(clamp(10px, 3.2%, 28px) + 0.9rem); left: calc(clamp(10px, 3.2%, 28px) + 1rem);
    display: flex; gap: 0.9em; margin: 0;
    font-family: var(--ff-mono); font-size: var(--step--2); font-weight: var(--fw-medium);
    letter-spacing: var(--tracking-etiqueta); text-transform: uppercase; color: var(--niebla);
  }
  .reproductor__sello span:first-child { color: var(--verde-300); }
  @container (max-width: 30rem) { .reproductor__sello { display: none; } }

  .reproductor__play {
    position: absolute; inset: 0; z-index: 3; display: grid; place-items: center; align-content: center; gap: var(--sp-s);
    width: 100%; padding: var(--sp-m); border: 0; background: none; color: #fff; cursor: pointer;
    font: inherit;
  }
  .reproductor__play:focus-visible { outline-offset: -8px; border-radius: var(--radio-m); box-shadow: inset 0 0 0 12px rgb(12 19 16 / 0.35); }
  .reproductor__play-icono {
    position: relative; display: grid; place-items: center;
    width: clamp(3.75rem, 2.6rem + 4.2vw, 6.75rem); height: auto; aspect-ratio: 1; border-radius: 50%; /* anula el alto fijo de components.css */
    background: var(--niebla); color: var(--basalto);
    box-shadow: 0 10px 40px rgb(0 0 0 / 0.35);
    transition: transform var(--dur-ui) var(--ease-viento), background-color var(--dur-micro) ease;
  }
  .reproductor__play-icono .icono { width: 34%; height: 34%; margin-left: 7%; fill: currentColor; stroke-width: 1.2; }
  .reproductor__play-icono::before, .reproductor__play-icono::after {
    content: ""; position: absolute; inset: -12px; border-radius: 50%; border: 1px solid rgb(233 240 234 / 0.42); pointer-events: none;
  }
  .reproductor__play-icono::after { inset: -26px; border-color: rgb(125 240 168 / 0.22); }
  .reproductor__play:hover .reproductor__play-icono, .reproductor__play:focus-visible .reproductor__play-icono { transform: scale(1.06); background: #fff; }
  .reproductor__play-texto {
    display: inline-flex; flex-wrap: wrap; justify-content: center; align-items: baseline; gap: 0.15em 0.5em;
    padding: 0.5em 1.05em; border-radius: var(--radio-pildora);
    background: rgb(12 19 16 / 0.72); -webkit-backdrop-filter: blur(6px); backdrop-filter: blur(6px);
    font-family: var(--ff-texto); font-size: var(--step-0); font-weight: var(--fw-semibold); line-height: 1.25; color: #fff;
  }
  .reproductor__duracion { font-family: var(--ff-mono); font-size: 0.82em; font-weight: var(--fw-medium); letter-spacing: 0.04em; color: var(--ceniza-300); }
  /* Versión audiodescrita al mismo nivel que «Reproducir» (EN 301 549 7.3). En marcos estrechos queda el
     conmutador «Audiodescripción» de la barra, justo debajo del vídeo. */
  .reproductor__play-ad {
    position: absolute; z-index: 4; left: 50%; bottom: clamp(10px, 3.2%, 28px); transform: translateX(-50%);
    display: inline-flex; align-items: center; gap: 0.55em; min-height: 44px; padding: 0.45em 1.1em;
    border: 1px solid rgb(233 240 234 / 0.55); border-radius: var(--radio-pildora);
    background: rgb(12 19 16 / 0.86); color: #fff; cursor: pointer;
    font-family: var(--ff-texto); font-size: var(--step--1); font-weight: var(--fw-semibold); line-height: 1.25; white-space: nowrap;
  }
  .reproductor__play-ad:hover { background: var(--basalto); border-color: #fff; }
  .reproductor__play-ad-icono .icono { width: 1.2em; height: 1.2em; }
  @container (max-width: 34rem) { .reproductor__play-ad { display: none; } }
  .reproductor__noscript-ad { margin-top: var(--sp-xs); }

  @media (prefers-reduced-motion: no-preference) {
    /* Un solo latido (< 5 s): una animación infinita necesitaría control de pausa (WCAG 2.2.2). */
    :root:not([data-motion="reduced"]) .reproductor__play-icono::before { animation: zecsa-latido 3.2s var(--ease-viento) 1; }
    :root:not([data-motion="reduced"]) .reproductor__play-icono::after { animation: zecsa-latido 3.2s var(--ease-viento) 0.5s 1; }
    :root:not([data-motion="reduced"]) .reproductor__poster { transition: transform 1.6s var(--ease-viento); }
    :root:not([data-motion="reduced"]) .reproductor__marco:hover .reproductor__poster { transform: scale(1.025); }
  }
  @keyframes zecsa-latido {
    0% { transform: scale(0.92); opacity: 0; }
    35% { opacity: 1; }
    100% { transform: scale(1.18); opacity: 0; }
  }

  .reproductor__video { position: absolute; inset: 0; width: 100%; height: 100%; background: #000; }
  .reproductor__video:focus-visible { outline-offset: -4px; }
  .reproductor__video::cue {
    background: rgb(12 19 16 / 0.86); color: #fff;
    font-family: "Mona Sans", "Segoe UI", system-ui, sans-serif; line-height: 1.35;
  }
  /* Sin JavaScript: el <video> nativo de <noscript> sustituye a la fachada. */
  .no-js .reproductor__fachada, .no-js [data-video-cc], .no-js [data-video-ad] { display: none; }
  .reproductor__marco > video { position: absolute; inset: 0; width: 100%; height: 100%; }

  /* Barra de opciones bajo la película. */
  .reproductor__pie { margin-top: var(--sp-s); }
  .reproductor__barra { display: flex; flex-wrap: wrap; align-items: center; gap: var(--sp-2xs); }
  .reproductor__opcion {
    display: inline-flex; align-items: center; gap: 0.5rem; min-height: 44px; padding: 0.45rem 1rem;
    border: 1px solid var(--c-borde-control); border-radius: var(--radio-pildora);
    background: transparent; color: var(--c-texto); cursor: pointer;
    font-family: var(--ff-texto); font-size: var(--step--1); font-weight: var(--fw-medium); line-height: 1.2; text-decoration: none;
    transition: background-color var(--dur-micro) ease, color var(--dur-micro) ease, border-color var(--dur-micro) ease;
  }
  .reproductor__opcion:hover { border-color: var(--c-acento-texto); color: var(--c-acento-texto); }
  .reproductor__opcion[aria-pressed="true"] { background: var(--c-boton); border-color: var(--c-boton); color: var(--c-boton-texto); }
  .reproductor__opcion[aria-pressed="true"]:hover { background: var(--c-boton-hover); border-color: var(--c-boton-hover); color: var(--c-boton-texto); }
  .reproductor__atajos { display: block; }
  .reproductor__atajos[open] { flex-basis: 100%; }
  .reproductor__atajos > summary { list-style: none; }
  .reproductor__atajos > summary::-webkit-details-marker { display: none; }
  .reproductor__atajos > summary::after {
    content: ""; width: 0.5em; height: 0.5em; margin-left: 0.15rem; border-right: 1.5px solid currentColor; border-bottom: 1.5px solid currentColor;
    transform: translateY(-0.15em) rotate(45deg); transition: transform var(--dur-ui) var(--ease-viento);
  }
  .reproductor__atajos[open] > summary::after { transform: translateY(0.1em) rotate(-135deg); }
  .atajos {
    display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 17rem), 1fr)); gap: 0.25rem var(--sp-m);
    margin: var(--sp-2xs) 0 0; padding: var(--sp-s) var(--sp-m);
    border: var(--borde); border-radius: var(--radio-m); background: var(--c-superficie);
    font-size: var(--step--1);
  }
  .atajos > div { display: grid; grid-template-columns: minmax(7.5rem, auto) 1fr; gap: var(--sp-xs); align-items: baseline; padding-block: 0.4rem; border-bottom: var(--borde); }
  .atajos dt { color: var(--c-texto); }
  .atajos dd { margin: 0; color: var(--c-texto-suave); }
  kbd {
    display: inline-block; min-width: 1.8em; padding: 0.05em 0.45em; text-align: center;
    border: 1px solid var(--c-borde-control); border-bottom-width: 2px; border-radius: var(--radio-xs);
    background: var(--c-superficie-2); font-family: var(--ff-mono); font-size: 0.85em; line-height: 1.5; color: var(--c-texto);
  }

  .reproductor__descripcion {
    margin-top: var(--sp-s); padding: var(--sp-s) var(--sp-m);
    border-left: 3px solid var(--c-acento); border-radius: 0 var(--radio-s) var(--radio-s) 0; background: var(--c-superficie);
  }
  .reproductor__descripcion[hidden] { display: none; }
  .reproductor__descripcion-texto { margin: 0.35rem 0 0; max-width: 72ch; min-height: 3.2em; font-family: var(--ff-editorial); font-size: var(--step-0); line-height: 1.5; }
  .reproductor__error { margin-top: var(--sp-s); padding: var(--sp-s) var(--sp-m); border: 1px solid var(--c-error); border-radius: var(--radio-s); }

  /* ------------------------------------------------------------ Capítulos */
  .capitulos-pelicula__lista {
    list-style: none; margin: 0; padding: 0;
    display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 9.5rem), 1fr)); gap: 0 var(--medianil);
  }
  .capitulo {
    position: relative; display: grid; grid-template-columns: auto 1fr; grid-template-areas: "num tiempo" "titulo titulo"; gap: 0.35rem 0.75rem;
    min-height: 44px; padding: var(--sp-xs) 0 var(--sp-s);
    border-top: 1px solid var(--c-borde); color: var(--c-texto); text-decoration: none;
    transition: color var(--dur-micro) ease, border-color var(--dur-micro) ease;
  }
  .capitulo__num { grid-area: num; font-family: var(--ff-mono); font-size: var(--step--2); letter-spacing: var(--tracking-etiqueta); color: var(--c-texto-suave); }
  .capitulo__tiempo { grid-area: tiempo; justify-self: end; font-family: var(--ff-mono); font-size: var(--step--2); color: var(--c-texto-suave); font-variant-numeric: tabular-nums; }
  .capitulo__titulo { grid-area: titulo; font-size: var(--step-0); font-weight: var(--fw-semibold); line-height: 1.2; text-wrap: balance; }
  .capitulo__barra { position: absolute; left: 0; top: -1px; height: 2px; width: 100%; background: var(--c-acento); transform-origin: left center; transform: scaleX(var(--progreso, 0)); }
  .capitulo:hover { color: var(--c-acento-texto); border-top-color: var(--c-acento-texto); }
  .capitulo[aria-current="true"] .capitulo__num { color: var(--c-acento-texto); }
  .capitulo[aria-current="true"] .capitulo__titulo { color: var(--c-titulo); }

  /* -------------------------------------------------------------- Bucles */
  .bucle { position: relative; overflow: hidden; isolation: isolate; aspect-ratio: 16 / 9; border-radius: var(--radio-m); background: var(--basalto); color: var(--niebla); }
  .bucle::after { content: ""; position: absolute; inset: 0; z-index: 2; border-radius: inherit; box-shadow: inset 0 0 0 1px rgb(233 240 234 / 0.1); pointer-events: none; }
  .bucle__poster-marco, .bucle__poster, .bucle__video { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; }
  .bucle__video { opacity: 0; }
  .bucle.is-vivo .bucle__video { opacity: 1; }
  @media (prefers-reduced-motion: no-preference) {
    :root:not([data-motion="reduced"]) .bucle__video { transition: opacity 700ms var(--ease-salida); }
  }
  .bucle__pausa {
    position: absolute; z-index: 3; left: var(--sp-s); bottom: var(--sp-s);
    background: rgb(12 19 16 / 0.72); border-color: rgb(233 240 234 / 0.4); color: var(--niebla);
    -webkit-backdrop-filter: blur(6px); backdrop-filter: blur(6px); cursor: pointer;
  }
  .bucle__pausa[hidden] { display: none; }
  .bucle__pausa:hover { border-color: var(--verde-300); color: #fff; }
  .bucle__pausa-icono { display: inline-grid; }
  .bucle__icono-reanudar { display: none; }
  .bucle.is-pausado .bucle__icono-pausa { display: none; }
  .bucle.is-pausado .bucle__icono-reanudar { display: inline-block; }

  /* Teaser: el bucle invita a ver la película (enlace a /pelicula; la pausa queda aparte, nunca anidada). */
  .bucle__enlace {
    position: absolute; inset: 0; z-index: 2; display: grid; place-items: center; align-content: center; gap: var(--sp-s);
    color: #fff; text-decoration: none;
    background: radial-gradient(60% 55% at 50% 50%, rgb(12 19 16 / 0.1), rgb(12 19 16 / 0.55));
  }
  .bucle__enlace:focus-visible { outline-offset: -8px; }
  .bucle__enlace-icono {
    display: grid; place-items: center; width: clamp(3.5rem, 2.6rem + 3.5vw, 5.75rem); aspect-ratio: 1; border-radius: 50%;
    background: var(--niebla); color: var(--basalto); transition: transform var(--dur-ui) var(--ease-viento);
  }
  .bucle__enlace-icono .icono { width: 34%; height: 34%; margin-left: 7%; fill: currentColor; stroke-width: 1.2; }
  .bucle__enlace:hover .bucle__enlace-icono, .bucle__enlace:focus-visible .bucle__enlace-icono { transform: scale(1.06); }
  /* Pastilla casi opaca: ≥ 4,5:1 para el texto y la duración incluso sobre el fotograma más claro (WCAG 1.4.3). */
  .bucle__enlace-texto { padding: 0.45em 1em; border-radius: var(--radio-pildora); background: rgb(12 19 16 / 0.88); font-weight: var(--fw-semibold); }
  .bucle__enlace-duracion { font-family: var(--ff-mono); font-size: 0.85em; font-weight: var(--fw-medium); color: var(--ceniza-300); }

  @media print {
    .reproductor__barra, .reproductor__play, .bucle__pausa, .bucle__video { display: none !important; }
  }
}
