/*
 * Stuaim: base.
 * Design tokens (colours, type, fluid sizes) as custom properties, and the
 * defaults of plain HTML elements: page ground, text, links, focus, the skip link.
 *
 * Fluid sizes. The design fixes two widths, 390 and 1240. A size written
 * fluid(a, b) is a at 390 wide, b at 1240 wide, a straight line between, and
 * held outside them:
 *   clamp(a, calc(a + (b - a) * ((100vw - 390px) / 850)), b)
 * Font sizes use rem, so they follow the reader's browser text size.
 */

:root {
	/* Palette (also in theme.json, where the editor offers it). */
	--stuaim-lampblack: #211d17;
	--stuaim-soot: #2b2620;
	--stuaim-stone: #8b8579;
	--stuaim-vellum: #e4dfd2;
	--stuaim-paper: #f0ede6;
	--stuaim-moss: #4c6147;
	--stuaim-moss-lit: #93a88b;

	/* Text on Paper is Lampblack at reduced strength. */
	--stuaim-ink: #211d17;
	--stuaim-ink-82: rgba(33, 29, 23, 0.82);
	--stuaim-ink-75: rgba(33, 29, 23, 0.75);
	--stuaim-ink-70: rgba(33, 29, 23, 0.7);
	--stuaim-ink-66: rgba(33, 29, 23, 0.66); /* the lightest ink used for text: 5.06 to 1 on Paper, 4.78 on Vellum */
	--stuaim-ink-55: rgba(33, 29, 23, 0.55); /* lines only: too light for small text (3.62 to 1) */
	--stuaim-rule: rgba(33, 29, 23, 0.14);
	--stuaim-hairline: rgba(33, 29, 23, 0.09);
	--stuaim-paper-75: rgba(240, 237, 230, 0.75);
	--stuaim-paper-12: rgba(240, 237, 230, 0.12);

	/* Type families: serif speaks, sans explains, Space Grotesk counts. */
	--stuaim-serif: "Source Serif 4", Georgia, "Times New Roman", serif;
	--stuaim-sans: "Source Sans 3", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
	--stuaim-numeral: "Space Grotesk", ui-sans-serif, system-ui, sans-serif;
	--stuaim-mono: ui-monospace, Menlo, Consolas, monospace;

	/* Roles. Dark grounds redefine these (see below), so every part follows. */
	--stuaim-text: var(--stuaim-ink);
	--stuaim-text-body: var(--stuaim-ink-75);
	--stuaim-text-soft: var(--stuaim-ink-70);
	--stuaim-text-note: var(--stuaim-ink-66);
	--stuaim-text-caption: var(--stuaim-ink-66);
	--stuaim-line: var(--stuaim-rule);
	--stuaim-line-faint: var(--stuaim-hairline);
	--stuaim-link: var(--stuaim-moss);
	--stuaim-focus: var(--stuaim-moss);
	--stuaim-button-fill: var(--stuaim-lampblack);
	--stuaim-button-on-fill: var(--stuaim-paper);
	--stuaim-button-line: rgba(33, 29, 23, 0.3);
	--stuaim-button-on-line: var(--stuaim-ink);

	/* The section box: 1128px wide at most, with fluid side padding (56px at 1240, 24px at 390). */
	--stuaim-box: 1128px;
	--stuaim-pad: clamp(24px, calc(24px + 32 * ((100vw - 390px) / 850)), 56px);
	--stuaim-box-inline: calc(max(0px, (100% - var(--stuaim-box)) / 2) + var(--stuaim-pad));

	/* Section heights: default, tight, roomy. */
	--stuaim-section-y: clamp(60px, calc(60px + 28 * ((100vw - 390px) / 850)), 88px);
	--stuaim-section-y-tight: clamp(52px, calc(52px + 20 * ((100vw - 390px) / 850)), 72px);
	--stuaim-section-y-roomy: clamp(72px, calc(72px + 48 * ((100vw - 390px) / 850)), 120px);

	/* Fluid type sizes used by the sections (the same values are presets in theme.json). */
	--stuaim-fs-note: clamp(0.78125rem, calc(0.78125rem + 1.5 * ((100vw - 390px) / 850)), 0.875rem);
	--stuaim-fs-caption: clamp(0.8125rem, calc(0.8125rem + 0.5 * ((100vw - 390px) / 850)), 0.84375rem);
	--stuaim-fs-caption-large: clamp(0.84375rem, calc(0.84375rem + 0.5 * ((100vw - 390px) / 850)), 0.875rem);
	--stuaim-fs-step: clamp(0.9375rem, calc(0.9375rem + 0.5 * ((100vw - 390px) / 850)), 0.96875rem);
	--stuaim-fs-body: clamp(0.96875rem, calc(0.96875rem + 1 * ((100vw - 390px) / 850)), 1.03125rem);
	--stuaim-fs-lead: clamp(1rem, calc(1rem + 2 * ((100vw - 390px) / 850)), 1.125rem);
	--stuaim-fs-h3: clamp(1.3125rem, calc(1.3125rem + 1 * ((100vw - 390px) / 850)), 1.375rem);
	--stuaim-fs-statement: clamp(1.375rem, calc(1.375rem + 3 * ((100vw - 390px) / 850)), 1.5625rem);
	--stuaim-fs-h2: clamp(1.8125rem, calc(1.8125rem + 5 * ((100vw - 390px) / 850)), 2.125rem);
	--stuaim-fs-h1: clamp(2.375rem, calc(2.375rem + 18 * ((100vw - 390px) / 850)), 3.5rem);
	--stuaim-fs-numeral: clamp(3.25rem, calc(3.25rem + 28 * ((100vw - 390px) / 850)), 5rem);

	/* Space between blocks inside a section. */
	--stuaim-after-h1: clamp(16px, calc(16px + 6 * ((100vw - 390px) / 850)), 22px);
	--stuaim-after-h2: clamp(14px, calc(14px + 4 * ((100vw - 390px) / 850)), 18px);
	--stuaim-after-h3: clamp(8px, calc(8px + 2 * ((100vw - 390px) / 850)), 10px);
	--stuaim-before-buttons: clamp(26px, calc(26px + 8 * ((100vw - 390px) / 850)), 34px);
	--stuaim-after-buttons: clamp(12px, calc(12px + 2 * ((100vw - 390px) / 850)), 14px);
	--stuaim-before-list: clamp(22px, calc(22px + 4 * ((100vw - 390px) / 850)), 26px);
	--stuaim-after-list: clamp(18px, calc(18px + 4 * ((100vw - 390px) / 850)), 22px);
	--stuaim-after-strokes: clamp(14px, calc(14px + 2 * ((100vw - 390px) / 850)), 16px);
	--stuaim-after-numeral: clamp(10px, calc(10px + 2 * ((100vw - 390px) / 850)), 12px);
	--stuaim-flow: clamp(14px, calc(14px + 4 * ((100vw - 390px) / 850)), 18px);

	/* Text pages (not in the locked design: one column, the same type system). */
	--stuaim-page-top: clamp(40px, calc(40px + 32 * ((100vw - 390px) / 850)), 72px);
	--stuaim-page-bottom: clamp(56px, calc(56px + 40 * ((100vw - 390px) / 850)), 96px);
	--stuaim-fs-page-title: clamp(2.125rem, calc(2.125rem + 10 * ((100vw - 390px) / 850)), 2.75rem);
	--stuaim-reading: 680px;
	--stuaim-wide: 1016px;
}

/* Dark grounds: any group (or the body of a block) with a Lampblack or Soot
   background switches to Paper text, paper-75 body, Stone captions and Moss lit links. */
.has-lampblack-background-color,
.has-soot-background-color {
	--stuaim-text: var(--stuaim-paper);
	--stuaim-text-body: var(--stuaim-paper-75);
	--stuaim-text-soft: var(--stuaim-paper-75);
	--stuaim-text-note: var(--stuaim-stone);
	--stuaim-text-caption: var(--stuaim-stone);
	--stuaim-line: var(--stuaim-paper-12);
	--stuaim-line-faint: var(--stuaim-paper-12);
	--stuaim-link: var(--stuaim-moss-lit);
	--stuaim-focus: var(--stuaim-moss-lit);
	--stuaim-button-fill: var(--stuaim-paper);
	--stuaim-button-on-fill: var(--stuaim-ink);
	--stuaim-button-line: rgba(240, 237, 230, 0.4);
	--stuaim-button-on-line: var(--stuaim-paper);
	color: var(--stuaim-text);
}

/* Light grounds set inside a dark one switch back. */
.has-paper-background-color,
.has-vellum-background-color,
.has-moss-lit-background-color {
	--stuaim-text: var(--stuaim-ink);
	--stuaim-text-body: var(--stuaim-ink-75);
	--stuaim-text-soft: var(--stuaim-ink-70);
	--stuaim-text-note: var(--stuaim-ink-66);
	--stuaim-text-caption: var(--stuaim-ink-66);
	--stuaim-line: var(--stuaim-rule);
	--stuaim-line-faint: var(--stuaim-hairline);
	--stuaim-link: var(--stuaim-moss);
	--stuaim-focus: var(--stuaim-moss);
	--stuaim-button-fill: var(--stuaim-lampblack);
	--stuaim-button-on-fill: var(--stuaim-paper);
	--stuaim-button-line: rgba(33, 29, 23, 0.3);
	--stuaim-button-on-line: var(--stuaim-ink);
	color: var(--stuaim-text);
}

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

html {
	-webkit-text-size-adjust: 100%;
	text-size-adjust: 100%;
}

body {
	margin: 0;
	background: var(--stuaim-paper);
	color: var(--stuaim-ink);
	font-family: var(--stuaim-sans);
	font-weight: 400;
	line-height: normal;
	-webkit-font-smoothing: antialiased;
	-moz-osx-font-smoothing: grayscale;
	text-rendering: optimizeLegibility;
}

h1,
h2,
h3,
h4,
h5,
h6 {
	font-family: var(--stuaim-serif);
	font-weight: 600;
	color: var(--stuaim-text);
}

img,
svg,
video {
	max-width: 100%;
	height: auto;
}

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

a:hover {
	text-decoration-thickness: 2px;
}

/* Visible focus everywhere: a 2px Moss ink outline, 2px away (Moss lit on dark). */
:focus-visible {
	outline: 2px solid var(--stuaim-focus);
	outline-offset: 2px;
}

:focus:not(:focus-visible) {
	outline: none;
}

strong,
b {
	font-weight: 600;
}

hr {
	height: 0;
	border: 0;
	border-top: 1px solid var(--stuaim-line);
}

::selection {
	background: rgba(147, 168, 139, 0.45);
}

/* Text for screen readers only. */
.screen-reader-text {
	border: 0;
	clip-path: inset(50%);
	height: 1px;
	margin: -1px;
	overflow: hidden;
	padding: 0;
	position: absolute;
	width: 1px;
	word-wrap: normal !important;
}

.screen-reader-text:focus {
	clip-path: none;
	height: auto;
	width: auto;
	margin: 0;
	overflow: visible;
}

/* The skip link: hidden until a keyboard reaches it. */
.skip-link {
	position: absolute;
	inset-inline-start: 12px;
	top: -100px;
	z-index: 100;
	padding: 10px 16px;
	border-radius: 8px;
	background: var(--stuaim-lampblack);
	color: var(--stuaim-paper);
	font-weight: 500;
	text-decoration: none;
}

.skip-link:focus {
	top: 12px;
}

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