:root {
	--bg: #161c2b;
	--bar: #1e2638;
	--text: #eef1f7;
	--muted: #9aa3b5;
	--accent: #4f7cff;
	--panel: #f3efe6;
	--ink: #1c2130;
	--line: #d9d3c6;
	color-scheme: dark;
}

* { box-sizing: border-box; }

html, body {
	margin: 0;
	height: 100%;
	background: var(--bg);
	color: var(--text);
	font: 15px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
	overscroll-behavior: none;
	-webkit-tap-highlight-color: transparent;
}

body {
	display: flex;
	flex-direction: column;
	height: 100dvh;
	padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
}

.bar {
	display: flex;
	align-items: center;
	justify-content: space-between;
	gap: 12px;
	padding: 8px 16px;
	background: var(--bar);
	border-bottom: 1px solid #2a3449;
}

.bar h1 {
	margin: 0;
	font-size: 17px;
	font-weight: 650;
	letter-spacing: 0.01em;
}

.menu-wrap { position: relative; }

.menu-btn {
	display: inline-flex;
	align-items: center;
	gap: 6px;
	min-height: 40px;
	padding: 0 14px;
	border: 1px solid #36425c;
	border-radius: 10px;
	background: #273149;
	color: var(--text);
	font: inherit;
	font-weight: 550;
	cursor: pointer;
}
.menu-btn:hover:not(:disabled) { background: #2e3a56; }
.menu-btn:disabled { opacity: 0.45; cursor: default; }

.menu {
	position: absolute;
	right: 0;
	top: calc(100% + 6px);
	z-index: 10;
	min-width: 210px;
	padding: 4px;
	border: 1px solid #36425c;
	border-radius: 12px;
	background: #222b40;
	box-shadow: 0 12px 32px rgba(0, 0, 0, 0.45);
}

.menu-group + .menu-group {
	margin-top: 4px;
	padding-top: 4px;
	border-top: 1px solid #36425c;
}

.menu button {
	display: flex;
	justify-content: space-between;
	width: 100%;
	min-height: 40px;
	padding: 8px 12px;
	border: 0;
	border-radius: 8px;
	background: none;
	color: var(--text);
	font: inherit;
	text-align: left;
	cursor: pointer;
}
.menu button:hover, .menu button:focus-visible { background: #2f3b58; outline: none; }
.menu .state { color: var(--muted); }

.stage {
	position: relative;
	flex: 1;
	min-height: 0;
	min-width: 0;
	overflow: hidden;
	display: flex;
	align-items: center;
	justify-content: center;
	padding: 16px;
}

canvas {
	position: absolute;
	top: 50%;
	left: 50%;
	transform: translate(-50%, -50%);
	display: block;
	border-radius: 14px;
	box-shadow: 0 10px 40px rgba(0, 0, 0, 0.45);
	touch-action: none;
	user-select: none;
	-webkit-user-select: none;
	cursor: pointer;
}

/* Dialogs (MsgBox / High Scores / About / Tips) */
.dlg {
	width: min(340px, calc(100vw - 32px));
	padding: 18px 18px 14px;
	border: 0;
	border-radius: 14px;
	background: var(--panel);
	color: var(--ink);
	box-shadow: 0 20px 60px rgba(0, 0, 0, 0.5);
}
.dlg::backdrop { background: rgba(8, 11, 20, 0.55); }

.dlg-title {
	margin: 0 0 10px;
	font-size: 17px;
	font-weight: 700;
}

.dlg-body p { margin: 0 0 8px; }
.dlg-body .muted { color: #6b7180; font-size: 13px; }

.dlg-body input {
	width: 100%;
	margin: 2px 0 6px;
	padding: 9px 10px;
	border: 1px solid #bfb8a8;
	border-radius: 8px;
	background: #fff;
	color: var(--ink);
	font: inherit;
}
.dlg-body input:focus { outline: 2px solid var(--accent); outline-offset: 1px; }

.tips { margin: 0; padding-left: 18px; }
.tips li { margin-bottom: 6px; }

.scores { width: 100%; border-collapse: collapse; font-variant-numeric: tabular-nums; }
.scores td { padding: 5px 4px; border-bottom: 1px solid var(--line); }
.scores tr:last-child td { border-bottom: 0; }
.scores .rank { width: 2em; color: #6b7180; }
.scores .name { overflow-wrap: anywhere; }
.scores .pts { text-align: right; font-family: ui-monospace, "Cascadia Mono", Consolas, monospace; }
.scores .hl td { background: #ffe9a8; font-weight: 650; }

.dlg-buttons {
	display: flex;
	justify-content: flex-end;
	gap: 8px;
	margin-top: 14px;
}
.dlg-buttons button {
	min-width: 84px;
	min-height: 40px;
	padding: 0 14px;
	border: 1px solid #bfb8a8;
	border-radius: 9px;
	background: #fff;
	color: var(--ink);
	font: inherit;
	font-weight: 600;
	cursor: pointer;
}
.dlg-buttons button.primary { background: #2f4fb8; border-color: #2f4fb8; color: #fff; }
.dlg-buttons button:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
