:root {
	--design-width: 376;
	--design-height: 300;
	--puzzle-canvas-max-width: 658px;
	--control-width: 8.5rem;
	color-scheme: light dark;
	font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

body {
	margin: 0;
	min-height: 100vh;
	display: grid;
	place-items: start center;
	background: #202020;
	color: #F5F5F5;
}

.app {
	box-sizing: border-box;
	width: min(96vw, 720px);
	padding: 1.5rem;
}

h1 {
	margin: 0;
	font-size: 1.7rem;
}

header p {
	margin: 0.35rem 0 1rem;
	color: #CFCFCF;
}

.panel {
	background: #111;
	border: 1px solid #444;
	border-radius: 14px;
	padding: 1rem;
	box-shadow: 0 12px 30px rgb(0 0 0 / 0.35);
}

.puzzle-canvas-container {
	position: relative;
}

canvas {
	display: block;
	width: min(100%, var(--puzzle-canvas-max-width));
	height: auto;
	margin-inline: auto;
	background: #000;
	border-radius: 8px;
	touch-action: none;
}

.lower-panel {
	display: grid;
	grid-template-columns: var(--control-width) minmax(0, var(--control-width));
	gap: 1rem;
	justify-content: center;
	align-items: start;
	margin-top: 0.8rem;
}

.controls {
	display: flex;
	flex-direction: column;
	align-items: stretch;
	gap: 0.45rem;
}

button,
.checkbox-control,
.settings input,
.settings select {
	box-sizing: border-box;
	border: 1px solid #777;
	border-radius: 8px;
	background: linear-gradient(#FAFAFA, #E7E7E7);
	color: #111;
	font: inherit;
	box-shadow: 0 1px 2px rgb(0 0 0 / 0.25);
}

.checkbox-control input
{
	width: 1rem;
	height: 1rem;
	margin: 0;
	flex: 0 0 auto;
	accent-color: #356FC0;
}

button {
	min-height: 2.15rem;
	padding: 0.35rem 0.65rem;
	font-weight: 600;
	cursor: pointer;
}

button:hover:not(:disabled),
.checkbox-control:hover {
	border-color: #AAA;
	background: linear-gradient(#FFF, #EFEFEF);
}

button:focus-visible,
.settings input:focus-visible,
.settings select:focus-visible,
.about-text:focus-visible,
.checkbox-control:has(input:focus-visible) {
	outline: 3px solid #8AB4F8;
	outline-offset: 2px;
}

/* The ring belongs around the entire checkbox control, not just its square. */
.checkbox-control input:focus-visible {
	outline: none;
}

button:active:not(:disabled) {
	transform: translateY(1px);
	box-shadow: none;
}

.checkbox-control {
	min-height: 2.15rem;
	display: flex;
	align-items: center;
	gap: 0.5rem;
	padding: 0.35rem 0.6rem;
	font-size: 0.9rem;
	font-weight: 600;
	cursor: pointer;
}

.settings .checkbox-control input {
	width: 1rem;
	height: 1rem;
	margin: 0;
	accent-color: #356FC0;
}

button:disabled,
.checkbox-control:has(input:disabled),
.settings input:disabled,
.settings select:disabled
{
	opacity: 0.45;
	cursor: default;
}

.settings
{
	display: flex;
	flex-direction: column;
	height: 100%;
}

.secondary-controls
{
	display: flex;
	flex-direction: column;
	gap: 0.45rem;

	margin-top: auto;
}

.settings label:first-child {
	margin-top: 0;
}

.settings input,
.settings select {
	width: 100%;
	min-width: 0;
	height: 2.15rem;
	padding: 0.3rem 0.5rem;
}

.moves-taken-output
{
	display: block;
	margin-top: 0.2rem;
	font-weight: normal;
	text-align: left;
}

.info {
	margin-top: 0.8rem;
}

.status {
	box-sizing: border-box;
	height: calc(3 * 1.3em + 1rem + 2px);
	display: flex;
	align-items: center;
	margin: 0.35rem 0 0;
	border: 1px solid #555;
	border-radius: 6px;
	padding: 0.5rem 0.65rem;
	color: #D6D6D6;
	line-height: 1.3;
	overflow-wrap: anywhere;
	white-space: pre-line;
}

body.screen-grabbing-mode .status #status
{
	visibility: hidden;
}

.loading-message {
	position: absolute;
	inset: 0;
	display: flex;
	align-items: center;
	justify-content: center;
	font: 1.25rem system-ui;
	color: #808080;
	pointer-events: none;
}

.loading-message[hidden] {
	display: none;
}

.about-overlay {
	position: fixed;
	inset: 0;
	display: grid;
	place-items: center;
	padding: 1rem;
	background: rgb(0 0 0 / 0.55);
}

.about-overlay.hidden {
	display: none;
}

.about-box {
	box-sizing: border-box;
	width: min(90vw, 36rem);
	max-height: min(86vh, 42rem);
	display: flex;
	flex-direction: column;
	gap: 0.8rem;
	border: 1px solid #999;
	border-radius: 12px;
	padding: 1rem;
	background: #E8E8E8;
	color: #111;
	box-shadow: 0 18px 45px rgb(0 0 0 / 0.45);
}

.about-box h2 {
	margin: 0;
	font-size: 1.25rem;
}

.about-text {
	overflow: auto;
	white-space: pre-wrap;
	line-height: 1.35;
	padding: 0.75rem;
	border: 1px solid #AAA;
	border-radius: 6px;
	background: #F8F8F8;
	font-family: inherit;
	font-size: 0.9rem;
}

.about-actions {
	display: flex;
	justify-content: flex-end;
}

@media (max-width: 420px) {
	.app {
		width: 100%;
		padding: 0.75rem;
	}

	.panel {
		padding: 0.75rem;
	}

	.lower-panel {
		grid-template-columns: repeat(2, minmax(0, 1fr));
		gap: 0.75rem;
	}
}

@media (orientation: landscape) and (min-width: 760px) {
	.app {
		width: min(98vw, 1040px);
		padding: 1rem;
	}

	.panel {
		display: grid;
		grid-template-columns: minmax(0, 1fr) calc((2 * var(--control-width)) + 1rem);
		grid-template-areas:
			"puzzle-canvas lower"
			"puzzle-canvas info";
		gap: 1rem;
		align-items: start;
	}

	.puzzle-canvas-container {
		grid-area: puzzle-canvas;
	}

	canvas {
		width: min(
			100%,
			var(--puzzle-canvas-max-width),
			calc((100vh - 9rem) * var(--design-width) / var(--design-height))
		);
	}

	.lower-panel {
		grid-area: lower;
		margin-top: 0;
	}

	.info {
		grid-area: info;
		margin-top: 0;
	}
}
