:root {
	color-scheme: dark;
	--bg: #121212;
	--bar: #161616;
	--line: #2a2a2a;
	--text: #e8e4dc;
	--muted: #9a9488;
	--btn: #242424;
	--btn-hover: #2e2e2e;
	--focus: #d8d0c4;
	--paper: #ece8e1;
	--danger: #c45c4a;
	--workspace: var(--paper);
	--safe-top: env(safe-area-inset-top, 0px);
	--safe-right: env(safe-area-inset-right, 0px);
	--safe-bottom: env(safe-area-inset-bottom, 0px);
	--safe-left: env(safe-area-inset-left, 0px);
}

*,
*::before,
*::after {
	box-sizing: border-box;
}

html,
body {
	margin: 0;
	height: 100%;
	max-width: 100%;
	overflow: hidden;
	overscroll-behavior: none;
	background: var(--bg);
	color: var(--text);
	font-family: ui-sans-serif, system-ui, -apple-system, "Segoe UI", sans-serif;
	font-size: 16px;
}

body {
	min-height: 100dvh;
	overflow: hidden;
}

.app {
	display: flex;
	flex-direction: column;
	height: 100vh;
	height: 100dvh;
	overflow: hidden;
	max-width: 100%;
}

.toolbar {
	display: flex;
	flex-wrap: wrap;
	align-items: center;
	gap: 6px 8px;
	padding: calc(6px + var(--safe-top)) calc(10px + var(--safe-right)) 6px calc(10px + var(--safe-left));
	background: var(--bar);
	border-bottom: 1px solid var(--line);
	user-select: none;
	-webkit-user-select: none;
	touch-action: manipulation;
	position: relative;
	z-index: 2;
	max-width: 100%;
}

.tool-panel {
	display: contents;
}

.tool-legal {
	display: none;
}

.top-row {
	display: flex;
	align-items: center;
	gap: 10px;
	width: auto;
	margin-right: 8px;
}

.brand {
	margin: 0;
	font-size: 0.95rem;
	font-weight: 600;
	letter-spacing: 0.02em;
	padding-right: 4px;
	margin-right: auto;
}

.btn-about {
	display: inline-flex;
	align-items: center;
	min-height: 40px;
	padding: 0 12px;
	background: var(--btn);
	color: var(--muted);
	border: 1px solid var(--line);
	border-radius: 8px;
	text-decoration: none;
	font-size: 0.82rem;
}

.btn-about:hover {
	background: var(--btn-hover);
	color: var(--text);
}

.group {
	display: flex;
	align-items: center;
	gap: 6px;
}

.group-color,
.group-size,
.group-actions {
	padding-left: 10px;
	border-left: 1px solid var(--line);
}

.group-actions {
	margin-left: auto;
	flex-wrap: wrap;
}

label.field {
	display: flex;
	align-items: center;
	gap: 8px;
	color: var(--muted);
	font-size: 0.8rem;
}

select,
button,
input[type="range"] {
	min-height: 40px;
	font: inherit;
}

select,
button {
	background: var(--btn);
	color: var(--text);
	border: 1px solid var(--line);
	border-radius: 8px;
	padding: 0 12px;
}

select {
	min-width: 7.5rem;
}

button {
	cursor: pointer;
	min-width: 40px;
}

button:hover,
select:hover {
	background: var(--btn-hover);
}

button:disabled {
	opacity: 0.4;
	cursor: default;
}

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

button.danger:hover {
	border-color: var(--danger);
}

button.is-active {
	background: var(--text);
	color: var(--bg);
	border-color: var(--text);
}

.swatch {
	position: relative;
	width: 40px;
	height: 40px;
	border-radius: 8px;
	border: 1px solid rgba(255, 255, 255, 0.18);
	overflow: hidden;
	background: var(--btn);
	box-shadow: inset 0 0 0 1px rgba(0, 0, 0, 0.25);
}

.swatch input {
	position: absolute;
	inset: 0;
	width: 100%;
	height: 100%;
	padding: 0;
	border: 0;
	cursor: pointer;
	background: none;
}

.swatch input::-webkit-color-swatch-wrapper {
	padding: 0;
}

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

.size {
	min-width: 120px;
	flex: 1 1 120px;
	max-width: 200px;
	accent-color: var(--text);
}

.size-value {
	min-width: 2rem;
	color: var(--text);
	font-variant-numeric: tabular-nums;
}

.stage {
	flex: 1;
	min-height: 0;
	position: relative;
	overflow: hidden;
	padding: 0 var(--safe-right) var(--safe-bottom) var(--safe-left);
	background: var(--workspace);
	touch-action: none;
}

canvas {
	display: block;
	touch-action: none;
	cursor: crosshair;
	background: var(--paper);
}

canvas.is-erasing {
	cursor: cell;
}

dialog {
	border: 1px solid var(--line);
	border-radius: 16px;
	background: #1a1a1a;
	color: var(--text);
	padding: 0;
	width: min(28rem, calc(100vw - 2rem));
}

dialog::backdrop {
	background: rgb(0 0 0 / 0.55);
}

.sheet {
	padding: 20px;
}

.sheet h2 {
	margin: 0 0 12px;
	font-size: 1.1rem;
}

.sheet p,
.sheet a {
	color: var(--muted);
}

.sheet a {
	color: var(--text);
}

.sheet menu {
	display: flex;
	justify-content: flex-end;
	gap: 8px;
	margin: 18px 0 0;
	padding: 0;
}

.sheet nav {
	display: grid;
	gap: 8px;
	margin: 12px 0 18px;
}

.sheet nav a {
	display: block;
	padding: 12px 14px;
	border: 1px solid var(--line);
	border-radius: 10px;
	text-decoration: none;
	background: var(--btn);
	color: var(--text);
}

html.compact-ui .toolbar {
	flex-wrap: nowrap;
	flex-direction: column;
	align-items: stretch;
	gap: 0;
	padding: calc(4px + var(--safe-top)) calc(8px + var(--safe-right)) 4px calc(8px + var(--safe-left));
}

html.compact-ui .top-row {
	width: 100%;
	min-height: 44px;
	margin-right: 0;
}

html.compact-ui .brand {
	font-size: 0.95rem;
	padding-right: 0;
}

html.compact-ui .btn-about {
	min-height: 44px;
}

html.compact-ui select,
html.compact-ui button,
html.compact-ui input[type="range"] {
	min-height: 44px;
}

html.compact-ui button {
	min-width: 44px;
}

html.compact-ui .swatch {
	width: 44px;
	height: 44px;
}

html.compact-ui .tool-panel {
	display: none;
	position: absolute;
	top: 100%;
	left: 0;
	right: 0;
	z-index: 3;
	flex-wrap: wrap;
	align-items: center;
	gap: 8px;
	padding: 10px calc(8px + var(--safe-right)) 12px calc(8px + var(--safe-left));
	background: var(--bar);
	border-bottom: 1px solid var(--line);
	max-height: min(70dvh, 28rem);
	overflow-x: hidden;
	overflow-y: auto;
	-webkit-overflow-scrolling: touch;
}

html.compact-ui.tools-open .tool-panel {
	display: flex;
}

html.compact-ui .group {
	flex-wrap: wrap;
	min-width: 0;
	padding-left: 0;
	border-left: 0;
}

html.compact-ui .group-mode,
html.compact-ui .group-color,
html.compact-ui .group-size,
html.compact-ui .group-actions {
	width: 100%;
	margin-left: 0;
}

html.compact-ui .group-mode select {
	flex: 1;
	min-width: 0;
}

html.compact-ui #eraser {
	flex: 0 0 auto;
}

html.compact-ui .group-size .size {
	flex: 1 1 0;
	min-width: 0;
	max-width: none;
}

html.compact-ui .group-actions {
	display: grid;
	grid-template-columns: repeat(3, minmax(0, 1fr));
	gap: 8px;
}

html.compact-ui .group-actions button {
	width: 100%;
	min-width: 0;
	padding: 0 6px;
	font-size: 0.82rem;
}

html.compact-ui .tool-legal {
	display: flex;
	flex-wrap: wrap;
	gap: 8px 14px;
	width: 100%;
	padding-top: 4px;
}

html.compact-ui .tool-legal a {
	color: var(--muted);
	font-size: 0.85rem;
	min-height: 44px;
	display: inline-flex;
	align-items: center;
}

html.compact-ui .stage {
	padding: 0 var(--safe-right) var(--safe-bottom) var(--safe-left);
}

.update-banner {
	position: fixed;
	bottom: calc(12px + var(--safe-bottom));
	left: 50%;
	transform: translateX(-50%);
	z-index: 100;
	display: flex;
	align-items: center;
	gap: 10px;
	padding: 8px 14px;
	background: var(--bar);
	border: 1px solid var(--line);
	border-radius: 10px;
	color: var(--text);
	font-size: 0.85rem;
	box-shadow: 0 4px 16px rgba(0, 0, 0, 0.5);
	white-space: nowrap;
}

.update-banner[hidden] {
	display: none;
}

.update-banner button {
	min-height: 32px;
	min-width: auto;
	padding: 0 10px;
	font-size: 0.8rem;
	border-radius: 6px;
}
