/* ---------------------------------------------------------------------------------------------

	Tiled Gallery Fallback
	Only enqueued when Jetpack's own Tiled Gallery module isn't active. Reproduces the
	jetpack/tiled-gallery block's frontend styles for galleries already saved with that
	markup, and styles core/gallery output converted to the same markup by bjork_render_tiled_gallery().

--------------------------------------------------------------------------------------------- */


/* Existing "jetpack/tiled-gallery" block markup ---------------------------------------------- */

.tiled-gallery__gallery {
	display: flex;
	flex-wrap: wrap;
	padding: 0;
	width: 100%;
}

.tiled-gallery__row {
	display: flex;
	flex-direction: row;
	justify-content: center;
	margin: 0;
	width: 100%;
}

.tiled-gallery__row + .tiled-gallery__row {
	margin-top: 4px;
}

.tiled-gallery__col {
	display: flex;
	flex-direction: column;
	justify-content: center;
	margin: 0;
}

.tiled-gallery__col + .tiled-gallery__col {
	margin-inline-start: 4px;
}

.tiled-gallery__item {
	flex-grow: 1;
	justify-content: center;
	margin: 0;
	overflow: hidden;
	padding: 0;
	position: relative;
}

.tiled-gallery__item + .tiled-gallery__item {
	margin-top: 4px;
}

.tiled-gallery__item > a,
.tiled-gallery__item > a > img,
.tiled-gallery__item > img {
	display: block;
	height: auto;
	margin: 0;
	max-width: 100%;
	object-fit: cover;
	object-position: center;
	padding: 0;
	width: 100%;
}

.tiled-gallery__item:focus-within {
	box-shadow: 0 0 0 2px var( --wp--preset--color--primary, #0085ba );
	overflow: visible;
}

.tiled-gallery__item > a,
.tiled-gallery__item > a > img,
.tiled-gallery__item > img,
.bjork-tiled-gallery-item img {
	cursor: zoom-in;
}


/* Carousel lightbox (assets/js/tiled-gallery-carousel.js) -------------------------------------- */

body.bjork-carousel-open {
	overflow: hidden;
}

.bjork-carousel {
	align-items: center;
	background: rgba( 0, 0, 0, .9 );
	display: none;
	inset: 0;
	justify-content: center;
	position: fixed;
	z-index: 100000;
}

.bjork-carousel.is-open {
	display: flex;
}

.bjork-carousel__stage {
	align-items: center;
	display: flex;
	height: 90vh;
	justify-content: center;
	width: 90vw;
}

.bjork-carousel__image {
	display: block;
	height: auto;
	max-height: 90vh;
	max-width: 90vw;
	width: auto;
}

.bjork-carousel__close,
.bjork-carousel__prev,
.bjork-carousel__next {
	background: transparent;
	border: none;
	color: #fff;
	cursor: pointer;
	line-height: 1;
}

.bjork-carousel__close {
	font-size: 2.5rem;
	padding: .5em;
	position: absolute;
	right: 0;
	top: 0;
}

.bjork-carousel__prev,
.bjork-carousel__next {
	font-size: 3rem;
	padding: .25em .75em;
	position: absolute;
	top: 50%;
	transform: translateY( -50% );
}

.bjork-carousel__prev {
	left: 0;
}

.bjork-carousel__next {
	right: 0;
}

:where( .wp-block-jetpack-tiled-gallery.is-style-columns, .wp-block-jetpack-tiled-gallery.is-style-rectangular ) .tiled-gallery__item {
	display: flex;
}

:where( .wp-block-jetpack-tiled-gallery.is-style-circle ) .tiled-gallery__item img {
	border-radius: 50%;
}

:where( .wp-block-jetpack-tiled-gallery.is-style-square, .wp-block-jetpack-tiled-gallery.is-style-circle ) .tiled-gallery__item img {
	aspect-ratio: 1;
}

:where( .wp-block-jetpack-tiled-gallery.is-style-square, .wp-block-jetpack-tiled-gallery.is-style-circle ) .tiled-gallery__row {
	flex-grow: 1;
	width: 100%;
}

/* Square/Circle styles divide each row into even columns (covers up to 9 columns). */
:where( .wp-block-jetpack-tiled-gallery.is-style-square, .wp-block-jetpack-tiled-gallery.is-style-circle ) .tiled-gallery__row.columns-1 .tiled-gallery__col { width: 100%; }
:where( .wp-block-jetpack-tiled-gallery.is-style-square, .wp-block-jetpack-tiled-gallery.is-style-circle ) .tiled-gallery__row.columns-2 .tiled-gallery__col { width: calc( ( 100% - 4px ) / 2 ); }
:where( .wp-block-jetpack-tiled-gallery.is-style-square, .wp-block-jetpack-tiled-gallery.is-style-circle ) .tiled-gallery__row.columns-3 .tiled-gallery__col { width: calc( ( 100% - 8px ) / 3 ); }
:where( .wp-block-jetpack-tiled-gallery.is-style-square, .wp-block-jetpack-tiled-gallery.is-style-circle ) .tiled-gallery__row.columns-4 .tiled-gallery__col { width: calc( ( 100% - 12px ) / 4 ); }
:where( .wp-block-jetpack-tiled-gallery.is-style-square, .wp-block-jetpack-tiled-gallery.is-style-circle ) .tiled-gallery__row.columns-5 .tiled-gallery__col { width: calc( ( 100% - 16px ) / 5 ); }
:where( .wp-block-jetpack-tiled-gallery.is-style-square, .wp-block-jetpack-tiled-gallery.is-style-circle ) .tiled-gallery__row.columns-6 .tiled-gallery__col { width: calc( ( 100% - 20px ) / 6 ); }
:where( .wp-block-jetpack-tiled-gallery.is-style-square, .wp-block-jetpack-tiled-gallery.is-style-circle ) .tiled-gallery__row.columns-7 .tiled-gallery__col { width: calc( ( 100% - 24px ) / 7 ); }
:where( .wp-block-jetpack-tiled-gallery.is-style-square, .wp-block-jetpack-tiled-gallery.is-style-circle ) .tiled-gallery__row.columns-8 .tiled-gallery__col { width: calc( ( 100% - 28px ) / 8 ); }
:where( .wp-block-jetpack-tiled-gallery.is-style-square, .wp-block-jetpack-tiled-gallery.is-style-circle ) .tiled-gallery__row.columns-9 .tiled-gallery__col { width: calc( ( 100% - 32px ) / 9 ); }

/* Per-image filters (css-gram, ported from Jetpack's tiled-gallery block) */

.tiled-gallery__item.filter__black-and-white { filter: grayscale( 100% ); }
.tiled-gallery__item.filter__sepia { filter: sepia( 100% ); }

.tiled-gallery__item.filter__1977,
.tiled-gallery__item.filter__clarendon,
.tiled-gallery__item.filter__gingham {
	position: relative;
}

.tiled-gallery__item.filter__1977 img,
.tiled-gallery__item.filter__clarendon img,
.tiled-gallery__item.filter__gingham img {
	position: relative;
	z-index: 1;
}

.tiled-gallery__item.filter__1977::before,
.tiled-gallery__item.filter__1977::after,
.tiled-gallery__item.filter__clarendon::before,
.tiled-gallery__item.filter__clarendon::after,
.tiled-gallery__item.filter__gingham::before,
.tiled-gallery__item.filter__gingham::after {
	content: "";
	display: block;
	height: 100%;
	left: 0;
	pointer-events: none;
	position: absolute;
	top: 0;
	width: 100%;
}

.tiled-gallery__item.filter__1977::before,
.tiled-gallery__item.filter__clarendon::before,
.tiled-gallery__item.filter__gingham::before {
	z-index: 2;
}

.tiled-gallery__item.filter__1977::after,
.tiled-gallery__item.filter__clarendon::after,
.tiled-gallery__item.filter__gingham::after {
	z-index: 3;
}

.tiled-gallery__item.filter__1977 {
	filter: contrast( 1.1 ) brightness( 1.1 ) saturate( 1.3 );
}

.tiled-gallery__item.filter__1977::after {
	background: rgba( 243, 106, 188, .3 );
	mix-blend-mode: screen;
}

.tiled-gallery__item.filter__clarendon {
	filter: contrast( 1.2 ) saturate( 1.35 );
}

.tiled-gallery__item.filter__clarendon::before {
	background: rgba( 127, 187, 227, .2 );
	mix-blend-mode: overlay;
}

.tiled-gallery__item.filter__gingham {
	filter: brightness( 1.05 ) hue-rotate( -10deg );
}

.tiled-gallery__item.filter__gingham::after {
	background: rgb( 230, 230, 250 );
	mix-blend-mode: soft-light;
}


/* core/gallery converted by bjork_render_tiled_gallery() ------------------------------------- */

.bjork-tiled-gallery {
	display: flex;
	flex-direction: column;
	gap: 4px;
	margin: 0 0 1.5em;
}

.bjork-tiled-gallery-row {
	display: flex;
	gap: 4px;
	height: clamp( 120px, 22vw, 320px );
}

.bjork-tiled-gallery-item {
	flex-basis: 0;
	flex-grow: var( --bjork-tiled-gallery-item-ratio, 1 );
	margin: 0;
	min-width: 0;
	overflow: hidden;
	position: relative;
}

.bjork-tiled-gallery-item a,
.bjork-tiled-gallery-item img {
	display: block;
	height: 100%;
	width: 100%;
}

.bjork-tiled-gallery-item img {
	object-fit: cover;
}
