/* Base: Ben Evans eYqWNYb MIT https://codepen.io/ivorjetski/pen/eYqWNYb */
/* Wobble: Trevor Knutson rNyPzmO MIT https://codepen.io/treknuts/pen/rNyPzmO */
/* Float: webitia GRzQepg MIT https://codepen.io/webitia/pen/GRzQepg */
/* Pop splash SVG: yoksel EyZgLo MIT https://codepen.io/yoksel/pen/EyZgLo — GSAP replaced with WAAPI */

.bubble {
  position: absolute;
  left: 50%;
  top: -65%;
  /* --bubble-offset-y controls vertical gap above portal; --bubble-offset-x via translate */
  margin-bottom: 2ch;
  z-index: 10;
  /* size — base is sprite-scale 4 (perfect), 3 is smaller */
  width: clamp(48px, 10vmin, 88px);
  aspect-ratio: 1;
  background: transparent;
  border: none;
  outline: none;
  border-radius: 50%;
  image-rendering: auto;
  container-type: inline-size;
  /* counter portal scale (portal is max(2, --sprite-scale)) so bubble stays 1:1 */
  --portal-scale: max(2, var(--sprite-scale));
  scale: calc(1 / var(--portal-scale));
  /* Always float */
  animation: bubbleFloat 8s ease-in-out infinite;
}

@media (height < 498px) {
  html[data-sprite-scale="1"] .bubble { 
    left: -20%;
    top: 45%;
  }
}

/* Float animation (webitia) */
@keyframes bubbleFloat {
  0%, 100% { transform: translateY(-15px); }
  50% { transform: translateY(15px); }
}

.bubble-visual {
  position: absolute;
  inset: 0;
  margin: auto;
  border-radius: 50%;
  font-size: 2cqw;
  background: radial-gradient(circle at 50% 40%, rgba(255, 255, 255, 0.28), rgba(255, 255, 255, 0.08));
  backdrop-filter: blur(3px);
  -webkit-backdrop-filter: blur(3px);
  box-shadow: 
    8em 8em 4em -6em rgba(0, 0, 0, 0.5), 
    8em 8em 4em -2em rgba(0, 255, 170, 0.1), 
    8em 8em 4em -2em rgba(255, 255, 255, 0.05), 
    inset 16em 16em 4em -6em rgba(0, 0, 0, 0.1), 
    inset 16em 16em 4em -2em rgba(255, 255, 255, 0.1), 
    10em 10em 4em rgba(255, 0, 255, 0.1);
  filter: contrast(1.1);
  /* Wobble (Trevor Knutson) */
  animation: bubbleWobble 2s ease-out infinite;
}

/* Dark frost — d2d2d2 as requested */
html[data-theme="dark"] .bubble-visual {
  background: radial-gradient(circle at 50% 40%, rgba(210, 210, 210, 0.42), rgba(210, 210, 210, 0.14));
}

@media (prefers-color-scheme: dark) {
  html:not([data-theme="light"]) .bubble-visual {
    background: radial-gradient(circle at 50% 40%, rgba(210, 210, 210, 0.42), rgba(210, 210, 210, 0.14));
  }
}

/* Wobble can be disabled by adding .no-wobble to host */
.bubble.no-wobble .bubble-visual {
  animation: none;
}

@keyframes bubbleWobble {
  0%, 100% { transform: scaleY(0.95) scaleX(1.05); }
  50% { transform: scaleY(1.1) scaleX(0.9); }
}

/* Specular highlights */
.bubble-visual::before,
.bubble-visual::after {
  content: "";
  position: absolute;
  inset: 0;
  border-radius: 50%;
}

/* Colored rim */
.bubble-visual::before {
  box-shadow: 
    inset 2em 0 5em magenta, 
    inset 0 -2em 5em yellow, 
    inset 0 2em 5em blue, 
    inset -2em 0 5em cyan;
  opacity: 0.7;
}

/* Highlight dots */
.bubble-visual::after {
  box-shadow: 
    inset -3em -3em 2em rgba(0, 255, 170, 0.1), 
    inset 0 0 1em #00ffaa, 
    inset 4em 4em 5em rgba(0, 0, 0, 0.1);
  filter: blur(0.5em);
  opacity: 0.9;
  background: 
    radial-gradient(circle at 40% 15%, white 1%, rgba(255, 255, 255, 0) 3%), 
    radial-gradient(circle at 35% 25%, white 1%, rgba(255, 255, 255, 0) 2.5%), 
    radial-gradient(circle at 50% 12%, rgba(255, 255, 255, 0.5) 1.5%, rgba(255, 255, 255, 0) 4%), 
    radial-gradient(circle at 55% 22%, rgba(255, 255, 255, 0.3) 1%, rgba(255, 255, 255, 0) 2.5%), 
    radial-gradient(circle at 10% 40%, rgba(255, 255, 255, 0.2) 2.5%, rgba(255, 255, 255, 0) 5%), 
    radial-gradient(circle at 20% 50%, rgba(255, 255, 255, 0.15) 1.5%, rgba(255, 255, 255, 0) 3%), 
    radial-gradient(circle at 40% 10%, rgba(255, 255, 255, 0.8) 1.5%, rgba(255, 255, 255, 0) 3.5%), 
    radial-gradient(circle at 30% 20%, rgba(255, 255, 255, 0.5) 1%, rgba(255, 255, 255, 0) 2%);
}

/* Shards — custom pop using bubble rainbow (magenta / yellow / blue / cyan) */
.bubble-shards {
  position: absolute;
  inset: 0;
  pointer-events: none;
  overflow: visible;
}

.bubble-shard {
  position: absolute;
  left: var(--shard-x, 50%);
  top: var(--shard-y, 50%);
  width: var(--shard-size, 6px);
  height: calc(var(--shard-size, 6px) * var(--shard-aspect, 1));
  background: var(--shard-color, #aaaaaa);
  box-shadow: 0 0 2px var(--shard-color, #aaaaaa);
  translate: -50% -50%;
  will-change: transform, opacity;
  opacity: 0;
  /* sharp, not blobby — no blur */
  filter: contrast(1.15);
}

.shard-triangle {
  clip-path: polygon(50% 0%, 0% 100%, 100% 100%);
  border-radius: 1px;
  --shard-aspect: 0.7;
}

.shard-diamond {
  clip-path: polygon(50% 0%, 100% 50%, 50% 100%, 0% 50%);
  border-radius: 1px;
}

.shard-quad {
  /* Using CSS variables for irregular quad points if set, otherwise a fallback shape */
  clip-path: polygon(var(--quad-a, 20%) 0%, 100% var(--quad-b, 30%), calc(100% - var(--quad-a, 20%)) 100%, 0% calc(100% - var(--quad-b, 30%)));
  border-radius: 1px;
}

.shard-dot {
  clip-path: none;
  border-radius: 1px;
}

/* Popped state */
.bubble.popped .bubble-visual {
  display: none;
}

.bubble.is-popping, .bubble.is-popping .bubble-visual {
  animation-play-state: paused !important;
}

.bubble.popped {
  pointer-events: none;
}

/* scale 3 is too big at base size — shrink ~18% */
html[data-sprite-scale="3"] .bubble {
  width: clamp(38px, 8vmin, 72px);
}

html[data-sprite-scale="2"] .bubble {
  width: clamp(36px, 7.5vmin, 64px);
}

html[data-sprite-scale="1"] .bubble {
  width: clamp(34px, 7vmin, 58px);
}

@media (prefers-reduced-motion: reduce) {
  .bubble, .bubble-visual {
    animation: none !important;
  }
}
