/**
 * PP Malaga - Reels front end behaviour.
 *
 * The loop carousel renders Elementor's stock hosted-video widget, which ships
 * an image overlay and a play button meant for click-to-play. Playback here is
 * driven by hover (desktop) and visibility (touch), so the overlay becomes
 * decorative: pointer-events none stops Elementor's own click handler from ever
 * firing and removing it, and it simply fades instead. The 0.5s transition it
 * animates with already comes from the loop item template.
 */

.pp-reels-carousel .e-hosted-video {
	position: relative;
}

.pp-reels-carousel .elementor-custom-embed-image-overlay {
	pointer-events: none;
}

.pp-reels-carousel .e-loop-item.is-playing .elementor-custom-embed-image-overlay {
	opacity: 0;
}

/* Playback is automatic, so the play button is only noise. */
.pp-reels-carousel .elementor-custom-embed-play {
	display: none;
}

/* The caption sits over the video and steps aside while it plays. */
.pp-reels-carousel .pp-reel-caption {
	transition: opacity .3s ease, visibility .3s ease;
	pointer-events: none;
}

.pp-reels-carousel .e-loop-item.is-playing .pp-reel-caption {
	opacity: 0;
	visibility: hidden;
}

/*
 * On touch devices playback starts on its own, so hiding the caption would mean
 * nobody ever reads it. Remove this block to hide it there too.
 */
@media (hover: none) {
	.pp-reels-carousel .e-loop-item.is-playing .pp-reel-caption {
		opacity: 1;
		visibility: visible;
	}
}

/* Sound toggle, built by the script. */
.pp-reels-carousel .pp-reel-sound {
	position: absolute;
	top: 12px;
	right: 12px;
	z-index: 2;
	display: flex;
	align-items: center;
	justify-content: center;
	width: 40px;
	height: 40px;
	padding: 0;
	color: #fff;
	background-color: rgba(0, 0, 0, .55);
	border: 0;
	border-radius: 50%;
	opacity: 0;
	cursor: pointer;
	pointer-events: none;
	transition: opacity .2s ease, background-color .2s ease;
}

.pp-reels-carousel .e-loop-item:hover .pp-reel-sound,
.pp-reels-carousel .e-loop-item:focus-within .pp-reel-sound,
.pp-reels-carousel .e-loop-item.is-playing .pp-reel-sound {
	opacity: 1;
	pointer-events: auto;
}

.pp-reels-carousel .pp-reel-sound:hover {
	background-color: rgba(0, 0, 0, .78);
}

.pp-reels-carousel .pp-reel-sound:focus-visible {
	opacity: 1;
	outline: 2px solid #fff;
	outline-offset: 2px;
	pointer-events: auto;
}

.pp-reels-carousel .pp-reel-sound svg {
	display: block;
	width: 20px;
	height: 20px;
}

.pp-reels-carousel .pp-reel-sound .pp-reel-icon-on {
	display: none;
}

.pp-reels-carousel .pp-reel-sound.is-on .pp-reel-icon-on {
	display: block;
}

.pp-reels-carousel .pp-reel-sound.is-on .pp-reel-icon-off {
	display: none;
}

@media (prefers-reduced-motion: reduce) {
	.pp-reels-carousel .pp-reel-caption,
	.pp-reels-carousel .pp-reel-sound {
		transition: none;
	}
}

/**
 * Column grid for a carousel holding fewer reels than columns.
 *
 * Elementor Pro collapses the grid on purpose when there are few items: its
 * carousel handler clamps the columns with Math.min( slidesCount, slidesPerView )
 * and returns early on `1 >= getSlidesCount()`, so a lone reel never gets a
 * Swiper at all and stretches across the whole track. The design here asks for
 * the opposite - one reel occupies one column, not the row.
 *
 * Overriding Swiper's geometry is only safe while nothing scrolls, which is
 * exactly while the reels still fit in the columns: Swiper then applies no
 * transform and the arrows move nothing, so pinning the widths cannot
 * desynchronise it. Past that point the :not(:has()) guard stops matching and
 * Swiper is left completely alone.
 *
 * The guards look for the ( columns + 1 )th slide - 5 for four columns, 3 for
 * two, 2 for one - and count it with `of .swiper-slide` on purpose: Elementor
 * prints the loop template's <style> as the wrapper's first child, so a plain
 * :nth-child() counts that node too and releases every guard one slide early.
 * A carousel configured with a different number of columns needs these blocks
 * adjusted to match. Mobile only silences the arrows: at one column a lone reel
 * already fills the track, so there is no width left to correct there.
 *
 * Browsers without :has() support simply keep Elementor's own behaviour.
 */

.pp-reels-carousel {
	/* Mirrors the widget's Space Between; override per widget if it differs. */
	--pp-reels-gap: 24px;
}

@media (min-width: 1025px) {
	/*
	 * The widget is a flex item sized by its own content, so a track holding a
	 * single reel shrinks to that reel's intrinsic video width - and a quarter
	 * of a shrunken row is not a column. Claim the row before splitting it.
	 */
	.pp-reels-carousel:not(:has(.swiper-wrapper > :nth-child(5 of .swiper-slide))) {
		width: 100%;
	}

	.pp-reels-carousel .swiper-wrapper:not(:has(> :nth-child(5 of .swiper-slide))) {
		gap: var(--pp-reels-gap);
	}

	.pp-reels-carousel .swiper-wrapper:not(:has(> :nth-child(5 of .swiper-slide))) > .swiper-slide {
		/* flex-basis beats the width Swiper writes inline, so no !important here. */
		flex: 0 0 calc((100% - 3 * var(--pp-reels-gap)) / 4);
		/* Its spacing is inline though, and the gap above already replaces it. */
		margin-right: 0 !important;
	}

	/*
	 * Arrows that cannot scroll anything are noise, and while the reels fit in
	 * the columns there is nothing to scroll.
	 */
	.pp-reels-carousel:not(:has(.swiper-wrapper > :nth-child(5 of .swiper-slide))) > .elementor-swiper-button {
		display: none;
	}
}

@media (min-width: 768px) and (max-width: 1024px) {
	.pp-reels-carousel:not(:has(.swiper-wrapper > :nth-child(3 of .swiper-slide))) {
		width: 100%;
	}

	.pp-reels-carousel .swiper-wrapper:not(:has(> :nth-child(3 of .swiper-slide))) {
		gap: var(--pp-reels-gap);
	}

	.pp-reels-carousel .swiper-wrapper:not(:has(> :nth-child(3 of .swiper-slide))) > .swiper-slide {
		flex: 0 0 calc((100% - var(--pp-reels-gap)) / 2);
		margin-right: 0 !important;
	}

	/*
	 * Arrows that cannot scroll anything are noise, and while the reels fit in
	 * the columns there is nothing to scroll.
	 */
	.pp-reels-carousel:not(:has(.swiper-wrapper > :nth-child(3 of .swiper-slide))) > .elementor-swiper-button {
		display: none;
	}
}

@media (max-width: 767px) {
	/* One column here, so a second reel is already enough to scroll. */
	.pp-reels-carousel:not(:has(.swiper-wrapper > :nth-child(2 of .swiper-slide))) > .elementor-swiper-button {
		display: none;
	}
}
