/* Brentwood Image Gallery — fixed brick grid + shared lightbox.
 * Mirrors the gallery on brentwood.ca/arts/dance. Self-contained. */

.bw-gallery,
.bw-gallery * {
	box-sizing: border-box;
}

/* ── brick grid ─────────────────────────────────────────────────────────────
 * A CSS grid with fixed-height rows; each item is placed explicitly (inline
 * grid-column / grid-row) into the brick pattern — even columns hold two stacked
 * images, odd columns hold one tall (2-row) image. Images cover their cell. */
.bw-gallery {
	display: grid;
	grid-template-columns: repeat(var(--bw-gallery-cols, 5), 1fr);
	grid-auto-rows: var(--bw-gallery-rowh, 190px);
	gap: var(--bw-gallery-gap, 8px);
	border-bottom-left-radius: var(--bw-gallery-radius, 0);
	border-bottom-right-radius: var(--bw-gallery-radius, 0);
}

/* When a radius is set, clip the grid so the bottom-left / bottom-right images
 * pick up the rounded corner (mirrors the live gallery's rounded-b-lg). */
.bw-gallery--rounded {
	overflow: hidden;
}

.bw-gallery__item {
	position: relative;
	display: block;
	overflow: hidden;
	border-radius: 2px;
	line-height: 0;
	cursor: zoom-in;
	text-decoration: none;
}

.bw-gallery__img {
	display: block;
	width: 100%;
	height: 100%;
	object-fit: cover;
}

/* ── single variant: each image framed on black, kept whole (contain) ──────────
 * Portrait images keep their shape, letterboxed by the black cell; landscape
 * images fit inside too. Clicking a frame opens the shared lightbox. */
/* Aspect-ratio drives each frame's height (not the fixed row height): a chosen
 * ratio via --bw-ig-ratio, or per-image via an inline aspect-ratio (Auto). */
.bw-gallery--single {
	grid-auto-rows: auto;
}

.bw-gallery--single .bw-gallery__item {
	background: #000;
	aspect-ratio: var(--bw-ig-ratio, 4 / 3);
}

.bw-gallery--single .bw-gallery__img {
	/* contain = whole image, letterboxed on the black frame (default);
	   cover = "Full bleed" — zoom + crop to fill the frame (no black bars). */
	object-fit: var(--bw-ig-fit, contain);
}

/* ── caption overlay (used by the mosaic variant) ──────────────────────────── */
/* Mirrors the live site's caption:
 * <div class="bg-black bg-opacity-50 rounded-tr absolute bottom-0 z-3 text-white
 *  px-2 py-1 text-shadow">…</div> */
.bw-gallery__caption {
	position: absolute;            /* absolute bottom-0 (left edge of the cell) */
	left: 0;
	bottom: 0;
	z-index: 3;                    /* z-3 */
	max-width: 90%;
	padding: 0.25rem 0.5rem;       /* py-1 px-2 */
	background: rgba(0, 0, 0, 0.5); /* bg-black bg-opacity-50 */
	color: #fff;                   /* text-white */
	/* No font-size — the live caption has no size class, so it inherits the
	 * surrounding text size (matches live's behaviour). */
	line-height: 1.4;
	border-top-right-radius: 0.25rem; /* rounded-tr */
	text-shadow: 0 1px 2px rgba(0, 0, 0, 0.6); /* text-shadow */
	pointer-events: none;
}

/* ── magnifier hint (optional, bottom-right of each image) ───────────────────
 * Mirrors the card-gallery lightbox icon and the live brentwood.ca "enlarge"
 * icon: a plain white icon at ~60% opacity, full opacity on hover / focus. The
 * caption sits bottom-left, so the two never collide. */
.bw-gallery__zoom {
	position: absolute;
	bottom: 0;
	right: 0;
	z-index: 3;
	display: flex;
	margin: 0 0.5rem 0.5rem 0;
	color: #fff;
	opacity: 0.6;
	transition: opacity 0.2s ease;
	pointer-events: none; /* the whole <a> handles the click */
}
.bw-gallery__item:hover .bw-gallery__zoom,
.bw-gallery__item:focus-visible .bw-gallery__zoom {
	opacity: 1;
}
.bw-gallery__zoom svg {
	width: 1.125rem;
	height: 1.125rem;
	display: block;
	fill: currentColor;
	filter: drop-shadow(0 1px 2px rgba(0, 0, 0, 0.5));
}

/* Phones: drop the brick spans and show a simple, uniform two-column grid.
 * !important neutralises the per-item inline grid placement. */
@media (max-width: 600px) {
	.bw-gallery {
		grid-template-columns: repeat(2, 1fr);
		grid-auto-rows: 44vw;
	}
	.bw-gallery__item {
		grid-column: auto !important;
		grid-row: auto !important;
	}
	/* Single frames keep their aspect-ratio (height follows the ratio, not 44vw). */
	.bw-gallery--single {
		grid-auto-rows: auto;
	}
}

/* No hover effect on images. Keyboard focus still gets a visible outline for
 * accessibility (this is not a mouse-hover effect). */
.bw-gallery__item:focus-visible {
	outline: 2px solid var(--global-palette3, #cc0000);
	outline-offset: 2px;
}

/* ── lightbox (shared singleton appended to <body> by view.js) ─────────────── */
.bw-lightbox {
	position: fixed;
	inset: 0;
	z-index: 100000;
	display: flex;
	align-items: center;
	justify-content: center;
	font-family: "Open Sans", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}
.bw-lightbox[hidden] {
	display: none;
}
.bw-lightbox__overlay {
	position: absolute;
	inset: 0;
	background: rgba(0, 0, 0, 0.9);
	opacity: 0;
	transition: opacity 0.25s ease;
}
.bw-lightbox.is-open .bw-lightbox__overlay {
	opacity: 1;
}
.bw-lightbox__figure {
	position: relative;
	z-index: 1;
	margin: 0;
	max-width: 92vw;
	max-height: 92vh;
	display: flex;
	flex-direction: column;
	align-items: center;
	opacity: 0;
	transform: scale(0.98);
	transition: opacity 0.25s ease, transform 0.25s ease;
}
.bw-lightbox.is-open .bw-lightbox__figure {
	opacity: 1;
	transform: none;
}
.bw-lightbox__img {
	display: block;
	width: auto;
	height: auto;
	max-width: 92vw;
	max-height: 84vh;
	box-shadow: 0 10px 40px rgba(0, 0, 0, 0.5);
}
.bw-lightbox__caption {
	margin-top: 0.6rem;
	max-width: 80vw;
	color: #e5e7eb;
	font-size: 0.9rem;
	line-height: 1.4;
	text-align: center;
}

/* Buttons — hard resets (!important) so the theme's global button styling can't
 * leak in (same approach as the course/team modals). */
.bw-lightbox__close,
.bw-lightbox__nav {
	position: absolute;
	z-index: 2;
	display: flex;
	align-items: center;
	justify-content: center;
	margin: 0;
	padding: 0 !important;
	border: 0 !important;
	background: rgba(0, 0, 0, 0.35) !important;
	color: #fff;
	box-shadow: none !important;
	border-radius: 9999px !important;
	cursor: pointer;
	-webkit-appearance: none;
	appearance: none;
	transition: background-color 0.2s ease;
}
.bw-lightbox__close:hover,
.bw-lightbox__close:focus,
.bw-lightbox__nav:hover,
.bw-lightbox__nav:focus {
	background: rgba(0, 0, 0, 0.6) !important;
	color: #fff;
	outline: none;
}
.bw-lightbox__close {
	top: 1rem;
	right: 1rem;
	width: 2.5rem;
	height: 2.5rem;
}
.bw-lightbox__close svg {
	width: 1.1rem;
	height: 1.1rem;
	fill: currentColor;
}
.bw-lightbox__nav {
	top: 50%;
	transform: translateY(-50%);
	width: 3rem;
	height: 3rem;
}
.bw-lightbox__prev { left: 1rem; }
.bw-lightbox__next { right: 1rem; }
.bw-lightbox__nav svg {
	width: 1.3rem;
	height: 1.3rem;
	fill: currentColor;
}
.bw-lightbox__counter {
	position: absolute;
	bottom: 1rem;
	left: 50%;
	transform: translateX(-50%);
	z-index: 2;
	color: #e5e7eb;
	font-size: 0.85rem;
	letter-spacing: 0.03em;
}

html.bw-lightbox-open {
	overflow: hidden;
}

@media (max-width: 600px) {
	.bw-lightbox__nav { width: 2.5rem; height: 2.5rem; }
	.bw-lightbox__prev { left: 0.4rem; }
	.bw-lightbox__next { right: 0.4rem; }
	.bw-lightbox__close { top: 0.5rem; right: 0.5rem; }
}
