:root {
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --bg1: #2b1055;
  --bg2: #7597de;
  --panel: rgba(20, 10, 45, 0.92);
  --accent: #ff5fa2;
  --accent2: #ffd166;
}

* { margin: 0; padding: 0; box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body {
  height: 100%;
  overflow: hidden;
  overscroll-behavior: none;
  touch-action: manipulation;
  font-family: "Avenir Next", "Segoe UI", system-ui, sans-serif;
  background: linear-gradient(160deg, var(--bg1), #4527a0 55%, var(--bg2));
  color: #fff;
  user-select: none;
  -webkit-user-select: none;
}

#app {
  height: 100dvh;
  display: flex;
  flex-direction: column;
  padding-top: var(--safe-top);
  padding-bottom: var(--safe-bottom);
}

/* HUD */
#hud {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 8px 12px 4px;
}
.hud-block {
  background: rgba(255, 255, 255, 0.12);
  border-radius: 14px;
  padding: 4px 12px;
  text-align: center;
  min-width: 64px;
  backdrop-filter: blur(6px);
}
.hud-label { display: block; font-size: 10px; letter-spacing: 1px; text-transform: uppercase; opacity: 0.75; }
.hud-value { display: block; font-size: 19px; font-weight: 800; font-variant-numeric: tabular-nums; }
.hud-score .hud-value { color: var(--accent2); }
.icon-btn {
  background: rgba(255, 255, 255, 0.12);
  border: none;
  color: #fff;
  font-size: 18px;
  border-radius: 12px;
  width: 42px;
  height: 42px;
  cursor: pointer;
}
.icon-btn.muted { opacity: 0.45; }

/* Goal bar */
#goalbar { padding: 4px 16px 6px; }
#goal-text { font-size: 12px; opacity: 0.9; margin-bottom: 3px; }
#goal-progress {
  height: 10px;
  border-radius: 6px;
  background: rgba(0, 0, 0, 0.35);
  overflow: hidden;
}
#goal-fill {
  height: 100%;
  width: 0%;
  border-radius: 6px;
  background: linear-gradient(90deg, var(--accent), var(--accent2));
  transition: width 0.35s ease;
}

/* Stage */
#stage {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 0;
  padding: 4px 8px;
}
#board {
  border-radius: 18px;
  box-shadow: 0 10px 40px rgba(0, 0, 0, 0.45);
  background: rgba(0, 0, 0, 0.28);
  max-width: 100%;
  max-height: 100%;
}

/* Bottom bar */
#bottombar {
  display: flex;
  gap: 10px;
  justify-content: center;
  padding: 8px 12px 10px;
}
.pill-btn {
  background: rgba(255, 255, 255, 0.14);
  border: none;
  color: #fff;
  font-size: 14px;
  font-weight: 600;
  padding: 10px 18px;
  border-radius: 999px;
  cursor: pointer;
}
.pill-btn:active { transform: scale(0.96); }

/* Overlays */
.overlay {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(10, 5, 25, 0.72);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.25s ease;
  z-index: 50;
  padding: 20px;
  padding-top: calc(20px + var(--safe-top));
  padding-bottom: calc(20px + var(--safe-bottom));
}
.overlay.visible { opacity: 1; pointer-events: auto; }
.panel {
  background: var(--panel);
  border: 1px solid rgba(255, 255, 255, 0.15);
  border-radius: 24px;
  padding: 28px 24px;
  width: min(92vw, 380px);
  max-height: 100%;
  overflow-y: auto;
  text-align: center;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.5);
}

.game-title {
  font-size: 44px;
  font-weight: 900;
  background: linear-gradient(90deg, #ff5fa2, #ffd166, #6ee7b7);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  line-height: 1.05;
}
.game-title span { display: block; font-size: 30px; }
.subtitle { opacity: 0.85; margin: 6px 0 22px; font-size: 14px; }

.name-label { display: block; font-size: 12px; opacity: 0.8; margin-bottom: 6px; text-align: left; }
#player-name {
  width: 100%;
  padding: 12px 14px;
  font-size: 16px;
  border-radius: 14px;
  border: 1px solid rgba(255, 255, 255, 0.25);
  background: rgba(255, 255, 255, 0.1);
  color: #fff;
  outline: none;
  margin-bottom: 16px;
}
#player-name:focus { border-color: var(--accent); }

.big-btn {
  display: block;
  width: 100%;
  padding: 14px;
  font-size: 18px;
  font-weight: 800;
  color: #2b1055;
  background: linear-gradient(90deg, var(--accent2), #ffb347);
  border: none;
  border-radius: 16px;
  cursor: pointer;
  margin-top: 6px;
}
.big-btn:active { transform: scale(0.97); }
.ghost-btn {
  display: block;
  width: 100%;
  margin-top: 10px;
  padding: 12px;
  font-size: 15px;
  color: #fff;
  background: transparent;
  border: 1px solid rgba(255, 255, 255, 0.3);
  border-radius: 16px;
  cursor: pointer;
}
.hidden { display: none !important; }
.hint { font-size: 12px; opacity: 0.65; margin-top: 16px; }

.stars { font-size: 42px; color: var(--accent2); letter-spacing: 6px; margin: 8px 0; text-shadow: 0 3px 12px rgba(255, 209, 102, 0.5); }
.stars .off { color: rgba(255, 255, 255, 0.2); text-shadow: none; }

#level-result-text, #gameover-text { opacity: 0.9; font-size: 15px; margin: 8px 0 14px; }

/* Leaderboard */
#lb-list { list-style: none; text-align: left; margin: 12px 0; max-height: 45dvh; overflow-y: auto; }
#lb-list li {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 10px;
  border-radius: 12px;
  font-size: 15px;
}
#lb-list li:nth-child(odd) { background: rgba(255, 255, 255, 0.06); }
#lb-list li.me { background: rgba(255, 95, 162, 0.25); }
#lb-list .rank { width: 28px; font-weight: 800; color: var(--accent2); }
#lb-list .name { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
#lb-list .pts { font-variant-numeric: tabular-nums; font-weight: 700; }
#lb-list .lvl { font-size: 12px; opacity: 0.7; margin-left: 6px; }
#lb-status { font-size: 14px; opacity: 0.8; }

@media (max-width: 380px) {
  .hud-value { font-size: 16px; }
  .hud-block { min-width: 54px; padding: 4px 8px; }
  .game-title { font-size: 36px; }
}
