/* Reset-ish */
* {
  box-sizing: border-box;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
  margin: 0;
  padding: 0;
}

body {
  width: 100vw;
  height: 100vh;
  overflow: hidden;
  background: radial-gradient(circle at 20% 20%, #1a0033 0%, #000011 60%);
  color: #fff;
  font-family: "Inter", system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI",
    Roboto, "Helvetica Neue", Arial, sans-serif;
  position: relative;
  touch-action: none; /* prevent mobile scroll while chasing */
}

/* animated background blobs */
.glow {
  position: absolute;
  width: 45vmax;
  height: 45vmax;
  filter: blur(80px);
  opacity: 0.45;
  mix-blend-mode: screen;
  border-radius: 50%;
  pointer-events: none;
  background: radial-gradient(circle, rgba(255,0,153,1) 0%, rgba(0,0,0,0) 70%);
  animation: floaty 10s infinite linear;
  will-change: transform;
}

.glow-1 {
  background: radial-gradient(circle, rgba(255,0,153,1) 0%, rgba(0,0,0,0) 70%);
  left: 10%;
  top: 15%;
  animation-duration: 11s;
}
.glow-2 {
  background: radial-gradient(circle, rgba(0,200,255,1) 0%, rgba(0,0,0,0) 70%);
  right: 10%;
  top: 40%;
  animation-duration: 13s;
}
.glow-3 {
  background: radial-gradient(circle, rgba(150,0,255,1) 0%, rgba(0,0,0,0) 70%);
  left: 40%;
  bottom: 5%;
  animation-duration: 17s;
}

@keyframes floaty {
  0%   { transform: translate3d(0, 0, 0) scale(1);   }
  33%  { transform: translate3d(-5vw, 3vh, 0) scale(1.1); }
  66%  { transform: translate3d(6vw, -4vh, 0) scale(0.9); }
  100% { transform: translate3d(0, 0, 0) scale(1);   }
}

/* bubble with text */
.bubble {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  background: rgba(20, 20, 30, 0.6);
  backdrop-filter: blur(8px) saturate(160%);
  -webkit-backdrop-filter: blur(8px) saturate(160%);

  color: #fff;
  font-size: clamp(1rem, 2vw + 1rem, 2rem);
  font-weight: 700;
  line-height: 1.4;
  padding: 1rem 1.25rem;
  min-width: max-content;
  max-width: 80vw;        /* mobile safety */
  border-radius: 1rem;
  box-shadow:
    0 20px 60px rgba(0, 0, 0, 0.8),
    0 0 30px rgba(0, 255, 234, 0.4),
    0 0 60px rgba(255, 0, 191, 0.3);
  border: 1px solid rgba(255, 255, 255, 0.12);

  cursor: default;
  user-select: none;
  text-align: center;
  pointer-events: none; /* can't click directly, but we listen on document */
  will-change: transform, filter, box-shadow;

  display: flex;
  align-items: center;
  justify-content: center;
  gap: .5rem;

  position: absolute;
}

/* the 🤢 face appears when dizzy or broken */
.dizzy-face {
  font-size: 1.4em;
  display: none;
}

/* --- DIZZY STATE (running too fast) --- */
.bubble.dizzy {
  animation: spin-wobble .4s linear infinite;
  filter: hue-rotate(40deg) blur(1px) brightness(1.3) saturate(1.8);
}
.bubble.dizzy .dizzy-face {
  display: inline-block;
}

@keyframes spin-wobble {
  0%   { transform: translate(-50%, -50%) rotate(0deg)    scale(1);   }
  25%  { transform: translate(-50%, -50%) rotate(5deg)    scale(1.05);}
  50%  { transform: translate(-50%, -50%) rotate(-5deg)   scale(0.95);}
  75%  { transform: translate(-50%, -50%) rotate(8deg)    scale(1.08);}
  100% { transform: translate(-50%, -50%) rotate(-8deg)   scale(0.97);}
}

/* --- CRACKED STATE (after ~4 edge hovers) --- */
.bubble.cracked {
  border: 1px solid rgba(255, 80, 80, 0.6);
  box-shadow:
    0 0 20px rgba(255, 0, 0, 0.6),
    0 0 50px rgba(255, 0, 0, 0.4),
    0 30px 60px rgba(0,0,0,0.9);
  background: rgba(40, 0, 0, 0.5);
  position: absolute;
}

.bubble.cracked::after {
  content: "";
  position: absolute;
  inset: 0;
  border-radius: 1rem;
  background-image: repeating-linear-gradient(
    115deg,
    rgba(255,0,0,0.4) 0px,
    rgba(255,0,0,0.0) 4px,
    rgba(255,0,0,0.0) 8px
  );
  mix-blend-mode: screen;
  pointer-events: none;
  animation: crack-flicker .15s steps(2,end) infinite;
}

@keyframes crack-flicker {
  0%   { opacity: 0.4; }
  100% { opacity: 0.8; }
}

/* --- BROKEN STATE (after more abuse OR click) --- */
.bubble.broken {
  background: rgba(60, 0, 0, 0.6);
  border: 2px solid rgba(255,0,0,0.8);
  box-shadow:
    0 0 10px rgba(255,0,0,0.9),
    0 0 80px rgba(255,0,0,0.7),
    0 40px 120px rgba(0,0,0,0.95);

  filter: contrast(1.4) brightness(1.2) saturate(2) hue-rotate(-20deg);
  animation: broken-shake .08s infinite;
}

.bubble.broken .dizzy-face {
  display: inline-block;
}

.bubble.broken span#textContent {
  display: inline-block;
  transform: skewX(-6deg) scaleY(0.95);
  text-shadow:
    0 0 4px rgba(255,0,0,0.8),
    0 0 10px rgba(255,50,0,0.8),
    0 0 30px rgba(255,0,0,0.5);
}

@keyframes broken-shake {
  0%   { transform: translate(-50%, -50%) translate(-1px, 1px) rotate(-1deg); }
  25%  { transform: translate(-50%, -50%) translate(1px, -1px) rotate(1deg); }
  50%  { transform: translate(-50%, -50%) translate(-2px, 0px) rotate(0deg); }
  75%  { transform: translate(-50%, -50%) translate(2px, 2px) rotate(2deg); }
  100% { transform: translate(-50%, -50%) translate(0px, -2px) rotate(-2deg); }
}

/* control card (button etc) */
.controls-card {
  position: absolute;
  right: 1rem;
  bottom: 1rem;
  z-index: 10;
  max-width: 260px;
  color: #fff;
  font-size: 0.9rem;
}

.card-inner {
  background: rgba(0, 0, 0, 0.5);
  backdrop-filter: blur(12px) saturate(180%);
  -webkit-backdrop-filter: blur(12px) saturate(180%);
  padding: 1rem 1.25rem 1.25rem;
  border-radius: 1rem;
  box-shadow:
    0 30px 80px rgba(0, 0, 0, 0.9),
    0 0 40px rgba(0, 195, 255, 0.4),
    0 0 80px rgba(255, 0, 200, 0.3);
  border: 1px solid rgba(255, 255, 255, 0.12);
}

.title {
  font-size: 1rem;
  font-weight: 600;
  display: flex;
  align-items: center;
  gap: 0.4rem;
  color: #fff;
}
.subtitle {
  font-size: 0.8rem;
  font-weight: 400;
  opacity: 0.7;
  margin-top: 0.25rem;
  margin-bottom: 0.75rem;
}

.btn {
  appearance: none;
  border: 0;
  outline: 0;
  cursor: pointer;
  width: 100%;
  font-size: 1rem;
  font-weight: 600;
  line-height: 1.2;
  padding: 0.9rem 1rem;
  border-radius: 0.75rem;
  color: #000;
  background: radial-gradient(
    circle at 20% 20%,
    #ffffff 0%,
    #c0fff9 40%,
    #8cf6ff 60%,
    #ff55f9 100%
  );
  box-shadow:
    0 10px 30px rgba(0, 0, 0, 0.8),
    0 0 30px rgba(0, 255, 213, 0.6),
    0 0 60px rgba(255, 0, 200, 0.4);
  border: 1px solid rgba(0, 0, 0, 0.4);
  transition: transform 0.12s ease;
  touch-action: manipulation;
}
.btn:active {
  transform: scale(0.97);
}

.hint {
  margin-top: 0.75rem;
  font-size: 0.75rem;
  line-height: 1.4;
  opacity: 0.7;
  text-align: center;
}

/* mobile layout */
@media (max-width: 480px) {
  .controls-card {
    left: 0;
    right: 0;
    bottom: 0;
    margin: 0 auto 0.75rem auto;
    max-width: calc(100% - 1.5rem);
    font-size: 0.85rem;
  }

  .card-inner {
    padding: 0.9rem 1rem 1rem;
    border-radius: 0.9rem;
  }

  .btn {
    font-size: 1rem;
    padding: 0.8rem 1rem;
    border-radius: 0.7rem;
  }

  .bubble {
    font-size: clamp(1rem, 3vw + 1rem, 1.4rem);
    padding: 0.8rem 1rem;
    max-width: 90vw;
  }
}
