:root {
  --bg: #0f1419;
  --panel: #1a2028;
  --border: #2a323d;
  --text: #e6edf3;
  --muted: #8b949e;
  --accent: #3fb950;
  --accent-2: #2ea043;
  --food: #f85149;
  --gold: #e3b341;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--text);
  font-family: system-ui, -apple-system, "Segoe UI", sans-serif;
  display: flex;
  justify-content: center;
  padding: 24px 16px;
}

main {
  display: flex;
  gap: 24px;
  align-items: flex-start;
  flex-wrap: wrap;
  justify-content: center;
  width: 100%;
  max-width: 760px;
}

.game { width: 100%; max-width: 420px; }

header {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  margin-bottom: 12px;
}

h1 { margin: 0; font-size: 28px; letter-spacing: 1px; color: var(--accent); }
h2 { margin: 0 0 12px; font-size: 18px; }

.stats { display: flex; gap: 16px; color: var(--muted); font-size: 14px; }
.stats strong { color: var(--text); font-size: 18px; margin-left: 4px; }

.board-wrap {
  position: relative;
  aspect-ratio: 1;
  border: 2px solid var(--border);
  border-radius: 8px;
  overflow: hidden;
  background: var(--panel);
}

canvas { display: block; width: 100%; height: 100%; touch-action: none; }

.overlay {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  text-align: center;
  background: rgba(15, 20, 25, 0.85);
  padding: 20px;
}
.overlay[hidden] { display: none; }
.overlay p { margin: 0 0 14px; color: var(--muted); line-height: 1.5; }
.overlay .big { font-size: 30px; font-weight: 700; color: var(--text); }
.overlay strong { color: var(--accent); font-size: 20px; }

button {
  font: inherit;
  font-weight: 600;
  border: 0;
  border-radius: 6px;
  padding: 10px 18px;
  background: var(--accent-2);
  color: #fff;
  cursor: pointer;
}
button:hover { background: var(--accent); }
button:disabled { opacity: 0.5; cursor: default; }
button.secondary { background: transparent; border: 1px solid var(--border); color: var(--text); }
button.secondary:hover { border-color: var(--muted); }

form { display: flex; gap: 8px; justify-content: center; margin-bottom: 8px; }
input {
  font: inherit;
  padding: 10px 12px;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
  width: 160px;
}
input:focus { outline: 2px solid var(--accent); border-color: transparent; }

.msg { min-height: 1.5em; font-size: 14px; }
.msg.ok { color: var(--accent) !important; }
.msg.err { color: var(--food) !important; }

.dpad {
  display: none;
  grid-template-columns: repeat(3, 56px);
  grid-template-areas: ". up ." "left down right";
  gap: 8px;
  justify-content: center;
  margin-top: 16px;
}
.dpad button { height: 56px; padding: 0; background: var(--panel); border: 1px solid var(--border); font-size: 20px; }
.dpad [data-dir="up"] { grid-area: up; }
.dpad [data-dir="left"] { grid-area: left; }
.dpad [data-dir="down"] { grid-area: down; }
.dpad [data-dir="right"] { grid-area: right; }
@media (pointer: coarse) { .dpad { display: grid; } }

.leaderboard {
  flex: 1;
  min-width: 240px;
  max-width: 420px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 16px;
}

ol { list-style: none; margin: 0; padding: 0; counter-reset: rank; }
ol li {
  counter-increment: rank;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 4px;
  border-bottom: 1px solid var(--border);
}
ol li:last-child { border-bottom: 0; }
ol li::before { content: counter(rank); width: 22px; color: var(--muted); font-weight: 700; text-align: right; }
ol li:nth-child(1)::before { color: var(--gold); }
ol li .name { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
ol li .pts { font-weight: 700; font-variant-numeric: tabular-nums; }
ol li.me { background: rgba(63, 185, 80, 0.12); border-radius: 4px; }
ol li.empty { color: var(--muted); justify-content: center; }
ol li.empty::before { content: none; }
