:root {
  --bg: #07060D; --panel: #13111F; --line: #2A2540; --text: #EDEBF5; --muted: #A6A1BD;
  --gold: #FFD23F; --gold-d: #B88A00; --lead: #B98CFF; --lead-d: #6A3FC0; --green: #14F195; --green-d: #0A8F5A; --purple: #B98CFF; --red: #FF8A8A;
  --pixel: "Press Start 2P", monospace; --mono: "Space Mono", ui-monospace, monospace;
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--text); font-family: var(--mono); -webkit-tap-highlight-color: transparent; }
body { display: flex; justify-content: center; overscroll-behavior: none; }
#app { width: 100%; max-width: 440px; min-height: 100dvh; position: relative; }
button, input { font: inherit; color: inherit; }
button { cursor: pointer; }
button:focus-visible, input:focus-visible { outline: 2px solid var(--green); outline-offset: 2px; }

.screen { display: none; flex-direction: column; gap: 16px; padding: max(16px, env(safe-area-inset-top)) 18px max(16px, env(safe-area-inset-bottom)); min-height: 100dvh; }
.screen.active { display: flex; }

.row { display: flex; align-items: center; }
.col { display: flex; flex-direction: column; }
.between { justify-content: space-between; }
.gap { gap: 10px; } .gap-s { gap: 8px; } .gap > * { flex: 1; }
.center { text-align: center; align-items: center; }
.pad-top { padding-top: 28px; }
.muted { color: var(--muted); } .small { font-size: 12px; } .tiny { font-size: 11px; line-height: 1.5; margin: 0; }
.accent { color: var(--lead); } .green { color: var(--green); } .red { color: var(--red); }
.label { font-size: 12px; color: var(--muted); text-transform: uppercase; letter-spacing: 1px; margin: 0; font-weight: 400; }

.topbar { display: flex; justify-content: space-between; align-items: center; }
.tag { font-family: var(--pixel); font-size: 9px; color: var(--muted); }
.chip { display: flex; align-items: center; gap: 8px; border: 1px solid var(--line); background: none; border-radius: 999px; padding: 0 14px; min-height: 44px; font-size: 13px; }
.dot { width: 8px; height: 8px; border-radius: 50%; background: var(--muted); }
.dot.on { background: var(--green); }

.hero { display: flex; flex-direction: column; align-items: center; gap: 20px; padding-top: 18px; }
.hero-coins { width: 270px; height: 84px; }
.logo { margin: 0; font-family: var(--pixel); font-size: 30px; line-height: 1.3; text-align: center; letter-spacing: 1px; }
.logo span { color: var(--green); }
.big-logo { font-size: 40px; color: var(--lead); letter-spacing: 3px; text-shadow: 3px 3px 0 var(--lead-d), 6px 6px 0 #1E1A33; }
.big-logo span { font-size: 26px; text-shadow: 3px 3px 0 var(--green-d), 6px 6px 0 #1E1A33; }
.logo.small { font-size: 14px; text-align: left; }
h2.logo { font-size: 22px; }
.sub { margin: 0; font-size: 14px; color: var(--muted); text-align: center; max-width: 280px; }

.card { background: var(--panel); border: 1px solid var(--line); border-radius: 16px; padding: 18px; display: flex; flex-direction: column; gap: 12px; }
.pool { font-family: var(--pixel); font-size: 22px; color: var(--green); }
.pool.small { font-size: 14px; }
.stats { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; font-size: 12px; }
.stats div, .mini { background: var(--bg); border-radius: 10px; padding: 10px; display: flex; flex-direction: column; gap: 4px; }
.mini { background: var(--panel); padding: 14px; }
.stats b { font-size: 15px; } .mini b { font-size: 18px; }

.btn-primary { min-height: 56px; background: var(--lead); color: var(--bg); border: 0; border-radius: 14px; font-family: var(--pixel); font-size: 14px; box-shadow: 0 5px 0 var(--lead-d); }
.btn-primary:active { transform: translateY(3px); box-shadow: 0 2px 0 var(--lead-d); }
.btn-primary:disabled { opacity: .5; }
.btn-primary.big { min-height: 66px; font-size: 18px; }
.btn-ghost { min-height: 48px; background: none; border: 1px solid var(--line); border-radius: 12px; font-size: 14px; font-weight: 700; }
.btn-ghost.slim { flex: none; padding: 0 16px; }
.btn-alt { min-height: 58px; background: none; border: 2px solid var(--green); color: var(--green); border-radius: 14px; font-weight: 700; font-size: 15px; }
.icon-btn { width: 44px; height: 44px; flex: none; display: flex; align-items: center; justify-content: center; border: 1px solid var(--line); border-radius: 10px; background: none; font-size: 22px; }
.badge { background: var(--green); color: var(--bg); font-weight: 700; font-size: 12px; padding: 5px 10px; border-radius: 6px; }
.score-big { font-family: var(--pixel); font-size: 32px; }

input { width: 100%; min-height: 48px; background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 0 14px; font-size: 15px; }
input::placeholder { color: #6E6890; }

/* play */
#play { gap: 10px; padding-top: max(12px, env(safe-area-inset-top)); touch-action: none; user-select: none; -webkit-user-select: none; }
.hud { display: flex; align-items: center; justify-content: space-between; gap: 8px; font-family: var(--pixel); font-size: 11px; }
.hud > div { display: flex; flex-direction: column; gap: 6px; }
.hud .c { align-items: center; } .hud .r { align-items: flex-end; }
.hud-l { color: var(--muted); font-size: 8px; }
.field { flex: 1; min-height: 0; position: relative; border: 1px solid var(--line); border-radius: 14px; background: #0B0915; overflow: hidden; display: flex; align-items: center; justify-content: center; }
#game { width: 100%; height: 100%; display: block; object-fit: contain; }
.paused { position: absolute; inset: 0; background: rgba(7, 6, 13, .88); display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 14px; padding: 40px; }
.paused[hidden] { display: none; }
.paused button { width: 100%; max-width: 240px; }
#play .field { flex: none; align-self: center; width: min(100%, calc((100dvh - 280px) * 360 / 424)); aspect-ratio: 360 / 424; border: 0; background: none; border-radius: 14px; }
#game { touch-action: none; }
.dpad { display: grid; grid-template-columns: repeat(3, 84px); grid-template-rows: repeat(2, 64px); margin-top: auto; gap: 6px 8px; justify-content: center; grid-template-areas: ". up ." "left down right"; }
.pad { background: var(--panel); border: 1px solid var(--line); border-radius: 14px; font-size: 18px; color: var(--lead); min-width: 44px; min-height: 44px; touch-action: none; }
.pad.up { grid-area: up; } .pad.left { grid-area: left; } .pad.right { grid-area: right; } .pad.down { grid-area: down; }
.pad.on { background: var(--line); border-color: var(--lead); }

/* lists */
.list { margin: 0; padding: 0; list-style: none; display: flex; flex-direction: column; gap: 4px; }
.list li { display: flex; align-items: center; gap: 12px; padding: 11px 12px; border-radius: 10px; font-size: 14px; }
.list li.top { background: var(--panel); }
.list .rk { width: 28px; font-weight: 700; color: var(--muted); }
.list .nm { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.list .pz { color: var(--green); font-size: 12px; }
#history li { background: var(--panel); }
.me-row { display: flex; align-items: center; gap: 12px; padding: 12px; border-radius: 12px; border: 2px solid var(--lead); font-size: 14px; font-weight: 700; }
.me-row .nm { flex: 1; }
.split { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 6px; font-size: 11px; text-align: center; }
.split div { background: var(--bg); border-radius: 8px; padding: 8px 4px; display: flex; flex-direction: column; gap: 2px; }

.banner { margin-top: auto; display: flex; justify-content: center; min-height: 50px; }
.banner[hidden] { display: none; }
#hud-best { font-size: 10px; }
/* play: keep the board and the pad together, centred in the spare height */
#play .field { margin-top: auto; }
#play .dpad { margin-top: 18px; margin-bottom: auto; grid-template-rows: repeat(2, 70px); grid-template-columns: repeat(3, 92px); }
#over-rank { align-items: stretch; }
