/* @link https://utopia.fyi/type/calculator?c=320,16,1.2,1240,18,1.25,3,2,&s=0.75|0.5|0.25,1.5|2|3|4|6,s-l&g=s,l,xl,12 */

:root {
	/* Step -2: 11.11px → 11.52px */
	--step--2: clamp(0.6944rem, 0.6855rem + 0.0446vw, 0.72rem);

	/* Step -1: 13.33px → 14.40px */
	--step--1: clamp(0.8331rem, 0.8099rem + 0.1163vw, 0.9rem);

	/* Step 0: 16.00px → 18.00px */
	--step-0: clamp(1rem, 0.9565rem + 0.2174vw, 1.125rem);

	/* Step 1: 19.20px → 22.50px */
	--step-1: clamp(1.2rem, 1.1283rem + 0.3587vw, 1.4063rem);

	/* Step 2: 23.04px → 28.13px */
	--step-2: clamp(1.44rem, 1.3293rem + 0.5533vw, 1.7581rem);

	/* Step 3: 27.65px → 35.16px */
	--step-3: clamp(1.7281rem, 1.5649rem + 0.8163vw, 2.1975rem);
}

/* @link https://utopia.fyi/space/calculator?c=320,16,1.2,1240,18,1.25,3,2,&s=0.75|0.5|0.25,1.5|2|3|4|6,s-l&g=s,l,xl,12 */

:root {
	/* Space 3xs: 4px → 5px */
	--space-3xs: clamp(0.25rem, 0.2283rem + 0.1087vw, 0.3125rem);

	/* Space 2xs: 8px → 9px */
	--space-2xs: clamp(0.5rem, 0.4783rem + 0.1087vw, 0.5625rem);

	/* Space xs: 12px → 14px */
	--space-xs: clamp(0.75rem, 0.7065rem + 0.2174vw, 0.875rem);

	/* Space s: 16px → 18px */
	--space-s: clamp(1rem, 0.9565rem + 0.2174vw, 1.125rem);

	/* Space m: 24px → 27px */
	--space-m: clamp(1.5rem, 1.4348rem + 0.3261vw, 1.6875rem);

	/* Space l: 32px → 36px */
	--space-l: clamp(2rem, 1.913rem + 0.4348vw, 2.25rem);

	/* Space xl: 48px → 54px */
	--space-xl: clamp(3rem, 2.8696rem + 0.6522vw, 3.375rem);

	/* Space 2xl: 64px → 72px */
	--space-2xl: clamp(4rem, 3.8261rem + 0.8696vw, 4.5rem);

	/* Space 3xl: 96px → 108px */
	--space-3xl: clamp(6rem, 5.7391rem + 1.3043vw, 6.75rem);

	/* One-up pairs */
	/* Space 3xs-2xs: 4px → 9px */
	--space-3xs-2xs: clamp(0.25rem, 0.1413rem + 0.5435vw, 0.5625rem);

	/* Space 2xs-xs: 8px → 14px */
	--space-2xs-xs: clamp(0.5rem, 0.3696rem + 0.6522vw, 0.875rem);

	/* Space xs-s: 12px → 18px */
	--space-xs-s: clamp(0.75rem, 0.6196rem + 0.6522vw, 1.125rem);

	/* Space s-m: 16px → 27px */
	--space-s-m: clamp(1rem, 0.7609rem + 1.1957vw, 1.6875rem);

	/* Space m-l: 24px → 36px */
	--space-m-l: clamp(1.5rem, 1.2391rem + 1.3043vw, 2.25rem);

	/* Space l-xl: 32px → 54px */
	--space-l-xl: clamp(2rem, 1.5217rem + 2.3913vw, 3.375rem);

	/* Space xl-2xl: 48px → 72px */
	--space-xl-2xl: clamp(3rem, 2.4783rem + 2.6087vw, 4.5rem);

	/* Space 2xl-3xl: 64px → 108px */
	--space-2xl-3xl: clamp(4rem, 3.0435rem + 4.7826vw, 6.75rem);

	/* Custom pairs */
	/* Space s-l: 16px → 36px */
	--space-s-l: clamp(1rem, 0.5652rem + 2.1739vw, 2.25rem);
}

/* Colors */
:root {
	--bg-color: #fffff3;
	--text-color: #1c1c1c;
	--text-muted: color-mix(in srgb, var(--text-color) 72%, var(--bg-color) 28%);
	--link-color: #af2e1b;
	--link-decoration: black;
	--paper-opacity: 0.75;
}

/* Dark mode styles (respect user preference) */
@media (prefers-color-scheme: dark) {
	:root {
		--bg-color: #292722;
		--text-color: #b6b3ac;
		--text-muted: color-mix(
			in srgb,
			var(--text-color) 72%,
			var(--bg-color) 28%
		);
		--link-color: #c9776c;
		--link-decoration: white;
		--paper-opacity: 0;
	}

	img[src$="fleuron_opt.svg"] {
		filter: invert(82%) sepia(5%) saturate(250%) hue-rotate(2deg)
			brightness(92%) contrast(88%);
	}
}

@font-face {
	font-family: "Besley";
	src: url("/fonts/Besley-VariableFont_wght.woff2") format("woff2");
	font-weight: 400 800;
	font-style: normal;
	font-display: swap;
}

@font-face {
	font-family: "Besley";
	src: url("/fonts/Besley-Italic-VariableFont_wght.woff2") format("woff2");
	font-weight: 400 800;
	font-style: italic;
	font-display: swap;
}

html {
	/* Keep a flat page hue as a fallback if images are blocked */
	background-color: var(--bg-color);
	scroll-behavior: smooth;
	-webkit-font-smoothing: antialiased;
	text-rendering: optimizeLegibility;
	/* Let form controls, scrollbars, etc. adapt to theme */
	color-scheme: light dark;
}

/* Full-viewport paper texture placed behind content using a pseudo-element.
   This is more reliable than relying on background-blend-mode and ensures
   the texture appears underneath the `.page` element. */
body::before {
	content: "";
	position: fixed;
	inset: 0;
	z-index: -1;
	pointer-events: none;
	background-image: url("/img/paper.webp");
	background-repeat: no-repeat;
	background-position: center top;
	background-size: cover;
	/* Make the texture subtle */
	opacity: var(--paper-opacity);
	backdrop-filter: none;
}

body {
	width: 100%;
	margin: 0;
	font-family: "Besley", Georgia, "Times New Roman", Times, serif;
	font-weight: 450;
	font-size: var(--step-0);
	color: var(--text-color);
}

.page {
	margin: var(--space-s) auto;
	max-width: 70ch;
}

.content {
	margin: 0 var(--space-s);
}

address {
	font-style: normal;
}

sup {
	font-size: 0.7em;
	line-height: 1;
}

a {
	text-decoration-line: underline;
	text-decoration-thickness: 1px;
	text-underline-offset: 2px;
	text-decoration-color: var(--link-decoration);
	color: var(--link-color);
}

a:hover {
	text-decoration-thickness: 2px;
	text-decoration-color: color-mix(
		in srgb,
		var(--link-decoration),
		transparent 50%
	);
}

a:not(:is(:hover, :focus)) {
	text-decoration-color: color-mix(in srgb, currentColor, transparent 75%);
}

h1 {
	text-align: left;
	font-weight: 800;
	line-height: 1;
	font-size: var(--step-3);
	margin-block-start: var(--space-l);
	margin-block-end: var(--space-2xs);
}

h1 > small {
	font-size: var(--step--1);
	margin-top: 0;
	font-weight: 700;
}

h2 {
	margin: 0;
	margin-block-start: var(--space-l);
	margin-block-end: 0;
	font-size: var(--step-1);
	font-weight: 800;
}

h3 {
	margin-block-start: var(--space-l);
	margin-block-end: var(--space-2xs);
	font-size: var(--step--0);
	font-weight: 800;
}

/* If the previous element is another heading */
:is(h1, h2, h3, h4, h5, h6) + h3 {
  margin-block-start: var(--space-s);
}

div.references {
	font-size: 0.8em;
}

div.references h2 {
	margin-block-start: var(--space-xl);
	font-size: 0.8em;
	letter-spacing: 0.08em;
}

p {
	margin: var(--space-xs) 0;
}

p.intro {
	font-style: italic;
	font-weight: 450;
}

ul {
	padding: 0;
	margin: 0;
}

li {
	margin-block-end: var(--space-xs);
	list-style-type: none;
}

li::marker {
	content: "";
}

blockquote {
	font-style: italic;
	margin: var(--space-m);
}

blockquote > .author {
	font-style: normal;
}

figure {
	margin: 0;
}

figcaption {
	margin-block-start: var(--space-3xs);
	font-size: var(--step--1);
	font-style: italic;
}

.article-image,
figure.article-image {
	content-visibility: auto; /* kept for performance */
	contain: layout paint;
}

.article-image img,
figure.article-image img {
	display: block;
	max-width: 100%;
	height: auto;
	inline-size: 100%;
	block-size: auto;
	object-fit: cover;
}

figure.article-image img {
	inline-size: 100%;
	block-size: auto;
	object-fit: cover;
}

time.pubdate {
	display: block; /* puts date on its own line under the link */
	font-size: var(--step--2); /* smaller than main text; adjust as needed */
	font-weight: 500;
	color: var(--text-muted); /* muted colour for secondary info */
	margin-block-start: 0.2em;
	line-height: 1;
	font-style: italic;
}

.essay .byline {
	font-size: var(--step--1);
	margin-block-start: 0;
	margin-block-end: var(--space-xl);
	font-style: italic;
}

.essay nav {
	margin: 0;
	margin-block-end: var(--space-2xl);
	font-size: var(--step--2);
	font-weight: 600;
	letter-spacing: 0.15ch;
}

.essay .footnotes-area {
	margin-block-start: var(--space-xl);
	font-size: var(--step--1);
	text-indent: -2em;
	padding-left: 2em;
}

.essay hr {
	display: none;
}

.end {
	font-size: var(--step-1);
	display: block;
	text-align: center;
}

.end > img[src$="fleuron_opt.svg"] {
	width: var(--space-s);
	height: var(--space-s);
	filter: opacity(0.8);
}

@media (prefers-color-scheme: dark) {
	.end > img[src$="fleuron_opt.svg"] {
		filter: invert(82%) sepia(5%) saturate(250%) hue-rotate(2deg)
			brightness(92%) contrast(88%);
	}
}

.poem {
	font-style: italic;
	margin: var(--space-m);
}
