/*
 * Galleries of the kit (inc/galleries.php): what every gallery section built
 * on WordPress's Gallery block shares, the three looks a gallery can take, and
 * the filter buttons.
 *
 *   wprk-gallery                          a gallery of the kit
 *   wprk-gallery--captions                captions under the pictures
 *   wprk-gallery-filter                   sent with filter buttons
 *   is-style-wprk-gallery-masonry         pictures keep their shapes, in columns
 *   is-style-wprk-gallery-swipe           a grid; one row to slide on a phone
 *   is-style-wprk-gallery-masonry-swipe   masonry; one row to slide on a phone
 *
 * WordPress writes its rules for a picture of a gallery with the weight of an
 * ID (":not(#individual-image)"). The rules here that have to win carry the
 * same, ":not(#wprk)", which matches every picture.
 */

.wp-block-gallery.has-nested-images.wprk-gallery {
	--wp--style--gallery-gap-default: var(--wp--preset--spacing--20);
	gap: var(--wp--preset--spacing--20);
}

@media (min-width: 782px) {
	.wp-block-gallery.has-nested-images.wprk-gallery {
		--wp--style--gallery-gap-default: var(--wp--preset--spacing--30);
		gap: var(--wp--preset--spacing--30);
	}
}

.wprk-gallery figure.wp-block-image img {
	border-radius: var(--wprk-picture-radius, 0);
}

/* A cropped grid has tiles of one shape, whatever the shape of each upload. */
.wprk-gallery.is-cropped:not([class*="is-style-wprk-gallery-masonry"]) figure.wp-block-image img {
	aspect-ratio: 4 / 3;
}

/*
 * In a gallery with filter buttons a tile keeps its size, however many are
 * left: WordPress lets the pictures of a short last line grow to fill it.
 */
.wp-block-gallery.has-nested-images.wprk-gallery-filter figure.wp-block-image:not(#wprk) {
	flex-grow: 0;
}

/* A picture taken out by a filter button. */
.wp-block-gallery.wprk-gallery figure.wp-block-image:not(#wprk)[hidden] {
	display: none !important; /* the masonry look gives a picture a display of its own */
}

/* Enlarge button: finger-sized, in the theme's shape. WordPress shows it on hover and on focus. */
.wprk-gallery .wp-lightbox-container button {
	border-radius: var(--wp--custom--radius--sm);
	height: 2.75rem;
	width: 2.75rem;
}

.wprk-gallery .wp-lightbox-container button svg {
	height: 1rem;
	width: 1rem;
}

.wprk-gallery .wp-lightbox-container button:focus-visible {
	box-shadow: 0 0 0 4px var(--wprk-focus);
	outline: 2px solid var(--wprk-bg);
	outline-offset: 0;
}

.wprk-gallery .wp-lightbox-container:has(button:focus-visible) img {
	outline: 2px solid var(--wprk-focus);
	outline-offset: 2px;
}

/*
 * Captions under the pictures. WordPress lays a caption over the foot of its
 * picture, white on a dark fade. Here it stands under the picture in the
 * colours of the section, and the picture keeps its own shape.
 */
.wp-block-gallery.has-nested-images.wprk-gallery--captions figure.wp-block-image:not(#wprk) {
	align-self: flex-start;
	display: block;
}

.wp-block-gallery.has-nested-images.wprk-gallery--captions figure.wp-block-image:not(#wprk) img {
	display: block;
	height: auto;
	width: 100%;
}

.wp-block-gallery.has-nested-images.wprk-gallery--captions figure.wp-block-image:not(#wprk)::before,
.wp-block-gallery.has-nested-images.wprk-gallery--captions figure.wp-block-image:not(#wprk)::after {
	content: none;
}

.wp-block-gallery.has-nested-images.wprk-gallery--captions figure.wp-block-image:not(#wprk) figcaption {
	background: none;
	color: var(--wprk-muted);
	font-size: var(--wp--preset--font-size--small);
	line-height: 1.5;
	margin: 0;
	max-height: none;
	overflow: visible;
	padding: var(--wp--preset--spacing--20) 0 0;
	position: static;
	text-align: start;
	text-shadow: none;
	width: auto;
}

.wp-block-gallery.has-nested-images.wprk-gallery--captions figure.wp-block-image:not(#wprk) figcaption :where(strong) {
	color: var(--wprk-heading);
	display: block;
	font-size: var(--wp--preset--font-size--medium);
	font-weight: 600;
}

.wp-block-gallery.has-nested-images.wprk-gallery--captions figure.wp-block-image:not(#wprk) figcaption a {
	color: inherit;
}

/*
 * Masonry: columns of pictures, each in its own shape. Two columns on a
 * phone, three from 782 px, four from 1024 px where the gallery asks for four
 * or more. The room under a picture is padding of the picture's box: a browser
 * drops a margin at the foot of a column.
 */
.wp-block-gallery.has-nested-images[class*="is-style-wprk-gallery-masonry"] {
	column-count: 2;
	column-gap: var(--wp--style--gallery-gap-default, var(--wp--preset--spacing--20));
	display: block;
}

.wp-block-gallery.has-nested-images[class*="is-style-wprk-gallery-masonry"] figure.wp-block-image:not(#wprk) {
	break-inside: avoid;
	display: block;
	margin: 0;
	padding-block-end: var(--wp--style--gallery-gap-default, var(--wp--preset--spacing--20));
	width: 100%;
}

.wp-block-gallery.has-nested-images[class*="is-style-wprk-gallery-masonry"] figure.wp-block-image:not(#wprk) img {
	display: block;
	flex: none;
	height: auto;
	width: 100%;
}

/* A caption over the picture is placed from the picture, not from the padded box. */
.wp-block-gallery.has-nested-images[class*="is-style-wprk-gallery-masonry"]:not(.wprk-gallery--captions) figure.wp-block-image:not(#wprk) figcaption {
	bottom: var(--wp--style--gallery-gap-default, var(--wp--preset--spacing--20));
}

@media (min-width: 782px) {
	.wp-block-gallery.has-nested-images[class*="is-style-wprk-gallery-masonry"] {
		column-count: 3;
	}

	.wp-block-gallery.has-nested-images[class*="is-style-wprk-gallery-masonry"].columns-2 {
		column-count: 2;
	}
}

@media (min-width: 1024px) {
	.wp-block-gallery.has-nested-images[class*="is-style-wprk-gallery-masonry"]:is(.columns-4, .columns-5, .columns-6, .columns-7, .columns-8) {
		column-count: 4;
	}
}

/*
 * One row to slide on a phone, for the two looks that end in "swipe": a
 * picture takes most of the width and the next one shows in part. Where the
 * gallery stands directly in a section the row reaches both edges of the
 * screen and the first picture still begins where the heading does.
 */
@media (max-width: 599px) {
	.wp-block-gallery.has-nested-images:is(.is-style-wprk-gallery-swipe, .is-style-wprk-gallery-masonry-swipe) {
		column-count: auto;
		display: flex;
		flex-wrap: nowrap;
		overflow-x: auto;
		overscroll-behavior-x: contain;
		scroll-snap-type: x mandatory;
		scrollbar-width: none;
	}

	.wp-block-gallery.has-nested-images:is(.is-style-wprk-gallery-swipe, .is-style-wprk-gallery-masonry-swipe)::-webkit-scrollbar {
		display: none;
	}

	.wp-block-gallery.has-nested-images:is(.is-style-wprk-gallery-swipe, .is-style-wprk-gallery-masonry-swipe) figure.wp-block-image:not(#wprk) {
		flex: 0 0 84%;
		padding-block-end: 0;
		scroll-snap-align: start;
		width: 84%;
	}

	.wp-block-gallery.has-nested-images:is(.is-style-wprk-gallery-swipe, .is-style-wprk-gallery-masonry-swipe) figure.wp-block-image:not(#wprk) img {
		aspect-ratio: 4 / 3;
		object-fit: cover;
	}

	.wp-block-gallery.has-nested-images:is(.is-style-wprk-gallery-swipe, .is-style-wprk-gallery-masonry-swipe):not(.wprk-gallery--captions) figure.wp-block-image:not(#wprk) figcaption {
		bottom: 0;
	}

	.wprk-section > .wp-block-gallery.has-nested-images:is(.is-style-wprk-gallery-swipe, .is-style-wprk-gallery-masonry-swipe) {
		margin-inline: calc(0px - var(--wp--style--root--padding-left, 0px)) !important;
		max-width: none;
		padding-inline: var(--wp--style--root--padding-left, 0px);
		scroll-padding-inline: var(--wp--style--root--padding-left, 0px);
	}
}

/* The editor shows the scrollbar of a sliding row, so every picture can be reached. */
.editor-styles-wrapper .wp-block-gallery:is(.is-style-wprk-gallery-swipe, .is-style-wprk-gallery-masonry-swipe) {
	scrollbar-width: thin;
}

/*
 * Filter buttons: "All", then one for each tag. They take the shape of the
 * theme's buttons; the one that is pressed is filled.
 */
.wprk-gallery-filter__bar {
	display: flex;
	flex-wrap: wrap;
	gap: var(--wp--preset--spacing--20);
	margin-block-end: var(--wp--preset--spacing--40);
}

.wprk-gallery-filter__bar[hidden] {
	display: none;
}

.wprk-gallery-filter__btn {
	background: transparent;
	border: 1px solid var(--wprk-border);
	border-radius: var(--wp--custom--button--radius);
	color: var(--wprk-fg);
	cursor: pointer;
	font: inherit;
	font-size: var(--wp--preset--font-size--small);
	line-height: 1.4;
	min-height: 2.75rem;
	padding: 0.5em 1.1em;
	transition: background-color 0.18s ease, border-color 0.18s ease, color 0.18s ease;
}

.wprk-gallery-filter__btn:hover {
	border-color: color-mix(in srgb, var(--wprk-heading) 45%, transparent);
	color: var(--wprk-heading);
}

.wprk-gallery-filter__btn[aria-pressed="true"] {
	background-color: var(--wprk-btn-bg);
	border-color: var(--wprk-btn-bg);
	color: var(--wprk-btn-fg);
}

.wprk-gallery-filter__btn:focus-visible {
	outline: 2px solid var(--wprk-focus);
	outline-offset: 3px;
}

@media (prefers-reduced-motion: reduce) {
	.wprk-gallery-filter__btn {
		transition: none;
	}
}
