/* mod_ah_gallery - tile grid + lightbox. Self-contained: no template or framework CSS needed. */

.ahg {
	display: grid;
	grid-template-columns: repeat(3, 1fr);
	gap: 10px;
	align-items: start;
	margin: 0;
	padding: 0;
	list-style: none;
}

.ahg[data-ahg-cols="2"] { grid-template-columns: repeat(2, 1fr); }
.ahg[data-ahg-cols="4"] { grid-template-columns: repeat(4, 1fr); }
.ahg[data-ahg-cols="5"] { grid-template-columns: repeat(5, 1fr); }

/* Square tile via the padding trick - works everywhere, no aspect-ratio needed. */
.ahg .ahg-item {
	position: relative;
	display: block;
	width: 100%;
	height: 0;
	padding-bottom: 100%;
	margin: 0;
	float: none;
	overflow: hidden;
	border: 0;
	border-radius: 10px;
	box-shadow: 0 1px 4px rgba(0, 0, 0, .18);
	background: #eee;
	text-decoration: none;
	transition: transform .2s ease, box-shadow .2s ease;
}

.ahg .ahg-item:hover,
.ahg .ahg-item:focus {
	transform: translateY(-3px);
	box-shadow: 0 6px 18px rgba(0, 0, 0, .25);
}

.ahg .ahg-item img {
	position: absolute;
	top: 0;
	left: 0;
	width: 100%;
	height: 100%;
	margin: 0;
	object-fit: cover;
	display: block;
	border: 0;
}

/* Play badge */
.ahg .ahg-play {
	position: absolute;
	top: 50%;
	left: 50%;
	width: 46px;
	height: 46px;
	margin: -23px 0 0 -23px;
	border-radius: 50%;
	background: rgba(0, 0, 0, .55);
	box-shadow: 0 0 0 2px rgba(255, 255, 255, .85) inset;
	transition: background .2s ease;
}

.ahg .ahg-play:after {
	content: "";
	position: absolute;
	top: 50%;
	left: 50%;
	margin: -9px 0 0 -5px;
	border-style: solid;
	border-width: 9px 0 9px 14px;
	border-color: transparent transparent transparent #fff;
}

.ahg .ahg-item-video:hover .ahg-play { background: #79C36F; }

.ahg .ahg-caption {
	position: absolute;
	right: 0;
	bottom: 0;
	left: 0;
	padding: 16px 8px 6px;
	background: linear-gradient(to top, rgba(0, 0, 0, .72), rgba(0, 0, 0, 0));
	color: #fff;
	font-size: 13px;
	line-height: 1.25;
	text-align: center;
}

/* Mobile: the video plays inside the tile, so the iframe fills it. */
.ahg .ahg-item.is-playing { box-shadow: none; transform: none; }
.ahg .ahg-item.is-playing img,
.ahg .ahg-item.is-playing .ahg-play,
.ahg .ahg-item.is-playing .ahg-caption { display: none; }

.ahg .ahg-item iframe {
	position: absolute;
	top: 0;
	left: 0;
	width: 100%;
	height: 100%;
	border: 0;
}

/* Mobile: a video gets the full row - it is also where it plays inline, so the
   tile becomes the player. 16:9 rather than a square, which would be far too tall. */
@media (max-width: 767px) {
	.ahg .ahg-item-video {
		grid-column: 1 / -1;
		padding-bottom: 56.25%;
	}

	.ahg .ahg-item-video .ahg-play {
		width: 64px;
		height: 64px;
		margin: -32px 0 0 -32px;
	}

	.ahg .ahg-item-video .ahg-play:after {
		margin: -12px 0 0 -7px;
		border-width: 12px 0 12px 19px;
	}
}

@media (max-width: 480px) {
	.ahg { grid-template-columns: repeat(2, 1fr) !important; }
}

/* ---------- Lightbox ---------- */
.ahg-modal {
	position: fixed;
	top: 0;
	right: 0;
	bottom: 0;
	left: 0;
	z-index: 99999;
	display: flex;
	align-items: center;
	justify-content: center;
	padding: 24px;
	background: rgba(0, 0, 0, .88);
	opacity: 0;
	transition: opacity .18s ease;
}

.ahg-modal.is-open { opacity: 1; }

.ahg-modal-body {
	position: relative;
	width: 100%;
	max-width: 1000px;
	max-height: 100%;
	text-align: center;
}

.ahg-modal-body img {
	max-width: 100%;
	max-height: 86vh;
	border-radius: 8px;
	display: inline-block;
}

/* 16:9 frame for the player */
.ahg-modal-video {
	position: relative;
	width: 100%;
	height: 0;
	padding-bottom: 56.25%;
	background: #000;
	border-radius: 8px;
	overflow: hidden;
}

.ahg-modal-video iframe {
	position: absolute;
	top: 0;
	left: 0;
	width: 100%;
	height: 100%;
	border: 0;
}

.ahg-modal-close {
	position: absolute;
	top: -14px;
	right: -14px;
	width: 40px;
	height: 40px;
	padding: 0;
	border: 0;
	border-radius: 50%;
	background: #fff;
	color: #222;
	font-size: 24px;
	line-height: 38px;
	cursor: pointer;
	box-shadow: 0 2px 10px rgba(0, 0, 0, .4);
}

.ahg-modal-close:hover { background: #79C36F; color: #fff; }

/* RTL: the close button belongs on the other corner. */
[dir="rtl"] .ahg-modal-close { right: auto; left: -14px; }

@media (max-width: 560px) {
	.ahg-modal { padding: 16px; }
	.ahg-modal-close { top: -12px; right: -6px; }
	[dir="rtl"] .ahg-modal-close { right: auto; left: -6px; }
}
