/* ---------------------------------------------------------------------------
   Champ `at_video` (attps-get-field) — lecteur (mode bloc) et calque de fond
   (mode background). Le couplage aux conteneurs (position relative, calque en
   z-index 0, enfants au-dessus) est à la charge du consommateur : cf.
   attps-builder/assets/css/video.css.

   Le fond vidéo reprend le principe du calque d'image de fond
   (.atb-*--bg-images::before) : un calque absolu en z-index 0, les enfants du
   conteneur au-dessus. Le poster est l'image de fond du calque ; la vidéo ou
   l'iframe vient par-dessus une fois chargée par video.js.
   --------------------------------------------------------------------------- */

/* --- Bloc ------------------------------------------------------------------ */

.atgf-video {
    --atgf-video-radius: var(--atb-radius, 0);
    --atgf-video-play-size: 4.5rem;
    --atgf-video-play-bg: var(--atb-primary, #0099DD);
    --atgf-video-play-color: var(--atb-light, #fff);

    position: relative;
    width: 100%;
    overflow: hidden;
    border-radius: var(--atgf-video-radius);
    background: #000;
}

.atgf-video--aspect-16-9 { aspect-ratio: 16 / 9; }
.atgf-video--aspect-4-3  { aspect-ratio: 4 / 3; }
.atgf-video--aspect-1-1  { aspect-ratio: 1 / 1; }
.atgf-video--aspect-9-16 { aspect-ratio: 9 / 16; }
.atgf-video--aspect-21-9 { aspect-ratio: 21 / 9; }

.atgf-video__media,
.atgf-video iframe {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    border: 0;
    display: block;
}

.atgf-video__media {
    object-fit: cover;
}

/* Ratio auto : le média dicte sa hauteur (fichier local surtout). */
.atgf-video--aspect-auto .atgf-video__media {
    position: static;
    height: auto;
    object-fit: initial;
}

.atgf-video--aspect-auto .atgf-video__facade {
    position: relative;
    aspect-ratio: 16 / 9;
}

/* Fournisseur inconnu : l'HTML oEmbed n'est pas positionné par nos soins. */
.atgf-video--embed {
    aspect-ratio: auto;
    background: transparent;
}

.atgf-video--embed iframe {
    position: static;
    aspect-ratio: 16 / 9;
    height: auto;
}

/* --- Façade (clic pour charger) ------------------------------------------- */

.atgf-video__facade {
    appearance: none;
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    margin: 0;
    padding: 0;
    border: 0;
    background: #000;
    cursor: pointer;
    display: block;
}

.atgf-video__poster {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    object-fit: cover;
    transition: transform var(--atb-transition-slow, 0.3s ease), opacity var(--atb-transition, 0.2s ease);
}

.atgf-video__facade:hover .atgf-video__poster,
.atgf-video__facade:focus-visible .atgf-video__poster {
    transform: scale(1.03);
}

.atgf-video__play {
    position: absolute;
    top: 50%;
    left: 50%;
    width: var(--atgf-video-play-size);
    height: var(--atgf-video-play-size);
    transform: translate(-50%, -50%);
    border-radius: 50%;
    background: var(--atgf-video-play-bg);
    box-shadow: var(--atb-shadow-lg, 0 12px 32px rgba(0, 0, 0, 0.12));
    transition: transform var(--atb-transition, 0.2s ease);
}

.atgf-video__play::after {
    content: '';
    position: absolute;
    top: 50%;
    left: 54%;
    transform: translate(-50%, -50%);
    border-style: solid;
    border-width: 0.9rem 0 0.9rem 1.5rem;
    border-color: transparent transparent transparent var(--atgf-video-play-color);
}

.atgf-video__facade:hover .atgf-video__play,
.atgf-video__facade:focus-visible .atgf-video__play {
    transform: translate(-50%, -50%) scale(1.08);
}

.atgf-video__facade:focus-visible {
    outline: 3px solid var(--atgf-video-play-bg);
    outline-offset: -3px;
}

/* --- Calque de fond (mode background) : le média dans son calque ------------ */

/* Le calque lui-même est positionné par le consommateur (ex. .atb-section--bg-video
   > .atgf-bg-video dans le builder) ; on ne fixe ici que son remplissage. */
.atgf-bg-video {
    overflow: hidden;
    background-size: cover;
    background-position: center;
    opacity: var(--atgf-video-opacity, 1);
    pointer-events: none;
}



.atgf-bg-video__media {
    position: absolute;
    top: 50%;
    left: 50%;
    width: 100%;
    height: 100%;
    transform: translate(-50%, -50%);
    border: 0;
    object-fit: cover;
    opacity: 0;
    transition: opacity var(--atb-transition-slow, 0.3s ease);
}

/* Une fois chargée (classe posée par video.js), la vidéo recouvre le poster. */
.atgf-bg-video.is-playing .atgf-bg-video__media {
    opacity: 1;
}

/* Une iframe n'a pas d'object-fit : video.js la dimensionne pour couvrir le
   calque (ratio 16:9), d'où width/height inline. */
iframe.atgf-bg-video__media {
    max-width: none;
    max-height: none;
}

/* Fond désactivé sur mobile : le poster reste, video.js ne charge rien. */
@media (max-width: 768px) {
    .atgf-bg-video--no-mobile .atgf-bg-video__media {
        display: none;
    }
}

@media (prefers-reduced-motion: reduce) {
    .atgf-bg-video .atgf-bg-video__media {
        display: none;
    }
}
