.wsmpg-gallery {
	--wsmpg-gap: 10px;
	--wsmpg-cell: 0px;
	--wsmpg-columns: 3;
	box-sizing: border-box;
	width: 100%;
}

.wsmpg-gallery *,
.wsmpg-gallery *::before,
.wsmpg-gallery *::after {
	box-sizing: inherit;
}

/*
 * Diagonal collage on a 6-column square unit grid (small = 2 cols, large = 4).
 * Each cycle of 6 images occupies 4 rows:
 *   [1][ 3 ]
 *   [2][ 3 ]
 *   [ 4 ][5]
 *   [ 4 ][6]
 * Explicit line placement keeps that structure.
 * When the count leaves 2 leftovers (…2 or …5 mod 6), the last two tiles sit
 * side-by-side at 50% width instead of leaving an empty collage slot.
 */
.wsmpg-gallery__grid {
	display: grid;
	gap: var(--wsmpg-gap);
	grid-template-columns: repeat(6, minmax(0, 1fr));
	width: 100%;
}

.wsmpg-gallery.is-sized .wsmpg-gallery__grid {
	/* One row = one small tile height (2 unit cols + gap). */
	grid-auto-rows: calc(var(--wsmpg-cell) * 2 + var(--wsmpg-gap));
	grid-template-columns: repeat(6, var(--wsmpg-cell));
	justify-content: space-between;
}

.wsmpg-gallery__item {
	align-self: stretch;
	aspect-ratio: 1 / 1;
	display: block;
	height: auto;
	justify-self: stretch;
	margin: 0;
	min-height: 0;
	min-width: 0;
	overflow: hidden;
	padding: 0;
	position: relative;
	width: auto;
}

.wsmpg-gallery.is-sized .wsmpg-gallery__item {
	aspect-ratio: auto;
	height: 100%;
}

/* ---- Cycle 1: rows 1–4 ---- */
.wsmpg-gallery__item:nth-child(1) { grid-column: 1 / span 2; grid-row: 1; }
.wsmpg-gallery__item:nth-child(2) { grid-column: 1 / span 2; grid-row: 2; }
.wsmpg-gallery__item:nth-child(3) { grid-column: 3 / span 4; grid-row: 1 / span 2; }
.wsmpg-gallery__item:nth-child(4) { grid-column: 1 / span 4; grid-row: 3 / span 2; }
.wsmpg-gallery__item:nth-child(5) { grid-column: 5 / span 2; grid-row: 3; }
.wsmpg-gallery__item:nth-child(6) { grid-column: 5 / span 2; grid-row: 4; }

/* ---- Cycle 2: rows 5–8 ---- */
.wsmpg-gallery__item:nth-child(7) { grid-column: 1 / span 2; grid-row: 5; }
.wsmpg-gallery__item:nth-child(8) { grid-column: 1 / span 2; grid-row: 6; }
.wsmpg-gallery__item:nth-child(9) { grid-column: 3 / span 4; grid-row: 5 / span 2; }
.wsmpg-gallery__item:nth-child(10) { grid-column: 1 / span 4; grid-row: 7 / span 2; }
.wsmpg-gallery__item:nth-child(11) { grid-column: 5 / span 2; grid-row: 7; }
.wsmpg-gallery__item:nth-child(12) { grid-column: 5 / span 2; grid-row: 8; }

/* ---- Cycle 3: rows 9–12 ---- */
.wsmpg-gallery__item:nth-child(13) { grid-column: 1 / span 2; grid-row: 9; }
.wsmpg-gallery__item:nth-child(14) { grid-column: 1 / span 2; grid-row: 10; }
.wsmpg-gallery__item:nth-child(15) { grid-column: 3 / span 4; grid-row: 9 / span 2; }
.wsmpg-gallery__item:nth-child(16) { grid-column: 1 / span 4; grid-row: 11 / span 2; }
.wsmpg-gallery__item:nth-child(17) { grid-column: 5 / span 2; grid-row: 11; }
.wsmpg-gallery__item:nth-child(18) { grid-column: 5 / span 2; grid-row: 12; }

/* ---- Cycle 4: rows 13–16 ---- */
.wsmpg-gallery__item:nth-child(19) { grid-column: 1 / span 2; grid-row: 13; }
.wsmpg-gallery__item:nth-child(20) { grid-column: 1 / span 2; grid-row: 14; }
.wsmpg-gallery__item:nth-child(21) { grid-column: 3 / span 4; grid-row: 13 / span 2; }
.wsmpg-gallery__item:nth-child(22) { grid-column: 1 / span 4; grid-row: 15 / span 2; }
.wsmpg-gallery__item:nth-child(23) { grid-column: 5 / span 2; grid-row: 15; }
.wsmpg-gallery__item:nth-child(24) { grid-column: 5 / span 2; grid-row: 16; }

/*
 * Remainder 2 (count % 3 === 2): last pair would leave an empty collage slot.
 * Place them side-by-side at 50% width instead.
 * Covers 6n+2 (8, 14, 20) and 6n+5 (5, 11, 17, 23). Count 2 uses --count-2.
 */
.wsmpg-gallery__grid:has(> .wsmpg-gallery__item:nth-child(5):last-child) > .wsmpg-gallery__item:nth-child(4) {
	grid-column: 1 / span 3;
	grid-row: 3;
}

.wsmpg-gallery__grid:has(> .wsmpg-gallery__item:nth-child(5):last-child) > .wsmpg-gallery__item:nth-child(5) {
	grid-column: 4 / span 3;
	grid-row: 3;
}

.wsmpg-gallery__grid:has(> .wsmpg-gallery__item:nth-child(8):last-child) > .wsmpg-gallery__item:nth-child(7) {
	grid-column: 1 / span 3;
	grid-row: 5;
}

.wsmpg-gallery__grid:has(> .wsmpg-gallery__item:nth-child(8):last-child) > .wsmpg-gallery__item:nth-child(8) {
	grid-column: 4 / span 3;
	grid-row: 5;
}

.wsmpg-gallery__grid:has(> .wsmpg-gallery__item:nth-child(11):last-child) > .wsmpg-gallery__item:nth-child(10) {
	grid-column: 1 / span 3;
	grid-row: 7;
}

.wsmpg-gallery__grid:has(> .wsmpg-gallery__item:nth-child(11):last-child) > .wsmpg-gallery__item:nth-child(11) {
	grid-column: 4 / span 3;
	grid-row: 7;
}

.wsmpg-gallery__grid:has(> .wsmpg-gallery__item:nth-child(14):last-child) > .wsmpg-gallery__item:nth-child(13) {
	grid-column: 1 / span 3;
	grid-row: 9;
}

.wsmpg-gallery__grid:has(> .wsmpg-gallery__item:nth-child(14):last-child) > .wsmpg-gallery__item:nth-child(14) {
	grid-column: 4 / span 3;
	grid-row: 9;
}

.wsmpg-gallery__grid:has(> .wsmpg-gallery__item:nth-child(17):last-child) > .wsmpg-gallery__item:nth-child(16) {
	grid-column: 1 / span 3;
	grid-row: 11;
}

.wsmpg-gallery__grid:has(> .wsmpg-gallery__item:nth-child(17):last-child) > .wsmpg-gallery__item:nth-child(17) {
	grid-column: 4 / span 3;
	grid-row: 11;
}

.wsmpg-gallery__grid:has(> .wsmpg-gallery__item:nth-child(20):last-child) > .wsmpg-gallery__item:nth-child(19) {
	grid-column: 1 / span 3;
	grid-row: 13;
}

.wsmpg-gallery__grid:has(> .wsmpg-gallery__item:nth-child(20):last-child) > .wsmpg-gallery__item:nth-child(20) {
	grid-column: 4 / span 3;
	grid-row: 13;
}

.wsmpg-gallery__grid:has(> .wsmpg-gallery__item:nth-child(23):last-child) > .wsmpg-gallery__item:nth-child(22) {
	grid-column: 1 / span 3;
	grid-row: 15;
}

.wsmpg-gallery__grid:has(> .wsmpg-gallery__item:nth-child(23):last-child) > .wsmpg-gallery__item:nth-child(23) {
	grid-column: 4 / span 3;
	grid-row: 15;
}

/* 1 image: one full-width square */
.wsmpg-gallery--count-1 .wsmpg-gallery__grid {
	grid-template-columns: repeat(2, minmax(0, 1fr));
}

.wsmpg-gallery--count-1.is-sized .wsmpg-gallery__grid {
	grid-auto-rows: var(--wsmpg-cell);
	grid-template-columns: repeat(2, var(--wsmpg-cell));
}

.wsmpg-gallery--count-1 .wsmpg-gallery__item:nth-child(1) {
	grid-column: 1 / span 2;
	grid-row: 1 / span 2;
}

/* 2 images: pair of squares */
.wsmpg-gallery--count-2 .wsmpg-gallery__grid {
	grid-template-columns: repeat(2, minmax(0, 1fr));
}

.wsmpg-gallery--count-2.is-sized .wsmpg-gallery__grid {
	grid-auto-rows: var(--wsmpg-cell);
	grid-template-columns: repeat(2, var(--wsmpg-cell));
}

.wsmpg-gallery--count-2 .wsmpg-gallery__item:nth-child(1) {
	grid-column: 1;
	grid-row: 1;
}

.wsmpg-gallery--count-2 .wsmpg-gallery__item:nth-child(2) {
	grid-column: 2;
	grid-row: 1;
}

.wsmpg-gallery__link {
	display: block;
	height: 100%;
	inset: 0;
	line-height: 0;
	overflow: hidden;
	position: absolute;
	width: 100%;
}

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

.wsmpg-gallery__image {
	display: block !important;
	height: 100% !important;
	left: 0;
	max-width: none !important;
	object-fit: cover;
	object-position: center;
	position: absolute;
	top: 0;
	width: 100% !important;
}

.wsmpg-gallery__caption {
	font-size: 0.875rem;
	line-height: 1.4;
	margin-top: 0.5rem;
}

.wsmpg-modal-is-open {
	overflow: hidden;
}

.wsmpg-modal {
	align-items: center;
	background: rgba(0, 0, 0, 0.82);
	display: flex;
	inset: 0;
	justify-content: center;
	opacity: 0;
	padding: 24px;
	pointer-events: none;
	position: fixed;
	transition: opacity 0.28s ease, visibility 0.28s ease;
	visibility: hidden;
	z-index: 999999;
}

.wsmpg-modal.is-open {
	opacity: 1;
	pointer-events: auto;
	visibility: visible;
}

.wsmpg-modal__frame {
	max-height: 90vh;
	max-width: min(1100px, 92vw);
	opacity: 0;
	text-align: center;
	transform: translateY(8px);
	transition: opacity 0.28s ease, transform 0.28s ease;
}

.wsmpg-modal.is-open .wsmpg-modal__frame {
	opacity: 1;
	transform: translateY(0);
}

.wsmpg-modal__image {
	display: block;
	height: auto;
	margin: 0 auto;
	max-height: 84vh;
	max-width: 100%;
	width: auto;
}

.wsmpg-modal__caption {
	color: #fff;
	font-size: 0.875rem;
	line-height: 1.4;
	margin: 12px 0 0;
}

.wsmpg-modal__close,
.wsmpg-modal__nav {
	align-items: center;
	background: rgba(255, 255, 255, 0.95);
	border: 0;
	border-radius: 999px;
	color: #000;
	cursor: pointer;
	display: flex;
	font-size: 28px;
	height: 44px;
	justify-content: center;
	line-height: 1;
	opacity: 0;
	padding: 0;
	position: fixed;
	transition: opacity 0.28s ease;
	width: 44px;
}

.wsmpg-modal__close {
	right: 18px;
	top: 18px;
}

.wsmpg-modal__nav {
	top: 50%;
	transform: translateY(-50%);
}

.wsmpg-modal__nav--prev {
	left: 18px;
}

.wsmpg-modal__nav--next {
	right: 18px;
}

.wsmpg-modal__nav[hidden] {
	display: none;
}

.wsmpg-modal.is-open .wsmpg-modal__close,
.wsmpg-modal.is-open .wsmpg-modal__nav {
	opacity: 1;
}

.wsmpg-modal__close:focus-visible,
.wsmpg-modal__nav:focus-visible {
	outline: 2px solid #fff;
	outline-offset: 3px;
}

@media (prefers-reduced-motion: reduce) {
	.wsmpg-modal,
	.wsmpg-modal__frame,
	.wsmpg-modal__close,
	.wsmpg-modal__nav {
		transition: none;
	}

	.wsmpg-modal__frame {
		transform: none;
	}
}

@media (max-width: 767px) {
	.wsmpg-gallery__grid,
	.wsmpg-gallery--count-1 .wsmpg-gallery__grid,
	.wsmpg-gallery--count-2 .wsmpg-gallery__grid {
		grid-template-columns: repeat(2, minmax(0, 1fr)) !important;
	}

	.wsmpg-gallery.is-sized .wsmpg-gallery__grid,
	.wsmpg-gallery--count-1.is-sized .wsmpg-gallery__grid,
	.wsmpg-gallery--count-2.is-sized .wsmpg-gallery__grid {
		grid-auto-rows: var(--wsmpg-cell) !important;
		grid-template-columns: repeat(2, var(--wsmpg-cell)) !important;
		justify-content: space-between;
	}

	.wsmpg-gallery__item,
	.wsmpg-gallery--count-1 .wsmpg-gallery__item:nth-child(1),
	.wsmpg-gallery--count-2 .wsmpg-gallery__item:nth-child(1),
	.wsmpg-gallery--count-2 .wsmpg-gallery__item:nth-child(2) {
		aspect-ratio: 1 / 1;
		grid-column: auto !important;
		grid-row: auto !important;
	}

	.wsmpg-gallery.is-sized .wsmpg-gallery__item {
		aspect-ratio: auto;
	}

	.wsmpg-gallery--count-1 .wsmpg-gallery__grid,
	.wsmpg-gallery--count-1.is-sized .wsmpg-gallery__grid {
		grid-template-columns: minmax(0, 1fr) !important;
	}

	.wsmpg-gallery--count-1.is-sized .wsmpg-gallery__grid {
		grid-auto-rows: var(--wsmpg-cell) !important;
		grid-template-columns: var(--wsmpg-cell) !important;
	}
}

/*
 * Mobile slideshow: one image at a time, swipeable via scroll snapping, with
 * prev/next arrows and an optional thumbnail strip. Desktop keeps the collage.
 */
.wsmpg-gallery__stage {
	position: relative;
}

.wsmpg-gallery__nav,
.wsmpg-gallery__thumbs {
	display: none;
}

@media (max-width: 767px) {
	.wsmpg-gallery.wsmpg-gallery--mobile-slideshow .wsmpg-gallery__grid {
		-webkit-overflow-scrolling: touch;
		display: flex;
		/* Snap offsets round to device pixels; a gutter keeps any sub-pixel
		   shortfall from revealing the edge of the neighbouring slide. */
		gap: var(--wsmpg-gap);
		justify-content: flex-start;
		overflow-x: auto;
		overflow-y: hidden;
		overscroll-behavior-x: contain;
		scroll-snap-type: x mandatory;
		scrollbar-width: none;
	}

	.wsmpg-gallery.wsmpg-gallery--mobile-slideshow .wsmpg-gallery__grid::-webkit-scrollbar {
		display: none;
	}

	.wsmpg-gallery.wsmpg-gallery--mobile-slideshow .wsmpg-gallery__grid > .wsmpg-gallery__item {
		aspect-ratio: var(--wsmpg-slide-ratio, 1 / 1);
		flex: 0 0 100%;
		height: auto;
		scroll-snap-align: start;
		width: 100%;
	}

	.wsmpg-gallery--mobile-slideshow .wsmpg-gallery__image {
		object-fit: contain;
	}

	.wsmpg-gallery--mobile-slideshow .wsmpg-gallery__nav {
		align-items: center;
		appearance: none;
		background: rgba(255, 255, 255, 0.9);
		border: 0;
		border-radius: 999px;
		box-shadow: 0 1px 4px rgba(0, 0, 0, 0.18);
		color: #000;
		cursor: pointer;
		display: flex;
		height: 40px;
		justify-content: center;
		line-height: 1;
		margin: 0;
		min-height: 0;
		min-width: 0;
		padding: 0;
		position: absolute;
		top: 50%;
		transform: translateY(-50%);
		transition: opacity 0.2s ease;
		width: 40px;
		z-index: 2;
	}

	.wsmpg-gallery--mobile-slideshow .wsmpg-gallery__nav svg {
		display: block;
		pointer-events: none;
	}

	[dir="rtl"] .wsmpg-gallery--mobile-slideshow .wsmpg-gallery__nav svg {
		transform: scaleX(-1);
	}

	.wsmpg-gallery--mobile-slideshow .wsmpg-gallery__nav--prev {
		inset-inline-start: 8px;
	}

	.wsmpg-gallery--mobile-slideshow .wsmpg-gallery__nav--next {
		inset-inline-end: 8px;
	}

	.wsmpg-gallery--mobile-slideshow .wsmpg-gallery__nav:disabled {
		cursor: default;
		opacity: 0.35;
	}

	.wsmpg-gallery--mobile-slideshow .wsmpg-gallery__nav:focus-visible,
	.wsmpg-gallery--mobile-slideshow .wsmpg-gallery__thumb:focus-visible {
		outline: 2px solid currentColor;
		outline-offset: 2px;
	}

	.wsmpg-gallery--mobile-slideshow .wsmpg-gallery__thumbs {
		display: flex;
		flex-wrap: wrap;
		gap: 6px;
		margin-top: 6px;
	}

	.wsmpg-gallery--mobile-slideshow .wsmpg-gallery__thumb {
		appearance: none;
		aspect-ratio: 1 / 1;
		background: transparent;
		border: 0;
		border-radius: 0;
		box-shadow: none;
		cursor: pointer;
		flex: 0 0 calc((100% - 5 * 6px) / 6);
		line-height: 0;
		margin: 0;
		min-height: 0;
		min-width: 0;
		opacity: 0.5;
		overflow: hidden;
		padding: 0;
		transition: opacity 0.2s ease;
	}

	.wsmpg-gallery--mobile-slideshow .wsmpg-gallery__thumb.is-active {
		opacity: 1;
	}

	.wsmpg-gallery--mobile-slideshow .wsmpg-gallery__thumb img {
		display: block;
		height: 100%;
		max-width: none;
		object-fit: cover;
		width: 100%;
	}

	.wsmpg-gallery--mobile-slideshow.wsmpg-gallery--count-1 .wsmpg-gallery__nav,
	.wsmpg-gallery--mobile-slideshow.wsmpg-gallery--count-1 .wsmpg-gallery__thumbs {
		display: none;
	}
}

@media (max-width: 767px) and (prefers-reduced-motion: reduce) {
	.wsmpg-gallery--mobile-slideshow .wsmpg-gallery__nav,
	.wsmpg-gallery--mobile-slideshow .wsmpg-gallery__thumb {
		transition: none;
	}
}
