/*
 * card.css — the listing card.
 *
 * The markup is template-parts/card.php, one card for articles, projects and
 * videos. It used to live in archive.css, when a card only ever appeared in an
 * archive. Since the videos it is also printed by blocks on ordinary pages —
 * the latest videos on the home page, the project and the articles under a
 * video — and those pages never load archive.css.
 *
 * So the card has a stylesheet of its own and a handle of its own,
 * sws-theme-card, registered on init. archive.css depends on it; a block that
 * prints cards names it in the style list of its block.json, next to its own
 * file, and core loads it wherever that block renders.
 *
 * Only the card is here. The grid a card stands in belongs to whoever lays it
 * out: archive.css for the archives, the block's own style.css for a block.
 */

/*--------------------------------------------------------------
# Card
--------------------------------------------------------------*/

.sws-card,
.sws-card *,
.sws-card *::before,
.sws-card *::after {
	box-sizing: border-box;
}

.sws-card {
	display: flex;
	flex-direction: column;
	overflow: hidden;
	border: 1px solid var(--wp--preset--color--line, #dbeefd);
	border-radius: var(--sws-radius-lg, 5px);
	background-color: var(--wp--preset--color--surface, #fff);
	transition: box-shadow var(--sws-transition, 0.3s ease), transform var(--sws-transition, 0.3s ease);
}

.sws-card:hover,
.sws-card:focus-within {
	box-shadow: var(--sws-shadow-dropdown, 0 0 30px 0 rgb(0 0 0 / 5%));
	transform: translateY(-3px);
}

/*--------------------------------------------------------------
# Card media
--------------------------------------------------------------*/

.sws-card__media {
	display: flex;
	align-items: center;
	justify-content: center;
	overflow: hidden;
	aspect-ratio: 16 / 10;
	background-color: var(--wp--preset--color--surface-alt, #f7fafd);
}

.sws-card__media img {
	width: 100%;
	height: 100%;
	object-fit: cover;
}

/*
 * The stand-in for a missing featured image. It is the common case while the
 * media library is nearly empty, so it is styled as a first-class state rather
 * than a fallback: a schematic symbol from the theme's own icon set, on the
 * alternate surface.
 */
.sws-card__media--placeholder {
	border-bottom: 1px solid var(--wp--preset--color--line, #dbeefd);
	color: var(--wp--preset--color--accent, #44ce6f);
}

.sws-card__icon {
	width: 3.5rem;
	height: 3.5rem;
	opacity: 0.55;
}

/*--------------------------------------------------------------
# Card body
--------------------------------------------------------------*/

.sws-card__body {
	display: flex;
	flex: 1 1 auto;
	flex-direction: column;
	gap: 0.625rem;
	padding: 1.5rem;
}

.sws-card__title {
	/*
	 * Not the x-large h2 from theme.json: that size is set for prose, and a
	 * card heading sits in a 17.5rem track.
	 */
	margin: 0;
	color: var(--wp--preset--color--heading, #0e314c);
	font-size: 1.25rem;
	font-weight: 700;
	line-height: 1.4;
}

.sws-card__link {
	color: inherit;
	text-decoration: none;
	transition: color var(--sws-transition, 0.3s ease);
}

.sws-card__link:hover,
.sws-card__link:focus {
	color: var(--wp--preset--color--accent, #44ce6f);
}

.sws-card__date {
	color: var(--wp--preset--color--text, #4a6f8a);
	font-size: var(--wp--preset--font-size--small, 0.875rem);
}

.sws-card__excerpt {
	/*
	 * Clamped rather than shortened in PHP. An excerpt WordPress generated for
	 * itself runs 55 words, which is fine on a feed and far too long in a
	 * 17.5rem track — one verbose entry would set the height of its whole grid
	 * row. A filter on excerpt_length would change the excerpt everywhere,
	 * including the RSS feed and search results; this only changes how many
	 * lines the card shows.
	 */
	display: -webkit-box;
	overflow: hidden;
	-webkit-box-orient: vertical;
	-webkit-line-clamp: 4;
	line-clamp: 4;
	margin: 0;
	color: var(--wp--preset--color--text, #4a6f8a);
	line-height: 1.7;
}

/*--------------------------------------------------------------
# Card topics
--------------------------------------------------------------*/

.sws-card__topics {
	display: flex;
	flex-wrap: wrap;
	gap: 0.5rem;
	/* Pushed to the bottom so cards of unequal height still line up. */
	margin: auto 0 0;
	padding: 0;
	list-style: none;
}

.sws-card__topic {
	margin: 0;
}

.sws-card__topic-link {
	display: inline-block;
	padding: 0.25rem 0.625rem;
	border-radius: var(--sws-radius, 4px);
	background-color: var(--wp--preset--color--surface-alt, #f7fafd);
	color: var(--wp--preset--color--text, #4a6f8a);
	font-size: var(--wp--preset--font-size--small, 0.875rem);
	text-decoration: none;
	transition: background-color var(--sws-transition, 0.3s ease), color var(--sws-transition, 0.3s ease);
}

.sws-card__topic-link:hover,
.sws-card__topic-link:focus {
	background-color: var(--wp--preset--color--accent-soft, #cdf1d8);
	color: var(--wp--preset--color--heading, #0e314c);
}

/*--------------------------------------------------------------
# Video
--------------------------------------------------------------*/

/*
 * A video's picture is a frame of the video, and the videos so far are
 * vertical. Cropped to the common 16:10 box only the middle third of the frame
 * would be left, so among articles and projects it is fitted in whole, and the
 * navy beside it reads as the edges of a screen.
 */
.sws-card--video .sws-card__media {
	position: relative;
	background-color: var(--wp--preset--color--heading, #0e314c);
}

.sws-card--video .sws-card__media img {
	object-fit: contain;
}

/* No frame to fit: the stand-in keeps the light surface every other card has. */
.sws-card--video .sws-card__media--placeholder {
	background-color: var(--wp--preset--color--surface-alt, #f7fafd);
}

/*
 * The play mark. A sign, not a control: the whole picture is the link, and it
 * leads to the video's page, where the player is. White on the navy is about
 * 13:1, which the accent green would not give.
 */
.sws-card__play {
	position: absolute;
	top: 50%;
	left: 50%;
	display: flex;
	align-items: center;
	justify-content: center;
	width: 3.25rem;
	height: 3.25rem;
	margin: -1.625rem 0 0 -1.625rem;
	border-radius: 50%;
	background-color: rgb(14 49 76 / 80%);
	color: #ffffff;
	transition: transform var(--sws-transition, 0.3s ease);
}

.sws-card:hover .sws-card__play,
.sws-card:focus-within .sws-card__play {
	transform: scale(1.1);
}

/* The triangle is heavier on its left, so it is nudged to sit centred by eye. */
.sws-card__play-icon {
	width: 1.25rem;
	height: 1.25rem;
	margin-left: 0.125rem;
}

.sws-card__length {
	position: absolute;
	right: 0.5rem;
	bottom: 0.5rem;
	padding: 0.125rem 0.4375rem;
	border-radius: var(--sws-radius, 4px);
	background-color: rgb(14 49 76 / 85%);
	color: #ffffff;
	font-size: 0.75rem;
	font-weight: 600;
	font-variant-numeric: tabular-nums;
	line-height: 1.5;
}

/*--------------------------------------------------------------
# Poster variant
--------------------------------------------------------------*/

/*
 * Asked for by a listing of videos alone. There the card takes the proportions
 * of a vertical frame and the frame fills it; a horizontal video keeps the
 * rule above and is fitted into the same tall box whole, over a blurred copy
 * of itself.
 *
 * The track such a card stands in is narrow — two to a row on a phone — so the
 * body tightens with it.
 */
.sws-card--poster .sws-card__media {
	aspect-ratio: 9 / 16;
}

.sws-card--poster.sws-card--short .sws-card__media img {
	object-fit: cover;
}

/*
 * A horizontal video in the tall box: the frame stays whole in the middle, and
 * the same picture, blurred and dimmed, fills the box behind it. Scaled up so
 * the soft edges the blur leaves fall outside the box; the media box already
 * clips. The frame is positioned so that it paints over the backdrop, which
 * comes first in the markup; the play mark and the length come after both.
 */
.sws-card--video .sws-card__media .sws-card__backdrop {
	position: absolute;
	inset: 0;
	object-fit: cover;
	filter: blur(1rem) brightness(0.7);
	transform: scale(1.15);
}

.sws-card--poster.sws-card--long .sws-card__media img:not(.sws-card__backdrop) {
	position: relative;
}

.sws-card--poster .sws-card__body {
	gap: 0.375rem;
	padding: 1rem;
}

.sws-card--poster .sws-card__title {
	font-size: 1rem;
}
