:root { --bg:#161b2c; --fg:#f4f6ff; --dim:#aab0d6; --accent:#5ee7ff; --ball:#ffe66d; --danger:#ff4d6d; }
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body {
  margin: 0; height: 100%; overflow: hidden; background: #070812; color: var(--fg);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  overscroll-behavior: none; touch-action: none;
  -webkit-user-select: none; user-select: none; -webkit-touch-callout: none;
}
#stage {
  position: relative; height: 100vh; height: 100dvh; width: 100%; max-width: 520px; margin: 0 auto;
  background: var(--bg); overflow: hidden; touch-action: none; cursor: pointer;
}
#game { position: absolute; inset: 0; width: 100%; height: 100%; display: block; }

#hud {
  position: absolute; top: 0; left: 0; right: 0; z-index: 2; pointer-events: none;
  display: flex; align-items: flex-start; justify-content: space-between;
  padding: max(12px, env(safe-area-inset-top)) 14px 0;
}
#hud .best { flex: 1; font-size: 14px; font-weight: 700; letter-spacing: .08em; color: var(--dim); padding-top: 10px; }
#score {
  flex: 1; text-align: center; font-size: 56px; font-weight: 800; line-height: 1;
  text-shadow: 0 2px 16px rgba(94,231,255,.45); font-variant-numeric: tabular-nums;
}
#hud .btns { flex: 1; display: flex; gap: 8px; justify-content: flex-end; }
button {
  pointer-events: auto; width: 44px; height: 44px; border-radius: 12px; cursor: pointer;
  border: 1px solid rgba(255,255,255,.25); background: rgba(255,255,255,.08); color: var(--fg);
  font-size: 16px; line-height: 1; padding: 0;
}
button:hover { background: rgba(255,255,255,.16); }
button:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }
button[aria-pressed="true"] { opacity: .55; }

#overlay {
  position: absolute; inset: 0; z-index: 1; pointer-events: none; text-align: center;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 10px;
  padding: 90px 28px 40px; background: rgba(7,8,18,.62);
  opacity: 0; visibility: hidden; transition: opacity .25s, visibility .25s;
}
#overlay.show { opacity: 1; visibility: visible; }
#overlay h1 { margin: 0; font-size: clamp(34px, 11vw, 56px); letter-spacing: .02em; text-shadow: 0 4px 24px rgba(94,231,255,.5); }
#overlay.over { justify-content: flex-start; padding-top: 16vh; background: linear-gradient(rgba(7,8,18,.8), rgba(7,8,18,.15)); }
#overlay.over h1 { color: var(--ball); text-shadow: 0 4px 24px rgba(255,230,109,.4); }
#msg { margin: 0; font-size: 20px; font-weight: 700; min-height: 1.3em; }
#tip { margin: 0; max-width: 320px; font-size: 16px; line-height: 1.45; color: var(--dim); }
#tip:empty { display: none; }
#cta { margin: 18px 0 0; font-size: 20px; font-weight: 800; color: #0e1020; background: var(--ball);
  padding: 12px 28px; border-radius: 999px; animation: pulse 1.1s ease-in-out infinite; }
@keyframes pulse { 50% { transform: scale(1.08); } }
@media (prefers-reduced-motion: reduce) { #cta { animation: none; } #overlay { transition: none; } }


#overlay.result { justify-content: flex-end; padding: 0 28px 7vh; background: linear-gradient(rgba(7,8,18,0), rgba(7,8,18,.88) 55%); }
#overlay.result h1 { color: var(--ball); text-shadow: 0 4px 24px rgba(255,201,60,.45); }
#overlay.result #cta { margin-top: 10px; }
#overlay.over { justify-content: center; padding-top: 90px; background: rgba(7,8,18,.7); }
#hint {
  position: absolute; left: 0; right: 0; bottom: 9vh; z-index: 2; pointer-events: none; text-align: center;
  font-size: 18px; font-weight: 800; letter-spacing: .04em; color: #0d1022; opacity: 0; transition: opacity .25s;
}
#hint span { background: var(--ball); padding: 10px 18px; border-radius: 999px; }
#hint.show { opacity: 1; }
