/**
 * Video modal block (image with play button) and the shared modal: front end and editor.
 *
 * Motion uses the theme tokens (theme.json settings.custom.motion). Reduced motion zeroes
 * the durations (style.css), so everything below becomes instant without extra rules.
 *
 * Mobile layout (Figma "Design - Mobile Video"): heading, then video, then Watch + Read on
 * one row. Desktop keeps text left / video right via the Columns block; mobile reorders with
 * display:contents so the heading stays above the video.
 */

/*
 * Image with the play button centred over it. The frame has a background of its own: Page
 * (paper) darkened a touch toward Not as Dark, so before the image loads, or while there is no
 * image yet (is-placeholder, a 16:9 rectangle), it still reads as a video frame on paper.
 */
.wp-block-a-paul-singh-video-modal,
.aps-video-modal {
	--aps-video-frame-bg: color-mix(in srgb, var(--wp--preset--color--page) 88%, var(--wp--preset--color--not-as-dark));
}

.wp-block-a-paul-singh-video-modal {
	position: relative;
	margin: 0;
	overflow: hidden;
	background-color: var(--aps-video-frame-bg);
}

.wp-block-a-paul-singh-video-modal.is-placeholder {
	aspect-ratio: 16 / 9;
}

.wp-block-a-paul-singh-video-modal__image {
	display: block;
	width: 100%;
	height: auto;
	border-radius: inherit;
}

/* The whole image is the button; the play icon is its visible part. */
.wp-block-a-paul-singh-video-modal__trigger {
	position: absolute;
	inset: 0;
	display: flex;
	align-items: center;
	justify-content: center;
	width: 100%;
	margin: 0;
	padding: 0;
	border: 0;
	border-radius: inherit;
	background: transparent;
	color: inherit;
	cursor: pointer;
}

/* Figma "Play Button": a Page-colour disc with a dark triangle (64px desktop, ~40px mobile). */
.wp-block-a-paul-singh-video-modal__play {
	display: block;
	width: 4rem;
	height: 4rem;
	/*
	 * Scale feedback: 0.7 × quick (200ms → 140ms). Base transition = mouse-out
	 * (ease-out); :hover / :focus-visible overrides timing to ease-in.
	 */
	transition: transform calc( var( --wp--custom--motion--duration--quick ) * 0.7 )
		var( --wp--custom--motion--easing--out );
}

.wp-block-a-paul-singh-video-modal__play-disc {
	fill: var(--wp--preset--color--page);
}

.wp-block-a-paul-singh-video-modal__play-triangle {
	fill: var(--wp--preset--color--not-as-dark);
}

.wp-block-a-paul-singh-video-modal__trigger:is(:hover, :focus-visible) .wp-block-a-paul-singh-video-modal__play {
	transform: scale(1.06);
	transition-timing-function: var( --wp--custom--motion--easing--in );
}

.wp-block-a-paul-singh-video-modal__trigger:focus-visible {
	outline: 2px solid var(--wp--preset--color--page);
	outline-offset: -6px;
}

@media ( prefers-reduced-motion: reduce ) {
	.wp-block-a-paul-singh-video-modal__play {
		transition: none;
	}

	.wp-block-a-paul-singh-video-modal__trigger:is(:hover, :focus-visible) .wp-block-a-paul-singh-video-modal__play {
		transform: none;
	}
}

/* Editor preview: the same play icon, not interactive. */
.wp-block-a-paul-singh-video-modal.is-editor-preview::after {
	content: "";
	position: absolute;
	inset: 0;
}

.wp-block-a-paul-singh-video-modal.is-editor-preview .wp-block-a-paul-singh-video-modal__trigger {
	pointer-events: none;
}

/*
 * Shared modal (printed once in the footer). Opening: the Page-colour overlay fades in
 * over the "reveal" token. Only after that finishes does the grey stage fade in (half
 * "reveal"). The iframe fades up from slightly smaller once the overlay is mostly in
 * (80%). Closing: overlay and stage fade out together over the "reveal" token (stage has
 * no close delay, so it never floats after the backdrop). Overlay and close button only —
 * player chrome stays the provider's. Reduced motion zeroes the tokens (style.css), so
 * delay and duration become 0 with no extra rule.
 *
 * Backdrop fill is Page at 0.95 alpha (not element opacity), so when open the stage /
 * video stay fully opaque while the page shows through the overlay slightly.
 */
.aps-video-modal {
	--aps-video-modal-fade: var(--wp--custom--motion--duration--reveal);
	--aps-video-modal-stage-delay: var(--aps-video-modal-fade);
	--aps-video-modal-stage-duration: calc(var(--wp--custom--motion--duration--reveal) / 2);
	position: fixed;
	inset: 0;
	z-index: 100001;
	display: flex;
	align-items: center;
	justify-content: center;
	background-color: color-mix( in srgb, var( --wp--preset--color--page ) 95%, transparent );
	opacity: 0;
	visibility: hidden;
	pointer-events: none;
	transition:
		opacity var(--wp--custom--motion--duration--reveal) var(--wp--custom--motion--easing--in-out),
		visibility 0s linear var(--wp--custom--motion--duration--reveal);
}

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

.aps-video-modal.is-open {
	opacity: 1;
	visibility: visible;
	pointer-events: auto;
	transition:
		opacity var(--aps-video-modal-fade) var(--wp--custom--motion--easing--out),
		visibility 0s linear 0s;
}

/* Figma close (Group 2): 34px hit area, Not as Dark X. */
.aps-video-modal__close {
	position: absolute;
	top: 1.5rem;
	right: 1.5rem;
	z-index: 4;
	display: flex;
	align-items: center;
	justify-content: center;
	width: 2.125rem;
	height: 2.125rem;
	margin: 0;
	padding: 0;
	border: 0;
	border-radius: 0;
	background: transparent;
	box-shadow: none;
	color: var(--wp--preset--color--not-as-dark);
	cursor: pointer;
	transition: opacity var(--wp--custom--motion--duration--quick) var(--wp--custom--motion--easing--out);
}

.aps-video-modal__close-icon {
	display: block;
	width: 1.5rem;
	height: 1.5rem;
}

.aps-video-modal__close-icon line {
	stroke: currentColor;
}

.aps-video-modal__close:is(:hover, :focus-visible) {
	background: transparent;
	color: var(--wp--preset--color--not-as-dark);
	opacity: 0.55;
}

.aps-video-modal__close:focus-visible {
	outline: 2px solid var(--wp--preset--color--not-as-dark);
	outline-offset: 2px;
}

/*
 * The video rectangle: the same darker paper as the on-page frame, so it reads as a video
 * area on the Page overlay. Opacity starts at 0; open waits for the overlay fade to finish,
 * then fades in over half "reveal". Close uses the same duration with no delay.
 */
.aps-video-modal__stage {
	box-sizing: border-box;
	background-color: var(--aps-video-frame-bg);
	width: min(92vw, 1100px);
	max-height: 85vh;
	aspect-ratio: 16 / 9;
	opacity: 0;
	transition: opacity var(--aps-video-modal-stage-duration) var(--wp--custom--motion--easing--in-out);
}

.aps-video-modal.is-open .aps-video-modal__stage {
	opacity: 1;
	transition: opacity var(--aps-video-modal-stage-duration) var(--wp--custom--motion--easing--out) var(--aps-video-modal-stage-delay);
}

/* The wrapper is animated, not the iframe: transforms on iframes are often a visual no-op. */
.aps-video-modal__embed {
	width: 100%;
	height: 100%;
	opacity: 0;
	transform: scale(0.95);
	transition:
		opacity var(--wp--custom--motion--duration--reveal) var(--wp--custom--motion--easing--out),
		transform var(--wp--custom--motion--duration--reveal) var(--wp--custom--motion--easing--out);
}

.aps-video-modal__embed.is-visible {
	opacity: 1;
	transform: none;
}

.aps-video-modal__embed iframe {
	display: block;
	width: 100%;
	height: 100%;
	border: 0;
}

body.aps-video-modal-open {
	overflow: hidden;
}

/*
 * Mobile (Figma "Design - Mobile Video" / transcript / Open): columns stack at 781px.
 * Lift the text column's children so heading → video → Watch/Read can be ordered.
 */
@media (max-width: 781px) {
	.wp-block-columns:has(> .wp-block-column .wp-block-a-paul-singh-video-modal) {
		display: flex;
		flex-direction: column;
		gap: var(--wp--preset--spacing--40, 1.5rem);
	}

	.wp-block-columns:has(> .wp-block-column .wp-block-a-paul-singh-video-modal) > .wp-block-column:not(:has(.wp-block-a-paul-singh-video-modal)) {
		display: contents;
	}

	.wp-block-columns:has(> .wp-block-column .wp-block-a-paul-singh-video-modal) > .wp-block-column:not(:has(.wp-block-a-paul-singh-video-modal)) > .wp-block-heading {
		order: 1;
	}

	.wp-block-columns:has(> .wp-block-column .wp-block-a-paul-singh-video-modal) > .wp-block-column:has(.wp-block-a-paul-singh-video-modal) {
		order: 2;
		flex-basis: auto !important;
		width: 100%;
	}

	.wp-block-columns:has(> .wp-block-column .wp-block-a-paul-singh-video-modal) > .wp-block-column:not(:has(.wp-block-a-paul-singh-video-modal)) > .wp-block-group {
		order: 3;
		display: flex;
		flex-wrap: nowrap;
		align-items: center;
		justify-content: space-between;
		gap: 0.75rem;
		width: 100%;
	}

	.wp-block-columns:has(> .wp-block-column .wp-block-a-paul-singh-video-modal) > .wp-block-column:not(:has(.wp-block-a-paul-singh-video-modal)) > .wp-block-group .wp-block-buttons,
	.wp-block-columns:has(> .wp-block-column .wp-block-a-paul-singh-video-modal) > .wp-block-column:not(:has(.wp-block-a-paul-singh-video-modal)) > .wp-block-group .wp-block-button,
	.wp-block-columns:has(> .wp-block-column .wp-block-a-paul-singh-video-modal) > .wp-block-column:not(:has(.wp-block-a-paul-singh-video-modal)) > .wp-block-group .wp-block-button__link {
		width: auto;
	}

	.wp-block-columns:has(> .wp-block-column .wp-block-a-paul-singh-video-modal) > .wp-block-column:not(:has(.wp-block-a-paul-singh-video-modal)) > .wp-block-group > .wp-block-paragraph {
		margin: 0;
		text-align: right;
	}

	.wp-block-a-paul-singh-video-modal__play {
		width: 2.5rem;
		height: 2.5rem;
	}

	/* Figma "Design - Mobile Video - Open": close inset ~58px / 27px; stage uses content gutters. */
	.aps-video-modal__close {
		top: 3.625rem;
		right: 1.625rem;
	}

	.aps-video-modal__stage {
		width: min(calc(100vw - 3.25rem), 1100px);
	}
}
