/* ub/slider: a scroll-snap track (the slides) and its controls. Loaded only where the block is, in
   the editor and on the site. The track scrolls, never the page: it is exactly as wide as the block.
   Settings: [data-variant="reviews"|"cards"], [data-show-dots], [data-loop]; --ub-gap from the
   block's gap; --ub-count (the real slides) from render.php; .is-looping once view.js has copied the
   slides for the loop.
   Theme hooks (CSS custom properties): --ub-per-view on .ub-slider__track (cards in view: 1.15 /
   2.2 / 3.3 by the block's width), --ub-slider-inset (space before the first slide; align full: the
   wide layout's edge, the slides running to both screen edges), --ub-slider-pad-block (room above
   and below for lifted cards), --ub-slider-control (arrows and dots, default the text colour) and
   --ub-slider-pill (the current pill, default primary; highlight-on-deep on navy). */

.wp-block-ub-slider {
	--ub-gap: var(--wp--preset--spacing--40, 1.5rem);
	container: ub-slider / inline-size;
	box-sizing: border-box;
	min-inline-size: 0;
}

.ub-slider__track {
	position: relative;
	display: flex;
	gap: var(--ub-gap);
	overflow-x: auto;
	overflow-y: hidden;
	overscroll-behavior-x: contain;
	scroll-snap-type: x mandatory;
	padding-block: var(--ub-slider-pad-block, 0.5rem);
	padding-inline: var(--ub-slider-inset, 0px);
	scroll-padding-inline: var(--ub-slider-inset, 0px);
	box-sizing: border-box;
	--ub-per-view: 1.15;
}
/* Full width: the first slide lines up with the wide layout; the others run to the screen's edge */
.wp-block-ub-slider.alignfull {
	--ub-slider-inset: max(var(--wp--style--root--padding-left, 1rem), calc((100% - var(--wp--style--global--wide-size, 80rem)) / 2));
}
/* Endless at full width: from 1400 px the first card lines up with the wide layout and the cards
   before it fill the margin. Narrower, that margin is about one gap wide (both are spacing|40), so
   nothing would show on the left: there the current card sits in the middle, its neighbours peeking
   on both sides. view.js reads the alignment again whenever the width changes. */
@container ub-slider (max-width: 1399.98px) {
	.wp-block-ub-slider.alignfull.is-looping:not([data-variant="reviews"]) .ub-slider__track > * { scroll-snap-align: center; }
}
@container ub-slider (max-width: 559.98px) {
	.wp-block-ub-slider.alignfull.is-looping:not([data-variant="reviews"]) .ub-slider__track { --ub-per-view: 1.25; }
}
.ub-slider__track:focus-visible {
	outline-offset: -3px !important; /* inside the track: at the screen's edge an outer ring is cut off */
}

/* The slides (the inner core/group blocks) */
.ub-slider__track > * {
	flex: 0 0 calc((100% + var(--ub-gap)) / var(--ub-per-view) - var(--ub-gap));
	min-inline-size: 0;
	margin: 0;
	scroll-snap-align: start;
	box-sizing: border-box;
}
@container ub-slider (min-width: 560px) {
	.ub-slider__track { --ub-per-view: 2.2; }
}
@container ub-slider (min-width: 900px) {
	.ub-slider__track { --ub-per-view: 3.3; }
}

/* Reviews: one slide per view, centred */
.wp-block-ub-slider[data-variant="reviews"] .ub-slider__track { --ub-per-view: 1; }
.wp-block-ub-slider[data-variant="reviews"] .ub-slider__track > * {
	scroll-snap-align: center;
	text-align: center;
}

/* Smooth only when motion is allowed: the arrows' scrollTo() and keyboard scrolling follow this */
@media (prefers-reduced-motion: no-preference) {
	html:not([data-ub-motion="off"]) .ub-slider__track { scroll-behavior: smooth; }
}

/* With JavaScript the arrows and swipe move it: no scrollbar. Without, the scrollbar stays */
.ub-js .wp-block-ub-slider:not(.is-static, .is-editing) .ub-slider__track { scrollbar-width: none; }
.ub-js .wp-block-ub-slider:not(.is-static, .is-editing) .ub-slider__track::-webkit-scrollbar { display: none; }

/* The controls, centred under the track: ‹ pills › */
.ub-slider__controls {
	container: ub-slider-controls / inline-size; /* the dots below size themselves from its width */
	display: flex;
	align-items: center;
	justify-content: center;
	gap: 0.75rem;
	margin-block-start: var(--wp--preset--spacing--30, 1rem);
	color: var(--ub-slider-control, currentColor);
}
.wp-block-ub-slider.alignfull .ub-slider__controls { padding-inline: var(--ub-slider-inset); }

.ub-slider__arrow {
	flex: none;
	display: grid;
	place-items: center;
	inline-size: 2.75rem; /* 44 px targets */
	block-size: 2.75rem;
	padding: 0;
	border: 1px solid currentColor;
	border-radius: 50%;
	background: transparent;
	color: inherit;
	cursor: pointer;
}
.ub-slider__arrow:hover:not([aria-disabled="true"]) { background: color-mix(in srgb, currentColor 12%, transparent); }
.ub-slider__arrow[aria-disabled="true"] { opacity: 0.35; cursor: default; }
.ub-slider__arrow svg { display: block; }

/* The pills: one dot per real slide on one line, the current one stretched into a pill. 6 px dots,
   6 px gaps and a 20 px pill where there is room; with many slides on a narrow screen they shrink
   (23 at 360 px: about 4.5 px) rather than wrap. Position only (aria-hidden): the arrows, the
   focusable track and the live text are the accessible controls. */
.ub-slider__pills {
	/* the controls' width less the two arrows and their gaps, shared by the dots, their gaps and the pill */
	--ub-dot: clamp(3px, (100cqi - 2 * 2.75rem - 1.5rem) / (var(--ub-count, 5) * 2 + 1.5), 6px);
	display: flex;
	align-items: center;
	gap: var(--ub-dot);
	min-inline-size: 0;
	overflow: hidden; /* never wider than its place, whatever the count */
}
.ub-slider__pill {
	flex: none;
	inline-size: var(--ub-dot);
	block-size: var(--ub-dot);
	border-radius: 1rem;
	background: currentColor;
	opacity: 0.35;
}
.ub-slider__pill.is-current {
	inline-size: calc(var(--ub-dot) * 10 / 3);
	background: var(--ub-slider-pill, var(--wp--preset--color--primary, currentColor));
	opacity: 1;
}
@media (prefers-reduced-motion: no-preference) {
	html:not([data-ub-motion="off"]) .ub-slider__pill { transition: inline-size 0.25s ease, opacity 0.25s ease; }
}
.wp-block-ub-slider[data-show-dots="false"] .ub-slider__pills { display: none; }

/* Nothing to move (every slide fits), no JavaScript, or the editor: no controls */
.wp-block-ub-slider.is-static .ub-slider__controls,
html:not(.ub-js) .ub-slider__controls { display: none; }

/* Editor: the same row, without snapping while people select and type */
.wp-block-ub-slider.is-editing .ub-slider__track { scroll-snap-type: none; }
.wp-block-ub-slider.is-editing .ub-slider__track > .block-list-appender { flex: 0 0 auto; align-self: center; }
