/*
 * Video from YouTube, Vimeo, TikTok or Instagram: a poster with a Play button; the service's player loads on click (embeds.js).
 *
 * .mpvw-embed fills the slide. Behind, the poster blurred; in front, .mpvw-embed__frame in the video's own
 * proportions (--mpvw-embed-ratio, set by embeds.js from data-ratio), centred. The frame holds the poster and
 * later the player, so a 16:9 video in a 3:4 gallery is neither cropped nor stretched and nothing jumps on Play.
 *
 * Sizes use !important where WooCommerce and themes size every gallery img or iframe (`height: auto`, ratios).
 */
.mpvw-embed-box {
    display: block;
    width: 100%;
    height: 0;
    /* The photos' proportions once embeds.js has read them, otherwise 16:9. */
    padding: 0 0 var(--mpvw-ratio-pad, 56.25%);
    margin: 0;
    position: relative;
}

.mpvw-embed-box > .mpvw-embed {
    position: absolute;
    inset: 0;
}

.mpvw-embed-inline {
    position: relative;
    /* No width: a block is as wide as the content already, and themes (Blocksy) set the content width
       on the blocks of a post themselves. */
    aspect-ratio: 16 / 9;
}

.mpvw-embed {
    position: relative;
    overflow: hidden;
    width: 100%;
    height: 100%;
    background: #000;
    container-type: size;
}

.mpvw-embed .mpvw-embed__backdrop {
    position: absolute !important;
    inset: 0;
    display: block;
    width: 100% !important;
    height: 100% !important;
    max-width: none;
    object-fit: cover;
    filter: blur(28px) brightness(.55);
    transform: scale(1.15);
}

.mpvw-embed__frame {
    position: absolute;
    top: 50%;
    left: 50%;
    width: min(100cqw, 100cqh * var(--mpvw-embed-ratio, 1.7778));
    height: min(100cqh, 100cqw / var(--mpvw-embed-ratio, 1.7778));
    transform: translate(-50%, -50%);
    overflow: hidden;
    background: #000;
}

/* No poster (the service did not give one): the service's colours behind the Play button. */
.mpvw-embed[data-provider="instagram"] .mpvw-embed__frame {
    background: linear-gradient(45deg, #feda75, #fa7e1e 25%, #d62976 50%, #962fbf 75%, #4f5bd5);
}

.mpvw-embed[data-provider="tiktok"] .mpvw-embed__frame {
    background: radial-gradient(circle at 30% 30%, rgba(37, 244, 238, .35), transparent 55%),
        radial-gradient(circle at 70% 70%, rgba(254, 44, 85, .35), transparent 55%), #010101;
}

.mpvw-embed--playing[data-provider] .mpvw-embed__frame {
    background: #000;
}

.mpvw-embed .mpvw-embed__poster,
.mpvw-embed iframe {
    position: absolute !important;
    inset: 0;
    display: block;
    width: 100% !important;
    height: 100% !important;
    max-width: none;
    margin: 0;
    border: 0;
}

.mpvw-embed .mpvw-embed__poster {
    object-fit: cover;
}

/* Instagram's player: a card at its own size (360px wide, as tall as Instagram says), scaled to fit (embeds.js). */
.mpvw-embed iframe.mpvw-embed__ig {
    inset: auto;
    top: 50% !important;
    left: 50% !important;
    width: 360px !important;
    height: var(--mpvw-ig-height, 850px) !important;
    transform-origin: 50% 50%;
    opacity: 0;
    transition: opacity .2s ease;
}

.mpvw-embed--ig-ready iframe.mpvw-embed__ig {
    opacity: 1;
}

.mpvw-embed--playing[data-provider="instagram"] .mpvw-embed__frame {
    visibility: hidden;
}

.mpvw-embed--playing[data-provider="instagram"]:not(.mpvw-embed--ig-ready)::after {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    width: 2.5rem;
    height: 2.5rem;
    margin: -1.25rem 0 0 -1.25rem;
    border: 3px solid rgba(255, 255, 255, .35);
    border-top-color: #fff;
    border-radius: 50%;
    animation: mpvw-embed-spin .8s linear infinite;
}

@keyframes mpvw-embed-spin {
    to { transform: rotate(360deg); }
}

/* While the player runs, the poster under it is not needed. */
.mpvw-embed--playing .mpvw-embed__poster {
    visibility: hidden;
}

.mpvw-embed .mpvw-embed__play {
    position: absolute;
    top: 50%;
    left: 50%;
    width: 4.5rem;
    height: 4.5rem;
    margin: -2.25rem 0 0 -2.25rem;
    padding: 0;
    border: 0;
    border-radius: 50%;
    background: rgba(255, 255, 255, .95);
    box-shadow: 0 0 0 .5rem rgba(255, 255, 255, .25), 0 .9rem 1.8rem -.7rem rgba(0, 0, 0, .6);
    cursor: pointer;
    transition: transform .15s ease;
}

.mpvw-embed .mpvw-embed__play::before {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    margin: -.8rem 0 0 -.5rem;
    border-left: 1.4rem solid #20113d;
    border-top: .9rem solid transparent;
    border-bottom: .9rem solid transparent;
}

.mpvw-embed .mpvw-embed__play:hover,
.mpvw-embed .mpvw-embed__play:focus-visible {
    transform: scale(1.06);
}

.mpvw-embed .mpvw-embed__play:focus-visible {
    outline: 3px solid #8045f4;
    outline-offset: 3px;
}

@media (prefers-reduced-motion: reduce) {
    .mpvw-embed .mpvw-embed__play {
        transition: none;
    }
}

/* Play badge on the gallery thumbnail of the video slide. */
.flex-control-thumbs li.mpvw-video-thumb,
.flexy-pills li.mpvw-video-thumb {
    position: relative;
}

.flex-control-thumbs li.mpvw-video-thumb:before,
.flexy-pills li.mpvw-video-thumb:before {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 0;
    height: 0;
    border-left: 1.3rem solid #fff;
    border-top: 1rem solid transparent;
    border-bottom: 1rem solid transparent;
    z-index: 1;
    pointer-events: none;
}

/* Source for the WooCommerce lightbox only (the poster). Themes often set `img { display: block }`,
   which beats the [hidden] attribute, so hide it explicitly (styles.css is not loaded for these videos). */
.woocommerce-product-gallery__image--mpvw .mpvw-lightbox-source {
    display: none !important;
}

/* Shop and category grids: the video's poster over the product image, with a play mark. */
.mpvw-loop-embed {
    position: relative;
    display: block;
    overflow: hidden;
}

.mpvw-loop-embed > img.mpvw-loop-embed__poster {
    position: absolute !important;
    inset: 0;
    width: 100% !important;
    height: 100% !important;
    max-width: none;
    margin: 0;
    object-fit: cover;
}

.mpvw-loop-embed__play {
    position: absolute;
    top: 50%;
    left: 50%;
    width: 3rem;
    height: 3rem;
    margin: -1.5rem 0 0 -1.5rem;
    border-radius: 50%;
    background: rgba(255, 255, 255, .95);
    box-shadow: 0 0 0 .35rem rgba(255, 255, 255, .25), 0 .6rem 1.2rem -.5rem rgba(0, 0, 0, .6);
    pointer-events: none;
}

.mpvw-loop-embed__play::before {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    margin: -.55rem 0 0 -.3rem;
    border-left: .95rem solid #20113d;
    border-top: .6rem solid transparent;
    border-bottom: .6rem solid transparent;
}

/* WooCommerce lightbox (PhotoSwipe): the video in its own proportions, centred, as large as the screen allows. */
.mpvw-pswp {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 100%;
    height: 100%;
    padding: 44px 0;
    box-sizing: border-box;
}

.mpvw-pswp > .mpvw-embed {
    width: min(100%, calc((100vh - 88px) * var(--mpvw-embed-ratio, 1.7778)));
    height: auto;
    aspect-ratio: var(--mpvw-embed-ratio, 1.7778);
}

/* Gallery without a slider: the video is a tile in the list, its poster with a play mark;
   it plays in the lightbox. The poster takes the photos' proportions (--mpvw-ratio). */
.woocommerce-product-gallery__image--mpvw .mpvw-tile {
    position: relative;
    display: block;
}

.woocommerce-product-gallery__image--mpvw .mpvw-tile__poster {
    display: block;
    width: 100% !important;
    height: auto !important;
    aspect-ratio: var(--mpvw-ratio, auto);
    object-fit: cover;
}

.woocommerce-product-gallery__image--mpvw .mpvw-tile__play {
    position: absolute;
    top: 50%;
    left: 50%;
    width: 2.75rem;
    height: 2.75rem;
    margin: -1.375rem 0 0 -1.375rem;
    border-radius: 50%;
    background: rgba(255, 255, 255, .95);
    box-shadow: 0 0 0 .3rem rgba(255, 255, 255, .25), 0 .5rem 1rem -.4rem rgba(0, 0, 0, .6);
    pointer-events: none;
}

.woocommerce-product-gallery__image--mpvw .mpvw-tile__play::before {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    margin: -.5rem 0 0 -.28rem;
    border-left: .85rem solid #20113d;
    border-top: .55rem solid transparent;
    border-bottom: .55rem solid transparent;
}

/* Grid card playing its YouTube or Vimeo video ("Start without a click"): the player fills the card,
   centred and cropped (sized by embeds.js), and lets clicks through to the product link. */
.mpvw-loop-embed > iframe.mpvw-loop-embed__frame {
    position: absolute;
    top: 50%;
    left: 50%;
    max-width: none;
    margin: 0;
    border: 0;
    transform: translate(-50%, -50%);
    pointer-events: none;
}

.mpvw-loop-embed--playing .mpvw-loop-embed__play {
    display: none;
}

/* Blocksy: the video is a slide of the theme's own slider (includes/blocksy.php). The poster image keeps
   the slide the size of the photos; the player covers it. */
.mpvw-blocksy-slide {
    position: relative;
}

/* The poster under the player only sizes the slide (it would show at the edges of a video that does not fill it). */
.mpvw-blocksy-slide > img {
    visibility: hidden;
}

.mpvw-blocksy-slide > .woocommerce-product-gallery__image--mpvw {
    position: absolute;
    inset: 0;
    z-index: 2;
}

.mpvw-blocksy-slide .mpvw-embed-box {
    height: 100%;
    padding: 0;
}
