:root {
  --bg: #0b0b1a;
  --bg-raise: #17172d;
  --ink: #e8e6f0;
  --ink-dim: #9794ad;
  --neon-cyan: #4de8e0;
  --neon-pink: #ff5db1;
  --neon-amber: #ffc94d;
  --neon-violet: #9d7bff;
  --pixel: 4px;
  --font-pixel: "Press Start 2P", "Microsoft YaHei", monospace;
  --font-body: "PingFang SC", "Microsoft YaHei", "Noto Sans SC", sans-serif;
  --rod-w: clamp(34px, 8.6vw, 54px);
  --nut-h: clamp(20px, 5.4vw, 32px);
}

* { box-sizing: border-box; margin: 0; -webkit-tap-highlight-color: transparent; }
html { background: var(--bg); }
body { min-height: 100vh; background: var(--bg); color: var(--ink); font-family: var(--font-body); -webkit-font-smoothing: antialiased; touch-action: manipulation; }
button { font: inherit; color: inherit; }
.scanlines { position: fixed; inset: 0; z-index: 10; pointer-events: none; opacity: 0.3; background: repeating-linear-gradient(to bottom, transparent 0 3px, rgba(0, 0, 0, 0.16) 3px 4px); }
.wrap { width: min(100%, 620px); margin: 0 auto; padding: 24px 14px 40px; }

.head { text-align: center; }
.title { color: var(--ink); font-family: var(--font-pixel); font-size: clamp(22px, 6vw, 34px); letter-spacing: 0.06em; text-shadow: var(--pixel) var(--pixel) 0 var(--neon-pink), calc(var(--pixel) * -1) calc(var(--pixel) * -1) 0 rgba(77, 232, 224, 0.35); }
.subtitle { margin-top: 10px; color: var(--ink-dim); font-size: 13px; letter-spacing: 0.14em; }

.tabs { display: flex; gap: 10px; justify-content: center; margin: 22px 0 16px; }
.tab { padding: 9px 18px; background: var(--bg-raise); border: 3px solid var(--ink-dim); color: var(--ink-dim); font-family: var(--font-pixel); font-size: 10px; letter-spacing: 0.1em; cursor: pointer; }
.tab.is-on { color: var(--bg); background: var(--neon-cyan); border-color: var(--ink); box-shadow: var(--pixel) var(--pixel) 0 var(--neon-pink); }

.stage { background: var(--bg-raise); border: var(--pixel) solid var(--ink); box-shadow: calc(var(--pixel) * 2) calc(var(--pixel) * 2) 0 var(--neon-violet); padding: 16px 12px 18px; }
.stage-head { display: flex; flex-wrap: wrap; justify-content: center; gap: 8px 22px; }
.meta { display: flex; flex-direction: column; align-items: center; gap: 6px; }
.label { color: var(--ink-dim); font-family: var(--font-pixel); font-size: 8px; letter-spacing: 0.12em; }
.value { color: var(--neon-amber); font-family: var(--font-pixel); font-size: 14px; font-variant-numeric: tabular-nums; }
.hint { margin: 12px auto 4px; max-width: 440px; color: var(--ink-dim); font-size: 12px; line-height: 1.7; text-align: center; }

/* ---- board & rods ---- */
.board { display: flex; flex-wrap: wrap; justify-content: center; align-items: flex-end; gap: clamp(8px, 2.4vw, 18px); min-height: calc(var(--nut-h) * 6 + 46px); padding: 18px 4px 6px; }
.rod { position: relative; display: flex; flex-direction: column-reverse; align-items: center; gap: 3px; width: var(--rod-w); min-height: calc(var(--nut-h) * var(--cap, 4) + 26px); padding-top: 22px; padding-bottom: 6px; cursor: pointer; user-select: none; -webkit-user-select: none; }
.rod::before { content: ""; position: absolute; left: 50%; top: 8px; bottom: 10px; width: 34%; transform: translateX(-50%); z-index: 0; background: repeating-linear-gradient(to bottom, #cfd2e8 0 3px, #8f93b8 3px 6px); border: 2px solid #565a80; border-radius: 3px; }
.rod::after { content: ""; position: absolute; left: 50%; top: 2px; width: 56%; height: 8px; transform: translateX(-50%); z-index: 1; background: #cfd2e8; border: 2px solid #565a80; border-radius: 3px; }
.rod-base { position: absolute; left: 50%; bottom: 0; width: 118%; height: 8px; transform: translateX(-50%); background: #565a80; border: 2px solid var(--ink); }
.rod.is-picked::before { background: repeating-linear-gradient(to bottom, var(--neon-cyan) 0 3px, #8f93b8 3px 6px); }
.rod.is-shake { animation: shake 0.28s ease; }
@keyframes shake { 20% { transform: translateX(-4px); } 45% { transform: translateX(4px); } 70% { transform: translateX(-3px); } 90% { transform: translateX(2px); } }

.nut { position: relative; z-index: 2; width: 100%; height: var(--nut-h); background: var(--nut-color, #888); border: 2px solid rgba(0, 0, 0, 0.55); border-radius: 6px; box-shadow: inset 0 3px 0 rgba(255, 255, 255, 0.38), inset 0 -4px 0 rgba(0, 0, 0, 0.28); }
.nut::after { content: ""; position: absolute; left: 50%; top: 50%; width: 34%; height: 46%; transform: translate(-50%, -50%); background: rgba(0, 0, 0, 0.22); border-radius: 3px; box-shadow: inset 0 2px 0 rgba(255, 255, 255, 0.16); }
.nut.is-lift { transform: translateY(-14px); filter: brightness(1.18); }
.nut.is-drop { animation: drop 0.16s ease-out; }
@keyframes drop { from { transform: translateY(-12px); } to { transform: translateY(0); } }
.board.is-won .nut { animation: pop 0.5s ease; }
@keyframes pop { 40% { transform: translateY(-6px) scale(1.06); } }

.c0 { --nut-color: #ff4d5e; } .c1 { --nut-color: #ffb01f; } .c2 { --nut-color: #ffe14d; }
.c3 { --nut-color: #3ecf6e; } .c4 { --nut-color: #35b7f0; } .c5 { --nut-color: #4d6bff; }
.c6 { --nut-color: #a95df0; } .c7 { --nut-color: #ff5db1; } .c8 { --nut-color: #8d6e63; }
.c9 { --nut-color: #4de8e0; } .c10 { --nut-color: #c9d1dc; } .c11 { --nut-color: #7bd44a; }

/* ---- controls / buttons ---- */
.controls { display: flex; flex-wrap: wrap; justify-content: center; gap: 10px; margin-top: 16px; }
.btn { padding: 12px 18px; background: var(--bg); border: 3px solid var(--ink); color: var(--neon-cyan); font-family: var(--font-pixel); font-size: 10px; letter-spacing: 0.1em; cursor: pointer; box-shadow: var(--pixel) var(--pixel) 0 rgba(77, 232, 224, 0.5); }
.btn:active { transform: translate(2px, 2px); box-shadow: 2px 2px 0 rgba(77, 232, 224, 0.5); }
.btn:disabled { opacity: 0.4; cursor: default; }
.btn-alt { color: var(--neon-pink); box-shadow: var(--pixel) var(--pixel) 0 rgba(255, 93, 177, 0.5); }

/* ---- overlays ---- */
.overlay { position: fixed; inset: 0; z-index: 40; display: grid; place-items: center; padding: 20px; background: rgba(5, 5, 14, 0.82); }
.overlay[hidden] { display: none; }
.overlay-box { width: min(100%, 420px); background: var(--bg-raise); border: var(--pixel) solid var(--ink); box-shadow: calc(var(--pixel) * 2) calc(var(--pixel) * 2) 0 var(--neon-amber); padding: 26px 20px; text-align: center; }
.overlay-box.wide { width: min(100%, 520px); max-height: 82vh; overflow-y: auto; }
.overlay-title { color: var(--neon-amber); font-family: var(--font-pixel); font-size: 18px; line-height: 1.6; text-shadow: 3px 3px 0 var(--neon-pink); }
.overlay-stars { margin-top: 8px; color: var(--neon-amber); font-size: 22px; letter-spacing: 6px; }
.overlay-stars .off { color: var(--ink-dim); opacity: 0.45; }
.overlay-stat { margin-top: 10px; color: var(--ink-dim); font-size: 13px; }
.overlay-stat strong { color: var(--ink); }
.overlay-badges { margin-top: 8px; color: var(--neon-cyan); font-family: var(--font-pixel); font-size: 9px; line-height: 2; letter-spacing: 0.06em; }
.overlay-actions { display: flex; justify-content: center; gap: 12px; margin-top: 18px; }

.level-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(64px, 1fr)); gap: 10px; margin: 18px 0; }
.lvl { position: relative; display: flex; flex-direction: column; align-items: center; gap: 4px; padding: 10px 4px 8px; background: var(--bg); border: 3px solid var(--ink-dim); color: var(--ink); font-family: var(--font-pixel); font-size: 11px; cursor: pointer; }
.lvl .stars { color: var(--neon-amber); font-size: 9px; letter-spacing: 1px; min-height: 12px; }
.lvl .rec { color: var(--ink-dim); font-size: 7px; }
.lvl.is-locked { opacity: 0.45; cursor: default; }
.lvl.is-cur { border-color: var(--neon-cyan); box-shadow: 3px 3px 0 var(--neon-cyan); }

.back { margin-top: 26px; text-align: center; }
.back a { color: var(--ink-dim); font-family: var(--font-pixel); font-size: 9px; letter-spacing: 0.08em; text-decoration: none; }
.back a:hover { color: var(--neon-cyan); }
.noscript { padding: 40px 20px; color: var(--ink-dim); text-align: center; }

@media (prefers-reduced-motion: reduce) {
  .rod.is-shake, .nut.is-drop, .board.is-won .nut { animation: none; }
}
