:root {
	--bg: #04050b;
	--ink: #ece8ff;
	--muted: #9a9fc2;
	--accent: #ffc46b;
	--hypo: #ff8fa6;
	--track: rgba(154, 159, 194, 0.22);
	--panel: rgba(10, 11, 24, 0.72);
	--line: rgba(154, 159, 194, 0.28);
	color-scheme: dark;
}

* {
	box-sizing: border-box;
}

html,
body {
	margin: 0;
	height: 100%;
}

body {
	overflow: hidden;
	background: var(--bg);
	color: var(--ink);
	font-family: ui-sans-serif, system-ui, -apple-system, "Segoe UI", sans-serif;
	-webkit-font-smoothing: antialiased;
}

.scene {
	position: fixed;
	inset: 0;
	width: 100%;
	height: 100%;
	display: block;
	cursor: grab;
	touch-action: none;
	user-select: none;
	-webkit-user-select: none;
}

.scene.is-orbiting {
	cursor: grabbing;
}

.labels {
	position: fixed;
	inset: 0;
	pointer-events: none;
	overflow: hidden;
}

.prime-label {
	position: absolute;
	top: 0;
	left: 0;
	font: 600 0.78rem/1 ui-monospace, "SF Mono", Menlo, monospace;
	color: var(--accent);
	text-shadow: 0 0 0.25rem #000, 0 0 0.6rem #000, 0 0 0.8rem rgba(255, 170, 70, 0.45);
	white-space: nowrap;
	opacity: 0;
	will-change: transform, opacity;
}

.scene-label {
	position: absolute;
	top: 0;
	left: 0;
	font: 500 0.7rem/1.2 ui-monospace, "SF Mono", Menlo, monospace;
	letter-spacing: 0.04em;
	white-space: nowrap;
	text-shadow: 0 0 0.3rem #000, 0 0 0.7rem #000;
	opacity: 0;
	will-change: transform, opacity;
}

.column-label {
	color: #fff3dc;
}

.limit-label {
	padding: 0.3rem 0.7rem;
	font-size: 0.72rem;
	color: #fff3dc;
	background: rgba(8, 9, 20, 0.72);
	border: 1px solid rgba(255, 243, 220, 0.18);
	border-radius: 1rem;
	text-shadow: none;
}

.caption {
	position: fixed;
	top: 1.5rem;
	left: 1.5rem;
	width: min(24rem, calc(100% - 3rem));
	display: grid;
	gap: 0.55rem;
	padding: 1rem 1.1rem;
	background: rgba(10, 11, 24, 0.62);
	border: 1px solid rgba(236, 232, 255, 0.07);
	border-radius: 0.75rem;
	backdrop-filter: blur(0.75rem);
	transition: background-color 0.35s ease, border-color 0.35s ease;
}

/* Only the contents fade at rest; an element-wide opacity would let the scene's labels show through. */
.caption > * {
	opacity: 0.72;
	transition: opacity 0.35s ease;
}

.caption:hover,
.caption:focus-within {
	background: rgba(10, 11, 24, 0.85);
	border-color: var(--line);
}

.caption:hover > *,
.caption:focus-within > * {
	opacity: 1;
}

.caption-head {
	display: flex;
	align-items: center;
	gap: 0.25rem;
}

.caption-head h1 {
	flex: 1;
	white-space: nowrap;
	margin-inline-end: 0.5rem;
}

/* Collapses by animating its row from 0fr to 1fr, so the caption's height eases and the camera follows it. */
.tools {
	display: grid;
	grid-template-rows: 1fr;
	align-self: start;
	transition: grid-template-rows 0.35s cubic-bezier(0.2, 0.8, 0.2, 1), margin-top 0.35s cubic-bezier(0.2, 0.8, 0.2, 1), visibility 0s;
}

/* The clip margin keeps focus rings clear of the clipping edge. */
.tools-inner {
	min-height: 0;
	overflow: clip;
	overflow-clip-margin: 0.25rem;
}

/* Margins, not gap: a grid gap inside would keep the closed row from reaching zero height. */
.tools-inner > * + * {
	margin-top: 0.55rem;
}

.is-tools-closed .tools {
	grid-template-rows: 0fr;
	margin-top: -0.55rem;
	visibility: hidden;
	transition: grid-template-rows 0.3s ease, margin-top 0.3s ease, visibility 0s 0.3s;
}

.tools-toggle .knob {
	fill: var(--panel);
}

.tools-toggle[aria-expanded="true"] {
	color: var(--accent);
}

/* A what-if left running stays visible on the closed button. */
.is-hypothetical .tools-toggle {
	color: var(--hypo);
}

.caption h1 {
	margin: 0;
	font-size: 0.8rem;
	font-weight: 600;
	letter-spacing: 0.32em;
	text-transform: uppercase;
	color: var(--accent);
}

.icon-button {
	flex: none;
	display: grid;
	place-items: center;
	width: 1.75rem;
	height: 1.75rem;
	padding: 0;
	color: var(--muted);
	background: transparent;
	border: 0;
	border-radius: 50%;
	cursor: pointer;
	transition: color 0.2s ease, background-color 0.2s ease;
}

.icon-button:hover {
	color: var(--accent);
	background: rgba(255, 196, 107, 0.1);
}

.icon-button svg {
	width: 1.25rem;
	height: 1.25rem;
	fill: none;
	stroke: currentColor;
	stroke-width: 1.4;
	stroke-linecap: round;
}

.icon-button .dot {
	fill: currentColor;
	stroke: none;
}

.caption .subtitle {
	margin: -0.2rem 0 0.1rem;
	font-family: ui-serif, "New York", Georgia, "Times New Roman", serif;
	font-size: 0.8rem;
	font-style: italic;
	line-height: 1.35;
	letter-spacing: 0.01em;
	color: var(--muted);
}

.experiment {
	display: grid;
	grid-template-columns: 1fr auto;
	gap: 0.3rem 0.75rem;
	align-items: center;
	padding-top: 0.6rem;
	border-top: 1px solid var(--line);
	font-size: 0.78rem;
	color: var(--ink);
}

.experiment input[type="range"] {
	grid-column: 1 / -1;
	min-width: 0;
	margin: 0;
}

.experiment output {
	font-family: ui-monospace, "SF Mono", Menlo, monospace;
	font-size: 0.72rem;
	color: var(--muted);
	white-space: nowrap;
}

.is-hypothetical .experiment output {
	color: var(--hypo);
}

.range {
	--fill: 0%;
	--range-color: var(--accent);
	appearance: none;
	height: 1.25rem;
	background: transparent;
	cursor: pointer;
}

.is-hypothetical #beta {
	--range-color: var(--hypo);
}

.range::-webkit-slider-runnable-track {
	height: 0.375rem;
	border-radius: 0.1875rem;
	background: linear-gradient(to right, var(--range-color) var(--fill), var(--track) var(--fill));
}

.range::-moz-range-track {
	height: 0.375rem;
	border-radius: 0.1875rem;
	background: linear-gradient(to right, var(--range-color) var(--fill), var(--track) var(--fill));
}

.range::-webkit-slider-thumb {
	appearance: none;
	width: 1.125rem;
	height: 1.125rem;
	margin-top: -0.375rem;
	border: 2px solid var(--bg);
	border-radius: 50%;
	background: var(--range-color);
	box-shadow: 0 0 0.75rem color-mix(in srgb, var(--range-color) 55%, transparent);
	transition: transform 0.15s ease;
}

.range::-moz-range-thumb {
	width: 1.125rem;
	height: 1.125rem;
	border: 2px solid var(--bg);
	border-radius: 50%;
	background: var(--range-color);
	box-shadow: 0 0 0.75rem color-mix(in srgb, var(--range-color) 55%, transparent);
	transition: transform 0.15s ease;
}

.range:hover::-webkit-slider-thumb,
.range:active::-webkit-slider-thumb {
	transform: scale(1.15);
}

.range:hover::-moz-range-thumb,
.range:active::-moz-range-thumb {
	transform: scale(1.15);
}

.range:focus-visible {
	outline: 2px solid var(--range-color);
	outline-offset: 0.25rem;
	border-radius: 0.5rem;
}

.range:disabled {
	cursor: not-allowed;
}

.switch {
	display: flex;
	align-items: center;
	gap: 0.55rem;
	width: fit-content;
	min-height: 2.75rem;
	padding-inline-end: 0.5rem;
	font-size: 0.78rem;
	color: var(--ink);
	cursor: pointer;
}

.switch input {
	position: absolute;
	opacity: 0;
	width: 1px;
	height: 1px;
}

.eye {
	width: 1.35rem;
	height: 1.35rem;
	fill: none;
	stroke: var(--muted);
	stroke-width: 1.5;
	stroke-linecap: round;
	stroke-linejoin: round;
	border-radius: 0.3rem;
	transition: stroke 0.25s ease;
}

.eye-slash {
	stroke-dasharray: 1;
	stroke-dashoffset: 0;
	transition: stroke-dashoffset 0.3s cubic-bezier(0.2, 0.8, 0.2, 1);
}

.switch:hover .eye {
	stroke: var(--ink);
}

.switch input:checked + .eye {
	stroke: var(--accent);
}

.switch input:checked + .eye .eye-slash {
	stroke-dashoffset: 1;
}

.switch input:focus-visible + .eye,
.caption :focus-visible {
	outline: 2px solid var(--accent);
	outline-offset: 2px;
}

.about {
	width: min(34rem, calc(100% - 2rem));
	max-height: min(36rem, calc(100% - 2rem));
	padding: 1.5rem 1.6rem 1.25rem;
	color: var(--ink);
	background: rgba(12, 13, 28, 0.94);
	border: 1px solid var(--line);
	border-radius: 1rem;
	box-shadow: 0 1.5rem 4rem rgba(0, 0, 0, 0.55);
	opacity: 0;
	transform: translateY(0.75rem) scale(0.98);
	transition: opacity 0.3s ease, transform 0.4s cubic-bezier(0.2, 0.8, 0.2, 1), overlay 0.4s allow-discrete, display 0.4s allow-discrete;
}

.about[open] {
	display: grid;
	gap: 0.8rem;
	opacity: 1;
	transform: none;
}

@starting-style {
	.about[open] {
		opacity: 0;
		transform: translateY(0.75rem) scale(0.98);
	}
}

.about::backdrop {
	background: rgba(4, 5, 11, 0);
	backdrop-filter: blur(0);
	transition: background-color 0.35s ease, backdrop-filter 0.35s ease, overlay 0.4s allow-discrete, display 0.4s allow-discrete;
}

.about[open]::backdrop {
	background: rgba(4, 5, 11, 0.55);
	backdrop-filter: blur(0.2rem);
}

@starting-style {
	.about[open]::backdrop {
		background: rgba(4, 5, 11, 0);
		backdrop-filter: blur(0);
	}
}

.about .about-lede {
	font-family: ui-serif, "New York", Georgia, "Times New Roman", serif;
	font-size: 1.02rem;
	line-height: 1.5;
	color: var(--ink);
}

.about {
	scrollbar-width: thin;
	scrollbar-color: var(--line) transparent;
}

/* Safari ignores scrollbar-color; the WebKit pseudo-elements give it the same thin, quiet thumb. */
.about::-webkit-scrollbar {
	width: 0.5rem;
}

.about::-webkit-scrollbar-track {
	background: transparent;
}

.about::-webkit-scrollbar-thumb {
	background: var(--line);
	border: 2px solid transparent;
	border-radius: 1rem;
	background-clip: padding-box;
}

.about::-webkit-scrollbar-thumb:hover {
	background-color: var(--muted);
}

.about-head {
	display: flex;
	align-items: center;
	justify-content: space-between;
	gap: 0.75rem;
	margin: -0.4rem -0.5rem 0 0;
}

.about-head h2 {
	margin: 0;
}

.about h2 {
	margin: 0 0 0.2rem;
	font-size: 0.8rem;
	font-weight: 600;
	letter-spacing: 0.24em;
	text-transform: uppercase;
	color: var(--accent);
}

.about p {
	margin: 0;
	font-size: 0.9rem;
	line-height: 1.6;
	color: #c4c8e4;
}

.about b {
	font-weight: 600;
	color: var(--ink);
}

.about .for-touch {
	display: none;
}

.about-close {
	justify-self: end;
	margin-top: 0.3rem;
	padding: 0.45rem 1.1rem;
	font: inherit;
	font-size: 0.82rem;
	color: #1a1306;
	background: var(--accent);
	border: 0;
	border-radius: 2rem;
	cursor: pointer;
}

.about-close:focus-visible {
	outline: 2px solid #fff;
	outline-offset: 2px;
}

.fallback {
	margin: 1rem 0 0;
	font-size: 0.9rem;
	color: #ffb36b;
}

.panel-toggle {
	position: fixed;
	top: 1.5rem;
	right: 1.5rem;
	width: 8.5rem;
	height: 2rem;
	font: 600 0.72rem/1 ui-monospace, "SF Mono", Menlo, monospace;
	letter-spacing: 0.08em;
	color: var(--ink);
	background: var(--panel);
	border: 1px solid var(--line);
	border-radius: 0.6rem;
	backdrop-filter: blur(0.6rem);
	cursor: pointer;
}

.panel-toggle::after {
	content: " ▾" / "";
	color: var(--muted);
}

.panel-toggle[aria-expanded="false"]::after {
	content: " ▸" / "";
}

.panel-toggle:focus-visible {
	outline: 2px solid var(--accent);
	outline-offset: 2px;
}

.panel {
	transform-origin: top center;
	transition: opacity 0.35s ease, transform 0.45s cubic-bezier(0.2, 0.8, 0.2, 1), visibility 0s;
}

/* Until the script has set the starting state, nothing animates and a phone never shows the panel open. */
.is-loading .panel,
.is-loading .tools {
	transition: none;
}

.is-panel-closed .panel {
	opacity: 0;
	transform: translateY(-0.6rem) scaleY(0.97);
	visibility: hidden;
	pointer-events: none;
	transition: opacity 0.3s ease, transform 0.35s ease, visibility 0s 0.35s;
}

.panel {
	position: fixed;
	top: 4rem;
	right: 1.5rem;
	width: 8.5rem;
	height: calc(100% - 12rem);
	background: var(--panel);
	border: 1px solid var(--line);
	border-radius: 0.6rem;
	backdrop-filter: blur(0.6rem);
	pointer-events: none;
}

.controls {
	position: fixed;
	left: 50%;
	bottom: 3.2rem;
	transform: translateX(-50%);
	width: min(46rem, calc(100% - 2rem));
	display: flex;
	flex-wrap: wrap;
	justify-content: center;
	gap: 0.7rem 1rem;
	align-items: center;
	font-size: 0.75rem;
	color: var(--ink);
}

.transport {
	display: flex;
	gap: 0.5rem;
}

.controls button {
	display: grid;
	place-items: center;
	padding: 0;
	font: 600 0.8rem/1 ui-monospace, "SF Mono", Menlo, monospace;
	color: var(--ink);
	background: var(--panel);
	border: 1px solid var(--line);
	cursor: pointer;
	backdrop-filter: blur(0.5rem);
	transition: background-color 0.2s ease, color 0.2s ease, opacity 0.2s ease;
}

.controls svg {
	width: 1.1rem;
	height: 1.1rem;
	fill: currentColor;
}

.round {
	width: 2.75rem;
	height: 2.75rem;
	border-radius: 50%;
}

.round .pause,
.round[aria-pressed="true"] .go {
	display: none;
}

.round[aria-pressed="true"] .pause {
	display: inline;
}

.round[aria-pressed="true"] {
	color: var(--bg);
	background: var(--accent);
	border-color: var(--accent);
}

.controls button:disabled {
	opacity: 0.35;
	cursor: default;
}

.zeros {
	flex: 1 1 16rem;
	min-width: 0;
	display: flex;
	gap: 0.7rem;
	align-items: center;
	height: 2.75rem;
	padding: 0 1rem;
	background: var(--panel);
	border: 1px solid var(--line);
	border-radius: 1.375rem;
	backdrop-filter: blur(0.5rem);
	color: var(--muted);
}

.zeros input {
	flex: 1;
	min-width: 0;
}

.zeros input:disabled {
	opacity: 0.45;
	cursor: not-allowed;
}

.value {
	min-width: 8.5rem;
	font-family: ui-monospace, "SF Mono", Menlo, monospace;
	font-variant-numeric: tabular-nums;
	color: var(--ink);
}

.picker {
	display: flex;
	align-items: center;
	gap: 0.25rem;
}

.picker-label {
	margin-right: 0.25rem;
	font-family: ui-monospace, "SF Mono", Menlo, monospace;
	color: var(--muted);
}

.arrow {
	width: 2rem;
	height: 2rem;
	border-radius: 50%;
}

.arrow svg {
	fill: none;
	stroke: currentColor;
	stroke-width: 2.4;
	stroke-linecap: round;
	stroke-linejoin: round;
}

.reel {
	width: 10.5rem;
	overflow: hidden;
	mask-image: linear-gradient(to right, transparent, #000 32%, #000 68%, transparent);
}

.strip {
	display: flex;
	transition: transform 0.35s cubic-bezier(0.3, 0.7, 0.2, 1);
}

.strip button {
	flex: none;
	width: 3.5rem;
	height: 2.75rem;
	border-radius: 1.375rem;
	background: transparent;
	border-color: transparent;
	backdrop-filter: none;
	font-size: 0.85rem;
	color: var(--muted);
	opacity: 0.9;
}

.strip button[aria-pressed="true"] {
	font-size: 1rem;
	color: var(--bg);
	background: var(--accent);
	border-color: var(--accent);
	opacity: 1;
}

.controls button:focus-visible,
.controls input:focus-visible {
	outline: 2px solid var(--accent);
	outline-offset: 2px;
}

.hints {
	position: fixed;
	right: 1rem;
	bottom: 1.2rem;
	left: 1rem;
	display: flex;
	flex-wrap: wrap;
	justify-content: center;
	gap: 0.5rem 1.5rem;
	font-size: 0.78rem;
	color: var(--muted);
	text-shadow: 0 0 0.5rem #000;
	transition: opacity 1.2s ease;
}

.hints b {
	font-weight: 600;
	color: var(--ink);
}

.hints .for-touch {
	display: none;
}

@media (pointer: coarse) {
	.about .for-touch {
		display: block;
	}

	.hints .for-mouse {
		display: none;
	}

	.hints .for-touch {
		display: inline;
	}
}

.hints.is-quiet {
	opacity: 0.35;
}

@media (max-width: 40rem) {
	.caption {
		top: 0.75rem;
		left: 0.75rem;
		width: calc(100% - 1.5rem);
		padding: 0.75rem 0.9rem;
		gap: 0.45rem;
	}

	.caption .subtitle {
		font-size: 0.76rem;
	}

	.is-loading .panel {
		visibility: hidden;
	}

	.is-loading .tools {
		grid-template-rows: 0fr;
		margin-top: -0.45rem;
		visibility: hidden;
	}

	.tools-inner > * + * {
		margin-top: 0.45rem;
	}

	.is-tools-closed .tools {
		margin-top: -0.45rem;
	}

	.hints > span,
	.hints > span.for-touch {
		display: none;
	}

	.controls {
		bottom: 2.8rem;
		gap: 0.6rem;
	}

	.zeros {
		order: 1;
		flex-basis: 100%;
	}

	.picker-label {
		display: none;
	}

	.value {
		min-width: 7.5rem;
	}

	.panel-toggle {
		top: auto;
		bottom: 13.4rem;
		right: 0.75rem;
		width: 5.5rem;
	}

	.panel {
		transform-origin: bottom center;
	}

	.is-panel-closed .panel {
		transform: translateY(0.6rem) scaleY(0.97);
	}

	.panel {
		top: auto;
		bottom: 15.8rem;
		right: 0.75rem;
		width: 5.5rem;
		height: min(20rem, calc(100% - 32rem));
	}

	.hints {
		gap: 0.25rem 1rem;
		font-size: 0.7rem;
	}
}

@media (prefers-reduced-motion: reduce) {
	.range::-webkit-slider-thumb,
	.range::-moz-range-thumb {
		transition: none;
	}

	.strip,
	.controls button,
	.hints,
	.caption,
	.caption > *,
	.tools,
	.is-tools-closed .tools,
	.panel,
	.is-panel-closed .panel,
	.about,
	.about::backdrop,
	.eye,
	.eye-slash {
		transition: none;
	}
}

.about:focus {
	outline: none;
}
