/**
 * Carousel block front-end styles.
 *
 * Layout is fully driven by row-level CSS custom properties emitted by
 * render.php — no JS measurement participates in sizing. Controls
 * (arrows, dots) stay hidden until view.js adds `.is-initialized`, so a
 * no-JS visitor sees a clean static first view.
 *
 * @package WpmintyAddon
 */

.wpminty-carousel {
	position: relative;
	/* Active variables switched by the media queries below. */
	--wpminty-carousel-spv: var(--wpminty-carousel-spv-desktop, 1);
	--wpminty-carousel-gap: var(--wpminty-carousel-gap-desktop, 0px);
}

.wpminty-carousel__viewport {
	overflow: hidden;
}

.wpminty-carousel__container {
	display: flex;
	align-items: stretch;
	gap: var(--wpminty-carousel-gap, 0px);
}

/* Each top-level inner block is one slide. */
.wpminty-carousel__container > * {
	flex: 0 0 calc(
		(100% - (var(--wpminty-carousel-spv, 1) - 1) * var(--wpminty-carousel-gap, 0px)) /
			var(--wpminty-carousel-spv, 1)
	);
	min-width: 0;
}

/*
 * Theme-level block margins (e.g. theme.json spacing on core/image) do not
 * collapse inside a flex container: vertical margins would double the slide
 * gap and pad each slide. Reset them on the slide's top-level element only;
 * nested blocks inside a slide keep their own typography.
 *
 * The class is repeated to raise specificity above the theme.json compiled
 * selector `:root :where(.wp-block-image)` (where() contributes zero, so
 * that rule sits at 0-1-0). The global-styles stylesheet is printed after
 * block styles, so an equal-specificity rule would lose the cascade — no
 * !important per project convention.
 */
.wpminty-carousel__container.wpminty-carousel__container > * {
	margin-top: 0;
	margin-bottom: 0;
}

/*
 * Embla loop wrap-around gap. CSS `gap` only exists between consecutive DOM
 * siblings, so the seam where the last slide wraps back to the first has
 * none. Embla measures that seam from the last slide's `margin-{endEdge}`
 * (SlideSizes → measureEndGap in embla-carousel.esm), which reads 0 under a
 * container-gap layout and makes the first/last slides touch. Compensate
 * with one gap of trailing margin on the last slide only.
 *
 * Non-loop note: Embla sets readEdgeGap = loop || containScroll, so without
 * loop this margin is ignored by the engine and clipped by the viewport's
 * overflow — spacing stays identical.
 */
.wpminty-carousel__container > *:last-child:not(.block-list-appender) {
	margin-inline-end: var(--wpminty-carousel-gap, 0px);
}

/* Equal-height slides when an aspect ratio is configured. */
.wpminty-carousel--has-ratio .wpminty-carousel__container > * {
	aspect-ratio: var(--wpminty-carousel-ratio, auto);
}

.wpminty-carousel--has-ratio .wpminty-carousel__container > * img {
	width: 100%;
	height: 100%;
	object-fit: cover;
}

/* ----------------------------------------------------------------------
 * Controls: overlay, never in document flow, gated until initialized.
 * ------------------------------------------------------------------- */

.wpminty-carousel__arrow {
	display: none;
	position: absolute;
	z-index: 2;
	width: var(--wpminty-carousel-arrow-size, 44px);
	height: var(--wpminty-carousel-arrow-size, 44px);
	padding: 0;
	align-items: center;
	justify-content: center;
	color: var(--wpminty-carousel-arrow-color, #fff);
	background: var(--wpminty-carousel-arrow-bg, rgba(17, 17, 17, 0.55));
	border: none;
	border-radius: var(--wpminty-carousel-arrow-radius, 50%);
	cursor: pointer;
	transition: background-color 0.2s ease, opacity 0.2s ease;
}

.wpminty-carousel__arrow:hover {
	background: var(--wpminty-carousel-arrow-hover-bg, rgba(17, 17, 17, 0.8));
}

.wpminty-carousel__arrow:focus-visible {
	outline: 2px solid currentColor;
	outline-offset: 2px;
}

.wpminty-carousel__arrow:disabled {
	opacity: 0.35;
	cursor: default;
}

.wpminty-carousel__arrow svg {
	width: 24px;
	height: 24px;
	fill: none;
	stroke: currentColor;
	stroke-width: 2;
	stroke-linecap: round;
	stroke-linejoin: round;
}

/* ------------------------------------------------------------------
 * Split mode: arrows on opposite sides.
 * ---------------------------------------------------------------- */

.wpminty-carousel--arrows-split-inside-left .wpminty-carousel__arrow--prev,
.wpminty-carousel--arrows-split-inside-left .wpminty-carousel__arrow--next {
	left: clamp(8px, 2vw, 20px);
	top: 50%;
	transform: translateY(-50%);
}
.wpminty-carousel--arrows-split-inside-left .wpminty-carousel__arrow--next {
	left: auto;
	right: clamp(8px, 2vw, 20px);
}

.wpminty-carousel--arrows-split-inside-right .wpminty-carousel__arrow--prev,
.wpminty-carousel--arrows-split-inside-right .wpminty-carousel__arrow--next {
	right: clamp(8px, 2vw, 20px);
	top: 50%;
	transform: translateY(-50%);
}
.wpminty-carousel--arrows-split-inside-right .wpminty-carousel__arrow--prev {
	right: auto;
	left: clamp(8px, 2vw, 20px);
}

/* Outside split: root needs overflow:visible so negative offsets are visible. */
.wpminty-carousel--arrows-split-outside-left,
.wpminty-carousel--arrows-split-outside-right {
	overflow: visible;
}

.wpminty-carousel--arrows-split-outside-left .wpminty-carousel__arrow--prev,
.wpminty-carousel--arrows-split-outside-left .wpminty-carousel__arrow--next {
	left: calc((var(--wpminty-carousel-arrow-size, 40px) + 8px) * -1);
	top: 50%;
	transform: translateY(-50%);
}
.wpminty-carousel--arrows-split-outside-left .wpminty-carousel__arrow--next {
	left: auto;
	right: calc((var(--wpminty-carousel-arrow-size, 40px) + 8px) * -1);
}

.wpminty-carousel--arrows-split-outside-right .wpminty-carousel__arrow--prev,
.wpminty-carousel--arrows-split-outside-right .wpminty-carousel__arrow--next {
	right: calc((var(--wpminty-carousel-arrow-size, 40px) + 8px) * -1);
	top: 50%;
	transform: translateY(-50%);
}
.wpminty-carousel--arrows-split-outside-right .wpminty-carousel__arrow--prev {
	right: auto;
	left: calc((var(--wpminty-carousel-arrow-size, 40px) + 8px) * -1);
}

/* ------------------------------------------------------------------
 * Grouped mode: arrows side-by-side in a flex container.
 * ---------------------------------------------------------------- */

.wpminty-carousel__arrows-group {
	display: none;
	position: absolute;
	z-index: 2;
	flex-direction: row;
	gap: 8px;
}

.wpminty-carousel.is-initialized .wpminty-carousel__arrows-group:not([hidden]) {
	display: flex;
}

.wpminty-carousel__arrows-group .wpminty-carousel__arrow {
	position: static;
	transform: none;
}

/* Grouped top positions. */
.wpminty-carousel--arrows-grouped-top-left .wpminty-carousel__arrows-group {
	top: 8px; left: 8px;
}
.wpminty-carousel--arrows-grouped-top-center .wpminty-carousel__arrows-group {
	top: 8px; left: 50%; transform: translateX(-50%);
}
.wpminty-carousel--arrows-grouped-top-right .wpminty-carousel__arrows-group {
	top: 8px; right: 8px;
}

/* Grouped bottom positions. */
.wpminty-carousel--arrows-grouped-bottom-left .wpminty-carousel__arrows-group {
	bottom: 8px; left: 8px;
}
.wpminty-carousel--arrows-grouped-bottom-center .wpminty-carousel__arrows-group {
	bottom: 8px; left: 50%; transform: translateX(-50%);
}
.wpminty-carousel--arrows-grouped-bottom-right .wpminty-carousel__arrows-group {
	bottom: 8px; right: 8px;
}

/* ------------------------------------------------------------------
 * Runtime clipping guard: outside split arrows forced inside.
 * Chained selector raises specificity — no !important needed.
 * ---------------------------------------------------------------- */

[class*="wpminty-carousel--arrows-split-outside"].wpminty-carousel--arrows-force-inside .wpminty-carousel__arrow {
	left: auto;
	right: auto;
	transform: translateY(-50%);
	top: 50%;
}

[class*="wpminty-carousel--arrows-split-outside"].wpminty-carousel--arrows-force-inside .wpminty-carousel__arrow--prev {
	left: clamp(8px, 2vw, 20px);
}

[class*="wpminty-carousel--arrows-split-outside"].wpminty-carousel--arrows-force-inside .wpminty-carousel__arrow--next {
	right: clamp(8px, 2vw, 20px);
}

/* Hover visibility: arrows hidden by default, revealed on container hover/focus. */
.wpminty-carousel--arrows-hover .wpminty-carousel__arrow {
	opacity: 0;
}

.wpminty-carousel--arrows-hover:hover .wpminty-carousel__arrow,
.wpminty-carousel--arrows-hover:focus-within .wpminty-carousel__arrow {
	opacity: 1;
}

/* Touch devices: always show arrows regardless of hover mode. */
@media (hover: none) {
	.wpminty-carousel--arrows-hover .wpminty-carousel__arrow {
		opacity: 1;
	}
}

.wpminty-carousel__dots {
	display: none;
	position: absolute;
	left: 50%;
	bottom: clamp(10px, 2vw, 20px);
	z-index: 2;
	transform: translateX(-50%);
	gap: 8px;
	max-width: calc(100% - 120px);
	flex-wrap: wrap;
	justify-content: center;
}

.wpminty-carousel__dot {
	width: var(--wpminty-carousel-dot-width, 10px);
	height: var(--wpminty-carousel-dot-height, 10px);
	padding: 0;
	border: none;
	border-radius: var(--wpminty-carousel-dot-border-radius, 50%);
	background: var(--wpminty-carousel-dot-color, rgba(255, 255, 255, 0.55));
	cursor: pointer;
	transition: background-color 0.2s ease, transform 0.2s ease;
}

.wpminty-carousel__dot:hover {
	background: var(--wpminty-carousel-dot-hover-color, rgba(255, 255, 255, 0.85));
}

.wpminty-carousel__dot.is-current {
	background: var(--wpminty-carousel-dot-active-color, #fff);
	transform: scale(var(--wpminty-carousel-dot-active-scale, 1.5));
}

.wpminty-carousel__dot:focus-visible {
	outline: 2px solid #fff;
	outline-offset: 2px;
}

/* Reveal controls only once the engine is up; without JS the markup
   degrades to a static first view. */
.wpminty-carousel.is-initialized .wpminty-carousel__arrow {
	display: inline-flex;
}

.wpminty-carousel.is-initialized .wpminty-carousel__dots:not([hidden]) {
	display: flex;
}

/* ----------------------------------------------------------------------
 * Responsive switching. Breakpoint values must mirror theme.json
 * settings.viewport (mobile: 600px, tablet: 960px).
 * ------------------------------------------------------------------- */

/* Must mirror theme.json settings.viewport (tablet: 960px). */
@media (max-width: 960px) {
	.wpminty-carousel {
		--wpminty-carousel-spv: var(--wpminty-carousel-spv-tablet, var(--wpminty-carousel-spv-desktop, 1));
		--wpminty-carousel-gap: var(--wpminty-carousel-gap-tablet, var(--wpminty-carousel-gap-desktop, 0px));
	}
}

/* Must mirror theme.json settings.viewport (mobile: 600px). */
@media (max-width: 600px) {
	.wpminty-carousel {
		--wpminty-carousel-spv: var(--wpminty-carousel-spv-mobile, var(--wpminty-carousel-spv-tablet, var(--wpminty-carousel-spv-desktop, 1)));
		--wpminty-carousel-gap: var(--wpminty-carousel-gap-mobile, var(--wpminty-carousel-gap-tablet, var(--wpminty-carousel-gap-desktop, 0px)));
	}
}

/* ----------------------------------------------------------------------
 * Fade transition: slides cross-fade instead of translating.
 * Requires embla-carousel-fade plugin loaded in view.js.
 * ------------------------------------------------------------------- */

.wpminty-carousel--fade .wpminty-carousel__container > * {
	opacity: 0;
	transition: opacity 0.4s ease;
}

.wpminty-carousel--fade .wpminty-carousel__container > .is-selected {
	opacity: 1;
}

/* ----------------------------------------------------------------------
 * Reduced motion: drop decorative transitions; the engine itself skips
 * autoplay in view.js when the preference is set.
 * ------------------------------------------------------------------- */

@media (prefers-reduced-motion: reduce) {
	.wpminty-carousel__arrow,
	.wpminty-carousel__dot {
		transition: none;
	}

	.wpminty-carousel__dot.is-current {
		transform: none;
	}
}

/* ----------------------------------------------------------------------
 * Editor: arrow placement selector.
 * ------------------------------------------------------------------- */

.wpminty-carousel-editor__placement-row {
	display: flex;
	flex-wrap: wrap;
	gap: 6px;
	margin-bottom: 16px;
}

.wpminty-carousel-editor__placement-grid {
	display: grid;
	grid-template-columns: repeat(3, 1fr);
	gap: 6px;
	margin-bottom: 16px;
}

.wpminty-carousel-editor__placement-btn {
	padding: 6px 10px;
	border: 1px solid #949494;
	border-radius: 4px;
	background: #fff;
	color: #1e1e1e;
	font-size: 12px;
	cursor: pointer;
	transition: background-color 0.15s ease, border-color 0.15s ease;
	text-align: center;
}

.wpminty-carousel-editor__placement-btn:hover {
	background: #f0f0f0;
	border-color: #1e1e1e;
}

.wpminty-carousel-editor__placement-btn.is-active {
	background: var(--wp-admin-theme-color, #007cba);
	border-color: var(--wp-admin-theme-color, #007cba);
	color: #fff;
}

.wpminty-carousel-editor__placement-btn--grid {
	font-size: 16px;
	line-height: 1;
	padding: 8px;
}
