/* ==========================================================================
   The Journal — base
   Tokens, the paper stock, the type scale, and the pieces every template
   shares: rails, stamps, pills, Courier furniture, the footer band.

   SPEC-design-system.md is the contract. Two rules that bite:
   1. --doc-sheet-bg and --doc-sheet-bg-image exist on the page element and
      nowhere else. Inner boxes use --card. Do not move them.
   2. Every light value is declared once, in the :root block, and overridden
      once, in the dark block. No literal light hex in a rule body.
   ========================================================================== */

/* --------------------------------------------------------------------------
   1. Tokens
   -------------------------------------------------------------------------- */

:root {
	/* Colour — light. SPEC-design-system.md §2. */
	--sheet: #f6f2e6;
	--card: #fffdf8;
	--band: #efe9d9;
	--rule: #ddd6c8;
	--ink: #16202b;
	--ink-soft: #4a4438;
	--accent: #3e7391;
	--accent-hover: #2f5a73;
	--magenta: #b00858;
	--stamp: #b3172b;
	--pen: #2f5a73;
	--on-accent: #ffffff;

	/* The tooth in the paper. 1.8% black over cream; reads as fibre. */
	--tooth: rgba(26, 28, 34, 0.018);

	/* Stamps sit in the stock, not on it. */
	--stamp-blend: multiply;
	--stamp-opacity: 0.78;

	/* The ink slab: masthead bar and the dark cards. Identical in both
	   themes on purpose — SPEC-design-system.md §2, closing paragraph. */
	--slab-bg: #16202b;
	--slab-rule: #2a3746;
	--slab-ink: #ffffff;
	--slab-nav: #c9d4de;
	--slab-meta: #8ca3b5;
	--slab-accent: #68a6c6;
	--slab-on-accent: #08131c;

	/* Type */
	--font-body: system-ui, -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
	--font-courier: "Courier New", Courier, monospace;
	--font-hand: Caveat, "Segoe Script", cursive;

	/* Measure and shell */
	--shell-max: 1360px;
	--pad-x: 40px;
	--measure-post: 730px;
	--measure-page: 760px;
	--rail-left: 262px;
	--rail-right: 300px;
	--grid-gap: 52px;

	/* Set from the real masthead height by rail.js; this is the fallback. */
	--masthead-h: 66px;
	--rail-top: calc(var(--masthead-h) + 16px);

	--radius: 4px;
	--radius-stamp: 3px;
}

@media (prefers-color-scheme: dark) {
	:root {
		--sheet: #0f1720;
		--card: #16202b;
		--band: #1b2836;
		--rule: #2a3746;
		--ink: #e8edf2;
		--ink-soft: #9aa7b4;
		--accent: #68a6c6;
		--accent-hover: #7ab4d2;
		--magenta: #e5588f;
		--stamp: #e5588f;
		--pen: #7ab4d2;
		--on-accent: #08131c;

		/* Same 1px-every-3px rhythm, inverted so the fibre still reads. */
		--tooth: rgba(232, 237, 242, 0.022);

		/* Multiply would erase a stamp on dark stock. Screening it back in
		   costs contrast, so the ink is pressed a little harder: at .78 a
		   screened stamp reads 3.9:1 against the dark card, and 12px Courier
		   needs 4.5. */
		--stamp-blend: screen;
		--stamp-opacity: 0.95;
	}
}

.journal-index {
	--shell-max: 1600px;
	--grid-gap: 48px;
	--rail-left: 236px;
}

.journal-contact {
	--shell-max: 1160px;
}

/* --------------------------------------------------------------------------
   2. Reset, and the sheet
   -------------------------------------------------------------------------- */

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

html {
	-webkit-text-size-adjust: 100%;
	scroll-padding-top: var(--rail-top);
	scroll-behavior: smooth;
}

/* The page element — the sheet. The only place the stock is declared. */
body {
	--doc-sheet-bg: var(--sheet);
	--doc-sheet-bg-image: repeating-linear-gradient(0deg, var(--tooth) 0 1px, transparent 1px 3px);

	margin: 0;
	background-color: var(--doc-sheet-bg);
	background-image: var(--doc-sheet-bg-image);
	color: var(--ink);
	font-family: var(--font-body);
	font-size: 17px;
	line-height: 1.75;
	min-height: 100vh;
	overflow-x: hidden;
}

img,
picture,
svg,
video {
	display: block;
	max-width: 100%;
}

h1,
h2,
h3,
h4,
p,
figure,
blockquote,
ul,
ol,
dl {
	margin: 0;
}

a {
	color: var(--accent);
	text-decoration: none;
}

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

:where(a, button, input, select, textarea, summary, [tabindex]):focus-visible {
	outline: 2px solid var(--accent);
	outline-offset: 2px;
	border-radius: 2px;
}

/* Containers the scripts move focus into — a heading the table of contents
   jumped to, the Received frame — take focus without drawing a ring at it.
   Anything a reader can actually operate keeps its ring, above. */
[tabindex="-1"]:focus:not(:focus-visible) {
	outline: none;
}

::selection {
	background: var(--magenta);
	color: var(--on-accent);
}

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

	*,
	*::before,
	*::after {
		transition-duration: 0.01ms;
		animation-duration: 0.01ms;
	}
}

/* --------------------------------------------------------------------------
   3. Type scale — SPEC-design-system.md §3
   -------------------------------------------------------------------------- */

h1,
h2,
h3,
h4 {
	font-weight: 800;
	text-wrap: balance;
}

p {
	text-wrap: pretty;
}

.j-h1 {
	font-size: 46px;
	line-height: 1.08;
	letter-spacing: -0.025em;
}

.j-h2-page {
	font-size: 44px;
	line-height: 1.08;
	letter-spacing: -0.025em;
}

.j-h2-section {
	font-size: 34px;
	line-height: 1.14;
	letter-spacing: -0.02em;
}

.j-h3-row {
	font-size: 22px;
	line-height: 1.28;
	font-weight: 700;
}

.j-lede {
	font-size: 20px;
	line-height: 1.6;
	font-weight: 500;
	color: var(--ink-soft);
}

.j-summary {
	font-size: 15px;
	line-height: 1.6;
	color: var(--ink-soft);
}

/* --------------------------------------------------------------------------
   4. Courier furniture — quoted or filed material only, never prose
   -------------------------------------------------------------------------- */

.j-slug {
	font-family: var(--font-courier);
	font-size: 11px;
	letter-spacing: 0.12em;
	font-weight: 700;
	color: var(--ink-soft);
	text-transform: uppercase;
}

.j-slug--rail {
	letter-spacing: 0.14em;
}

.j-key {
	font-family: var(--font-courier);
	font-size: 12px;
	font-weight: 700;
	color: var(--stamp);
	letter-spacing: 0.04em;
}

.j-verbatim {
	background: var(--card);
	border: 1px solid var(--rule);
	padding: 18px 20px;
	font-family: var(--font-courier);
	font-size: 13px;
	line-height: 1.8;
	color: var(--ink);
}

.j-verbatim__label {
	display: block;
	letter-spacing: 0.1em;
	color: var(--magenta);
	font-weight: 700;
	text-transform: uppercase;
	margin-bottom: 2px;
}

.j-verbatim p {
	margin: 0;
	text-wrap: initial;
}

/* --------------------------------------------------------------------------
   5. Handwriting — opinion in the margin, never information
   -------------------------------------------------------------------------- */

.j-hand {
	font-family: var(--font-hand);
	font-size: 20px;
	line-height: 1.35;
	color: var(--pen);
	display: inline-block;
	text-wrap: pretty;
	transform: rotate(-2deg);
}

.j-hand--lift {
	font-size: 21px;
	transform: rotate(-2.5deg);
}

.j-hand--right {
	transform: rotate(2deg);
}

.j-hand--flat {
	transform: rotate(-1.5deg);
}

/* --------------------------------------------------------------------------
   6. Stamps — status, one per page. SPEC-design-system.md §4
   -------------------------------------------------------------------------- */

.j-stamp {
	flex: 0 0 auto;
	display: inline-block;
	font-family: var(--font-courier);
	font-size: 12px;
	font-weight: 700;
	letter-spacing: 0.16em;
	text-transform: uppercase;
	text-align: center;
	line-height: 1.4;
	color: var(--stamp);
	border: 2.5px solid var(--stamp);
	border-radius: var(--radius-stamp);
	padding: 6px 11px;
	opacity: var(--stamp-opacity);
	mix-blend-mode: var(--stamp-blend);
	rotate: var(--stamp-rotate, -2.5deg);
}

.j-stamp__line {
	display: block;
}

/* A stamp that carries a destination is an anchor. It keeps the stamp's ink
   rather than the link palette, and it takes a focus ring like anything else
   a keyboard can reach. */
a.j-stamp {
	text-decoration: none;
}

a.j-stamp:hover,
a.j-stamp:focus-visible {
	opacity: 1;
	text-decoration: none;
}

a.j-stamp.j-stamp--ink:hover,
a.j-stamp.j-stamp--ink:focus-visible {
	color: var(--ink);
}

.j-stamp--ink {
	color: var(--ink);
	border-color: var(--ink);
	opacity: 0.72;
}

/* --------------------------------------------------------------------------
   7. Pills, buttons, cards
   -------------------------------------------------------------------------- */

.j-pill {
	font-family: var(--font-courier);
	font-size: 11px;
	letter-spacing: 0.12em;
	font-weight: 700;
	text-transform: uppercase;
	background: var(--magenta);
	color: var(--on-accent);
	padding: 3px 8px;
	border-radius: var(--radius-stamp);
}

a.j-pill:hover,
a.j-pill:focus-visible {
	color: var(--on-accent);
	text-decoration: underline;
}

.j-btn {
	display: inline-block;
	background: var(--accent);
	color: var(--on-accent);
	font-size: 15px;
	font-weight: 700;
	padding: 12px 22px;
	border: 0;
	border-radius: var(--radius);
	cursor: pointer;
	font-family: inherit;
	text-align: center;
}

.j-btn:hover,
.j-btn:focus-visible {
	background: var(--accent-hover);
	color: var(--on-accent);
	text-decoration: none;
}

.j-link-courier {
	font-family: var(--font-courier);
	font-size: 12px;
	letter-spacing: 0.1em;
	font-weight: 700;
	text-transform: uppercase;
	color: var(--magenta);
}

.j-link-courier:hover,
.j-link-courier:focus-visible {
	color: var(--magenta);
	text-decoration: underline;
}

.j-card {
	background: var(--card);
	border: 1px solid var(--rule);
	border-radius: var(--radius);
	padding: 18px;
	display: flex;
	flex-direction: column;
	gap: 11px;
}

.j-card__body {
	margin: 0;
	font-size: 14px;
	line-height: 1.6;
	color: var(--ink-soft);
}

/* The ink slab: a dark card, in both themes. */
.j-slab {
	background: var(--slab-bg);
	border-radius: var(--radius);
	padding: 20px;
	display: flex;
	flex-direction: column;
	gap: 10px;
}

.j-slab__title {
	color: var(--slab-ink);
	font-size: 16px;
	font-weight: 800;
	line-height: 1.3;
}

.j-slab p {
	margin: 0;
	color: var(--slab-nav);
	font-size: 14px;
	line-height: 1.6;
}

.j-slab__btn {
	background: var(--slab-accent);
	color: var(--slab-on-accent);
	font-size: 14px;
	font-weight: 800;
	padding: 9px 14px;
	border-radius: var(--radius);
	text-align: center;
}

.j-slab__btn:hover,
.j-slab__btn:focus-visible {
	color: var(--slab-on-accent);
	text-decoration: underline;
}

/* The whole card is the target. The heading carries the real link and its
   ::after covers the card, so the accessible name is the heading text and
   there is exactly one tab stop — not three. */
.j-slab--linked {
	position: relative;
}

.j-slab__link {
	color: var(--slab-ink);
	text-decoration: none;
}

.j-slab__link::after {
	content: '';
	position: absolute;
	inset: 0;
	border-radius: var(--radius);
}

.j-slab--linked:hover .j-slab__link {
	text-decoration: underline;
}

.j-slab--linked:hover .j-slab__btn {
	background: var(--slab-ink);
}

.j-slab__link:focus-visible {
	outline: none;
}

.j-slab__link:focus-visible::after {
	outline: 2px solid var(--slab-accent);
	outline-offset: 3px;
}

/* Paint, not a control: the card's own link does the work. */
.j-slab--linked .j-slab__btn {
	cursor: pointer;
}

/* The handwritten aside keeps its hand when it becomes a link. */
.j-hand a {
	color: inherit;
	text-decoration-color: color-mix(in srgb, var(--pen) 40%, transparent);
	text-decoration-thickness: 1px;
	text-underline-offset: 3px;
}

.j-hand a:hover,
.j-hand a:focus-visible {
	color: inherit;
	text-decoration-color: currentColor;
}

.j-dashed {
	border: 1px dashed var(--accent);
	padding: 18px 20px;
	display: flex;
	gap: 18px;
	align-items: flex-start;
}

.j-dashed__text {
	margin: 0;
	flex: 1;
	font-family: var(--font-courier);
	font-size: 14px;
	line-height: 1.85;
	color: var(--ink);
}

/* --------------------------------------------------------------------------
   8. Shell, journal line, footer band
   -------------------------------------------------------------------------- */

.j-wrap {
	max-width: var(--shell-max);
	margin-inline: auto;
	padding-inline: var(--pad-x);
}

.j-skip {
	position: absolute;
	left: -9999px;
	top: 0;
	z-index: 100;
	background: var(--card);
	color: var(--ink);
	padding: 10px 16px;
	border: 2px solid var(--ink);
	font-weight: 700;
}

.j-skip:focus {
	left: 8px;
	top: 8px;
}

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

.journal-line {
	display: grid;
	grid-template-columns: 1fr 1fr 1fr;
	gap: 20px;
	font-family: var(--font-courier);
	font-size: 12px;
	color: var(--ink-soft);
	border-bottom: 1px solid var(--rule);
	padding-bottom: 10px;
}

.journal-line__section {
	font-weight: 700;
	color: var(--ink);
	letter-spacing: 0.04em;
	text-transform: uppercase;
}

.journal-line__date {
	text-align: right;
}

.footer-band {
	background: var(--band);
	border-top: 1px solid var(--rule);
	font-family: var(--font-courier);
	font-size: 10px;
	letter-spacing: 0.14em;
	text-transform: uppercase;
	color: var(--ink-soft);
}

.footer-band__inner {
	display: flex;
	justify-content: space-between;
	gap: 20px;
	padding-block: 12px;
}

/* --------------------------------------------------------------------------
   9. Rails
   -------------------------------------------------------------------------- */

.j-rail {
	display: flex;
	flex-direction: column;
	gap: 24px;
	align-self: start;
	min-width: 0;
}

/* rail.js adds .is-sticky only when the rail is shorter than the viewport,
   so a tall rail never traps the reader mid-column. Grid containment keeps a
   sticky rail inside its own row, so it releases at the end of the content
   and cannot reach the footer band. */
.j-rail.is-sticky {
	position: sticky;
	top: var(--rail-top);
}

.j-rail__block {
	display: flex;
	flex-direction: column;
	gap: 9px;
	min-width: 0;
}

/* A rail is 236-262px wide. One unbroken URL in an author bio is enough to
   push it over the reading column, so nothing in a rail may refuse to wrap. */
.j-rail,
.j-rail__block,
.j-author__bio,
.j-card__body {
	overflow-wrap: anywhere;
}

.j-rail__block + .j-rail__block {
	padding-top: 22px;
	border-top: 1px solid var(--rule);
}

.j-rail__block--card {
	padding-top: 0;
	border-top: 0;
}

/* Section list, and the table of contents: the same device. */
.j-list {
	display: flex;
	flex-direction: column;
	gap: 8px;
	font-size: 15px;
	list-style: none;
	padding: 0;
	margin: 0;
}

.j-list a {
	display: block;
	color: var(--ink-soft);
	border-left: 2px solid var(--rule);
	padding-left: 12px;
	line-height: 1.35;
}

.j-list a:hover,
.j-list a:focus-visible {
	color: var(--ink);
	border-left-color: var(--ink-soft);
}

.j-list a[aria-current],
.j-list .is-current > a {
	font-weight: 700;
	color: var(--magenta);
	border-left-color: var(--magenta);
}

.j-list__count {
	font-family: var(--font-courier);
	font-size: 12px;
	letter-spacing: 0.04em;
}

/* Author card */
.j-author__avatar {
	border-radius: 50%;
	width: 72px;
	height: 72px;
	object-fit: cover;
}

.j-author__name {
	font-size: 15px;
	font-weight: 800;
}

.j-author__bio {
	margin: 0;
	font-size: 14px;
	line-height: 1.6;
	color: var(--ink-soft);
}

/* Tag chips */
.j-chips {
	display: flex;
	flex-wrap: wrap;
	gap: 6px;
	list-style: none;
	margin: 0;
	padding: 0;
}

.j-chips a {
	display: block;
	font-family: var(--font-courier);
	font-size: 11px;
	letter-spacing: 0.08em;
	text-transform: uppercase;
	border: 1px solid var(--rule);
	color: var(--ink-soft);
	padding: 4px 9px;
}

.j-chips a:hover,
.j-chips a:focus-visible {
	color: var(--ink);
	border-color: var(--ink-soft);
	text-decoration: none;
}

/* Courier search box, on sheet stock inside a card */
.j-search {
	display: flex;
	flex-direction: column;
	gap: 10px;
}

.j-search__input {
	width: 100%;
	border: 1px solid var(--rule);
	background: var(--sheet);
	color: var(--ink);
	padding: 9px 11px;
	font-family: var(--font-courier);
	font-size: 13px;
}

.j-search__input::placeholder {
	color: var(--ink-soft);
	opacity: 1;
}

.j-search__submit {
	align-self: flex-start;
	background: none;
	border: 0;
	padding: 0;
	cursor: pointer;
	font-family: var(--font-courier);
	font-size: 11px;
	letter-spacing: 0.1em;
	font-weight: 700;
	text-transform: uppercase;
	color: var(--magenta);
}

.j-search__submit:hover {
	text-decoration: underline;
}

/* Courier checkbox rows */
.j-checks {
	display: flex;
	flex-direction: column;
	gap: 7px;
	font-family: var(--font-courier);
	font-size: 12px;
	letter-spacing: 0.06em;
	text-transform: uppercase;
	list-style: none;
	margin: 0;
	padding: 0;
}

.j-checks a {
	color: var(--ink-soft);
}

.j-checks a:hover,
.j-checks a:focus-visible {
	color: var(--ink);
}

.j-checks .is-current a {
	color: var(--ink);
	font-weight: 700;
	text-decoration: none;
}

.j-checks__box {
	font-style: normal;
}

/* --------------------------------------------------------------------------
   10. The two shared content grids
   -------------------------------------------------------------------------- */

.j-grid {
	display: grid;
	grid-template-columns: var(--rail-left) minmax(0, 1fr);
	gap: var(--grid-gap);
	padding-block: 38px 46px;
	align-items: start;
}

.j-grid--home {
	grid-template-columns: var(--rail-left) minmax(0, 1fr) var(--rail-right);
	padding-block: 32px 52px;
}

.j-column {
	min-width: 0;
}

.j-column--post {
	max-width: var(--measure-post);
}

.j-column--page {
	max-width: var(--measure-page);
}

/* --------------------------------------------------------------------------
   11. Responsive — SPEC-templates.md §7
   -------------------------------------------------------------------------- */

@media (max-width: 1400px) {
	.j-grid--home {
		grid-template-columns: var(--rail-left) minmax(0, 1fr);
	}

	.j-grid--home > .j-rail--right {
		grid-column: 1 / -1;
		display: grid;
		grid-template-columns: repeat(2, minmax(0, 1fr));
		align-items: start;
	}

	.j-grid--home > .j-rail--right.is-sticky {
		position: static;
	}
}

@media (max-width: 1080px) {
	.j-grid,
	.j-grid--home {
		grid-template-columns: minmax(0, 1fr);
		gap: 32px;
	}

	.j-rail {
		order: 2;
	}

	.j-rail.is-sticky {
		position: static;
	}

	.j-column {
		order: 1;
	}

	/* The section list becomes a horizontal scroller. */
	.j-rail__block--scroller .j-list {
		flex-direction: row;
		overflow-x: auto;
		gap: 0;
		padding-bottom: 6px;
		scrollbar-width: thin;
	}

	.j-rail__block--scroller .j-list li {
		flex: 0 0 auto;
	}

	.j-rail__block--scroller .j-list a {
		border-left: 0;
		border-bottom: 2px solid var(--rule);
		padding: 0 16px 8px 0;
		margin-right: 16px;
		white-space: nowrap;
	}

	.j-rail__block--scroller .j-list a[aria-current],
	.j-rail__block--scroller .j-list .is-current > a {
		border-left: 0;
		border-bottom-color: var(--magenta);
	}

	.j-rail__block + .j-rail__block {
		padding-top: 20px;
	}
}

@media (max-width: 640px) {
	:root {
		--pad-x: 20px;
	}

	.j-h1 {
		font-size: 30px;
		letter-spacing: -0.02em;
	}

	.j-h2-page,
	.j-h2-section {
		font-size: 28px;
		letter-spacing: -0.015em;
	}

	.j-lede {
		font-size: 18px;
	}

	.journal-line {
		grid-template-columns: minmax(0, 1fr) auto;
		row-gap: 6px;
	}

	.journal-line__section {
		grid-column: 1;
	}

	.journal-line__count {
		grid-column: 1;
	}

	.journal-line__date {
		grid-column: 2;
		grid-row: 1;
	}

	.footer-band__inner {
		flex-direction: column;
		gap: 6px;
	}

	.j-grid--home > .j-rail--right {
		grid-template-columns: minmax(0, 1fr);
	}
}
