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

body {
  background: #111827;
  color: #f9fafb;
  font-family: 'Fredoka', 'Nunito', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  touch-action: none;
}

#game-wrapper {
  position: relative;
  width: 100vw;
  height: 100vh;
  max-width: 1280px;
  max-height: 720px;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 20px 50px rgba(0, 0, 0, 0.6);
  border-radius: 16px;
  overflow: hidden;
  background: #000;
}

@media (min-aspect-ratio: 16/9) {
  #game-wrapper {
    height: 100vh;
    width: calc(100vh * (16 / 9));
  }
}

@media (max-aspect-ratio: 16/9) {
  #game-wrapper {
    width: 100vw;
    height: calc(100vw * (9 / 16));
  }
}

#gameCanvas {
  width: 100%;
  height: 100%;
  display: block;
  image-rendering: auto;
}

/* --- HUD OVERLAY --- */
#hud {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  padding: 16px 24px;
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  pointer-events: none;
  z-index: 10;
}

.hud-group {
  display: flex;
  gap: 16px;
  align-items: center;
}

.hud-card {
  background: rgba(17, 24, 39, 0.75);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  border: 2px solid rgba(255, 255, 255, 0.15);
  border-radius: 14px;
  padding: 8px 16px;
  display: flex;
  align-items: center;
  gap: 10px;
  box-shadow: 0 4px 15px rgba(0, 0, 0, 0.3);
  font-weight: 700;
}

.hud-label {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 1px;
  color: #9ca3af;
}

.hud-value {
  font-size: 22px;
  color: #fbbf24;
  text-shadow: 0 2px 4px rgba(0, 0, 0, 0.5);
  font-weight: 800;
}

.hearts-container {
  display: flex;
  gap: 4px;
}

.heart-icon {
  font-size: 24px;
  filter: drop-shadow(0 2px 4px rgba(0,0,0,0.4));
  transition: transform 0.2s cubic-bezier(0.34, 1.56, 0.64, 1);
}

.heart-lost {
  opacity: 0.25;
  filter: grayscale(1);
  transform: scale(0.8);
}

.combo-badge {
  background: linear-gradient(135deg, #f59e0b, #ef4444);
  color: #ffffff;
  padding: 6px 14px;
  border-radius: 20px;
  font-size: 14px;
  font-weight: 900;
  letter-spacing: 0.5px;
  box-shadow: 0 0 15px rgba(245, 158, 11, 0.6);
  opacity: 0;
  transform: scale(0.8);
  transition: opacity 0.2s, transform 0.2s;
}

.combo-badge.active {
  opacity: 1;
  transform: scale(1);
  animation: pulseCombo 0.8s infinite alternate ease-in-out;
}

@keyframes pulseCombo {
  from { transform: scale(1); }
  to { transform: scale(1.1); box-shadow: 0 0 25px rgba(239, 68, 68, 0.8); }
}

.hud-btn {
  pointer-events: auto;
  background: rgba(31, 41, 55, 0.8);
  border: 2px solid rgba(255, 255, 255, 0.2);
  color: #f3f4f6;
  width: 44px;
  height: 44px;
  border-radius: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  font-size: 18px;
  transition: all 0.15s ease;
  backdrop-filter: blur(6px);
}

.hud-btn:hover {
  background: rgba(55, 65, 81, 0.95);
  transform: translateY(-2px);
  border-color: #fbbf24;
}

.hud-btn:active {
  transform: translateY(1px);
}

/* --- OVERLAYS (START, GAMEOVER, PAUSE) --- */
.overlay-screen {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  background: rgba(15, 23, 42, 0.82);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  z-index: 50;
  padding: 24px;
  text-align: center;
  transition: opacity 0.3s ease;
}

.overlay-screen.hidden {
  display: none;
}

.game-title {
  font-size: clamp(36px, 7vw, 64px);
  font-weight: 900;
  text-transform: uppercase;
  letter-spacing: 2px;
  background: linear-gradient(135deg, #fde047 0%, #f97316 50%, #ec4899 100%);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  filter: drop-shadow(0 6px 12px rgba(0, 0, 0, 0.6));
  margin-bottom: 8px;
  line-height: 1.1;
}

.game-subtitle {
  font-size: clamp(14px, 2.5vw, 18px);
  color: #cbd5e1;
  max-width: 520px;
  margin-bottom: 24px;
  font-weight: 600;
  line-height: 1.5;
}

.mechanic-tip {
  background: rgba(245, 158, 11, 0.15);
  border: 1.5px dashed #f59e0b;
  border-radius: 12px;
  padding: 10px 18px;
  margin-bottom: 24px;
  color: #fef3c7;
  font-size: 14px;
  max-width: 460px;
  display: flex;
  align-items: center;
  gap: 10px;
}

.mechanic-tip span {
  font-size: 24px;
}

.btn-primary {
  pointer-events: auto;
  cursor: pointer;
  background: linear-gradient(135deg, #10b981 0%, #059669 100%);
  border: none;
  color: white;
  padding: 16px 42px;
  font-size: 20px;
  font-weight: 800;
  border-radius: 50px;
  letter-spacing: 1px;
  text-transform: uppercase;
  box-shadow: 0 8px 25px rgba(16, 185, 129, 0.5), inset 0 2px 0 rgba(255, 255, 255, 0.3);
  transition: all 0.2s cubic-bezier(0.34, 1.56, 0.64, 1);
  margin-bottom: 20px;
}

.btn-primary:hover {
  transform: scale(1.06) translateY(-2px);
  box-shadow: 0 12px 30px rgba(16, 185, 129, 0.7);
}

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

.controls-hint {
  display: flex;
  gap: 16px;
  justify-content: center;
  flex-wrap: wrap;
  font-size: 13px;
  color: #94a3b8;
  margin-top: 10px;
}

.key-badge {
  background: rgba(255, 255, 255, 0.1);
  border: 1px solid rgba(255, 255, 255, 0.2);
  border-radius: 6px;
  padding: 2px 8px;
  color: #f8fafc;
  font-weight: 700;
  display: inline-block;
}

/* --- STATS IN GAMEOVER --- */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 14px;
  margin-bottom: 24px;
  width: 100%;
  max-width: 480px;
}

.stat-box {
  background: rgba(30, 41, 59, 0.85);
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 14px;
  padding: 12px 14px;
  text-align: center;
}

.stat-box .stat-num {
  font-size: 24px;
  font-weight: 900;
  color: #38bdf8;
  margin-top: 4px;
}

.stat-box.highlight {
  border-color: #f59e0b;
  background: rgba(245, 158, 11, 0.15);
}

.stat-box.highlight .stat-num {
  color: #fde047;
}

/* --- TOUCH CONTROLS FOR MOBILE --- */
#touch-controls {
  position: absolute;
  bottom: 16px;
  left: 0;
  right: 0;
  padding: 0 24px;
  display: flex;
  justify-content: space-between;
  pointer-events: none;
  z-index: 20;
}

.touch-btn {
  pointer-events: auto;
  width: 80px;
  height: 80px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.2);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  border: 2px solid rgba(255, 255, 255, 0.4);
  color: white;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  font-size: 22px;
  font-weight: 800;
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.4);
  touch-action: manipulation;
  transition: transform 0.1s, background 0.1s;
}

.touch-btn span {
  font-size: 11px;
  letter-spacing: 0.5px;
  margin-top: 2px;
  text-transform: uppercase;
}

.touch-btn:active {
  transform: scale(0.9);
  background: rgba(255, 255, 255, 0.4);
}

#btn-touch-jump {
  background: rgba(16, 185, 129, 0.4);
  border-color: rgba(52, 211, 153, 0.8);
}

#btn-touch-slide {
  background: rgba(59, 130, 246, 0.4);
  border-color: rgba(96, 165, 250, 0.8);
}

@media (hover: hover) and (pointer: fine) {
  /* Hide touch buttons on desktop with mouse pointer */
  #touch-controls {
    display: none;
  }
}
