/* Adaptive media skeletons.
 *
 * The first layer is CSS-only and therefore survives LiteSpeed Delay JS: every
 * selected media frame paints a finite token-driven shimmer behind its image.
 * A loaded image naturally covers that layer. skeleton.js upgrades only images
 * that are genuinely pending to a short decoded-image fade.
 *
 * No dimensions are invented here. The existing image width/height, aspect
 * ratio or component frame remains the source of truth, so the loading state
 * cannot introduce layout shift. TotalPoll stays read-only; its selector below
 * changes only the transient paint behind nominee images, never its geometry.
 */

	:is(
	.single-featured-image > img,
	.single .entry-content > p > img,
	:is(.single, .sa-doc) .entry-content figure.wp-block-image img,
	.sa-hero__frame > .sa-hero__bg-fit,
	.sa-votecard__media > .sa-votecard__img,
	.sa-banner img.sa-banner__im-el,
	.sa-media-image
) {
	background-color: var(--sa-surface-2);
}

/* Prose images have no guaranteed clipping frame that the theme owns. Keep
 * the finite paint fallback for those uncommon cases; every purpose-built
 * media component below uses the compositor path instead. */
.single .entry-content > p > img,
:is(.single, .sa-doc) .entry-content figure.wp-block-image img {
	background-image: linear-gradient(
		105deg,
		transparent 22%,
		color-mix(in srgb, var(--sa-violet-light) 18%, var(--sa-surface-2)) 43%,
		transparent 64%
	);
	background-position: 160% 0;
	background-repeat: no-repeat;
	background-size: 230% 100%;
	animation: sa-skeleton-sweep 1.45s cubic-bezier(.42, 0, .3, 1) 3 both;
}

/* Framed theme media can carry the shimmer on a pseudo-element. A ballot page
 * contains dozens of these images, so moving the 230%-wide gradient with a
 * transform avoids a main-thread repaint on every animation frame. */
:is(
	.single-featured-image,
	.sa-hero__frame,
	.sa-votecard__media,
	.sa-banner--banner,
	.sa-slides__slide,
	.sa-banner__card,
	.sa-media-shell
)::before,
.totalpoll-wrapper .totalpoll-question-choices-item-profile::after {
	content: "";
	position: absolute;
	inset: 0 auto 0 0;
	z-index: 0;
	width: 230%;
	border-radius: inherit;
	pointer-events: none;
	background: linear-gradient(
		105deg,
		transparent 22%,
		color-mix(in srgb, var(--sa-violet-light) 18%, var(--sa-surface-2)) 43%,
		transparent 64%
	);
	transform: translate3d(-90.435%, 0, 0);
	animation: sa-skeleton-sweep-transform 1.45s cubic-bezier(.42, 0, .3, 1) 3 both;
}

/* Establish containing blocks only where the component does not already own
 * one. These declarations do not move the elements; the carousel's stronger
 * active/inactive positioning rules continue to win. */
.single-featured-image,
.sa-slides__slide,
.sa-banner__card {
	position: relative;
}

/* TotalPoll owns ::before for its frame sheen, so the theme deliberately uses
 * ::after above. Its sheen remains at z-index 2; the portrait stays between
 * the shimmer and that sheen, with no geometry change. */
.totalpoll-wrapper .totalpoll-question-choices-item-profile > img {
	z-index: 1;
}

/* Blurred cover-fill layers sit at z-index 0 in these components. Lift only
 * their transient shimmer and sharp image; existing captions/controls remain
 * above both at their established z-index. */
:is(
	.sa-hero__frame,
	.sa-votecard__media,
	.sa-banner--banner,
	.sa-slides__slide
)::before {
	z-index: 1;
}

.sa-hero__frame > .sa-hero__bg-fit,
.sa-votecard__media > .sa-votecard__img,
.sa-banner img.sa-banner__im-el {
	z-index: 2;
}

.sa-hero__frame::after {
	z-index: 3;
}

/* These images are already positioned by their owning component. z-index is
 * enough to keep their pixels above the pseudo-element without changing any
 * crop, offset or containing block. Prose images are safely made positioned. */
.sa-media-shell > .sa-media-image {
	z-index: 1;
}

.single-featured-image > img,
:is(.single, .sa-doc) .entry-content figure.wp-block-image img {
	position: relative;
	z-index: 1;
}

/* The script adds this class only while the requested image is still pending.
 * It is removed on both load and error, so a failed request cannot leave an
 * endless skeleton. Background declarations are important only for this short
 * state: several established components own a higher-specificity background.
 * Movement lives on the pseudo-elements above, never on this host itself. */
.sa-skeleton-host {
	background-color: var(--sa-surface-2) !important;
	background-image: none !important;
	animation: none;
}

/* The unframed prose cases keep matching host paint while JS temporarily hides
 * the pending image. This is normally one image, not a ballot-sized set. */
.single .entry-content > p.sa-skeleton-host,
:is(.single, .sa-doc) .entry-content figure.wp-block-image.sa-skeleton-host {
	background-image: linear-gradient(
		105deg,
		transparent 22%,
		color-mix(in srgb, var(--sa-violet-light) 18%, var(--sa-surface-2)) 43%,
		transparent 64%
	) !important;
	background-position: 160% 0;
	background-repeat: no-repeat !important;
	background-size: 230% 100% !important;
	animation: sa-skeleton-sweep 1.45s cubic-bezier(.42, 0, .3, 1) 3 both;
}

/* Cached, loaded and failed media release their temporary compositor layer
 * immediately instead of retaining it for the rest of the page life. */
:is(
	.single-featured-image,
	.sa-hero__frame,
	.sa-votecard__media,
	.sa-banner--banner,
	.sa-slides__slide,
	.sa-banner__card,
	.sa-media-shell
).sa-skeleton-settled::before,
.totalpoll-wrapper .totalpoll-question-choices-item-profile.sa-skeleton-settled::after {
	content: none;
	animation: none;
}

/* Only script-managed pending images are transparent. With JS delayed or off,
 * images keep their native visibility and the CSS-only background remains the
 * fallback. This is the rule that prevents LiteSpeed from trapping content. */
img.sa-media-pending {
	opacity: 0 !important;
}

img.sa-media-ready {
	opacity: 1;
	animation: none !important;
	transition: opacity .42s cubic-bezier(.2, .78, .2, 1);
}

@keyframes sa-skeleton-sweep {
	0% { background-position: 160% 0; }
	62%, 100% { background-position: -160% 0; }
}

/* background-position 160% -> -160% on a 230%-wide image resolves to a
 * -90.435% -> 90.435% translation of that image itself. Keeping the same 62%
 * stop reproduces the old sweep and pause without main-thread paint work. */
@keyframes sa-skeleton-sweep-transform {
	0% { transform: translate3d(-90.435%, 0, 0); }
	62%, 100% { transform: translate3d(90.435%, 0, 0); }
}

@media (prefers-reduced-motion: reduce) {
	:is(
		.single .entry-content > p > img,
		:is(.single, .sa-doc) .entry-content figure.wp-block-image img,
		.sa-skeleton-host
	) {
		animation: none;
		background-position: 50% 0;
	}

	:is(
		.single-featured-image,
		.sa-hero__frame,
		.sa-votecard__media,
		.sa-banner--banner,
		.sa-slides__slide,
		.sa-banner__card,
		.sa-media-shell
	)::before,
	.totalpoll-wrapper .totalpoll-question-choices-item-profile::after {
		animation: none;
		transform: translate3d(-28.261%, 0, 0);
	}

	img.sa-media-ready {
		transition: none;
	}
}
