:root {
	--bg: #0a0a0e;
	--ink: #e9e7f1;
	--muted: #807d8e;
	--line: #25232f;
	--tint: #121119;
	--accent: #a996ff;
	--hot: #dcff5e;
	--display: "Syne", "Helvetica Neue", Arial, sans-serif;
	--mono: "Martian Mono", ui-monospace, "SF Mono", Menlo, monospace;
	--sans: "Instrument Sans", system-ui, -apple-system, "Segoe UI", sans-serif;
	color-scheme: dark;
}

@media (prefers-color-scheme: light) {
	:root:not([data-theme="dark"]) {
		--bg: #e8e7ee;
		--ink: #0f0e17;
		--muted: #5e5b6d;
		--line: #c6c4d1;
		--tint: #dedce7;
		--accent: #4a2fe0;
		--hot: #ff3d1f;
		color-scheme: light;
	}
}

:root[data-theme="light"] {
	--bg: #e8e7ee;
	--ink: #0f0e17;
	--muted: #5e5b6d;
	--line: #c6c4d1;
	--tint: #dedce7;
	--accent: #4a2fe0;
	--hot: #ff3d1f;
	color-scheme: light;
}


/* The colour of the lamp is light itself, chosen in Settings, and not part of the theme. */
:root {
	--lamp: #ffffff;
}

* {
	box-sizing: border-box;
}

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

body {
	margin: 0;
	background: var(--bg);
	color: var(--ink);
	font-family: var(--sans);
	font-size: 17px;
	line-height: 1.6;
	-webkit-font-smoothing: antialiased;
}

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

:focus-visible {
	outline: 1px solid var(--hot);
	outline-offset: 3px;
}

[hidden] {
	display: none !important;
}

/* The app fills the window: header, stage, settings sheet, tabs. Only the sheet scrolls. */
.app {
	display: flex;
	flex-direction: column;
	height: 100vh;
	height: 100dvh;
	overflow: hidden;
	background: var(--bg);
}

/* Header */

.site-header {
	flex: none;
	display: flex;
	align-items: center;
	justify-content: space-between;
	gap: 16px;
	margin: 0 24px;
	padding: 22px 0;
	border-bottom: 1px solid var(--line);
}

.wordmark {
	display: inline-flex;
	align-items: center;
	gap: 10px;
	font-family: var(--display);
	font-weight: 700;
	font-size: 1.15rem;
	letter-spacing: -0.02em;
	color: var(--ink);
	text-decoration: none;
}

/* three nested rings, each tangent to the last */
.wordmark::before {
	content: "";
	width: 18px;
	height: 18px;
	border-radius: 50%;
	border: 1px solid currentColor;
	background:
		radial-gradient(circle at 50% 78%, transparent 2.5px, currentColor 2.5px, currentColor 3.5px, transparent 3.5px),
		radial-gradient(circle at 50% 64%, transparent 5px, currentColor 5px, currentColor 6px, transparent 6px);
}

.header-right {
	display: flex;
	align-items: center;
	gap: 22px;
}

/* the shared label type */
.crumb,
.readouts,
.caption,
.tool,
.play,
.group-head,
.row-label i,
.preset-pick span {
	font-family: var(--mono);
	font-size: 0.62rem;
	font-weight: 400;
	font-style: normal;
	letter-spacing: 0.1em;
	text-transform: uppercase;
	color: var(--muted);
}

.crumb b {
	font-weight: 400;
	color: var(--accent);
}

/* half-filled ring: flips between the light and dark theme */
.theme-toggle {
	width: 16px;
	height: 16px;
	padding: 0;
	border: 1px solid var(--muted);
	border-radius: 50%;
	background: linear-gradient(90deg, var(--muted) 50%, transparent 50%);
	cursor: pointer;
	transition: transform 0.3s;
}

.theme-toggle:hover {
	border-color: var(--ink);
	background: linear-gradient(90deg, var(--ink) 50%, transparent 50%);
	transform: rotate(180deg);
}

/* Stage */

.stage {
	position: relative;
	flex: 1;
	min-height: 180px;
	display: flex;
	align-items: center;
	justify-content: center;
	overflow: hidden;
	/* room for the readings above and the buttons below; the rings are sized from what is left */
	padding: 40px 0 66px;
	container-type: size;
}

/* The light is shown in the dark whatever the theme of the page. */
.stage[data-mode="light"] {
	--bg: #0a0a0e;
	--ink: #e9e7f1;
	--muted: #807d8e;
	--line: #25232f;
	--tint: #121119;
	--accent: #a996ff;
	--hot: #dcff5e;
	background: var(--bg);
	color: var(--ink);
}

/* Sized from the smaller side of the stage, with room left to grow into. */
.rings {
	width: min(58cqw, 58cqh);
	height: min(58cqw, 58cqh);
	overflow: visible;
	pointer-events: none;
	/* the rings breathe about a point a little below their middle */
	transform-origin: 50% 62%;
}

.rings circle,
.rings path {
	fill: none;
	stroke: var(--line);
	stroke-width: 1;
	vector-effect: non-scaling-stroke;
}

.rings circle:nth-child(4),
.rings path:nth-child(4) {
	stroke: var(--accent);
}

.lamp {
	position: absolute;
	inset: 0;
	background: var(--lamp);
	opacity: 0;
}

.stage[data-mode="light"] .rings,
.stage[data-mode="circle"] .lamp,
.stage[data-mode="circle"] .warn,
.stage[data-on] .warn,
.stage[data-mode="light"]:not([data-on]) .readouts {
	display: none;
}

.caption {
	position: absolute;
	top: 14%;
	left: 0;
	right: 0;
	margin: 0;
	text-align: center;
	font-size: 0.7rem;
	letter-spacing: 0.3em;
	color: var(--ink);
}

.warn {
	position: relative;
	max-width: 44ch;
	margin: 0 24px;
	text-align: center;
	font-size: 0.95rem;
	color: var(--muted);
}

/* readings in the corners of the stage; each keeps a patch of background so it
   stays readable over the lit lamp */
.readouts span {
	position: absolute;
	padding: 3px 7px;
	background: var(--bg);
	font-variant-numeric: tabular-nums;
}

.readouts b {
	font-weight: 400;
	color: var(--ink);
}

.readouts i {
	font-style: normal;
	text-transform: none;
	font-size: 1.25em;
	line-height: 0;
}

.r-alpha {
	top: 14px;
	left: 17px;
}

.r-int {
	bottom: 18px;
	left: 17px;
}

.r-left {
	bottom: 18px;
	right: 17px;
}

.readouts span > span {
	position: static;
	padding: 0;
}

/* four corners */
.full {
	position: absolute;
	top: 10px;
	right: 14px;
	width: 34px;
	height: 34px;
	padding: 7px;
	color: var(--muted);
	background: var(--bg);
	border: 0;
	cursor: pointer;
}

.full svg {
	display: block;
	width: 100%;
	height: 100%;
	fill: none;
	stroke: currentColor;
	stroke-width: 1.2;
}

.full:hover,
.full[aria-pressed="true"] {
	color: var(--ink);
}

/* speaker, to the left of the corners: waves while the sound is on, a cross while it is off */
.sound {
	right: 52px;
}

.sound .off,
.sound[aria-pressed="false"] .on {
	display: none;
}

.sound[aria-pressed="false"] .off {
	display: inline;
}

.controls {
	position: absolute;
	bottom: 14px;
	left: 50%;
	transform: translateX(-50%);
	display: flex;
	align-items: center;
	gap: 10px;
}

/* main button: a pill with a triangle that becomes a square while running */
.play {
	display: inline-flex;
	align-items: center;
	gap: 9px;
	color: var(--ink);
	background: var(--bg);
	border: 1px solid var(--ink);
	border-radius: 999px;
	padding: 9px 16px 9px 14px;
	cursor: pointer;
}

.play::before {
	content: "";
	width: 0;
	height: 0;
	border-style: solid;
	border-width: 5px 0 5px 8px;
	border-color: transparent transparent transparent currentColor;
}

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

.play[aria-pressed="true"]::before {
	width: 8px;
	height: 8px;
	border: 0;
	background: currentColor;
}

.play:hover {
	border-color: var(--hot);
}

/* secondary button: the same pill with a quiet border */
.tool {
	color: var(--ink);
	background: var(--bg);
	border: 1px solid var(--line);
	border-radius: 999px;
	padding: 9px 14px;
	cursor: pointer;
}

.tool:hover {
	border-color: var(--accent);
}

.tool[aria-expanded="true"] {
	border-color: var(--ink);
}

/* Settings sheet: rises between the stage and the tabs */

.sheet {
	flex: none;
	max-height: 52%;
	overflow-y: auto;
	padding: 0 24px 4px;
	border-top: 1px solid var(--line);
}

/* the series being played, with a playhead; it stays in view while the settings scroll */
.trace {
	position: sticky;
	top: 0;
	z-index: 1;
	display: grid;
	grid-template-columns: 96px 1fr;
	align-items: center;
	gap: 16px;
	margin: 0 0 18px;
	padding: 12px 0 10px;
	background: var(--bg);
	border-bottom: 1px solid var(--line);
}

.trace-label {
	font-family: var(--mono);
	font-size: 0.6rem;
	text-transform: uppercase;
	letter-spacing: 0.1em;
	line-height: 1.7;
	color: var(--muted);
}

.trace-label b {
	display: block;
	font-weight: 400;
	color: var(--ink);
}

.plot {
	position: relative;
	height: 64px;
	cursor: crosshair;
}

.plot svg {
	display: block;
	width: 100%;
	height: 100%;
}

.plot path {
	fill: none;
	stroke: var(--accent);
	stroke-width: 1.15;
	stroke-linejoin: round;
	vector-effect: non-scaling-stroke;
}

.ph {
	position: absolute;
	top: 0;
	bottom: 0;
	width: 1px;
	background: var(--hot);
	display: none;
}

.ph b {
	position: absolute;
	left: -3px;
	width: 7px;
	height: 7px;
	margin-top: -3.5px;
	border-radius: 50%;
	background: var(--hot);
}

.presets {
	display: flex;
	align-items: center;
	justify-content: space-between;
	flex-wrap: wrap;
	gap: 12px 20px;
	margin-bottom: 18px;
}

.preset-pick,
.preset-save {
	display: flex;
	align-items: center;
	gap: 10px;
}

.preset-save .num {
	width: 210px;
}

.group {
	margin: 0 0 20px;
	border: 1px solid var(--line);
	break-inside: avoid;
}

.group-head {
	display: flex;
	align-items: center;
	min-height: 40px;
	margin: 0;
	padding: 8px 14px;
	border-bottom: 1px solid var(--line);
}

.row {
	display: flex;
	align-items: center;
	justify-content: space-between;
	gap: 12px;
	min-height: 44px;
	padding: 6px 14px;
}

.row + .row {
	border-top: 1px solid var(--line);
}

.row-label {
	font-size: 0.86rem;
	line-height: 1.3;
}

.row-label i {
	margin-left: 8px;
	font-size: 0.56rem;
	opacity: 0.8;
}

.sel,
.num {
	height: 30px;
	font-family: var(--mono);
	font-size: 0.68rem;
	color: var(--ink);
	background-color: transparent;
	border: 1px solid var(--line);
	border-radius: 0;
}

/* the arrow is two small gradients, so the select stays square in every browser */
.sel {
	max-width: 230px;
	-webkit-appearance: none;
	appearance: none;
	padding: 0 26px 0 10px;
	background-image: linear-gradient(45deg, transparent 50%, var(--muted) 50%), linear-gradient(135deg, var(--muted) 50%, transparent 50%);
	background-position:
		calc(100% - 14px) 50%,
		calc(100% - 10px) 50%;
	background-size: 4px 4px;
	background-repeat: no-repeat;
}

.sel option,
.sel optgroup {
	color: var(--ink);
	background: var(--bg);
}

.num {
	width: 76px;
	padding: 0 8px;
}

.num::placeholder {
	color: var(--muted);
	opacity: 1;
}

.sel:hover,
.num:hover {
	border-color: var(--muted);
}

.range-pair {
	display: flex;
	align-items: center;
	gap: 12px;
	font-family: var(--mono);
	font-size: 0.68rem;
}

/* colour well: a square of the chosen colour */
.swatch {
	-webkit-appearance: none;
	appearance: none;
	flex: none;
	width: 44px;
	height: 30px;
	padding: 0;
	background: none;
	border: 1px solid var(--line);
	border-radius: 0;
	cursor: pointer;
}

.swatch::-webkit-color-swatch-wrapper {
	padding: 3px;
}

.swatch::-webkit-color-swatch {
	border: 0;
	border-radius: 0;
}

.swatch::-moz-color-swatch {
	border: 3px solid var(--bg);
	border-radius: 0;
}

.swatch:hover {
	border-color: var(--muted);
}

.range-pair b {
	min-width: 4ch;
	font-weight: 400;
	text-align: right;
	font-variant-numeric: tabular-nums;
}

/* a hairline with a ring for a knob */
.range {
	-webkit-appearance: none;
	appearance: none;
	width: 140px;
	height: 18px;
	margin: 0;
	background: linear-gradient(var(--muted), var(--muted)) center / 100% 1px no-repeat;
	cursor: pointer;
}

.range::-webkit-slider-thumb {
	-webkit-appearance: none;
	width: 13px;
	height: 13px;
	border: 1px solid var(--accent);
	border-radius: 50%;
	background: var(--bg);
}

.range::-moz-range-thumb {
	box-sizing: border-box;
	width: 13px;
	height: 13px;
	border: 1px solid var(--accent);
	border-radius: 50%;
	background: var(--bg);
}

.range:hover::-webkit-slider-thumb {
	background: var(--accent);
}

.range:hover::-moz-range-thumb {
	background: var(--accent);
}

/* switch */
.toggle {
	position: relative;
	flex: none;
	width: 34px;
	height: 18px;
	padding: 0;
	background: none;
	border: 1px solid var(--muted);
	border-radius: 999px;
	cursor: pointer;
	transition:
		background-color 0.2s,
		border-color 0.2s;
}

.toggle::after {
	content: "";
	position: absolute;
	top: 3px;
	left: 3px;
	width: 10px;
	height: 10px;
	border-radius: 50%;
	background: var(--muted);
	transition:
		transform 0.2s,
		background-color 0.2s;
}

.toggle[aria-checked="true"] {
	background: var(--accent);
	border-color: var(--accent);
}

.toggle[aria-checked="true"]::after {
	background: var(--bg);
	transform: translateX(16px);
}

.sheet-note {
	max-width: 76ch;
	margin: 0 0 18px;
	font-size: 0.88rem;
	line-height: 1.5;
	color: var(--muted);
}

/* Tabs: the bottom menu of tools.fractality.app */

.tabs {
	flex: none;
	display: flex;
	justify-content: center;
	height: 64px;
	padding-bottom: env(safe-area-inset-bottom);
	box-sizing: content-box;
	background: var(--bg);
	border-top: 1px solid var(--line);
}

.tabs button {
	flex: 1;
	max-width: 168px;
	min-width: 0;
	padding: 8px 2px;
	display: inline-flex;
	flex-direction: column;
	align-items: center;
	justify-content: center;
	color: var(--muted);
	background: none;
	border: 0;
	cursor: pointer;
	transition: color 0.25s;
}

.tabs svg {
	width: 1.25rem;
	height: 1.25rem;
	fill: none;
	stroke: currentColor;
	stroke-width: 1.2;
	stroke-linecap: round;
}

.tabs span {
	margin-top: 5px;
	font-family: var(--mono);
	font-size: 0.54rem;
	font-weight: 400;
	letter-spacing: 0.06em;
	text-transform: uppercase;
}

.tabs button[aria-current="page"] {
	color: var(--accent);
}

/* Full screen: only the stage is left, and its buttons fade until the pointer moves */

.app[data-full] .site-header,
.app[data-full] .sheet,
.app[data-full] .tabs {
	display: none;
}

.controls,
.full,
.readouts {
	transition: opacity 0.3s;
}

.app[data-idle] .controls,
.app[data-idle] .full,
.app[data-idle] .readouts {
	opacity: 0;
}

.app[data-idle] {
	cursor: none;
}

@media (min-width: 760px) {
	.settings {
		columns: 2;
		column-gap: 20px;
	}
}

@media (max-width: 820px) {
	.site-header {
		margin: 0 16px;
		padding: 16px 0;
	}
	.sheet {
		padding: 0 16px 4px;
	}
	.trace {
		grid-template-columns: 1fr;
		gap: 2px;
	}
	.trace-label b {
		display: inline;
		margin-right: 8px;
	}
	.plot {
		height: 52px;
	}
	.preset-pick,
	.preset-save {
		flex: 1 1 100%;
		flex-wrap: wrap;
	}
	.preset-pick .sel {
		flex: 1;
		max-width: none;
	}
	.preset-save .num {
		flex: 1 1 100%;
		width: auto;
		min-width: 0;
	}
	/* the buttons take the bottom of a narrow stage, so the readings stack at the top */
	.r-int {
		top: 38px;
		bottom: auto;
	}
	.r-left {
		top: 62px;
		bottom: auto;
		left: 17px;
		right: auto;
	}
	.sel,
	.num {
		height: 34px;
	}
	.row-label {
		font-size: 0.82rem;
	}
	.range {
		width: 110px;
	}
}

@media (prefers-reduced-motion: reduce) {
	.theme-toggle,
	.toggle,
	.toggle::after,
	.tabs button,
	.controls,
	.full,
	.readouts {
		transition: none;
	}
}
