/*
 * Related Posts CTA
 *
 * The section takes its look from the theme: fonts and text color are inherited, the heading keeps
 * the theme's own h2 style, and the background is a light tint of the text color, so it suits both
 * light and dark themes. With theme.json (block themes and some classic ones) the plugin also sets
 * the variables below to the theme's link color, heading color and heading font (class-rpcta-theme.php).
 *
 * Override any variable in the theme or in Additional CSS, e.g. for a dark band:
 * .rpcta { --rpcta-bg: #2b2d42; --rpcta-text: #fff; --rpcta-heading: #fff; --rpcta-accent: #ef8354; }
 */

/* Defaults. :where() has no specificity, so any .rpcta { … } rule overrides them. */
:where(.rpcta) {
	--rpcta-bg: color-mix(in srgb, currentColor 6%, transparent);
	--rpcta-bg-edge: var(--rpcta-bg);    /* a different color makes the band a gradient */
	--rpcta-text: currentColor;          /* the theme's text color */
	--rpcta-heading: var(--rpcta-text);
	--rpcta-muted: var(--rpcta-text);    /* the line under the heading */
	--rpcta-accent: var(--rpcta-text);   /* hover and focus */
	--rpcta-thumb-bg: color-mix(in srgb, currentColor 10%, transparent);
	--rpcta-tooltip-bg: #1e1e1e;
	--rpcta-tooltip-text: #ffffff;       /* 16.7:1 on the tooltip background */
	--rpcta-radius: 16px;
	--rpcta-thumb-radius: 8px;
	/* --rpcta-title-font and --rpcta-title-weight have no default: the titles keep the text font, weight 600. */
}

.rpcta {
	box-sizing: border-box;
	clear: both;
	margin: 3em 0 1.5em;
	padding: clamp(1.5em, 4vw, 2.5em);
	border-radius: var(--rpcta-radius);
	background: linear-gradient(160deg, var(--rpcta-bg) 55%, var(--rpcta-bg-edge) 100%);
	color: var(--rpcta-text);
	font-family: inherit;
}

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

/* Header */
.rpcta .rpcta__header {
	margin: 0 0 1.5em;
	max-width: 38em;
}

/* Font, size and weight come from the theme's h2 style; only the spacing is reset. */
.rpcta .rpcta__title {
	margin: 0;
	padding: 0;
	border: 0;
	color: var(--rpcta-heading);
}

.rpcta .rpcta__intro {
	margin: 0.5em 0 0;
	color: var(--rpcta-muted);
}

/* List */
.rpcta .rpcta__list {
	display: grid;
	grid-template-columns: repeat(auto-fill, minmax(min(100%, 12.5em), 1fr));
	gap: 1.5em 1.25em;
	margin: 0;
	padding: 0;
	list-style: none;
}

.rpcta .rpcta__item {
	margin: 0;
	padding: 0;
	list-style: none;
}

.rpcta .rpcta__item::before,
.rpcta .rpcta__item::marker {
	content: none;
}

/* Link (the whole item is clickable) */
.rpcta a.rpcta__link {
	position: relative;
	display: flex;
	flex-direction: column;
	gap: 0.75em;
	color: var(--rpcta-text);
	text-decoration: none;
	border: 0;
	box-shadow: none;
	background: none;
}

.rpcta a.rpcta__link:focus {
	outline: none;
}

.rpcta a.rpcta__link:focus-visible {
	outline: 3px solid var(--rpcta-accent);
	outline-offset: 4px;
	border-radius: var(--rpcta-thumb-radius);
}

/* Thumbnail */
.rpcta .rpcta__thumb {
	display: block;
	position: relative;
	aspect-ratio: 16 / 10;
	overflow: hidden;
	border-radius: var(--rpcta-thumb-radius);
	background: var(--rpcta-thumb-bg);
}

.rpcta .rpcta__img {
	display: block;
	width: 100%;
	height: 100%;
	max-width: none;
	margin: 0;
	object-fit: cover;
	transition: transform 0.35s ease;
}

.rpcta .rpcta__placeholder {
	display: flex;
	align-items: center;
	justify-content: center;
	width: 100%;
	height: 100%;
	color: var(--rpcta-accent);
	font-size: 3em;
	font-weight: 700;
	line-height: 1;
	text-transform: uppercase;
}

/* Title. Without --rpcta-title-font the font-family is unset, i.e. inherited from the text. */
.rpcta .rpcta__name {
	display: -webkit-box;
	-webkit-box-orient: vertical;
	-webkit-line-clamp: 3;
	overflow: hidden;
	font-family: var(--rpcta-title-font);
	font-size: 1.0625em;
	font-weight: var(--rpcta-title-weight, 600);
	line-height: 1.35;
	text-decoration: underline;
	text-decoration-color: transparent;
	text-decoration-thickness: 2px;
	text-underline-offset: 0.2em;
	transition: text-decoration-color 0.2s ease;
}

/* Hover / focus: the title gets an accent underline, the image zooms slightly */
.rpcta a.rpcta__link:hover .rpcta__name,
.rpcta a.rpcta__link:focus-visible .rpcta__name {
	text-decoration-color: var(--rpcta-accent);
}

.rpcta a.rpcta__link:hover .rpcta__img,
.rpcta a.rpcta__link:focus-visible .rpcta__img {
	transform: scale(1.04);
}

/*
 * Tooltip with the full title (the name is clamped to 3 lines).
 * It floats over the image, its bottom edge just above the title, and long titles grow upwards.
 * Percentage margins resolve against the width, so 62.5% (10 / 16) is the thumbnail height.
 * Absolutely positioned and inset from the sides, so it never shifts the layout or leaves the item.
 */
.rpcta .rpcta__tooltip {
	position: absolute;
	z-index: 2;
	top: 0;
	left: 0.5em;
	right: 0.5em;
	margin-top: calc(62.5% - 0.5em);
	padding: 0.5em 0.75em;
	border-radius: 6px;
	background: var(--rpcta-tooltip-bg);
	color: var(--rpcta-tooltip-text);
	box-shadow: 0 6px 18px rgba(0, 0, 0, 0.35);
	font-size: 0.875em;
	font-weight: 500;
	line-height: 1.4;
	text-align: left;
	overflow-wrap: anywhere;
	pointer-events: none;
	visibility: hidden;
	opacity: 0;
	transform: translateY(calc(-100% + 0.25em));
	transition: opacity 0.15s ease, transform 0.15s ease, visibility 0s linear 0.15s;
}

/* Arrow pointing down to the title */
.rpcta .rpcta__tooltip::after {
	content: "";
	position: absolute;
	top: 100%;
	left: 1em;
	border: 6px solid transparent;
	border-top-color: var(--rpcta-tooltip-bg);
}

.rpcta a.rpcta__link:hover .rpcta__tooltip,
.rpcta a.rpcta__link:focus-visible .rpcta__tooltip {
	visibility: visible;
	opacity: 1;
	transform: translateY(-100%);
	transition-delay: 0s;
}

/* Touch screens: a tap opens the link, so there is no hover to show the tooltip on */
@media (hover: none) {
	.rpcta .rpcta__tooltip {
		display: none;
	}
}

@media (prefers-reduced-motion: reduce) {
	.rpcta .rpcta__img,
	.rpcta .rpcta__name,
	.rpcta .rpcta__tooltip {
		transition: none;
	}

	.rpcta a.rpcta__link:hover .rpcta__img,
	.rpcta a.rpcta__link:focus-visible .rpcta__img {
		transform: none;
	}
}

@media print {
	.rpcta {
		display: none;
	}
}
