/*
 * Articles (ADR 0061): a grid (or carousel) of article cards. Each card is a Service card
 * (service-card/style.css, "requires": ["service-card"]); this file adds the grid, the category
 * buttons, the details line, the link text and the page links.
 */
.sv-posts {
	display: grid;
	gap: var(--sv-space-sm);
}

.sv-posts__grid {
	display: grid;
	grid-template-columns: repeat(3, minmax(0, 1fr));
	/* Space between cards (ADR 0054, 0187): the same between rows as between columns. */
	gap: var(--sv-colgap, var(--sv-space-element, var(--sv-space-md)));
}

.sv-posts--columns-1 .sv-posts__grid {
	grid-template-columns: minmax(0, 1fr);
}

.sv-posts--columns-2 .sv-posts__grid {
	grid-template-columns: repeat(2, minmax(0, 1fr));
}

.sv-posts--columns-4 .sv-posts__grid {
	grid-template-columns: repeat(4, minmax(0, 1fr));
}

@media (max-width: 1024px) {
	:is(.sv-posts--columns-3, .sv-posts--columns-4) .sv-posts__grid {
		grid-template-columns: repeat(2, minmax(0, 1fr));
	}
}

@media (max-width: 767px) {
	.sv-posts .sv-posts__grid[class] {
		grid-template-columns: minmax(0, 1fr);
	}
}

/* Carousel (ADR 0047): as many cards in view as the columns; on phones one and a glimpse of the next. */
.sv-posts .sv-carousel {
	--sv-carousel-per: 3;
}

.sv-posts--columns-1 .sv-carousel {
	--sv-carousel-per: 1;
}

.sv-posts--columns-2 .sv-carousel {
	--sv-carousel-per: 2;
}

.sv-posts--columns-4 .sv-carousel {
	--sv-carousel-per: 4;
}

@media (max-width: 1024px) {
	:is(.sv-posts--columns-3, .sv-posts--columns-4) .sv-carousel {
		--sv-carousel-per: 2;
	}
}

@media (max-width: 767px) {
	.sv-posts .sv-carousel[class] {
		--sv-carousel-per: 1.15;
	}

	.sv-posts--columns-1 .sv-carousel[class] {
		--sv-carousel-per: 1;
	}
}

/* An article without a featured picture: a soft block in the Accent's tint, so the cards line up. */
.sv-posts__nophoto {
	display: block;
	inline-size: 100%;
	block-size: 100%;
	min-block-size: 8rem;
	background:
		radial-gradient(circle at 30% 20%, color-mix(in srgb, var(--sv-color-primary) 22%, transparent), transparent 60%),
		color-mix(in srgb, var(--sv-color-primary) 10%, var(--sv-color-surface));
}

.sv-service-card--look-text .sv-service-card__media:has(.sv-posts__nophoto) {
	display: none;
}

/* The details line: category · date · reading time, small, the category in the accent. */
.sv-posts__meta {
	display: flex;
	flex-wrap: wrap;
	gap: 0.25rem 0.5rem;
	align-items: center;
	margin: 0;
	margin-block-end: 0.4rem;
	color: var(--sv-color-muted);
	font-size: var(--sv-size-small);
	line-height: 1.4;
}

.sv-posts__meta:empty {
	display: none;
}

.sv-posts__meta > * + *::before {
	content: "·";
	margin-inline-end: 0.5rem;
	color: var(--sv-color-muted);
	font-weight: 400;
}

.sv-posts__category {
	color: var(--sv-accent, var(--sv-color-link));
	font-weight: 600;
}

/* In Tiles the words' tile is narrow: the category on its own line, the date and reading time under it (no "·" first). */
.sv-service-card--look-tiles .sv-posts__category {
	flex-basis: 100%;
}

.sv-service-card--look-tiles .sv-posts__category + *::before {
	content: none;
}

/*
 * On a dark card or the photo, the details follow the card's light text, a little softer; on an accent-color card
 * at full strength, since the card's text color only just reads on it (ADR 0102). The cards taking turns stay in
 * :where() so the accent card's full strength below still wins; in Tiles they are light (ADR 0154), so these leave them.
 */
:is(.sv-card-dark, .sv-card-primary, .sv-service-card--look-overlay-shade, :where(.sv-card-turns:nth-of-type(3n + 2):where(:not(.sv-service-card--look-tiles)), .sv-card-turns:nth-of-type(3n):where(:not(.sv-service-card--look-tiles)))) .sv-posts__meta,
:is(.sv-card-dark, .sv-card-primary, .sv-service-card--look-overlay-shade, :where(.sv-card-turns:nth-of-type(3n + 2):where(:not(.sv-service-card--look-tiles)), .sv-card-turns:nth-of-type(3n):where(:not(.sv-service-card--look-tiles)))) .sv-posts__meta > * + *::before {
	color: inherit;
	opacity: 0.85;
}

.sv-card-primary .sv-posts__meta,
.sv-card-primary .sv-posts__meta > * + *::before,
.sv-card-turns:nth-of-type(3n):where(:not(.sv-service-card--look-tiles)) .sv-posts__meta,
.sv-card-turns:nth-of-type(3n):where(:not(.sv-service-card--look-tiles)) .sv-posts__meta > * + *::before {
	opacity: 1;
}

:is(.sv-card-dark, .sv-card-primary, .sv-service-card--look-overlay-shade, .sv-card-turns:nth-of-type(3n + 2):where(:not(.sv-service-card--look-tiles)), .sv-card-turns:nth-of-type(3n):where(:not(.sv-service-card--look-tiles))) .sv-posts__category {
	color: inherit;
}

.sv-posts__author {
	margin: 0;
	margin-block-start: 0.5rem;
	color: var(--sv-color-muted);
	font-size: var(--sv-size-small);
}

/* The link text: the accent, with an arrow that moves when the card is pointed at. */
.sv-posts__more {
	display: inline-flex;
	gap: 0.35em;
	align-items: center;
	margin-block-start: 0.75rem;
	color: var(--sv-accent, var(--sv-color-link));
	font-size: var(--sv-size-small);
	font-weight: 600;
}

.sv-posts__more::after {
	content: "→";
	transition: translate 0.2s ease;
}

:where([dir="rtl"]) .sv-posts__more::after {
	content: "←";
}

.sv-posts__item:is(:hover, :focus-within) .sv-posts__more::after {
	translate: 3px 0;
}

:where([dir="rtl"]) .sv-posts__item:is(:hover, :focus-within) .sv-posts__more::after {
	translate: -3px 0;
}

:is(.sv-card-dark, .sv-card-primary, .sv-service-card--look-overlay-shade, .sv-card-turns:nth-of-type(3n + 2):where(:not(.sv-service-card--look-tiles)), .sv-card-turns:nth-of-type(3n):where(:not(.sv-service-card--look-tiles))) .sv-posts__more {
	color: inherit;
}

/*
 * Cards in a row are as tall as the tallest: the text fills the card and the author and link text go
 * to its foot, so they line up whatever the title's length (not on the photo, where the text is a box).
 */
.sv-posts__item:is(.sv-service-card--look-text, .sv-service-card--look-top-open, .sv-service-card--look-top-card) {
	grid-template-rows: auto 1fr;
}

.sv-posts__item:not(.sv-service-card--look-overlay-box, .sv-service-card--look-overlay-shade) .sv-service-card__body {
	display: flex;
	flex-direction: column;
}

.sv-posts__item:not(.sv-service-card--look-overlay-box, .sv-service-card--look-overlay-shade) .sv-posts__author {
	margin-block-start: auto;
	padding-block-start: 0.5rem;
}

.sv-posts__item:not(.sv-service-card--look-overlay-box, .sv-service-card--look-overlay-shade) .sv-posts__more {
	align-self: flex-start;
	margin-block-start: auto;
	padding-block-start: 0.75rem;
}

.sv-posts__item:not(.sv-service-card--look-overlay-box, .sv-service-card--look-overlay-shade) .sv-posts__author ~ .sv-posts__more {
	margin-block-start: 0;
}

/*
 * Category on top (ADR 0167): the category alone over the title; the author, date and reading time at the
 * card's foot, lined up across a row like the author.
 */
.sv-posts__meta--foot {
	margin-block-end: 0;
	padding-block-start: 0.75rem;
}

.sv-posts__item:not(.sv-service-card--look-overlay-box, .sv-service-card--look-overlay-shade) .sv-posts__meta--foot {
	margin-block-start: auto;
}

.sv-posts__item:not(.sv-service-card--look-overlay-box, .sv-service-card--look-overlay-shade) .sv-posts__meta--foot ~ .sv-posts__more {
	margin-block-start: 0;
}

.sv-posts__by {
	color: var(--sv-color-text);
	font-weight: 600;
}

/*
 * Arrow after the title (ADR 0167): ↗ at the end of the title's first line, which keeps room for it; it nudges
 * toward its corner when the article is pointed at (the start's corner, right to left). The Featured article's
 * titles too (it requires this stylesheet).
 */
:is(.sv-posts__item--arrow .sv-service-card__title, .sv-post-featured__main--arrow :is(.sv-post-featured__title, .sv-post-featured__rowtitle)) {
	position: relative;
	padding-inline-end: 1.6em;
}

:is(.sv-posts__item--arrow .sv-service-card__title, .sv-post-featured__main--arrow :is(.sv-post-featured__title, .sv-post-featured__rowtitle))::after {
	--sv-arrow-size: max(1rem, 0.8em);

	position: absolute;
	inset-block-start: calc(0.5lh - var(--sv-arrow-size) / 2);
	inset-inline-end: 0;
	inline-size: var(--sv-arrow-size);
	block-size: var(--sv-arrow-size);
	background-color: currentColor;
	content: "";
	-webkit-mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M7 7h10v10'/%3E%3Cpath d='M7 17 17 7'/%3E%3C/svg%3E") center / contain no-repeat;
	mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M7 7h10v10'/%3E%3Cpath d='M7 17 17 7'/%3E%3C/svg%3E") center / contain no-repeat;
	transition: translate 0.2s ease;
}

:where([dir="rtl"]) :is(.sv-posts__item--arrow .sv-service-card__title, .sv-post-featured__main--arrow :is(.sv-post-featured__title, .sv-post-featured__rowtitle))::after {
	scale: -1 1;
}

:is(.sv-posts__item--arrow:is(:hover, :focus-within) .sv-service-card__title, .sv-post-featured__main--arrow :is(.sv-post-featured__card:is(:hover, :focus-within) .sv-post-featured__title, .sv-post-featured__row:is(:hover, :focus-visible) .sv-post-featured__rowtitle))::after {
	translate: 0.15rem -0.15rem;
}

:where([dir="rtl"]) :is(.sv-posts__item--arrow:is(:hover, :focus-within) .sv-service-card__title, .sv-post-featured__main--arrow :is(.sv-post-featured__card:is(:hover, :focus-within) .sv-post-featured__title, .sv-post-featured__row:is(:hover, :focus-visible) .sv-post-featured__rowtitle))::after {
	translate: -0.15rem -0.15rem;
}

/*
 * On the photo the text shares the photo's height: three lines of the article at most, and on the
 * shade a deeper fade, so the details at the top of the text stay readable on a light photo.
 */
.sv-posts__item:is(.sv-service-card--look-overlay-box, .sv-service-card--look-overlay-shade) .sv-service-card__text {
	display: -webkit-box;
	overflow: hidden;
	-webkit-box-orient: vertical;
	-webkit-line-clamp: 3;
}

/* The details and the link text follow the shade's white text. */
.sv-posts__item.sv-service-card--look-overlay-shade .sv-service-card__body {
	color: var(--sv-color-text);
}

/* Side by side: room above and below the text when it is taller than the photo (phones: photo on top). */
@media (min-width: 768px) {
	.sv-posts__item.sv-service-card--look-side .sv-service-card__body {
		padding-block: 0.85rem;
	}
}

.sv-posts__item.sv-service-card--look-overlay-shade .sv-service-card__media::before {
	background: linear-gradient(to top, rgb(0 0 0 / 86%) 0%, rgb(0 0 0 / 62%) 45%, rgb(0 0 0 / 0%) 82%);
}

/* Category buttons (All, with pages): pills, the chosen one in the accent. */
.sv-posts__filters {
	display: flex;
	flex-wrap: wrap;
	gap: 0.5rem;
	margin-block-end: var(--sv-space-sm);
}

.sv-align-center .sv-posts__filters {
	justify-content: center;
}

.sv-posts__filter {
	display: inline-block;
	padding-block: 0.45rem;
	padding-inline: 1rem;
	border: 1px solid var(--sv-color-border);
	border-radius: 999px;
	color: var(--sv-color-text);
	font-size: var(--sv-size-small);
	font-weight: 500;
	line-height: 1.3;
	text-decoration: none;
	transition: border-color 0.15s ease, color 0.15s ease, background-color 0.15s ease;
}

.sv-posts__filter:is(:hover, :focus-visible) {
	border-color: var(--sv-accent, var(--sv-color-primary));
	color: var(--sv-accent, var(--sv-color-link));
}

.sv-posts__filter[aria-current="page"] {
	border-color: var(--sv-color-primary);
	background: var(--sv-color-primary);
	color: var(--sv-color-on-primary);
}

/*
 * Category buttons as tabs (ADR 0167): the names as words in one row, the chosen one in a light box; a row too long
 * for the screen slides sideways instead of wrapping.
 */
.sv-posts__filters--tabs {
	flex-wrap: nowrap;
	gap: 0.25rem;
	overflow-x: auto;
	padding: 2px;
	scrollbar-width: none;
}

.sv-align-center .sv-posts__filters--tabs {
	justify-content: safe center;
}

.sv-posts__filters--tabs .sv-posts__filter {
	flex: none;
	padding-inline: 0.85rem;
	border-color: transparent;
	border-radius: var(--sv-radius-sm);
	color: var(--sv-color-muted);
	font-weight: 600;
	white-space: nowrap;
}

.sv-posts__filters--tabs .sv-posts__filter:is(:hover, :focus-visible) {
	border-color: transparent;
	color: var(--sv-color-text);
}

.sv-posts__filters--tabs .sv-posts__filter[aria-current="page"] {
	border-color: color-mix(in srgb, var(--sv-color-text) 14%, transparent);
	background: color-mix(in srgb, var(--sv-color-text) 4%, transparent);
	color: var(--sv-color-text);
}

/* Newer · page x of y · Older. */
.sv-posts__pages {
	display: flex;
	flex-wrap: wrap;
	gap: 0.75rem 1.5rem;
	align-items: center;
	justify-content: center;
	margin-block-start: var(--sv-space-sm);
	font-size: var(--sv-size-small);
}

.sv-posts__page {
	padding-block: 0.55rem;
	padding-inline: 1.1rem;
	border: 1px solid var(--sv-color-border);
	border-radius: var(--sv-radius-button, 10px);
	color: var(--sv-color-text);
	font-weight: 600;
	text-decoration: none;
	transition: border-color 0.15s ease, color 0.15s ease;
}

.sv-posts__page:is(:hover, :focus-visible) {
	border-color: var(--sv-accent, var(--sv-color-primary));
	color: var(--sv-accent, var(--sv-color-link));
}

.sv-posts__page-count {
	color: var(--sv-color-muted);
}

/* One article a row with the photo beside (the Simple list design): the photo keeps to a quarter of the row. */
@media (min-width: 768px) {
	.sv-posts--columns-1 .sv-service-card.sv-service-card--look-side[class]:not(:has(.sv-service-card__number)) {
		grid-template-columns: minmax(0, 3fr) minmax(0, 1fr);
	}
}

/*
 * A section whose one element has nothing to show — the Featured article or a list that the blog
 * page's category view leaves out (ADR 0063) — takes no room.
 */
.sv-section:has(> .sv-container > .sv-column:only-child > :is(.sv-posts, .sv-posts-section, .sv-post-featured):only-child:empty) {
	display: none;
}

/* Latest articles (the ready-made section): the heading, the cards, then the button. */
.sv-posts-section {
	display: grid;
	gap: var(--sv-space-md);
}

.sv-posts__action {
	display: flex;
	justify-content: center;
}

.sv-posts__action--start {
	justify-content: flex-start;
}

.sv-posts__action--end {
	justify-content: flex-end;
}

@media (prefers-reduced-motion: reduce) {
	.sv-posts__more::after,
	.sv-posts__filter,
	.sv-posts__page,
	:is(.sv-posts__item--arrow .sv-service-card__title, .sv-post-featured__main--arrow :is(.sv-post-featured__title, .sv-post-featured__rowtitle))::after {
		transition: none;
	}
}

/*
 * Tiles (ADR 0126, service-card/style.css): rows as far apart as the tiles; every second row puts the card before
 * the picture (--sv-tile-swap), a checkerboard. Tablets: one item per row, unless a number per row is chosen there.
 */
.sv-posts--look-tiles .sv-posts__grid {
	row-gap: var(--sv-colgap, var(--sv-space-element, var(--sv-space-md)));
}

.sv-posts--columns-1 .sv-posts__grid > .sv-service-card--look-tiles:nth-of-type(2n),
.sv-posts:not(.sv-posts--columns-1) .sv-posts__grid > .sv-service-card--look-tiles:is(:nth-of-type(4n + 3), :nth-of-type(4n + 4)) {
	--sv-tile-swap: 1;
}

/* Wide screens: two items a row, whatever the number per row — four equal squares (the owner's sample). */
@media (min-width: 1025px) {
	.sv-posts--look-tiles:not(.sv-posts--columns-1) .sv-posts__grid {
		grid-template-columns: repeat(2, minmax(0, 1fr));
	}
}

@media (max-width: 1024px) {
	.sv-posts--look-tiles .sv-posts__grid {
		grid-template-columns: minmax(0, 1fr);
	}

	.sv-posts.sv-posts--look-tiles .sv-posts__grid > .sv-service-card.sv-service-card:nth-of-type(n) {
		--sv-tile-swap: 0;
	}

	.sv-posts.sv-posts--look-tiles .sv-posts__grid > .sv-service-card.sv-service-card:nth-of-type(2n) {
		--sv-tile-swap: 1;
	}
}
