.cnmg-gallery {
	width: 100%;
}
.cnmg-gallery .wp-block-gallery {
	display: grid !important;
	grid-template-columns: repeat(var(--cnmg-columns-desktop, 4), minmax(0, 1fr));
	gap: var(--cnmg-gap, 12px) !important;
	margin: 0;
	padding: 0;
	align-items: stretch;
}
.cnmg-gallery .wp-block-gallery > .cnmg-gallery__item {
	display: block;
	min-width: 0;
	margin: 0 !important;
	width: auto !important;
	max-width: none !important;
}
.cnmg-gallery .cnmg-gallery__item[hidden] {
	display: none !important;
}
.cnmg-gallery .cnmg-gallery__item figure,
.cnmg-gallery figure.wp-block-image {
	position: relative;
	width: 100%;
	height: 100%;
	margin: 0;
	overflow: hidden;
	border-radius: 8px;
}
.cnmg-gallery .cnmg-gallery__item img {
	display: block;
	width: 100%;
	height: auto;
	aspect-ratio: 4 / 3;
	object-fit: cover;
	border-radius: 8px;
	cursor: zoom-in;
	transition: transform .25s ease;
}
.cnmg-gallery .cnmg-gallery__item:hover img {
	transform: scale(1.025);
}
.cnmg-gallery .cnmg-gallery__controls {
	display: flex;
	justify-content: center;
	margin-top: 22px;
}
.cnmg-gallery__load-more {
	display: inline-flex;
	align-items: center;
	justify-content: center;
	min-height: 44px;
	padding: 10px 28px;
	border: 0;
	border-radius: 999px;
	background: #222;
	color: #fff;
	font: inherit;
	font-weight: 600;
	line-height: 1.3;
	cursor: pointer;
	transition: background-color .2s ease, transform .2s ease;
}
.cnmg-gallery__load-more:hover {
	background: #444;
	transform: translateY(-1px);
}
.cnmg-gallery__load-more:focus-visible {
	outline: 3px solid currentColor;
	outline-offset: 3px;
}
.cnmg-gallery__load-more[hidden] {
	display: none !important;
}
@media (max-width: 1024px) {
	.cnmg-gallery .wp-block-gallery {
		grid-template-columns: repeat(var(--cnmg-columns-tablet, 3), minmax(0, 1fr));
	}
}
@media (max-width: 767px) {
	.cnmg-gallery .wp-block-gallery {
		grid-template-columns: repeat(var(--cnmg-columns-mobile, 2), minmax(0, 1fr));
	}
	.cnmg-gallery .cnmg-gallery__item img {
		aspect-ratio: 1 / 1;
	}
	.cnmg-gallery .cnmg-gallery__controls {
		margin-top: 16px;
	}
	.cnmg-gallery__load-more {
		width: 100%;
	}
}


/* Add only the Media Library title to WordPress's existing native lightbox.
   All original gallery, button, and hover styles remain unchanged. */
.wp-lightbox-overlay .cnmg-lightbox-title {
	position: absolute;
	left: 50%;
	bottom: 24px;
	z-index: 3000001;
	max-width: calc(100vw - 32px);
	margin: 0;
	padding: 8px 14px;
	transform: translateX(-50%);
	border-radius: 4px;
	background: rgba(0, 0, 0, .65);
	color: #fff;
	font-size: 14px;
	line-height: 1.5;
	text-align: center;
	overflow-wrap: anywhere;
	pointer-events: none;
	box-sizing: border-box;
}
.wp-lightbox-overlay .cnmg-lightbox-title[hidden] {
	display: none !important;
}

/* Keep the original gallery thumbnails untouched. Make only the enlarged
   native-lightbox image use the full available viewport height, while keeping
   the entire source image visible (no cropping or distortion). */
.wp-lightbox-overlay .lightbox-image-container:not(.lightbox-thumbnail-container) {
	width: 100vw !important;
	height: 100vh !important;
	height: 100dvh !important;
	max-width: 100vw !important;
	max-height: 100vh !important;
	max-height: 100dvh !important;
	margin: 0 !important;
	padding: 0 !important;
	display: flex !important;
	align-items: center !important;
	justify-content: center !important;
	box-sizing: border-box !important;
}
.wp-lightbox-overlay .lightbox-image-container:not(.lightbox-thumbnail-container) img {
	width: auto !important;
	height: 100vh !important;
	height: 100dvh !important;
	max-width: 100vw !important;
	max-height: 100vh !important;
	max-height: 100dvh !important;
	aspect-ratio: auto !important;
	object-fit: contain !important;
	object-position: center center !important;
}

/* 1.0.11: hide items past the initial count before frontend.js runs
   (breakpoints match getDevice() in frontend.js). JS adds .cnmg-js-ready
   and takes over with item.hidden. */
@media (max-width: 767px) {
	.cnmg-gallery:not(.cnmg-js-ready) .cnmg-ph-m { display: none !important; }
}
@media (min-width: 768px) and (max-width: 1024px) {
	.cnmg-gallery:not(.cnmg-js-ready) .cnmg-ph-t { display: none !important; }
}
@media (min-width: 1025px) {
	.cnmg-gallery:not(.cnmg-js-ready) .cnmg-ph-d { display: none !important; }
}
