/*
 * Carousel block styles (inc/carousel.php). The post template's Columns setting is the number of visible cards and its
 * block spacing the gap: the render filter writes them (per viewport too) as custom properties, and the list becomes
 * one scroll-snap row. Buttons are core/icon blocks: their colours, size, padding and glyph are the icon's settings.
 * A post gallery's Carousel layout uses the same track (inc/post-gallery.php). Loaded only on pages where a block uses
 * one of the styles or the layout.
 */
[data-rtthemes-carousel] {
	--rtthemes-carousel-columns: var(--rtthemes-carousel-columns-base);
	--rtthemes-carousel-gap: var(--rtthemes-carousel-gap-base);
}

/*
 * The columns are the visible cards: core's column template (and its per-viewport rules) keeps the column count but
 * fixes each track to a card's width, and the posts after it continue in one row of tracks of the same width.
 */
:is(.wp-block-post-template.is-style-carousel, .wp-block-rtthemes-post-gallery .wp-block-post-template)[data-rtthemes-carousel] {
	--rtthemes-carousel-card: calc((100% - (var(--rtthemes-carousel-columns) - 1) * var(--rtthemes-carousel-gap)) / var(--rtthemes-carousel-columns));
	display: grid;
	grid-template-columns: repeat(var(--rtthemes-carousel-columns), var(--rtthemes-carousel-card)) !important;
	grid-auto-columns: var(--rtthemes-carousel-card);
	grid-auto-flow: column;
	overflow-x: auto;
	overscroll-behavior-x: contain;
	scroll-snap-type: x mandatory;
	scrollbar-width: none;
}

:is(.wp-block-post-template.is-style-carousel, .wp-block-rtthemes-post-gallery .wp-block-post-template)[data-rtthemes-carousel]::-webkit-scrollbar {
	display: none;
}

:is(.wp-block-post-template.is-style-carousel, .wp-block-rtthemes-post-gallery .wp-block-post-template)[data-rtthemes-carousel] > li {
	min-width: 0;
	scroll-snap-align: start;
}

/* Buttons: the icon's box is the button; drawn above the cards when pulled over them */
button.is-style-carousel-previous,
button.is-style-carousel-next {
	position: relative;
	z-index: 1;
	padding: 0;
	border: 0;
	background: none;
	color: inherit;
	font: inherit;
	line-height: 0;
	cursor: pointer;
}

button.is-style-carousel-previous:focus-visible,
button.is-style-carousel-next:focus-visible {
	outline: 2px solid currentColor;
	outline-offset: 2px;
}

/* Buttons of a carousel that shows all its cards (inc/carousel.php lists the viewports where they fit; the inline
   viewport rules repeat this per viewport) keep their place, so the layout around them does not move */
button[data-rtthemes-carousel-fits~="base"] {
	visibility: hidden;
}

/* A bare glyph moves towards its direction on hover */
button:is(.is-style-carousel-previous, .is-style-carousel-next) > svg:not(.has-background) {
	transition: translate 0.2s ease;
}

button.is-style-carousel-next:hover > svg:not(.has-background) {
	translate: 0.25rem 0;
}

button.is-style-carousel-previous:hover > svg:not(.has-background) {
	translate: -0.25rem 0;
}

/* A glyph on a background swaps its colours on hover */
button:is(.is-style-carousel-previous, .is-style-carousel-next) > svg.has-background {
	transition: background-color 0.2s ease, color 0.2s ease;
}

button:is(.is-style-carousel-previous, .is-style-carousel-next):hover > svg.has-background {
	background-color: currentColor !important;
}

button:is(.is-style-carousel-previous, .is-style-carousel-next):hover > svg.has-background > * {
	fill: var(--wp--preset--color--base);
}

@media (prefers-reduced-motion: reduce) {
	button:is(.is-style-carousel-previous, .is-style-carousel-next) > svg {
		transition: none;
	}
}
