/* Post Grid (docs/widgets/post-grid.md), in Soft, the default design (spec §3.7). The other
   designs change only the --hafe-posts-d-* tokens below, so a Style control always wins.

   Each card stacks its own parts, with no room held for a part it doesn't show (owner,
   2026-11-16). Cards in a row are as tall as the tallest, "Read more" level at their foot. */
.hafe-posts {
	--hafe-posts-d-bg: var(--hafe-surface);
	--hafe-posts-d-line: var(--hafe-line);
	--hafe-posts-d-hover-line: var(--hafe-line);
	--hafe-posts-d-shadow: var(--hafe-shadow);
	--hafe-posts-d-shadow-up: var(--hafe-shadow-up);
	--hafe-posts-d-radius: var(--hafe-radius);
	--hafe-posts-d-mat: 0px;
	--hafe-posts-d-image-radius: 0px;
	--hafe-posts-d-tile: var(--hafe-tint);
	--hafe-posts-d-badge-bg: var(--hafe-tint);
	--hafe-posts-d-badge-ink: var(--hafe-accent-ink);
	--hafe-posts-d-badge-line: transparent;
	--hafe-posts-d-page-bg: var(--hafe-surface);
	--hafe-posts-d-page-ink: var(--hafe-ink);
	--hafe-posts-d-page-line: var(--hafe-line);
	--hafe-posts-d-now-bg: var(--hafe-accent);
	--hafe-posts-d-now-ink: var(--hafe-on-accent);
	--hafe-posts-d-load-bg: var(--hafe-tint);
	--hafe-posts-d-load-ink: var(--hafe-accent-ink);
	--hafe-posts-d-load-line: transparent;
	--hafe-posts-pad: var(--hafe-posts-padding, 1.5em);
	position: relative;
	color: var(--hafe-ink);
	/* A page link opens at the grid (#its-id): a little room above it, for a fixed header. */
	scroll-margin-top: 5rem;
}

.hafe-posts__items {
	display: grid;
	grid-template-columns: repeat(var(--hafe-posts-columns, 3), minmax(0, 1fr));
	gap: var(--hafe-posts-gap, 1.5rem);
	margin: 0;
	padding: 0;
	list-style: none;
}

.hafe-posts__item {
	display: flex;
	min-inline-size: 0;
	margin: 0;
	padding: 0;
}

.hafe-posts__card {
	position: relative;
	display: flex;
	flex: 1;
	flex-direction: column;
	min-inline-size: 0;
	box-sizing: border-box;
	margin: 0;
	padding: 0 var(--hafe-posts-pad) var(--hafe-posts-pad);
	overflow: clip;
	border: var(--hafe-posts-line-width, 1px) solid var(--hafe-posts-line, var(--hafe-posts-d-line));
	border-radius: var(--hafe-posts-radius, var(--hafe-posts-d-radius));
	background: var(--hafe-posts-bg, var(--hafe-posts-d-bg));
	box-shadow: var(--hafe-posts-d-shadow);
	transition: border-color 0.2s;
}

.hafe-posts--image-none .hafe-posts__card {
	padding-block-start: var(--hafe-posts-pad);
}

.hafe-posts__card:hover {
	border-color: var(--hafe-posts-hover-line, var(--hafe-posts-line, var(--hafe-posts-d-hover-line)));
}

/* The image, cropped to its shape; a quiet tile of the same shape for a post without one. */
.hafe-posts__media {
	position: relative;
	flex: none;
	aspect-ratio: var(--hafe-posts-ratio, 3 / 2);
	/* Across the card, out to its edges, or inside them by the design's mat. */
	margin: var(--hafe-posts-d-mat) calc(var(--hafe-posts-d-mat) - var(--hafe-posts-pad)) var(--hafe-posts-pad);
	overflow: hidden;
	border-radius: var(--hafe-posts-image-radius, var(--hafe-posts-d-image-radius));
	background: var(--hafe-posts-tile, var(--hafe-posts-d-tile));
}

.hafe-posts__frame {
	display: block;
	block-size: 100%;
}

.hafe-posts .hafe-posts__image {
	display: block;
	inline-size: 100%;
	block-size: 100%;
	max-inline-size: none;
	margin: 0;
	border-radius: 0;
	object-fit: cover;
}

/* The text, its parts one under another; "Read more" at the foot. */
.hafe-posts__body {
	display: flex;
	flex: 1;
	flex-direction: column;
	min-inline-size: 0;
}

.hafe-posts .hafe-posts__tax,
.hafe-posts .hafe-posts__title,
.hafe-posts .hafe-posts__meta,
.hafe-posts .hafe-posts__excerpt,
.hafe-posts .hafe-posts__action {
	margin: 0;
	overflow-wrap: break-word;
}

.hafe-posts .hafe-posts__tax {
	margin-block-end: 0.75em;
}

.hafe-posts__badge {
	display: inline-block;
	padding: 0.3em 0.8em;
	border: 1px solid var(--hafe-posts-d-badge-line);
	border-radius: var(--hafe-pill);
	background: var(--hafe-posts-badge-bg, var(--hafe-posts-d-badge-bg));
	color: var(--hafe-posts-badge-ink, var(--hafe-posts-d-badge-ink));
	font-size: 0.8125em;
	font-weight: 600;
	line-height: 1.3;
}

.hafe-posts__badge--over {
	position: absolute;
	inset-block-start: 0.75rem;
	inset-inline-start: 0.75rem;
	max-inline-size: calc(100% - 1.5rem);
	box-sizing: border-box;
}

.hafe-posts .hafe-posts__title {
	color: var(--hafe-posts-title-color, var(--hafe-ink));
	font-size: 1.1875em;
	font-weight: 600;
	line-height: 1.3;
}

.hafe-posts .hafe-posts__title a {
	color: inherit;
	text-decoration: none;
}

.hafe-posts .hafe-posts__title a:hover,
.hafe-posts--card .hafe-posts__card:hover .hafe-posts__title a {
	color: var(--hafe-posts-title-hover, var(--hafe-posts-title-color, var(--hafe-ink)));
	text-decoration: underline;
	text-decoration-thickness: 1px;
	text-underline-offset: 0.2em;
}

.hafe-posts .hafe-posts__meta {
	display: flex;
	flex-wrap: wrap;
	/* Each detail has its dot in the space before it; the start of every line is clipped, so a line
	   never begins with a dot. */
	margin-block-start: 0.5em;
	margin-inline-start: -1em;
	clip-path: inset(0 0 0 1em);
	color: var(--hafe-posts-meta-color, var(--hafe-ink-soft));
	/* Well below the text (four fifths of it) and in italics, so it reads as details (owner,
	   2026-11-16). */
	font-size: 0.75em;
	font-style: italic;
	line-height: 1.5;
}

.hafe-posts__detail {
	position: relative;
	margin-inline-start: 1em;
}

.hafe-posts__detail::before {
	content: "·" / "";
	position: absolute;
	inset-inline-start: -0.65em;
}

.hafe-posts .hafe-posts__meta:dir(rtl) {
	clip-path: inset(0 1em 0 0);
}

.hafe-posts .hafe-posts__excerpt {
	margin-block-start: 0.75em;
	color: var(--hafe-posts-excerpt-color, var(--hafe-ink-soft));
	font-size: 0.9375em;
	line-height: 1.6;
}

.hafe-posts .hafe-posts__action {
	margin-block-start: auto;
	padding-block-start: 1.25em;
}

.hafe-posts .hafe-posts__more {
	color: var(--hafe-posts-more-color, var(--hafe-accent-ink));
	font-size: 0.9375em;
	font-weight: 600;
	text-decoration: none;
}

.hafe-posts .hafe-posts__more::after {
	content: "→" / "";
	display: inline-block;
	margin-inline-start: 0.4em;
	transition: transform 0.2s;
}

/* Arrow characters don't turn round right to left. */
.hafe-posts .hafe-posts__more:dir(rtl)::after {
	content: "←" / "";
	--hafe-posts-nudge: -0.2em;
}

.hafe-posts .hafe-posts__more:hover,
.hafe-posts--card .hafe-posts__card:hover .hafe-posts__more {
	text-decoration: underline;
	text-underline-offset: 0.2em;
}

/* The whole card as the link: the title's link covers it, and the card shows the keyboard's ring. */
.hafe-posts--card .hafe-posts__link--card::after {
	content: "";
	position: absolute;
	inset: 0;
	z-index: 1;
}

.hafe-posts.hafe-posts--card .hafe-posts__link--card:focus-visible {
	outline: none;
}

.hafe-posts--card .hafe-posts__card:has(.hafe-posts__link--card:focus-visible) {
	outline: 2px solid var(--hafe-accent);
	outline-offset: 2px;
}

/* Hover effects move the card, so they're for a mouse, and for visitors happy with motion. */
@media (hover: hover) and (prefers-reduced-motion: no-preference) {
	.hafe-posts-hover-lift .hafe-posts__card,
	.hafe-posts-hover-grow .hafe-posts__card {
		transition: transform 0.2s ease, box-shadow 0.2s ease, border-color 0.2s;
	}

	.hafe-posts-hover-lift .hafe-posts__card:is(:hover, :has(:focus-visible)) {
		box-shadow: var(--hafe-posts-d-shadow-up);
		transform: translateY(-0.1em);
	}

	.hafe-posts-hover-grow .hafe-posts__card:is(:hover, :has(:focus-visible)) {
		transform: scale(1.015);
	}

	.hafe-posts__card:hover .hafe-posts__more::after {
		transform: translateX(var(--hafe-posts-nudge, 0.2em));
	}
}

/* The image beside the text, inside the card's padding; above it once the card is narrow. */
.hafe-posts--image-side .hafe-posts__item {
	container-type: inline-size;
}

.hafe-posts--image-side .hafe-posts__card {
	flex-direction: row;
	column-gap: var(--hafe-posts-pad);
	align-items: flex-start;
	padding-block-start: var(--hafe-posts-pad);
}

.hafe-posts--image-side .hafe-posts__media {
	flex: 0 0 var(--hafe-posts-image-width, 40%);
	margin: 0;
	border-radius: var(--hafe-posts-image-radius, var(--hafe-radius-sm));
}

.hafe-posts--image-side .hafe-posts__body {
	align-self: stretch;
}

@container (max-width: 28rem) {
	.hafe-posts--image-side .hafe-posts__card {
		flex-direction: column;
		align-items: stretch;
	}

	.hafe-posts--image-side .hafe-posts__media {
		flex-basis: auto;
		margin: 0 0 var(--hafe-posts-pad);
	}
}

/* More posts: numbered pages, or "Load more". */
.hafe-posts__pages,
.hafe-posts .hafe-posts__load-row {
	display: flex;
	justify-content: var(--hafe-posts-pages-align, center);
	margin: 2rem 0 0;
}

.hafe-posts__numbers {
	display: flex;
	flex-wrap: wrap;
	align-items: center;
	justify-content: inherit;
	gap: 0.5rem;
	margin: 0;
	padding: 0;
	list-style: none;
}

/* Hovered and focused too (spec §4). */
.hafe-posts .hafe-posts__page,
.hafe-posts .hafe-posts__page:is(:hover, :focus) {
	display: inline-flex;
	align-items: center;
	justify-content: center;
	box-sizing: border-box;
	min-inline-size: 2.5em;
	min-block-size: 2.5em;
	padding: 0 0.75em;
	border: 1px solid var(--hafe-posts-d-page-line);
	border-radius: var(--hafe-pill);
	background: var(--hafe-posts-page-bg, var(--hafe-posts-d-page-bg));
	box-shadow: none;
	color: var(--hafe-posts-page-ink, var(--hafe-posts-d-page-ink));
	font-size: 0.9375em;
	font-weight: 600;
	line-height: 1;
	text-decoration: none;
	transition: background-color 0.15s, border-color 0.15s;
}

/* Linkless buttons, without the theme's button look. */
.hafe-posts button.hafe-posts__page,
.hafe-posts button.hafe-posts__load {
	margin: 0;
	font-family: inherit;
	letter-spacing: inherit;
	text-transform: none;
	cursor: pointer;
}

.hafe-posts .hafe-posts__page:not(.is-current):hover {
	border-color: var(--hafe-accent);
}

.hafe-posts .hafe-posts__page.is-current {
	border-color: transparent;
	background: var(--hafe-posts-now-bg, var(--hafe-posts-d-now-bg));
	color: var(--hafe-posts-now-ink, var(--hafe-posts-d-now-ink));
	cursor: default;
}

.hafe-posts__gap {
	color: var(--hafe-ink-soft);
}

.hafe-posts .hafe-posts__load,
.hafe-posts .hafe-posts__load:is(:hover, :focus) {
	display: inline-block;
	padding: 0.75em 1.6em;
	border: 1px solid var(--hafe-posts-d-load-line);
	border-radius: var(--hafe-pill);
	background: var(--hafe-posts-now-bg, var(--hafe-posts-d-load-bg));
	box-shadow: none;
	color: var(--hafe-posts-now-ink, var(--hafe-posts-d-load-ink));
	font-size: 0.9375em;
	font-weight: 600;
	line-height: 1.3;
	text-decoration: none;
	cursor: pointer;
	transition: background-color 0.15s, filter 0.15s;
}

.hafe-posts .hafe-posts__load:hover {
	filter: brightness(0.95);
}

.hafe-posts.is-loading .hafe-posts__load {
	opacity: 0.6;
	cursor: progress;
}

.hafe-posts.is-loading .hafe-posts__items {
	opacity: 0.6;
}

/* Linkless buttons wait for the script. */
.hafe-posts .hafe-posts__pages[hidden],
.hafe-posts .hafe-posts__load-row[hidden] {
	display: none;
}

.hafe-posts .hafe-posts__page:focus-visible,
.hafe-posts .hafe-posts__load:focus-visible,
.hafe-posts .hafe-posts__link:focus-visible {
	outline: 2px solid var(--hafe-accent);
	outline-offset: 2px;
}

/* Read by screen readers only. Inside the positioned card, so it never widens the page. */
.hafe-posts__sr {
	position: absolute;
	inline-size: 1px;
	block-size: 1px;
	margin: -1px;
	padding: 0;
	overflow: hidden;
	clip: rect(0 0 0 0);
	white-space: nowrap;
	border: 0;
}

.hafe-posts .hafe-posts__status {
	margin: 0;
}

@media print {
	.hafe-posts__pages,
	.hafe-posts__load-row {
		display: none;
	}
}
