/*
 * Karussell — a Gallery block style (inc/karussell.php): one photo at a time,
 * shown whole, its caption underneath.
 *
 * The gallery itself becomes the track, a row of slides that scrolls sideways
 * and snaps to each photo. That works on its own — swipe on a phone, scroll
 * with a trackpad — so without main.js the photos are still all reachable.
 * main.js wraps the track in .karussell and adds the arrows and the counter.
 *
 * Every photo sits in one frame, 3:2, and is fitted into it rather than
 * cropped: Doris's photographs are portrait and landscape mixed, and cropping
 * a portrait to a landscape frame cuts off the people it was taken of. The
 * frame never grows taller than two thirds of the screen, so on a wide
 * monitor the photo and its caption stay in view together.
 *
 * WordPress's own gallery CSS lays photos out as a grid of tiles and puts the
 * caption on the picture, in white over a dark gradient. The selectors below
 * repeat its :not(#individual-image) so they outrank it.
 */
.p-bar-text .wp-block-gallery.is-style-karussell {
	/* The frame's height, shared by the photos and the arrows. */
	--karussell-h: min(calc(100cqw * 2 / 3), 66vh);
	--karussell-grund: color-mix(in srgb, var(--brand-cream) 45%, #fff);

	container-type: inline-size;
	display: flex;
	flex-wrap: nowrap;
	gap: 16px;
	width: 100%;
	margin: 0;
	padding: 0 0 6px;
	overflow-x: auto;
	scroll-snap-type: x mandatory;
	overscroll-behavior-x: contain;
}

.p-bar-text .wp-block-gallery.is-style-karussell.has-nested-images figure.wp-block-image:not(#individual-image) {
	/* A sliver of the next photo shows without the script, which is what says
	   the row goes on. With the arrows there, each photo takes the full width. */
	flex: 0 0 88%;
	width: auto;
	margin: 0;
	display: flex;
	flex-direction: column;
	align-items: stretch;
	justify-content: flex-start;
	scroll-snap-align: start;
}

.p-bar-text .karussell .wp-block-gallery.is-style-karussell {
	gap: 0;
	padding: 0;
	scrollbar-width: none;
}

.p-bar-text .karussell .wp-block-gallery.is-style-karussell::-webkit-scrollbar {
	display: none;
}

.p-bar-text .karussell .wp-block-gallery.is-style-karussell.has-nested-images figure.wp-block-image:not(#individual-image) {
	flex-basis: 100%;
}

/* No dark gradient over the picture: the caption moves under it. */
.p-bar-text .wp-block-gallery.is-style-karussell.has-nested-images figure.wp-block-image:not(#individual-image)::before {
	display: none;
}

.p-bar-text .wp-block-gallery.is-style-karussell.has-nested-images figure.wp-block-image:not(#individual-image) img {
	display: block;
	flex: none;
	width: 100% !important; /* core sets max-width: 100% !important and width: auto */
	max-width: 100% !important;
	height: var(--karussell-h);
	object-fit: contain;
	background: var(--karussell-grund);
	border-radius: 6px;
}

.p-bar-text .wp-block-gallery.is-style-karussell.has-nested-images figure.wp-block-image:not(#individual-image) figcaption {
	position: static;
	flex: none;
	max-height: none;
	margin: 0;
	/* Room on the right for the counter, which shares this line. */
	padding: 10px 72px 0 2px;
	overflow: visible;
	background: none;
	color: #333;
	font-family: 'Open Sans', sans-serif;
	font-size: 16px;
	font-weight: 400;
	line-height: 1.45;
	text-align: left;
	text-shadow: none;
	/* Core clips long captions to the tile; here they wrap. */
	white-space: normal;
}

.p-bar-text .wp-block-gallery.is-style-karussell figcaption a {
	color: #057e65;
	font-weight: 600;
	text-decoration: underline;
	text-underline-offset: 2px;
}

.p-bar-text .wp-block-gallery.is-style-karussell:focus-visible {
	outline: 3px solid #1c1c1c;
	outline-offset: 4px;
}

/* --- Added by main.js ------------------------------------------------- */
.karussell {
	container-type: inline-size;
	position: relative;
	min-width: 0;
	/* Same expression as the track's, resolved against this box, which is the
	   same width: the arrows are centred on the frame, not on frame + caption. */
	--karussell-h: min(calc(100cqw * 2 / 3), 66vh);
}

.karussell-btn {
	position: absolute;
	top: calc(var(--karussell-h) / 2);
	z-index: 1;
	display: grid;
	place-items: center;
	width: var(--tap);
	height: var(--tap);
	margin: 0;
	padding: 0;
	border: 0;
	border-radius: 50%;
	background: rgba(255, 255, 255, 0.94);
	box-shadow: 0 2px 10px rgba(0, 0, 0, 0.22);
	color: #1c1c1c;
	font-size: 16px;
	cursor: pointer;
	transform: translateY(-50%);
	transition: background-color 0.2s ease, color 0.2s ease, opacity 0.2s ease;
}

.karussell-prev {
	left: 10px;
}

.karussell-next {
	right: 10px;
}

.karussell-btn:hover:not(:disabled),
.karussell-btn:focus-visible {
	background: #057e65;
	color: #fff;
}

.karussell-btn:focus-visible {
	outline: 3px solid #1c1c1c;
	outline-offset: 2px;
}

/* At either end the arrow that leads nowhere fades rather than vanishing, so
   the controls do not jump about. */
.karussell-btn:disabled {
	opacity: 0;
	pointer-events: none;
}

.karussell-zaehler {
	position: absolute;
	top: calc(var(--karussell-h) + 10px);
	right: 2px;
	margin: 0;
	font-family: 'Open Sans', sans-serif;
	font-size: 14px;
	font-weight: 600;
	line-height: 1.65;
	color: #555;
	font-variant-numeric: tabular-nums;
}

@media (prefers-reduced-motion: reduce) {
	.karussell-btn {
		transition: none;
	}
}
