/* Afterimage Gallery: masonry layout and a full-screen viewer. Colours follow the theme's variables when present. */

/* Before the script runs (or without it): simple columns. */
.aig-gallery {
	column-count: 3;
	column-gap: var(--aig-gap, 18px);
	margin: 32px 0;
}

@media (max-width: 899px) {
	.aig-gallery { column-count: 2; }
}

@media (max-width: 559px) {
	.aig-gallery { column-count: 1; }
}

.aig-item {
	break-inside: avoid;
	margin: 0 0 var(--aig-gap, 18px);
}

/* Masonry: the script places each photo in the shortest column, makes some photos
   double width where the columns below are level, and evens out the bottom edge. */
.aig-gallery.aig-ready {
	position: relative;
	column-count: auto;
}

.aig-ready .aig-item {
	position: absolute;
	margin: 0;
}

.aig-link {
	display: block;
	overflow: hidden;
	background: var(--surface, #1a1816);
	cursor: zoom-in;
}

.aig-ready .aig-link {
	height: 100%;
}

.aig-link img {
	display: block;
	width: 100%;
	height: auto;
	transition: opacity 0.2s ease;
}

.aig-ready .aig-link img {
	height: 100%;
	object-fit: cover;
}

.aig-hover .aig-link:hover img {
	opacity: 0.82;
}

.aig-link:focus {
	outline: 0;
}

/* Keyboard focus: same ring as the album covers. */
.aig-link:focus-visible {
	outline: 2px solid var(--signal, #f37e7e);
	outline-offset: 3px;
}

/* ---------- viewer ---------- */
html.aig-open,
html.aig-open body {
	overflow: hidden;
}

.aig-viewer {
	position: fixed;
	inset: 0;
	z-index: 100000;
	display: flex;
	flex-direction: column;
	background: #0c0b0a;
	color: #efe9e0;
	font-family: var(--sans, "Jost", sans-serif);
}

.aig-viewer[hidden] {
	display: none;
}

.aig-viewer__stage {
	flex: 1;
	min-height: 0;
	display: flex;
	align-items: center;
	justify-content: center;
	padding: 56px 72px 8px;
}

.aig-viewer__img {
	max-width: 100%;
	max-height: 100%;
	object-fit: contain;
	user-select: none;
	-webkit-user-drag: none;
}

.aig-viewer__text {
	align-self: center;
	width: 100%;
	max-width: 68ch;
	min-height: 3.5em;
	padding: 10px 24px 22px;
	text-align: center;
	font-size: 0.9375rem;
	line-height: 1.5;
}

.aig-viewer__title {
	display: block;
	font-family: var(--serif, Georgia, serif);
	font-size: 1.125rem;
	font-weight: 300;
}

.aig-viewer__caption {
	display: block;
	margin-top: 4px;
	color: #b4ac9f;
}

.aig-viewer__count {
	position: absolute;
	top: 18px;
	left: 22px;
	color: #9b9489;
	font-size: 0.8125rem;
	letter-spacing: 0.04em;
}

.aig-btn {
	position: absolute;
	display: flex;
	align-items: center;
	justify-content: center;
	width: 48px;
	height: 48px;
	padding: 0;
	border: 0;
	border-radius: 50%;
	background: none;
	color: #efe9e0;
	opacity: 0.75;
	cursor: pointer;
	transition: opacity 0.15s, color 0.15s;
}

.aig-btn:hover,
.aig-btn:focus-visible {
	opacity: 1;
	color: var(--signal, #f37e7e);
}

.aig-btn:focus-visible {
	outline: 2px solid var(--signal, #f37e7e);
}

.aig-btn svg {
	width: 26px;
	height: 26px;
}

.aig-close { top: 6px; right: 8px; }

/* Previous and next: the left and right halves of the photo, as in Modula's lightbox. The script
   lays them over the photo; the arrow shows on hover. */
.aig-half {
	position: absolute;
	padding: 0;
	border: 0;
	background: none no-repeat;
	cursor: pointer;
}

.aig-half[hidden] {
	display: none;
}

.aig-half:focus {
	outline: 0;
}

.aig-half:focus-visible {
	outline: 2px solid var(--signal, #f37e7e);
	outline-offset: -4px;
}

/* The arrow sits on its own layer so it can fade in and out. */
.aig-half::before {
	content: "";
	position: absolute;
	top: 48%;
	width: 50px;
	height: 45px;
	transform: translateY(-50%);
	background: no-repeat center;
	opacity: 0;
	transition: opacity 0.3s ease;
	pointer-events: none;
}

.aig-half:hover::before,
.aig-half:focus-visible::before {
	opacity: 1;
}

.aig-prev::before {
	left: 0;
	background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='50' height='45'%3E%3Cpath d='M40 7 28.5 19.4Q25.5 22.5 28.5 25.6L40 38' fill='none' stroke='%23fff' stroke-opacity='.55' stroke-width='7' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
}

.aig-next::before {
	right: 0;
	background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='50' height='45'%3E%3Cpath d='M10 7 21.5 19.4Q24.5 22.5 21.5 25.6L10 38' fill='none' stroke='%23fff' stroke-opacity='.55' stroke-width='7' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
}

@media (prefers-reduced-motion: reduce) {
	.aig-half::before { transition: none; }
}

@media (max-width: 559px) {
	.aig-viewer__stage { padding: 52px 6px 6px; }
	.aig-viewer__text { padding: 10px 56px 18px; }
}

/* Viewer that follows the site's colours (light or dark). */
.aig-viewer--theme {
	background: var(--bg, #0c0b0a);
	color: var(--ink, #efe9e0);
}

.aig-viewer--theme .aig-btn {
	color: var(--ink, #efe9e0);
}

.aig-viewer--theme .aig-viewer__caption {
	color: var(--muted, #b4ac9f);
}

/* ---------- viewer: layout of the panel ---------- */
.aig-viewer__panel {
	position: relative;
	flex: 1;
	min-height: 0;
	display: flex;
	flex-direction: column;
	width: 100%;
}

/* Pop-up window: the photo sits in a framed window over the dimmed page. */
.aig-viewer--window {
	align-items: center;
	justify-content: center;
	padding: 32px 76px;
	background: rgba(8, 7, 6, 0.78);
	-webkit-backdrop-filter: blur(6px);
	backdrop-filter: blur(6px);
	animation: aig-fade 0.18s ease-out;
}

.aig-viewer--window .aig-viewer__panel {
	flex: 0 1 auto;
	width: auto;
	max-width: min(1200px, 100%);
	max-height: 100%;
	background: #141210;
	border: 1px solid rgba(239, 233, 224, 0.12);
	border-radius: 6px;
	box-shadow: 0 24px 70px rgba(0, 0, 0, 0.55);
	overflow: hidden;
	animation: aig-pop 0.2s ease-out;
}

.aig-viewer--window .aig-viewer__stage {
	flex: 0 1 auto;
	padding: 48px 20px 0;
}

.aig-viewer--window .aig-viewer__img {
	max-height: calc(100vh - 230px);
}

.aig-viewer--window .aig-viewer__text {
	padding: 12px 24px 18px;
	min-height: 0;
}

.aig-viewer--window .aig-viewer__count {
	top: 14px;
	left: 18px;
}

.aig-viewer--window .aig-close {
	top: 2px;
	right: 4px;
}

.aig-viewer--window.aig-viewer--theme .aig-viewer__panel {
	background: var(--surface, #141210);
	border-color: var(--rule, rgba(239, 233, 224, 0.12));
}

@keyframes aig-fade { from { opacity: 0; } to { opacity: 1; } }
@keyframes aig-pop { from { opacity: 0; transform: scale(0.97); } to { opacity: 1; transform: none; } }

@media (prefers-reduced-motion: reduce) {
	.aig-viewer--window,
	.aig-viewer--window .aig-viewer__panel { animation: none; }
}

@media (max-width: 559px) {
	.aig-viewer--window { padding: 12px 8px 64px; }
	.aig-viewer--window .aig-viewer__img { max-height: calc(100vh - 220px); }
}
