/*
 * Common Shamans Core — media facade.
 *
 * Lives in the plugin because the player is a plugin feature: it must still work, and still
 * reserve its space (no layout shift), under any theme. Colours come from theme.json tokens;
 * the fallbacks are CSS system keywords, never hex.
 */
.cs-media {
	position: relative;
	margin-inline: 0;
	margin-block: 0;
	aspect-ratio: var(--cs-media-ratio, 16 / 9);
	inline-size: 100%;
	max-inline-size: 100%;
	background-color: var(--wp--preset--color--inverse, CanvasText);
	border-radius: var(--wp--custom--radius--card, 8px);
	overflow: hidden;
}

.cs-media__play {
	display: flex;
	flex-direction: column;
	align-items: center;
	justify-content: center;
	gap: 0.75rem;
	inline-size: 100%;
	block-size: 100%;
	padding: 1rem;
	border: 0;
	background: transparent;
	color: var(--wp--preset--color--inverse-ink, Canvas);
	font: inherit;
	cursor: pointer;
}

.cs-media__icon {
	position: relative;
	flex-shrink: 0;
	inline-size: 4rem;
	block-size: 4rem;
	border: 2px solid currentColor;
	border-radius: 50%;
	transition: transform var(--wp--custom--motion--duration, 160ms) var(--wp--custom--motion--easing, ease);
}

/* The play triangle, drawn in currentColor so it follows the token — no image, no hex. */
.cs-media__icon::after {
	content: "";
	position: absolute;
	inset: 0;
	background-color: currentColor;
	clip-path: polygon(40% 30%, 40% 70%, 72% 50%);
}

.cs-media--audio .cs-media__play {
	flex-direction: row;
	justify-content: flex-start;
	padding-inline: 1.5rem;
}

.cs-media--audio .cs-media__icon {
	inline-size: 2.5rem;
	block-size: 2.5rem;
}

/* A Spotify episode's ratio is ~82px tall on a phone: keep the label to one line and the
 * provider link out of its way, rather than letting the two overlap. */
.cs-media--audio {
	min-block-size: 5.5rem;
}

.cs-media--audio .cs-media__label {
	min-inline-size: 0;
	overflow: hidden;
	white-space: nowrap;
	text-overflow: ellipsis;
	padding-inline-end: 7rem;
}

.cs-media--audio .cs-media__caption {
	inset-block-end: auto;
	inset-block-start: 50%;
	transform: translateY(-50%);
}

.cs-media__play:hover .cs-media__icon,
.cs-media__play:focus-visible .cs-media__icon {
	transform: scale(1.08);
}

.cs-media__play:focus-visible {
	outline: 2px solid var(--wp--preset--color--inverse-focus, Canvas);
	outline-offset: -6px;
}

.cs-media__label {
	font-size: var(--wp--preset--font-size--small, 0.875rem);
	font-weight: 600;
}

/* The video's own thumbnail behind the Play button (set when the URL is saved). A scrim keeps the
 * icon, label and "Open on…" link readable on any frame; the icon and label sit above it. */
.cs-media.has-poster .cs-media__play {
	position: relative;
	isolation: isolate;
}

.cs-media__poster {
	position: absolute;
	inset: 0;
	z-index: -1;
	inline-size: 100%;
	block-size: 100%;
	object-fit: cover;
}

.cs-media.has-poster .cs-media__play::before {
	content: "";
	position: absolute;
	inset: 0;
	z-index: -1;
	background-color: color-mix(in srgb, var(--wp--preset--color--inverse, CanvasText) 45%, transparent);
}

.cs-media.has-poster .cs-media__label {
	position: absolute;
	inline-size: 1px;
	block-size: 1px;
	overflow: hidden;
	clip-path: inset(50%);
	white-space: nowrap;
}

.cs-media__frame {
	display: block;
	inline-size: 100%;
	block-size: 100%;
	border: 0;
}

.cs-media__caption {
	position: absolute;
	inset-block-end: 0.5rem;
	inset-inline-end: 0.75rem;
	font-size: var(--wp--preset--font-size--x-small, 0.75rem);
}

/* The link sits over the Play button, so it needs its own 24 px target (WCAG 2.5.8): as small text it
 * was ~16 px tall and failed Lighthouse target-size on every video profile and piece (M6). Its cs- class
 * keeps the theme's in-text link rule (colour: inherit, i.e. ink on this dark pill) off it (Brian, 28 Oct). */
.cs-media__caption a {
	display: inline-flex;
	align-items: center;
	min-block-size: 1.5rem;
	padding-inline: 0.5rem;
	border-radius: 0.25rem;
	background-color: color-mix(in srgb, var(--wp--preset--color--inverse, CanvasText) 85%, transparent);
	color: var(--wp--preset--color--inverse-ink, Canvas);
}

/* The player is dark (inverse), outside any .cs-band-inverse, so the site-wide ink focus ring was
 * ~1.1:1 here and tabbing from Play to this link showed nothing (standards audit, M6). */
.cs-media__caption a:focus-visible {
	outline: 2px solid var(--wp--preset--color--inverse-focus, Canvas);
	outline-offset: 2px;
}

/* A pill, not a text link: theme.json's link hover (0,1,1) would underline it, so this rule sits one class
 * above it. The fill goes solid instead, so the pointer still gets a response (Brian, 20 Oct: no underline
 * on button-like links). */
.cs-media__caption a:is(:hover, :focus-visible) {
	background-color: var(--wp--preset--color--inverse, CanvasText);
	text-decoration: none;
}

.cs-media.is-playing .cs-media__caption {
	display: none;
}

@media (prefers-reduced-motion: reduce) {
	.cs-media__icon {
		transition: none;
	}
}
