/* nyimbi.com — an exercise book kept in public.
   The world is the Kenyan counter book: squared paper, a red margin rule, a
   pasted cover label, handwriting in the margin. It carries the page rather
   than picturing it — the margin rule is where the notes actually live, the
   grid is the ground text is set on, and the label names the owner instead of
   kicking a headline.

   Light is the default because paper is the object. Dark exists for reading
   under a lamp, not as a second brand. */

:root {
	--paper: #f4efe1;
	--paper-edge: #e8e0cc;
	--ink: #241f18;
	--ink-soft: #554c3e;
	--ink-faint: #6b6152;
	--rule-red: #9c3227;
	--rule-grid: rgba(36, 31, 24, 0.09);
	--rule-grid-major: rgba(36, 31, 24, 0.16);

	--note-col: 9.5rem;
	--note-gap: 2.75rem;

	--serif: "Newsreader", "Iowan Old Style", Georgia, serif;
	--display: "Instrument Serif", "Iowan Old Style", Georgia, serif;
	--hand: "Caveat", "Bradley Hand", cursive;
}

@media (prefers-color-scheme: dark) {
	:root:not([data-theme="light"]) {
		--paper: #17150f;
		--paper-edge: #201d15;
		--ink: #ece5d3;
		--ink-soft: #bdb29c;
		--ink-faint: #9a8f78;
		--rule-red: #c8635a;
		--rule-grid: rgba(236, 229, 211, 0.05);
		--rule-grid-major: rgba(236, 229, 211, 0.1);
	}
}

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

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

@media (prefers-reduced-motion: reduce) {
	html { scroll-behavior: auto; }
}

body {
	margin: 0;
	background-color: var(--paper);
	background-image:
		/* the fine grid */
		repeating-linear-gradient(to right, var(--rule-grid) 0 1px, transparent 1px 6.5px),
		repeating-linear-gradient(to bottom, var(--rule-grid) 0 1px, transparent 1px 6.5px),
		/* the heavy grid every four squares */
		repeating-linear-gradient(to right, var(--rule-grid-major) 0 1px, transparent 1px 26px),
		repeating-linear-gradient(to bottom, var(--rule-grid-major) 0 1px, transparent 1px 26px);
	color: var(--ink);
	font-family: var(--serif);
	font-size: clamp(1.0625rem, 1rem + 0.3vw, 1.1875rem);
	line-height: 1.68;
	font-weight: 400;
	text-rendering: optimizeLegibility;
	-webkit-font-smoothing: antialiased;
}

::selection {
	background: var(--rule-red);
	color: var(--paper);
}

.book {
	max-width: 62rem;
	margin: 0 auto;
	padding: clamp(1.5rem, 4vw, 3.5rem) clamp(1.25rem, 4vw, 3rem) 0;
}

/* ── The cover label ───────────────────────────────────────────────────────
   Pasted on, so it gets a border and its own ruled lines rather than sitting
   flush with the page. It names the owner and the date; it is not a kicker. */

.label {
	border: 1px solid var(--rule-red);
	padding: 1.1rem 1.35rem 1.25rem;
	max-width: 30rem;
	/* Sit on the body column, not between it and the margin: the label is the
	   book's first entry, and an entry starts where the writing starts. */
	margin: 0 0 clamp(3rem, 9vw, 5.5rem) 0;
	margin-left: calc(var(--note-col) + var(--note-gap));
	background: color-mix(in srgb, var(--paper) 82%, transparent);
}

@media (max-width: 46rem) {
	.label { margin-left: 0; }
}

.label__rule {
	display: grid;
	gap: 0.35rem;
}

.label__field {
	margin: 0;
	display: grid;
	grid-template-columns: 4.75rem 1fr;
	align-items: baseline;
	gap: 0.75rem;
	border-bottom: 1px solid color-mix(in srgb, var(--rule-red) 32%, transparent);
	padding-bottom: 0.3rem;
	font-family: var(--display);
	font-size: 1.0625rem;
	font-variation-settings: "opsz" 24;
}

.label__field span {
	font-family: var(--serif);
	font-size: 0.6875rem;
	letter-spacing: 0.13em;
	text-transform: uppercase;
	color: var(--ink-faint);
}

.label__epigraph {
	margin: 0.9rem 0 0;
	font-family: var(--hand);
	font-size: 1.35rem;
	line-height: 1.25;
	color: var(--rule-red);
}

/* ── The page ───────────────────────────────────────────────────────────── */

main {
	position: relative;
	padding-bottom: 1rem;
}

/* The margin rule runs the length of the writing, not past the last entry:
   it starts at the label and stops where the prose stops. */
main::before {
	content: "";
	position: absolute;
	top: -1.35rem;
	bottom: 0;
	left: calc(var(--note-col) + var(--note-gap) / 2);
	width: 1px;
	background: color-mix(in srgb, var(--rule-red) 62%, transparent);
}

section {
	display: grid;
	grid-template-columns: var(--note-col) minmax(0, 1fr);
	column-gap: var(--note-gap);
	padding-bottom: clamp(2.75rem, 6vw, 4.25rem);
}

section h2 {
	grid-column: 2;
	margin: 0 0 1.35rem;
	font-family: var(--display);
	font-size: clamp(1.6rem, 1.2rem + 1.5vw, 2.35rem);
	font-weight: 500;
	line-height: 1.1;
	letter-spacing: -0.018em;
	font-variation-settings: "opsz" 48;
	text-wrap: balance;
	position: relative;
	padding-bottom: 0.55rem;
}

/* The heading rule draws in as the section arrives. Without JS, or with
   reduced motion, it is simply drawn — the page never waits on the script. */
section h2::after {
	content: "";
	position: absolute;
	left: 0;
	bottom: 0;
	width: min(6.5rem, 42%);
	height: 1.5px;
	background: var(--rule-red);
	transform-origin: left center;
}

.js-rules section h2::after {
	transform: scaleX(0);
	transition: transform 620ms cubic-bezier(0.16, 1, 0.3, 1);
}

.js-rules section h2.drawn::after { transform: scaleX(1); }

@media (prefers-reduced-motion: reduce) {
	.js-rules section h2::after { transform: none; transition: none; }
}

section .note {
	grid-column: 1;
	grid-row: 1 / span 3;
	align-self: start;
	margin: 0.15rem 0 0;
	padding-right: 0.35rem;
	text-align: right;
	font-family: var(--hand);
	font-size: 1.3rem;
	line-height: 1.22;
	color: var(--rule-red);
	transform: rotate(-1.2deg);
	text-wrap: balance;
}

section .body {
	grid-column: 2;
	max-width: 62ch;
}

section .body p {
	margin: 0 0 1.15rem;
}

section .body p:last-child { margin-bottom: 0; }

section .body em {
	font-style: italic;
	color: var(--ink-soft);
}

/* Fragments read as items on a page, not as cards. The grid is already
   there; the marker is the indent. */
.fragments {
	list-style: none;
	margin: 0;
	padding: 0;
	display: grid;
	gap: 0.85rem;
}

.fragments li {
	position: relative;
	padding-left: 1.5rem;
	text-wrap: pretty;
}

.fragments li::before {
	content: "";
	position: absolute;
	left: 0;
	top: 0.62em;
	width: 0.55rem;
	height: 1.5px;
	background: var(--rule-red);
}

.signoff {
	display: flex;
	flex-wrap: wrap;
	gap: 0.35rem 1.75rem;
	margin-top: 1.75rem;
	padding-top: 1.1rem;
	border-top: 1px solid color-mix(in srgb, var(--ink) 14%, transparent);
}

a {
	color: var(--ink);
	text-decoration-line: underline;
	text-decoration-thickness: 1px;
	text-underline-offset: 0.22em;
	text-decoration-color: color-mix(in srgb, var(--rule-red) 55%, transparent);
	transition: color 150ms ease, text-decoration-color 150ms ease;
}

a:hover,
a:focus-visible {
	color: var(--rule-red);
	text-decoration-color: var(--rule-red);
}

a:focus-visible {
	outline: 2px solid var(--rule-red);
	outline-offset: 3px;
	border-radius: 1px;
}

.colophon {
	margin-top: clamp(1.5rem, 4vw, 3rem);
	padding: 1.5rem 0 2.5rem;
	border-top: 1px solid color-mix(in srgb, var(--ink) 14%, transparent);
	display: flex;
	flex-wrap: wrap;
	justify-content: space-between;
	gap: 0.5rem 2rem;
	font-size: 0.8125rem;
	color: var(--ink-faint);
}

.colophon p { margin: 0; }

/* ── Narrow: the margin notes move above their section ──────────────────── */

@media (max-width: 46rem) {
	main::before { display: none; }

	section {
		grid-template-columns: minmax(0, 1fr);
		column-gap: 0;
	}

	section h2 { grid-column: 1; }

	section .note {
		grid-column: 1;
		grid-row: auto;
		order: -1;
		margin: 0 0 0.6rem;
		padding-right: 0;
		text-align: left;
		font-size: 1.2rem;
		transform: rotate(-1deg);
		transform-origin: left center;
	}

	section .body { grid-column: 1; }
}
