:root {
  --bg-color: #0b0f19;
  --panel-bg: rgba(17, 24, 39, 0.85);
  --border-neon: #38bdf8;
  --neon-pink: #ec4899;
  --neon-purple: #a855f7;
  --neon-yellow: #facc15;
  --neon-green: #22c55e;
  --text-main: #f8fafc;
  --text-sub: #94a3b8;
  --hud-font: 'JetBrains Mono', 'Outfit', monospace;
}

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

body, html {
  width: 100%;
  height: 100%;
  height: 100svh;
  height: 100dvh;
  margin: 0;
  padding: 0;
  overflow: hidden;
  background-color: var(--bg-color);
  font-family: 'Outfit', 'M PLUS 1p', sans-serif;
  color: var(--text-main);
  touch-action: none;
}

#game-wrapper {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  width: 100%;
  width: 100dvw;
  height: 100%;
  height: 100svh;
  height: 100dvh;
  display: flex;
  justify-content: center;
  align-items: center;
  padding: max(env(safe-area-inset-top, 0px), 4px) max(env(safe-area-inset-right, 0px), 4px) max(env(safe-area-inset-bottom, 0px), 6px) max(env(safe-area-inset-left, 0px), 4px);
  box-sizing: border-box;
  background: radial-gradient(circle at 50% 30%, #1e1b4b 0%, #07090e 100%);
  overflow: hidden;
}

#canvas-container {
  position: relative;
  aspect-ratio: 450 / 800;

  /* Fallback for older browsers without svh/dvh */
  height: min(calc(100vh - 16px), calc((100vw - 12px) * 800 / 450));
  width: min(calc((100vh - 16px) * 450 / 800), calc(100vw - 12px));

  /* Modern mobile viewport: 100svh guarantees canvas fits when mobile browser bars are visible */
  height: min(calc(100svh - env(safe-area-inset-top, 0px) - env(safe-area-inset-bottom, 0px) - 14px), calc((100dvw - 12px) * 800 / 450));
  width: min(calc((100svh - env(safe-area-inset-top, 0px) - env(safe-area-inset-bottom, 0px) - 14px) * 450 / 800), calc(100dvw - 12px));

  max-height: 960px;
  max-width: 540px;
  box-shadow: 0 0 50px rgba(56, 189, 248, 0.2), inset 0 0 20px rgba(0, 0, 0, 0.8);
  border-radius: 16px;
  overflow: hidden;
  background: #030712;
  border: 2px solid rgba(56, 189, 248, 0.3);
}

canvas#game-canvas {
  width: 100%;
  height: 100%;
  display: block;
  object-fit: contain;
}

/* HUD Overlay */
.hud-overlay {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  padding: 12px;
}

.top-bar {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.exp-bar-container {
  width: 100%;
  height: 12px;
  background: rgba(15, 23, 42, 0.8);
  border: 1px solid rgba(168, 85, 247, 0.5);
  border-radius: 6px;
  overflow: hidden;
  position: relative;
  box-shadow: 0 0 10px rgba(168, 85, 247, 0.3);
}

.exp-bar-fill {
  width: 0%;
  height: 100%;
  background: linear-gradient(90deg, #a855f7, #38bdf8);
  transition: width 0.15s ease-out;
  box-shadow: 0 0 8px #38bdf8;
}

.stats-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.stat-chip {
  background: rgba(15, 23, 42, 0.85);
  border: 1px solid rgba(255, 255, 255, 0.15);
  border-radius: 20px;
  padding: 4px 10px;
  font-size: 13px;
  font-family: var(--hud-font);
  font-weight: 700;
  display: flex;
  align-items: center;
  gap: 5px;
  box-shadow: 0 2px 8px rgba(0,0,0,0.5);
  backdrop-filter: blur(4px);
}

.chip-level {
  background: linear-gradient(135deg, #a855f7, #6366f1);
  color: #fff;
  border: none;
}

.chip-hp {
  border-color: rgba(239, 68, 68, 0.5);
  color: #f87171;
}

.chip-score {
  border-color: rgba(250, 204, 21, 0.5);
  color: #facc15;
}

/* Touch Controls / 3-Zone On-Screen Guides (Left 35% | Center 30% Tilt | Right 35%) */
.touch-controls {
  position: absolute;
  bottom: 0;
  left: 0;
  width: 100%;
  height: 120px;
  display: flex;
  pointer-events: none; /* Touches seamlessly pass to canvas-container */
  z-index: 10;
  user-select: none;
  -webkit-user-select: none;
  -webkit-tap-highlight-color: transparent;
}

.touch-zone {
  height: 100%;
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
  align-items: center;
  padding-bottom: 14px;
  background: transparent !important; /* No blue or colored background rectangles */
  transition: opacity 0.1s ease;
  user-select: none;
  -webkit-user-select: none;
  -webkit-tap-highlight-color: transparent;
}

.touch-zone.left {
  flex: 0.35;
  border-right: 1px dashed rgba(255, 255, 255, 0.05);
}

.touch-zone.center {
  flex: 0.30;
  justify-content: flex-end;
  border-right: 1px dashed rgba(255, 255, 255, 0.05);
}

.touch-zone.right {
  flex: 0.35;
}

/* Strictly ensure no rectangular background fill on active */
.touch-zone.active {
  background: transparent !important;
}

.touch-hint-label {
  color: rgba(255, 255, 255, 0.28);
  font-size: 11px;
  font-weight: 700;
  font-family: var(--hud-font);
  letter-spacing: 1.5px;
  pointer-events: none;
  transition: color 0.1s ease, text-shadow 0.1s ease, transform 0.1s ease;
}

.touch-zone.left.active .touch-hint-label,
.touch-zone.right.active .touch-hint-label {
  color: #38bdf8;
  text-shadow: 0 0 10px #38bdf8;
  transform: translateY(-2px);
}

.tilt-center-btn {
  background: rgba(236, 72, 153, 0.18);
  border: 1.5px solid rgba(236, 72, 153, 0.6);
  color: #f472b6;
  font-size: 11px;
  font-weight: 800;
  font-family: var(--hud-font);
  padding: 6px 14px;
  border-radius: 18px;
  pointer-events: none; /* Touches handled by unified canvas listener */
  box-shadow: 0 0 10px rgba(236, 72, 153, 0.25);
  transition: transform 0.1s ease, background 0.1s ease, box-shadow 0.1s ease;
  user-select: none;
  -webkit-user-select: none;
  -webkit-tap-highlight-color: transparent;
  margin-bottom: 4px;
}

.tilt-center-btn.active,
.touch-zone.center.active .tilt-center-btn {
  background: rgba(236, 72, 153, 0.55);
  border-color: #f472b6;
  box-shadow: 0 0 18px rgba(236, 72, 153, 0.8);
  transform: scale(0.94);
}

/* Modals (Level Up / Game Over / Start) */
.modal-overlay {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(3, 7, 18, 0.88);
  backdrop-filter: blur(8px);
  display: flex;
  justify-content: center;
  align-items: center;
  z-index: 100;
  opacity: 1;
  transition: opacity 0.25s ease;
  pointer-events: auto;
  touch-action: pan-y;
  padding: 12px;
}

.modal-overlay.hidden {
  opacity: 0;
  pointer-events: none;
}

.modal-card {
  width: 100%;
  max-width: 380px;
  max-height: 92%;
  overflow-y: auto;
  overscroll-behavior: contain;
  touch-action: pan-y;
  -webkit-overflow-scrolling: touch;
  background: #0f172a;
  border: 2px solid var(--border-neon);
  border-radius: 20px;
  padding: 16px 18px;
  box-shadow: 0 0 30px rgba(56, 189, 248, 0.3), inset 0 0 15px rgba(255, 255, 255, 0.05);
  display: flex;
  flex-direction: column;
  gap: 10px;
  text-align: center;
}

/* Custom sleek scrollbar for modal-card */
.modal-card::-webkit-scrollbar {
  width: 5px;
}
.modal-card::-webkit-scrollbar-thumb {
  background: rgba(56, 189, 248, 0.4);
  border-radius: 10px;
}

.modal-title {
  font-size: 24px;
  font-weight: 800;
  color: #fff;
  text-transform: uppercase;
  letter-spacing: 1.5px;
  text-shadow: 0 0 12px var(--border-neon);
}

.modal-subtitle {
  font-size: 13px;
  color: var(--text-sub);
}

.upgrade-options-list {
  display: flex;
  flex-direction: column;
  gap: 12px;
  margin-top: 8px;
}

.upgrade-card {
  background: rgba(30, 41, 59, 0.7);
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 12px;
  padding: 14px 16px;
  text-align: left;
  cursor: pointer;
  transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
  display: flex;
  align-items: center;
  gap: 14px;
}

.upgrade-card:hover, .upgrade-card:active {
  border-color: var(--border-neon);
  background: rgba(56, 189, 248, 0.15);
  transform: translateY(-2px);
  box-shadow: 0 0 15px rgba(56, 189, 248, 0.4);
}

.upgrade-icon {
  font-size: 28px;
  min-width: 40px;
  text-align: center;
}

.upgrade-content {
  display: flex;
  flex-direction: column;
  gap: 3px;
}

.upgrade-name {
  font-weight: 700;
  font-size: 15px;
  color: #fff;
}

.upgrade-desc {
  font-size: 12px;
  color: var(--text-sub);
  line-height: 1.3;
}

.upgrade-tier {
  font-size: 10px;
  font-family: var(--hud-font);
  color: var(--neon-yellow);
  margin-top: 2px;
}

.btn-primary {
  flex-shrink: 0;
  background: linear-gradient(135deg, #38bdf8, #6366f1);
  border: none;
  color: #fff;
  font-size: 15px;
  font-weight: 800;
  padding: 12px 28px;
  border-radius: 30px;
  cursor: pointer;
  letter-spacing: 1.5px;
  box-shadow: 0 0 20px rgba(56, 189, 248, 0.5);
  transition: transform 0.15s, box-shadow 0.15s;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
  animation: pulse-start-btn 2.2s infinite ease-in-out;
}

@keyframes pulse-start-btn {
  0%, 100% {
    box-shadow: 0 0 16px rgba(56, 189, 248, 0.45);
    transform: scale(1);
  }
  50% {
    box-shadow: 0 0 26px rgba(56, 189, 248, 0.8), 0 0 10px #6366f1;
    transform: scale(1.02);
  }
}

.btn-primary:hover {
  transform: scale(1.04);
  box-shadow: 0 0 30px rgba(56, 189, 248, 0.85);
}

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

.instruction-guide {
  background: rgba(15, 23, 42, 0.7);
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 12px;
  padding: 10px 12px;
  font-size: 12px;
  color: #cbd5e1;
  text-align: left;
  line-height: 1.45;
  display: flex;
  flex-direction: column;
  gap: 7px;
}

.instruction-guide strong {
  color: var(--border-neon);
}

.guide-row {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.guide-badge {
  font-size: 10px;
  font-weight: 800;
  padding: 2px 7px;
  border-radius: 6px;
  white-space: nowrap;
}

.guide-badge.mobile {
  background: rgba(56, 189, 248, 0.2);
  color: #38bdf8;
  border: 1px solid rgba(56, 189, 248, 0.4);
}

.guide-badge.pc {
  background: rgba(168, 85, 247, 0.2);
  color: #c084fc;
  border: 1px solid rgba(168, 85, 247, 0.4);
}

.guide-text {
  font-size: 11.5px;
  color: #e2e8f0;
}

.guide-tip {
  margin-top: 2px;
  font-size: 11px;
  color: var(--neon-yellow);
  background: rgba(250, 204, 21, 0.1);
  padding: 5px 8px;
  border-radius: 6px;
  border: 1px dashed rgba(250, 204, 21, 0.3);
  text-align: center;
}

@media (max-height: 680px), (max-width: 420px) {
  .modal-card {
    padding: 12px 14px;
    gap: 8px;
  }
  .modal-title {
    font-size: 18px;
    letter-spacing: 1px;
  }
  .modal-subtitle {
    font-size: 11px;
  }
  .instruction-guide {
    padding: 8px 10px;
    gap: 5px;
  }
  .guide-text {
    font-size: 11px;
  }
  .guide-tip {
    font-size: 10px;
    padding: 4px 6px;
  }
  .btn-primary {
    padding: 10px 22px;
    font-size: 14px;
  }
}

/* Sound / Options button */
.top-actions {
  display: flex;
  gap: 8px;
  pointer-events: auto;
}

.icon-btn {
  background: rgba(15, 23, 42, 0.7);
  border: 1px solid rgba(255, 255, 255, 0.2);
  color: #fff;
  width: 32px;
  height: 32px;
  border-radius: 50%;
  display: flex;
  justify-content: center;
  align-items: center;
  cursor: pointer;
  font-size: 14px;
}

.icon-btn:hover {
  border-color: var(--border-neon);
}

/* Combo / Multiplier floating notification */
.combo-banner {
  position: absolute;
  top: 75px;
  left: 50%;
  transform: translateX(-50%);
  font-family: var(--hud-font);
  font-size: 20px;
  font-weight: 800;
  color: var(--neon-yellow);
  text-shadow: 0 0 10px rgba(250, 204, 21, 0.8);
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.2s, transform 0.2s;
}

.combo-banner.visible {
  opacity: 1;
  transform: translateX(-50%) scale(1.1);
}
