* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

body {
  background:
    radial-gradient(circle at 15% 10%, rgba(0, 212, 255, 0.14), transparent 45%),
    radial-gradient(circle at 85% 80%, rgba(255, 77, 109, 0.12), transparent 45%),
    linear-gradient(160deg, #0a0d24 0%, #06071a 60%, #040510 100%) fixed;
  display: flex;
  justify-content: center;
  align-items: center;
  min-height: 100vh;
  font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
  color: #fff;
  overflow-x: hidden;
  touch-action: pan-y;
}

#game-container {
  position: relative;
  max-width: 100vw;
}

#hud {
  display: flex;
  justify-content: space-between;
  padding: 12px 20px;
  background: linear-gradient(180deg, rgba(40, 56, 120, 0.55), rgba(16, 22, 56, 0.55));
  border: 1px solid rgba(120, 170, 255, 0.25);
  border-bottom: 0;
  border-radius: 14px 14px 0 0;
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  font-size: 18px;
  font-weight: 700;
  letter-spacing: 1px;
  font-variant-numeric: tabular-nums;
}

#score { color: #00d4ff; text-shadow: 0 0 12px rgba(0, 212, 255, 0.6); }
#level { color: #ffd700; text-shadow: 0 0 12px rgba(255, 215, 0, 0.5); }
#lives { color: #ff4d6d; text-shadow: 0 0 12px rgba(255, 77, 109, 0.5); }

canvas {
  display: block;
  width: min(800px, 100vw, max(240px, calc((100vh - var(--gp-header-h, 80px) - 88px) * 4 / 3)));
  width: min(800px, 100vw, max(240px, calc((100dvh - var(--gp-header-h, 80px) - 88px) * 4 / 3)));
  height: auto;
  background: #060a1e;
  border-radius: 0 0 14px 14px;
  border: 1px solid rgba(120, 170, 255, 0.25);
  border-top: none;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.55), 0 0 80px rgba(0, 212, 255, 0.12);
  touch-action: none;
}

#overlay {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: radial-gradient(circle at 50% 30%, rgba(30, 40, 100, 0.78), rgba(5, 6, 20, 0.92));
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  display: flex;
  flex-direction: column;
  justify-content: center;
  justify-content: safe center;
  align-items: center;
  overflow-y: auto;
  border-radius: 14px;
  z-index: 10;
}

#overlay.hidden {
  display: none;
}

#overlay h1 {
  font-size: 48px;
  margin-bottom: 12px;
  letter-spacing: 2px;
  text-shadow: 0 0 24px currentColor;
}

#overlay p {
  font-size: 20px;
  margin-bottom: 20px;
  color: #b9c3e6;
  white-space: pre-line;
  text-align: center;
}

#overlay button,
#overlay-btn-secondary {
  padding: 14px 40px;
  font-size: 18px;
  font-weight: 800;
  border: none;
  border-radius: 999px;
  background: linear-gradient(135deg, #00e5ff, #7c4dff);
  color: #05061a;
  cursor: pointer;
  transition: transform 0.2s, box-shadow 0.2s;
  box-shadow: 0 6px 24px rgba(0, 212, 255, 0.35);
  margin: 6px;
}

#overlay button:hover,
#overlay-btn-secondary:hover {
  transform: translateY(-2px);
  box-shadow: 0 10px 30px rgba(0, 212, 255, 0.5);
}

#overlay-btn-secondary {
  background: rgba(255, 255, 255, 0.08);
  color: #fff;
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.2);
}

#overlay #precision-btn {
  margin-top: 8px;
  padding: 8px 20px;
  font-size: 13px;
  font-weight: 800;
  border: 2px solid #ffd700;
  background: transparent;
  color: #ffd700;
  box-shadow: 0 0 16px rgba(255, 215, 0, 0.2);
}

#overlay #precision-btn:hover {
  background: rgba(255,215,0,0.15);
  border-color: #ffe44d;
  color: #ffe44d;
}

.pu { font-weight: 800; }
.pu-w { color: #00e676; }
.pu-m { color: #e040fb; }
.pu-s { color: #00d4ff; }
.pu-l1 { color: #ff4d6d; }
.pu-f { color: #ff6600; }
.pu-l { color: #ffff00; }
.pu-g { color: #ff69b4; }
.combo-tip { color: #ffd700; font-size: 11px; }
.brick-key { display: inline-block; padding: 0 6px; border-radius: 4px; font-size: 11px; font-weight: 800; color: #0a0b1e; }
.brick-key.steel { background: linear-gradient(180deg, #e3e8f5, #8f9bb8); }
.brick-key.boom { background: linear-gradient(180deg, #ffc8b8, #ff5a36); }
.brick-key.gold { background: linear-gradient(180deg, #fff2b0, #ffc93c); }

/* High Scores */
#highscores {
  margin-bottom: 20px;
  text-align: center;
}

#highscores.hidden {
  display: none;
}

#highscores h2 {
  font-size: 22px;
  color: #ffd700;
  margin-bottom: 10px;
}

#score-list {
  list-style: none;
  padding: 0;
}

#score-list li {
  font-size: 16px;
  padding: 4px 0;
  color: #ccc;
  font-variant-numeric: tabular-nums;
}

#score-list li:first-child {
  color: #ffd700;
  font-weight: 700;
}

#score-list li:nth-child(2) {
  color: #c0c0c0;
}

#score-list li:nth-child(3) {
  color: #cd7f32;
}

/* Active Power-up indicators */
#powerup-hud {
  display: flex;
  gap: 8px;
  justify-content: center;
  padding: 6px 0;
  min-height: 30px;
}

.powerup-indicator {
  position: relative;
  padding: 3px 10px;
  border-radius: 999px;
  font-size: 13px;
  font-weight: 800;
  color: #0f0f1a;
  overflow: hidden;
  box-shadow: 0 0 14px rgba(255, 255, 255, 0.15);
}

.powerup-timer-bar {
  position: absolute;
  bottom: 0;
  left: 0;
  height: 3px;
  border-radius: 0 0 4px 4px;
  transition: width 0.3s linear;
}

@keyframes pulse {
  from { opacity: 0.8; }
  to { opacity: 1; }
}

/* ── Level Select Screen ── */
#level-select {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: radial-gradient(circle at 50% 30%, rgba(30, 40, 100, 0.85), rgba(5, 6, 20, 0.95));
  display: flex;
  flex-direction: column;
  justify-content: center;
  justify-content: safe center;
  align-items: center;
  overflow-y: auto;
  border-radius: 14px;
  z-index: 11;
  padding: 30px 20px;
}

#level-select.hidden {
  display: none;
}

.ls-title {
  font-size: 36px;
  color: #00d4ff;
  text-shadow: 0 0 20px rgba(0, 212, 255, 0.55);
  margin-bottom: 24px;
  text-align: center;
  letter-spacing: 2px;
}

.ls-world-tabs {
  display: flex;
  gap: 8px;
  margin-bottom: 30px;
  flex-wrap: wrap;
  justify-content: center;
}

.ls-tab {
  padding: 10px 22px;
  font-size: 15px;
  font-weight: 600;
  border: 1px solid rgba(255, 255, 255, 0.16);
  border-radius: 999px;
  background: rgba(255,255,255,0.05);
  color: #b9c3e6;
  cursor: pointer;
  transition: all 0.2s;
  position: relative;
}

.ls-tab:hover:not([disabled]) {
  border-color: #00d4ff;
  color: #fff;
}

.ls-tab.active {
  border-color: #00d4ff;
  background: rgba(0,212,255,0.12);
  color: #00d4ff;
}

.ls-tab.locked {
  opacity: 0.35;
  cursor: not-allowed;
}

.ls-tab .lock-icon {
  font-size: 12px;
  margin-right: 4px;
}

.ls-levels {
  display: flex;
  gap: 14px;
  margin-bottom: 30px;
  flex-wrap: wrap;
  justify-content: center;
}

.ls-level-btn {
  width: 90px;
  height: 90px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 6px;
  border: 1px solid rgba(255, 255, 255, 0.16);
  border-radius: 16px;
  background: linear-gradient(180deg, rgba(255,255,255,0.10), rgba(255,255,255,0.03));
  color: #fff;
  cursor: pointer;
  transition: all 0.2s;
  font-family: inherit;
}

.ls-level-btn:hover:not([disabled]) {
  border-color: #00d4ff;
  background: rgba(0,212,255,0.1);
  transform: translateY(-2px);
}

.ls-level-btn.locked {
  opacity: 0.3;
  cursor: not-allowed;
}

.ls-level-num {
  font-size: 28px;
  font-weight: 700;
  line-height: 1;
}

.ls-level-stars {
  font-size: 16px;
  letter-spacing: 2px;
}

.ls-level-stars .star {
  color: #555;
  transition: color 0.2s;
}

.ls-level-stars .star.earned {
  color: #ffd700;
  text-shadow: 0 0 6px rgba(255,215,0,0.5);
}

.ls-back-btn {
  padding: 12px 36px;
  font-size: 16px;
  font-weight: 600;
  border: 1px solid rgba(255, 255, 255, 0.25);
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.05);
  color: #b9c3e6;
  cursor: pointer;
  transition: all 0.2s;
  font-family: inherit;
}

.ls-back-btn:hover {
  border-color: #00d4ff;
  color: #fff;
}

/* Responsive */
@media (max-width: 820px) {
  #game-container { max-width: 100vw; }
  canvas { max-width: 100vw; height: auto; }
  #hud { font-size: 14px; padding: 8px 12px; }
  #overlay h1 { font-size: 32px; }
  #overlay p { font-size: 16px; }
  .ls-title { font-size: 28px; }
  .ls-level-btn { width: 60px; height: 60px; }
  .ls-level-num { font-size: 20px; }
  .ls-level-stars { font-size: 12px; }
  .ls-tab { padding: 8px 14px; font-size: 13px; }
  #level-select { padding: 16px 10px; }
}

@media (max-width: 520px), (max-height: 700px) {
  #overlay h1 { font-size: 28px; margin-bottom: 4px; }
  #overlay p { font-size: 14px; margin-bottom: 4px; }
  #overlay .how-to-play { margin: 4px 0 !important; font-size: 12px !important; line-height: 1.45 !important; }
  #overlay button, #overlay-btn-secondary { padding: 10px 28px; font-size: 16px; margin: 4px; }
  .ls-title { margin-bottom: 12px; }
  .ls-world-tabs, .ls-levels { margin-bottom: 14px; }
}

@media (max-width: 500px), (max-height: 500px) {
  #overlay, #level-select { position: fixed; top: var(--gp-header-h, 48px); right: 0; bottom: 0; left: 0; z-index: 900; border-radius: 0; width: auto; height: auto; }
}

@media (orientation: landscape) and (max-height: 500px) {
  #overlay:not(.hidden) { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); column-gap: 24px; align-items: center; align-content: center; justify-items: center; width: auto; padding-left: max(12px, calc((100% - 780px) / 2)); padding-right: max(12px, calc((100% - 780px) / 2)); }
  #overlay:not(.hidden) > * { grid-column: 2; }
  #overlay:not(.hidden) > .how-to-play { grid-column: 1; grid-row: 1 / span 6; margin: 0; max-width: 340px; width: 100%; }
}

@media (pointer: coarse) and (min-width: 700px) and (min-height: 700px) {
  canvas {
    width: min(980px, 100vw, max(240px, calc((100vh - var(--gp-header-h, 80px) - 88px) * 4 / 3)));
    width: min(980px, 100vw, max(240px, calc((100dvh - var(--gp-header-h, 80px) - 88px) * 4 / 3)));
  }
}

.how-to-play { max-width: 380px; text-align: left; margin: 16px 0; padding: 14px 18px; background: rgba(255,255,255,0.05); border: 1px solid rgba(140,180,255,0.16); border-radius: 12px; font-size: 13px; line-height: 1.7; color: #b9c3e6; }
.how-to-title { font-size: 11px; font-weight: 700; letter-spacing: 2px; color: #7f8bb3; margin-bottom: 8px; text-transform: uppercase; }

[data-theme="light"] html,
[data-theme="light"] body { background: var(--gp-page-grad) fixed; color: var(--gp-ink); }
[data-theme="light"] #hud { background: var(--gp-surface); color: var(--gp-ink); box-shadow: inset 0 0 0 1px var(--gp-line), var(--gp-shadow); }
[data-theme="light"] #score { color: #0a84b8; }
[data-theme="light"] #level { color: #b7791f; }
[data-theme="light"] #overlay { background: var(--gp-overlay); color: var(--gp-ink); }
[data-theme="light"] #overlay p { color: var(--gp-ink-2); }
[data-theme="light"] #overlay-btn-secondary { background: #e5e7f1; color: var(--gp-ink); }
[data-theme="light"] #highscores h2, [data-theme="light"] #score-list li:first-child { color: #b7791f; }
[data-theme="light"] #score-list li { color: var(--gp-ink-2); }
[data-theme="light"] #score-list li:nth-child(2) { color: #6b7280; }
[data-theme="light"] #score-list li:nth-child(3) { color: #a16207; }
[data-theme="light"] #level-select { background: rgba(250, 248, 255, 0.96); color: var(--gp-ink); }
[data-theme="light"] .ls-title, [data-theme="light"] .ls-tab.active { color: #0a84b8; }
[data-theme="light"] .ls-tab, [data-theme="light"] .ls-back-btn { color: var(--gp-ink-2); }
[data-theme="light"] .ls-tab:hover:not([disabled]), [data-theme="light"] .ls-back-btn:hover { color: var(--gp-ink); }
[data-theme="light"] .ls-level-stars .star.earned { color: #b7791f; }
[data-theme="light"] #overlay-title { filter: brightness(0.72) saturate(1.3); text-shadow: none; }
[data-theme="light"] .how-to-play { background: rgba(31, 27, 69, 0.05); color: var(--gp-ink-2); }
[data-theme="light"] .how-to-title { color: var(--gp-ink-3); }
[data-theme="light"] .how-to-play .pu, [data-theme="light"] .combo-tip { filter: brightness(0.72) saturate(1.3); }
[data-theme="light"] #precision-btn { filter: brightness(0.72) saturate(1.3); }
[data-theme="light"] .ls-tab, [data-theme="light"] .ls-level-btn, [data-theme="light"] .ls-back-btn { background: var(--gp-surface); border-color: var(--gp-line); }
[data-theme="light"] .ls-level-btn { color: var(--gp-ink); }

.gp-btn-music.off { opacity: .4; }
