/* ============================================================
   From Real-World Mathematical Models to Engineering Solutions
   Fixed 1600x900 stage, scaled to fit.
   ============================================================ */

:root {
	--bg: #08080b;
	--panel: #111116;
	--raise: #17171d;
	--white: #f4f6f9;
	--grey: #8b93a1;
	--grey-d: #767e8e; /* was #4a5160, which sat at 2.51:1 on this ground */
	--line: rgba(255, 255, 255, 0.075);
	--line-2: rgba(255, 255, 255, 0.17);
	--red: #ef4444;
	--red-dim: rgba(239, 68, 68, 0.16);
	--cyan: #22d3ee;
	--cyan-dim: rgba(34, 211, 238, 0.14);

	/* Surfaces. Named so the light theme can restate them: a white wash over
	   black has no meaning once the ground is white. */
	--grid: rgba(255, 255, 255, 0.022);
	--sheen-a: rgba(255, 255, 255, 0.045);
	--sheen-b: rgba(255, 255, 255, 0.012);
	--tint: rgba(255, 255, 255, 0.015);
	--hover: rgba(255, 255, 255, 0.05);
	--fig-line: #23232b;
	--axis: #1c1c22;

	--display: 'Archivo Black', 'Archivo', system-ui, sans-serif;
	--sans: 'Archivo', system-ui, -apple-system, sans-serif;
	--mono: 'JetBrains Mono', ui-monospace, Menlo, monospace;
	--ease: cubic-bezier(0.22, 0.9, 0.3, 1);
}

* {
	margin: 0;
	padding: 0;
	box-sizing: border-box;
}
html,
body {
	height: 100%;
	overflow: hidden;
	background: var(--bg);
}
body {
	font-family: var(--sans);
	color: var(--white);
	-webkit-font-smoothing: antialiased;
}

/* ---------- stage ---------- */
#viewport {
	position: fixed;
	inset: 0;
	overflow: hidden;
}
#stage {
	position: absolute;
	left: 50%;
	top: 50%;
	width: 1600px;
	height: 900px;
	transform-origin: center center;
	background: var(--bg);
	overflow: hidden;
}
#stage::before {
	content: '';
	position: absolute;
	inset: 0;
	pointer-events: none;
	z-index: 0;
	background-image:
		linear-gradient(to right, var(--grid) 1px, transparent 1px),
		linear-gradient(to bottom, var(--grid) 1px, transparent 1px);
	background-size: 80px 80px;
}

/* ---------- slides ---------- */
.slide {
	position: absolute;
	inset: 0;
	z-index: 1;
	display: flex;
	flex-direction: column;
	justify-content: center;
	padding: 78px 112px;
	opacity: 0;
	visibility: hidden;
	transition:
		opacity 0.34s ease,
		visibility 0s 0.42s;
}
.slide.active {
	opacity: 1;
	visibility: visible;
	transition:
		opacity 0.34s ease,
		visibility 0s 0s;
}
.slide.centered {
	align-items: center;
	text-align: center;
}

/* content rises in, staggered */
/* :not(.frag) matters: animation fill-mode outranks .frag's opacity:0,
   which would make every build step visible at once. */
.slide.active .rise:not(.frag) {
	animation: rise 0.56s var(--ease) both;
	animation-delay: var(--d, 0s);
}
@keyframes rise {
	from {
		opacity: 0;
		transform: translateY(18px);
	}
	to {
		opacity: 1;
		transform: none;
	}
}

/* click-through build steps */
.frag {
	opacity: 0;
	transform: translateY(10px);
	transition:
		opacity 0.34s ease,
		transform 0.42s var(--ease);
}
.frag.on {
	opacity: 1;
	transform: none;
}

/* ---------- type ---------- */
.eyebrow {
	font-family: var(--mono);
	font-size: 19px;
	font-weight: 500;
	letter-spacing: 0.26em;
	text-transform: uppercase;
	color: var(--red);
	margin-bottom: 26px;
}
.eyebrow.cy {
	color: var(--cyan);
}
.eyebrow.gy {
	color: var(--grey-d);
}

.huge {
	font-family: var(--display);
	font-size: 118px;
	line-height: 0.94;
	letter-spacing: -0.03em;
}
.h1 {
	font-family: var(--display);
	font-size: 74px;
	line-height: 1.02;
	letter-spacing: -0.025em;
}
.h2 {
	font-family: var(--sans);
	font-weight: 700;
	font-size: 46px;
	line-height: 1.14;
	letter-spacing: -0.015em;
}
.h3 {
	font-family: var(--sans);
	font-weight: 600;
	font-size: 30px;
	line-height: 1.24;
}
.lead {
	font-size: 27px;
	line-height: 1.5;
	color: var(--white);
}
.body {
	font-size: 23px;
	line-height: 1.6;
	color: var(--grey);
}
.small {
	font-size: 22px;
	line-height: 1.55;
	color: var(--grey);
}
.mono {
	font-family: var(--mono);
}
.red {
	color: var(--red);
}
.cy {
	color: var(--cyan);
}
.gy {
	color: var(--grey);
}
.dim {
	color: var(--grey-d);
}
.wh {
	color: var(--white);
}
b,
strong {
	font-weight: 700;
	color: var(--white);
}
em {
	font-style: italic;
}

.stack {
	display: flex;
	flex-direction: column;
}
.g10 {
	gap: 10px;
}
.g16 {
	gap: 16px;
}
.g22 {
	gap: 22px;
}
.g30 {
	gap: 30px;
}
.g44 {
	gap: 44px;
}
.row {
	display: flex;
	align-items: center;
}
.split {
	display: grid;
	grid-template-columns: 1fr 1fr;
	gap: 64px;
	align-items: center;
}
.split.wide-l {
	grid-template-columns: 1.25fr 0.75fr;
}
.split.wide-r {
	grid-template-columns: 0.75fr 1.25fr;
}

/* ---------- equations ---------- */
.eq {
	background: linear-gradient(180deg, var(--sheen-a), var(--sheen-b));
	border: 1px solid var(--line);
	border-left: 2px solid var(--grey-d);
	border-radius: 2px;
	padding: 24px 34px;
	font-size: 30px;
	overflow-x: auto;
	overflow-y: hidden;
	position: relative;
}
.eq.key {
	border-left-color: var(--red);
}
.eq.cyk {
	border-left-color: var(--cyan);
}
.eq.bare {
	background: none;
	border: none;
	padding: 10px 0;
}
.eq .tag {
	position: absolute;
	right: 14px;
	top: 11px;
	font-family: var(--mono);
	font-size: 17px;
	color: var(--grey-d);
	letter-spacing: 0.06em;
}
mjx-container {
	color: inherit !important;
}
mjx-container[display] {
	margin: 0 !important;
}

/* ---------- morphing equations ---------- */
/* MathJax sizes its svg in ex units, so this font-size sets the maths size */
.morph {
	position: relative;
	width: 100%;
	font-size: 44px;
}
.mlayer {
	position: absolute;
	left: 50%;
	top: 50%;
	transform: translate(-50%, -50%);
}
.gly {
	position: absolute;
	display: block;
	transform-origin: 50% 50%;
	will-change: transform, opacity;
	color: inherit;
}
.gly svg {
	display: block;
	overflow: visible;
}
.morph-src {
	display: none;
}

/* ---------- drifting air ---------- */
.airflow {
	position: absolute;
	inset: 0;
	overflow: hidden;
	pointer-events: none;
	z-index: 0;
}
.airflow i {
	position: absolute;
	left: -460px;
	height: 2px;
	border-radius: 2px;
	opacity: 0;
	background: linear-gradient(90deg, transparent, var(--cyan) 30%, var(--cyan) 70%, transparent);
	animation: drift linear infinite;
}
.slide:not(.active) .airflow i {
	animation-play-state: paused;
}
@keyframes drift {
	0% {
		transform: translateX(0);
		opacity: 0;
	}
	12% {
		opacity: var(--o, 0.4);
	}
	88% {
		opacity: var(--o, 0.4);
	}
	100% {
		transform: translateX(2160px);
		opacity: 0;
	}
}
.above {
	position: relative;
	z-index: 1;
}

/* one caption per morph step, stacked so the block never changes height */
.mcaps {
	display: grid;
}
.mcaps > * {
	grid-area: 1/1;
	opacity: 0;
	transform: translateY(6px);
	transition:
		opacity 0.3s ease,
		transform 0.36s var(--ease);
}
.mcaps > *.on {
	opacity: 1;
	transform: none;
}

/* ---------- code ---------- */
.code {
	font-family: var(--mono);
	font-size: 22px;
	line-height: 1.62;
	background: linear-gradient(180deg, var(--sheen-a), var(--sheen-b));
	border: 1px solid var(--line);
	border-left: 2px solid var(--cyan);
	border-radius: 2px;
	padding: 24px 30px;
	white-space: pre;
	overflow-x: auto;
	color: var(--white);
}
.code .kw {
	color: var(--red);
}
.code .fn {
	color: var(--cyan);
}
.code .cm {
	color: var(--grey-d);
}
.code .di {
	color: var(--grey);
}

/* ---------- code annotations, anchored to a line ---------- */
.annot {
	position: relative;
}
.annot .code {
	width: 664px;
}
.ann {
	position: absolute;
	left: 720px;
	width: 620px;
	top: calc(var(--pad) + var(--i) * var(--lh) - 2px);
	font-size: 17px;
	line-height: 1.45;
	color: var(--grey);
	white-space: nowrap;
	--pad: 24px;
	--lh: 29.2px;
}
.ann b {
	font-family: var(--mono);
	font-size: 16px;
	font-weight: 500;
}
.ann::before {
	content: '';
	position: absolute;
	left: -72px;
	top: 0.66em;
	width: 62px;
	height: 1px;
	background: var(--grey);
}
.ann::after {
	content: '';
	position: absolute;
	left: -74px;
	top: 0.66em;
	margin-top: -4px;
	border: 4px solid transparent;
	border-right-color: var(--grey);
}

/* ---------- live simulation panels ---------- */
.sim {
	display: grid;
	grid-template-columns: 1fr 330px;
	gap: 48px;
	align-items: start;
}
.sim canvas {
	width: 100%;
	height: auto;
	display: block;
	border-radius: 2px;
	border: 1px solid var(--line);
	background: var(--tint);
}
.ctrls {
	display: flex;
	flex-direction: column;
	gap: 22px;
}
.ctrl label {
	display: block;
	margin-bottom: 10px;
	font-family: var(--mono);
	font-size: 16px;
	letter-spacing: 0.16em;
	text-transform: uppercase;
	color: var(--grey-d);
}
.ctrl label .val {
	color: var(--red);
	letter-spacing: 0.04em;
}
.ctrl input[type='range'] {
	width: 100%;
	height: 26px;
	cursor: pointer;
	accent-color: var(--red);
}
/* custom dropdown, because the native popup ignores the page theme */
.pick {
	position: relative;
	z-index: 20;
}
.pick-btn {
	width: 100%;
	display: flex;
	align-items: center;
	justify-content: space-between;
	gap: 12px;
	padding: 11px 14px;
	cursor: pointer;
	border-radius: 2px;
	font-family: var(--mono);
	font-size: 18px;
	color: var(--white);
	text-align: left;
	background: var(--panel);
	border: 1px solid var(--line-2);
	transition: border-color 0.18s ease;
}
.pick-btn:hover {
	border-color: var(--grey-d);
}
.pick.open .pick-btn {
	border-color: var(--red);
}
.pick-btn::after {
	content: '';
	width: 0;
	height: 0;
	flex: none;
	border: 5px solid transparent;
	border-top-color: var(--grey);
	transform: translateY(2px);
	transition: transform 0.18s ease;
}
.pick.open .pick-btn::after {
	transform: translateY(-2px) rotate(180deg);
}
.pick-menu {
	position: absolute;
	left: 0;
	right: 0;
	top: calc(100% + 6px);
	list-style: none;
	margin: 0;
	padding: 5px;
	display: none;
	background: var(--raise);
	border: 1px solid var(--line-2);
	border-radius: 2px;
	box-shadow: 0 22px 50px -18px #000;
}
.pick.open .pick-menu {
	display: block;
}
.pick-menu li {
	padding: 9px 12px;
	cursor: pointer;
	border-radius: 2px;
	font-family: var(--mono);
	font-size: 18px;
	color: var(--grey);
}
.pick-menu li:hover {
	color: var(--white);
	background: var(--hover);
}
.pick-menu li.on {
	color: var(--red);
}
.pick-menu li.on::before {
	content: '';
	float: right;
	width: 6px;
	height: 6px;
	border-radius: 50%;
	background: var(--red);
	margin-top: 8px;
}
.readout {
	display: grid;
	grid-template-columns: 1fr auto;
	gap: 11px 18px;
	margin-top: 4px;
	padding-top: 20px;
	border-top: 1px solid var(--line);
	font-family: var(--mono);
	font-size: 19px;
}
.readout span {
	color: var(--grey-d);
}
.readout b {
	font-weight: 500;
	text-align: right;
	color: var(--white);
	font-variant-numeric: tabular-nums;
}
.readout b.rd {
	color: var(--red);
}
.readout b.cy {
	color: var(--cyan);
}

/* ---------- links ---------- */
a {
	color: var(--cyan);
	text-decoration: none;
	border-bottom: 1px solid rgba(34, 211, 238, 0.35);
	transition: border-color 0.18s ease;
}
a:hover {
	border-bottom-color: var(--cyan);
}

/* ---------- notes and rules ---------- */
.note {
	border-left: 2px solid var(--cyan);
	padding: 2px 0 2px 22px;
	font-size: 22px;
	line-height: 1.55;
	color: var(--grey);
}
.note b {
	color: var(--cyan);
	font-weight: 600;
}
.note.warn {
	border-left-color: var(--red);
}
.note.warn b {
	color: var(--red);
}
.rule {
	height: 1px;
	background: var(--line);
}

/* ---------- lists ---------- */
.steps {
	list-style: none;
	display: flex;
	flex-direction: column;
	gap: 20px;
}
.steps li {
	position: relative;
	padding-left: 58px;
	font-size: 24px;
	line-height: 1.4;
	color: var(--white);
}
.steps li::before {
	content: attr(data-n);
	position: absolute;
	left: 0;
	top: 0.32em;
	font-family: var(--mono);
	font-size: 16px;
	letter-spacing: 0.08em;
	color: var(--red);
}
.steps.cy li::before {
	color: var(--cyan);
}

/* ---------- chrome ---------- */
#chrome {
	position: absolute;
	inset: 0;
	z-index: 40;
	pointer-events: none;
}
#act {
	position: absolute;
	top: 32px;
	right: 42px;
	font-family: var(--mono);
	font-size: 16px;
	letter-spacing: 0.2em;
	text-transform: uppercase;
	color: var(--grey-d);
}
#brand {
	position: absolute;
	bottom: 28px;
	left: 42px;
	font-family: var(--mono);
	font-size: 15px;
	letter-spacing: 0.2em;
	text-transform: uppercase;
	color: var(--grey-d);
}
#count {
	position: absolute;
	bottom: 28px;
	right: 42px;
	font-family: var(--mono);
	font-size: 15px;
	letter-spacing: 0.14em;
	color: var(--grey-d);
}
#count b {
	color: var(--red);
	font-weight: 500;
}
#bar {
	position: absolute;
	left: 0;
	bottom: 0;
	height: 2px;
	background: var(--red);
	transition: width 0.42s var(--ease);
}

/* ---------- jump index ---------- */
#jump {
	position: fixed;
	inset: 0;
	z-index: 60;
	background: rgba(6, 6, 9, 0.97);
	backdrop-filter: blur(6px);
	display: none;
	padding: 54px 62px;
	overflow-y: auto;
}
#jump.on {
	display: block;
}
#jump h4 {
	font-family: var(--mono);
	font-size: 13px;
	letter-spacing: 0.24em;
	text-transform: uppercase;
	color: var(--red);
	margin-bottom: 24px;
}
#jumpList {
	columns: 3;
	column-gap: 50px;
}
#jumpList .ji {
	break-inside: avoid;
	display: grid;
	grid-template-columns: 38px 1fr;
	gap: 10px;
	font-size: 16px;
	line-height: 1.35;
	color: var(--grey);
	padding: 6px 9px;
	cursor: pointer;
	border: 1px solid transparent;
	border-radius: 2px;
}
#jumpList .ji:hover {
	color: var(--white);
	border-color: var(--line-2);
	background: var(--hover);
}
#jumpList .ji.cur {
	color: var(--red);
	border-color: var(--red);
}
#jumpList .ji .n {
	font-family: var(--mono);
	font-size: 12px;
	color: var(--grey-d);
	padding-top: 3px;
}
#jumpList .ji.cur .n {
	color: var(--red);
}
#jumpList .ji.head {
	margin-top: 18px;
	font-family: var(--mono);
	font-size: 11px;
	letter-spacing: 0.22em;
	text-transform: uppercase;
	color: var(--cyan);
	pointer-events: none;
	grid-template-columns: 1fr;
}

/* ---------- help ---------- */
#help {
	position: fixed;
	z-index: 70;
	left: 50%;
	top: 50%;
	transform: translate(-50%, -50%);
	background: var(--panel);
	border: 1px solid var(--line-2);
	border-radius: 4px;
	padding: 32px 38px;
	display: none;
	font-family: var(--mono);
	font-size: 14px;
	color: var(--grey);
}
#help.on {
	display: block;
}
#help h4 {
	font-size: 11px;
	letter-spacing: 0.24em;
	text-transform: uppercase;
	color: var(--white);
	margin-bottom: 16px;
}
#help td {
	padding: 5px 14px 5px 0;
	text-align: left;
}
#help td:first-child {
	color: var(--red);
	width: 140px;
}

@media (prefers-reduced-motion: reduce) {
	.slide,
	.frag,
	#bar {
		transition: none !important;
	}
	.slide.active .rise {
		animation: none !important;
	}
	/* morph.js checks the same query and skips its animations */
}

/* ============================================================
   Figures

   The inline SVGs carry literal hex in fill= and stroke=. Routing them
   through the tokens means one palette drives the diagrams, the prose and
   the canvases, and the light theme needs no edits to the markup. A CSS
   property beats a presentation attribute, so no !important is needed.
   ============================================================ */
[fill='#f4f6f9'] {
	fill: var(--white);
}
[stroke='#f4f6f9'] {
	stroke: var(--white);
}
[fill='#8b93a1'] {
	fill: var(--grey);
}
[fill='#4a5160'] {
	fill: var(--grey-d);
}
[stroke='#4a5160'] {
	stroke: var(--grey-d);
}
[fill='#ef4444'] {
	fill: var(--red);
}
[stroke='#ef4444'] {
	stroke: var(--red);
}
[fill='#22d3ee'] {
	fill: var(--cyan);
}
[stroke='#22d3ee'] {
	stroke: var(--cyan);
}
[stroke='#23232b'] {
	stroke: var(--fig-line);
}
/* knockout rects that punch a hole in the ground behind a label */
[fill='#08080b'] {
	fill: var(--bg);
}

/* ============================================================
   Light theme

   Not an inversion. The greys are re-picked so every one of them clears
   4.5:1 on white, which is the whole reason this option exists.
   ============================================================ */
:root[data-theme='light'] {
	--bg: #ffffff;
	--panel: #f5f7fa;
	--raise: #eef1f6;
	--white: #14161c;
	--grey: #4b5462;
	--grey-d: #69727f;
	--line: rgba(17, 20, 26, 0.14);
	--line-2: rgba(17, 20, 26, 0.3);
	--red: #c81e1e;
	--red-dim: rgba(200, 30, 30, 0.12);
	--cyan: #0b6e86;
	--cyan-dim: rgba(11, 110, 134, 0.12);

	--grid: rgba(17, 20, 26, 0.045);
	--sheen-a: rgba(17, 20, 26, 0.035);
	--sheen-b: rgba(17, 20, 26, 0.012);
	--tint: rgba(17, 20, 26, 0.018);
	--hover: rgba(17, 20, 26, 0.055);
	--fig-line: rgba(17, 20, 26, 0.22);
	--axis: rgba(17, 20, 26, 0.18);
}
:root[data-theme='light'] #jump {
	background: rgba(255, 255, 255, 0.97);
}

/* ---------- theme switch, first slide only ---------- */
#themeBtn {
	/* Top left: the slide counter owns the bottom right and the act label the
	   top right, and the title slide puts nothing in this corner. */
	position: fixed;
	left: 30px;
	top: 24px;
	z-index: 70;
	display: none;
	align-items: center;
	gap: 10px;
	padding: 9px 15px;
	background: var(--bg);
	border: 1px solid var(--line-2);
	border-radius: 2px;
	color: var(--grey);
	font-family: var(--mono);
	font-size: 12px;
	letter-spacing: 0.2em;
	text-transform: uppercase;
	cursor: pointer;
	transition:
		color 0.18s var(--ease),
		border-color 0.18s var(--ease);
}
body.first #themeBtn {
	display: flex;
}
#themeBtn:hover {
	color: var(--white);
	border-color: var(--red);
}
#themeBtn .sw {
	width: 10px;
	height: 10px;
	border: 1px solid var(--line-2);
	background: var(--white);
}

/* ---------- a photograph or a rendered frame, run as a band ---------- */
.shot {
	margin: 0;
}
.shot img {
	display: block;
	width: 100%;
	height: 500px;
	object-fit: cover;
	border: 1px solid var(--line);
	border-radius: 2px;
}
.shot figcaption {
	margin-top: 13px;
	font-family: var(--mono);
	font-size: 18px;
	color: var(--grey-d);
}
