:root {
  --ink: #0b0d1c;
  --panel: #14172e;
  --rule: #2a2e52;
  --paper: #fff;
  --smoke: #a9adc8;
  --cyan: #00d8ef;
  --magenta: #ed27c2;
  --gold: #ffd438;
  --display: ui-rounded, "SF Pro Rounded", "Arial Rounded MT Bold", "Nunito", "Varela Round", system-ui, sans-serif;
  --body: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; background: var(--ink); color: var(--paper); }
body { font-family: var(--body); font-size: 15px; line-height: 1.45; -webkit-font-smoothing: antialiased; }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); }

.top { display: flex; align-items: baseline; justify-content: space-between; gap: 16px; height: 48px; padding: 10px 16px 0; max-width: 860px; margin: 0 auto; }
.top h1 { margin: 0; font: 700 20px/1 var(--display); letter-spacing: .02em; }
.top a { color: var(--cyan); text-decoration: none; font-weight: 600; }
.top a:hover { text-decoration: underline; }

.layout { display: flex; flex-wrap: wrap; justify-content: center; align-items: flex-start; gap: 24px; padding: 0 0 32px; }

/* The playfield is 390 x 640 and scales to whatever fits */
.stage {
  position: relative;
  width: min(100vw, calc((100dvh - 56px) * 390 / 640), 468px);
  aspect-ratio: 390 / 640;
  container-type: inline-size;
  overflow: hidden;
  background: #11152f;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
  -webkit-tap-highlight-color: transparent;
}
@media (min-width: 480px) { .stage { border-radius: 14px; } }
canvas { display: block; width: 100%; height: 100%; }

.hud { position: absolute; inset: 0; pointer-events: none; font-family: var(--display); font-weight: 800; text-shadow: 0 2px 0 rgba(0, 0, 0, .55); }
.score { position: absolute; top: 3cqw; left: 0; right: 0; text-align: center; font-size: 15cqw; line-height: 1; }
.coins { position: absolute; top: 4.5cqw; left: 4cqw; display: flex; align-items: center; gap: 1.5cqw; font-size: 5.5cqw; color: var(--gold); }
.coin-dot { width: 4.5cqw; height: 4.5cqw; border-radius: 50%; background: var(--gold); box-shadow: inset 0 0 0 .7cqw #c99a00; }

.controls { position: absolute; z-index: 1; top: 3cqw; right: 3cqw; display: flex; gap: 2cqw; }
.controls button { width: 11cqw; height: 11cqw; min-width: 40px; min-height: 40px; padding: 0; border: 0; border-radius: 50%; background: rgba(11, 13, 28, .7); color: var(--paper); cursor: pointer; }
.controls svg { width: 55%; height: 55%; fill: currentColor; vertical-align: middle; }

.overlay { position: absolute; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: flex-end; gap: 12px; padding: 0 7cqw 12cqw; text-align: center; }
.overlay.shade { justify-content: center; padding-bottom: 0; background: rgba(11, 13, 28, .82); }
.overlay h2 { margin: 0; font: 800 9cqw/1.1 var(--display); }
.overlay p { margin: 0; }
.hint { font-weight: 600; text-shadow: 0 1px 6px #000, 0 0 2px #000; }
#over-cause { color: var(--smoke); }
.result { display: flex; gap: 28px; font-family: var(--display); color: var(--smoke); }
.result b { display: block; font-size: 10cqw; line-height: 1; color: var(--paper); }
.pose { background-repeat: no-repeat; animation: bob 1.4s ease-in-out infinite alternate; }
@keyframes bob { from { transform: translateY(-4px); } to { transform: translateY(4px); } }
@media (prefers-reduced-motion: reduce) { .pose { animation: none; } }

button { font: inherit; }
button.main, #save-btn, #reload { border: 0; border-radius: 999px; padding: 12px 28px; font: 700 17px/1 var(--display); background: var(--cyan); color: #06222a; cursor: pointer; }
#save-btn { padding: 12px 16px; font-size: 15px; background: var(--gold); color: #2a2100; white-space: nowrap; }
button:focus-visible, input:focus-visible, a:focus-visible { outline: 3px solid var(--magenta); outline-offset: 2px; }
button:disabled { opacity: .5; cursor: default; }

#save { width: 100%; max-width: 320px; text-align: left; }
#save label { display: block; margin-bottom: 6px; font-size: 13px; color: var(--smoke); }
.row { display: flex; gap: 8px; }
#name { flex: 1; min-width: 0; padding: 10px 12px; border: 1px solid var(--rule); border-radius: 10px; background: var(--panel); color: var(--paper); font: 600 16px var(--body); }
#save-msg { min-height: 1.45em; font-size: 14px; color: var(--gold); }

.side { width: min(100vw, 320px); padding: 0 16px; }
.side section { margin-bottom: 24px; }
.side h2 { margin: 0 0 10px; font: 700 13px/1 var(--display); letter-spacing: .12em; text-transform: uppercase; color: var(--cyan); }
#board { margin: 0; padding: 0; list-style: none; counter-reset: rank; }
#board li { counter-increment: rank; display: flex; gap: 10px; padding: 7px 0; border-bottom: 1px solid var(--rule); font-variant-numeric: tabular-nums; }
#board li::before { content: counter(rank); width: 1.5em; color: var(--smoke); }
#board li span:first-child { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
#board li.me { color: var(--gold); font-weight: 700; }
#board-msg { margin: 8px 0 0; font-size: 14px; color: var(--smoke); }
.how { margin: 0; padding-left: 18px; color: var(--smoke); }
.how li { margin-bottom: 6px; }
.how b { color: var(--paper); }
