/*
 * Schedule Sync — the Events block as a carousel.
 *
 * The events sit on one row; assets/events-carousel.js slides them. This file
 * loads even when the default styles are turned off, because without it the
 * carousel would fall back to a grid.
 *
 * The block sets these on its wrapper (.is-ss-carousel):
 *   --ss-carousel-columns  events visible at once (fewer on narrow screens)
 *   --ss-carousel-gap      space between events (the post template's block spacing)
 *
 * Arrows (.ss-carousel-prev / .ss-carousel-next) sit either side of the row:
 *   --ss-carousel-arrow-size, --ss-carousel-arrow-space (between arrow and row),
 *   --ss-carousel-arrow-bg, --ss-carousel-arrow-bg-hover, --ss-carousel-arrow-color
 * Dots sit underneath: .ss-carousel-dots, .ss-carousel-dot (the current one
 * has aria-current="true").
 */

.is-ss-carousel {
	container-type: inline-size;
}

/* Doubled class: beats core's grid layout rules for the post template. */
.is-ss-carousel .wp-block-post-template.wp-block-post-template {
	--ss-carousel-show: var(--ss-carousel-columns, 3);
	display: flex;
	flex-wrap: nowrap;
	gap: var(--ss-carousel-gap, 1.25em);
	grid-template-columns: none;
	overflow-x: auto;
	overscroll-behavior-x: contain;
	scroll-snap-type: x mandatory;
	scroll-behavior: auto;
	position: relative;
	margin-block: 0;
	padding-block: 2px; /* room for focus outlines */
}

@container (max-width: 900px) {
	.is-ss-carousel .wp-block-post-template.wp-block-post-template {
		--ss-carousel-show: min(var(--ss-carousel-columns, 3), 2);
	}
}

@container (max-width: 600px) {
	.is-ss-carousel .wp-block-post-template.wp-block-post-template {
		--ss-carousel-show: 1;
	}
}

.is-ss-carousel .wp-block-post-template.wp-block-post-template > * {
	flex: 0 0 calc((100% - (var(--ss-carousel-show) - 1) * var(--ss-carousel-gap, 1.25em)) / var(--ss-carousel-show));
	min-width: 0;
	max-width: none;
	margin: 0;
	scroll-snap-align: start;
}

/* Once the script runs it provides the controls, so the scrollbar can go. */
.is-ss-carousel-ready .wp-block-post-template.wp-block-post-template {
	scrollbar-width: none;
	cursor: grab;
}

.is-ss-carousel-ready .wp-block-post-template.wp-block-post-template::-webkit-scrollbar {
	display: none;
}

/* Dragging with the mouse. */
.ss-carousel-viewport.is-dragging .wp-block-post-template.wp-block-post-template {
	cursor: grabbing;
	user-select: none;
}

.ss-carousel-viewport.is-dragging .wp-block-post-template a {
	pointer-events: none;
}

/* Arrows, either side of the row ------------------------------------------ */

/*
 * The arrows get a gutter of their own either side of the row, so they never
 * cover an event. On narrow screens they go: visitors swipe there.
 */
.ss-carousel-viewport {
	--ss-carousel-arrow-size: 2.75rem;
	--ss-carousel-arrow-edge: 0px;
	position: relative;
}

/* Full width: keep the arrows off the screen's edges, in line with the site's own padding. */
.is-ss-carousel.alignfull .ss-carousel-viewport {
	--ss-carousel-arrow-edge: var(--wp--style--root--padding-left, 1rem);
}

@container (min-width: 601px) {
	.ss-carousel-viewport.has-ss-arrows {
		padding-inline: calc(var(--ss-carousel-arrow-edge) + var(--ss-carousel-arrow-size) + var(--ss-carousel-arrow-space, 0.75rem));
	}
}

@container (max-width: 600px) {
	.ss-carousel-viewport .ss-carousel-button.ss-carousel-button {
		display: none;
	}
}

.ss-carousel-viewport .ss-carousel-button {
	appearance: none;
	position: absolute;
	top: 50%;
	z-index: 2;
	display: inline-flex;
	align-items: center;
	justify-content: center;
	box-sizing: border-box;
	width: var(--ss-carousel-arrow-size);
	height: var(--ss-carousel-arrow-size);
	margin: 0;
	padding: 0;
	border: 1px solid var(--ss-border, rgba(127, 127, 127, 0.25));
	border-radius: 999px;
	background: var(--ss-carousel-arrow-bg, transparent);
	color: var(--ss-carousel-arrow-color, inherit);
	font: inherit;
	line-height: 1;
	cursor: pointer;
	transform: translateY(-50%);
	transition: opacity 0.2s, background-color 0.2s;
}

.ss-carousel-viewport .ss-carousel-prev {
	inset-inline-start: var(--ss-carousel-arrow-edge);
}

.ss-carousel-viewport .ss-carousel-next {
	inset-inline-end: var(--ss-carousel-arrow-edge);
}

.ss-carousel-viewport .ss-carousel-button:hover {
	background: var(--ss-carousel-arrow-bg-hover, var(--ss-muted, rgba(127, 127, 127, 0.08)));
}

/* At either end of a carousel that doesn't go round, that arrow goes away. */
.ss-carousel-viewport .ss-carousel-button:disabled {
	opacity: 0;
	visibility: hidden;
}

.ss-carousel-viewport .ss-carousel-button svg {
	width: 1.4rem;
	height: 1.4rem;
	fill: currentColor;
}

/* RTL: the arrows point the way the row moves. */
[dir="rtl"] .ss-carousel-viewport .ss-carousel-button svg {
	transform: scaleX(-1);
}

/* Dots, underneath ---------------------------------------------------------- */

.ss-carousel-controls {
	display: flex;
	justify-content: center;
	margin-top: var(--ss-gap, 1rem);
}

.ss-carousel-controls .ss-carousel-dots {
	display: flex;
	flex-wrap: wrap;
	justify-content: center;
}

/* A 1.5rem target around a small dot. */
.ss-carousel-controls .ss-carousel-dot {
	appearance: none;
	display: inline-flex;
	align-items: center;
	justify-content: center;
	width: 1.5rem;
	height: 1.5rem;
	margin: 0;
	padding: 0;
	border: 0;
	background: transparent;
	color: inherit;
	cursor: pointer;
}

.ss-carousel-controls .ss-carousel-dot::before {
	content: "";
	width: 0.6rem;
	height: 0.6rem;
	border-radius: 50%;
	background: currentColor;
	opacity: 0.25;
}

.ss-carousel-controls .ss-carousel-dot[aria-current="true"]::before {
	opacity: 0.9;
}

/* Doubled so it beats the display rules above. */
.ss-carousel-controls[hidden][hidden],
.ss-carousel-viewport [hidden][hidden] {
	display: none;
}

/*
 * Wide and full width, for themes that don't provide them (block themes and
 * themes with "align-wide" support lay these out themselves). The body class
 * comes from includes/carousel.php; --ss-scrollbar from events-carousel.js.
 */
.ss-theme-no-wide .is-ss-carousel.alignwide {
	--ss-carousel-wide: min(var(--ss-wide-width, 1200px), 100vw - var(--ss-scrollbar, 0px) - 2rem);
	box-sizing: border-box;
	width: var(--ss-carousel-wide);
	max-width: none;
	margin-left: calc(50% - var(--ss-carousel-wide) / 2);
	margin-right: calc(50% - var(--ss-carousel-wide) / 2);
}

.ss-theme-no-wide .is-ss-carousel.alignfull {
	box-sizing: border-box;
	width: calc(100vw - var(--ss-scrollbar, 0px));
	max-width: none;
	margin-left: calc(50% - (50vw - var(--ss-scrollbar, 0px) / 2));
	margin-right: calc(50% - (50vw - var(--ss-scrollbar, 0px) / 2));
}
