/**
 * The fallback shell's structural CSS.
 *
 * ⚠ THIS IS NOT BRAND PAINT, and it is not optional. The plugin prints this
 * shell itself (`WPAUC_Frontend::shell()`), so the plugin owns what makes it a
 * shell: fixed position, a stacking context, an overlay, a scroll region.
 * Without it the markup is a plain `<div>` that lands wherever it happens to be
 * in the document — measured on the FAQ page at 20 203px down, 0px wide, and
 * therefore invisible even though the content had loaded correctly.
 *
 * Everything a site would want to restyle is a custom property, so a theme
 * overrides values rather than fighting selectors. Colour, radius, spacing and
 * typography inside the body are deliberately left alone — that is the theme's.
 */

.wpauc-modal {
	position: fixed;
	inset: 0;
	z-index: var( --wpauc-z, 100000 );
	display: none;
}

.wpauc-modal.is-open {
	display: block;
}

.wpauc-modal__overlay {
	position: absolute;
	inset: 0;
	display: flex;
	align-items: flex-start;
	justify-content: center;
	overflow-y: auto;
	overscroll-behavior: contain;
	padding: var( --wpauc-gutter, 5vh 1rem );
	background: var( --wpauc-overlay, rgba( 0, 0, 0, 0.7 ) );
}

.wpauc-modal__frame {
	position: relative;
	width: 100%;
	max-width: var( --wpauc-width, 860px );
	max-height: none;
	background: var( --wpauc-bg, #fff );
	box-shadow: var( --wpauc-shadow, 0 10px 40px rgba( 0, 0, 0, 0.35 ) );
}

.wpauc-modal__close {
	position: absolute;
	top: 0;
	right: 0;
	z-index: 1;
	width: 2.5rem;
	height: 2.5rem;
	padding: 0;
	border: 0;
	background: transparent;
	color: inherit;
	font-size: 1.75rem;
	line-height: 1;
	cursor: pointer;
}

.wpauc-modal__body {
	padding: var( --wpauc-padding, 2rem );
}

/* The injected content is a rendered post: its own first heading is the title,
   so it needs no margin fighting the frame's top edge. */
.wpauc-modal__body > :first-child {
	margin-top: 0;
}

.wpauc-modal__body > :last-child {
	margin-bottom: 0;
}

/* Scroll lock. Applied to <html> while a modal is open so the page behind does
   not scroll away under the overlay. */
.wpauc-modal-open {
	overflow: hidden;
}

@media ( prefers-reduced-motion: no-preference ) {
	.wpauc-modal.is-open .wpauc-modal__frame {
		animation: wpauc-modal-in 160ms ease-out;
	}

	@keyframes wpauc-modal-in {
		from {
			opacity: 0;
			transform: translateY( -0.5rem );
		}
	}
}

/* ── The waiting state ──────────────────────────────────────────────────────
 *
 * ⚠ THIS IS STRUCTURAL, not paint, which is why it lives here and not in the
 * theme. The shell opens BEFORE the content is fetched (see loader.js), so
 * there is a period — sometimes a long one, because the endpoint re-runs
 * WordPress against the target URL in process — where the frame is on screen
 * and empty. Something has to occupy it, or opening early just moves the
 * silence from the page to the modal.
 *
 * Keyed on `aria-busy`, so the state is announced to assistive technology and
 * drawn from the same attribute rather than a second class kept in step by
 * hand. Size and colour are custom properties like everything else here.
 */
.wpauc-modal__body[aria-busy="true"] {
	display: flex;
	align-items: center;
	justify-content: center;
	min-height: var( --wpauc-busy-height, 40vh );
}

.wpauc-modal__body[aria-busy="true"]::after {
	content: "";
	width: var( --wpauc-spinner-size, 2.5rem );
	height: var( --wpauc-spinner-size, 2.5rem );
	border: var( --wpauc-spinner-weight, 3px ) solid var( --wpauc-spinner-track, rgba( 0, 0, 0, 0.12 ) );
	border-top-color: var( --wpauc-spinner-color, currentColor );
	border-radius: 50%;
	animation: wpauc-spin 700ms linear infinite;
}

@keyframes wpauc-spin {
	to {
		transform: rotate( 360deg );
	}
}

/* ⚠ Still a visible indicator, not nothing. Reduced motion means no spin, not
   "leave the reader staring at an empty frame" — so the ring stays and simply
   pulses instead of rotating. */
@media ( prefers-reduced-motion: reduce ) {
	.wpauc-modal__body[aria-busy="true"]::after {
		animation: wpauc-pulse 1.2s ease-in-out infinite;
	}

	@keyframes wpauc-pulse {
		50% {
			opacity: 0.35;
		}
	}
}

/* ── The close button sits OUTSIDE the frame, and stays there ────────────────
 *
 * ⚠ TWO THINGS WERE WRONG, and only one of them showed standing still.
 *
 * 1. IT SAT INSIDE THE FRAME, overlapping the content's top-right corner. The
 *    site this replaces put it in the gutter ABOVE the panel, right-aligned to
 *    it — which is also why it never had to fight the content underneath.
 *
 * 2. IT SCROLLED AWAY. `position: absolute` pinned it to the FRAME, and the
 *    frame was what scrolled inside the overlay. Measured on a 3072px-tall
 *    detail: 900px down, the button was at -836px — gone, leaving the overlay
 *    click or the keyboard as the only way out.
 *
 * ⚠ AND STICKY CANNOT FIX BOTH, which is worth writing down because it is the
 * obvious first try. A sticky element is clamped to its CONTAINING BLOCK, and
 * for a child of the frame that is the frame — so `top: 0` pins it to the
 * frame's top edge, back inside, however far a negative margin tries to lift
 * it. Measured: 60px inside, exactly the margin that was supposed to take it
 * out.
 *
 * So the scroll moves instead. The frame is capped to the viewport and the
 * BODY scrolls inside it, which is what the old popup did too
 * (`popup-button.less`: `max-height: 80vh; overflow-y: auto` on the columns).
 * With the frame no longer scrolling, a plain absolute button above its
 * top-right corner is always where the reader left it.
 */
.wpauc-modal__overlay {
	/* No longer the scroller — the body is. Two scrollbars otherwise. */
	overflow: hidden;

	/* Room above the frame for the button that now lives there. */
	padding-top: calc(5vh + var(--wpauc-close-size, 2.5rem));
}

.wpauc-modal__frame {
	display: flex;
	flex-direction: column;
	max-height: 100%;
}

.wpauc-modal__body {
	overflow-y: auto;
	overscroll-behavior: contain;
}

.wpauc-modal__close {
	top: calc(-1 * var(--wpauc-close-size, 2.5rem));
	right: 0;
	width: var(--wpauc-close-size, 2.5rem);
	height: var(--wpauc-close-size, 2.5rem);
}
