/* Gallery style „Vějíř“: covers overlap in an arc. --max covers are shown
   (7 / 5 by screen width), --n = how many are in a row. Phones: two rows of
   3, the second in front of the first. */

.wp-block-gallery.is-style-pkcs-vejir {
	--max: 7;
	--count: 8;
	--n: min(var(--count), var(--max));
	--overlap: .28;
	--edge: .45; /* room for the tilted outer covers, in cover widths */
	--w: min(190px, calc((100% - 1px) / (var(--n) * (1 - var(--overlap)) + var(--overlap) + var(--edge))));
	--step: 6deg;
	--drop: 3%;
	display: flex;
	flex-wrap: wrap;
	justify-content: center;
	align-items: flex-end;
	gap: 0 !important;
	box-sizing: border-box;
	padding: .5em 2em calc(.5em + var(--w) * .3); /* the outer covers drop lower */
	overflow: clip; /* never wider than the page (overflow-clip-margin needs clip on both axes) */
	overflow-clip-margin: 2em; /* corners of the outer covers may stick out */
}

.wp-block-gallery.is-style-pkcs-vejir:has(> figure.wp-block-image:nth-of-type(1):last-of-type) { --count: 1; }
.wp-block-gallery.is-style-pkcs-vejir:has(> figure.wp-block-image:nth-of-type(2):last-of-type) { --count: 2; }
.wp-block-gallery.is-style-pkcs-vejir:has(> figure.wp-block-image:nth-of-type(3):last-of-type) { --count: 3; }
.wp-block-gallery.is-style-pkcs-vejir:has(> figure.wp-block-image:nth-of-type(4):last-of-type) { --count: 4; }
.wp-block-gallery.is-style-pkcs-vejir:has(> figure.wp-block-image:nth-of-type(5):last-of-type) { --count: 5; }
.wp-block-gallery.is-style-pkcs-vejir:has(> figure.wp-block-image:nth-of-type(6):last-of-type) { --count: 6; }
.wp-block-gallery.is-style-pkcs-vejir:has(> figure.wp-block-image:nth-of-type(7):last-of-type) { --count: 7; }

.wp-block-gallery.is-style-pkcs-vejir > figure.wp-block-image:not(#individual-image) {
	--off: calc(var(--i) - (var(--n) - 1) / 2);
	position: relative;
	flex: 0 0 auto !important;
	width: var(--w) !important;
	margin: 0 0 0 calc(var(--w) * -1 * var(--overlap)) !important;
	transform: translateY(calc(var(--off) * var(--off) * var(--drop))) rotate(calc(var(--off) * var(--step))) scale(var(--scale, 1));
	transform-origin: 50% 100%;
}

.wp-block-gallery.is-style-pkcs-vejir > figure.wp-block-image:first-of-type {
	margin-left: 0 !important;
}

.wp-block-gallery.is-style-pkcs-vejir > figure.wp-block-image:nth-of-type(1) { --i: 0; }
.wp-block-gallery.is-style-pkcs-vejir > figure.wp-block-image:nth-of-type(2) { --i: 1; }
.wp-block-gallery.is-style-pkcs-vejir > figure.wp-block-image:nth-of-type(3) { --i: 2; }
.wp-block-gallery.is-style-pkcs-vejir > figure.wp-block-image:nth-of-type(4) { --i: 3; }
.wp-block-gallery.is-style-pkcs-vejir > figure.wp-block-image:nth-of-type(5) { --i: 4; }
.wp-block-gallery.is-style-pkcs-vejir > figure.wp-block-image:nth-of-type(6) { --i: 5; }
.wp-block-gallery.is-style-pkcs-vejir > figure.wp-block-image:nth-of-type(7) { --i: 6; }
.wp-block-gallery.is-style-pkcs-vejir > figure.wp-block-image:nth-of-type(n+8) { display: none; }

.wp-block-gallery.is-style-pkcs-vejir > figure.wp-block-image:not(#individual-image) img {
	display: block;
	width: 100% !important;
	height: auto !important;
	aspect-ratio: auto; /* the child theme forces 4 / 3 on gallery images; on the front end vejir.php sets the real one inline */
	object-fit: contain !important;
	border-radius: 3px;
	box-shadow: 0 2px 4px rgba(0, 0, 0, .12), 0 10px 24px rgba(40, 45, 10, .28);
}

.wp-block-gallery.is-style-pkcs-vejir > figure.wp-block-image::before,
.wp-block-gallery.is-style-pkcs-vejir > figure.wp-block-image figcaption {
	display: none !important;
}

.wp-block-gallery.is-style-pkcs-vejir > .blocks-gallery-caption {
	flex-basis: 100%;
	margin-top: 1.5em;
}

@media (max-width: 921px) {
	.wp-block-gallery.is-style-pkcs-vejir {
		--max: 5;
	}
	.wp-block-gallery.is-style-pkcs-vejir > figure.wp-block-image:nth-of-type(n+6) {
		display: none;
	}
}

@media (max-width: 544px) {
	.wp-block-gallery.is-style-pkcs-vejir {
		--max: 3;
		--edge: 0;
		--step: 8deg;
		padding: .5em 1em .75em;
		overflow-clip-margin: 0;
	}
	.wp-block-gallery.is-style-pkcs-vejir > figure.wp-block-image:nth-of-type(6) {
		display: flex;
	}
	.wp-block-gallery.is-style-pkcs-vejir > figure.wp-block-image:nth-of-type(n+7) {
		display: none;
	}
	/* Back row: the first three, a bit smaller. */
	.wp-block-gallery.is-style-pkcs-vejir:has(> figure.wp-block-image:nth-of-type(4)) > figure.wp-block-image:nth-of-type(-n+3) {
		--scale: .9;
	}
	/* Front row: covers 4–6, pulled up over the back row. */
	.wp-block-gallery.is-style-pkcs-vejir > figure.wp-block-image:nth-of-type(n+4) {
		--n: min(calc(var(--count) - 3), 3);
	}
	.wp-block-gallery.is-style-pkcs-vejir > figure.wp-block-image:not(#individual-image):nth-of-type(n+4) {
		margin-top: calc(var(--w) * -.6) !important;
	}
	.wp-block-gallery.is-style-pkcs-vejir > figure.wp-block-image:not(#individual-image):nth-of-type(4) {
		margin-left: 0 !important;
	}
	.wp-block-gallery.is-style-pkcs-vejir > figure.wp-block-image:nth-of-type(4) { --i: 0; }
	.wp-block-gallery.is-style-pkcs-vejir > figure.wp-block-image:nth-of-type(5) { --i: 1; }
	.wp-block-gallery.is-style-pkcs-vejir > figure.wp-block-image:nth-of-type(6) { --i: 2; }
}
