/**
 * Component: background video (homepage hero, subpage hero).
 *
 * Markup from cartrack_background_video() and cartrack_video_toggle()
 * (inc/components.php); js/background-video.js attaches the source only
 * from --bp-md, without reduced motion and on a fast connection, then adds
 * .is-video-ready to the [data-bg-video] container. Until then (and on
 * mobile) the poster image underneath stays visible. The toggle's position
 * belongs to the context. Values come from assets/css/tokens.css.
 *
 * @package cartrack
 */

.bg-video {
	position: absolute;
	inset: 0;
	display: none;
	width: 100%;
	height: 100%;
	object-fit: cover;
	opacity: 0;
	transition: opacity var(--transition-base);
}

.is-video-ready .bg-video {
	opacity: 1;
}

/* Scale an iframe so it covers the box like object-fit: cover. */
.bg-video--embed {
	container-type: size;
	pointer-events: none;
}

.bg-video--embed iframe {
	position: absolute;
	top: 50%;
	left: 50%;
	width: max(100cqw, 177.78cqh);
	height: max(100cqh, 56.25cqw);
	border: 0;
	transform: translate(-50%, -50%);
}

/* ---------- Pause / play toggle ---------- */

.video-toggle {
	display: inline-flex;
	align-items: center;
	justify-content: center;
	width: var(--video-toggle-size);
	height: var(--video-toggle-size);
	padding: 0;
	border: 1px solid var(--color-border-inverse);
	border-radius: 50%;
	background-color: var(--video-toggle-bg);
	color: var(--color-text-inverse);
	cursor: pointer;
}

.video-toggle[hidden] {
	display: none;
}

.video-toggle:focus-visible {
	outline: 2px solid var(--color-focus);
	outline-offset: 2px;
}

/* Pause icon: two bars. */
.video-toggle__icon {
	width: 0.75rem;
	height: 0.75rem;
	border-inline: 0.25rem solid currentColor;
}

/* Play icon: triangle. */
.video-toggle.is-paused .video-toggle__icon {
	width: 0;
	border-inline-end: 0;
	border-inline-start: 0.7rem solid currentColor;
	border-block: 0.4rem solid transparent;
	height: 0;
}

/* Video is only attached by JS at this width and up. */
@media (min-width: 48em) { /* --bp-md */
	.bg-video {
		display: block;
	}
}

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