/*
 * Effective column count: capped at 2 on narrow viewports.
 * The 640px breakpoint must match NARROW_VIEWPORT_QUERY in assets/js/masonry-init.js.
 */
.rfgallery,
.rfalbum {
	--rfgallery-columns-effective: var(--rfgallery-columns, 3);
	--rfalbum-columns-effective: var(--rfalbum-columns, 3);
}

@media (max-width: 640px) {
	.rfgallery,
	.rfalbum {
		--rfgallery-columns-effective: min(var(--rfgallery-columns, 3), 2);
		--rfalbum-columns-effective: min(var(--rfalbum-columns, 3), 2);
	}
}

.rfgallery__items {
	list-style: none;
	margin: 0;
	padding: 0;
}

.rfgallery--grid .rfgallery__items {
	display: grid;
	grid-template-columns: repeat(var(--rfgallery-columns-effective, 3), 1fr);
	gap: var(--rfgallery-gap, 8px);
}

/*
 * Every tile has the same shape (--rfgallery-ratio), so portrait and landscape images line up evenly.
 * --rfgallery-fit: contain shows each image whole inside the tile (default), cover crops it to fill the tile.
 */
.rfgallery--grid .rfgallery__trigger {
	height: auto;
	aspect-ratio: var(--rfgallery-ratio, 3 / 2);
	overflow: hidden;
	background: var(--rfgallery-tile-background, transparent);
}

.rfgallery--grid .rfgallery__item img {
	display: block;
	width: 100%;
	height: 100%;
	object-fit: var(--rfgallery-fit, contain);
}

.rfgallery--masonry.is-packed .rfgallery__items {
	position: relative;
}

/*
 * Before the script has packed the tiles (and without JavaScript) they sit in normal flow, so each
 * tile is where it will be and the browser loads only the images near the viewport. Absolutely
 * positioned tiles would all start at the top left and every lazy image would load at once.
 */
.rfgallery--masonry:not(.is-packed) .rfgallery__items {
	display: grid;
	grid-template-columns: repeat(var(--rfgallery-columns-effective, 3), 1fr);
	gap: var(--rfgallery-gap, 8px);
	align-items: start;
}

.rfgallery--masonry.is-packed .rfgallery__item {
	position: absolute;
	width: calc((100% - (var(--rfgallery-columns-effective, 3) - 1) * var(--rfgallery-gap, 8px)) / var(--rfgallery-columns-effective, 3));
}

.rfgallery--masonry .rfgallery__item img {
	display: block;
	width: 100%;
	height: auto;
}

.rfgallery--justified.is-packed .rfgallery__items {
	position: relative;
}

/* Fallback before packing: a wrapped flex row, each tile as wide as its aspect ratio asks. */
.rfgallery--justified:not(.is-packed) .rfgallery__items {
	display: flex;
	flex-wrap: wrap;
	gap: 8px;
}

.rfgallery--justified:not(.is-packed) .rfgallery__item {
	flex: calc(var(--rfgallery-ar, 1.5) * 100) 1 calc(var(--rfgallery-ar, 1.5) * var(--rfgallery-row-height, 220px));
}

.rfgallery--justified:not(.is-packed) .rfgallery__item img {
	height: auto;
	aspect-ratio: var(--rfgallery-ar, 1.5);
}

.rfgallery--justified.is-packed .rfgallery__item {
	position: absolute;
}

.rfgallery--justified .rfgallery__item img {
	display: block;
	width: 100%;
	height: 100%;
	object-fit: cover;
}

.rfgallery--slideshow {
	position: relative;
}

.rfgallery--slideshow .rfgallery__item {
	display: none;
	overflow: hidden;
}

.rfgallery--slideshow:not(.is-js-ready) .rfgallery__item:first-child {
	display: block;
}

.rfgallery--slideshow .rfgallery__item.is-active {
	display: block;
}

/* Fixed stage shape: slides of any orientation are shown whole and the slideshow never changes height. */
.rfgallery--slideshow .rfgallery__trigger {
	height: auto;
	aspect-ratio: var(--rfgallery-ratio, 3 / 2);
	overflow: hidden;
	background: var(--rfgallery-slideshow-background, transparent);
	cursor: default;
}

.rfgallery--slideshow .rfgallery__item img {
	display: block;
	width: 100%;
	height: 100%;
	object-fit: contain;
	transform-origin: center;
}

.rfgallery-slideshow__prev,
.rfgallery-slideshow__next {
	position: absolute;
	top: 50%;
	transform: translateY(-50%);
	background: rgba(0, 0, 0, 0.4);
	border: 0;
	color: #fff;
	font-size: 2rem;
	line-height: 1;
	cursor: pointer;
	padding: 8px 12px;
	z-index: 1;
}

.rfgallery-slideshow__prev {
	left: 0;
}

.rfgallery-slideshow__next {
	right: 0;
}

.rfgallery__caption {
	display: block;
	font-size: 0.85em;
	margin-top: 4px;
}

.rfgallery__trigger {
	display: block;
	width: 100%;
	height: 100%;
	padding: 0;
	border: 0;
	background: none;
	cursor: zoom-in;
	font: inherit;
}

.rfgallery-lightbox {
	position: fixed;
	inset: 0;
	display: flex;
	align-items: center;
	justify-content: center;
	background: rgba(0, 0, 0, 0.9);
	opacity: 0;
	transition: opacity 0.2s ease;
	z-index: 100000;
}

.rfgallery-lightbox[hidden] {
	display: none;
}

.rfgallery-lightbox.is-open {
	opacity: 1;
}

.rfgallery-lightbox__figure {
	max-width: 90vw;
	max-height: 90vh;
	margin: 0;
	text-align: center;
}

.rfgallery-lightbox__image {
	max-width: 90vw;
	max-height: 80vh;
	display: block;
	margin: 0 auto;
	transform-origin: center;
	touch-action: none;
	cursor: grab;
	user-select: none;
	-webkit-user-select: none;
}

.rfgallery-lightbox__image.is-zoomable {
	cursor: zoom-in;
}

.rfgallery-lightbox__image.is-zoomed {
	cursor: grab;
}

.rfgallery-lightbox__image.is-panning {
	cursor: grabbing;
}

.rfgallery-lightbox__caption {
	color: #fff;
	margin-top: 8px;
	font-size: 0.9em;
}

.rfgallery-lightbox__actions {
	display: flex;
	align-items: center;
	justify-content: center;
	gap: 12px;
	margin-top: 8px;
	min-height: 2.25em;
}

.rfgallery-lightbox__zoom,
.rfgallery-lightbox__download,
.rfgallery-lightbox__share {
	background: none;
	border: 1px solid rgba(255, 255, 255, 0.6);
	border-radius: 4px;
	color: #fff;
	cursor: pointer;
	font: inherit;
	font-size: 0.9em;
	padding: 6px 12px;
	text-decoration: none;
}

.rfgallery-lightbox__zoom:hover,
.rfgallery-lightbox__download:hover,
.rfgallery-lightbox__share:hover,
.rfgallery-lightbox__zoom:focus-visible,
.rfgallery-lightbox__download:focus-visible,
.rfgallery-lightbox__share:focus-visible {
	background: rgba(255, 255, 255, 0.15);
}

.rfgallery-lightbox__zoom[hidden],
.rfgallery-lightbox__download[hidden],
.rfgallery-lightbox__share[hidden] {
	display: none;
}

.rfgallery-lightbox__status {
	color: #fff;
	font-size: 0.85em;
}

.rfgallery-lightbox__close,
.rfgallery-lightbox__prev,
.rfgallery-lightbox__next {
	position: absolute;
	background: none;
	border: 0;
	color: #fff;
	font-size: 2rem;
	line-height: 1;
	cursor: pointer;
	padding: 8px;
}

.rfgallery-lightbox__close {
	top: 16px;
	right: 16px;
}

.rfgallery-lightbox__prev {
	left: 16px;
	top: 50%;
	transform: translateY(-50%);
}

.rfgallery-lightbox__next {
	right: 16px;
	top: 50%;
	transform: translateY(-50%);
}

.rfalbum__items {
	display: grid;
	grid-template-columns: repeat(var(--rfalbum-columns-effective, 3), 1fr);
	gap: 16px;
	list-style: none;
	margin: 0;
	padding: 0;
}

.rfalbum__link {
	display: block;
	text-decoration: none;
	color: inherit;
}

.rfalbum__cover {
	width: 100%;
	aspect-ratio: 1 / 1;
	object-fit: cover;
	display: block;
}

.rfalbum__title {
	display: block;
	margin-top: 4px;
}
