* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  width: 100%;
  height: 100%;
  overflow: hidden;
  background: #05060c;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  color: #eef1ff;
  touch-action: none;
}

#scene {
  position: fixed;
  inset: 0;
  display: block;
  width: 100%;
  height: 100%;
}

.hidden { display: none !important; }

/* ---------- HUD ---------- */

#hud {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  padding: 14px 16px;
  z-index: 10;
  pointer-events: none;
}

.hud-top {
  display: flex;
  align-items: center;
  gap: 16px;
  pointer-events: auto;
}

.hud-stat {
  display: flex;
  align-items: center;
  gap: 8px;
  background: rgba(10, 14, 30, 0.55);
  backdrop-filter: blur(6px);
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 999px;
  padding: 6px 14px;
}

.hud-stat-moves, .hud-stat-level { flex: 0 0 auto; }

.hud-label {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: #9aa3c7;
  white-space: nowrap;
}

.hud-value {
  font-variant-numeric: tabular-nums;
  font-weight: 700;
  font-size: 15px;
  min-width: 2.2em;
  text-align: right;
}

.timebar {
  width: 140px;
  height: 8px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.12);
  overflow: hidden;
}

.timebar-fill {
  height: 100%;
  width: 100%;
  border-radius: 999px;
  background: linear-gradient(90deg, #33e0a1, #35c0ff);
  transition: background 0.4s ease;
}

.hud-top .btn { margin-left: auto; }

/* ---------- Mute button ---------- */

/* Bottom-right corner, deliberately far from the HUD's top-aligned stat
   pills and buttons (which can wrap to a second line on narrow screens) so
   it can never collide with them, on any screen size, without needing
   per-breakpoint offset math. */
.mute-btn {
  position: fixed;
  bottom: calc(16px + env(safe-area-inset-bottom, 0px));
  right: 16px;
  z-index: 30;
  width: 42px;
  height: 42px;
  border-radius: 50%;
  border: 1px solid rgba(255, 255, 255, 0.12);
  background: rgba(10, 14, 30, 0.55);
  backdrop-filter: blur(6px);
  color: #eef1ff;
  font-size: 18px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: transform 0.15s ease, background 0.15s ease;
}
.mute-btn:hover { transform: translateY(-1px); background: rgba(20, 26, 50, 0.75); }
.mute-btn:active { transform: translateY(0); }

/* ---------- Overlays ---------- */

.overlay {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: center;
  background: radial-gradient(ellipse at 50% 30%, rgba(30, 40, 90, 0.55), rgba(2, 3, 8, 0.9));
  padding: 20px;
}

.panel {
  max-width: 480px;
  width: 100%;
  background: rgba(15, 18, 34, 0.85);
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 18px;
  padding: 32px 28px;
  text-align: center;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.5);
}

.panel h1 {
  margin: 0 0 10px;
  font-size: 26px;
}

.panel .lead {
  color: #c7cdf0;
  margin: 0 0 16px;
  line-height: 1.5;
}

.panel .stats {
  color: #ffd166;
  font-size: 17px;
  font-weight: 600;
  margin: 0 0 20px;
}

.rules {
  text-align: left;
  color: #b7bfe6;
  font-size: 14px;
  line-height: 1.6;
  padding-left: 20px;
  margin: 0 0 22px;
}

.rules li { margin-bottom: 8px; }
.rules strong { color: #eef1ff; }

.btn {
  border: none;
  border-radius: 12px;
  padding: 13px 26px;
  font-size: 16px;
  font-weight: 700;
  cursor: pointer;
  color: #04121a;
  background: linear-gradient(135deg, #33e0a1, #35c0ff);
  box-shadow: 0 8px 24px rgba(53, 192, 255, 0.35);
  transition: transform 0.15s ease, box-shadow 0.15s ease;
}

.btn:hover { transform: translateY(-1px); box-shadow: 0 10px 28px rgba(53, 192, 255, 0.45); }
.btn:active { transform: translateY(0); }

.btn-small {
  padding: 7px 14px;
  font-size: 13px;
  border-radius: 999px;
}

.btn-secondary {
  background: rgba(255, 255, 255, 0.08);
  color: #eef1ff;
  box-shadow: none;
  border: 1px solid rgba(255, 255, 255, 0.16);
}
.btn-secondary:hover { box-shadow: none; background: rgba(255, 255, 255, 0.13); }

.btn-row {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  justify-content: center;
}

/* ---------- Level picker ---------- */

.level-picker { margin-bottom: 22px; text-align: left; }
.level-picker .hud-label { display: block; margin-bottom: 8px; }

.level-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.level-card {
  text-align: left;
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 10px;
  padding: 9px 12px;
  cursor: pointer;
  color: #eef1ff;
  display: flex;
  flex-direction: column;
  gap: 2px;
  transition: border-color 0.15s ease, background 0.15s ease;
}
.level-card:hover:not(:disabled) { background: rgba(255, 255, 255, 0.09); }
.level-card.selected {
  border-color: #35c0ff;
  background: rgba(53, 192, 255, 0.14);
  box-shadow: 0 0 0 1px rgba(53, 192, 255, 0.4) inset;
}
.level-card.locked {
  opacity: 0.45;
  cursor: not-allowed;
}
.level-card-name { font-weight: 700; font-size: 13.5px; }
.level-card-desc { font-size: 11.5px; color: #9aa3c7; line-height: 1.35; }

@media (max-width: 520px) {
  .level-grid { grid-template-columns: 1fr; }
}

/* ---------- Buttons: text-only variant, score line, leaderboard ---------- */

.btn-text {
  background: none;
  box-shadow: none;
  border: none;
  color: #9aa3c7;
  font-size: 13px;
  font-weight: 600;
  padding: 8px 10px;
  margin-top: 6px;
  cursor: pointer;
  text-decoration: underline;
  text-underline-offset: 2px;
}
.btn-text:hover { color: #eef1ff; }

.score-line {
  color: #35c0ff;
  font-size: 20px;
  font-weight: 800;
  margin: -8px 0 18px;
}
.score-line .score-rank {
  display: block;
  font-size: 12.5px;
  font-weight: 600;
  color: #9aa3c7;
  margin-top: 2px;
}

.leaderboard-list {
  text-align: left;
  max-height: 46vh;
  overflow-y: auto;
  margin-bottom: 18px;
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 10px;
}
.leaderboard-empty {
  padding: 18px 14px;
  color: #9aa3c7;
  font-size: 14px;
  text-align: center;
}
.leaderboard-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 12px;
  font-size: 13.5px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.06);
}
.leaderboard-row:last-child { border-bottom: none; }
.leaderboard-rank {
  width: 1.8em;
  flex: 0 0 auto;
  color: #9aa3c7;
  font-variant-numeric: tabular-nums;
  font-weight: 700;
}
.leaderboard-score {
  font-weight: 800;
  color: #ffd166;
  min-width: 3.4em;
  text-align: right;
  flex: 0 0 auto;
  font-variant-numeric: tabular-nums;
}
.leaderboard-meta { flex: 1 1 auto; color: #c7cdf0; }
.leaderboard-meta .level-name { color: #eef1ff; font-weight: 600; }
.leaderboard-date { flex: 0 0 auto; color: #6c7399; font-size: 11.5px; }

.mastery-badge {
  display: inline-block;
  margin-left: 5px;
  color: #ffd166;
  font-weight: 700;
}

@media (max-width: 640px) {
  .hud-top { flex-wrap: wrap; row-gap: 8px; }
}

@media (max-width: 520px) {
  .panel { padding: 24px 18px; }
  .timebar { width: 90px; }
  .hud-stat { padding: 6px 10px; }
}
