/* Discovery home: filters, grid, card, rail. */

.rd-discovery {
	max-width: 1180px;
	margin: 0 auto;
	padding: 2rem 1.25rem 3rem;
}

.rd-intro { margin: 0 0 1.75rem; }

.rd-intro__title {
	margin: 0 0 0.4rem;
	font-size: clamp(1.6rem, 4vw, 2.4rem);
	letter-spacing: -0.02em;
	line-height: 1.15;
}

.rd-intro__sub {
	margin: 0;
	color: var(--rd-ink-muted);
	font-size: 1.0625rem;
}

/* ------------------------------------------------------------------ filters */

.rd-filters {
	display: grid;
	gap: 1.25rem;
	margin-bottom: 1.25rem;
}

.rd-filter {
	border: 0;
	margin: 0;
	padding: 0;
	min-width: 0; /* lets the scroll container actually shrink inside a fieldset */
}

.rd-filter__legend {
	padding: 0;
	margin-bottom: 0.5rem;
	font-size: 0.8125rem;
	font-weight: 600;
	letter-spacing: 0.04em;
	text-transform: uppercase;
	color: var(--rd-ink-muted);
}

.rd-chips {
	display: flex;
	flex-wrap: wrap;
	gap: 0.5rem;
}

.rd-chip { position: relative; }

/*
 * The radio stays in the accessibility tree and keeps native keyboard
 * behaviour (arrow keys move within the group); only its paint is replaced.
 */
.rd-chip input {
	position: absolute;
	opacity: 0;
	inset: 0;
	width: 100%;
	height: 100%;
	margin: 0;
	cursor: pointer;
}

/*
 * min-height, not extra padding: the chip must clear 44px as a tap target
 * without the label text growing to match.
 */
.rd-chip__label {
	display: inline-flex;
	align-items: center;
	min-height: var(--rd-tap);
	padding: 0.5rem 1.15rem;
	/* Interactive boundary — needs 3:1, so not the decorative --rd-line. */
	border: 1px solid var(--rd-line-strong);
	border-radius: 999px;
	background: var(--rd-surface);
	font-size: 0.9375rem;
	white-space: nowrap;
	cursor: pointer;
	transition: background-color 0.16s ease, border-color 0.16s ease, color 0.16s ease;
}

.rd-chip:hover .rd-chip__label {
	border-color: var(--rd-accent);
	color: var(--rd-accent);
}

.rd-chip input:checked:hover + .rd-chip__label { color: var(--rd-accent-ink); }

.rd-chip input:checked + .rd-chip__label {
	background: var(--rd-accent);
	color: var(--rd-accent-ink);
	border-color: var(--rd-accent);
	/* Selected state is carried by the radio itself, not by colour alone. */
	font-weight: 600;
}

.rd-chip input:focus-visible + .rd-chip__label {
	outline: 3px solid var(--rd-focus);
	outline-offset: 2px;
}

.rd-count {
	margin: 0 0 1rem;
	color: var(--rd-ink-muted);
	font-size: 0.875rem;
}

/* --------------------------------------------------------------------- grid */

/*
 * Larger tiles: 3 across in the 1180px container rather than 4.
 * The card has to carry a reading-time badge, a title and a 2-3 line hook, and
 * at 280px the hook was clipping to the point of being useless — the blurb is
 * the thing that makes the grid scannable in one pass (spec 4).
 */
.rd-grid {
	display: grid;
	gap: var(--rd-gap);
	grid-template-columns: repeat(auto-fill, minmax(330px, 1fr));
}

.rd-grid[data-loading="true"] { opacity: 0.55; }

.rd-grid__ad {
	grid-column: 1 / -1;
}

.rd-grid__ad--placeholder {
	min-height: 280px;
	background: color-mix(in srgb, var(--rd-line) 35%, transparent);
	border-radius: var(--rd-radius);
}

/* --------------------------------------------------------------------- card */

.rd-card {
	background: var(--rd-surface);
	border: 1px solid var(--rd-line);
	border-radius: var(--rd-radius);
	overflow: hidden;
	transition: transform 0.14s ease, box-shadow 0.14s ease;
}

.rd-card:hover {
	transform: translateY(-2px);
	box-shadow: 0 6px 20px rgb(0 0 0 / 0.07);
}

/* Whole card is one link: one tab stop, click anywhere (spec 4). */
.rd-card__link {
	display: block;
	text-decoration: none;
	color: inherit;
	height: 100%;
	cursor: pointer;
}

/*
 * The card clips its children (overflow: hidden, for the image corners), which
 * also clips a focus ring drawn on the link inside it — leaving keyboard users
 * with no visible focus at all. Draw the ring on the card instead.
 */
.rd-card:has(.rd-card__link:focus-visible) {
	outline: 3px solid var(--rd-focus);
	outline-offset: 2px;
}

.rd-card__link:focus-visible { outline: none; }

/* Fallback where :has() is unavailable. */
@supports not (selector(:has(*))) {
	.rd-card:focus-within {
		outline: 3px solid var(--rd-focus);
		outline-offset: 2px;
	}
}

.rd-card__media {
	aspect-ratio: 16 / 9;
	background: var(--rd-line);
}
.rd-card__media img {
	width: 100%;
	height: 100%;
	object-fit: cover;
}

.rd-card__body { padding: 1.35rem 1.45rem 1.55rem; }

/* Reading time is the primary scan cue, so it leads the card. */
.rd-card__time {
	display: flex;
	align-items: center;
	gap: 0.35rem;
	margin: 0 0 0.5rem;
	font-size: 0.8125rem;
	font-weight: 600;
	letter-spacing: 0.02em;
	color: var(--rd-accent);
}

.rd-icon { width: 0.95em; height: 0.95em; flex: none; }

.rd-card__title {
	margin: 0 0 0.45rem;
	/* Story titles are content, not chrome — same voice as the reader. */
	font-family: var(--rd-font-read);
	font-size: 1.45rem;
	font-weight: 600;
	line-height: 1.22;
	letter-spacing: -0.015em;
	text-wrap: balance;
	/* Spec 4: truncate past ~2 lines on narrow cards. */
	display: -webkit-box;
	-webkit-line-clamp: 2;
	-webkit-box-orient: vertical;
	overflow: hidden;
}

.rd-card__hook {
	margin: 0 0 0.9rem;
	color: var(--rd-ink-muted);
	font-size: 1rem;
	line-height: 1.5;
	display: -webkit-box;
	-webkit-line-clamp: 3;
	-webkit-box-orient: vertical;
	overflow: hidden;
	text-wrap: pretty;
}

/* Moods are secondary to the time badge - muted and small. */
.rd-card__moods {
	display: flex;
	flex-wrap: wrap;
	gap: 0.35rem;
	margin: 0;
}

.rd-card__mood {
	font-size: 0.75rem;
	color: var(--rd-ink-muted);
	border: 1px solid var(--rd-line);
	border-radius: 999px;
	padding: 0.15rem 0.55rem;
}

.rd-card__progress { margin-top: 0.85rem; }

.rd-card__bar {
	height: 3px;
	border-radius: 999px;
	background: var(--rd-line);
	overflow: hidden;
}

.rd-card__bar-fill {
	display: block;
	height: 100%;
	background: var(--rd-accent);
}

.rd-card__status {
	margin: 0.4rem 0 0;
	font-size: 0.8125rem;
	font-weight: 600;
	color: var(--rd-accent);
}

.rd-card.is-finished .rd-card__status { color: var(--rd-ink-muted); }

/* --------------------------------------------------------------------- rail */

.rd-rail { margin-bottom: 2.25rem; }

.rd-rail__heading {
	margin: 0 0 0.85rem;
	font-size: 1.0625rem;
	letter-spacing: -0.01em;
}

.rd-rail__track {
	display: grid;
	grid-auto-flow: column;
	grid-auto-columns: minmax(260px, 300px);
	gap: 1rem;
	overflow-x: auto;
	padding-bottom: 0.5rem;
	scroll-snap-type: x mandatory;
	overscroll-behavior-x: contain;
}
.rd-rail__track > * { scroll-snap-align: start; }

/* ------------------------------------------------------------ empty/surprise */

.rd-empty {
	text-align: center;
	padding: 3.5rem 1rem;
}

.rd-empty__message {
	margin: 0 0 1.25rem;
	font-size: 1.125rem;
	color: var(--rd-ink-muted);
}

.rd-surprise {
	margin-top: 2.5rem;
	text-align: center;
}

.rd-surprise__note {
	margin: 0.6rem 0 0;
	font-size: 0.875rem;
	color: var(--rd-ink-muted);
}

/* --------------------------------------------------------------- responsive */

/* Spec 7: on mobile the chip rows scroll sideways instead of eating vertical
   space above the fold. */
@media (max-width: 640px) {
	.rd-chips {
		flex-wrap: nowrap;
		overflow-x: auto;
		padding-bottom: 0.35rem;
		scrollbar-width: none;
		overscroll-behavior-x: contain;
	}
	.rd-chips::-webkit-scrollbar { display: none; }

	/*
	 * One column on a phone. With the larger tile the hook stays readable
	 * instead of clipping to a single line, and the spec puts the reader view
	 * first on mobile anyway — the grid's job here is to get out of the way.
	 */
	.rd-grid {
		grid-template-columns: 1fr;
		gap: 1rem;
	}

	.rd-card__body { padding: 1.1rem 1.2rem 1.25rem; }
	.rd-card__title { font-size: 1.3rem; }
}

/* Tablets and small laptops: two across. */
@media (min-width: 641px) and (max-width: 900px) {
	.rd-grid { grid-template-columns: repeat(2, 1fr); }
}
