/* Base: tokens, reset, shared components. */

/*
 * Newsreader — a serif drawn for long-form reading on screen, with a variable
 * optical size axis so the same file renders titles and body text correctly.
 * On a site whose entire product is the reading experience, the typeface is
 * not decoration.
 *
 * Self-hosted, latin subset only. Hotlinking Google Fonts sends every visitor's
 * IP to Google, which is a live GDPR problem for an ad-supported site taking EU
 * traffic — and this site already needs a consent CMP without adding to it.
 *
 * font-display: optional is deliberate. It guarantees ZERO layout shift: the
 * browser uses Newsreader only if it arrives before first paint, otherwise it
 * renders Georgia and caches the font for the next visit. `swap` would show the
 * font sooner but reflow the whole story mid-read, and CLS costs both search
 * ranking and ad viewability. Returning readers — the ones worth having — get
 * Newsreader from cache on every visit after the first.
 *
 * The italic face is declared but not preloaded: browsers only fetch it if a
 * page actually renders italic text, so it costs nothing on pages without it.
 */
@font-face {
	font-family: 'Newsreader';
	font-style: normal;
	font-weight: 400 700;
	font-display: optional;
	src: url('../fonts/newsreader-latin.woff2') format('woff2');
	unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA,
		U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191,
		U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}

@font-face {
	font-family: 'Newsreader';
	font-style: italic;
	font-weight: 400 700;
	font-display: optional;
	src: url('../fonts/newsreader-latin-italic.woff2') format('woff2');
	unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA,
		U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191,
		U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}

:root {
	--rd-bg: #fbfaf8;
	--rd-surface: #ffffff;
	--rd-ink: #1c1a17;
	--rd-ink-muted: #6b655d;

	/*
	 * Two border tokens, because they answer to different rules.
	 * --rd-line is decorative (card edges, dividers) and may be subtle.
	 * --rd-line-strong bounds interactive controls: an unselected filter chip
	 * reads as tappable only because of its border, so WCAG 1.4.11 wants 3:1
	 * against the surface. Measured 3.75:1 on white, 3.60:1 on the page bg.
	 */
	--rd-line: #e4dfd7;
	--rd-line-strong: #8a8378;

	--rd-accent: #7a4b2a;
	--rd-accent-ink: #ffffff;
	--rd-focus: #1f6feb;

	--rd-radius: 12px;
	--rd-gap: 1.5rem;
	--rd-measure: 68ch;

	/* Minimum comfortable touch target. */
	--rd-tap: 44px;

	--rd-font-ui: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
	--rd-font-read: 'Newsreader', Georgia, "Iowan Old Style", "Times New Roman", serif;
}

/*
 * Dark palette, applied in two situations:
 *
 *   1. the OS asks for dark AND the reader has not explicitly chosen light
 *   2. the reader has explicitly chosen dark, whatever the OS says
 *
 * The values are repeated rather than shared because CSS has no way to apply
 * one declaration block to two selectors across a media-query boundary. Keep
 * the two lists in sync.
 *
 * An explicit choice must win over the OS: people read in bed with the phone
 * still in light mode, which is exactly when the override matters.
 */
@media (prefers-color-scheme: dark) {
	:root:not([data-rd-theme="light"]) {
		color-scheme: dark;
		--rd-bg: #16150f;
		--rd-surface: #1f1d18;
		--rd-ink: #efe9df;
		--rd-ink-muted: #a49c90;
		--rd-line: #33302a;
		/* 3.49:1 on the card surface, 3.79:1 on the page background. */
		--rd-line-strong: #787167;
		--rd-accent: #d9a273;
		--rd-accent-ink: #1c1a17;
	}
}

:root[data-rd-theme="dark"] {
	color-scheme: dark;
	--rd-bg: #16150f;
	--rd-surface: #1f1d18;
	--rd-ink: #efe9df;
	--rd-ink-muted: #a49c90;
	--rd-line: #33302a;
	--rd-line-strong: #787167;
	--rd-accent: #d9a273;
	--rd-accent-ink: #1c1a17;
}

:root[data-rd-theme="light"] { color-scheme: light; }

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

/*
 * The `hidden` attribute only hides via a UA-stylesheet `display: none`, which
 * ANY author `display` rule silently beats. Several components here are
 * toggled with `hidden` from JS and also carry a `display` rule (the resume
 * prompt, the anchor ad, the continue-reading rail), so without this they stay
 * on screen while the DOM insists they are hidden.
 *
 * Global and !important on purpose: the failure is invisible in code review and
 * only shows up in the browser.
 */
[hidden] { display: none !important; }

body {
	margin: 0;
	background: var(--rd-bg);
	color: var(--rd-ink);
	font-family: var(--rd-font-ui);
	line-height: 1.5;
	-webkit-text-size-adjust: 100%;
	/*
	 * Newsreader carries an optical size axis: letterforms open up and spacing
	 * loosens at body sizes, and tighten at display sizes. Letting the browser
	 * drive it is what stops large titles looking spindly and small text
	 * looking cramped — it is the main reason to use this face over Georgia.
	 */
	font-optical-sizing: auto;
}

img { max-width: 100%; height: auto; display: block; }

a { color: inherit; }

:focus-visible {
	outline: 3px solid var(--rd-focus);
	outline-offset: 2px;
	border-radius: 4px;
}

.screen-reader-text {
	position: absolute;
	width: 1px; height: 1px;
	margin: -1px; padding: 0;
	overflow: hidden;
	clip: rect(0 0 0 0);
	white-space: nowrap;
	border: 0;
}

.rd-skip {
	position: absolute;
	left: -9999px;
	top: 0;
	background: var(--rd-accent);
	color: var(--rd-accent-ink);
	padding: 0.75rem 1rem;
	z-index: 100;
}
.rd-skip:focus { left: 0; }

/* ------------------------------------------------------------- header/footer */

.rd-header {
	border-bottom: 1px solid var(--rd-line);
	background: var(--rd-surface);
}

.rd-header__inner,
.rd-footer__inner {
	max-width: 1180px;
	margin: 0 auto;
	padding: 1rem 1.25rem;
	display: flex;
	align-items: center;
	justify-content: space-between;
	gap: 1rem;
	flex-wrap: wrap;
}

.rd-header__brand {
	margin: 0;
	font-weight: 700;
	font-size: 1.125rem;
	letter-spacing: -0.01em;
}
.rd-header__brand a { text-decoration: none; }

.rd-header__tools {
	display: flex;
	align-items: center;
	gap: 1rem;
	flex-wrap: wrap;
}

/* ------------------------------------------------------------------- search */

.rd-search {
	display: flex;
	align-items: center;
	gap: 0.25rem;
}

.rd-search__input {
	font: inherit;
	font-size: 0.9375rem;
	min-height: var(--rd-tap);
	width: clamp(9rem, 22vw, 15rem);
	padding: 0 0.9rem;
	color: var(--rd-ink);
	background: var(--rd-bg);
	border: 1px solid var(--rd-line-strong);
	border-radius: 999px;
}

.rd-search__input::placeholder { color: var(--rd-ink-muted); }

.rd-search__submit {
	display: inline-flex;
	align-items: center;
	justify-content: center;
	width: var(--rd-tap);
	height: var(--rd-tap);
	padding: 0;
	color: var(--rd-ink);
	background: transparent;
	border: 1px solid transparent;
	border-radius: 50%;
	cursor: pointer;
	transition: background-color 0.16s ease, color 0.16s ease;
}

.rd-search__submit:hover {
	background: var(--rd-accent);
	color: var(--rd-accent-ink);
}

/* -------------------------------------------------------------- theme control */

.rd-theme {
	display: inline-flex;
	align-items: center;
	gap: 0.2rem;
	padding: 0.2rem;
	border: 1px solid var(--rd-line-strong);
	border-radius: 999px;
}

.rd-theme__btn {
	display: inline-flex;
	align-items: center;
	justify-content: center;
	/*
	 * 36px rather than the 44px used elsewhere. These three sit in a segmented
	 * control in the site header where 44px each would dominate the bar; 36
	 * still clears the WCAG 2.5.8 AA minimum of 24px comfortably.
	 */
	min-width: 36px;
	height: 36px;
	padding: 0 0.5rem;
	font: inherit;
	font-size: 0.75rem;
	font-weight: 600;
	color: var(--rd-ink-muted);
	background: transparent;
	border: 0;
	border-radius: 999px;
	cursor: pointer;
	transition: background-color 0.16s ease, color 0.16s ease;
}

.rd-theme__btn:hover { color: var(--rd-ink); }

.rd-theme__btn[aria-pressed="true"] {
	background: var(--rd-accent);
	color: var(--rd-accent-ink);
}

.rd-nav__list,
.rd-footer__list {
	list-style: none;
	display: flex;
	gap: 1.25rem;
	margin: 0;
	padding: 0;
	flex-wrap: wrap;
	font-size: 0.9375rem;
}

.rd-footer {
	margin-top: 4rem;
	border-top: 1px solid var(--rd-line);
	background: var(--rd-surface);
}

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

/* -------------------------------------------------------------------- button */

.rd-button {
	display: inline-block;
	background: var(--rd-accent);
	color: var(--rd-accent-ink);
	border: 1px solid transparent;
	border-radius: 999px;
	padding: 0.7rem 1.5rem;
	font: inherit;
	font-weight: 600;
	text-decoration: none;
	cursor: pointer;
}
.rd-button:hover { filter: brightness(1.08); }

.rd-button--ghost {
	background: transparent;
	color: var(--rd-ink);
	border-color: var(--rd-line-strong);
}

/* ------------------------------------------------------------------ ad slots */

/*
 * Every slot reserves height before the ad resolves. Without this, ads are the
 * dominant source of CLS, which costs ranking and revenue simultaneously.
 */
.rd-ad {
	display: flex;
	flex-direction: column;
	align-items: center;
	justify-content: center;
	gap: 0.35rem;
	width: 100%;
	background: color-mix(in srgb, var(--rd-line) 35%, transparent);
	border-radius: var(--rd-radius);
	overflow: hidden;
}

.rd-ad__label {
	font-size: 0.6875rem;
	letter-spacing: 0.08em;
	text-transform: uppercase;
	color: var(--rd-ink-muted);
}

.rd-ad .adsbygoogle { width: 100%; }

/* --------------------------------------------------------------- anchor ad */

.rd-anchor {
	position: fixed;
	left: 0;
	right: 0;
	bottom: 0;
	z-index: 40;
	display: flex;
	flex-direction: column;
	align-items: center;
	justify-content: center;
	min-height: var(--rd-anchor-h, 100px);
	background: var(--rd-surface);
	border-top: 1px solid var(--rd-line);
	box-shadow: 0 -2px 12px rgb(0 0 0 / 0.08);
}

/*
 * The body reserves matching space, so the anchor never sits on top of the
 * last line of a story. An anchor unit that covers content is both a bad read
 * and an AdSense policy problem.
 */
body.has-rd-anchor { padding-bottom: calc(var(--rd-anchor-h, 100px) + 1rem); }

.rd-anchor__label {
	font-size: 0.625rem;
	letter-spacing: 0.08em;
	text-transform: uppercase;
	color: var(--rd-ink-muted);
}

.rd-anchor__close {
	position: absolute;
	/* Sits above the unit so it never overlaps the ad creative itself. */
	top: -18px;
	right: 8px;
	display: inline-flex;
	align-items: center;
	justify-content: center;
	width: 34px;
	height: 34px;
	padding: 0;
	border-radius: 50%;
	border: 1px solid var(--rd-line-strong);
	background: var(--rd-surface);
	color: var(--rd-ink);
	line-height: 1;
	cursor: pointer;
	transition: background-color 0.16s ease, color 0.16s ease;
}

.rd-anchor__close:hover {
	background: var(--rd-accent);
	color: var(--rd-accent-ink);
}

/* ------------------------------------------------------- archive furniture */

.rd-crumbs {
	display: flex;
	gap: 0.5rem;
	align-items: center;
	margin-bottom: 0.75rem;
	font-size: 0.8125rem;
	color: var(--rd-ink-muted);
}
.rd-crumbs a { color: inherit; }

.rd-intro__body {
	max-width: 62ch;
	color: var(--rd-ink-muted);
	font-size: 1.0625rem;
}

.rd-crosslinks {
	display: flex;
	flex-wrap: wrap;
	align-items: center;
	gap: 0.5rem;
	margin: 0 0 1.75rem;
	font-size: 0.875rem;
}

.rd-crosslinks__label { color: var(--rd-ink-muted); }

.rd-crosslinks__item {
	display: inline-flex;
	align-items: center;
	min-height: var(--rd-tap);
	border: 1px solid var(--rd-line-strong);
	border-radius: 999px;
	padding: 0.35rem 1rem;
	text-decoration: none;
	background: var(--rd-surface);
	transition: color 0.16s ease, border-color 0.16s ease;
}

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

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

@media (max-width: 720px) {
	.rd-header__inner {
		gap: 0.65rem;
	}

	.rd-header__tools {
		width: 100%;
		gap: 0.5rem;
	}

	/* Search takes the remaining row so the theme control stays reachable. */
	.rd-search { flex: 1 1 auto; }
	.rd-search__input { width: 100%; }
}

/* ------------------------------------------------------------------- motion */

@media (prefers-reduced-motion: reduce) {
	*, *::before, *::after {
		animation-duration: 0.01ms !important;
		animation-iteration-count: 1 !important;
		transition-duration: 0.01ms !important;
		scroll-behavior: auto !important;
	}
}
