/*
 * Nostot (avalon/features + avalon/feature).
 *
 * Tighter items: image → title 16px, title → text 8px, text → button 16px; titles 17/18/20px (h3 or h4).
 * Buttons that repeat the title wrap between words only; they are 48px high on phones (--ab-btn-h), 44px wider.
 * Tablets and desktops: the items of a row are equally high and their buttons line up at the bottom.
 * Tablet: at most 2 across, 4:3 pictures. Phones: 2 across only when every item is short (.ab-features--duo, set in
 * render.php), otherwise rows: a 72px picture next to the title, text and button below (or next to it when the item
 * has no text).
 * A link item (.is-link: a picture, a title and one button, which usually repeats the title) is one link at every
 * width: the button's link is stretched over the item and its label is hidden visually (it stays the link's name for
 * screen readers); a chevron follows the title (in a tint circle on tablets and desktops, as in the image link cards;
 * on phones the item is one tappable row with a plain chevron).
 * Items that list people (.ab-features--people) are person cards, styled in people.css.
 */

.ab-features .ab-grid {
	gap: 48px var(--ab-gap, 48px);
}

.ab-feature {
	min-width: 0;
}

/* item rhythm (replaces the .ab-item rules of blocks.css) */
.ab-feature.ab-item > * {
	margin-block: 0;
}

.ab-feature.ab-item > * + *,
.ab-feature.ab-item > p + p {
	margin-block-start: 8px;
}

.ab-feature.ab-item > .wp-block-image + * {
	margin-block-start: 16px;
}

.ab-feature.ab-item > * + .wp-block-buttons {
	margin-block-start: 16px;
}

.ab-feature.ab-item :is(h2, h3, h4, h5, h6) {
	margin: 0;
	color: var(--ab-heading);
	font-size: 18px;
	font-weight: 700;
	line-height: 1.3;
	overflow-wrap: normal;
	hyphens: auto;
}

.ab-feature :is(p, li) {
	font-size: 16px;
	line-height: 1.55;
}

.ab-feature .wp-block-image {
	margin: 0;
}

.ab-feature .wp-block-image img {
	display: block;
	width: 100%;
	height: auto;
	aspect-ratio: 1;
	border-radius: var(--ab-radius, 12px);
	object-fit: cover;
}

/* round pictures (people) stay round and no bigger than a person's photo: 160px, 120px on tablets (items that list
   people are person cards anyway; this is for a round picture in other items) */
.ab-feature .wp-block-image.is-style-rounded img {
	width: min(100%, 160px) !important;
	height: auto !important;
	aspect-ratio: 1;
	border-radius: 9999px;
}

/* a button with the item's title in it: whole words on the next line, never a word split */
.ab-feature .wp-block-buttons {
	max-width: 100%;
}

.ab-feature .wp-block-button {
	max-width: 100%;
}

.ab-feature .wp-block-button__link {
	display: inline-flex;
	align-items: center;
	box-sizing: border-box;
	min-height: var(--ab-btn-h, 44px);
	max-width: 100%;
	padding: 10px 16px;
	text-align: left;
	white-space: normal;
	overflow-wrap: normal;
	word-break: normal;
	hyphens: manual;
}

/* ---------------------------------------------------------------- link items (every width) */

/* the picture across the item, the title and the chevron below it */
.ab-feature.ab-item.is-link {
	position: relative;
	display: grid;
	grid-template-columns: minmax(0, 1fr) 32px;
	grid-template-rows: auto 1fr;
	align-content: start;
	column-gap: 12px;
}

.ab-feature.is-link > .wp-block-image {
	grid-row: 1;
	grid-column: 1 / -1;
	overflow: hidden;
	border-radius: var(--ab-radius, 12px);
}

.ab-feature.is-link > .wp-block-image img {
	transition: transform 0.3s ease;
}

.ab-feature.ab-item.is-link > :is(h2, h3, h4, h5, h6) {
	grid-row: 2;
	grid-column: 1;
	align-self: start;
	margin: 16px 0 0;
}

/* the buttons' wrappers leave the layout; the link itself is a 1px box (its label clipped by overflow, not by clip
   or clip-path, which would clip the stretched ::after too) */
.ab-feature.is-link > .wp-block-buttons,
.ab-feature.is-link > .wp-block-buttons > .wp-block-button {
	display: contents;
}

.ab-feature.is-link > .wp-block-buttons .wp-block-button__link {
	grid-row: 2;
	grid-column: 1;
	align-self: start;
	position: static;
	width: 1px;
	min-width: 0;
	height: 1px;
	min-height: 0;
	margin: 0;
	padding: 0;
	overflow: hidden;
	border: 0;
	background: none;
	white-space: nowrap;
}

.ab-feature.is-link > .wp-block-buttons .wp-block-button__link::after {
	content: "";
	position: absolute;
	inset: 0;
	z-index: 1;
	display: block;
	width: auto;
	height: auto;
	margin: 0;
	background: none;
	-webkit-mask: none;
	mask: none;
}

.ab-feature.is-link > .wp-block-buttons .wp-block-button__link:focus-visible {
	outline: none;
}

.ab-feature.is-link:has(.wp-block-button__link:focus-visible) {
	outline: 2px solid var(--wp--preset--color--accent, #30cbd3);
	outline-offset: 4px;
	border-radius: 0;
}

/* chevron in a tint circle (as in the link cards), next to the first line of the title */
.ab-feature__chev {
	display: none;
}

.ab-feature.is-link > .ab-feature__chev {
	display: grid;
	grid-row: 2;
	grid-column: 2;
	align-self: start;
	place-items: center;
	width: 32px;
	height: 32px;
	margin: 13px 0 0;
	border-radius: 50%;
	background: var(--ab-tint, #eaf8f9);
	color: var(--ab-navy, #002b56);
	transition: background-color 0.2s ease;
}

.ab-feature__chev svg {
	display: block;
	width: 18px;
	height: 18px;
}

.ab-feature.is-link:hover > :is(h2, h3, h4, h5, h6) {
	text-decoration: underline;
	text-decoration-thickness: var(--ab-underline, 2px);
	text-underline-offset: 0.18em;
}

.ab-feature.is-link:hover > .ab-feature__chev {
	background: var(--ab-accent, #30cbd3);
}

.ab-feature.is-link:hover > .wp-block-image img {
	transform: scale(1.03);
}

.is-dark .ab-feature.is-link > .ab-feature__chev {
	background: rgba(255, 255, 255, 0.12);
	color: var(--wp--preset--color--accent, #30cbd3);
}

.is-dark .ab-feature.is-link:hover > .ab-feature__chev {
	background: var(--wp--preset--color--accent, #30cbd3);
	color: var(--ab-navy, #002b56);
}

@media (prefers-reduced-motion: reduce) {
	.ab-feature.is-link > .wp-block-image img,
	.ab-feature.is-link > .ab-feature__chev {
		transition: none;
	}

	.ab-feature.is-link:hover > .wp-block-image img {
		transform: none;
	}
}

/* ---------------------------------------------------------------- tablets and desktops */

@media (min-width: 769px) {
	/* the items of a row are as high as the highest; the buttons line up at the bottom (titles of 1 or 2 lines) */
	.ab-feature.ab-item {
		display: flex;
		flex-direction: column;
	}

	.ab-feature.ab-item > .wp-block-image {
		align-self: stretch;
	}

	.ab-feature.ab-item > * + .wp-block-buttons {
		margin-block-start: auto;
		padding-top: 16px;
	}
}

/* ---------------------------------------------------------------- tablet */

@media (min-width: 769px) and (max-width: 1024px) {
	.ab-features:not(.ab-features--people) .ab-grid {
		grid-template-columns: repeat(min(var(--ab-cols, 4), 2), minmax(0, 1fr));
		gap: 40px var(--ab-gap, 32px);
	}

	.ab-feature .wp-block-image.is-style-rounded img {
		width: min(100%, 120px) !important;
	}

	/* landscape pictures instead of squares (the square is an inline style of the image block) */
	.ab-feature .wp-block-image:not(.is-style-rounded):not(.is-resized) img {
		width: 100%;
		aspect-ratio: 4 / 3 !important;
		object-fit: cover;
	}

	.ab-feature.ab-item :is(h2, h3, h4, h5, h6) {
		font-size: 17px;
	}
}

/* ---------------------------------------------------------------- phones */

@media (max-width: 768px) {
	.ab-feature.ab-item :is(h2, h3, h4, h5, h6) {
		font-size: 17px;
		line-height: 1.3;
	}

	.ab-feature :is(p, li) {
		font-size: 15px;
		line-height: 1.55;
	}

	/* two across: short items (e.g. people with a name and a number) */
	.ab-features--duo .ab-grid {
		grid-template-columns: repeat(2, minmax(0, 1fr)) !important;
		gap: 24px 12px;
	}

	.ab-features--duo .ab-feature.ab-item > .wp-block-image + * {
		margin-block-start: 12px;
	}

	.ab-features--duo .ab-feature .wp-block-image img {
		width: 100% !important;
		height: auto !important;
	}

	/* portraits of people: smaller circles */
	.ab-features--duo .ab-feature .wp-block-image:is(.is-style-rounded, .is-resized) img {
		width: min(100%, 128px) !important;
		aspect-ratio: 1;
		object-fit: cover;
	}

	/* rows */
	.ab-features--rows .ab-grid {
		grid-template-columns: minmax(0, 1fr) !important;
		gap: 16px;
	}

	.ab-features--rows .ab-feature + .ab-feature {
		padding-top: 16px;
		border-top: 1px solid var(--ab-line, #e3e8ee);
	}

	.is-dark.ab-features--rows .ab-feature + .ab-feature {
		border-top-color: rgba(255, 255, 255, 0.18);
	}

	.ab-features--rows .ab-feature.has-media {
		display: grid;
		grid-template-columns: 72px minmax(0, 1fr);
		column-gap: 14px;
		align-items: center;
	}

	.ab-features--rows .ab-feature.has-media > .wp-block-image {
		grid-row: 1;
		grid-column: 1;
	}

	.ab-features--rows .ab-feature.has-media .wp-block-image img {
		width: 72px !important;
		height: 72px !important;
		aspect-ratio: 1 !important;
		border-radius: 0;
		object-fit: cover;
	}

	.ab-features--rows .ab-feature.has-media .wp-block-image.is-style-rounded img {
		border-radius: 50%;
	}

	.ab-features--rows .ab-feature.has-media > :is(h2, h3, h4, h5, h6) {
		grid-row: 1;
		grid-column: 2;
		margin: 0;
	}

	/* text, lists and buttons below the picture and the title, full width */
	.ab-features--rows .ab-feature.has-media > :not(.wp-block-image):not(h2, h3, h4, h5, h6) {
		grid-column: 1 / -1;
		margin-block-start: 12px;
	}

	/* an item with only a title and a button: the button next to the picture, under the title */
	.ab-features--rows .ab-feature.has-media:not(:has(> :is(p, ul, ol))) > .wp-block-image {
		grid-row: 1 / span 2;
	}

	.ab-features--rows .ab-feature.has-media:not(:has(> :is(p, ul, ol))) > :is(h2, h3, h4, h5, h6) {
		align-self: end;
	}

	.ab-features--rows .ab-feature.has-media:not(:has(> :is(p, ul, ol))) > .wp-block-buttons {
		grid-row: 2;
		grid-column: 2;
		align-self: start;
		margin-block-start: 8px;
	}

	.ab-feature .wp-block-button__link {
		padding: 10px 14px;
		font-size: 15px;
	}

	/* link items: one row – picture, title, a plain chevron; the button's link covers the row (the link and the hidden
	   label: see "link items" above; .has-media: stronger than the rules for items with a title and a button above) */
	.ab-features--rows .ab-feature.has-media.is-link {
		grid-template-columns: 72px minmax(0, 1fr) 20px;
		grid-template-rows: auto;
		align-content: normal;
		column-gap: 14px;
	}

	.ab-features--rows .ab-feature.has-media.is-link > .wp-block-image,
	.ab-features--rows .ab-feature.has-media.is-link > :is(h2, h3, h4, h5, h6) {
		grid-row: 1;
		align-self: center;
	}

	.ab-features--rows .ab-feature.has-media.is-link > .wp-block-image {
		border-radius: 0;
	}

	.ab-features--rows .ab-feature.has-media.is-link > .wp-block-image.is-style-rounded {
		border-radius: 50%;
	}

	.ab-features--rows .ab-feature.has-media.is-link > .wp-block-buttons .wp-block-button__link {
		grid-row: 1;
		grid-column: 2;
	}

	.ab-features--rows .ab-feature.has-media.is-link > .ab-feature__chev,
	.ab-features--rows .ab-feature.has-media.is-link:hover > .ab-feature__chev {
		grid-row: 1;
		grid-column: 3;
		align-self: center;
		width: 20px;
		height: auto;
		margin: 0;
		border-radius: 0;
		background: none;
		color: var(--ab-navy, #002b56);
	}

	.is-dark.ab-features--rows .ab-feature.has-media.is-link > .ab-feature__chev,
	.is-dark.ab-features--rows .ab-feature.has-media.is-link:hover > .ab-feature__chev {
		color: var(--wp--preset--color--accent, #30cbd3);
	}
}
