/* BSF Gallery — front end */

.bsfg {
	--bsfg-gutter: 10px;
	--bsfg-rh: 150px;
	--bsfg-cols: 4;
	--bsfg-bw: 800px;
	margin: 0 0 1.5em;
	clear: both;
}

.bsfg figure,
.bsfg .bsfg__item,
.bsfg .bsfg__slide {
	margin: 0;
	padding: 0;
}

.bsfg .bsfg__link {
	display: block;
	position: relative;
	overflow: hidden;
	background: rgba(127, 127, 127, 0.12);
	border: 0;
	box-shadow: none;
	text-decoration: none;
	line-height: 0;
}

.bsfg .bsfg__img {
	display: block;
	width: 100%;
	height: 100%;
	max-width: none;
	margin: 0;
	border: 0;
	border-radius: 0;
	box-shadow: none;
	transition: opacity 0.2s ease, transform 0.3s ease;
}

.bsfg .bsfg__link:hover .bsfg__img,
.bsfg .bsfg__link:focus-visible .bsfg__img {
	opacity: 0.85;
}

.bsfg .bsfg__link:focus-visible {
	outline: 2px solid currentColor;
	outline-offset: 2px;
}

.bsfg .bsfg__caption {
	padding: 6px 2px 0;
	font-size: 0.875em;
	line-height: 1.35;
	text-align: center;
}

/* ---------- Justified rows (pure CSS: each item grows in proportion to its aspect ratio) ---------- */

.bsfg--justified .bsfg__grid {
	display: flex;
	flex-wrap: wrap;
	gap: var(--bsfg-gutter);
}

/* Soaks up the leftover space so the last row keeps its natural height instead of stretching. */
.bsfg--justified .bsfg__grid::after {
	content: "";
	flex-grow: 1000000;
	min-width: 0;
}

.bsfg--justified .bsfg__item {
	flex: var(--r) 1 calc(var(--r) * var(--bsfg-rh));
	min-width: 0;
}

.bsfg--justified .bsfg__link {
	aspect-ratio: var(--r);
}

.bsfg--justified .bsfg__img {
	object-fit: cover;
}

/* A gallery with one image (e.g. the server map galleries) just shows the image at full width. */
.bsfg--justified.bsfg--single .bsfg__grid::after {
	display: none;
}

.bsfg--justified.bsfg--single .bsfg__item {
	flex: 0 1 var(--w);
	max-width: 100%;
}

/* ---------- Uniform grid ---------- */

.bsfg--grid .bsfg__grid {
	display: grid;
	grid-template-columns: repeat(var(--bsfg-cols), minmax(0, 1fr));
	gap: var(--bsfg-gutter);
}

.bsfg--grid .bsfg__link {
	aspect-ratio: 4 / 3;
}

.bsfg--grid .bsfg__img {
	object-fit: cover;
}

@media (max-width: 600px) {
	.bsfg--grid .bsfg__grid {
		grid-template-columns: repeat(min(var(--bsfg-cols), 2), minmax(0, 1fr));
	}
}

/* ---------- Image browser (one at a time) ---------- */

.bsfg--browser {
	max-width: var(--bsfg-bw);
	margin-left: auto;
	margin-right: auto;
}

.bsfg--browser .bsfg__slide + .bsfg__slide {
	margin-top: var(--bsfg-gutter);
}

.bsfg--browser.bsfg--ready .bsfg__slide {
	display: none;
	margin-top: 0;
}

.bsfg--browser.bsfg--ready .bsfg__slide.is-active {
	display: block;
}

.bsfg--browser .bsfg__img {
	height: auto;
}

.bsfg--browser .bsfg__caption {
	padding-top: 8px;
	font-size: 1em;
}

.bsfg__nav {
	display: flex;
	align-items: center;
	justify-content: center;
	gap: 4px;
	margin-top: 8px;
	user-select: none;
}

.bsfg__nav[hidden] {
	display: none;
}

.bsfg .bsfg__btn {
	min-width: 36px;
	height: 32px;
	margin: 0;
	padding: 0 8px;
	border: 1px solid rgba(127, 127, 127, 0.45);
	border-radius: 3px;
	background: transparent;
	color: inherit;
	font: inherit;
	font-size: 18px;
	line-height: 1;
	cursor: pointer;
}

.bsfg .bsfg__btn:hover:not(:disabled),
.bsfg .bsfg__btn:focus-visible {
	background: rgba(127, 127, 127, 0.18);
}

.bsfg .bsfg__btn:disabled {
	opacity: 0.35;
	cursor: default;
}

.bsfg__count {
	min-width: 70px;
	text-align: center;
	font-size: 0.9em;
}

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

html.bsfg-lb-open {
	overflow: hidden;
}

.bsfg-lb {
	position: fixed;
	inset: 0;
	z-index: 999999;
	display: flex;
	flex-direction: column;
	background: rgba(8, 8, 10, 0.94);
	color: #eee;
	font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
	font-size: 15px;
	line-height: 1.4;
	opacity: 0;
	transition: opacity 0.2s ease;
	touch-action: pan-y;
}

.bsfg-lb[hidden] {
	display: none;
}

.bsfg-lb.is-visible {
	opacity: 1;
}

.bsfg-lb__bar {
	display: flex;
	align-items: center;
	justify-content: space-between;
	flex: 0 0 auto;
	height: 48px;
	padding: 0 6px 0 16px;
}

.bsfg-lb__counter {
	font-size: 14px;
	opacity: 0.75;
}

.bsfg-lb__stage {
	position: relative;
	flex: 1 1 auto;
	display: flex;
	align-items: center;
	justify-content: center;
	min-height: 0;
	padding: 0 56px;
}

.bsfg-lb__figure {
	display: flex;
	flex-direction: column;
	align-items: center;
	justify-content: center;
	max-width: 100%;
	max-height: 100%;
	margin: 0;
}

.bsfg-lb__img {
	display: block;
	max-width: 100%;
	max-height: calc(100vh - 48px - 40px - var(--bsfg-lb-thumbs, 0px) - 16px);
	width: auto;
	height: auto;
	object-fit: contain;
	box-shadow: 0 6px 30px rgba(0, 0, 0, 0.6);
	transition: opacity 0.15s ease;
	user-select: none;
	-webkit-user-drag: none;
}

.bsfg-lb__img.is-loading {
	opacity: 0.25;
}

.bsfg-lb .bsfg-lb__caption {
	margin: 0;
	background: none;
	color: #eee;
	border: 0;
	min-height: 40px;
	padding: 10px 12px 0;
	text-align: center;
	font-size: 15px;
}

.bsfg-lb button {
	margin: 0;
	border: 0;
	border-radius: 4px;
	background: transparent;
	color: #fff;
	font: inherit;
	line-height: 1;
	cursor: pointer;
	box-shadow: none;
}

.bsfg-lb button:focus-visible {
	outline: 2px solid #fff;
	outline-offset: 2px;
}

.bsfg-lb__close {
	width: 44px;
	height: 44px;
	font-size: 30px !important;
	opacity: 0.8;
}

.bsfg-lb__close:hover {
	opacity: 1;
}

.bsfg-lb__arrow {
	position: absolute;
	top: 50%;
	width: 48px;
	height: 72px;
	margin-top: -36px !important;
	font-size: 44px !important;
	opacity: 0.65;
}

.bsfg-lb__arrow:hover {
	opacity: 1;
	background: rgba(255, 255, 255, 0.08) !important;
}

.bsfg-lb__arrow--prev {
	left: 4px;
}

.bsfg-lb__arrow--next {
	right: 4px;
}

.bsfg-lb__thumbs {
	flex: 0 0 auto;
	display: flex;
	gap: 6px;
	height: 72px;
	padding: 8px 12px;
	overflow-x: auto;
	overflow-y: hidden;
	scrollbar-width: thin;
	justify-content: safe center;
}

.bsfg-lb__thumbs[hidden] {
	display: none;
}

.bsfg-lb__thumb {
	flex: 0 0 auto;
	width: 56px;
	height: 56px;
	padding: 0 !important;
	overflow: hidden;
	opacity: 0.45;
	outline: 2px solid transparent !important;
	outline-offset: -2px;
	transition: opacity 0.15s ease;
}

.bsfg-lb__thumb img {
	display: block;
	width: 100%;
	height: 100%;
	object-fit: cover;
}

.bsfg-lb__thumb:hover {
	opacity: 0.8;
}

.bsfg-lb__thumb.is-active {
	opacity: 1;
	outline-color: #fff !important;
}

@media (max-width: 600px) {
	.bsfg-lb__stage {
		padding: 0 4px;
	}

	.bsfg-lb__arrow {
		display: none;
	}
}

@media (prefers-reduced-motion: reduce) {
	.bsfg-lb,
	.bsfg-lb__img,
	.bsfg .bsfg__img {
		transition: none;
	}
}
