/* MAX Media Card + full-screen viewer */

.max-mc {
	--max-mc-media-w: 50%;
	--max-mc-gap: 32px;
	--max-mc-row-gap: max(var(--max-mc-gap), 40px);
	--max-mc-split: 300px;
	--max-mc-align: start;
	--max-mc-valign: start;
	--max-mc-clamp: 6;

	/* Flex rather than grid so the two columns can wrap: once neither can hold
	   --max-mc-split they drop onto separate rows, which a fixed two-column
	   grid template could never do. */
	display: flex;
	flex-wrap: wrap;
	/**
	 * Row gap is deliberately not the same as the column gap. A gap tuned to
	 * separate two columns reads as far too tight once the card stacks and a
	 * full-width image sits directly above the text, so the stacked gap has its
	 * own control and never falls below 40px.
	 */
	gap: var(--max-mc-row-gap) var(--max-mc-gap);
	align-items: var(--max-mc-valign);
	box-sizing: border-box;
}

.max-mc__media {
	flex: 1 1 var(--max-mc-media-w);
	min-width: min(100%, var(--max-mc-split));
	max-width: 100%;
}

.max-mc__body {
	flex: 1 1 calc(100% - var(--max-mc-media-w) - var(--max-mc-gap));
	min-width: min(100%, var(--max-mc-split));
	max-width: 100%;
}

/* Gallery on the right without reordering the markup: the title still comes
   first for screen readers and for the stacked layout. */
.max-mc--media-right .max-mc__media {
	order: 2;
}

.max-mc--media-right .max-mc__body {
	order: 1;
}

.max-mc__media {
	position: relative;
}

/* Nothing to show in the media column: let the text use the whole card. */
.max-mc--no-media .max-mc__body {
	flex-basis: 100%;
}

.max-mc__body {
	text-align: var(--max-mc-align);
	display: flex;
	flex-direction: column;
	align-items: var(--max-mc-align);
}

/* Opening from the image is handled on this wrapper, not by an overlay
   element — a covering button would block swiping on touch. */
.max-mc__media[data-mc-open-media] .max-gs__slide {
	cursor: zoom-in;
}

.max-mc__title {
	margin: 0 0 12px;
}

.max-mc__text {
	margin: 0;
}

.max-mc__text p {
	margin: 0;
}

/* Cut long copy off on the card; the viewer always shows all of it. */
.max-mc--clamped .max-mc__text p {
	display: -webkit-box;
	-webkit-box-orient: vertical;
	-webkit-line-clamp: var(--max-mc-clamp);
	line-clamp: var(--max-mc-clamp);
	overflow: hidden;
}

.max-mc__btn {
	display: inline-block;
	margin-top: 20px;
	border: 0;
	padding: 12px 24px;
	background: #e03a3c;
	color: #fff;
	font: inherit;
	cursor: pointer;
	transition: background 0.2s ease, color 0.2s ease;
}

.max-mc__btn:hover {
	background: #c62f31;
}

/* =====================================================
   Full-screen viewer
   ===================================================== */
.max-mv {
	position: fixed;
	inset: 0;
	z-index: 999998;
	background: var(--max-mv-bg, #0b1b34);
}

/* Per-instance look: these are written onto .max-mv__inner by the widget and
   copied up to the overlay on open, so the backdrop and close button match. */
.max-mv__inner {
	--max-mv-bg: #0b1b34;
	--max-mv-media-bg: transparent;
	--max-mv-panel-bg: #102a4c;
	--max-mv-panel-w: 400px;
	--max-mv-panel-pad: 72px 32px 40px;
	--max-mv-title: #ffffff;
	--max-mv-text: #c8d4e6;
	--max-mv-accent: #e03a3c;
	--max-mv-cta-color: #ffffff;
	--max-mv-close: #ffffff;
	--max-mv-close-bg: rgba(255, 255, 255, 0.14);
	--max-mv-align: start;
	--max-mv-valign: flex-start;
}

.max-mv[hidden] {
	display: none;
}

.max-mv__backdrop {
	position: absolute;
	inset: 0;
}

.max-mv__stage,
.max-mv__inner {
	position: relative;
	height: 100%;
}

.max-mv__inner {
	display: grid;
	grid-template-columns: minmax(0, 1fr) var(--max-mv-panel-w);
	height: 100vh;
	height: 100dvh;
}

/* Panel on the left: swap the track order rather than the markup, so the
   media still comes first for screen readers. */
.max-mv__inner--panel-left {
	grid-template-columns: var(--max-mv-panel-w) minmax(0, 1fr);
}

.max-mv__inner--panel-left .max-mv__media {
	order: 2;
}

.max-mv__inner--panel-left .max-mv__panel {
	order: 1;
}


/* ---- media side ---- */
.max-mv__media {
	display: flex;
	align-items: center;
	justify-content: center;
	min-width: 0;
	padding: 32px;
	box-sizing: border-box;
	background: var(--max-mv-media-bg, transparent);
}

.max-mv__media .max-gs {
	width: 100%;
	max-width: 100%;
}

/* the viewer shows whole images, never cropped */
.max-mv__media .max-gs__slide {
	background: transparent;
}

.max-mv__media .max-gs__slide img {
	aspect-ratio: auto;
	object-fit: contain;
	max-height: calc(100dvh - 160px);
	width: 100%;
}

.max-mv__media .max-gs__caption {
	color: var(--max-mv-text);
	text-align: center;
}

/* ---- panel side ---- */
.max-mv__panel {
	background: var(--max-mv-panel-bg);
	color: var(--max-mv-text);
	padding: var(--max-mv-panel-pad, 72px 32px 40px);
	overflow-y: auto;
	overscroll-behavior: contain;
	box-sizing: border-box;
	min-width: 0;
	text-align: var(--max-mv-align, start);
	display: flex;
	flex-direction: column;
	align-items: var(--max-mv-align, start);
	/**
	 * `safe` matters here. Centring (or bottom-aligning) a flex column that
	 * overflows pushes the first child ABOVE the container's start edge, and
	 * the scrollable region never extends upwards — so the top of a long story
	 * was cut off with no way to scroll back to it. `safe` drops the alignment
	 * back to start exactly when the content overflows, which is the only time
	 * the alignment could do that damage. Browsers without it fall back to
	 * flex-start, which is also safe.
	 */
	justify-content: safe var(--max-mv-valign, flex-start);
}

.max-mv__content,
.max-mv__title,
.max-mv__meta {
	width: 100%;
}

.max-mv__title {
	margin: 0 0 16px;
	color: var(--max-mv-title);
	font-size: 22px;
	line-height: 1.3;
}

.max-mv__meta {
	margin: 0 0 16px;
	font-size: 13px;
	opacity: 0.75;
}

.max-mv__content {
	font-size: 15px;
	line-height: 1.65;
}

.max-mv__content p {
	margin: 0 0 1em;
}

.max-mv__content p:last-child {
	margin-bottom: 0;
}

.max-mv__content a {
	color: var(--max-mv-accent);
}

.max-mv__content img {
	max-width: 100%;
	height: auto;
}

.max-mv__cta {
	display: inline-block;
	margin-top: 24px;
	padding: 14px 26px;
	background: var(--max-mv-accent);
	color: var(--max-mv-cta-color, #fff);
	text-decoration: none;
	font-weight: 700;
}

.max-mv__close {
	position: absolute;
	top: 18px;
	right: 18px;
	z-index: 3;
	display: flex;
	align-items: center;
	justify-content: center;
	width: 44px;
	height: 44px;
	padding: 0;
	border: 0;
	border-radius: 50%;
	background: var(--max-mv-close-bg, rgba(255, 255, 255, 0.14));
	color: var(--max-mv-close, #fff);
	cursor: pointer;
	transition: background 0.2s ease;
}

.max-mv__close:hover,
.max-mv__close:focus-visible {
	background: rgba(255, 255, 255, 0.28);
}

.max-mv__close svg {
	width: 20px;
	height: 20px;
}

/* ---- stacked viewer ---- */
@media (max-width: 900px) {
	.max-mv__inner {
		grid-template-columns: minmax(0, 1fr);
		grid-template-rows: auto minmax(0, 1fr);
		overflow-y: auto;
	}

	.max-mv__media {
		/* Same side inset as the panel below it, so the image lines up with the
		   text rather than sitting on a slightly different margin. */
		padding: 56px 20px 24px;
	}

	.max-mv__media .max-gs__slide img {
		max-height: 46dvh;
	}

	.max-mv__panel {
		padding: 28px 20px 40px;
		overflow: visible;
	}
}

@media (prefers-reduced-motion: reduce) {
	.max-mc__btn,
	.max-mv__close {
		transition: none;
	}
}

/* =====================================================
   Card grid (query mode)
   ===================================================== */
.max-mc-grid {
	--max-mcg-cols: 1;
	--max-mcg-min: 520px;
	--max-mcg-gap: 48px;

	display: grid;
	/* Cards Per Row is a ceiling: a column drops rather than squeezing a card
	   below its minimum, so a two-column card stays readable. */
	grid-template-columns: repeat(
		auto-fill,
		minmax(
			min(
				100%,
				max(
					var(--max-mcg-min),
					calc((100% - (var(--max-mcg-cols) - 1) * var(--max-mcg-gap)) / var(--max-mcg-cols))
				)
			),
			1fr
		)
	);
	gap: var(--max-mcg-gap);
}

.max-mc__empty {
	margin: 0;
	opacity: 0.7;
}
