:root {
	--bg: #f6f3ea;
	--card: #fffdf7;
	--ink: #1f2a1f;
	--muted: #6b7366;
	--line: #e2ddcc;
	--accent: #c0392b;
	--accent-ink: #fff;
	--me: #fff1c9;
	color-scheme: light;
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
body {
	margin: 0;
	background: var(--bg);
	color: var(--ink);
	font: 16px/1.45 system-ui, -apple-system, "Segoe UI", sans-serif;
}
header, main, footer { max-width: 760px; margin: 0 auto; padding: 0 16px; }
header {
	display: flex; flex-wrap: wrap; gap: 8px 24px;
	align-items: flex-end; justify-content: space-between;
	padding-top: 20px; padding-bottom: 12px;
}
h1 { margin: 0; font-size: 26px; letter-spacing: -0.5px; }
h1 span { display: block; font-size: 14px; font-weight: 400; color: var(--muted); letter-spacing: 0; }
h2 { font-size: 22px; margin: 8px 0 12px; }
h3 { font-size: 16px; margin: 20px 0 6px; }
.name { font-size: 13px; color: var(--muted); display: flex; flex-direction: column; gap: 2px; }
.name input {
	font: inherit; font-size: 16px; color: var(--ink);
	padding: 6px 10px; border: 1px solid var(--line); border-radius: 8px;
	background: var(--card); width: 200px;
}
section { background: var(--card); border: 1px solid var(--line); border-radius: 12px; padding: 16px; margin-bottom: 16px; }
.small { font-size: 14px; color: var(--muted); }
.error { color: var(--accent); }
.button {
	display: inline-block; font: inherit; font-weight: 600; cursor: pointer;
	background: var(--accent); color: var(--accent-ink);
	border: 0; border-radius: 8px; padding: 9px 16px;
}
.button.secondary { background: transparent; color: var(--ink); border: 1px solid var(--line); }
.link { font: inherit; background: none; border: 0; padding: 0; color: var(--accent); cursor: pointer; text-decoration: underline; }
kbd { font: 12px ui-monospace, monospace; border: 1px solid currentColor; border-radius: 4px; padding: 0 4px; opacity: 0.8; }
.actions { display: flex; gap: 8px; flex-wrap: wrap; }

/* Level list */
#levels { padding: 0; overflow: hidden; }
.levelhead, #levellist li {
	display: grid; grid-template-columns: 2.2rem 1fr 5.5rem 9rem; gap: 8px;
	padding: 8px 16px; align-items: baseline;
}
.levelhead { font-size: 13px; color: var(--muted); border-bottom: 1px solid var(--line); }
#levellist { list-style: none; margin: 0; padding: 0; }
#levellist li { border-bottom: 1px solid var(--line); cursor: pointer; }
#levellist li:last-child { border-bottom: 0; }
#levellist li:hover { background: var(--bg); }
#levellist li span:first-child { color: var(--muted); }
#levellist small { color: var(--muted); }
@media (max-width: 520px) {
	.levelhead, #levellist li { grid-template-columns: 2rem 1fr 6.5rem; }
	.levelhead span:nth-child(3), #levellist li span:nth-child(3) { display: none; }
}

/* Top 20 */
#toptable { width: 100%; border-collapse: collapse; }
#toptable td { padding: 6px 4px; border-bottom: 1px solid var(--line); }
#toptable td:first-child { color: var(--muted); width: 2em; }
#toptable td:nth-child(3) { font-variant-numeric: tabular-nums; }
#toptable td:last-child { text-align: right; }
#toptable tr.me { background: var(--me); }

/* Game */
#stage {
	position: fixed; inset: 0; background: #000;
	display: flex; align-items: center; justify-content: center;
}
#stage[hidden] { display: none; }
#canvas {
	width: min(100vw, calc(100vh * 4 / 3));
	width: min(100vw, calc(100dvh * 4 / 3)); height: auto; aspect-ratio: 4 / 3;
	image-rendering: pixelated; outline: none;
}
#result {
	position: absolute; left: 50%; bottom: 8%; transform: translateX(-50%);
	background: rgba(255, 253, 247, 0.95); color: var(--ink);
	border-radius: 12px; padding: 12px 24px; text-align: center; min-width: 280px;
}
#result p { margin: 4px 0; }
#resulttime { font-size: 32px; font-weight: 700; font-variant-numeric: tabular-nums; }
#resultnote { font-weight: 600; color: var(--accent); }
.resultbuttons { display: flex; gap: 8px; justify-content: center; flex-wrap: wrap; margin-top: 10px !important; }
@media (pointer: coarse) { kbd { display: none; } }

/* On-screen buttons (touch screens) */
#stage { touch-action: none; user-select: none; -webkit-user-select: none; }
#touch button {
	position: absolute; width: 76px; height: 76px; border-radius: 50%;
	border: 2px solid rgba(255, 255, 255, 0.55); background: rgba(255, 255, 255, 0.18);
	color: #fff; font: 700 30px/1 system-ui, sans-serif; touch-action: none;
	-webkit-tap-highlight-color: transparent; -webkit-touch-callout: none;
	text-shadow: 0 1px 2px rgba(0, 0, 0, 0.6);
}
#touch button.down { background: rgba(255, 255, 255, 0.45); }
#touch .t-left  { left: max(16px, env(safe-area-inset-left)); bottom: 20px; }
#touch .t-right { left: calc(max(16px, env(safe-area-inset-left)) + 92px); bottom: 20px; }
#touch .t-gas   { right: max(16px, env(safe-area-inset-right)); bottom: 106px; width: 88px; height: 88px; }
#touch .t-brake { right: max(16px, env(safe-area-inset-right)); bottom: 12px; }
#touch .t-turn  { right: calc(max(16px, env(safe-area-inset-right)) + 104px); bottom: 20px; }
#touch .t-esc   { left: max(12px, env(safe-area-inset-left)); top: 12px; width: 48px; height: 48px; font-size: 20px; }
#rotate {
	position: absolute; inset: 0; display: flex; align-items: center; justify-content: center;
	background: rgba(0, 0, 0, 0.82); color: #fff; font-size: 20px; text-align: center; padding: 24px;
}

footer { font-size: 12px; color: var(--muted); padding-bottom: 24px; }
footer a { color: inherit; }
a { color: var(--accent); }
footer summary { cursor: pointer; width: fit-content; }
