/*
 * Server-rendered speakers grid — layout only, theme-neutral.
 *
 * The counterpart of mep-agenda.css: this asserts the shape (a responsive grid of portrait cards
 * with a square media block) and nothing opinionated. Colour, type and surface belong to a skin,
 * which loads after this and wins. Unskinned, the grid inherits the host theme's own text colour
 * and paints no background — a plain wall of names that looks like the site it sits in.
 */

/* mep.css has laid out `.mep-speakers` as a grid of cards since before the widget moved into a
   shadow root, and that rule still applies to this container — which made the server-rendered grid
   a single 220px track with everything crushed inside it. The old rule is left alone (it is not
   ours to redefine from here); this states what the server render actually is. */
.mep-speakers--server {
	display: block;
	width: 100%;
	box-sizing: border-box;
}

/* Four across at most, fewer as the room runs out — by MEASURE, not by fixed breakpoints.
   `auto-fill` + `minmax` re-flows at every width, including inside a narrow column or a sidebar,
   which a viewport media query cannot see.

   The `max()` is the column CAP: a track is never narrower than the minimum (so cards do not get
   squeezed) and never narrower than a quarter of the row (so a 1920px screen cannot fit a fifth
   column in). Without it the same rule that gives 2-up on a phone gives 5-up on a desktop.

   `auto-fill`, NOT `auto-fit`: the two are identical once there are enough speakers to fill a row,
   and differ only for a short grid. auto-fit collapses the tracks nobody occupies, so a line-up of
   one or two announced so far stretched each portrait across half the page or all of it. A card is
   sized by the grid it belongs to, not by how much of the line-up has been announced. */
.mep-speakers-cards {
	--mep-speakers-gap: 24px;
	--mep-speaker-min: 220px;
	--mep-speaker-cols: 4;

	width: 100%;
	box-sizing: border-box;
	display: grid;
	grid-template-columns: repeat(
		auto-fill,
		minmax(
			max(
				var(--mep-speaker-min),
				calc(
					(100% - (var(--mep-speaker-cols) - 1) * var(--mep-speakers-gap)) /
						var(--mep-speaker-cols)
				)
			),
			1fr
		)
	);
	gap: var(--mep-speakers-gap);
	margin: 0;
	padding: 0;
	list-style: none;
}

.mep-speaker-card {
	position: relative;
	display: flex;
	flex-direction: column;
	overflow: hidden;
	box-sizing: border-box;
}

/* Square by construction, whatever the photo's own ratio is: a wall of portraits only reads as a
   wall when every tile is the same shape. */
.mep-speaker-card__media {
	display: grid;
	place-items: center;
	aspect-ratio: 1 / 1;
	overflow: hidden;
}

/* A theme that does not normalise images would otherwise let the 600px width attribute push the
   card wider than its track. */
.mep-speaker-card__photo {
	display: block;
	width: 100%;
	max-width: 100%;
	height: 100%;
	object-fit: cover;
}

/* The whole card is one link when a profile page is configured, so the inner element carries the
   card's layout and the <li> stays a plain grid cell. Colour and decoration are the skin's. */
.mep-speaker-card__inner {
	display: flex;
	flex: 1;
	flex-direction: column;
}

/* Both card controls are the card: a button must not look like a button, and a link must not look
   like a link — the card IS the affordance. */
.mep-speaker-card__open {
	color: inherit;
	text-decoration: none;
	font: inherit;
	text-align: inherit;
	background: none;
	border: 0;
	padding: 0;
	width: 100%;
	cursor: pointer;
}

.mep-speaker-card__body {
	display: flex;
	flex: 1;
	flex-direction: column;
}

.mep-speaker-card__name,
.mep-speaker-card__role {
	margin: 0;
}

/* Two up is the floor: one enormous portrait per row on a phone wastes the screen and buries the
   last speaker. 140px + a 12px gap keeps two columns on a 360px device even after the host page has
   taken its own margins out of the width. */
@media (max-width: 460px) {
	.mep-speakers-cards {
		--mep-speaker-min: 140px;
		--mep-speakers-gap: 12px;
	}
}

/* A small phone, where the host page's own margins have already taken ~100px out of 360: the
   minimum has to come down again or the second column cannot fit and the wall becomes a list. */
@media (max-width: 400px) {
	.mep-speakers-cards {
		--mep-speaker-min: 120px;
	}
}


/* ---- one speaker's page -------------------------------------------------- */

.mep-speaker-profile--server {
	width: 100%;
	box-sizing: border-box;
}

.mep-speaker-profile__head {
	display: flex;
	flex-wrap: wrap;
	gap: 24px;
	align-items: flex-start;
}

.mep-speaker-profile__media {
	display: grid;
	place-items: center;
	flex: none;
	/* Scales with the page rather than sitting at one desktop size: 200px on a wide layout, down to
	   about 130px on a phone, where a fixed 200 would leave no room for the name beside it. */
	width: clamp(130px, 22vw, 200px);
	aspect-ratio: 1 / 1;
	overflow: hidden;
}

.mep-speaker-profile__photo {
	display: block;
	width: 100%;
	max-width: 100%;
	height: 100%;
	object-fit: cover;
}

.mep-speaker-profile__identity {
	flex: 1 1 260px;
}

.mep-speaker-profile__name,
.mep-speaker-profile__role,
.mep-speaker-profile__socials {
	margin: 0;
}

.mep-speaker-profile__appearances {
	margin: 0;
	padding: 0;
	list-style: none;
}

.mep-speaker-profile__appearance {
	display: flex;
	flex-wrap: wrap;
	gap: 4px 12px;
}


/* ---- the popout ----------------------------------------------------------
 * A native <dialog>: the browser owns the modality, the focus trap, Esc, and the top layer, so
 * there is no focus-management code to get wrong. Layout only here; the skin paints it. */

.mep-speaker-dialog {
	/* Sized to the content it actually holds — a portrait, a few lines of identity, a bio and one
	   event's sessions. Wider than this and the bio runs past a comfortable measure with empty
	   space beside it. */
	width: min(620px, 100% - 32px);
	max-height: min(84vh, 800px);
	padding: 0;
	border: 0;
	overflow: auto;
	box-sizing: border-box;
}

/* A deep link (/speakers/<name>/) renders the popout ALREADY OPEN, before any script has run. An
   open <dialog> nobody has made modal is position:absolute with auto margins, which would float it
   over the line-up; in the flow it is simply the profile, printed under the grid, which is what a
   reader with no JavaScript should get. The script removes this class the moment it upgrades the
   element to a real modal. */
.mep-speaker-dialog--inline {
	position: static;
	width: 100%;
	max-height: none;
	margin: 24px 0 0;
	overflow: visible;
}

.mep-speaker-dialog__body {
	padding: clamp(18px, 3.5vw, 32px);
}

/*
 * Our buttons keep the background WE declared, in every state.
 *
 * A host theme that styles `button:hover` / `button:focus` outspecifies a single class of ours —
 * hello-elementor's reset.css paints both states #c36 — and `showModal()` focuses the close button
 * the instant the popout opens, so that pink landed on the close button every single time it was
 * used. Restating the background against the state pseudo-class puts these at (0,2,0), which beats
 * the theme's (0,1,1); a skin that wants a real hover scopes with a second class and still wins,
 * and skins load after this file so an equal-specificity skin rule wins on order.
 *
 * Only the buttons this stylesheet gives a background to are listed. The agenda's buttons
 * deliberately declare none — the theme paints those, and taking that over here would be a
 * redesign rather than a fix.
 */
.mep-speaker-card__open:hover,
.mep-speaker-card__open:focus,
.mep-speaker-dialog__close:hover,
.mep-speaker-dialog__close:focus,
.mep-speaker-dialog__retry:hover,
.mep-speaker-dialog__retry:focus {
	background: none;
}

.mep-speaker-dialog__close {
	position: sticky;
	top: 0;
	float: right;
	z-index: 1;
	margin: 8px 8px 0 0;
	width: 40px;
	height: 40px;
	font-size: 24px;
	line-height: 1;
	cursor: pointer;
	background: none;
	border: 0;
	color: inherit;
}

/* The name is an h1 in the page flow, which is right on a page of its own and too loud in a modal. */
.mep-speaker-dialog .mep-speaker-profile__name {
	font-size: clamp(1.3rem, 2.4vw, 1.65rem);
}

/* The portrait comes down with the dialog — at 200px it took half the width of a 620px modal. */
.mep-speaker-dialog .mep-speaker-profile__media {
	width: clamp(110px, 20vw, 150px);
}


/* ---- loading, and long bios ----------------------------------------------
 * The popout opens with the person already on screen — the card supplied the portrait and the
 * name — so the only placeholder is for the text nobody has yet. */

.mep-skeleton {
	display: block;
	height: 0.85em;
	margin: 0.55em 0;
	border-radius: 4px;
	background: currentColor;
	opacity: 0.12;
	animation: mep-skeleton-pulse 1.4s ease-in-out infinite;
}

.mep-skeleton--short {
	width: 60%;
}

@keyframes mep-skeleton-pulse {
	0%, 100% { opacity: 0.1; }
	50% { opacity: 0.2; }
}

/* A pulsing block is decoration, and for some readers a trigger. Hold it still. */
@media (prefers-reduced-motion: reduce) {
	.mep-skeleton { animation: none; }
}

/* Clamped by script, and only when the text really overflows — so a page with no JavaScript never
   hides a bio behind a control that cannot work. */
.mep-speaker-profile__bio.is-clamped {
	display: -webkit-box;
	-webkit-line-clamp: 7;
	-webkit-box-orient: vertical;
	overflow: hidden;
}

.mep-speaker-profile__more {
	display: inline-block;
	margin-top: 10px;
	padding: 0;
	font: inherit;
	background: none;
	border: 0;
	cursor: pointer;
	text-decoration: underline;
	text-underline-offset: 3px;
}

.mep-speaker-dialog__error {
	margin: 0;
	padding: 8px 0;
}

.mep-speaker-dialog__retry {
	font: inherit;
	padding: 0;
	background: none;
	border: 0;
	cursor: pointer;
	text-decoration: underline;
	text-underline-offset: 3px;
}


/* ---- the card morphing into the popout -----------------------------------
 * The browser tweens between the two rectangles; these rules only set the pace and stop the two
 * snapshots cross-fading as squashed copies of each other while it does.
 *
 * Nothing here is required for the feature to work — without View Transitions the popout simply
 * opens, which is what every other browser gets. */

::view-transition-group(mep-speaker-morph) {
	animation-duration: 260ms;
	animation-timing-function: cubic-bezier(0.22, 1, 0.36, 1);
}

/* Both snapshots are scaled into the same box, so a portrait card and a wide dialog would each
   distort on the way. Cropping instead of squashing is what makes it read as one thing moving. */
::view-transition-old(mep-speaker-morph),
::view-transition-new(mep-speaker-morph) {
	height: 100%;
	overflow: clip;
	object-fit: cover;
	object-position: top center;
}

/* The old card fades early, the new dialog arrives late: the middle of the morph is mostly the
   shape changing, not two pictures blended. */
::view-transition-old(mep-speaker-morph) {
	animation-name: mep-morph-out;
}

::view-transition-new(mep-speaker-morph) {
	animation-name: mep-morph-in;
}

@keyframes mep-morph-out {
	to { opacity: 0; }
}

@keyframes mep-morph-in {
	from { opacity: 0; }
}

@media (prefers-reduced-motion: reduce) {
	::view-transition-group(mep-speaker-morph),
	::view-transition-old(mep-speaker-morph),
	::view-transition-new(mep-speaker-morph) {
		animation: none;
	}
}
