/**
 * Artwork gallery styles (Standard, masonry, carousel, fullscreen background)
 *
 * - Standard gallery: clean 4-column grid (1 col mobile, 2 col tablet, 4 col desktop).
 * - Masonry: CSS columns, natural aspect ratios.
 * - Captions hidden in the grid, shown in the lightbox via JS.
 */

/* Shared gap token for all artwork galleries. */
.wp-block-gallery.has-nested-images {
	--jofei-gallery-gap: var(--wp--style--unstable-gallery-gap,
			var(--wp--preset--spacing--40, 1.5rem));
}

/* ------------------------------------------------------------------
 * Masonry layout
 * ------------------------------------------------------------------ */
.wp-block-gallery.is-style-artwork-masonry.has-nested-images {
	box-sizing: border-box;
	column-count: 1;
	column-gap: var(--jofei-gallery-gap);
	display: block;
	margin: 0;
	max-width: 100%;
	overflow-x: clip;
	padding: 0;
}

.wp-block-gallery.is-style-artwork-masonry.has-nested-images.columns-1 {
	column-count: 1;
}

@media (min-width: 480px) {

	.wp-block-gallery.is-style-artwork-masonry.has-nested-images.columns-2,
	.wp-block-gallery.is-style-artwork-masonry.has-nested-images.columns-default,
	.wp-block-gallery.is-style-artwork-masonry.has-nested-images.columns-3,
	.wp-block-gallery.is-style-artwork-masonry.has-nested-images.columns-4 {
		column-count: 2;
	}
}

@media (min-width: 782px) {
	.wp-block-gallery.is-style-artwork-masonry.has-nested-images.columns-3 {
		column-count: 3;
	}

	.wp-block-gallery.is-style-artwork-masonry.has-nested-images.columns-4 {
		column-count: 4;
	}
}

.wp-block-gallery.is-style-artwork-masonry.has-nested-images figure.wp-block-image:not(#individual-image) {
	break-inside: avoid;
	display: block;
	margin: 0 0 var(--jofei-gallery-gap);
	width: 100% !important;
}

.wp-block-gallery.is-style-artwork-masonry.has-nested-images figure.wp-block-image img {
	display: block;
	height: auto;
	width: 100%;
}

/* Editor: core forces display:block on the figure; match column layout in the canvas. */
.editor-styles-wrapper .wp-block-gallery.is-style-artwork-masonry.has-nested-images,
.block-editor-block-list__layout .wp-block-gallery.is-style-artwork-masonry.has-nested-images {
	column-gap: var(--jofei-gallery-gap);
	display: block;
}

/* ------------------------------------------------------------------
 * Standard gallery: enforce the responsive 4-column breakpoints.
 * Core supplies the base flex layout; these rules make sure a columns-4
 * gallery degrades cleanly on smaller screens and keeps consistent gaps.
 * ------------------------------------------------------------------ */
@media (max-width: 479px) {

	.wp-block-gallery.has-nested-images.columns-4 figure.wp-block-image:not(#individual-image),
	.editor-styles-wrapper .wp-block-gallery.has-nested-images.columns-4 figure.wp-block-image:not(#individual-image),
	.block-editor-block-list__layout .wp-block-gallery.has-nested-images.columns-4 figure.wp-block-image:not(#individual-image) {
		width: 100% !important;
	}
}

@media (min-width: 480px) and (max-width: 781px) {

	.wp-block-gallery.has-nested-images.columns-4 figure.wp-block-image:not(#individual-image),
	.editor-styles-wrapper .wp-block-gallery.has-nested-images.columns-4 figure.wp-block-image:not(#individual-image),
	.block-editor-block-list__layout .wp-block-gallery.has-nested-images.columns-4 figure.wp-block-image:not(#individual-image) {
		width: calc(50% - var(--jofei-gallery-gap) / 2) !important;
	}
}

@media (min-width: 782px) {

	.wp-block-gallery.has-nested-images.columns-4 figure.wp-block-image:not(#individual-image),
	.editor-styles-wrapper .wp-block-gallery.has-nested-images.columns-4 figure.wp-block-image:not(#individual-image),
	.block-editor-block-list__layout .wp-block-gallery.has-nested-images.columns-4 figure.wp-block-image:not(#individual-image) {
		width: calc(25% - var(--jofei-gallery-gap) * 3 / 4) !important;
	}
}

/* Auto border-radius on every gallery image — applies to Standard,
 * masonry, carousel, fullscreen background, and any other gallery style.
 * Lightbox images render outside .wp-block-gallery, so they're unaffected. */
.wp-block-gallery img {
	border-radius: 7px;
}

/* Custom Lightbox Zoom Cursors */
.wp-lightbox-container img {
	cursor: url('../../images/icons/zoom-in-3.svg') 15 15, zoom-in;
}

.wp-lightbox-overlay img,
.wp-lightbox-overlay {
	cursor: url('../../images/icons/zoom-out-3.svg') 15 15, zoom-out;
}

/* Lightbox image: 8px rounded corners (always, regardless of gallery style). */
.wp-lightbox-overlay img {
	border-radius: 8px;
}

.wp-lightbox-container button:focus {
	opacity: 0;
}

.wp-lightbox-container img:hover+button {
	background-image: url('../../images/icons/zoom-in-2.svg') !important;
	background-size: 20px 20px !important;
	background-repeat: no-repeat !important;
	background-position: center !important;
	opacity: 1;
}

.wp-lightbox-container img:hover+button svg {
	opacity: 0;
}


.wp-lightbox-overlay .wp-lightbox-close-button {
	background-image: url('../../images/icons/close.svg') !important;
	background-size: 32px 32px !important;
	background-repeat: no-repeat !important;
	background-position: center !important;
}

.wp-lightbox-overlay .wp-lightbox-close-button svg {
	opacity: 0;
}

.wp-lightbox-overlay:hover .wp-lightbox-close-button:hover {
	cursor: url('../../images/icons/close.svg') 32 32, default;
	background-size: 0px 0px !important;
}

.wp-lightbox-overlay .wp-lightbox-navigation-button-prev {
	background-image: url('../../images/icons/arrow-back.svg') !important;
	background-size: 32px 40px !important;
	background-repeat: no-repeat !important;
	background-position: center !important;
}

.wp-lightbox-overlay .wp-lightbox-navigation-button-prev svg {
	opacity: 0;
}

.wp-lightbox-overlay:hover .wp-lightbox-navigation-button-prev:hover {
	cursor: url('../../images/icons/arrow-back.svg') 32 40, default;
	background-size: 0px 0px !important;
}

.wp-lightbox-overlay .wp-lightbox-navigation-button-next {
	background-image: url('../../images/icons/arrow-forward.svg') !important;
	background-size: 32px 40px !important;
	background-repeat: no-repeat !important;
	background-position: center !important;
}

.wp-lightbox-overlay .wp-lightbox-navigation-button-next svg {
	opacity: 0;
}

.wp-lightbox-overlay:hover .wp-lightbox-navigation-button-next:hover {
	cursor: url('../../images/icons/arrow-forward.svg') 32 40, default;
	background-size: 0px 0px !important;
}

/* Captions: hidden in the grid for all gallery styles, shown in lightbox via JS */
.wp-block-gallery.has-nested-images figure.wp-block-image figcaption {
	display: none;
}

/* Remove core's gradient overlay on images that have captions */
.wp-block-gallery.has-nested-images figure.wp-block-image:has(figcaption):before {
	display: none;
}

/* Mobile / default: caption at bottom of screen, centered between prev/next arrows.
 * White text on a semi-transparent dark backdrop for visibility on the dark overlay.
 * Respects iOS safe-area inset at the bottom. */
.wp-lightbox-overlay .jofei-lightbox-caption {
	box-sizing: border-box;
	color: #fff;
	background-color: rgba(0, 0, 0, 0.55);
	font-size: var(--wp--preset--font-size--small, 0.875rem);
	line-height: 1.5;
	padding: var(--wp--preset--spacing--30, 1rem) var(--wp--preset--spacing--40, 1.5rem);
	padding-bottom: calc(var(--wp--preset--spacing--30, 1rem) + env(safe-area-inset-bottom, 0px));
	text-align: center;
	width: calc(100vw - 6rem); /* 3rem inset each side leaves room for prev/next arrows */
	max-width: 32rem;
	margin: 0;
	position: fixed;
	bottom: 0;
	left: 50%;
	transform: translateX(-50%);
	border-radius: 7px 7px 0 0;
	z-index: 3000001;
}

.wp-lightbox-overlay .jofei-lightbox-caption[hidden] {
	display: none;
}

/* Desktop: side-by-side — caption beside the image.
 * Image cap adapts to viewport so the caption always has room (max 16rem):
 *   - When 80vw fits: image = 80vw, caption gets up to 16rem.
 *   - When 80vw would squeeze the caption: image shrinks to 100vw - 20rem
 *     (leaving at least ~14rem for the caption on the right).
 * Works for portrait images too: their natural width is below the cap,
 * so the layout just naturally leaves more space on the right. */
@media (min-width: 782px) {
	.wp-lightbox-overlay {
		--jofei-lightbox-effective-width: min(
			var(--wp--lightbox-container-width, 320px),
			80vw,
			calc(100vw - 20rem)
		);
	}

	.wp-lightbox-overlay img {
		max-width: min(80vw, calc(100vw - 20rem));
	}

	.wp-lightbox-overlay .jofei-lightbox-caption {
		font-size: var(--wp--preset--font-size--medium, 1rem);
		position: fixed;
		top: 50%;
		bottom: auto;
		left: calc(50% + (var(--jofei-lightbox-effective-width) / 2) + 1.5rem);
		right: 1.5rem;
		transform: translateY(-50%);
		width: auto;
		max-width: 16rem;
		max-height: min(var(--wp--lightbox-container-height, 60vh), calc(100vh - 6rem));
		overflow-y: auto;
		padding: 0;
		padding-right: env(safe-area-inset-right, 0px);
		text-align: left;
		background-color: transparent;
		border-radius: 0;
	}
}

