/**
 * Tempest Masonry Gallery
 * Authored by Tempest Technologies — Built for Fort Benton.
 *
 * Layout:
 *   Desktop: 3 columns x 2 rows
 *   Tablet / Mobile: 2 columns x 3 rows
 *
 * Uses CSS multi-column layout for a true masonry feel where image heights
 * can vary. `break-inside: avoid` keeps individual tiles intact.
 */

.tmg-gallery {
	column-count: 3;
	column-gap: 16px;
	margin: 0 auto;
	max-width: 100%;
}

/* Classic/default WordPress gallery markup. JavaScript adds the second class
   while preserving Smush, WebP, srcset, sizes, and lazy-loading attributes. */
.gallery.tmg-native-gallery {
	column-count: 3;
	column-gap: 16px;
	display: block !important;
	margin: 0 auto !important;
	max-width: 100%;
}

.gallery.tmg-native-gallery .gallery-item {
	break-inside: avoid;
	-webkit-column-break-inside: avoid;
	display: block !important;
	float: none !important;
	margin: 0 0 16px !important;
	max-width: none !important;
	page-break-inside: avoid;
	width: 100% !important;
}

.gallery.tmg-native-gallery .gallery-icon,
.gallery.tmg-native-gallery .gallery-item a.tmg-item {
	display: block;
	line-height: 0;
}

.gallery.tmg-native-gallery .gallery-item a {
	background: #f5f5f5;
	border-radius: 4px;
	cursor: zoom-in;
	overflow: hidden;
	transition: transform 0.25s ease, box-shadow 0.25s ease;
}

.gallery.tmg-native-gallery .gallery-item a.tmg-item:hover,
.gallery.tmg-native-gallery .gallery-item a.tmg-item:focus-visible {
	box-shadow: 0 6px 16px rgba(0, 0, 0, 0.18);
	outline: none;
	transform: translateY(-2px);
}

.gallery.tmg-native-gallery .gallery-item img {
	border: 0 !important;
	display: block;
	height: auto;
	max-width: 100%;
	transition: transform 0.35s ease;
	width: 100%;
}

.gallery.tmg-native-gallery .gallery-item a.tmg-item:hover img {
	transform: scale(1.03);
}

.gallery.tmg-native-gallery .gallery-caption {
	line-height: 1.4;
	padding: 8px 4px;
}

.tmg-gallery .tmg-item {
	display: block;
	margin: 0 0 16px 0;
	break-inside: avoid;
	-webkit-column-break-inside: avoid;
	page-break-inside: avoid;
	overflow: hidden;
	border-radius: 4px;
	position: relative;
	cursor: zoom-in;
	line-height: 0;
	background: #f5f5f5;
	transition: transform 0.25s ease, box-shadow 0.25s ease;
}

.tmg-gallery .tmg-item:hover,
.tmg-gallery .tmg-item:focus-visible {
	transform: translateY(-2px);
	box-shadow: 0 6px 16px rgba(0, 0, 0, 0.18);
	outline: none;
}

.tmg-gallery .tmg-item img {
	display: block;
	width: 100%;
	height: auto;
	transition: transform 0.35s ease;
}

.tmg-gallery .tmg-item:hover img {
	transform: scale(1.03);
}

/* Tablet and mobile: 2 columns (6 images => 3 rows) */
@media (max-width: 1024px) {
	.tmg-gallery,
	.gallery.tmg-native-gallery {
		column-count: 2;
		column-gap: 12px;
	}
	.tmg-gallery .tmg-item,
	.gallery.tmg-native-gallery .gallery-item {
		margin-bottom: 12px;
	}
}

.tmg-error {
	padding: 12px 16px;
	background: #fff3cd;
	border: 1px solid #ffeeba;
	color: #856404;
	border-radius: 4px;
}

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

.tmg-lightbox {
	position: fixed;
	inset: 0;
	background: rgba(0, 0, 0, 0.9);
	z-index: 99999;
	display: none;
	align-items: center;
	justify-content: center;
	padding: 40px;
	box-sizing: border-box;
}

.tmg-lightbox.is-open {
	display: flex;
}

.tmg-lb-stage {
	position: relative;
	max-width: 100%;
	max-height: 100%;
	display: flex;
	flex-direction: column;
	align-items: center;
	justify-content: center;
}

.tmg-lb-image {
	max-width: 100%;
	max-height: calc(100vh - 140px);
	width: auto;
	height: auto;
	display: block;
	box-shadow: 0 10px 40px rgba(0, 0, 0, 0.5);
	background: #111;
}

.tmg-lb-caption {
	color: #f5f5f5;
	font-size: 14px;
	margin-top: 12px;
	text-align: center;
	max-width: 80ch;
	line-height: 1.4;
}

.tmg-lb-counter {
	color: #bbb;
	font-size: 12px;
	margin-top: 6px;
	letter-spacing: 0.05em;
}

.tmg-lightbox button {
	position: absolute;
	background: rgba(255, 255, 255, 0.1);
	color: #fff;
	border: 0;
	cursor: pointer;
	font-size: 28px;
	line-height: 1;
	width: 48px;
	height: 48px;
	display: flex;
	align-items: center;
	justify-content: center;
	border-radius: 50%;
	transition: background 0.2s ease, transform 0.2s ease;
	z-index: 2;
	user-select: none;
}

.tmg-lightbox button:hover,
.tmg-lightbox button:focus-visible {
	background: rgba(255, 255, 255, 0.25);
	outline: none;
}

.tmg-lb-close {
	top: 16px;
	right: 16px;
	font-size: 32px;
}

.tmg-lb-prev {
	left: 16px;
	top: 50%;
	transform: translateY(-50%);
}

.tmg-lb-next {
	right: 16px;
	top: 50%;
	transform: translateY(-50%);
}

@media (max-width: 640px) {
	.tmg-lightbox {
		padding: 16px;
	}
	.tmg-lb-close {
		top: 8px;
		right: 8px;
	}
	.tmg-lb-prev {
		left: 4px;
	}
	.tmg-lb-next {
		right: 4px;
	}
	.tmg-lb-image {
		max-height: calc(100vh - 120px);
	}
}

/* Prevent background scroll while lightbox is open */
body.tmg-lock-scroll {
	overflow: hidden;
}
