/*
 * Product Gallery video: YouTube players laid over WooCommerce's empty
 * <video> stand-ins (view.js builds them).
 *
 * Gallery slide: a muted preview covering the slide (cropped like the slide's
 * images, object-fit: cover). Clicks pass through to the stand-in, which keeps
 * WooCommerce's click (opens the lightbox) and swipe handlers. The Play video
 * Button block sits centred above it.
 *
 * Lightbox: the full player, placed by view.js exactly over the lightbox's
 * stand-in, which keeps its place in the list (WooCommerce plays and pauses
 * it as it scrolls into view).
 */
.wp-block-woocommerce-product-image:has( > .tccc-gallery-youtube ) {
	position: relative;
	overflow: hidden;
}

.tccc-gallery-youtube {
	position: absolute;
	/*
	 * Level with the stand-in (WooCommerce stacks slides at 1) and drawn after
	 * it, so above it; the gallery's arrows are also at 1 and come later in
	 * the markup, so they stay on top. Any higher covers the arrows.
	 */
	z-index: 1;
	overflow: hidden;
}

.tccc-gallery-youtube iframe {
	display: block;
	border: 0;
}

/* Gallery slide */
.tccc-gallery-youtube--gallery {
	inset: 0;
	pointer-events: none;
}

/*
 * Faded in once YouTube first plays, so the poster shows until then. The
 * slide only: the lightbox has no poster, so its player shows straight away
 * with YouTube's own thumbnail and spinner.
 */
.tccc-gallery-youtube--gallery iframe {
	opacity: 0;
	transition: opacity 0.3s ease;
}

.tccc-gallery-youtube--gallery.has-played iframe {
	opacity: 1;
}

/*
 * The product's featured image, shown until YouTube plays. The iframe comes
 * after it in the markup, so it covers the image once faded in.
 */
.tccc-gallery-youtube__cover {
	position: absolute;
	inset: 0;
	width: 100%;
	height: 100%;
	object-fit: cover;
}

.tccc-gallery-youtube--gallery iframe {
	position: absolute;
	top: 50%;
	left: 50%;
	translate: -50% -50%;
}

.tccc-gallery-youtube__play {
	position: absolute;
	top: 50%;
	left: 50%;
	translate: -50% -50%;
	/* Same as the player above: over the video, under the arrows. */
	z-index: 1;
	white-space: nowrap;
}

/* Lightbox: view.js sets top, left, width and height from the stand-in. */
.wc-block-product-gallery-dialog__content:has( > .tccc-gallery-youtube--dialog ) {
	position: relative;
}

.tccc-gallery-youtube--dialog iframe {
	width: 100%;
	height: 100%;
}

/*
 * Play icon on the video's thumbnail: a Boxed Icon block added at render
 * (product-gallery-video.php), centred. Decorative, so it never takes clicks.
 */
.wc-block-product-gallery-thumbnails__thumbnail--video {
	position: relative;
}

.tccc-gallery-youtube__thumbnail-icon {
	position: absolute;
	top: 50%;
	left: 50%;
	translate: -50% -50%;
	/* Above the thumbnail image, which WooCommerce stacks at z-index 1. */
	z-index: 2;
	pointer-events: none;
}
