:root {
  --bg-gradient: linear-gradient(145deg, #ff8da1 0%, #ffb6c1 28%, #e0c3fc 65%, #8ec5fc 100%);
  --panel-bg: rgba(255, 255, 255, 0.92);
  --panel-border: #ffffff;
  --primary-color: #ff3366;
  --secondary-color: #ff9900;
  --bubble-blue: #0284c7;
  --bubble-purple: #8b5cf6;
  --bubble-green: #10b981;
  --gold-color: #f59e0b;
  --text-main: #1e1b4b;
  --text-dim: #64748b;
  --danger-orange: #ef4444;
  --danger-glow: rgba(239, 68, 68, 0.6);
  --radius-lg: 20px;
  --radius-md: 14px;
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  user-select: none;
  -webkit-user-select: none;
  touch-action: manipulation;
}

html, body {
  width: 100%;
  height: 100%;
  overflow: hidden;
  position: relative;
}

body {
  font-family: 'Fredoka', cursive, sans-serif;
  background: var(--bg-gradient);
  color: var(--text-main);
  display: flex;
  justify-content: center;
  align-items: center;
}

/* Background floating cheerful iridescent candy bubbles */
.bubbles-container {
  position: fixed;
  inset: 0;
  pointer-events: none;
  overflow: hidden;
  z-index: 0;
}

.bubble {
  position: absolute;
  border-radius: 50%;
  background: radial-gradient(circle at 35% 28%, rgba(255, 255, 255, 0.85) 0%, rgba(255, 255, 255, 0.4) 30%, rgba(224, 195, 252, 0.35) 60%, rgba(142, 197, 252, 0.25) 100%);
  border: 1.5px solid rgba(255, 255, 255, 0.7);
  box-shadow: inset 0 0 14px rgba(255, 255, 255, 0.8), 0 4px 20px rgba(255, 141, 161, 0.3);
  animation: floatBubble linear infinite;
}

.bubble-1 {
  width: 70px;
  height: 70px;
  left: 6%;
  bottom: -80px;
  animation-duration: 15s;
}

.bubble-2 {
  width: 120px;
  height: 120px;
  left: 68%;
  bottom: -130px;
  animation-duration: 20s;
  animation-delay: 2s;
}

.bubble-3 {
  width: 48px;
  height: 48px;
  left: 88%;
  bottom: -55px;
  animation-duration: 12s;
  animation-delay: 6s;
}

.bubble-4 {
  width: 90px;
  height: 90px;
  left: 28%;
  bottom: -95px;
  animation-duration: 18s;
  animation-delay: 8s;
}

.bubble-5 {
  width: 55px;
  height: 55px;
  left: 50%;
  bottom: -65px;
  animation-duration: 14s;
  animation-delay: 4s;
}

.bubble-6 {
  width: 100px;
  height: 100px;
  left: -20px;
  bottom: -110px;
  animation-duration: 22s;
  animation-delay: 1s;
}

@keyframes floatBubble {
  0% {
    transform: translateY(0) translateX(0) scale(0.9);
    opacity: 0;
  }
  15% {
    opacity: 0.85;
  }
  50% {
    transform: translateY(-50vh) translateX(25px) scale(1.05);
    opacity: 0.95;
  }
  85% {
    opacity: 0.85;
  }
  100% {
    transform: translateY(-110vh) translateX(-20px) scale(1.15);
    opacity: 0;
  }
}

/* Toast Notifications (Candy Pill Style) */
.toast-notification {
  position: fixed;
  top: 14px;
  left: 50%;
  transform: translateX(-50%) translateY(-60px);
  background: rgba(255, 255, 255, 0.96);
  color: #1e1b4b;
  padding: 10px 24px;
  border-radius: 30px;
  font-size: 0.95rem;
  font-weight: 800;
  border: 2.5px solid var(--primary-color);
  box-shadow: 0 10px 28px rgba(255, 51, 102, 0.25), 0 0 16px rgba(255, 141, 161, 0.3);
  pointer-events: none;
  z-index: 1000;
  opacity: 0;
  transition: transform 0.25s cubic-bezier(0.34, 1.56, 0.64, 1), opacity 0.2s ease;
  white-space: nowrap;
}

.toast-notification.visible {
  transform: translateX(-50%) translateY(0);
  opacity: 1;
}

/* Festive Candy Level Up Announcement Banner */
.level-up-banner {
  position: fixed;
  top: 38%;
  left: 50%;
  transform: translate(-50%, -50%) scale(0.6);
  background: linear-gradient(135deg, #ffffff 0%, #fff0f5 100%);
  border: 3.5px solid var(--primary-color);
  border-radius: 26px;
  box-shadow: 0 20px 50px rgba(255, 51, 102, 0.35), 0 0 30px rgba(255, 141, 161, 0.5);
  padding: 20px 32px;
  text-align: center;
  z-index: 1100;
  opacity: 0;
  pointer-events: none;
  transition: transform 0.35s cubic-bezier(0.34, 1.56, 0.64, 1), opacity 0.25s ease;
}

.level-up-banner.visible {
  transform: translate(-50%, -50%) scale(1);
  opacity: 1;
}

.level-up-pill {
  background: linear-gradient(135deg, #ff3366, #ff758c);
  color: #ffffff;
  font-size: 0.85rem;
  font-weight: 800;
  padding: 4px 16px;
  border-radius: 20px;
  display: inline-block;
  box-shadow: 0 4px 12px rgba(255, 51, 102, 0.35);
  letter-spacing: 0.5px;
}

.level-up-number {
  font-size: 2.2rem;
  font-weight: 800;
  color: #8b5cf6;
  margin: 6px 0 2px;
  text-shadow: 0 2px 4px rgba(139, 92, 246, 0.2);
}

.level-up-sub {
  font-size: 0.95rem;
  font-weight: 700;
  color: #64748b;
}

/* Main Container */
.game-wrapper {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: space-between;
  width: 100%;
  max-width: 440px;
  height: 100vh;
  max-height: 100vh;
  padding: 6px 8px 8px;
  z-index: 1;
}

/* Header & HUD */
.game-header {
  flex-shrink: 0;
  width: 100%;
  display: flex;
  flex-direction: column;
  gap: 5px;
}

.header-top-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  width: 100%;
  padding: 0 2px;
}

.brand-title {
  font-size: 1.85rem;
  font-weight: 800;
  color: #1e1b4b;
  letter-spacing: -0.5px;
  text-shadow: 0 2px 0 #ffffff, 0 3px 8px rgba(255, 141, 161, 0.35);
  display: flex;
  align-items: center;
  gap: 6px;
}

.brand-popper {
  color: #ff5400;
  display: inline-flex;
  align-items: center;
  text-shadow: 0 2px 0 #cc3d00, 0 3px 6px rgba(255, 84, 0, 0.35);
  letter-spacing: -0.5px;
}

.title-emoji-o {
  width: 1.6rem;
  height: 1.6rem;
  margin: 0 2px;
  display: inline-block;
  vertical-align: middle;
  filter: drop-shadow(0 2px 4px rgba(0, 0, 0, 0.2));
  animation: bounceTitleEmoji 2.2s ease-in-out infinite alternate;
}

@keyframes bounceTitleEmoji {
  0% { transform: translateY(0) rotate(-4deg) scale(1); }
  100% { transform: translateY(-3px) rotate(6deg) scale(1.08); }
}

.brand-popper {
  color: #ff5400;
  display: inline-flex;
  align-items: center;
  text-shadow: 0 2px 0 #cc3d00, 0 3px 6px rgba(255, 84, 0, 0.35);
  letter-spacing: -0.5px;
}

.title-emoji-o {
  width: 1.6rem;
  height: 1.6rem;
  margin: 0 2px;
  display: inline-block;
  vertical-align: middle;
  filter: drop-shadow(0 2px 4px rgba(0, 0, 0, 0.2));
  animation: bounceTitleEmoji 2.2s ease-in-out infinite alternate;
}

@keyframes bounceTitleEmoji {
  0% { transform: translateY(0) rotate(-4deg) scale(1); }
  100% { transform: translateY(-3px) rotate(6deg) scale(1.08); }
}

.header-tools {
  display: flex;
  gap: 6px;
}

.tool-btn {
  background: rgba(255, 255, 255, 0.92);
  border: 2px solid #ffffff;
  border-radius: var(--radius-md);
  width: 36px;
  height: 36px;
  font-size: 1.05rem;
  cursor: pointer;
  box-shadow: 0 4px 12px rgba(255, 141, 161, 0.2);
  transition: transform 0.15s ease, background 0.15s ease, box-shadow 0.15s ease;
  display: flex;
  align-items: center;
  justify-content: center;
}

.tool-btn:hover {
  transform: scale(1.1);
  background: #ffffff;
  box-shadow: 0 6px 16px rgba(255, 141, 161, 0.35);
}

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

/* HUD Cards */
.hud-cards {
  display: flex;
  gap: 8px;
  width: 100%;
}

.hud-card {
  flex: 1;
  background: rgba(255, 255, 255, 0.94);
  border: 2px solid #ffffff;
  border-radius: var(--radius-md);
  padding: 5px 10px;
  display: flex;
  flex-direction: column;
  align-items: center;
  box-shadow: 0 6px 16px rgba(255, 141, 161, 0.18);
  backdrop-filter: blur(10px);
}

.level-card {
  border-bottom: 3px solid #8b5cf6;
  max-width: 72px;
  position: relative;
}

.level-progress-bg {
  width: 100%;
  height: 5px;
  background: rgba(139, 92, 246, 0.2);
  border-radius: 4px;
  overflow: hidden;
  margin-top: 4px;
}

.level-progress-fill {
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, #8b5cf6, #ec4899);
  border-radius: 4px;
  transition: width 0.2s ease;
}

.score-card {
  border-bottom: 3px solid #ff3366;
}

.best-card {
  border-bottom: 3px solid #0284c7;
}

.hud-label {
  font-size: 0.65rem;
  font-weight: 700;
  color: var(--text-dim);
  letter-spacing: 0.6px;
}

.hud-value {
  font-size: 1.3rem;
  font-weight: 800;
  color: var(--text-main);
  line-height: 1.1;
}

.level-card .hud-value {
  color: #8b5cf6;
}

.score-card .hud-value {
  color: #ff3366;
}

.best-card .hud-value {
  color: #0284c7;
}

/* Dynamic Status Bar Wrapper (Fixed Slot: Zero layout shift) */
.status-bar-wrapper {
  width: 100%;
  height: 22px;
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
}

/* Combo Streak Bar */
.combo-container {
  width: 100%;
  display: flex;
  align-items: center;
  gap: 8px;
  height: 14px;
}

.status-bar-wrapper.has-danger .combo-container {
  display: none;
}

.combo-bar-bg {
  flex: 1;
  height: 6px;
  background: rgba(255, 255, 255, 0.7);
  border-radius: 6px;
  overflow: hidden;
}

.combo-bar-fill {
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, #ff9900, #ff007f);
  border-radius: 6px;
  transition: width 0.1s linear;
}

.combo-badge {
  font-size: 0.74rem;
  font-weight: 800;
  color: #ff007f;
  animation: pulseBadge 0.6s ease-in-out infinite alternate;
}

@keyframes pulseBadge {
  0% { transform: scale(0.95); }
  100% { transform: scale(1.05); }
}

/* Danger Overflow Alert Meter */
.danger-meter-container {
  width: 100%;
  display: none;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  position: relative;
  z-index: 10;
}

.danger-meter-container.active-danger {
  display: flex;
}

.danger-label {
  font-size: 0.76rem;
  font-weight: 800;
  color: #ef4444;
  text-shadow: 0 1px 4px rgba(239, 68, 68, 0.35);
  letter-spacing: 0.5px;
  animation: flashDanger 0.4s ease-in-out infinite alternate;
}

.danger-bar-bg {
  width: 100%;
  height: 7px;
  background: rgba(239, 68, 68, 0.25);
  border-radius: 6px;
  overflow: hidden;
  border: 1px solid rgba(239, 68, 68, 0.35);
}

.danger-bar-fill {
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, #ff416c, #ef4444);
  box-shadow: 0 0 10px #ef4444;
  border-radius: 6px;
}

@keyframes flashDanger {
  0% { opacity: 0.5; }
  100% { opacity: 1; }
}

/* Canvas Container */
.canvas-container {
  flex: 1;
  width: 100%;
  display: flex;
  justify-content: center;
  align-items: center;
  position: relative;
  min-height: 0;
}

#gameCanvas {
  display: block;
  border-radius: 22px;
  background: rgba(255, 255, 255, 0.85);
  border: 3.5px solid #ffffff;
  box-shadow: 0 12px 36px rgba(255, 141, 161, 0.25), inset 0 0 20px rgba(255, 255, 255, 0.9);
  cursor: pointer;
}

/* Powerups Footer */
.powerups-footer {
  flex-shrink: 0;
  width: 100%;
  display: flex;
  gap: 8px;
  padding-top: 4px;
}

.powerup-btn {
  flex: 1;
  position: relative;
  height: 48px;
  border-radius: var(--radius-md);
  border: 2px solid #ffffff;
  box-shadow: 0 6px 18px rgba(0, 0, 0, 0.12);
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  cursor: pointer;
  font-family: inherit;
  font-weight: 800;
  font-size: 0.84rem;
  color: #ffffff;
  transition: transform 0.15s ease, box-shadow 0.15s ease, filter 0.15s ease;
}

.bomb-btn {
  background: linear-gradient(135deg, #ff416c, #ff4b2b);
  box-shadow: 0 6px 16px rgba(255, 65, 108, 0.35);
}

.shake-btn {
  background: linear-gradient(135deg, #00c6ff, #0072ff);
  box-shadow: 0 6px 16px rgba(0, 114, 255, 0.35);
}

.clean-pop-btn {
  background: linear-gradient(135deg, #11998e, #38ef7d);
  box-shadow: 0 6px 16px rgba(17, 153, 142, 0.35);
}

.powerup-btn:hover {
  transform: translateY(-2px);
  filter: brightness(1.08);
}

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

.powerup-btn.active-powerup {
  filter: brightness(1.2);
  box-shadow: 0 0 20px rgba(255, 65, 108, 0.8);
  animation: pulseActivePowerup 0.8s ease-in-out infinite alternate;
}

.powerup-btn.active-reward {
  filter: brightness(1.2);
  box-shadow: 0 0 20px rgba(56, 239, 125, 0.8);
}

@keyframes pulseActivePowerup {
  0% { transform: scale(0.98); }
  100% { transform: scale(1.04); }
}

.btn-icon {
  font-size: 1.25rem;
}

.count-badge {
  position: absolute;
  top: -6px;
  right: -6px;
  background: #ffffff;
  color: #ff3366;
  font-size: 0.72rem;
  font-weight: 800;
  min-width: 22px;
  height: 22px;
  padding: 0 4px;
  border-radius: 11px;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 3px 8px rgba(0, 0, 0, 0.18);
  border: 1.5px solid #ff3366;
}

.count-badge.ad-refill-badge {
  background: linear-gradient(135deg, #f59e0b, #d97706);
  color: #ffffff;
  font-size: 0.62rem;
  min-width: 38px;
  height: 18px;
  border: 1.5px solid #ffffff;
  animation: pulseAdBadge 1s ease-in-out infinite alternate;
}

@keyframes pulseAdBadge {
  0% { transform: scale(0.95); box-shadow: 0 0 6px rgba(245, 158, 11, 0.4); }
  100% { transform: scale(1.05); box-shadow: 0 0 14px rgba(245, 158, 11, 0.9); }
}

.ad-tag {
  position: absolute;
  top: -6px;
  left: -6px;
  background: #facc15;
  color: #1e1b4b;
  font-size: 0.62rem;
  font-weight: 800;
  padding: 2px 6px;
  border-radius: 6px;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.2);
  border: 1px solid #ffffff;
}

/* Modals */
.modal-backdrop,
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(30, 27, 75, 0.55);
  backdrop-filter: blur(8px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 999;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.25s ease;
  padding: 16px;
}

.modal-backdrop.visible,
.modal-overlay.visible {
  opacity: 1;
  pointer-events: auto;
}

.modal-card {
  background: #ffffff;
  border: 3px solid #ffffff;
  border-radius: var(--radius-lg);
  padding: 24px;
  width: 100%;
  max-width: 360px;
  text-align: center;
  box-shadow: 0 20px 50px rgba(255, 105, 180, 0.25);
  transform: scale(0.9);
  transition: transform 0.25s cubic-bezier(0.34, 1.56, 0.64, 1);
  display: flex;
  flex-direction: column;
  gap: 16px;
  color: var(--text-main);
}

.modal-backdrop.visible .modal-card {
  transform: scale(1);
}

.modal-header h2 {
  font-size: 1.65rem;
  font-weight: 800;
  color: #1e1b4b;
}

.modal-header p {
  font-size: 0.9rem;
  color: var(--text-dim);
}

/* Stats Grid */
.stats-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  background: #fdf2f8;
  padding: 14px;
  border-radius: var(--radius-md);
  border: 1.5px solid #fce7f3;
}

.stat-item {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.stat-label {
  font-size: 0.68rem;
  font-weight: 700;
  color: #9d174d;
}

.stat-val {
  font-size: 1.25rem;
  font-weight: 800;
  color: #1e1b4b;
}

.stat-val.highlight {
  color: #ff3366;
  font-size: 1.55rem;
}

/* Action Buttons */
.action-btn {
  width: 100%;
  padding: 14px;
  border-radius: var(--radius-md);
  border: none;
  font-family: inherit;
  font-size: 1.05rem;
  font-weight: 800;
  cursor: pointer;
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.15);
  transition: transform 0.15s ease, box-shadow 0.15s ease;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  position: relative;
}

.action-btn:hover {
  transform: translateY(-2px);
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.22);
}

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

.revive-btn {
  background: linear-gradient(135deg, #ec4899, #f43f5e);
  color: #ffffff;
  animation: pulseRevive 1.2s ease-in-out infinite alternate;
}

@keyframes pulseRevive {
  0% { box-shadow: 0 0 10px rgba(236, 72, 153, 0.4); }
  100% { box-shadow: 0 0 24px rgba(236, 72, 153, 0.8); }
}

.ad-tag-pill {
  background: #facc15;
  color: #1e1b4b;
  font-size: 0.65rem;
  font-weight: 800;
  padding: 2px 6px;
  border-radius: 6px;
}

.restart-btn {
  background: linear-gradient(135deg, #3b82f6, #2563eb);
  color: #ffffff;
}

.resume-btn {
  background: linear-gradient(135deg, #10b981, #059669);
  color: #ffffff;
}

/* Help Rules */
.help-content {
  display: flex;
  flex-direction: column;
  gap: 8px;
  text-align: left;
  max-height: 300px;
  overflow-y: auto;
  padding-right: 4px;
}

.help-rule {
  background: #f8fafc;
  padding: 10px 14px;
  border-radius: 12px;
  border-left: 4px solid #ff3366;
  font-size: 0.86rem;
  line-height: 1.4;
  color: #1e293b;
  border-top: 1px solid #f1f5f9;
  border-right: 1px solid #f1f5f9;
  border-bottom: 1px solid #f1f5f9;
}

.rule-emoji-inline {
  width: 1.35rem;
  height: 1.35rem;
  vertical-align: -3px;
  margin: 0 3px;
  display: inline-block;
  filter: drop-shadow(0 1px 3px rgba(0, 0, 0, 0.2));
}
