/**
 * [post_gallery] — horizontal slider and lightbox.
 *
 * The slider is a native scroll-snap strip rather than a transform-driven
 * carousel: swipe, momentum and RTL all come from the browser, and the strip
 * stays usable if the script never runs.
 *
 * The visible-slide count arrives as an inline --post-gallery-columns-desktop
 * on the wrapper. It is read into --post-gallery-columns rather than used
 * directly so the breakpoints below can override it: an inline custom property
 * would otherwise outrank every rule in this file.
 */

.post-gallery {
	--post-gallery-columns: var( --post-gallery-columns-desktop, 4 );
	--post-gallery-gap: 16px;
	--post-gallery-radius: 4px;
	--post-gallery-ratio: 4 / 3;
	--post-gallery-nav-size: 32px;
	--post-gallery-nav-icon: 13px;

	position: relative;
	margin: 1.5em 0;
}

.post-gallery__viewport {
	overflow-x: auto;
	overflow-y: hidden;
	scroll-snap-type: x mandatory;
	scroll-behavior: smooth;
	/* The dots below double as the scroll position indicator. */
	scrollbar-width: none;
	-ms-overflow-style: none;
	overscroll-behavior-x: contain;
}

.post-gallery__viewport::-webkit-scrollbar {
	display: none;
}

.post-gallery__track {
	display: flex;
	gap: var( --post-gallery-gap );
	margin: 0;
	padding: 0;
	list-style: none;
}

.post-gallery__item {
	flex: 0 0 calc( ( 100% - ( var( --post-gallery-columns ) - 1 ) * var( --post-gallery-gap ) ) / var( --post-gallery-columns ) );
	margin: 0;
	padding: 0;
	list-style: none;
	scroll-snap-align: start;
}

.post-gallery__link {
	display: block;
	overflow: hidden;
	border-radius: var( --post-gallery-radius );
	cursor: zoom-in;
	line-height: 0;
}

.post-gallery__link:focus-visible {
	outline: 2px solid currentColor;
	outline-offset: 2px;
}

.post-gallery__image {
	display: block;
	width: 100%;
	height: 100%;
	aspect-ratio: var( --post-gallery-ratio );
	object-fit: cover;
	transition: transform 0.25s ease;
}

.post-gallery__link:hover .post-gallery__image,
.post-gallery__link:focus-visible .post-gallery__image {
	transform: scale( 1.04 );
}

/* Arrows — injected by the script, so they never appear without JS. */

.post-gallery__nav {
	position: absolute;
	top: calc( 50% - var( --post-gallery-nav-size ) / 2 );
	z-index: 2;
	display: flex;
	align-items: center;
	justify-content: center;
	width: var( --post-gallery-nav-size );
	height: var( --post-gallery-nav-size );
	padding: 0;
	border: 0;
	border-radius: 50%;
	background: rgba( 0, 0, 0, 0.55 );
	color: #fff;
	cursor: pointer;
	transition: background 0.2s ease, opacity 0.2s ease;
}

/* An SVG centres exactly; a text chevron sits off-centre because of the
   glyph's own side-bearing, which no amount of flex alignment corrects. */
.post-gallery__nav svg {
	display: block;
	width: var( --post-gallery-nav-icon );
	height: var( --post-gallery-nav-icon );
}

/* The chevrons point outward, so they mirror along with the button sides. */
[dir="rtl"] .post-gallery__nav svg,
[dir="rtl"] .post-gallery-lightbox__nav svg {
	transform: scaleX( -1 );
}

.post-gallery__nav:hover,
.post-gallery__nav:focus-visible {
	background: rgba( 0, 0, 0, 0.8 );
	outline: none;
}

.post-gallery__nav[disabled] {
	opacity: 0.25;
	cursor: default;
}

/* Logical properties so the arrows swap sides automatically in RTL. */
.post-gallery__nav--prev {
	inset-inline-start: 8px;
}

.post-gallery__nav--next {
	inset-inline-end: 8px;
}

/* Dots */

.post-gallery__dots {
	display: flex;
	justify-content: center;
	gap: 8px;
	margin: 12px 0 0;
	padding: 0;
	list-style: none;
}

.post-gallery__dot {
	width: 9px;
	height: 9px;
	padding: 0;
	border: 0;
	border-radius: 50%;
	background: currentColor;
	opacity: 0.3;
	cursor: pointer;
	transition: opacity 0.2s ease, transform 0.2s ease;
}

.post-gallery__dot:hover,
.post-gallery__dot:focus-visible {
	opacity: 0.6;
	outline: none;
}

.post-gallery__dot[aria-current="true"] {
	opacity: 1;
	transform: scale( 1.25 );
}

.post-gallery__debug {
	margin: 0 0 0.5em;
	padding: 0.4em 0.7em;
	border-left: 3px solid #d63638;
	background: #fcf0f1;
	color: #1d2327;
	font-family: monospace;
	font-size: 13px;
	direction: ltr;
	text-align: left;
}

@media ( max-width: 1024px ) {
	.post-gallery {
		--post-gallery-columns: 3;
	}
}

@media ( max-width: 768px ) {
	.post-gallery {
		--post-gallery-columns: 2;
		--post-gallery-gap: 12px;
	}
}

@media ( max-width: 480px ) {
	.post-gallery {
		--post-gallery-columns: 1;
		--post-gallery-ratio: 3 / 2;
	}
}

/* Lightbox
   ------------------------------------------------------------------------- */

.post-gallery-lightbox[hidden] {
	display: none;
}

.post-gallery-lightbox {
	position: fixed;
	inset: 0;
	z-index: 99999;
	display: flex;
	align-items: center;
	justify-content: center;
	padding: clamp( 12px, 4vw, 48px );
	background: rgba( 0, 0, 0, 0.9 );
}

.post-gallery-lightbox__figure {
	margin: 0;
	max-width: 100%;
	max-height: 100%;
	line-height: 0;
}

.post-gallery-lightbox__image {
	display: block;
	max-width: 100%;
	max-height: 85vh;
	width: auto;
	height: auto;
	object-fit: contain;
}

.post-gallery-lightbox__close,
.post-gallery-lightbox__nav {
	position: absolute;
	display: flex;
	align-items: center;
	justify-content: center;
	width: 44px;
	height: 44px;
	padding: 0;
	border: 0;
	border-radius: 50%;
	background: rgba( 255, 255, 255, 0.12 );
	color: #fff;
	cursor: pointer;
	transition: background 0.2s ease;
}

.post-gallery-lightbox__close svg,
.post-gallery-lightbox__nav svg {
	display: block;
	width: 18px;
	height: 18px;
}

.post-gallery-lightbox__close:hover,
.post-gallery-lightbox__nav:hover,
.post-gallery-lightbox__close:focus-visible,
.post-gallery-lightbox__nav:focus-visible {
	background: rgba( 255, 255, 255, 0.28 );
	outline: none;
}

.post-gallery-lightbox__close {
	top: 16px;
	inset-inline-end: 16px;
}

.post-gallery-lightbox__nav--prev {
	inset-inline-start: 16px;
}

.post-gallery-lightbox__nav--next {
	inset-inline-end: 16px;
}

.post-gallery-lightbox__nav[hidden] {
	display: none;
}

.post-gallery-lightbox__counter {
	position: absolute;
	bottom: 16px;
	inset-inline-start: 0;
	inset-inline-end: 0;
	margin: 0;
	color: rgba( 255, 255, 255, 0.75 );
	font-size: 14px;
	text-align: center;
	direction: ltr;
}

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

	.post-gallery__image,
	.post-gallery__nav,
	.post-gallery__dot,
	.post-gallery-lightbox__close,
	.post-gallery-lightbox__nav {
		transition: none;
	}

	.post-gallery__link:hover .post-gallery__image,
	.post-gallery__link:focus-visible .post-gallery__image {
		transform: none;
	}
}
