/* The page fills the window. The tabs sit on top, the 3D view on the left and
 * the selected tab's panel on the right. Sizes are in rem, and the root font
 * grows with the window width, so the page reads the same on a 1080p screen
 * and on a 4K screen at 100 percent scaling.
 */

:root {
	color-scheme: light;
	--bg: #f3f2ee;
	--panel: #fbfaf8;
	--ink: #1f1e1b;
	--ink-2: #5c5a54;
	--ink-3: #8a877f;
	--rule: #dcdad3;
	--rule-strong: #b3b0a7;
	--viewport-bg: #fbfaf8;
	--inset-bg: #dde4ec;
	--code-bg: #eeede8;
	--blue: #378add;
	--green: #1d9e75;
	--red: #e24b4a;
	--grey: #888780;
	--amber: #e0962a;
	--sans: "IBM Plex Sans", system-ui, -apple-system, "Segoe UI", sans-serif;
	--mono: "IBM Plex Mono", ui-monospace, "SFMono-Regular", Menlo, monospace;
}

@media (prefers-color-scheme: dark) {
	:root:not([data-theme="light"]) {
		color-scheme: dark;
		--bg: #121211;
		--panel: #1a1a18;
		--ink: #ecebe6;
		--ink-2: #a9a69e;
		--ink-3: #7d7a73;
		--rule: #302f2c;
		--rule-strong: #57554f;
		--viewport-bg: #181816;
		--inset-bg: #27303a;
		--code-bg: #252522;
	}
}

:root[data-theme="dark"] {
	color-scheme: dark;
	--bg: #121211;
	--panel: #1a1a18;
	--ink: #ecebe6;
	--ink-2: #a9a69e;
	--ink-3: #7d7a73;
	--rule: #302f2c;
	--rule-strong: #57554f;
	--viewport-bg: #181816;
	--inset-bg: #27303a;
	--code-bg: #252522;
}

html {
	font-size: clamp(15px, calc(8.5px + 0.33vw), 24px);
}

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

body {
	background: var(--bg);
	color: var(--ink);
	font-family: var(--sans);
	font-size: 1rem;
	line-height: 1.5;
}

* {
	box-sizing: border-box;
}

[hidden] {
	display: none !important;
}

.app {
	display: grid;
	grid-template-rows: auto minmax(0, 1fr);
	height: 100vh;
	height: 100dvh;
}

/* The top bar with the title and the tabs. */

.topbar {
	display: flex;
	align-items: center;
	gap: 0.5rem 2rem;
	flex-wrap: wrap;
	padding: 0.5rem 1rem;
	border-bottom: 1px solid var(--rule);
}

.topbar h1 {
	margin: 0;
	font-size: 1.15rem;
	font-weight: 600;
	letter-spacing: -0.01em;
}

.tabs {
	display: flex;
	gap: 0.25rem;
}

.tabs button {
	font: inherit;
	font-weight: 600;
	padding: 0.3rem 1rem;
	border: 1px solid transparent;
	border-radius: 0.4rem;
	background: none;
	color: var(--ink-2);
	cursor: pointer;
}

.tabs button:hover {
	color: var(--ink);
}

.tabs button[aria-selected="true"] {
	background: var(--panel);
	border-color: var(--rule);
	color: var(--ink);
}

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

/* The 3D view and the panel beside it. */

.main {
	display: grid;
	grid-template-columns: minmax(0, 1fr) clamp(22rem, 30vw, 40rem);
	min-height: 0;
}

/* A page tab hides the 3D view and fills the main area with its own page. */

.main.page-mode {
	grid-template-columns: minmax(0, 1fr);
}

.main.page-mode .viewport {
	display: none;
}

.page-panel {
	display: flex;
	min-height: 0;
}

.page-panel[hidden] {
	display: none;
}

.page-panel iframe {
	flex: 1;
	border: 0;
	width: 100%;
	height: 100%;
}

.viewport {
	position: relative;
	min-width: 0;
	min-height: 0;
	overflow: hidden;
	background: var(--viewport-bg);
}

.viewport canvas {
	position: absolute;
	top: 0;
	left: 0;
	display: block;
	touch-action: none;
}

.viewport .hint {
	position: absolute;
	top: 0.6rem;
	left: 0.9rem;
	margin: 0;
	padding: 0.1rem 0.5rem;
	border-radius: 0.3rem;
	background: color-mix(in srgb, var(--viewport-bg) 85%, transparent);
	font-size: 0.85rem;
	color: var(--ink-2);
	pointer-events: none;
}

.inset {
	position: absolute;
	outline: 1px solid var(--rule-strong);
	border-radius: 2px;
	cursor: crosshair;
	touch-action: none;
}

.inset-label {
	position: absolute;
	right: -0.5rem;
	bottom: calc(100% + 0.2rem);
	padding: 0.1rem 0.5rem;
	border-radius: 0.3rem;
	background: color-mix(in srgb, var(--viewport-bg) 85%, transparent);
	font-size: 0.85rem;
	color: var(--ink-2);
	white-space: nowrap;
	pointer-events: none;
}

.panel {
	display: grid;
	align-content: start;
	gap: 1.25rem;
	overflow-y: auto;
	padding: 1rem 1.25rem 3rem;
	border-left: 1px solid var(--rule);
	background: var(--panel);
}

.panel h2 {
	margin: 0;
	font-size: 1.3rem;
	font-weight: 600;
	letter-spacing: -0.01em;
}

.panel h3 {
	margin: 0 0 0.4rem;
	font-size: 1rem;
	font-weight: 600;
}

.panel p {
	margin: 0;
}

.panel section {
	display: grid;
	gap: 0.5rem;
}

.lede {
	color: var(--ink-2);
}

code {
	font-family: var(--mono);
	font-size: 0.88em;
	padding: 0.05em 0.3em;
	border-radius: 0.25em;
	background: var(--code-bg);
}

a {
	color: var(--blue);
}

/* The live result of the current settings. */

.readout {
	display: grid;
	gap: 0.4rem;
	padding: 0.75rem 1rem;
	border: 1px solid var(--rule);
	border-radius: 0.5rem;
	background: var(--bg);
}

.readout .big {
	display: flex;
	align-items: center;
	gap: 0.75rem;
	font-family: var(--mono);
	font-size: 1.8rem;
	font-weight: 500;
	font-variant-numeric: tabular-nums;
}

.readout .big small {
	font-family: var(--sans);
	font-size: 0.85rem;
	font-weight: 400;
	color: var(--ink-2);
}

.swatch {
	width: 1.6rem;
	height: 1.6rem;
	border-radius: 0.3rem;
	border: 1px solid var(--rule-strong);
}

/* The colour key. */

.legend {
	display: flex;
	flex-wrap: wrap;
	gap: 0.3rem 1.2rem;
	margin: 0;
	padding: 0;
	list-style: none;
	font-size: 0.85rem;
	color: var(--ink-2);
}

.legend li {
	display: flex;
	align-items: center;
	gap: 0.4rem;
}

.dot,
.bar {
	display: inline-block;
	flex: none;
}

.dot {
	width: 0.7rem;
	height: 0.7rem;
	border-radius: 50%;
}

.dot.faint {
	opacity: 0.4;
}

.bar {
	width: 1rem;
	height: 0.2rem;
	border-radius: 0.1rem;
}

.blue { background: var(--blue); }
.green { background: var(--green); }
.red { background: var(--red); }
.grey { background: var(--grey); }
.amber { background: var(--amber); }

/* Sliders and switches. */

.controls {
	display: grid;
	gap: 0.45rem;
}

.control {
	display: grid;
	grid-template-columns: minmax(0, 12rem) minmax(0, 1fr) 4rem;
	align-items: center;
	gap: 0.75rem;
	font-size: 0.9rem;
	color: var(--ink-2);
}

.control output {
	font-family: var(--mono);
	font-variant-numeric: tabular-nums;
	text-align: right;
	color: var(--ink);
}

.toggles {
	display: flex;
	flex-wrap: wrap;
	gap: 0.4rem 1.4rem;
	font-size: 0.9rem;
	color: var(--ink-2);
}

.toggles label {
	display: flex;
	align-items: center;
	gap: 0.45rem;
	cursor: pointer;
}

input[type="checkbox"] {
	width: 1.05rem;
	height: 1.05rem;
	margin: 0;
	accent-color: var(--blue);
}

input[type="range"] {
	-webkit-appearance: none;
	appearance: none;
	width: 100%;
	height: 0.3rem;
	margin: 0.5rem 0;
	border-radius: 1rem;
	background: var(--rule);
	cursor: pointer;
}

input[type="range"]::-webkit-slider-thumb {
	-webkit-appearance: none;
	width: 1.1rem;
	height: 1.1rem;
	border-radius: 50%;
	border: 2px solid var(--blue);
	background: var(--panel);
}

input[type="range"]::-moz-range-thumb {
	width: 1.1rem;
	height: 1.1rem;
	border-radius: 50%;
	border: 2px solid var(--blue);
	background: var(--panel);
}

.note {
	font-size: 0.85rem;
	color: var(--ink-3);
}

/* The steps of each technique, and lists of things to try. */

ol.steps,
ul.tries {
	display: grid;
	gap: 0.6rem;
	margin: 0;
	padding-left: 1.4rem;
}

ol.steps li::marker {
	font-weight: 600;
	color: var(--ink-2);
}

ol.steps b {
	font-weight: 600;
}

.c-blue { color: var(--blue); font-weight: 600; }
.c-green { color: var(--green); font-weight: 600; }
.c-red { color: var(--red); font-weight: 600; }
.c-grey { color: var(--grey); font-weight: 600; }
.c-amber { color: var(--amber); font-weight: 600; }

ol.refs {
	display: grid;
	gap: 0.4rem;
	margin: 0;
	padding-left: 1.6rem;
	font-size: 0.85rem;
	color: var(--ink-2);
}

/* The per step and per sample tables. */

.tablewrap {
	overflow-x: auto;
}

table {
	width: 100%;
	border-collapse: collapse;
	font-size: 0.82rem;
	font-variant-numeric: tabular-nums;
}

th,
td {
	padding: 0.2rem 0.5rem;
	border-bottom: 1px solid var(--rule);
	text-align: right;
	white-space: nowrap;
}

th:first-child,
td:first-child,
th:last-child,
td:last-child {
	text-align: left;
}

th {
	font-weight: 500;
	color: var(--ink-2);
}

td {
	font-family: var(--mono);
}

td:last-child {
	font-family: var(--sans);
}

tbody tr:hover {
	background: var(--bg);
}

tbody tr td:first-child::before {
	content: "";
	display: inline-block;
	width: 0.6rem;
	height: 0.6rem;
	margin-right: 0.45rem;
	border-radius: 50%;
	background: var(--state, transparent);
}

tr.state-green { --state: var(--green); }
tr.state-red { --state: var(--red); }
tr.state-grey { --state: var(--grey); }
tr.state-amber { --state: var(--amber); }
tr.state-faint { --state: color-mix(in srgb, var(--grey) 40%, transparent); }

/* The SSAO result for every pixel. */

.ao-image {
	position: relative;
	cursor: crosshair;
	touch-action: none;
}

.ao-image canvas {
	display: block;
	width: 100%;
	aspect-ratio: 16 / 9;
	image-rendering: pixelated;
	border-radius: 0.25rem;
	outline: 1px solid var(--rule-strong);
}

.ao-image .marker {
	position: absolute;
	outline: 2px solid var(--blue);
	outline-offset: 1px;
	pointer-events: none;
}

/* On a narrow window the panel goes under the 3D view. */

@media (max-width: 900px) {
	.app {
		height: auto;
	}

	.main {
		grid-template-columns: minmax(0, 1fr);
	}

	.viewport {
		height: 70vh;
	}

	.panel {
		overflow: visible;
		border-left: 0;
		border-top: 1px solid var(--rule);
	}

	.control {
		grid-template-columns: minmax(0, 9rem) minmax(0, 1fr) 3.5rem;
	}
}
