/**
 * Justified gallery.
 *
 * Two layouts live here. Flexbox runs first and gets close on its own, so the
 * gallery looks right with JavaScript disabled and never flashes an unstyled
 * column while the script boots. Once ejg.js has measured the rows it adds
 * .ejg--laid-out and takes over with exact positions.
 */

.ejg {
	--ejg-row: 250px;
	--ejg-gap: 10px;

	display: flex;
	flex-wrap: wrap;
	gap: var( --ejg-gap );
	margin: 0 0 var( --ejg-gap );
	padding: 0;
	list-style: none;
}

.ejg__item {
	position: relative;
	display: block;
	overflow: hidden;
	height: var( --ejg-row );
	flex-grow: var( --ejg-ar, 1.5 );
	flex-shrink: 1;
	flex-basis: calc( var( --ejg-ar, 1.5 ) * var( --ejg-row ) );
	text-decoration: none;
	background-color: #f2f2f2;
	border-radius: var( --ejg-radius, 0 );
}

.ejg__image {
	display: block;
	width: 100%;
	height: 100%;
	max-width: none;
	object-fit: cover;
	margin: 0;
	border: 0;
	border-radius: inherit;
}

/* Exact layout, once ejg.js has run. */
.ejg--laid-out {
	display: block;
	position: relative;
}

.ejg--laid-out .ejg__item {
	position: absolute;
	flex: none;
}

/* Captions. */
.ejg__caption {
	position: absolute;
	right: 0;
	bottom: 0;
	left: 0;
	padding: 1.4em 0.75em 0.6em;
	font-size: 0.8125rem;
	line-height: 1.35;
	color: #fff;
	text-align: left;
	background: linear-gradient( to top, rgba( 0, 0, 0, 0.72 ), rgba( 0, 0, 0, 0 ) );
	pointer-events: none;
}

.ejg--captions-hover .ejg__caption {
	opacity: 0;
	transform: translateY( 0.5em );
	transition: opacity 0.2s ease, transform 0.2s ease;
}

.ejg--captions-hover .ejg__item:hover .ejg__caption,
.ejg--captions-hover .ejg__item:focus-visible .ejg__caption {
	opacity: 1;
	transform: none;
}

/* Hover effect, on every image rather than only captioned ones. */
.ejg__image {
	transition: transform 0.35s ease, opacity 0.25s ease;
}

.ejg__item:hover .ejg__image,
.ejg__item:focus-visible .ejg__image {
	transform: scale( 1.05 );
	opacity: 0.92;
}

.ejg__item:focus-visible {
	outline: 2px solid currentColor;
	outline-offset: 2px;
}

@media ( prefers-reduced-motion: reduce ) {
	.ejg__image,
	.ejg--captions-hover .ejg__caption {
		transition: none;
	}

	.ejg__item:hover .ejg__image,
	.ejg__item:focus-visible .ejg__image {
		transform: none;
	}
}

/**
 * In the editor the preview is real markup, so every image is a real link.
 * Clicking one would navigate the editor canvas to the image file. Taking the
 * links out of hit testing lets the click fall through to the block itself,
 * which is what selects it.
 */
.editor-styles-wrapper .ejg__item {
	pointer-events: none;
}
