/*
 * Directory: structural CSS only, loaded on every front-end page.
 * Colours, fonts, and spacing belong in the child theme.
 * Spec: docs/directory.md, section 2.
 */

/* Hidden on screen, still read by screen readers. */
.bsa-visually-hidden:not(:focus):not(:active) {
	position: absolute !important;
	width: 1px !important;
	height: 1px !important;
	margin: -1px !important;
	padding: 0 !important;
	overflow: hidden !important;
	clip: rect(0, 0, 0, 0) !important;
	clip-path: inset(50%) !important;
	white-space: nowrap !important;
	border: 0 !important;
}

/* Card initials placeholder, for a profile with no directory image: the
   image's 4:3 shape, with the letters centred. */
.bsa-card-initials {
	display: flex;
	align-items: center;
	justify-content: center;
	width: 100%;
	aspect-ratio: 4 / 3;
}

/* Profile gallery: rows of equal height, images uncropped. The script
   sets each item's --bsa-ratio (width / height); without it every item
   gets a 4:3 share and the gallery is a simple wrapping row. Change the
   gap and the row height in the child theme with --bsa-gallery-gap and
   --bsa-gallery-row on .bsa-gallery. */
.bsa-gallery {
	display: flex;
	flex-wrap: wrap;
	gap: var(--bsa-gallery-gap, 8px);
	margin: 0;
	padding: 0;
	list-style: none;
}

/* Keeps the last row from stretching across the page. */
.bsa-gallery::after {
	content: "";
	flex-grow: 999999;
}

.bsa-gallery-item {
	flex-grow: calc(var(--bsa-ratio, 1.333) * 100);
	flex-basis: calc(var(--bsa-ratio, 1.333) * var(--bsa-gallery-row, 220px));
	max-width: calc(var(--bsa-ratio, 1.333) * 560px);
	margin: 0;
	padding: 0;
}

.bsa-gallery-item figure {
	margin: 0;
}

.bsa-gallery-item a {
	display: block;
}

.bsa-gallery-item img {
	display: block;
	width: 100%;
	height: auto;
}

/* Lightbox: a native dialog the gallery script builds on first use. It
   covers the screen; the dark backdrop and white text are the minimum for
   it to be readable, and the child theme can restyle them. It fades in
   and out (--bsa-lightbox-fade, default 0.25s); browsers that can't
   animate a dialog's opening and closing just show and hide it. */
.bsa-lightbox {
	box-sizing: border-box;
	width: 100%;
	max-width: 100%;
	height: 100%;
	max-height: 100vh;
	max-height: 100dvh;
	margin: 0;
	padding: 1rem;
	overflow: hidden;
	border: 0;
	background: transparent;
	color: #fff;
	opacity: 0;
	transition:
		opacity var(--bsa-lightbox-fade, 0.25s) ease,
		display var(--bsa-lightbox-fade, 0.25s) allow-discrete,
		overlay var(--bsa-lightbox-fade, 0.25s) allow-discrete;
}

.bsa-lightbox[open] {
	display: flex;
	flex-direction: column;
	align-items: center;
	opacity: 1;
}

.bsa-lightbox::backdrop {
	background: rgba(0, 0, 0, 0);
	transition:
		background-color var(--bsa-lightbox-fade, 0.25s) ease,
		display var(--bsa-lightbox-fade, 0.25s) allow-discrete,
		overlay var(--bsa-lightbox-fade, 0.25s) allow-discrete;
}

.bsa-lightbox[open]::backdrop {
	background: rgba(0, 0, 0, 0.88);
}

@starting-style {
	.bsa-lightbox[open] {
		opacity: 0;
	}

	.bsa-lightbox[open]::backdrop {
		background: rgba(0, 0, 0, 0);
	}
}

.bsa-lightbox [hidden] {
	display: none;
}

.bsa-lightbox-bar {
	align-self: flex-end;
}

/* Previous | picture | Next. The buttons take what they need; the picture
   gets the rest, so a wide image can never push a button off the screen. */
.bsa-lightbox-stage {
	display: grid;
	grid-template-columns: auto minmax(0, 1fr) auto;
	flex: 1 1 auto;
	align-items: center;
	column-gap: 1rem;
	width: 100%;
	min-height: 0;
}

.bsa-lightbox-prev {
	grid-column: 1;
	grid-row: 1;
}

.bsa-lightbox-next {
	grid-column: 3;
	grid-row: 1;
}

.bsa-lightbox-image {
	display: block;
	grid-column: 2;
	grid-row: 1;
	justify-self: center;
	width: auto;
	max-width: 100%;
	height: auto;
	max-height: calc(100vh - 9rem);
	max-height: calc(100dvh - 9rem);
	object-fit: contain;
	opacity: 1;
	transition: opacity var(--bsa-lightbox-fade, 0.25s) ease;
}

/* Set by the script while the next picture loads, so it fades in. */
.bsa-lightbox-image.bsa-lightbox-loading {
	opacity: 0;
}

.bsa-lightbox-caption {
	margin: 0.75rem 0 0;
	text-align: center;
}

body:has(dialog.bsa-lightbox[open]) {
	overflow: hidden;
}

@media (prefers-reduced-motion: reduce) {
	.bsa-lightbox,
	.bsa-lightbox::backdrop,
	.bsa-lightbox-image {
		transition: none;
	}
}

/* Profile videos: two columns (one on a narrow screen), each player in a
   16:9 box. Change the column count and the gap in the child theme with
   --bsa-videos-columns and --bsa-videos-gap on .bsa-videos. */
.bsa-videos {
	display: grid;
	grid-template-columns: repeat(var(--bsa-videos-columns, 2), minmax(0, 1fr));
	gap: var(--bsa-videos-gap, 16px);
}

@media (max-width: 600px) {
	.bsa-videos {
		grid-template-columns: minmax(0, 1fr);
	}
}

.bsa-video {
	aspect-ratio: 16 / 9;
}

.bsa-video iframe {
	display: block;
	width: 100%;
	height: 100%;
	border: 0;
}
