:root {
  --bg-deep: #05060f;
  --bg-panel: rgba(12, 16, 36, 0.78);
  --border-glow: rgba(56, 232, 255, 0.28);
  --cyan: #38f2ff;
  --magenta: #ff2e93;
  --violet: #9d4edd;
  --gold: #ffd166;
  --lime: #4dff91;
  --danger: #ff4757;
  --text-main: #eef6ff;
  --text-dim: #8a9bc4;
}

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

html, body {
  width: 100%;
  height: 100vh;
  height: 100dvh;
  overflow: hidden;
  overscroll-behavior: none;
  background-color: var(--bg-deep);
  color: var(--text-main);
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'SF Pro Display', 'PingFang SC', 'Segoe UI', sans-serif;
}

/* Subtle cyberpunk ambient background */
.bg-grid {
  position: fixed;
  inset: 0;
  background:
    radial-gradient(circle at 20% 15%, rgba(56, 242, 255, 0.12), transparent 40%),
    radial-gradient(circle at 80% 85%, rgba(255, 46, 147, 0.12), transparent 45%),
    radial-gradient(circle at 50% 50%, rgba(157, 78, 221, 0.08), transparent 60%),
    linear-gradient(rgba(56, 242, 255, 0.04) 1px, transparent 1px),
    linear-gradient(90deg, rgba(56, 242, 255, 0.04) 1px, transparent 1px);
  background-size: 100% 100%, 100% 100%, 100% 100%, 48px 48px, 48px 48px;
  pointer-events: none;
  z-index: 0;
}

.bg-vignette {
  position: fixed;
  inset: 0;
  background: radial-gradient(circle at center, transparent 40%, rgba(2, 3, 10, 0.85) 100%);
  pointer-events: none;
  z-index: 0;
}

.app-shell {
  position: relative;
  z-index: 1;
  width: 100%;
  height: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: calc(12px + env(safe-area-inset-top)) calc(16px + env(safe-area-inset-right)) calc(14px + env(safe-area-inset-bottom)) calc(16px + env(safe-area-inset-left));
  gap: 10px;
}

/* HUD Bar */
.hud-bar {
  width: 100%;
  max-width: 1040px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 16px;
  background: var(--bg-panel);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  border: 1px solid var(--border-glow);
  border-radius: 16px;
  box-shadow:
    0 8px 32px rgba(0, 0, 0, 0.45),
    inset 0 1px 0 rgba(255, 255, 255, 0.08);
  flex-shrink: 0;
}

.hud-brand {
  display: flex;
  align-items: center;
  gap: 10px;
}

.logo-dot {
  width: 12px;
  height: 12px;
  border-radius: 50%;
  background: var(--cyan);
  box-shadow: 0 0 12px var(--cyan), 0 0 24px var(--magenta);
  animation: pulseDot 2s ease-in-out infinite;
}

@keyframes pulseDot {
  0%, 100% { transform: scale(1); opacity: 1; }
  50% { transform: scale(1.25); opacity: 0.75; }
}

.logo-text {
  display: flex;
  flex-direction: column;
  line-height: 1.05;
}

.logo-main {
  font-size: 14px;
  font-weight: 800;
  letter-spacing: 0.1em;
  white-space: nowrap;
  background: linear-gradient(90deg, #ffffff, var(--cyan), var(--magenta));
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}

.logo-sub {
  font-size: 9px;
  font-weight: 600;
  letter-spacing: 0.22em;
  white-space: nowrap;
  color: var(--text-dim);
}

.hud-metrics {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: nowrap;
  justify-content: center;
}

.metric-card {
  display: flex;
  flex-direction: column;
  align-items: center;
  min-width: 70px;
  padding: 4px 10px;
  border-radius: 10px;
  background: rgba(255, 255, 255, 0.03);
  border: 1px solid rgba(255, 255, 255, 0.06);
}

.metric-label {
  font-size: 9px;
  font-weight: 700;
  letter-spacing: 0.14em;
  color: var(--text-dim);
}

.metric-value {
  font-family: 'JetBrains Mono', 'SF Mono', 'Menlo', monospace;
  font-size: 16px;
  font-weight: 800;
  letter-spacing: 0.04em;
  color: #ffffff;
  text-shadow: 0 0 10px rgba(255, 255, 255, 0.35);
}

.metric-gold {
  color: var(--gold);
  text-shadow: 0 0 12px rgba(255, 209, 102, 0.45);
}

.metric-cyan {
  color: var(--cyan);
  text-shadow: 0 0 12px rgba(56, 242, 255, 0.5);
}

.metric-magenta {
  color: var(--magenta);
  text-shadow: 0 0 12px rgba(255, 46, 147, 0.55);
  transition: transform 0.12s ease;
}

.metric-pop {
  transform: scale(1.28);
}

.lives-card {
  min-width: 82px;
}

.lives-dots {
  display: flex;
  align-items: center;
  gap: 6px;
  height: 22px;
}

.life-orb {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: radial-gradient(circle at 35% 35%, #fff, var(--cyan));
  box-shadow: 0 0 8px var(--cyan), 0 0 14px rgba(56, 242, 255, 0.6);
  transition: all 0.25s ease;
}

.life-orb.lost {
  background: rgba(255, 255, 255, 0.12);
  box-shadow: none;
  transform: scale(0.75);
}

.hud-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

.icon-btn {
  position: relative;
  overflow: hidden;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  height: 36px;
  min-width: 36px;
  padding: 0 10px;
  border-radius: 10px;
  border: 1px solid rgba(255, 255, 255, 0.14);
  background: rgba(255, 255, 255, 0.05);
  color: var(--text-main);
  cursor: pointer;
  transition: all 0.18s ease;
}

.icon-btn:hover:not(:disabled) {
  border-color: var(--cyan);
  background: rgba(56, 242, 255, 0.14);
  box-shadow: 0 0 16px rgba(56, 242, 255, 0.28);
}

.icon-btn:disabled {
  opacity: 0.6;
  cursor: not-allowed;
}

#btn-nova {
  min-width: 108px;
  border-color: rgba(255, 46, 147, 0.35);
  background: rgba(255, 46, 147, 0.08);
}

#btn-nova.ready,
.touch-nova-btn.ready {
  opacity: 1 !important;
  cursor: pointer;
  border-color: var(--gold) !important;
  box-shadow: 0 0 20px rgba(255, 209, 102, 0.55), inset 0 0 12px rgba(255, 46, 147, 0.45);
  animation: novaPulse 1.1s ease-in-out infinite;
}

@keyframes novaPulse {
  0%, 100% { transform: scale(1); }
  50% { transform: scale(1.04); }
}

.nova-fill {
  position: absolute;
  left: 0;
  top: 0;
  bottom: 0;
  width: 0%;
  background: linear-gradient(90deg, rgba(157, 78, 221, 0.55), rgba(255, 46, 147, 0.7), rgba(255, 209, 102, 0.8));
  transition: width 0.2s ease;
  z-index: 0;
}

.nova-label {
  position: relative;
  z-index: 1;
  font-family: 'JetBrains Mono', 'SF Mono', monospace;
  font-size: 11px;
  font-weight: 800;
  letter-spacing: 0.08em;
}

.hidden {
  display: none !important;
}

/* Stage Container */
.stage-wrapper {
  flex: 1;
  width: 100%;
  max-width: 1040px;
  min-height: 0;
  display: flex;
  align-items: center;
  justify-content: center;
}

.canvas-frame {
  position: relative;
  width: 960px;
  height: 600px;
  max-width: 100%;
  max-height: 100%;
  border-radius: 18px;
  overflow: hidden;
  background: #060814;
  border: 1.5px solid rgba(56, 242, 255, 0.35);
  box-shadow:
    0 0 0 1px rgba(255, 46, 147, 0.14),
    0 20px 60px rgba(0, 0, 0, 0.72),
    0 0 40px rgba(56, 242, 255, 0.12);
  transition: border-color 0.3s ease, box-shadow 0.3s ease;
}

.canvas-frame.overdrive {
  border-color: rgba(255, 46, 147, 0.85);
  box-shadow:
    0 0 0 1px rgba(255, 209, 102, 0.5),
    0 20px 60px rgba(0, 0, 0, 0.75),
    0 0 55px rgba(255, 46, 147, 0.38);
}

#game-canvas {
  display: block;
  width: 100%;
  height: 100%;
  cursor: none;
  touch-action: none;
}

.canvas-frame.show-cursor #game-canvas {
  cursor: default;
}

/* Active Power-Up Floating Pills */
.powerup-hud {
  position: absolute;
  top: 10px;
  left: 12px;
  right: 12px;
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  pointer-events: none;
  z-index: 3;
}

.active-pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 3px 9px;
  border-radius: 999px;
  background: rgba(8, 12, 28, 0.8);
  border: 1px solid rgba(255, 255, 255, 0.2);
  backdrop-filter: blur(8px);
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.04em;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.4);
}

.pill-bar {
  width: 38px;
  height: 4px;
  border-radius: 99px;
  background: rgba(255, 255, 255, 0.15);
  overflow: hidden;
}

.pill-bar-fill {
  height: 100%;
  border-radius: 99px;
}

/* Overlays */
.overlay {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  overflow-y: auto;
  background: rgba(4, 6, 16, 0.8);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.22s ease;
  z-index: 10;
}

.overlay.active {
  opacity: 1;
  pointer-events: auto;
}

.overlay-card {
  width: 100%;
  max-width: 580px;
  padding: 20px 26px;
  border-radius: 20px;
  background: linear-gradient(160deg, rgba(16, 22, 48, 0.94), rgba(8, 10, 24, 0.97));
  border: 1px solid rgba(56, 242, 255, 0.35);
  box-shadow:
    0 24px 64px rgba(0, 0, 0, 0.7),
    0 0 40px rgba(56, 242, 255, 0.15),
    inset 0 1px 0 rgba(255, 255, 255, 0.12);
  text-align: center;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 11px;
}

.compact-card {
  max-width: 420px;
  padding: 28px 24px;
  gap: 16px;
}

.badge-pill {
  padding: 4px 12px;
  border-radius: 999px;
  font-size: 10px;
  font-weight: 800;
  letter-spacing: 0.22em;
  color: var(--cyan);
  background: rgba(56, 242, 255, 0.12);
  border: 1px solid rgba(56, 242, 255, 0.35);
}

.badge-success {
  color: var(--lime);
  background: rgba(77, 255, 145, 0.12);
  border-color: rgba(77, 255, 145, 0.4);
}

.badge-danger {
  color: var(--danger);
  background: rgba(255, 71, 87, 0.14);
  border-color: rgba(255, 71, 87, 0.42);
}

.hero-title {
  font-size: clamp(28px, 5vw, 48px);
  font-weight: 900;
  letter-spacing: 0.09em;
  line-height: 1.05;
  background: linear-gradient(100deg, #ffffff 10%, var(--cyan) 48%, var(--magenta) 88%);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  filter: drop-shadow(0 0 22px rgba(56, 242, 255, 0.4));
}

.hero-subtitle {
  font-size: 13px;
  letter-spacing: 0.12em;
  color: var(--text-dim);
}

.overlay-title {
  font-size: clamp(24px, 4vw, 32px);
  font-weight: 900;
  letter-spacing: 0.08em;
  color: #ffffff;
  text-shadow: 0 0 20px rgba(56, 242, 255, 0.4);
}

/* Level Selector */
.level-selector {
  width: 100%;
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-top: 2px;
}

.selector-label {
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.14em;
  color: var(--text-dim);
  text-transform: uppercase;
}

.level-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
}

.level-btn {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  padding: 8px 10px;
  border-radius: 10px;
  border: 1px solid rgba(255, 255, 255, 0.12);
  background: rgba(255, 255, 255, 0.04);
  color: var(--text-main);
  cursor: pointer;
  transition: all 0.16s ease;
  text-align: left;
}

.level-btn:hover {
  border-color: rgba(56, 242, 255, 0.55);
  background: rgba(56, 242, 255, 0.1);
}

.level-btn.selected {
  border-color: var(--cyan);
  background: linear-gradient(135deg, rgba(56, 242, 255, 0.2), rgba(255, 46, 147, 0.16));
  box-shadow: 0 0 18px rgba(56, 242, 255, 0.28);
}

.level-num {
  font-family: 'JetBrains Mono', monospace;
  font-size: 10px;
  font-weight: 800;
  color: var(--cyan);
}

.level-name {
  font-size: 12px;
  font-weight: 700;
  margin-top: 2px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  width: 100%;
}

/* Powerup Legend */
.powerup-legend {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 6px;
}

.legend-chip {
  font-size: 11px;
  font-weight: 700;
  padding: 3px 9px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid rgba(255, 255, 255, 0.12);
}

.chip-multi { color: #38f2ff; border-color: rgba(56, 242, 255, 0.4); }
.chip-wide { color: #4dff91; border-color: rgba(77, 255, 145, 0.4); }
.chip-laser { color: #ff2e93; border-color: rgba(255, 46, 147, 0.45); }
.chip-fire { color: #ff9f1c; border-color: rgba(255, 159, 28, 0.45); }
.chip-magnet { color: #c77dff; border-color: rgba(199, 125, 255, 0.45); }
.chip-shield { color: #4cc9f0; border-color: rgba(76, 201, 240, 0.45); }
.chip-slow { color: #ffd166; border-color: rgba(255, 209, 102, 0.45); }

/* Buttons */
.primary-btn {
  position: relative;
  overflow: hidden;
  padding: 13px 32px;
  border-radius: 12px;
  border: none;
  background: linear-gradient(100deg, #00d2ff, #ff2e93);
  color: #ffffff;
  font-size: 14px;
  font-weight: 800;
  letter-spacing: 0.1em;
  cursor: pointer;
  box-shadow: 0 8px 28px rgba(255, 46, 147, 0.42), 0 0 24px rgba(56, 242, 255, 0.32);
  transition: transform 0.15s ease, box-shadow 0.15s ease;
}

.primary-btn:hover {
  transform: translateY(-2px) scale(1.02);
  box-shadow: 0 12px 34px rgba(255, 46, 147, 0.55), 0 0 32px rgba(56, 242, 255, 0.48);
}

.primary-btn:active {
  transform: translateY(0) scale(0.98);
}

.secondary-btn {
  padding: 11px 22px;
  border-radius: 12px;
  border: 1px solid rgba(56, 242, 255, 0.45);
  background: rgba(56, 242, 255, 0.12);
  color: var(--cyan);
  font-size: 13px;
  font-weight: 700;
  letter-spacing: 0.06em;
  cursor: pointer;
  transition: all 0.16s ease;
}

.secondary-btn:hover {
  background: rgba(56, 242, 255, 0.22);
}

.ghost-btn {
  padding: 10px 18px;
  border-radius: 12px;
  border: 1px solid rgba(255, 255, 255, 0.14);
  background: transparent;
  color: var(--text-dim);
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.16s ease;
}

.ghost-btn:hover {
  color: #ffffff;
  border-color: rgba(255, 255, 255, 0.32);
}

.overlay-btn-row {
  display: flex;
  flex-direction: column;
  width: 100%;
  gap: 10px;
}

.clear-stats {
  width: 100%;
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(92px, 1fr));
  gap: 8px;
}

.stat-item {
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding: 10px 8px;
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid rgba(255, 255, 255, 0.08);
}

.stat-item span {
  font-size: 11px;
  color: var(--text-dim);
}

.stat-item strong {
  font-family: 'JetBrains Mono', monospace;
  font-size: 17px;
  color: var(--gold);
}

.controls-hint {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 12px;
  font-size: 11px;
  color: var(--text-dim);
  margin-top: 2px;
}

.controls-mobile {
  display: none;
}

kbd {
  display: inline-block;
  padding: 2px 6px;
  margin: 0 2px;
  border-radius: 5px;
  background: rgba(255, 255, 255, 0.08);
  border: 1px solid rgba(255, 255, 255, 0.16);
  color: var(--text-main);
  font-family: 'JetBrains Mono', monospace;
  font-size: 10px;
}

/* Mobile Anti-Occlusion Touch Control Deck (Hidden on Desktop) */
.mobile-deck {
  display: none;
  width: 100%;
  max-width: 560px;
  gap: 10px;
  align-items: stretch;
  flex-shrink: 0;
}

.touch-pad {
  position: relative;
  flex: 1;
  height: 64px;
  border-radius: 16px;
  background: linear-gradient(180deg, rgba(16, 24, 52, 0.85), rgba(8, 12, 28, 0.92));
  border: 1.5px solid rgba(56, 242, 255, 0.35);
  box-shadow:
    inset 0 2px 14px rgba(0, 0, 0, 0.55),
    0 6px 20px rgba(0, 0, 0, 0.4);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  touch-action: none;
  overflow: hidden;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

.touch-pad.active {
  border-color: var(--cyan);
  box-shadow:
    inset 0 2px 16px rgba(56, 242, 255, 0.2),
    0 0 22px rgba(56, 242, 255, 0.3);
}

.touch-pad-track {
  position: relative;
  width: 82%;
  height: 6px;
  border-radius: 99px;
  background: rgba(255, 255, 255, 0.1);
  margin-bottom: 6px;
}

.touch-pad-thumb {
  position: absolute;
  top: 50%;
  left: 50%;
  width: 44px;
  height: 12px;
  transform: translate(-50%, -50%);
  border-radius: 99px;
  background: linear-gradient(90deg, var(--cyan), #ffffff, var(--cyan));
  box-shadow: 0 0 14px var(--cyan);
  pointer-events: none;
}

.touch-pad-hint {
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.16em;
  color: rgba(138, 155, 196, 0.85);
  pointer-events: none;
}

.touch-actions {
  display: flex;
  gap: 8px;
}

.touch-action-btn {
  position: relative;
  overflow: hidden;
  width: 64px;
  height: 64px;
  border-radius: 16px;
  border: 1.5px solid rgba(56, 242, 255, 0.42);
  background: rgba(16, 24, 52, 0.88);
  color: #ffffff;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  cursor: pointer;
  touch-action: none;
  transition: transform 0.1s ease, border-color 0.18s ease, box-shadow 0.18s ease;
}

.touch-action-btn:active:not(:disabled) {
  transform: scale(0.94);
}

.touch-action-btn:disabled {
  opacity: 0.55;
}

.touch-fire-btn.laser-mode {
  border-color: var(--magenta);
  background: rgba(255, 46, 147, 0.18);
  box-shadow: 0 0 18px rgba(255, 46, 147, 0.4);
}

.touch-fire-btn.launch-ready {
  border-color: var(--cyan);
  background: rgba(56, 242, 255, 0.18);
  box-shadow: 0 0 18px rgba(56, 242, 255, 0.4);
}

.touch-nova-btn {
  border-color: rgba(255, 46, 147, 0.42);
  background: rgba(255, 46, 147, 0.1);
}

.touch-btn-icon {
  position: relative;
  z-index: 1;
  font-size: 18px;
  line-height: 1;
}

.touch-btn-text {
  position: relative;
  z-index: 1;
  font-family: 'JetBrains Mono', 'Inter', sans-serif;
  font-size: 10px;
  font-weight: 800;
  letter-spacing: 0.04em;
}

/* Responsive Breakpoints */
@media (max-width: 920px) {
  .hud-brand {
    display: none;
  }
}

/* Show mobile deck on touch devices or narrow screens */
@media (max-width: 768px), (pointer: coarse) and (max-width: 1024px) {
  .app-shell {
    padding: calc(8px + env(safe-area-inset-top)) calc(10px + env(safe-area-inset-right)) calc(10px + env(safe-area-inset-bottom)) calc(10px + env(safe-area-inset-left));
    gap: 8px;
  }

  .hud-bar {
    padding: 7px 10px;
    gap: 6px;
    border-radius: 14px;
  }

  .hud-metrics {
    gap: 5px;
    flex: 1;
    justify-content: flex-start;
  }

  .metric-card {
    min-width: 0;
    flex: 1;
    padding: 3px 5px;
    border-radius: 8px;
  }

  .metric-label {
    font-size: 8px;
    letter-spacing: 0.08em;
  }

  .metric-value {
    font-size: 13px;
  }

  .lives-card {
    min-width: 58px;
    flex: 0 0 auto;
  }

  .lives-dots {
    gap: 4px;
    height: 18px;
  }

  .life-orb {
    width: 8px;
    height: 8px;
  }

  .desktop-nova-btn {
    display: none;
  }

  .icon-btn {
    height: 34px;
    min-width: 34px;
    padding: 0 7px;
  }

  .mobile-deck {
    display: flex;
  }

  .controls-desktop {
    display: none;
  }

  .controls-mobile {
    display: flex;
  }

  .canvas-frame {
    border-radius: 14px;
  }

  .overlay {
    padding: 12px;
  }

  .overlay-card {
    padding: 16px 14px;
    gap: 10px;
    border-radius: 16px;
  }

  .hero-subtitle {
    font-size: 11px;
    letter-spacing: 0.06em;
  }

  .level-grid {
    grid-template-columns: repeat(2, 1fr);
    gap: 6px;
  }

  .level-btn {
    padding: 7px 8px;
  }

  .level-name {
    font-size: 11px;
  }

  .legend-chip {
    font-size: 10px;
    padding: 2px 7px;
  }

  .primary-btn {
    width: 100%;
    padding: 12px 18px;
    font-size: 13px;
  }
}

/* Extra compact phones (<= 410px) */
@media (max-width: 410px) {
  .metric-best-card {
    display: none;
  }
  .touch-pad {
    height: 58px;
  }
  .touch-action-btn {
    width: 58px;
    height: 58px;
  }
}
