/*
 * R3M Gallery — front end.
 *
 * One square module, four interlocking shapes. Row height is derived from the
 * wrapper's own width with container query units, so the grid stays square
 * without any JavaScript measuring it.
 */

.r3m-gallery-wrap {
	container-type: inline-size;
	width: 100%;
}

.r3m-gallery {
	--r3m-cols: var(--r3m-cols-desktop, 6);
	--r3m-gap: 0px;

	display: grid;
	grid-auto-flow: dense;
	grid-template-columns: repeat(var(--r3m-cols), 1fr);
	grid-auto-rows: 160px; /* replaced below where container units are supported */
	gap: var(--r3m-gap);
	margin: 0;
	padding: 0;
	list-style: none;
}

/*
 * Divi styles every list in the body — `.et-l--body ul { padding: 0 0 23px 1em }`
 * — which outranks a single-class reset and shows up as a gap down the left of
 * the grid and below it. These selectors carry enough weight to win, and they
 * also stop a theme drawing bullets beside the tiles.
 */
.r3m-gallery-wrap ul.r3m-gallery {
	margin: 0;
	padding: 0;
	list-style: none;
}
.r3m-gallery-wrap ul.r3m-gallery > li.r3m-cell {
	margin: 0;
	padding: 0;
	list-style: none;
	list-style-image: none;
	text-indent: 0;
}
.r3m-gallery-wrap ul.r3m-gallery > li.r3m-cell::before,
.r3m-gallery-wrap ul.r3m-gallery > li.r3m-cell::marker {
	content: none;
	display: none;
}

@supports (container-type: inline-size) {
	.r3m-gallery {
		grid-auto-rows: calc(
			(100cqw - (var(--r3m-cols) - 1) * var(--r3m-gap)) / var(--r3m-cols)
		);
	}
}

.r3m-gallery > .r3m-cell {
	position: relative;
	overflow: hidden;
	margin: 0;
	padding: 0;
	list-style: none;
	background: #1d1f24;
}

.r3m-gallery > .r3m-wide { grid-column: span 2; }
.r3m-gallery > .r3m-tall { grid-row: span 2; }
.r3m-gallery > .r3m-hero { grid-column: span 2; grid-row: span 2; }

.r3m-gallery .r3m-gallery-link {
	display: block;
	width: 100%;
	height: 100%;
	cursor: zoom-in;
}

.r3m-gallery .r3m-gallery-img {
	display: block;
	width: 100%;
	height: 100%;
	max-width: none;
	object-fit: cover;
	/* object-position is set per photo from its stored focal point */
}

.r3m-gallery .r3m-gallery-link:focus-visible {
	outline: 3px solid #c6a86b;
	outline-offset: -3px;
}

@media (hover: hover) {
	.r3m-gallery .r3m-gallery-link:hover .r3m-gallery-img {
		opacity: .88;
		transition: opacity .2s ease;
	}
}

/* On narrow screens the two-column shapes would swamp the row, so everything
   below tablet width collapses toward squares. */
@media (max-width: 900px) {
	.r3m-gallery { --r3m-cols: 4; }
}
@media (max-width: 560px) {
	.r3m-gallery { --r3m-cols: 2; }
	.r3m-gallery > .r3m-hero { grid-column: span 2; grid-row: span 2; }
	.r3m-gallery > .r3m-wide { grid-column: span 2; grid-row: span 1; }
}

/* ---- lightbox ---- */
.r3m-lightbox {
	position: fixed;
	inset: 0;
	z-index: 100000;
	display: flex;
	align-items: center;
	justify-content: center;
	padding: 40px 20px;
	background: rgba(8, 8, 10, .95);
}
.r3m-lightbox[hidden] { display: none; }
.r3m-lightbox img {
	max-width: 100%;
	max-height: 100%;
	width: auto;
	height: auto;
	object-fit: contain;
	display: block;
}
.r3m-lightbox button {
	position: fixed;
	appearance: none;
	width: 44px;
	height: 44px;
	line-height: 1;
	font-size: 22px;
	color: #f2efe9;
	background: rgba(21, 22, 26, .85);
	border: 1px solid #32343b;
	border-radius: 3px;
	cursor: pointer;
}
.r3m-lightbox button:focus-visible {
	outline: 2px solid #c6a86b;
	outline-offset: 2px;
}
.r3m-lb-close { top: 16px; right: 16px; }
.r3m-lb-prev { left: 16px; top: 50%; transform: translateY(-50%); }
.r3m-lb-next { right: 16px; top: 50%; transform: translateY(-50%); }
.r3m-lb-count {
	position: fixed;
	left: 0;
	right: 0;
	bottom: 0;
	text-align: center;
	padding: 12px;
	font-size: 13px;
	color: #9a948a;
	font-variant-numeric: tabular-nums;
}

@media (prefers-reduced-motion: reduce) {
	.r3m-gallery .r3m-gallery-img { transition: none !important; }
}
