.bg-gallery {
	--bg-accent: #c4121c;
	--bg-surface: #151515;
	--bg-border: rgba(255, 255, 255, 0.13);
	width: 100%;
}

.bg-gallery__grid {
	display: grid;
	grid-template-columns: repeat(var(--bg-cols-desktop, 4), minmax(0, 1fr));
	gap: var(--bg-gap, 14px);
}

.bg-gallery__item {
	min-width: 0;
	margin: 0;
}

.bg-gallery__open {
	position: relative;
	display: block;
	overflow: hidden;
	width: 100%;
	padding: 0;
	border: 1px solid var(--bg-border);
	border-radius: 10px;
	background: var(--bg-surface);
	box-shadow: 0 7px 22px rgba(0, 0, 0, 0.2);
	cursor: zoom-in;
	isolation: isolate;
}

.bg-gallery__open::after {
	position: absolute;
	inset: 0;
	z-index: 1;
	border: 2px solid transparent;
	border-radius: inherit;
	content: '';
	transition: border-color 180ms ease, background 180ms ease;
}

.bg-gallery__image {
	display: block;
	width: 100%;
	height: 100%;
	object-fit: cover;
	transition: transform 260ms ease, filter 260ms ease;
}

.bg-gallery--square .bg-gallery__open { aspect-ratio: 1 / 1; }
.bg-gallery--4-3 .bg-gallery__open { aspect-ratio: 4 / 3; }
.bg-gallery--3-2 .bg-gallery__open { aspect-ratio: 3 / 2; }
.bg-gallery--16-9 .bg-gallery__open { aspect-ratio: 16 / 9; }
.bg-gallery--natural .bg-gallery__image { height: auto; }

.bg-gallery__zoom {
	position: absolute;
	right: 12px;
	bottom: 12px;
	z-index: 2;
	display: grid;
	width: 42px;
	height: 42px;
	border: 1px solid rgba(255, 255, 255, 0.3);
	border-radius: 50%;
	background: rgba(10, 10, 10, 0.74);
	box-shadow: 0 4px 15px rgba(0, 0, 0, 0.28);
	color: #fff;
	place-items: center;
	opacity: 0;
	transform: translateY(7px);
	transition: opacity 180ms ease, transform 180ms ease, background 180ms ease;
}

.bg-gallery__zoom svg {
	width: 22px;
	height: 22px;
	fill: currentColor;
}

.bg-gallery__open:hover::after,
.bg-gallery__open:focus-visible::after {
	border-color: var(--bg-accent);
	background: rgba(0, 0, 0, 0.08);
}

.bg-gallery__open:hover .bg-gallery__image,
.bg-gallery__open:focus-visible .bg-gallery__image {
	transform: scale(1.035);
	filter: contrast(1.035);
}

.bg-gallery__open:hover .bg-gallery__zoom,
.bg-gallery__open:focus-visible .bg-gallery__zoom {
	opacity: 1;
	transform: translateY(0);
}

.bg-gallery__open:hover .bg-gallery__zoom {
	background: var(--bg-accent);
}

.bg-gallery__open:focus-visible {
	outline: 3px solid rgba(196, 18, 28, 0.38);
	outline-offset: 3px;
}

.bg-gallery__caption {
	margin: 8px 2px 0;
	font-size: 0.92rem;
	line-height: 1.45;
}

.bg-gallery-message {
	padding: 14px 16px;
	border-left: 4px solid #c4121c;
	background: #f6f7f7;
}

html.bg-lightbox-open,
body.bg-lightbox-open {
	overflow: hidden;
}

.bg-lightbox[hidden] {
	display: none !important;
}

.bg-lightbox {
	position: fixed;
	inset: 0;
	z-index: 999999;
	display: grid;
	padding: clamp(12px, 3vw, 36px);
	place-items: center;
	opacity: 0;
	transition: opacity 180ms ease;
}

.bg-lightbox.is-open {
	opacity: 1;
}

.bg-lightbox__backdrop {
	position: absolute;
	inset: 0;
	background: rgba(0, 0, 0, 0.94);
	backdrop-filter: blur(7px);
}

.bg-lightbox__dialog {
	position: relative;
	z-index: 1;
	display: grid;
	grid-template-columns: auto minmax(0, 1fr) auto;
	align-items: center;
	width: min(1500px, 100%);
	height: min(920px, 100%);
	color: #fff;
}

.bg-lightbox__figure {
	position: relative;
	display: flex;
	align-items: center;
	justify-content: center;
	min-width: 0;
	height: 100%;
	margin: 0;
	padding: 48px 18px 54px;
}

.bg-lightbox__image {
	display: block;
	max-width: 100%;
	max-height: 100%;
	border-radius: 6px;
	box-shadow: 0 16px 70px rgba(0, 0, 0, 0.55);
	object-fit: contain;
}

.bg-lightbox__caption {
	position: absolute;
	right: 18px;
	bottom: 13px;
	left: 18px;
	color: rgba(255, 255, 255, 0.9);
	font-size: 15px;
	line-height: 1.45;
	text-align: center;
}

.bg-lightbox__close,
.bg-lightbox__nav {
	display: grid;
	padding: 0;
	border: 1px solid rgba(255, 255, 255, 0.24);
	border-radius: 50%;
	background: rgba(20, 20, 20, 0.82);
	color: #fff;
	cursor: pointer;
	place-items: center;
	transition: background 160ms ease, border-color 160ms ease, transform 160ms ease;
}

.bg-lightbox__close:hover,
.bg-lightbox__nav:hover,
.bg-lightbox__close:focus-visible,
.bg-lightbox__nav:focus-visible {
	border-color: #c4121c;
	background: #c4121c;
	outline: none;
	transform: scale(1.04);
}

.bg-lightbox__close svg,
.bg-lightbox__nav svg {
	width: 28px;
	height: 28px;
	fill: currentColor;
}

.bg-lightbox__close {
	position: absolute;
	top: 0;
	right: 0;
	z-index: 3;
	width: 46px;
	height: 46px;
}

.bg-lightbox__nav {
	position: relative;
	z-index: 2;
	width: 52px;
	height: 52px;
}

.bg-lightbox__counter {
	position: absolute;
	top: 14px;
	left: 50%;
	padding: 6px 12px;
	border-radius: 999px;
	background: rgba(20, 20, 20, 0.74);
	color: rgba(255, 255, 255, 0.9);
	font-size: 13px;
	font-variant-numeric: tabular-nums;
	transform: translateX(-50%);
}

.bg-lightbox__loader {
	position: absolute;
	top: 50%;
	left: 50%;
	width: 44px;
	height: 44px;
	margin: -22px 0 0 -22px;
	border: 3px solid rgba(255, 255, 255, 0.24);
	border-top-color: #c4121c;
	border-radius: 50%;
	opacity: 0;
	animation: bg-spin 0.8s linear infinite;
	pointer-events: none;
}

.bg-lightbox.is-loading .bg-lightbox__loader {
	opacity: 1;
}

@keyframes bg-spin {
	to { transform: rotate(360deg); }
}

@media (max-width: 900px) {
	.bg-gallery__grid {
		grid-template-columns: repeat(var(--bg-cols-tablet, 3), minmax(0, 1fr));
	}

	.bg-lightbox__dialog {
		grid-template-columns: 1fr;
	}

	.bg-lightbox__figure {
		padding: 52px 0 74px;
	}

	.bg-lightbox__nav {
		position: absolute;
		bottom: 10px;
	}

	.bg-lightbox__prev { left: calc(50% - 66px); }
	.bg-lightbox__next { right: calc(50% - 66px); }
	.bg-lightbox__counter { top: 10px; }
}

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

	.bg-gallery__open {
		border-radius: 7px;
	}

	.bg-gallery__zoom {
		right: 8px;
		bottom: 8px;
		width: 34px;
		height: 34px;
		opacity: 1;
		transform: none;
	}

	.bg-gallery__zoom svg {
		width: 18px;
		height: 18px;
	}

	.bg-lightbox {
		padding: 8px;
	}

	.bg-lightbox__close {
		top: 4px;
		right: 4px;
		width: 42px;
		height: 42px;
	}

	.bg-lightbox__caption {
		right: 4px;
		left: 4px;
		font-size: 13px;
	}
}

@media (prefers-reduced-motion: reduce) {
	.bg-gallery__image,
	.bg-gallery__zoom,
	.bg-gallery__open::after,
	.bg-lightbox,
	.bg-lightbox__close,
	.bg-lightbox__nav {
		transition: none;
	}

	.bg-lightbox__loader {
		animation-duration: 1.5s;
	}
}
