/* [uw_video] facade: the play button over the thumbnail. */

/**
 * Shared styling for the [uw_video] shortcode's YouTube facade
 * (inc/shortcode-converters.php: .uw-video-embed > .uw-video-thumb +
 * .uw-video-play). Until now nothing in the theme styled it, so the play
 * button rendered as a static block below the thumbnail, sized by its own
 * unsized SVG: hundreds of pixels of blank white space and no visible
 * button, on all 42 products that carry the shortcode.
 *
 * SCOPING: woocommerce/taxonomy-product_cat.php reuses the class name
 * `.uw-video-embed` for three unrelated, self-contained implementations
 * (Tailwind utilities + inline onclick), and those already work. A bare
 * `.uw-video-embed { ... }` rule here would land on them too and is very
 * likely to break them (their inner element already carries its own
 * `overflow-hidden` + `shadow-lg`, so an outer `overflow: hidden` from this
 * file would clip that shadow).
 *
 * Every rule below is therefore scoped to `.uw-video-embed:has(.uw-video-play)`
 * instead of the bare class. `.uw-video-play` is a class only this
 * shortcode's own render ever uses (the category variants build their play
 * badge with unrelated Tailwind utility divs, no such class), so the
 * compound selector reaches exactly this markup and nothing else, with no
 * markup change required. `:has()` has full support in evergreen Chrome,
 * Safari and Firefox since 2023; this theme has no older-browser target.
 *
 * The click/keyboard handler lives in video-embed.js, enqueued alongside
 * this file only on single product pages (see inc/video-embed.php).
 */

.uw-video-embed:has(.uw-video-play) {
    position: relative;
    display: block;
    width: 100%;
    aspect-ratio: 16 / 9;
    max-width: 100%;
    margin: 1.5rem 0;
    border-radius: 0.75rem;
    overflow: hidden;
    cursor: pointer;
    background: #111;
}

/*
 * The thumbnail falls back from maxresdefault.jpg (1280x720, true 16:9) to
 * hqdefault.jpg (480x360, 4:3 with the real frame letterboxed inside it) via
 * the shortcode's own onerror handler. Locking the facade to a fixed
 * aspect-ratio box and letting the image cover it means neither source
 * changes the facade's footprint or introduces layout shift when the
 * fallback fires.
 */
.uw-video-embed:has(.uw-video-play) .uw-video-thumb {
    display: block;
    width: 100%;
    height: 100%;
    object-fit: cover;
}

/*
 * Once video-embed.js swaps in the real player, the wrapper no longer
 * contains `.uw-video-play`, so the `:has()` rule above stops matching and
 * would drop the box's own sizing along with it. `--playing` restates the
 * same shape (not just the parts specific to holding an iframe) so the
 * facade never resizes or jumps at the moment it starts playing.
 */
.uw-video-embed.uw-video-embed--playing {
    position: relative;
    display: block;
    width: 100%;
    aspect-ratio: 16 / 9;
    max-width: 100%;
    margin: 1.5rem 0;
    border-radius: 0.75rem;
    overflow: hidden;
    background: #111;
    cursor: auto;
}

.uw-video-embed.uw-video-embed--playing iframe {
    display: block;
    width: 100%;
    height: 100%;
    border: 0;
}

.uw-video-embed:has(.uw-video-play) .uw-video-play {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 4.5rem;
    height: 4.5rem;
    border-radius: 9999px;
    background: rgba(0, 0, 0, 0.55);
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background-color 0.2s ease, transform 0.2s ease;
    /* The wrapper (role="button") owns the click; the badge is decoration. */
    pointer-events: none;
}

.uw-video-embed:has(.uw-video-play) .uw-video-play svg {
    width: 1.75rem;
    height: 1.75rem;
    flex: none;
}

@media (max-width: 480px) {
    .uw-video-embed:has(.uw-video-play) .uw-video-play {
        width: 3.25rem;
        height: 3.25rem;
    }

    .uw-video-embed:has(.uw-video-play) .uw-video-play svg {
        width: 1.25rem;
        height: 1.25rem;
    }
}

.uw-video-embed:has(.uw-video-play):hover .uw-video-play,
.uw-video-embed:has(.uw-video-play):focus-visible .uw-video-play {
    background: rgba(0, 0, 0, 0.75);
    transform: translate(-50%, -50%) scale(1.08);
}

/*
 * role="button" tabindex="0" already sit on the wrapper (the shortcode's own
 * markup), so it is keyboard-reachable; this is its visible focus state.
 * An inset outline is used because the facade can butt against a light page
 * background, where an outset outline on a dark box is easy to miss.
 */
.uw-video-embed:has(.uw-video-play):focus-visible {
    outline: 3px solid #fff;
    outline-offset: -4px;
    box-shadow: 0 0 0 1px rgba(0, 0, 0, 0.6);
}
