:root {
  --bg: #0b0b2e;
  --panel: #1b1330;
  --panel-2: #241a4a;
  --line: #000;
  --text: #fff;
  --muted: #9a9acb;
  --gold: #ffd23f;
  --red: #e31937;
  --red-dark: #9b0f24;
  --red-light: #ff6b7f;
  --green: #7cfc7c;
  --font: 'Press Start 2P', monospace;
}

html, body {
  margin: 0; height: 100%; background: var(--bg); overflow: hidden;
  display: grid; place-items: center;
  touch-action: none; -webkit-user-select: none; user-select: none; -webkit-tap-highlight-color: transparent;
  font-family: var(--font); color: var(--text);
}
[hidden] { display: none !important; }
#stage { position: relative; }
canvas { display: block; width: 100%; height: 100%; image-rendering: pixelated; image-rendering: crisp-edges; cursor: pointer; }

/* ---------- pixel controls ---------- */
.px-btn {
  font: 11px/1 var(--font); color: var(--text); letter-spacing: 0;
  background: var(--red); border: 2px solid var(--line); border-radius: 0;
  padding: 9px 12px; min-height: 36px; cursor: pointer;
  box-shadow: inset -2px -2px 0 var(--red-dark), inset 2px 2px 0 var(--red-light);
  transition: transform .1s ease, filter .1s ease;
}
.px-btn:hover { filter: brightness(1.12); }
.px-btn:active { transform: scale(.96); }
.px-btn:focus-visible { outline: 2px solid var(--gold); outline-offset: 2px; }
.px-btn.small { font-size: 11px; padding: 6px 8px; min-height: 30px; }
.px-btn.ghost { background: var(--panel-2); box-shadow: inset -2px -2px 0 #120d24, inset 2px 2px 0 #3a2a6b; color: var(--muted); }
.px-btn.wide { width: 100%; }
.px-btn[disabled] { opacity: .6; cursor: default; }

.px-panel { background: rgba(27, 19, 48, .88); border: 2px solid var(--line); box-shadow: inset 0 0 0 2px var(--panel-2); }

/* ---------- top bar ---------- */
#ca {
  position: absolute; top: 10px; left: 10px;
  display: flex; align-items: center; gap: 8px; padding: 4px 4px 4px 10px; min-height: 36px; box-sizing: border-box;
  max-width: calc(100% - 214px); cursor: pointer;
}
#ca:hover { box-shadow: inset 0 0 0 2px var(--gold); }
#ca.empty { cursor: default; }
#ca.empty:hover { box-shadow: inset 0 0 0 2px var(--panel-2); }
.ca-label { font-size: 11px; color: var(--gold); }
#ca-value {
  font: 11px/1 var(--font); color: var(--text); background: none; border: 0; padding: 6px 0; cursor: pointer;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis; min-width: 0;
}
#ca.empty #ca-value { color: var(--muted); cursor: default; }
#top-right { position: absolute; top: 10px; right: 10px; display: flex; gap: 8px; }
.px-btn.icon { display: grid; place-items: center; width: 36px; padding: 0; text-decoration: none; background: #000; box-shadow: inset -2px -2px 0 #1b1330, inset 2px 2px 0 #3b3b46; }
#skip { position: absolute; bottom: 10px; right: 10px; }

#run-note {
  position: absolute; left: 50%; top: var(--note-top, 60%); transform: translateX(-50%);
  display: flex; justify-content: center; white-space: nowrap;
}
#run-saved { font-size: 11px; color: var(--green); text-shadow: 1px 1px 0 #000, -1px -1px 0 #000, 1px -1px 0 #000, -1px 1px 0 #000; }

/* ---------- leaderboard popup ---------- */
#board {
  width: min(380px, calc(100vw - 32px)); max-height: calc(100dvh - 32px); box-sizing: border-box;
  padding: 16px; margin: auto; color: var(--text); font-family: var(--font);
  background: var(--panel); border: 3px solid var(--line); border-radius: 0;
  box-shadow: inset 0 0 0 3px var(--panel-2), 0 12px 0 rgba(0, 0, 0, .35);
  overflow: auto; overscroll-behavior: contain; user-select: text;
}
#board::backdrop { background: rgba(5, 4, 20, .7); }
#board[open] { animation: pop .16s ease-out; }
@keyframes pop { from { transform: scale(.96); opacity: 0; } to { transform: none; opacity: 1; } }
@media (prefers-reduced-motion: reduce) { #board[open] { animation: none; } }

.board-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
#board h1 { margin: 0; font-size: 14px; color: var(--gold); text-shadow: 2px 2px 0 #000; }
.board-sub { margin: 8px 0 14px; font-family: system-ui, -apple-system, sans-serif; font-size: 13px; color: var(--muted); line-height: 1.5; }

#board-list { list-style: none; margin: 0; padding: 0; }
#board-list li {
  display: grid; grid-template-columns: 34px 1fr auto; align-items: center; gap: 8px;
  min-height: 32px; padding: 0 8px; font-size: 11px; font-variant-numeric: tabular-nums;
}
#board-list li:nth-child(odd) { background: var(--panel-2); }
#board-list li.me { outline: 2px solid var(--gold); outline-offset: -2px; }
#board-list .rank { color: var(--muted); }
#board-list li:nth-child(1) .rank { color: var(--gold); }
#board-list .name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
#board-list .score { color: var(--text); }
#board-empty { font-size: 11px; color: var(--muted); text-align: center; padding: 18px 0; margin: 0; }

#acct { margin-top: 16px; padding-top: 14px; border-top: 2px solid var(--panel-2); }
.acct-copy { font-family: system-ui, -apple-system, sans-serif; font-size: 13px; line-height: 1.5; color: var(--muted); margin: 0 0 12px; }
.acct-copy.hl { color: var(--gold); }
#name-form label { display: block; font-size: 11px; color: var(--gold); margin-bottom: 8px; }
.name-row { display: flex; gap: 8px; }
#name-input {
  flex: 1; min-width: 0; font: 12px var(--font); color: var(--text); text-transform: uppercase;
  background: #0b0b2e; border: 2px solid var(--line); box-shadow: inset 0 0 0 2px var(--panel-2);
  padding: 0 10px; min-height: 36px; border-radius: 0;
}
#name-input:focus { outline: 2px solid var(--gold); outline-offset: 0; }
#name-form small { display: block; margin-top: 8px; font-family: system-ui, -apple-system, sans-serif; font-size: 13px; color: var(--muted); }
.me-row { display: flex; justify-content: space-between; font-size: 11px; padding: 6px 0; }
.me-row span { color: var(--muted); }
.me-actions { display: flex; gap: 8px; margin-top: 10px; }
#acct-status { min-height: 1em; margin: 10px 0 0; font-family: system-ui, -apple-system, sans-serif; font-size: 13px; color: var(--red-light); }
#acct-status.ok { color: var(--green); }

@media (max-width: 480px) {
  #ca { max-width: calc(100% - 214px); padding-right: 10px; }
  #ca-copy { display: none; }   /* the whole box copies */
  #board-btn { padding: 9px 8px; }
}
