.xtool-mb {
	display: inline-block;
}

.xtool-mb__trigger {
	position: relative;
	display: inline-flex;
	align-items: center;
	justify-content: center;
	gap: 8px;
	border: none;
	cursor: pointer;
	color: #fff;
	background-color: #1c1c1e;
	transition: background-color 0.2s ease, transform 0.2s ease;
	z-index: 1;
}

.xtool-mb__trigger:hover {
	transform: scale(1.03);
}

/* Icon-only: --xmb-size is the circle's own diameter. */
.xtool-mb__trigger--icon-only {
	width: var(--xmb-size, 72px);
	height: var(--xmb-size, 72px);
	border-radius: 50%;
}

/* Labeled: --xmb-size is the button's HEIGHT only — width follows the
   content via padding, so a Button Text label never gets squeezed into a
   fixed circle (see class-media-button.php's own control description). */
.xtool-mb__trigger--labeled {
	height: var(--xmb-size, 72px);
	padding: 0 24px;
	border-radius: 999px;
}

.xtool-mb__icon {
	display: inline-flex;
	font-size: 24px;
	line-height: 1;
}

.xtool-mb__icon svg,
.xtool-mb__icon i {
	width: 1em;
	height: 1em;
}

.xtool-mb__icon svg {
	fill: currentColor;
}

.xtool-mb__text {
	white-space: nowrap;
}

/* Pulse ring — a pseudo-element rather than a second real element so it
   never needs its own markup or interferes with the button's click target. */
.xtool-mb--pulse .xtool-mb__trigger::after {
	content: '';
	position: absolute;
	inset: 0;
	border-radius: inherit;
	background-color: inherit;
	animation: xtool-mb-pulse 2.2s ease-out infinite;
	z-index: -1;
}

@keyframes xtool-mb-pulse {
	0% {
		transform: scale(1);
		opacity: 0.55;
	}
	100% {
		transform: scale(1.7);
		opacity: 0;
	}
}

@media (prefers-reduced-motion: reduce) {
	.xtool-mb--pulse .xtool-mb__trigger::after {
		animation: none;
		display: none;
	}
}

/* ─── Lightbox ────────────────────────────────────────────────────────── */
.xtool-mb__lightbox {
	position: fixed;
	inset: 0;
	z-index: 999999;
	display: flex;
	align-items: center;
	justify-content: center;
	padding: 24px;
	box-sizing: border-box;
	opacity: 0;
	visibility: hidden;
	transition: opacity 0.25s ease, visibility 0.25s;
}

.xtool-mb__lightbox.is-open {
	opacity: 1;
	visibility: visible;
}

.xtool-mb__overlay {
	position: absolute;
	inset: 0;
	background-color: rgba(0, 0, 0, 0.9);
}

/*
 * Video mode reuses the exact JS-computed-pixel-dimensions technique already
 * proven on the Video Button widget (see media-button.js's own sizeStage())
 * rather than `fit-content` + `aspect-ratio` — a `fit-content` box has
 * nothing to size around against a `width:100%` iframe/video child (a
 * percentage that can't resolve until the parent's own size is already
 * known), a combination already confirmed to collapse to zero in this exact
 * codebase. Gallery mode has no such problem (see below), since a real
 * `<img>` with `object-fit:contain` needs no JS measurement at all.
 */
.xtool-mb__stage {
	position: relative;
	width: min(900px, 92vw);
	max-width: 900px;
	max-height: 86vh;
	background-color: #000;
	border-radius: 8px;
	overflow: hidden;
	/* Fallbacks here exactly match the original hardcoded shadow, so an
	   untouched widget's appearance is unchanged until "Show Shadow" /
	   Color / Blur / Vertical Offset are actually touched in the panel —
	   these 3 custom properties are written by the matching Style controls
	   in class-media-button.php (Group: Style — Stage). */
	box-shadow: 0 var(--xtool-mb-shadow-y, 20px) var(--xtool-mb-shadow-blur, 60px) var(--xtool-mb-shadow-color, rgba(0, 0, 0, 0.5));
	z-index: 1;
}

.xtool-mb__stage--16-9 {
	aspect-ratio: 16 / 9;
}

.xtool-mb__stage--4-3 {
	aspect-ratio: 4 / 3;
}

.xtool-mb__stage--1-1 {
	aspect-ratio: 1 / 1;
}

.xtool-mb__stage--21-9 {
	aspect-ratio: 21 / 9;
}

.xtool-mb__stage--video iframe,
.xtool-mb__stage--video video {
	display: block;
	width: 100%;
	height: 100%;
	border: 0;
}

/*
 * Gallery mode: object-fit:contain naturally letterboxes any image's real
 * aspect ratio inside a fixed box — no JS measurement needed, unlike video.
 *
 * The stage itself drops its own background/radius/overflow-hidden here —
 * those move onto `.xtool-mb__swiper` (the actual image box) instead, since
 * the stage is now a flex column holding BOTH the image AND a footer bar
 * below it (counter + thumbnails), and the arrow buttons need to sit in the
 * gap around the image's own edges without being clipped by the stage.
 */
.xtool-mb__stage--gallery {
	background: none;
	overflow: visible;
}

.xtool-mb__gallery {
	display: flex;
	flex-direction: column;
	align-items: center;
	width: 100%;
}

.xtool-mb__gallery-imagewrap {
	position: relative;
	width: 100%;
}

.xtool-mb__stage--gallery .xtool-mb__swiper {
	width: 100%;
	height: min(70vh, 700px);
	background-color: #000;
	border-radius: 8px;
	overflow: hidden;
}

.xtool-mb__stage--gallery .swiper-slide {
	display: flex;
	align-items: center;
	justify-content: center;
}

.xtool-mb__stage--gallery .swiper-slide img {
	width: 100%;
	height: 100%;
	object-fit: contain;
}

/* Arrows are children of .xtool-mb__gallery-imagewrap (overflow:visible),
   never of .xtool-mb__swiper (overflow:hidden) — see media-button.js's own
   comment on buildGallery() for why. A negative "Distance From Edge" Style
   control genuinely pushes them past the image's own edge as a result.
 *
 * These are real <button> elements (media-button.js's buildGallery()) —
 * subject to a theme's own generic button-reset CSS the exact same way
 * this widget's own Close button already turned out to be (see that
 * fix's own comment) — never swept with the same hardening when the
 * gallery arrows were first built. Reported live: arrow icons rendering
 * invisible/wrong-colored in the editor, root-caused via an isolated
 * test simulating a real theme reset (`button{background:red!important}`)
 * — confirmed this base rule's own `background-color` (and, by the same
 * mechanism, its `display:flex` centering) genuinely lose that fight with
 * no `!important` here at all. Hardened every layout-critical property
 * plus background/color across every interactive state (not just resting
 * — a theme's own :hover rule is exactly where this class of bug has
 * slipped through unnoticed before elsewhere in this codebase), plus
 * `-webkit-appearance:none; appearance:none;` for Safari's own native
 * button chrome. `gallery_arrow_size`/`_icon_size`/`_radius`'s own
 * selectors in class-media-button.php carry matching `!important` so the
 * user's own Style-tab choices can still win over this hardening. */
.xtool-mb__gallery-imagewrap .swiper-button-prev,
.xtool-mb__gallery-imagewrap .swiper-button-next {
	position: absolute !important;
	top: 50% !important;
	transform: translateY(-50%) !important;
	width: 40px !important;
	height: 40px !important;
	margin: 0 !important;
	padding: 0 !important;
	box-sizing: border-box !important;
	display: flex !important;
	align-items: center !important;
	justify-content: center !important;
	border: none !important;
	border-radius: 999px !important;
	background-color: rgba(0, 0, 0, 0.35) !important;
	color: #fff !important;
	outline: none !important;
	box-shadow: none !important;
	cursor: pointer !important;
	z-index: 2 !important;
	-webkit-appearance: none !important;
	appearance: none !important;
	transition: background-color 0.2s ease;
}

.xtool-mb__gallery-imagewrap .swiper-button-prev:hover,
.xtool-mb__gallery-imagewrap .swiper-button-next:hover {
	background-color: rgba(0, 0, 0, 0.6) !important;
	color: #fff !important;
	border: none !important;
	outline: none !important;
	box-shadow: none !important;
}

/* Focus/active/visited deliberately fall back to the RESTING background
   (not hover's darker one, which has its own dedicated Style control) —
   this only exists to stop a theme's own :focus/:active button-reset CSS
   from bleeding through, not to make these states look like hover. */
.xtool-mb__gallery-imagewrap .swiper-button-prev:focus,
.xtool-mb__gallery-imagewrap .swiper-button-next:focus,
.xtool-mb__gallery-imagewrap .swiper-button-prev:focus-visible,
.xtool-mb__gallery-imagewrap .swiper-button-next:focus-visible,
.xtool-mb__gallery-imagewrap .swiper-button-prev:active,
.xtool-mb__gallery-imagewrap .swiper-button-next:active,
.xtool-mb__gallery-imagewrap .swiper-button-prev:visited,
.xtool-mb__gallery-imagewrap .swiper-button-next:visited {
	background-color: rgba(0, 0, 0, 0.35) !important;
	color: #fff !important;
	border: none !important;
	outline: none !important;
	box-shadow: none !important;
}

.xtool-mb__gallery-imagewrap .swiper-button-prev {
	left: -50px;
}

.xtool-mb__gallery-imagewrap .swiper-button-next {
	right: -50px;
}

/* Kill Swiper's own default pseudo-icon chevron — our own real <svg> icon
   (built in media-button.js) would otherwise double up with it, the same
   fix already needed on every other Swiper-based Xtool widget. */
.xtool-mb__gallery-imagewrap .swiper-button-prev:after,
.xtool-mb__gallery-imagewrap .swiper-button-next:after {
	content: none;
}

.xtool-mb__gallery-imagewrap .swiper-button-prev svg,
.xtool-mb__gallery-imagewrap .swiper-button-next svg {
	display: block !important;
	width: 18px !important;
	height: 18px !important;
	fill: none !important;
	stroke: currentColor !important;
	flex-shrink: 0;
}

.xtool-mb__gallery-imagewrap .swiper-button-disabled {
	opacity: 0.35;
	cursor: default;
	pointer-events: none;
}

/* ─── Counter + thumbnail strip ──────────────────────────────────────────
 * Sits below the image as its own row, never inside the clipped swiper
 * box — object-fit:cover on each thumbnail plus a fixed square size keeps
 * the row a uniform height regardless of each photo's own real ratio. */
.xtool-mb__gallery-footer {
	display: flex;
	align-items: center;
	gap: 12px;
	width: 100%;
	margin-top: 12px;
}

.xtool-mb__gallery-counter {
	flex: 0 0 auto;
	color: rgba(255, 255, 255, 0.85);
	font-size: 13px;
	white-space: nowrap;
}

.xtool-mb__gallery-thumbs {
	flex: 1 1 auto;
	display: flex;
	justify-content: center;
	/* `safe center`: when there are more thumbnails than fit and the row
	   has to scroll, plain `center` can make the very first item start
	   partially out of scroll reach in some engines — `safe` keeps it
	   reachable, falling back to plain `center` (the line above) wherever
	   the keyword isn't supported. */
	justify-content: safe center;
	gap: 8px;
	overflow-x: auto;
	scrollbar-width: none;
	scroll-snap-type: x proximity;
}

.xtool-mb__gallery-thumbs::-webkit-scrollbar {
	display: none;
}

.xtool-mb__gallery-thumb {
	flex: 0 0 auto;
	width: 56px;
	height: 56px;
	padding: 0;
	border: 2px solid rgba(255, 255, 255, 0.25);
	border-radius: 6px;
	overflow: hidden;
	background: none;
	cursor: pointer;
	opacity: 0.6;
	scroll-snap-align: start;
	transition: opacity 0.2s ease, border-color 0.2s ease;
}

.xtool-mb__gallery-thumb:hover {
	opacity: 0.85;
}

.xtool-mb__gallery-thumb.is-active {
	opacity: 1;
	border-color: #fff;
}

.xtool-mb__gallery-thumb img {
	display: block;
	width: 100%;
	height: 100%;
	object-fit: cover;
}

@media (max-width: 767px) {
	.xtool-mb__stage--gallery .xtool-mb__swiper {
		height: min(56vh, 520px);
	}

	.xtool-mb__gallery-footer {
		gap: 8px;
	}
}

/*
 * A theme's own generic button/hover-reset CSS can silently bleed through
 * an unhardened plain <button> (this codebase's own recurring bug class —
 * already found and fixed on the Video widget's Lightbox close, Fullscreen
 * Menu's close, Popup's close, Cart Drawer's buttons) — reported live here
 * as a solid red/pink circle instead of the configured translucent-white
 * default. Every layout-critical property plus background/color/outline/
 * box-shadow is hardened with !important across every interactive state
 * (not just resting, since a theme's own :hover rule is exactly where this
 * has slipped through unnoticed before) — `close_icon_color`/`_bg_color`'s
 * own control selectors already carry matching !important (see
 * class-media-button.php), so the user's own Style-tab choice can still
 * win over this hardening.
 */
.xtool-mb__close {
	position: fixed !important;
	top: 20px !important;
	right: 24px !important;
	width: 40px !important;
	height: 40px !important;
	margin: 0 !important;
	padding: 0 !important;
	display: flex !important;
	align-items: center !important;
	justify-content: center !important;
	box-sizing: border-box !important;
	background: none !important;
	border: none !important;
	border-radius: 50% !important;
	box-shadow: none !important;
	outline: none !important;
	color: #fff !important;
	font-size: 22px !important;
	cursor: pointer !important;
	z-index: 2 !important;
	-webkit-appearance: none !important;
	appearance: none !important;
}

.xtool-mb__close:hover,
.xtool-mb__close:focus,
.xtool-mb__close:focus-visible,
.xtool-mb__close:active,
.xtool-mb__close:visited {
	background: none !important;
	border: none !important;
	box-shadow: none !important;
	outline: none !important;
	color: #fff !important;
}

.xtool-mb__close svg {
	display: block !important;
	width: 1em !important;
	height: 1em !important;
	fill: currentColor !important;
}
