/**
 * Component: carousel (a block-editor group with class "cac-carousel"; script: assets/js/carousel.js).
 *
 * Without JS the slides are a horizontally scrollable, snapping row.
 * .wp-block-group (and body, for slides) in the selectors outrank the layout CSS WordPress
 * generates for flex groups, e.g. ".wp-block-group.is-layout-flex .wp-block-embed { flex: 1 1 0% }".
 */

.wp-block-group.cac-carousel {
	display: flex;
	flex-wrap: nowrap;
	gap: 0;
	min-width: 0;
	overflow-x: auto;
	scroll-snap-type: x mandatory;
	overscroll-behavior-x: contain;
}

body .wp-block-group.cac-carousel > *,
body .wp-block-group.cac-carousel .cac-carousel__track > * {
	flex: 0 0 100%;
	min-width: 0;
	margin: 0;
	scroll-snap-align: start;
}

/* Enhanced by JS: track + controls. */
.wp-block-group.cac-carousel.is-enhanced {
	flex-direction: column;
	align-items: stretch;
	/* WordPress's flex layout centres children, which would size the track to its content */
	gap: var(--cac-space-3);
	overflow: visible;
}

.cac-carousel__track {
	display: flex;
	min-width: 0;
	overflow-x: auto;
	scroll-snap-type: x mandatory;
	scroll-behavior: smooth;
	overscroll-behavior-x: contain;
	scrollbar-width: none;
}

.cac-carousel__track::-webkit-scrollbar {
	display: none;
}

@media (prefers-reduced-motion: reduce) {
	.cac-carousel__track {
		scroll-behavior: auto;
	}
}

.cac-carousel__controls {
	display: flex;
	align-items: center;
	justify-content: center;
	gap: var(--cac-space-2);
}

.cac-carousel__arrow {
	display: flex;
	align-items: center;
	justify-content: center;
	width: var(--cac-target-min);
	height: var(--cac-target-min);
	padding: 0;
	font-size: 1.5rem;
	line-height: 1;
	color: var(--cac-color-text-strong);
	background-color: var(--cac-color-bg);
	border: 1px solid var(--cac-color-border-control);
	border-radius: 50%;
	cursor: pointer;
}

.cac-carousel__arrow:hover {
	--bb-primary-button-background-hover: var(--cac-color-bg-active);
	--bb-primary-button-text-hover: var(--cac-color-brand);
	border-color: var(--cac-color-text-strong);
}

.cac-carousel__arrow:active {
	--bb-primary-button-background-hover: var(--cac-color-brand);
	--bb-primary-button-text-hover: var(--cac-color-bg);
}

.cac-carousel__dots {
	display: flex;
	gap: var(--cac-space-1);
}

/* 28px target around a small visual dot. */
.cac-carousel__dot {
	display: flex;
	align-items: center;
	justify-content: center;
	width: 1.75rem;
	height: 1.75rem;
	padding: 0;
	background: none;
	border: 0;
	border-radius: 50%;
	cursor: pointer;
	--bb-primary-button-background-hover: transparent;
}

.cac-carousel__dot::before {
	content: "";
	width: 0.5rem;
	height: 0.5rem;
	background-color: #9e9e9e;
	border-radius: 0.25rem;
	transition: width 0.2s, background-color 0.2s;
}

@media (prefers-reduced-motion: reduce) {
	.cac-carousel__dot::before {
		transition: none;
	}
}

.cac-carousel__dot[aria-current="true"]::before {
	width: 1.5rem;
	background-color: var(--cac-color-brand);
}

.cac-carousel__dot:focus {
	box-shadow: none;
}

.cac-carousel__dot:focus-visible {
	box-shadow: none;
	--bb-primary-button-background-hover: var(--cac-color-bg-active);
}

.cac-carousel__dot:focus-visible::before {
	background-color: var(--cac-color-brand);
}

.cac-carousel__dot:not([aria-current="true"]):hover::before {
	width: 1rem;
	background-color: var(--cac-color-brand);
}

/* Video slides */
.cac-carousel .wp-block-embed figcaption {
	margin: var(--cac-space-2) 0 0;
	font-size: var(--cac-font-size-md);
	font-weight: var(--cac-font-weight-bold);
	line-height: var(--cac-line-height-tight);
	color: var(--cac-color-text-strong);
	text-align: start;
}

/* 16:9 frame for the embed (independent of the theme's responsive-embed CSS). */
.cac-carousel .wp-block-embed__wrapper {
	position: relative;
	aspect-ratio: 16 / 9;
	overflow: hidden;
	background-color: #e9e9e9;
	border-radius: var(--cac-radius-md);
}

.cac-carousel .wp-block-embed__wrapper::before {
	display: none;
}

.cac-carousel .wp-block-embed__wrapper > :is(iframe, img, div) {
	position: absolute;
	inset: 0;
	width: 100%;
	height: 100%;
}