/* ============================================
   BalloonsBackground — CSS Animations
   Premium floating balloons with layered motion
   ============================================ */

/* ─── Container ─── */
.bl-container {
  position: fixed;
  inset: 0;
  pointer-events: none;
  overflow: hidden;
  z-index: 0;
}

/* ─── Cada globo SVG ─── */
.bl-balloon {
  position: absolute;
  left: var(--bl-x);
  top: var(--bl-y);
  width: calc(90px * var(--bl-scale));
  height: calc(225px * var(--bl-scale));
  z-index: var(--bl-z);
  opacity: 0;
  filter: blur(var(--bl-blur));
  transform-origin: 50% 55%;
  will-change: transform, opacity;
  pointer-events: auto;
  cursor: pointer;

  animation:
    bl-float   var(--bl-float) ease-in-out infinite,
    bl-drift   var(--bl-drift) ease-in-out infinite,
    bl-sway    var(--bl-sway)  ease-in-out infinite,
    bl-appear  1.8s cubic-bezier(0.22, 1, 0.36, 1) forwards;

  animation-delay:
    var(--bl-delay),
    var(--bl-delay),
    var(--bl-delay),
    var(--bl-delay);

  transition: filter 0.15s ease;
}

.bl-balloon:hover {
  filter: blur(var(--bl-blur)) brightness(1.15);
}

/* ─── Estado "reventando" ─── */
.bl-balloon--popping {
  animation:
    bl-pop 0.35s cubic-bezier(0.34, 1.56, 0.64, 1) forwards !important;
  pointer-events: none;
}

/* ─── Reflejo pulsante ─── */
.bl-shine {
  animation: bl-shine-pulse var(--bl-shine) ease-in-out infinite;
  animation-delay: var(--bl-delay);
  transform-origin: center;
}

/* ─── Cuerda micro-oscilación ─── */
.bl-string {
  animation: bl-string-wave 4s ease-in-out infinite;
  animation-delay: var(--bl-delay);
  transform-origin: 50% 0%;
}

/* ============================================
   KEYFRAMES — Movimiento
   ============================================ */

@keyframes bl-float {
  0%, 100% { transform: translateY(0); }
  33%      { transform: translateY(-18px); }
  66%      { transform: translateY(-8px); }
}

@keyframes bl-drift {
  0%, 100% { transform: translateX(0); }
  40%      { transform: translateX(10px); }
  70%      { transform: translateX(-6px); }
}

@keyframes bl-sway {
  0%, 100% { transform: rotate(0deg); }
  20%      { transform: rotate(2.5deg); }
  50%      { transform: rotate(-1.5deg); }
  80%      { transform: rotate(1deg); }
}

@keyframes bl-shine-pulse {
  0%, 100% { opacity: 0.65; transform: scale(1); }
  50%      { opacity: 1; transform: scale(1.12); }
}

@keyframes bl-string-wave {
  0%, 100% { transform: skewX(0deg); }
  30%      { transform: skewX(2deg); }
  70%      { transform: skewX(-2deg); }
}

@keyframes bl-appear {
  0%   { opacity: 0; transform: translateY(60px) scale(0.8); }
  60%  { opacity: var(--bl-opacity); }
  100% { opacity: var(--bl-opacity); transform: translateY(0) scale(1); }
}

/* ============================================
   KEYFRAMES — Estallido
   ============================================ */

/* Globo: infla rápido y desaparece */
@keyframes bl-pop {
  0%   { transform: scale(1); opacity: var(--bl-opacity, 1); }
  30%  { transform: scale(1.25); opacity: 1; }
  60%  { transform: scale(1.4); opacity: 0.5; }
  100% { transform: scale(0); opacity: 0; }
}

/* ─── Contenedor del estallido ─── */
.bl-burst {
  position: absolute;
  pointer-events: none;
  z-index: 100;
}

/* ─── Flash blanco central ─── */
.bl-burst-flash {
  position: absolute;
  width: 80px;
  height: 80px;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%) scale(0);
  border-radius: 50%;
  background: radial-gradient(circle, rgba(255,255,255,0.9) 0%, rgba(255,255,255,0) 70%);
  animation: bl-flash 0.5s ease-out forwards;
}

@keyframes bl-flash {
  0%   { transform: translate(-50%, -50%) scale(0); opacity: 1; }
  50%  { transform: translate(-50%, -50%) scale(2.5); opacity: 0.6; }
  100% { transform: translate(-50%, -50%) scale(4); opacity: 0; }
}

/* ─── Onda expansiva ─── */
.bl-burst-ring {
  position: absolute;
  width: 20px;
  height: 20px;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%) scale(0);
  border-radius: 50%;
  border: 2px solid var(--ring-color, rgba(255,255,255,0.4));
  animation: bl-ring 0.6s cubic-bezier(0.22, 1, 0.36, 1) forwards;
}

@keyframes bl-ring {
  0%   { transform: translate(-50%, -50%) scale(0); opacity: 1; }
  100% { transform: translate(-50%, -50%) scale(8); opacity: 0; }
}

/* ─── Partículas ─── */
.bl-particle {
  position: absolute;
  left: 50%;
  top: 50%;
  width: var(--p-size, 8px);
  height: var(--p-size, 8px);
  margin-left: calc(var(--p-size, 8px) / -2);
  margin-top: calc(var(--p-size, 8px) / -2);
  background: var(--p-color, #fff);
  border-radius: var(--p-radius, 50%);
  opacity: 0;
  animation: bl-particle-fly var(--p-duration, 0.8s) cubic-bezier(0.22, 1, 0.36, 1) forwards;
  animation-delay: var(--p-delay, 0s);
}

@keyframes bl-particle-fly {
  0% {
    transform: translate(0, 0) scale(1) rotate(0deg);
    opacity: 1;
  }
  40% {
    opacity: 1;
  }
  100% {
    transform:
      translate(var(--p-tx, 60px), var(--p-ty, -80px))
      scale(var(--p-end-scale, 0.3))
      rotate(var(--p-rotation, 180deg));
    opacity: 0;
  }
}

/* ─── Trozos de cuerda ─── */
.bl-string-piece {
  position: absolute;
  left: 50%;
  top: 55%;
  width: 2px;
  height: var(--sp-len, 20px);
  background: var(--sp-color, #666);
  border-radius: 1px;
  opacity: 0;
  transform-origin: top center;
  animation: bl-string-fall 1.2s cubic-bezier(0.33, 1, 0.68, 1) forwards;
  animation-delay: var(--sp-delay, 0.05s);
}

@keyframes bl-string-fall {
  0% {
    transform: translateX(0) translateY(0) rotate(0deg);
    opacity: 0.6;
  }
  30% {
    opacity: 0.6;
  }
  100% {
    transform:
      translateX(var(--sp-tx, 10px))
      translateY(var(--sp-ty, 120px))
      rotate(var(--sp-rot, 90deg));
    opacity: 0;
  }
}

/* ============================================
   MESSAGE BALLOONS — Grid container & slots
   ============================================ */

.bl-msg-container {
  position: relative;
  width: 100%;
  max-width: 700px;
  margin: 0 auto;
  padding: 0 16px;
}

.bl-msg-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 16px 8px;
  justify-items: center;
  padding: 8px 0;
}

@media (min-width: 580px) {
  .bl-msg-grid { grid-template-columns: repeat(3, 1fr); }
}
@media (min-width: 900px) {
  .bl-msg-grid { grid-template-columns: repeat(4, 1fr); }
}

.bl-msg-slot {
  display: flex;
  justify-content: center;
  min-height: 200px;
}

.bl-msg-slot--empty {
  min-height: 0;
  height: 0;
  overflow: hidden;
}

/* ─── Message balloon (wrapper div, NOT svg) ─── */
.bl-balloon.bl-balloon--message {
  position: relative !important;
  display: flex;
  flex-direction: column;
  align-items: center;
  cursor: pointer;
  pointer-events: auto;
  touch-action: manipulation;
  width: 140px !important;
  height: auto !important;
  opacity: 0;
  transform-origin: 50% 40%;
  will-change: transform, opacity;
  left: auto !important;
  top: auto !important;
  filter: none !important;
  z-index: auto !important;

  animation:
    bl-float   var(--bl-float) ease-in-out infinite,
    bl-drift   var(--bl-drift) ease-in-out infinite,
    bl-sway    var(--bl-sway)  ease-in-out infinite,
    bl-msg-appear 1.2s cubic-bezier(0.22, 1, 0.36, 1) forwards;

  animation-delay:
    var(--bl-delay),
    var(--bl-delay),
    var(--bl-delay),
    var(--bl-delay);
}

@keyframes bl-msg-appear {
  0%   { opacity: 0; transform: translateY(40px) scale(0.7); }
  60%  { opacity: 1; }
  100% { opacity: 1; transform: translateY(0) scale(1); }
}

.bl-balloon--message .bl-balloon-svg {
  width: 140px;
  height: 210px;
  display: block;
}

.bl-balloon.bl-balloon--message:hover {
  filter: brightness(1.15) !important;
}

.bl-balloon.bl-balloon--message.bl-balloon--popping {
  animation: bl-pop 0.35s cubic-bezier(0.34, 1.56, 0.64, 1) forwards !important;
  pointer-events: none;
}

/* ─── Glow pulsante ─── */
.bl-msg-glow {
  position: absolute;
  top: 10%;
  left: 50%;
  width: 100px;
  height: 100px;
  transform: translateX(-50%);
  border-radius: 50%;
  background: radial-gradient(circle, var(--bl-glow-color, #FF69B4) 0%, transparent 70%);
  opacity: 0.3;
  filter: blur(20px);
  animation: bl-msg-glow-pulse 2.5s ease-in-out infinite;
  animation-delay: var(--bl-delay);
  pointer-events: none;
}

@keyframes bl-msg-glow-pulse {
  0%, 100% { opacity: 0.2; transform: translateX(-50%) scale(0.9); }
  50%      { opacity: 0.45; transform: translateX(-50%) scale(1.15); }
}

/* ─── Author label ─── */
.bl-msg-label {
  font-family: 'Dancing Script', cursive;
  font-size: 0.95rem;
  font-weight: 600;
  color: rgba(255, 255, 255, 0.85);
  text-align: center;
  margin-top: -30px;
  padding: 0 4px;
  text-shadow: 0 1px 8px rgba(0, 0, 0, 0.5);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 130px;
}

/* ============================================
   MESSAGE BURST — Enhanced particles
   ============================================ */

.bl-burst--message .bl-burst-flash--big {
  width: 120px;
  height: 120px;
  animation: bl-flash-big 1.2s ease-out forwards;
}

@keyframes bl-flash-big {
  0%   { transform: translate(-50%, -50%) scale(0); opacity: 1; }
  30%  { transform: translate(-50%, -50%) scale(3); opacity: 0.8; }
  60%  { transform: translate(-50%, -50%) scale(4.5); opacity: 0.4; }
  100% { transform: translate(-50%, -50%) scale(6); opacity: 0; }
}

.bl-burst--message .bl-burst-ring--big {
  animation: bl-ring-big 1.4s cubic-bezier(0.22, 1, 0.36, 1) forwards;
}

@keyframes bl-ring-big {
  0%   { transform: translate(-50%, -50%) scale(0); opacity: 1; }
  50%  { transform: translate(-50%, -50%) scale(8); opacity: 0.5; }
  100% { transform: translate(-50%, -50%) scale(14); opacity: 0; }
}

/* ─── Confetti rectangulares ─── */
.bl-confetti {
  position: absolute;
  left: 50%;
  top: 50%;
  width: var(--p-size, 5px);
  height: var(--p-h, 10px);
  margin-left: calc(var(--p-size, 5px) / -2);
  margin-top: calc(var(--p-h, 10px) / -2);
  background: var(--p-color, #fff);
  border-radius: var(--p-radius, 2px);
  opacity: 0;
  animation: bl-confetti-fly var(--p-duration, 0.8s) cubic-bezier(0.22, 1, 0.36, 1) forwards;
  animation-delay: var(--p-delay, 0s);
}

@keyframes bl-confetti-fly {
  0% {
    transform: translate(0, 0) scale(1) rotate(0deg);
    opacity: 1;
  }
  50% { opacity: 1; }
  75% { opacity: 0.6; }
  100% {
    transform:
      translate(var(--p-tx, 60px), var(--p-ty, -80px))
      scale(var(--p-end-scale, 0.3))
      rotate(var(--p-rotation, 360deg));
    opacity: 0;
  }
}

/* ─── Emoji voladores ─── */
.bl-emoji-particle {
  position: absolute;
  left: 50%;
  top: 50%;
  font-size: 20px;
  line-height: 1;
  transform: translate(-50%, -50%);
  opacity: 0;
  pointer-events: none;
  animation: bl-emoji-fly var(--p-duration, 0.8s) cubic-bezier(0.22, 1, 0.36, 1) forwards;
  animation-delay: var(--p-delay, 0s);
}

@keyframes bl-emoji-fly {
  0% {
    transform: translate(0, 0) scale(0.5);
    opacity: 1;
  }
  15% { transform: translate(calc(var(--p-tx) * 0.2), calc(var(--p-ty) * 0.2)) scale(1.4); opacity: 1; }
  50% { transform: translate(calc(var(--p-tx) * 0.6), calc(var(--p-ty) * 0.6)) scale(1.1); opacity: 1; }
  75% { opacity: 0.7; }
  100% {
    transform: translate(var(--p-tx, 50px), var(--p-ty, -60px)) scale(0.3);
    opacity: 0;
  }
}

/* ─── Sparkle stars ─── */
.bl-sparkle-particle {
  position: absolute;
  left: 50%;
  top: 50%;
  color: var(--p-color, #FFD54F);
  opacity: 0;
  pointer-events: none;
  animation: bl-sparkle-fly var(--p-duration, 0.6s) cubic-bezier(0.22, 1, 0.36, 1) forwards;
  animation-delay: var(--p-delay, 0s);
}

@keyframes bl-sparkle-fly {
  0% {
    transform: translate(0, 0) scale(0) rotate(0deg);
    opacity: 1;
  }
  20% { opacity: 1; transform: translate(calc(var(--p-tx) * 0.3), calc(var(--p-ty) * 0.3)) scale(1.3) rotate(60deg); }
  55% { opacity: 1; transform: translate(calc(var(--p-tx) * 0.65), calc(var(--p-ty) * 0.65)) scale(0.9) rotate(180deg); }
  80% { opacity: 0.5; }
  100% {
    transform: translate(var(--p-tx, 40px), var(--p-ty, -50px)) scale(0) rotate(300deg);
    opacity: 0;
  }
}

/* ============================================
   RESPONSIVE
   ============================================ */

@media (max-width: 768px) {
  .bl-balloon {
    width: calc(65px * var(--bl-scale));
    height: calc(165px * var(--bl-scale));
  }
  .bl-balloon.bl-balloon--message {
    width: 110px !important;
  }
  .bl-balloon--message .bl-balloon-svg {
    width: 110px;
    height: 165px;
  }
  .bl-msg-label {
    font-size: 0.85rem;
    max-width: 100px;
    margin-top: -24px;
  }
  .bl-msg-glow {
    width: 80px;
    height: 80px;
  }
}

@media (max-width: 480px) {
  .bl-balloon {
    width: calc(50px * var(--bl-scale));
    height: calc(125px * var(--bl-scale));
  }
  .bl-balloon.bl-balloon--message {
    width: 85px !important;
  }
  .bl-balloon--message .bl-balloon-svg {
    width: 85px;
    height: 128px;
  }
  .bl-msg-label {
    font-size: 0.75rem;
    max-width: 80px;
    margin-top: -18px;
  }
  .bl-msg-glow {
    width: 60px;
    height: 60px;
  }
  .bl-msg-slot {
    min-height: 150px;
  }
}

/* ============================================
   ACCESIBILIDAD
   ============================================ */

@media (prefers-reduced-motion: reduce) {
  .bl-balloon,
  .bl-shine,
  .bl-string {
    animation: bl-appear 0.5s ease forwards !important;
  }

  .bl-balloon.bl-balloon--message {
    animation: bl-msg-appear 0.5s ease forwards !important;
  }

  .bl-balloon--popping {
    animation: none !important;
    opacity: 0 !important;
  }

  .bl-burst,
  .bl-burst-flash,
  .bl-burst-ring,
  .bl-particle,
  .bl-string-piece,
  .bl-confetti,
  .bl-emoji-particle,
  .bl-sparkle-particle,
  .bl-msg-glow {
    animation: none !important;
    display: none;
  }
}
