/*
 * Gallery, albums and the photo viewer.
 *
 * Shipped with the plugin rather than the child theme, and enqueued only on
 * pages that actually contain an album. The gallery is two or three pages out
 * of ninety-odd, so putting this in the site-wide stylesheet would make every
 * other page carry it.
 */

/* --------------------------------------------------------------------------
   Gallery and albums (spec P19)
   -------------------------------------------------------------------------- */

/* Album index */
.aop-albums {
	display: grid;
	grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
	gap: 20px;
	margin: 0 0 32px;
}

.aop-albumcard {
	display: flex;
	flex-direction: column;
	overflow: hidden;
	text-decoration: none;
	background: #fff;
	border: 1px solid var(--global-palette6, #D9D5CC);
	border-radius: var(--aop-radius);
	transition: transform var(--aop-ease), box-shadow var(--aop-ease);
}

.aop-albumcard:hover,
.aop-albumcard:focus-visible {
	transform: translateY(-2px);
	box-shadow: var(--aop-shadow-md);
}

.aop-albumcard__media {
	display: block;
	aspect-ratio: 4 / 3;
	overflow: hidden;
	background: var(--aop-tint);
}

.aop-albumcard__media img {
	width: 100%;
	height: 100%;
	object-fit: cover;
}

.aop-albumcard__blank {
	display: block;
	width: 100%;
	height: 100%;
}

.aop-albumcard__body {
	display: block;
	padding: 14px 16px 16px;
}

.aop-albumcard__title {
	display: block;
	font-weight: 700;
	line-height: 1.3;
	color: var(--global-palette1, #0B5D4A);
}

.aop-albumcard__meta {
	display: block;
	margin-top: 4px;
	font-size: .85rem;
	color: var(--global-palette5, #5A6672);
}

/* Masonry. CSS columns rather than a JavaScript layout: it reflows by itself,
   needs no measuring pass, and does not fight lazy loading - a JS masonry has
   to know each image's height, which is precisely what lazy loading defers. */
.aop-album {
	columns: 3 260px;
	column-gap: 14px;
	margin: 32px 0 0;
}

.aop-album__tile {
	/* break-inside is what stops a tile being sliced across two columns. */
	break-inside: avoid;
	margin: 0 0 14px;
	page-break-inside: avoid;
}

.aop-album__open {
	display: block;
	width: 100%;
	padding: 0;
	overflow: hidden;
	cursor: zoom-in;
	background: var(--aop-tint);
	border: 0;
	border-radius: var(--aop-radius-sm);
}

.aop-album__open img {
	display: block;
	width: 100%;
	height: auto;
	transition: transform var(--aop-ease);
}

.aop-album__open:hover img {
	transform: scale(1.03);
}

.aop-album__open:focus-visible {
	outline: 3px solid var(--global-palette1, #0B5D4A);
	outline-offset: 2px;
}

.aop-album__tile figcaption {
	margin-top: 6px;
	font-size: .82rem;
	line-height: 1.4;
	color: var(--global-palette5, #5A6672);
}

/* Video placeholder. Nothing is requested from YouTube or Vimeo until this is
   pressed, so the tile has to stand on its own rather than showing a remote
   poster image. */
.aop-album__open--video {
	display: flex;
	flex-direction: column;
	align-items: center;
	justify-content: center;
	gap: 8px;
	aspect-ratio: 16 / 9;
	cursor: pointer;
	color: #fff;
	background: var(--global-palette1, #0B5D4A);
}

.aop-album__videolabel {
	font-size: .9rem;
	font-weight: 600;
}

.aop-album__videonote {
	font-size: .75rem;
}

/* Lightbox */
.aop-lb[hidden] {
	display: none;
}

.aop-lb {
	position: fixed;
	inset: 0;
	z-index: 10000;
	display: flex;
	align-items: center;
	justify-content: center;
	padding: 24px;
}

.aop-lb__backdrop {
	position: absolute;
	inset: 0;
	background: rgba(0, 0, 0, .88);
}

.aop-lb__panel {
	position: relative;
	display: flex;
	flex-direction: column;
	align-items: center;
	gap: 12px;
	max-width: min(1100px, 100%);
	max-height: 100%;
}

.aop-lb__stage {
	display: flex;
	align-items: center;
	justify-content: center;
	max-height: calc(100vh - 140px);
}

.aop-lb__stage img {
	max-width: 100%;
	max-height: calc(100vh - 140px);
	width: auto;
	height: auto;
	border-radius: var(--aop-radius-sm);
}

.aop-lb__stage iframe {
	width: min(90vw, 960px);
	aspect-ratio: 16 / 9;
	height: auto;
	border: 0;
	border-radius: var(--aop-radius-sm);
}

.aop-lb__caption {
	margin: 0;
	font-size: .88rem;
	text-align: center;
	color: #fff;
}

.aop-lb__btn {
	position: absolute;
	z-index: 2;
	display: flex;
	align-items: center;
	justify-content: center;
	/* 48px, not the 24px minimum: these sit over a photograph with no layout
	   around them, so they need to be findable as well as hittable. */
	width: 48px;
	height: 48px;
	font-size: 2rem;
	line-height: 1;
	color: #fff;
	cursor: pointer;
	background: rgba(0, 0, 0, .55);
	border: 0;
	border-radius: 999px;
}

.aop-lb__btn:hover,
.aop-lb__btn:focus-visible {
	background: rgba(0, 0, 0, .85);
}

.aop-lb__btn:focus-visible {
	outline: 3px solid #fff;
	outline-offset: 2px;
}

.aop-lb__close {
	top: -8px;
	right: -8px;
}

.aop-lb__prev {
	top: 50%;
	left: -60px;
	transform: translateY(-50%);
}

.aop-lb__next {
	top: 50%;
	right: -60px;
	transform: translateY(-50%);
}

.aop-lb__btn[hidden] {
	display: none;
}

/* Stops the page scrolling behind the open viewer. */
body.aop-lb-open {
	overflow: hidden;
}

@media (max-width: 900px) {

	/* 140px, not 160px: the album container is about 311px wide on a 375px
	   phone, and at a 160px minimum the browser can only fit one column - so the
	   rule said "2" and delivered 1. At 140px two columns of roughly 148px
	   actually render, which is what makes a gallery scannable on a phone. */
	.aop-album {
		columns: 2 140px;
	}

	.aop-lb {
		padding: 12px;
	}

	/* On a narrow screen there is no room beside the photo, so the controls
	   move inside the panel rather than off the edge of the screen. */
	.aop-lb__prev {
		left: 4px;
	}

	.aop-lb__next {
		right: 4px;
	}

	.aop-lb__close {
		top: 4px;
		right: 4px;
	}
}

@media (prefers-reduced-motion: reduce) {

	.aop-albumcard,
	.aop-album__open img {
		transition: none;
	}

	.aop-albumcard:hover,
	.aop-albumcard:focus-visible {
		transform: none;
	}

	.aop-album__open:hover img {
		transform: none;
	}
}
