/* Bildi 0.11.3. No JS, no shadows. Override: --bildi-gap, --bildi-cols, --bildi-ratio, --bildi-ink, --bildi-ground, --bildi-accent */

.bildi {
	--bildi-gap: clamp(0.35rem, 1vw, 0.75rem);
	--bildi-cols: 3;
	--bildi-ratio: 4 / 3;
	--bildi-stage: min(72vh, 34rem);
	--bildi-tile: clamp(10rem, 30vw, 17rem);
	--bildi-ink: #f7f7f7;
	--bildi-ground: #0c0c0e;
	--bildi-accent: #ffd24d;
	margin-block: 1.5rem;
}

.bildi--cols-1 { --bildi-cols: 1; }
.bildi--cols-2 { --bildi-cols: 2; }
.bildi--cols-3 { --bildi-cols: 3; }
.bildi--cols-4 { --bildi-cols: 4; }
.bildi--cols-5 { --bildi-cols: 5; }
.bildi--cols-6 { --bildi-cols: 6; }

.bildi__grid {
	list-style: none;
	margin: 0;
	padding: 0;
	display: grid;
	gap: var(--bildi-gap);
	grid-template-columns: repeat(var(--bildi-cols), minmax(0, 1fr));
}

.bildi__item { margin: 0; }

.bildi__cell {
	margin: 0;
	display: flex;
	flex-direction: column;
	gap: 0.35rem;
	position: relative;
}

.bildi__link {
	display: block;
	line-height: 0;
	color: inherit;
	text-decoration: none;
	/* A missing attachment file leaves the anchor empty; axe flags a 0-height link as a target-size
	 * failure. Same guard z-designstudio put on its portfolio cards. */
	min-height: 24px;
}

.bildi__img {
	display: block;
	width: 100%;
	height: auto;
	aspect-ratio: var(--bildi-ratio);
	object-fit: cover;
}

/* Blur tile first, photo paints over it. */
.bildi__media {
	position: relative;
	display: block;
	overflow: hidden;
	isolation: isolate;
}

.bildi__media > .bildi__img {
	position: relative;
	z-index: 1;
}

.bildi__media[data-placeholder="blur"]::before {
	content: "";
	position: absolute;
	inset: -8%;
	z-index: 0;
	background-image: var(--bildi-lqip, none);
	background-size: cover;
	background-position: center;
	/* Scales the tile up slightly so the blurred edge never shows inside the crop. */
	filter: blur(18px);
}

/* Skeleton: no file, or a photo still loading. */
.bildi__media--empty {
	aspect-ratio: var(--bildi-ratio);
}

.bildi__media[data-placeholder="skeleton"],
.bildi__media--empty {
	background-color: #17171a;
}

.bildi__media[data-placeholder="skeleton"]::before,
.bildi__media--empty::before {
	content: "";
	position: absolute;
	inset: 0;
	z-index: 0;
	background-image: linear-gradient(100deg, transparent 20%, rgb(255 255 255 / 0.09) 50%, transparent 80%);
	background-size: 200% 100%;
	animation: bildi-shimmer 1.5s linear infinite;
}

@keyframes bildi-shimmer {
	from { background-position: 130% 0; }
	to   { background-position: -30% 0; }
}

@media (prefers-reduced-motion: reduce) {
	.bildi__media[data-placeholder="skeleton"]::before,
	.bildi__media--empty::before { animation: none; }
}

/* Placeholder off. */
.bildi[data-placeholder="off"] .bildi__media::before,
.bildi[data-placeholder="off"] .bildi__media--empty::before { content: none; }

/* Layouts: grid crops, masonry keeps heights, bento spans from shape, tiles justifies rows. */

.bildi--layout-masonry .bildi__grid {
	display: block;
	columns: var(--bildi-cols);
	column-gap: var(--bildi-gap);
}

.bildi--layout-masonry .bildi__item {
	break-inside: avoid;
	margin-block-end: var(--bildi-gap);
}

.bildi--layout-masonry .bildi__img {
	/* The photo's own shape, from the attachment. `auto` would follow whichever cropped candidate the
	 * browser selected from srcset, which is how a square crop turned three tiles into 1523 px towers. */
	aspect-ratio: var(--bildi-aspect, var(--bildi-ratio));
	height: auto;
}

.bildi--layout-bento .bildi__grid {
	grid-auto-rows: var(--bildi-tile);
	grid-auto-flow: row dense;
}

.bildi--layout-bento .bildi__item[data-span="wide"] {
	grid-column: span 2;
	grid-row: span 2;
}

.bildi--layout-bento .bildi__item[data-span="tall"] {
	grid-row: span 2;
}

.bildi--layout-bento .bildi__cell {
	height: 100%;
}

/* Media wrapper needs the height, or the image escapes the tile. */
.bildi--layout-bento .bildi__media {
	height: 100%;
}

.bildi--layout-bento .bildi__link {
	flex: 1 1 auto;
	min-height: 0;
}

.bildi--layout-bento .bildi__img {
	aspect-ratio: auto;
	height: 100%;
}

.bildi__item-caption {
	font-size: 0.8125rem;
	line-height: 1.35;
}

/* Tiles: one flex line per row, height fixed, width from the photo's ratio. */
.bildi--layout-tiles .bildi__rows { display: block; }

.bildi--layout-tiles .bildi__row {
	display: flex;
	gap: var(--bildi-gap);
	margin-block-end: var(--bildi-gap);
}

.bildi--layout-tiles .bildi__row > .bildi__cell {
	flex: var(--bildi-flex, 1) 1 0;
	min-width: 0;
}

.bildi--layout-tiles .bildi__media { height: var(--bildi-tile); }

.bildi--layout-tiles .bildi__img {
	height: 100%;
	aspect-ratio: auto;
}

/* 1px box: a background is fetched only when a rule matches. */

.bildi__preload {
	position: absolute;
	inset: auto auto 0 0;
	width: 1px;
	height: 1px;
	overflow: hidden;
	opacity: 0;
	pointer-events: none;
	background-repeat: no-repeat;
	background-size: cover;
}

.bildi__item:hover .bildi__preload,
.bildi__item:focus-within .bildi__preload {
	background-image: var(--bildi-full);
}

.bildi__light:target + .bildi__preload--next {
	background-image: var(--bildi-next);
}

/* Stage and stand-in are backgrounds, so a hidden node stays lazy. */

.bildi__photo {
	display: block;
	width: 100%;
	height: var(--bildi-stage);
	max-height: 100%;
	background-image: var(--bildi-photo), var(--bildi-place);
	background-size: contain, cover;
	background-position: center, center;
	background-repeat: no-repeat, no-repeat;
}

/* Focus needs its own ground. */
.bildi__link:focus-visible,
.bildi__step:focus-visible {
	outline: 3px solid var(--bildi-accent);
	outline-offset: 2px;
}

/* Lightbox: hidden until :target. */

.bildi__light {
	display: none;
	position: fixed;
	inset: 0;
	z-index: 1000;
	place-items: center;
	padding: clamp(1rem, 3vw, 2.5rem);
}

.bildi__light:target { display: grid; }

.bildi__backdrop {
	position: absolute;
	inset: 0;
	background: color-mix(in srgb, var(--bildi-ground) 95%, transparent);
}

.bildi__panel {
	position: relative;
	margin: 0;
	display: flex;
	flex-direction: column;
	align-items: center;
	gap: 0.5rem;
	max-width: min(100%, 92rem);
	max-height: 100%;
}

.bildi__caption,
.bildi__count {
	margin: 0;
	color: var(--bildi-ink);
	font-size: 0.875rem;
	line-height: 1.4;
	text-align: center;
	max-width: 60ch;
}

.bildi__nav {
	display: flex;
	flex-wrap: wrap;
	gap: 0.5rem;
	justify-content: center;
}

.bildi__step {
	display: inline-block;
	min-height: 2.75rem;
	padding: 0.6rem 1rem;
	color: var(--bildi-ink);
	background: rgb(255 255 255 / 0.14);
	text-decoration: none;
	border-radius: 0.35rem;
}

.bildi__step:hover { background: rgb(255 255 255 / 0.26); }

/* Scroll lock; no :has(), no lock unless the optional script adds the class. */
html:has(.bildi__light:target),
html.bildi-open { overflow: hidden; }

@media (prefers-reduced-motion: no-preference) {
	.bildi__light:target { animation: bildi-fade 0.18s ease-out; }
}

@keyframes bildi-fade {
	from { opacity: 0; }
	to { opacity: 1; }
}

/* Responsive columns. */

@media (max-width: 40em) {
	.bildi--cols-3,
	.bildi--cols-4,
	.bildi--cols-5,
	.bildi--cols-6 { --bildi-cols: 2; }
}

@media (max-width: 26em) {
	.bildi--cols-2,
	.bildi--cols-3,
	.bildi--cols-4,
	.bildi--cols-5,
	.bildi--cols-6 { --bildi-cols: 1; }

	/* A single column cannot absorb a span; collapse the bento to plain tiles. */
	.bildi--layout-bento .bildi__item[data-span="wide"],
	.bildi--layout-bento .bildi__item[data-span="tall"] {
		grid-column: span 1;
		grid-row: span 1;
	}

	.bildi--layout-bento .bildi__img {
		height: auto;
		aspect-ratio: var(--bildi-ratio);
	}
}

@media print {
	.bildi__viewer { display: none; }
}
