* { box-sizing: border-box; margin: 0; padding: 0; }
:root {
  --bg0: #1a1340;
  --bg1: #120d2e;
  --bg2: #0a0820;
  --ink: #f3f0ff;
  --sub: #b9aee6;
  --accent: #ffd23f;
  --pink: #ff6ea6;
}
html, body { height: 100%; }
html { -webkit-text-size-adjust: 100%; }
body {
  font-family: "Baloo 2", "Trebuchet MS", -apple-system, BlinkMacSystemFont, "Segoe UI", "Apple SD Gothic Neo", system-ui, sans-serif;
  color: var(--ink);
  background:
    radial-gradient(120% 90% at 50% -10%, #2a1e63 0%, var(--bg0) 32%, var(--bg1) 62%, var(--bg2) 100%);
  overflow: hidden;
  user-select: none;
  -webkit-user-select: none;
  -webkit-tap-highlight-color: transparent;
  touch-action: none;
}

.topbar {
  position: fixed; top: 0; left: 0; right: 0; z-index: 30;
  height: 50px; display: flex; align-items: center; gap: 12px;
  padding: 0 14px 0 max(14px, env(safe-area-inset-left));
  background: linear-gradient(180deg, rgba(10,8,32,.78), rgba(10,8,32,0));
  font-size: 14px;
}
.topbar .back { color: var(--sub); font-weight: 700; opacity: .9; }
.topbar .back:hover { opacity: 1; color: #fff; }
.topbar .brand { font-weight: 800; letter-spacing: -.01em; font-size: 16px; }
.topbar .brand .ic { filter: drop-shadow(0 2px 6px rgba(120,180,255,.5)); }
.topbar .hs { margin-left: auto; font-size: 12px; color: var(--sub); font-weight: 700; }
.topbar .hs b { color: var(--accent); font-size: 15px; }
a { text-decoration: none; color: inherit; }

#stage {
  position: fixed; inset: 0;
  display: flex; align-items: center; justify-content: center;
  padding: 54px 8px calc(8px + env(safe-area-inset-bottom));
}
#wrap {
  position: relative;
  height: 100%;
  max-height: 100%;
  aspect-ratio: 480 / 760;
  max-width: 100%;
  border-radius: 22px;
  overflow: hidden;
  box-shadow: 0 24px 70px rgba(0,0,0,.55), inset 0 0 0 1px rgba(255,255,255,.06);
}
canvas { display: block; width: 100%; height: 100%; }

/* ── Overlays ── */
.overlay {
  position: absolute; inset: 0; z-index: 20;
  display: flex; align-items: center; justify-content: center; padding: 22px;
  background: radial-gradient(120% 80% at 50% 30%, rgba(28,20,70,.5), rgba(8,6,24,.86));
  -webkit-backdrop-filter: blur(3px); backdrop-filter: blur(3px);
}
.overlay.hidden { display: none; }
.panel {
  width: 100%; max-width: 340px; text-align: center;
  background: linear-gradient(180deg, rgba(40,30,92,.92), rgba(22,16,52,.95));
  border: 1px solid rgba(255,255,255,.12);
  border-radius: 22px; padding: 26px 22px;
  box-shadow: 0 18px 50px rgba(0,0,0,.5);
}
.panel h1 {
  font-size: 34px; font-weight: 800; letter-spacing: -.02em; line-height: 1.05;
  background: linear-gradient(90deg, #ffd23f, #ff8fc4 55%, #8fd2ff);
  -webkit-background-clip: text; background-clip: text; -webkit-text-fill-color: transparent;
}
.panel h2 { font-size: 26px; font-weight: 800; margin-bottom: 4px; }
.panel .sub { margin-top: 12px; font-size: 14px; line-height: 1.6; color: var(--sub); }
.panel .ctrl { margin-top: 14px; font-size: 12px; line-height: 1.7; color: #9b90c8; }
.panel .ctrl b { color: #d9cfff; }
.btn {
  margin-top: 18px; width: 100%;
  padding: 13px 18px; border: 0; border-radius: 14px; cursor: pointer;
  font: inherit; font-size: 17px; font-weight: 800; color: #2a1330;
  background: linear-gradient(180deg, #ffe48a, #ffc23d);
  box-shadow: 0 8px 22px rgba(255,190,60,.4), inset 0 1px 0 rgba(255,255,255,.6);
  transition: transform .12s, filter .12s;
}
.btn:hover { transform: translateY(-1px); filter: brightness(1.05); }
.btn:active { transform: translateY(1px); }
.stats {
  margin: 18px 0 6px; display: grid; grid-template-columns: 1fr 1fr; gap: 10px;
}
.stats > div {
  background: rgba(0,0,0,.22); border-radius: 13px; padding: 11px 8px;
  border: 1px solid rgba(255,255,255,.07);
}
.stats span { display: block; font-size: 11px; color: var(--sub); font-weight: 700; }
.stats b { display: block; font-size: 22px; font-weight: 800; margin-top: 3px; color: #fff; }
.best { margin-top: 12px; font-size: 13px; font-weight: 700; color: var(--accent); min-height: 16px; }
.toast {
  position: absolute; left: 50%; top: 16%; transform: translateX(-50%);
  z-index: 18; pointer-events: none;
  font-size: 30px; font-weight: 800; letter-spacing: .02em;
  color: #fff; text-shadow: 0 3px 14px rgba(255,120,200,.7);
  opacity: 0;
}
.toast.show { animation: toastPop 1.1s ease forwards; }
@keyframes toastPop {
  0% { opacity: 0; transform: translateX(-50%) scale(.6); }
  20% { opacity: 1; transform: translateX(-50%) scale(1.1); }
  70% { opacity: 1; transform: translateX(-50%) scale(1); }
  100% { opacity: 0; transform: translateX(-50%) scale(1) translateY(-14px); }
}
