/**
 * Flex Gallery — front end.
 *
 * One stylesheet serves every gallery on the page. Per-gallery settings arrive
 * as CSS custom properties set inline on the layout root, so nothing here is
 * generated per instance.
 *
 * Client-neutral on purpose: no font families are declared anywhere (captions
 * inherit the theme's type), and every colour is a --fxg-* custom property with
 * a neutral default, so a theme restyles a gallery by redefining tokens rather
 * than by fighting these selectors.
 */

.fxg-gallery,
.fxg-lightbox,
.fxg-panel {
	--fxg-surface: #fff;
	--fxg-border: #e5e5e5;
	--fxg-text: #1a1a1a;
	--fxg-muted: #666;
	--fxg-accent: currentColor;
	--fxg-radius: 4px;
	--fxg-overlay: linear-gradient( to top, rgba( 0, 0, 0, 0.72 ), rgba( 0, 0, 0, 0 ) );
	/*
	 * The lightbox is the same white sheet as the photo panel, not a dark
	 * theatre. To a visitor the two are one surface -- the panel opens into
	 * the lightbox and closes back to it -- so they share a palette.
	 *
	 * Named against the panel's tokens rather than copied from them: a theme
	 * that repaints the panel gets the lightbox with it, and a theme that
	 * wants them to differ still has a name of its own to set here.
	 */
	--fxg-lb-surface: var( --fxg-panel-surface );
	--fxg-lb-fg: var( --fxg-panel-fg );
	--fxg-lb-muted: var( --fxg-panel-muted );
	--fxg-lb-radius: var( --fxg-panel-radius );
	--fxg-lb-close-bg: var( --fxg-panel-close-bg );
	--fxg-lb-close-bg-hover: var( --fxg-panel-close-bg-hover );
	--fxg-lb-close-fg: var( --fxg-panel-close-fg );
	--fxg-lb-nav-bg: rgba( 0, 0, 0, 0.06 );
	--fxg-lb-nav-bg-hover: rgba( 0, 0, 0, 0.12 );
	--fxg-panel-surface: #fff;
	--fxg-panel-fg: #1a1a1a;
	--fxg-panel-muted: #666;
	--fxg-panel-max: 1200px;
	--fxg-panel-gap: 8px;
	--fxg-panel-radius: 12px;
	/*
	 * The shape every panel cell is cropped to. 4/3 rather than the tile's
	 * 3/2: a landscape photograph loses about a tenth of its width to it,
	 * which is not noticed, where 3/2 would take half the height off a
	 * portrait and cut the subject in two. A theme with a gallery of one
	 * orientation can set it to whatever suits.
	 */
	--fxg-panel-ratio: 4 / 3;
	--fxg-panel-close-bg: rgba( 0, 0, 0, 0.06 );
	--fxg-panel-close-bg-hover: rgba( 0, 0, 0, 0.12 );
	--fxg-panel-close-fg: inherit;
}

.fxg-gallery,
.fxg-gallery *,
.fxg-lightbox,
.fxg-lightbox *,
.fxg-panel,
.fxg-panel * {
	box-sizing: border-box;
}

/*
 * .fxg-panel is load-bearing in this list, not tidiness: the panel prints in
 * the footer outside any .fxg-gallery, so without it the close button's
 * label renders as visible text beside the glyph on any theme that does not
 * define the class itself.
 */
.fxg-gallery .screen-reader-text,
.fxg-lightbox .screen-reader-text,
.fxg-panel .screen-reader-text {
	position: absolute;
	width: 1px;
	height: 1px;
	margin: -1px;
	padding: 0;
	overflow: hidden;
	clip: rect( 0, 0, 0, 0 );
	white-space: nowrap;
	border: 0;
}

/* ==================================================================== Tile */

.fxg-item {
	position: relative;
	display: flex;
	flex-direction: column;
	min-width: 0;
	color: inherit;
	text-decoration: none;
}

a.fxg-item {
	transition: transform 0.18s ease, box-shadow 0.18s ease;
}

/*
 * Themes very commonly underline links inside editor content with a
 * border-bottom rather than text-decoration — the Hilltop Inn theme does
 * exactly this with `.entry-content a { border-bottom: 1px solid … }`. A tile
 * is an <a>, so it picks that rule up and draws a line under every image.
 *
 * Scoped through .fxg-gallery (0,2,1) so it outranks a (0,1,1) theme selector
 * even though a theme stylesheet normally loads after this one. box-shadow is
 * deliberately not reset here: the grid uses it for hover lift.
 */
.fxg-gallery a.fxg-item,
.fxg-gallery a.fxg-item:hover,
.fxg-gallery a.fxg-item:focus,
.fxg-gallery a.fxg-item:focus-visible {
	border: 0;
	text-decoration: none;
}

a.fxg-item:focus-visible {
	outline: 2px solid var( --fxg-accent );
	outline-offset: 3px;
}

.fxg-media {
	display: block;
	width: 100%;
	overflow: hidden;
}

/*
 * Natural proportions by default: no aspect-ratio and no object-fit, so the
 * full image is always visible and height:auto preserves its shape at whatever
 * width the column happens to be.
 */
.fxg-media img {
	display: block;
	width: 100%;
	height: auto;
	margin: 0;
	border-radius: 0;
}

/*
 * Cropping is opt-in per layout, driven by the Image shape setting. --fxg-ratio
 * only ever holds a value from the plugin's own allowlist.
 */
.fxg-crop .fxg-media {
	aspect-ratio: var( --fxg-ratio, 3 / 2 );
}

.fxg-crop .fxg-media img {
	height: 100%;
	object-fit: cover;
}

/* -------------------------------------------------------------- Captions */

.fxg-body {
	flex: 1 1 auto;
	padding: 14px 2px 0;
}

.fxg-title {
	margin: 0;
	padding: 0;
	font-size: 1.05em;
	line-height: 1.3;
	color: var( --fxg-text );
}

.fxg-caption {
	margin: 4px 0 0;
	padding: 0;
	/*
	 * Themes often cap bare prose paragraphs at a reading measure — 66ch is a
	 * common choice, and the Hilltop Inn theme sets exactly that on every p.
	 * A caption is not prose: it must track the width of its own image.
	 */
	max-width: none;
	font-size: 0.9em;
	line-height: 1.55;
	color: var( --fxg-muted );
}

/*
 * Overlaid captions sit on a gradient rather than a flat panel, so the bottom
 * of the photograph stays visible behind the text.
 */
.fxg-body--overlay {
	position: absolute;
	inset-inline: 0;
	bottom: 0;
	flex: 0 0 auto;
	padding: 32px 16px 14px;
	background: var( --fxg-overlay );
	color: #fff;
	pointer-events: none;
}

.fxg-body--overlay .fxg-title,
.fxg-body--overlay .fxg-caption {
	color: inherit;
	text-shadow: 0 1px 2px rgba( 0, 0, 0, 0.4 );
}

/* ==================================================================== Grid */

/*
 * Flexbox with a calculated flex-basis, NOT CSS Grid. With grid, making the
 * alignment setting visible requires justify-items, which sizes each tile to
 * its own content — so any image narrower than its column leaves a visibly
 * shrunken tile. Flexbox keeps every tile exactly one column wide, and
 * justify-content aligns only a partial final row, which is the case the
 * alignment setting actually needs to control. If you touch this, re-verify
 * with images narrower than the column, not just wide ones.
 */
.fxg-grid {
	display: flex;
	flex-wrap: wrap;
	gap: var( --fxg-gap, 24px );
	align-items: stretch;
}

.fxg-grid .fxg-item {
	flex: 0 0 calc( ( 100% - ( var( --fxg-cols-d, 3 ) - 1 ) * var( --fxg-gap, 24px ) ) / var( --fxg-cols-d, 3 ) );
	max-width: 100%;
	background: var( --fxg-surface );
	border-radius: var( --fxg-radius );
	overflow: hidden;
}

.fxg-grid a.fxg-item:hover,
.fxg-grid a.fxg-item:focus-visible {
	transform: translateY( -2px );
	box-shadow: 0 6px 18px rgba( 0, 0, 0, 0.1 );
}

.fxg-grid .fxg-body {
	padding: 16px 18px 18px;
}

/*
 * Alignment. A full row has no free space, so this shows up where it matters:
 * a final row holding fewer tiles than there are columns. It also sets the
 * direction of the caption text.
 */
.fxg-align-left {
	justify-content: flex-start;
	text-align: left;
}

.fxg-align-center {
	justify-content: center;
	text-align: center;
}

.fxg-align-right {
	justify-content: flex-end;
	text-align: right;
}

/* ================================================================= Masonry */

/*
 * CSS multi-column, so there is no measuring, no reflow as images load, and no
 * JavaScript. The trade-off is documented in the admin panel: content fills
 * each column top to bottom, so it reads down rather than across.
 */
.fxg-masonry {
	column-count: var( --fxg-cols-d, 3 );
	column-gap: var( --fxg-gap, 16px );
}

.fxg-masonry .fxg-item {
	/* A tile split across a column break would show half an image twice. */
	break-inside: avoid;
	page-break-inside: avoid;
	margin: 0 0 var( --fxg-gap, 16px );
	border-radius: var( --fxg-radius );
	overflow: hidden;
	background: var( --fxg-surface );
}

.fxg-masonry a.fxg-item:hover .fxg-media img,
.fxg-masonry a.fxg-item:focus-visible .fxg-media img {
	opacity: 0.88;
}

.fxg-masonry .fxg-media img {
	transition: opacity 0.18s ease;
}

.fxg-masonry .fxg-body {
	padding: 10px 2px 2px;
}

/* ================================================== Airbnb hero collage */

/*
 * The whole collage is one fixed-ratio block and the cells stretch to fill it,
 * which is what makes the hero and its neighbours line up exactly. Rounding is
 * applied to the container with overflow:hidden, so the outer corners round and
 * the inner ones stay square.
 *
 * The height is ratio-driven but capped. A collage is full-bleed width, so at
 * 1280px a 3/2 ratio alone wants 853px of height and pushes everything below it
 * off the screen. max-height clamps the used height without touching the width
 * — the rows are 1fr, so they simply share less space and the images crop a
 * little further — which is why this is a max-height and not a height: while
 * the container is narrow enough for the ratio to fit under the cap, the ratio
 * still wins and the collage stays proportional instead of becoming a sliver.
 *
 * width:100% is LOAD-BEARING and is not the no-op it looks like on a
 * block-level box. An aspect-ratio box whose inline size is *automatic* has
 * that ratio transferred back into the inline axis once the block axis is
 * constrained, so aspect-ratio + max-height alone made the grid resolve to
 * 480 x 1.5 = 720px wide inside an 1184px container and left a quarter of the
 * gallery empty. Stating the width makes the inline size definite, so nothing
 * is transferred: the box stays full width and only the height clamps.
 * Measured in Chrome across 400-1184px containers; do not "simplify" it away.
 */
.fxg-airbnb {
	position: relative;
	display: grid;
	width: 100%;
	gap: var( --fxg-gap, 8px );
	aspect-ratio: var( --fxg-ratio, 3 / 2 );
	max-height: var( --fxg-max-h, 480px );
	border-radius: var( --fxg-radius, 12px );
	overflow: hidden;
}

.fxg-airbnb .fxg-item {
	min-height: 0;
	overflow: hidden;
}

.fxg-airbnb .fxg-media {
	height: 100%;
}

.fxg-airbnb .fxg-media img {
	height: 100%;
	object-fit: cover;
	transition: opacity 0.18s ease;
}

.fxg-airbnb a.fxg-item:hover .fxg-media img,
.fxg-airbnb a.fxg-item:focus-visible .fxg-media img {
	opacity: 0.86;
}

.fxg-airbnb a.fxg-item:focus-visible {
	outline-offset: -3px;
}

/*
 * One template per cell count, so a short gallery still looks deliberate rather
 * than leaving holes in the grid. Only the hero is placed explicitly; the rest
 * flow into what is left, which fills row by row in exactly the wanted order.
 */
.fxg-airbnb--n1 {
	grid-template-columns: 1fr;
}

.fxg-airbnb--n2 {
	grid-template-columns: repeat( 2, 1fr );
}

.fxg-airbnb--n3 {
	grid-template-columns: repeat( 3, 1fr );
	grid-template-rows: repeat( 2, 1fr );
}

.fxg-airbnb--n3 .fxg-airbnb__cell--hero {
	grid-column: 1 / 3;
	grid-row: 1 / 3;
}

.fxg-airbnb--n4 {
	grid-template-columns: repeat( 3, 1fr );
	grid-template-rows: repeat( 3, 1fr );
}

.fxg-airbnb--n4 .fxg-airbnb__cell--hero {
	grid-column: 1 / 3;
	grid-row: 1 / 4;
}

.fxg-airbnb--n5 {
	grid-template-columns: repeat( 4, 1fr );
	grid-template-rows: repeat( 2, 1fr );
}

.fxg-airbnb--n5 .fxg-airbnb__cell--hero {
	grid-column: 1 / 3;
	grid-row: 1 / 3;
}

.fxg-airbnb__all {
	position: absolute;
	right: 16px;
	bottom: 16px;
	display: inline-flex;
	align-items: center;
	gap: 8px;
	margin: 0;
	padding: 9px 15px;
	font: inherit;
	font-size: 0.85rem;
	font-weight: 600;
	line-height: 1.2;
	color: var( --fxg-text );
	background: var( --fxg-surface );
	border: 1px solid rgba( 0, 0, 0, 0.6 );
	border-radius: 8px;
	box-shadow: 0 2px 8px rgba( 0, 0, 0, 0.18 );
	cursor: pointer;
	transition: transform 0.15s ease, box-shadow 0.15s ease;
}

.fxg-airbnb__all:hover {
	transform: scale( 1.02 );
	box-shadow: 0 3px 12px rgba( 0, 0, 0, 0.24 );
}

.fxg-airbnb__all:focus-visible {
	outline: 2px solid var( --fxg-accent );
	outline-offset: 2px;
}

/*
 * The four-square grid glyph, painted as four background gradients rather than
 * loaded as an icon font or an SVG. No extra request, no dependency on the
 * theme's icon set, and it inherits the button's colour.
 */
.fxg-airbnb__all-icon {
	display: block;
	flex: 0 0 auto;
	width: 13px;
	height: 13px;
	background-image:
		linear-gradient( currentColor, currentColor ),
		linear-gradient( currentColor, currentColor ),
		linear-gradient( currentColor, currentColor ),
		linear-gradient( currentColor, currentColor );
	background-size: 5px 5px;
	background-position: 0 0, 8px 0, 0 8px, 8px 8px;
	background-repeat: no-repeat;
}

/* ================================================================ Carousel */

.fxg-carousel {
	position: relative;
}

/*
 * Native scroll-snap. Swipe, momentum, trackpad gestures, and keyboard
 * scrolling are the browser's job; the script only adds the arrows and dots.
 */
.fxg-carousel__viewport {
	display: flex;
	gap: var( --fxg-gap, 16px );
	overflow-x: auto;
	overflow-y: hidden;
	scroll-snap-type: x mandatory;
	overscroll-behavior-x: contain;
	/* The controls are the affordance; a scrollbar under the images is noise. */
	scrollbar-width: none;
	-ms-overflow-style: none;
}

.fxg-carousel__viewport::-webkit-scrollbar {
	display: none;
}

.fxg-carousel__viewport:focus-visible {
	outline: 2px solid var( --fxg-accent );
	outline-offset: 3px;
}

.fxg-carousel__slide {
	flex: 0 0 calc( ( 100% - ( var( --fxg-pv-d, 3 ) - 1 ) * var( --fxg-gap, 16px ) ) / var( --fxg-pv-d, 3 ) );
	scroll-snap-align: start;
	border-radius: var( --fxg-radius );
	overflow: hidden;
	background: var( --fxg-surface );
}

/*
 * Edge bleed: shave a sliver off every slide so the next one shows past the
 * edge, which is what tells a visitor there is more to scroll to.
 */
.fxg-carousel--peek {
	--fxg-peek-amt: clamp( 12px, 5vw, 64px );
}

.fxg-carousel--peek .fxg-carousel__slide {
	flex-basis: calc( ( ( 100% - ( var( --fxg-pv-d, 3 ) - 1 ) * var( --fxg-gap, 16px ) ) / var( --fxg-pv-d, 3 ) ) - var( --fxg-peek-amt ) );
}

.fxg-carousel__controls {
	display: flex;
	align-items: center;
	justify-content: center;
	gap: 14px;
	margin-top: 18px;
}

.fxg-carousel__arrow {
	display: inline-flex;
	align-items: center;
	justify-content: center;
	width: 42px;
	height: 42px;
	padding: 0;
	font: inherit;
	color: var( --fxg-text );
	background: var( --fxg-surface );
	border: 1px solid var( --fxg-border );
	border-radius: 50%;
	cursor: pointer;
	transition: background-color 0.15s ease, border-color 0.15s ease;
}

.fxg-carousel__arrow:hover:not( :disabled ) {
	border-color: var( --fxg-text );
}

.fxg-carousel__arrow:focus-visible {
	outline: 2px solid var( --fxg-accent );
	outline-offset: 2px;
}

.fxg-carousel__arrow:disabled {
	opacity: 0.35;
	cursor: default;
}

.fxg-carousel__glyph {
	font-size: 18px;
	line-height: 1;
}

.fxg-carousel__dots {
	display: flex;
	align-items: center;
	gap: 8px;
}

.fxg-carousel__dot {
	width: 9px;
	height: 9px;
	padding: 0;
	background: var( --fxg-border );
	border: 0;
	border-radius: 50%;
	cursor: pointer;
	transition: background-color 0.15s ease, transform 0.15s ease;
}

.fxg-carousel__dot.is-active {
	background: var( --fxg-text );
	transform: scale( 1.25 );
}

.fxg-carousel__dot:focus-visible {
	outline: 2px solid var( --fxg-accent );
	outline-offset: 3px;
}

/* ================================================================ Lightbox */

.fxg-lightbox {
	width: 100%;
	max-width: 100%;
	height: 100%;
	max-height: 100%;
	margin: 0;
	padding: 0;
	color: var( --fxg-lb-fg );
	background: var( --fxg-lb-surface );
	border: 0;
	overflow: hidden;
}

/*
 * The same opaque surface as the dialog, sitting directly behind it, for the
 * same reason .fxg-panel::backdrop is: the sheet covers the viewport, so the
 * backdrop is only ever seen where the sheet is not.
 */
.fxg-lightbox::backdrop {
	background: var( --fxg-lb-surface );
}

/*
 * Laid out as the panel's bar is, and deliberately so: closing the lightbox
 * frequently lands back on the panel, and a close control that moves between
 * the two reads as two different screens rather than one.
 *
 * So the close is taken out of flow at the same offset the panel uses, which
 * leaves the count centred on the bar itself rather than on whatever space is
 * left beside a button. The side padding is that button's reach.
 */
.fxg-lightbox__bar {
	position: absolute;
	inset-inline: 0;
	top: 0;
	z-index: 2;
	display: flex;
	align-items: center;
	justify-content: center;
	/*
	 * min-height, because the close is out of flow and so contributes nothing
	 * to it: the bar would size to the count alone, at 36px, and the dialog's
	 * overflow: hidden would shave the top off a 40px circle. Measured, not
	 * assumed -- the clipping is 2px and reads as a flat edge, not as a bug.
	 */
	min-height: 60px;
	padding: 10px 64px;
}

.fxg-lightbox__count {
	color: var( --fxg-lb-muted );
	font-size: 0.85rem;
	letter-spacing: 0.04em;
}

/*
 * Scoped through .fxg-lightbox (0,2,0) rather than written bare, and stating
 * every property a theme might hold an opinion about. These are <button>s
 * printed in the footer, where the plugin's usual .fxg-gallery scoping does
 * not reach them, and this stylesheet's position relative to the theme's is
 * not fixed -- see the note beside .fxg-panel__close.
 */
.fxg-lightbox .fxg-lightbox__close,
.fxg-lightbox .fxg-lightbox__nav {
	display: inline-flex;
	align-items: center;
	justify-content: center;
	margin: 0;
	padding: 0;
	font: inherit;
	border: 0;
	border-radius: 50%;
	cursor: pointer;
	transition: background-color 0.15s ease;
}

/* Same 40px circle at the same left: 16px the panel's close uses. */
.fxg-lightbox .fxg-lightbox__close {
	position: absolute;
	left: 16px;
	top: 50%;
	width: 40px;
	height: 40px;
	color: var( --fxg-lb-close-fg );
	background: var( --fxg-lb-close-bg );
	transform: translateY( -50% );
}

.fxg-lightbox .fxg-lightbox__close:hover {
	background: var( --fxg-lb-close-bg-hover );
}

/* The arrows stay the quieter pair: they are used repeatedly, the close once. */
.fxg-lightbox .fxg-lightbox__nav {
	width: 44px;
	height: 44px;
	color: inherit;
	background: var( --fxg-lb-nav-bg );
}

.fxg-lightbox .fxg-lightbox__nav:hover {
	background: var( --fxg-lb-nav-bg-hover );
}

.fxg-lightbox__close:focus-visible,
.fxg-lightbox__nav:focus-visible {
	outline: 2px solid var( --fxg-accent );
	outline-offset: 2px;
}

.fxg-lightbox__glyph {
	font-size: 22px;
	line-height: 1;
}

.fxg-lightbox__nav {
	position: absolute;
	top: 50%;
	z-index: 2;
	transform: translateY( -50% );
}

.fxg-lightbox__nav--prev {
	left: 16px;
}

.fxg-lightbox__nav--next {
	right: 16px;
}

.fxg-lightbox__figure {
	display: flex;
	flex-direction: column;
	align-items: center;
	justify-content: center;
	gap: 14px;
	width: 100%;
	height: 100%;
	margin: 0;
	/* Room for the bar above and the caption below, and clear of the arrows. */
	padding: 68px 76px 40px;
}

/*
 * Rounded to the panel's plate radius, not the tile's card radius. An image
 * arrives here from a panel cell that was already rounded, so a square-cornered
 * one would be a visible change of shape on the way in.
 *
 * It rounds the photograph and not an empty box around it because lbShow()
 * stamps the item's own aspect-ratio on the element before the file arrives,
 * so object-fit: contain has nothing left to letterbox. If that reservation
 * is ever dropped, this needs a wrapper to clip against instead.
 */
.fxg-lightbox__image {
	max-width: 100%;
	max-height: 100%;
	min-height: 0;
	object-fit: contain;
	border-radius: var( --fxg-lb-radius );
}

/* The dialog is in the DOM before an image is chosen, and again after close. */
.fxg-lightbox__image[hidden] {
	display: none;
}

.fxg-lightbox__caption {
	max-width: 62ch;
	text-align: center;
	font-size: 0.9rem;
	line-height: 1.5;
}

.fxg-lightbox__caption[hidden] {
	display: none;
}

.fxg-lightbox__title {
	display: block;
	margin-bottom: 2px;
}

.fxg-lightbox__text {
	display: block;
	color: var( --fxg-lb-muted );
}

/* ============================================================= Photo panel */

/*
 * A second modal <dialog>, printed beside the lightbox in the footer. Being
 * outside .entry-content is what keeps a theme's editor-content rules off it,
 * for the same reason the lightbox lives there.
 *
 * position and inset are stated rather than left to the UA's
 * `dialog:modal { position: fixed }`. :modal stops matching the instant
 * close() runs, so through the exit transition below the whole sheet would
 * otherwise drop to its static position down in the footer on any engine that
 * does not support `overlay`.
 *
 * 100%, not 100vw/100dvh. The box is fixed, so percentages already resolve
 * against the viewport, and a fixed box is sized to the viewport actually
 * visible -- which is what dvh would have been asked for. 100vw would
 * additionally include the scrollbar width and overflow the window.
 */
.fxg-panel {
	position: fixed;
	inset: 0;
	width: 100%;
	max-width: 100%;
	height: 100%;
	max-height: 100%;
	margin: 0;
	padding: 0;
	color: var( --fxg-panel-fg );
	background: var( --fxg-panel-surface );
	border: 0;
	overflow: hidden;
	display: flex;
	flex-direction: column;
}

/*
 * The UA sheet already hides a closed dialog. This is what a browser with no
 * <dialog> support needs, where [open] is never set and the sheet would
 * otherwise render inline in the footer as a wall of images.
 */
.fxg-panel:not( [open] ) {
	display: none;
}

/*
 * A flex sibling of the scroller rather than position: sticky. A flex header
 * cannot desync from the thing it sits above.
 *
 * The close control is taken out of flow so the heading centres on the bar
 * itself, rather than on whatever space is left beside a 40px button. The
 * side padding is that button's reach, so a long gallery name wraps instead
 * of running underneath it.
 */
.fxg-panel__bar {
	position: relative;
	flex: 0 0 auto;
	display: flex;
	align-items: center;
	justify-content: center;
	gap: 12px;
	padding: 10px 64px;
	border-bottom: 1px solid var( --fxg-border );
}

/*
 * Every property a theme might hold an opinion about is stated. A bare
 * <button> inherits whatever the host theme says buttons look like, and this
 * one sits in the footer where the plugin's usual .fxg-gallery scoping does
 * not reach it. See CLAUDE.md on assuming the theme has an opinion.
 */
/*
 * Filled rather than bare: this is the only way out of a surface that covers
 * the whole viewport, so it should read as a control at a glance. The colour
 * is a token with a neutral default -- a host theme paints it by redefining
 * --fxg-panel-close-* on .fxg-panel, not by overriding this rule.
 */
.fxg-panel .fxg-panel__close {
	position: absolute;
	left: 16px;
	top: 50%;
	display: inline-flex;
	align-items: center;
	justify-content: center;
	width: 40px;
	height: 40px;
	margin: 0;
	padding: 0;
	font: inherit;
	color: var( --fxg-panel-close-fg );
	background: var( --fxg-panel-close-bg );
	border: 0;
	border-radius: 50%;
	transform: translateY( -50% );
	cursor: pointer;
	transition: background-color 0.15s ease;
}

.fxg-panel .fxg-panel__close:hover {
	background: var( --fxg-panel-close-bg-hover );
}

.fxg-panel .fxg-panel__close:focus-visible {
	outline: 2px solid var( --fxg-accent );
	outline-offset: 2px;
}

.fxg-panel__glyph {
	font-size: 20px;
	line-height: 1;
}

/* max-width: none defends the reading measure a theme puts on every p. */
.fxg-panel__heading {
	display: flex;
	align-items: baseline;
	justify-content: center;
	flex-wrap: wrap;
	gap: 10px;
	max-width: none;
	margin: 0;
	font-size: 0.95rem;
	text-align: center;
}

.fxg-panel__title {
	display: block;
	font-weight: 600;
}

/* Stated display beats the hidden attribute, so give it back. */
.fxg-panel__title[hidden] {
	display: none;
}

.fxg-panel__count {
	color: var( --fxg-panel-muted );
	font-size: 0.85rem;
}

/*
 * min-height: 0 is required, not tidying: without it the flex item refuses to
 * shrink below its content and the scroller never appears at all.
 */
.fxg-panel__scroll {
	flex: 1 1 auto;
	min-height: 0;
	overflow-y: auto;
	overscroll-behavior: contain;
}

.fxg-panel__grid {
	display: grid;
	grid-template-columns: repeat( 2, 1fr );
	gap: var( --fxg-panel-gap );
	max-width: var( --fxg-panel-max );
	margin-inline: auto;
	padding: 16px 16px 64px;
}

/*
 * Scoped through .fxg-panel (0,2,0) rather than written bare (0,1,0). The
 * plugin stylesheet is enqueued before the theme's, so a specificity tie
 * loses -- and a theme with an .entry-content button rule would be exactly
 * such a tie. Same reasoning as the tile reset near the top of this file.
 */
.fxg-panel .fxg-panel__cell {
	display: block;
	width: 100%;
	margin: 0;
	padding: 0;
	font: inherit;
	color: inherit;
	background: none;
	border: 0;
	/* Its own token, not the shared --fxg-radius: these are large photo
	   plates, where a tile in a grid is a 4px card. */
	border-radius: var( --fxg-panel-radius );
	overflow: hidden;
	cursor: pointer;
	/*
	 * Every cell is the same shape, whatever the photograph inside it is.
	 * Sizing each to its own orientation instead -- landscape full width,
	 * portrait two-across -- is what this used to do, and scrolling it meant
	 * the column edge stepping in and out as the shapes alternated, which
	 * reads as a layout fault rather than as a mosaic.
	 *
	 * A fixed ratio also means the grid needs no per-image measurement and
	 * no reflow once the files decode: the rows are the right height before
	 * the first byte arrives. The cropping is object-fit: cover below.
	 */
	aspect-ratio: var( --fxg-panel-ratio );
}

.fxg-panel__cell img {
	display: block;
	width: 100%;
	height: 100%;
	margin: 0;
	object-fit: cover;
	transition: opacity 0.18s ease;
}

.fxg-panel .fxg-panel__cell:hover img {
	opacity: 0.88;
}

.fxg-panel .fxg-panel__cell:focus-visible {
	outline: 2px solid var( --fxg-accent );
	outline-offset: -3px;
}

/*
 * Opening and closing.
 *
 * Entry runs off @starting-style alone: showModal() renders the element for
 * the first time, so there is no previous style for a transition to start
 * from and this supplies one.
 *
 * display and overlay are not what makes the entry work -- they are what
 * makes the exit work. Both are discrete, and allow-discrete defers their
 * flip to the end of the transition rather than applying it at once: display
 * keeps the sheet rendered while it fades, overlay keeps it in the top layer
 * while it does.
 *
 * Where overlay is not supported the element leaves the top layer at once and
 * the exit reads as instant, which is acceptable -- and is exactly why
 * position and inset are stated above, so a sheet that has stopped matching
 * :modal does not also stop being fixed on its way out.
 *
 * The close event is queued at close() rather than at transition end, so
 * nothing here can delay the scroll lock or focus restoration.
 */
.fxg-panel {
	opacity: 1;
	transform: translateY( 0 );
	transition:
		opacity 0.24s ease,
		transform 0.24s ease;
}

/*
 * The exit is driven from the script, which holds the dialog open for the
 * length of this transition and closes it afterwards -- see panelClose().
 * So no display/overlay allow-discrete here: `overlay` is Chromium-only, and
 * deferring `display` would leave an invisible fixed, full-viewport element
 * swallowing clicks for a quarter-second after the panel had gone.
 */
.fxg-panel.is-closing {
	opacity: 0;
	transform: translateY( 20px );
}

.fxg-panel:not( [open] ) {
	opacity: 0;
	transform: translateY( 20px );
}

@starting-style {
	.fxg-panel[open] {
		opacity: 0;
		transform: translateY( 20px );
	}
}

/*
 * ::backdrop needs its own rule: inheriting from the originating element is a
 * recent change and not carried by every engine. Invisible in practice behind
 * an opaque sheet, and there for the moment one is not.
 */
/*
 * The backdrop is the same opaque surface as the panel, sitting directly
 * behind it. It has to fade out with the panel, not just in with it: left at
 * full opacity it simply replaces the sheet the panel was, and the exit reads
 * as an instant cut rather than a fade. That was a real bug, seen on staging.
 */
.fxg-panel::backdrop {
	background: var( --fxg-panel-surface );
	opacity: 1;
	transition: opacity 0.24s ease;
}

.fxg-panel.is-closing::backdrop {
	opacity: 0;
}

@starting-style {
	.fxg-panel[open]::backdrop {
		opacity: 0;
	}
}

/* ============================================================= Breakpoints */

/* Matches the reflow points the settings descriptions promise. */
@media all and ( max-width: 980px ) {
	.fxg-grid .fxg-item {
		flex-basis: calc( ( 100% - ( var( --fxg-cols-t, 2 ) - 1 ) * var( --fxg-gap, 24px ) ) / var( --fxg-cols-t, 2 ) );
	}

	.fxg-masonry {
		column-count: var( --fxg-cols-t, 2 );
	}

	.fxg-carousel__slide {
		flex-basis: calc( ( 100% - ( var( --fxg-pv-t, 2 ) - 1 ) * var( --fxg-gap, 16px ) ) / var( --fxg-pv-t, 2 ) );
	}

	.fxg-carousel--peek .fxg-carousel__slide {
		flex-basis: calc( ( ( 100% - ( var( --fxg-pv-t, 2 ) - 1 ) * var( --fxg-gap, 16px ) ) / var( --fxg-pv-t, 2 ) ) - var( --fxg-peek-amt ) );
	}
}

@media all and ( max-width: 760px ) {
	.fxg-grid .fxg-item {
		flex-basis: calc( ( 100% - ( var( --fxg-cols-m, 1 ) - 1 ) * var( --fxg-gap, 24px ) ) / var( --fxg-cols-m, 1 ) );
	}

	.fxg-masonry {
		column-count: var( --fxg-cols-m, 1 );
	}

	.fxg-carousel__slide {
		flex-basis: calc( ( 100% - ( var( --fxg-pv-m, 1 ) - 1 ) * var( --fxg-gap, 16px ) ) / var( --fxg-pv-m, 1 ) );
	}

	.fxg-carousel--peek .fxg-carousel__slide {
		flex-basis: calc( ( ( 100% - ( var( --fxg-pv-m, 1 ) - 1 ) * var( --fxg-gap, 16px ) ) / var( --fxg-pv-m, 1 ) ) - var( --fxg-peek-amt ) );
	}

	/*
	 * The collage narrows to the hero alone. Four thumbnails at phone width are
	 * too small to read, and the button reaches the rest anyway.
	 */
	.fxg-airbnb {
		grid-template-columns: 1fr;
		grid-template-rows: 1fr;
	}

	.fxg-airbnb .fxg-airbnb__cell:not( .fxg-airbnb__cell--hero ) {
		display: none;
	}

	.fxg-airbnb .fxg-airbnb__cell--hero {
		grid-column: 1 / -1;
		grid-row: 1 / -1;
	}

	/*
	 * One column. Two would put a room photograph in about 180px on a phone,
	 * which is a thumbnail rather than a plate. The cell keeps its ratio, so
	 * the only thing that changes is how many fit across.
	 */
	.fxg-panel__grid {
		grid-template-columns: 1fr;
		padding: 12px 12px 48px;
	}

	/* Tighter, but still clear of the close control on its left. */
	.fxg-panel__bar,
	.fxg-lightbox__bar {
		padding: 10px 56px;
	}

	/* Still clear of the bar, which keeps its 60px for the close button. */
	.fxg-lightbox__figure {
		padding: 72px 16px 32px;
	}

	.fxg-lightbox__nav {
		top: auto;
		bottom: 16px;
		transform: none;
	}
}

/* ========================================================= Reduced motion */

/*
 * The three dialog controls are listed scoped through their own dialog, not
 * bare. Each takes its transition from a rule written that way, so a bare
 * selector here ties on specificity, loses on order, and reduced motion is
 * quietly ignored.
 */
@media ( prefers-reduced-motion: reduce ) {
	a.fxg-item,
	.fxg-airbnb__all,
	.fxg-carousel__arrow,
	.fxg-carousel__dot,
	.fxg-masonry .fxg-media img,
	.fxg-airbnb .fxg-media img,
	.fxg-lightbox .fxg-lightbox__close,
	.fxg-lightbox .fxg-lightbox__nav,
	.fxg-panel,
	.fxg-panel::backdrop,
	.fxg-panel .fxg-panel__close,
	.fxg-panel__cell img {
		transition: none;
	}

	/* transition: none kills allow-discrete too, so this shows and hides
	   instantly rather than not at all. */
	.fxg-panel:not( [open] ),
	.fxg-panel.is-closing {
		transform: none;
	}

	.fxg-grid a.fxg-item:hover,
	.fxg-grid a.fxg-item:focus-visible,
	.fxg-airbnb__all:hover {
		transform: none;
	}

	.fxg-carousel__dot.is-active {
		transform: none;
	}
}
