:root {
  --bg-deep: #070B19;
  --bg-panel: rgba(12, 19, 40, 0.88);
  --bg-card: rgba(10, 16, 35, 0.94);
  --border-glow: rgba(0, 240, 255, 0.28);
  --neon-red: #FF2A55;
  --neon-green: #00FF88;
  --neon-cyan: #00F0FF;
  --neon-gold: #FFD700;
  --text-main: #F3F7FF;
  --text-muted: #94A8CE;
  --font-display: 'Trebuchet MS', 'Segoe UI', system-ui, -apple-system, sans-serif;
  --font-mono: ui-monospace, 'SFMono-Regular', Menlo, Monaco, Consolas, monospace;
}

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

html, body {
  width: 100%;
  height: 100%;
  background:
    radial-gradient(circle at 18% 12%, rgba(255, 42, 85, 0.12), transparent 36%),
    radial-gradient(circle at 82% 18%, rgba(0, 255, 136, 0.10), transparent 34%),
    radial-gradient(circle at 50% 95%, rgba(0, 240, 255, 0.10), transparent 40%),
    var(--bg-deep);
  color: var(--text-main);
  font-family: var(--font-display);
  overflow: hidden;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
}

.arcade-shell {
  width: 100%;
  height: 100dvh;
  max-width: 820px;
  margin: 0 auto;
  padding: 10px 12px 12px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

/* HUD Bar */
.hud-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 8px 12px;
  background: var(--bg-panel);
  border: 1px solid var(--border-glow);
  border-radius: 12px;
  box-shadow: 0 0 18px rgba(0, 240, 255, 0.10), inset 0 1px 0 rgba(255, 255, 255, 0.06);
  flex-shrink: 0;
}

.hud-brand {
  display: flex;
  flex-direction: column;
  line-height: 1.05;
}

.brand-title {
  font-size: 1.05rem;
  font-weight: 900;
  letter-spacing: 1.4px;
  background: linear-gradient(90deg, var(--neon-red), var(--neon-gold), var(--neon-green));
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  text-shadow: 0 0 16px rgba(255, 215, 0, 0.25);
}

.brand-sub {
  font-size: 0.62rem;
  letter-spacing: 2px;
  color: var(--neon-cyan);
  opacity: 0.85;
}

.hud-stats {
  display: flex;
  align-items: center;
  gap: 14px;
}

.stat-box {
  display: flex;
  flex-direction: column;
  align-items: center;
  min-width: 58px;
}

.stat-label {
  font-size: 0.62rem;
  letter-spacing: 1.2px;
  color: var(--text-muted);
  font-weight: 700;
}

.stat-value {
  font-family: var(--font-mono);
  font-size: 1.1rem;
  font-weight: 800;
  color: var(--text-main);
  text-shadow: 0 0 10px rgba(255, 255, 255, 0.2);
}

.stat-gold {
  color: var(--neon-gold);
  text-shadow: 0 0 10px rgba(255, 215, 0, 0.4);
}

.stat-cyan {
  color: var(--neon-cyan);
  text-shadow: 0 0 10px rgba(0, 240, 255, 0.4);
}

.stat-level {
  min-width: 74px;
}

.level-readout {
  display: inline-flex;
  align-items: center;
  gap: 5px;
}

.level-tier {
  font-size: 0.56rem;
  font-weight: 800;
  letter-spacing: 0.8px;
  padding: 2px 5px;
  border-radius: 999px;
  border: 1px solid currentColor;
  line-height: 1.1;
}

.tier-easy {
  color: var(--neon-green);
  background: rgba(0, 255, 136, 0.12);
}

.tier-medium {
  color: var(--neon-cyan);
  background: rgba(0, 240, 255, 0.12);
}

.tier-hard {
  color: var(--neon-gold);
  background: rgba(255, 215, 0, 0.14);
}

.tier-extreme {
  color: var(--neon-red);
  background: rgba(255, 42, 85, 0.16);
}

.level-bump {
  animation: levelBump 0.55s ease-out;
}

@keyframes levelBump {
  0% { transform: scale(1); }
  35% { transform: scale(1.22); filter: brightness(1.35); }
  100% { transform: scale(1); }
}

.stat-lives {
  min-width: 96px;
}

#livesCanvas {
  display: block;
  width: 96px;
  height: 24px;
}

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

.icon-btn {
  width: 36px;
  height: 36px;
  border-radius: 9px;
  border: 1px solid rgba(0, 240, 255, 0.35);
  background: rgba(15, 25, 52, 0.9);
  color: var(--text-main);
  font-size: 1rem;
  cursor: pointer;
  display: grid;
  place-items: center;
  transition: transform 0.12s ease, border-color 0.15s ease, box-shadow 0.15s ease;
}

.icon-btn:hover {
  border-color: var(--neon-gold);
  box-shadow: 0 0 12px rgba(255, 215, 0, 0.35);
}

.icon-btn:active {
  transform: scale(0.94);
}

/* Legend Bar */
.legend-bar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: center;
  gap: 8px 16px;
  padding: 5px 10px;
  background: rgba(10, 16, 35, 0.72);
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 10px;
  font-size: 0.76rem;
  color: var(--text-muted);
  flex-shrink: 0;
}

.legend-item {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  white-space: nowrap;
}

.legend-item strong {
  color: var(--neon-gold);
  font-family: var(--font-mono);
}

.legend-icon {
  width: 20px;
  height: 20px;
  display: block;
}

.lucia-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--neon-cyan);
  box-shadow: 0 0 8px var(--neon-cyan);
  display: inline-block;
}

/* Main Stage */
.stage-wrap {
  flex: 1 1 auto;
  min-height: 0;
  display: flex;
  align-items: center;
  justify-content: center;
}

.canvas-frame {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  max-width: 100%;
  max-height: 100%;
  border-radius: 14px;
  padding: 4px;
  background: linear-gradient(135deg, rgba(255, 42, 85, 0.35), rgba(0, 240, 255, 0.35), rgba(0, 255, 136, 0.35));
  box-shadow:
    0 0 32px rgba(0, 240, 255, 0.16),
    0 14px 40px rgba(0, 0, 0, 0.55);
}

#gameCanvas {
  display: block;
  border-radius: 11px;
  background: #070B19;
  touch-action: none;
}

/* Active Power-Up Status Pills */
.status-pills {
  position: absolute;
  top: 12px;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  pointer-events: none;
  z-index: 5;
}

.lucia-pill,
.freeze-pill {
  padding: 4px 12px;
  border-radius: 999px;
  background: rgba(10, 16, 35, 0.92);
  font-size: 0.78rem;
  font-weight: 800;
  letter-spacing: 0.8px;
  white-space: nowrap;
}

.lucia-pill {
  border: 1px solid var(--neon-gold);
  color: var(--neon-gold);
  box-shadow: 0 0 16px rgba(255, 215, 0, 0.45);
}

.freeze-pill {
  border: 1px solid var(--neon-cyan);
  color: #B8F6FF;
  box-shadow: 0 0 16px rgba(0, 240, 255, 0.5);
}

.lucia-pill span,
.freeze-pill span {
  font-family: var(--font-mono);
  margin-left: 4px;
  color: #FFF;
}

/* Score Level-Up Toast */
.level-toast {
  position: absolute;
  bottom: 14px;
  left: 50%;
  transform: translateX(-50%);
  padding: 6px 14px;
  border-radius: 999px;
  background: rgba(10, 18, 40, 0.94);
  border: 1.5px solid var(--neon-cyan);
  color: var(--text-main);
  font-size: 0.8rem;
  font-weight: 800;
  letter-spacing: 0.6px;
  box-shadow: 0 0 20px rgba(0, 240, 255, 0.4);
  pointer-events: none;
  white-space: nowrap;
  z-index: 6;
  animation: toastPop 0.25s ease-out;
}

@keyframes toastPop {
  from { opacity: 0; transform: translate(-50%, 8px) scale(0.95); }
  to { opacity: 1; transform: translate(-50%, 0) scale(1); }
}

/* Level-Up Banner */
.level-banner {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  pointer-events: none;
  z-index: 8;
  background: rgba(7, 11, 25, 0.42);
  border-radius: 11px;
}

.level-banner-inner {
  text-align: center;
  padding: 18px 30px;
  border-radius: 14px;
  background: rgba(10, 18, 40, 0.95);
  border: 2px solid var(--neon-green);
  box-shadow: 0 0 30px rgba(0, 255, 136, 0.45);
  animation: popIn 0.3s ease-out;
}

.level-banner-tag {
  display: inline-block;
  font-size: 0.75rem;
  font-weight: 800;
  letter-spacing: 2px;
  color: var(--neon-gold);
  margin-bottom: 4px;
}

.level-banner-inner h2 {
  font-size: 2rem;
  color: var(--neon-green);
  text-shadow: 0 0 14px rgba(0, 255, 136, 0.6);
}

.level-banner-inner p {
  margin-top: 4px;
  font-size: 0.88rem;
  color: var(--text-main);
}

/* Modal Overlays */
.modal-overlay {
  position: absolute;
  inset: 4px;
  border-radius: 11px;
  background: rgba(5, 9, 22, 0.82);
  backdrop-filter: blur(5px);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  z-index: 10;
}

.modal-card {
  width: 100%;
  max-width: 380px;
  background: var(--bg-card);
  border: 1.5px solid rgba(0, 240, 255, 0.45);
  border-radius: 16px;
  padding: 22px 22px 24px;
  text-align: center;
  box-shadow:
    0 0 32px rgba(0, 240, 255, 0.18),
    0 0 60px rgba(255, 42, 85, 0.12);
  animation: popIn 0.25s ease-out;
}

.modal-compact {
  max-width: 320px;
}

.modal-lights {
  display: flex;
  justify-content: center;
  gap: 10px;
  margin-bottom: 12px;
}

.bulb {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  animation: twinkle 1.6s infinite alternate;
}

.b-red { background: var(--neon-red); box-shadow: 0 0 10px var(--neon-red); }
.b-green { background: var(--neon-green); box-shadow: 0 0 10px var(--neon-green); animation-delay: 0.3s; }
.b-cyan { background: var(--neon-cyan); box-shadow: 0 0 10px var(--neon-cyan); animation-delay: 0.6s; }
.b-gold { background: var(--neon-gold); box-shadow: 0 0 10px var(--neon-gold); animation-delay: 0.9s; }

.modal-title {
  font-size: 1.8rem;
  font-weight: 900;
  letter-spacing: 2px;
  color: var(--neon-gold);
  text-shadow: 0 0 16px rgba(255, 215, 0, 0.5);
  margin-bottom: 8px;
}

.title-red {
  color: var(--neon-red);
  text-shadow: 0 0 16px rgba(255, 42, 85, 0.55);
}

.modal-subtitle {
  font-size: 0.9rem;
  line-height: 1.45;
  color: var(--text-muted);
  margin-bottom: 14px;
}

.modal-tips {
  background: rgba(15, 25, 52, 0.72);
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 10px;
  padding: 10px 12px;
  margin-bottom: 18px;
  font-size: 0.8rem;
  line-height: 1.65;
  color: #C7D6F2;
}

.tip-highlight {
  margin-top: 4px;
  color: var(--neon-gold);
}

kbd {
  display: inline-block;
  padding: 1px 5px;
  margin: 0 1px;
  border-radius: 4px;
  background: rgba(255, 255, 255, 0.12);
  border: 1px solid rgba(255, 255, 255, 0.25);
  font-family: var(--font-mono);
  font-size: 0.74rem;
  color: #FFF;
}

.primary-btn,
.secondary-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 11px 24px;
  border-radius: 10px;
  font-family: var(--font-display);
  font-size: 0.98rem;
  font-weight: 800;
  letter-spacing: 0.8px;
  cursor: pointer;
  border: none;
  transition: transform 0.12s ease, box-shadow 0.15s ease, filter 0.15s ease;
}

.primary-btn {
  background: linear-gradient(135deg, #FF2A55, #D91642);
  color: #FFF;
  box-shadow: 0 0 18px rgba(255, 42, 85, 0.45), inset 0 1px 0 rgba(255, 255, 255, 0.25);
}

.primary-btn:hover {
  filter: brightness(1.1);
  box-shadow: 0 0 24px rgba(255, 42, 85, 0.65);
}

.primary-btn:active {
  transform: scale(0.96);
}

.secondary-btn {
  background: rgba(20, 32, 64, 0.9);
  color: var(--text-main);
  border: 1px solid rgba(0, 240, 255, 0.35);
}

.secondary-btn:hover {
  border-color: var(--neon-cyan);
  box-shadow: 0 0 14px rgba(0, 240, 255, 0.3);
}

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

.record-badge {
  display: inline-block;
  margin-bottom: 12px;
  padding: 4px 12px;
  border-radius: 999px;
  background: rgba(255, 215, 0, 0.16);
  border: 1px solid var(--neon-gold);
  color: var(--neon-gold);
  font-size: 0.78rem;
  font-weight: 800;
  letter-spacing: 1px;
}

.gameover-stats {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  margin-bottom: 18px;
}

.go-stat {
  background: rgba(15, 25, 52, 0.78);
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 10px;
  padding: 10px 6px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.go-stat span {
  font-size: 0.62rem;
  letter-spacing: 1px;
  color: var(--text-muted);
}

.go-stat strong {
  font-family: var(--font-mono);
  font-size: 1.15rem;
}

.hidden {
  display: none !important;
}

/* Mobile Touch D-Pad */
.touch-controls {
  display: none;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  flex-shrink: 0;
  padding-top: 2px;
}

.dpad-mid {
  display: flex;
  gap: 10px;
}

.dpad-btn {
  width: 52px;
  height: 44px;
  border-radius: 10px;
  border: 1px solid rgba(0, 240, 255, 0.35);
  background: rgba(12, 22, 48, 0.9);
  color: var(--text-main);
  font-size: 1.05rem;
  display: grid;
  place-items: center;
  cursor: pointer;
  touch-action: manipulation;
}

.dpad-btn:active {
  background: rgba(0, 240, 255, 0.22);
  border-color: var(--neon-gold);
}

@keyframes popIn {
  from { opacity: 0; transform: scale(0.92); }
  to { opacity: 1; transform: scale(1); }
}

@keyframes twinkle {
  from { opacity: 0.45; transform: scale(0.88); }
  to { opacity: 1; transform: scale(1.12); }
}

/* Responsive adjustments */
@media (max-width: 680px) {
  .arcade-shell {
    padding: 6px 8px 8px;
    gap: 6px;
  }

  .hud-bar {
    padding: 6px 8px;
    gap: 6px;
  }

  .hud-brand {
    display: none;
  }

  .hud-stats {
    gap: 8px;
  }

  .stat-box {
    min-width: 46px;
  }

  .stat-level {
    min-width: 60px;
  }

  .level-tier {
    font-size: 0.5rem;
    padding: 1px 4px;
  }

  .stat-value {
    font-size: 0.95rem;
  }

  .stat-lives {
    min-width: 78px;
  }

  #livesCanvas {
    width: 78px;
    height: 20px;
  }

  .legend-bar {
    font-size: 0.68rem;
    gap: 4px 10px;
    padding: 4px 6px;
  }

  .legend-icon {
    width: 16px;
    height: 16px;
  }

  .icon-btn {
    width: 32px;
    height: 32px;
    font-size: 0.9rem;
  }
}

@media (hover: none) and (pointer: coarse), (max-width: 600px) {
  .touch-controls {
    display: flex;
  }
}
