/* ==========================================================================
   TACHYDEX COMPANION ROAMING MASCOT (HITODAMA-INSPIRED FEATURE)
   Luxury Glassmorphism, 60fps Organic Physics, Anime Cat-Girl Emoji Mascot
   ========================================================================== */

/* Main Host Container - Covers the viewport, non-blocking */
.companion-roam-host {
  position: fixed;
  inset: 0;
  z-index: 9999;
  pointer-events: none;
  overflow: hidden;
}

/* Roaming Mascot Button / Wrapper (Refined 68px Balanced Size) */
.companion-roam-stray {
  position: absolute;
  top: 0;
  left: 0;
  width: 68px;
  height: 68px;
  padding: 0;
  border: 0;
  background: transparent;
  cursor: grab;
  pointer-events: auto;
  user-select: none;
  -webkit-user-select: none;
  -webkit-tap-highlight-color: transparent;
  /* Smooth organic glide across coordinates */
  transition: transform 0.92s cubic-bezier(0.12, 0.88, 0.16, 1);
  will-change: transform;
}

.companion-roam-stray:active {
  cursor: grabbing;
}

.companion-roam-stray:focus-visible {
  outline: 2px solid #4ade80;
  outline-offset: 4px;
  border-radius: 50%;
}

/* Angular Tilt Layer (Spring Damper Physics) */
.companion-roam-tilt {
  display: block;
  width: 100%;
  height: 100%;
  transform-origin: 50% 85%;
  will-change: transform;
}

/* Idle Hover & Bobbing Layer */
.companion-roam-bob {
  display: block;
  width: 100%;
  height: 100%;
  animation: companionHoverBob 4.4s ease-in-out infinite;
}

@keyframes companionHoverBob {

  0%,
  100% {
    transform: translateY(-2.5px) rotate(-1.2deg);
  }

  50% {
    transform: translateY(2.5px) rotate(1.2deg);
  }
}

/* Anime Cat-Girl Avatar Image */
.companion-roam-avatar {
  width: 100%;
  height: 100%;
  object-fit: contain;
  display: block;
  filter: drop-shadow(0 4px 12px rgba(0, 0, 0, 0.35)) drop-shadow(0 0 14px rgba(74, 222, 128, 0.4)) drop-shadow(0 0 24px rgba(56, 189, 248, 0.25));
  transition: transform 0.22s cubic-bezier(0.34, 1.56, 0.64, 1), filter 0.3s ease;
  user-select: none;
  -webkit-user-drag: none;
}

.companion-roam-stray:hover .companion-roam-avatar {
  transform: scale(1.1);
  filter: drop-shadow(0 6px 16px rgba(0, 0, 0, 0.45)) drop-shadow(0 0 18px rgba(74, 222, 128, 0.7)) drop-shadow(0 0 28px rgba(56, 189, 248, 0.4));
}

/* Squash/stretch micro-animation on launch or poke */
.companion-roam-stray.is-chased .companion-roam-avatar {
  animation: companionSquash 0.38s cubic-bezier(0.34, 1.56, 0.64, 1);
}

@keyframes companionSquash {
  0% {
    transform: scale(1, 1);
  }

  30% {
    transform: scale(1.2, 0.84);
  }

  65% {
    transform: scale(0.92, 1.14);
  }

  100% {
    transform: scale(1, 1);
  }
}

/* Pure White Luxury Glassmorphic Speech Bubble */
.companion-roam-bubble {
  position: absolute;
  bottom: calc(100% + 12px);
  left: 50%;
  z-index: 10;
  padding: 8px 14px;
  border-radius: 11px;
  background: rgba(255, 255, 255, 0.96);
  border: 1px solid rgba(0, 0, 0, 0.08);
  box-shadow: 0 10px 26px rgba(0, 0, 0, 0.12),
    0 2px 8px rgba(0, 0, 0, 0.05),
    0 0 16px rgba(74, 222, 128, 0.15);
  -webkit-backdrop-filter: blur(16px);
  backdrop-filter: blur(16px);
  color: #0f172a;
  font-family: 'Plus Jakarta Sans', system-ui, -apple-system, sans-serif;
  font-size: 12.5px;
  font-weight: 600;
  line-height: 1.35;
  letter-spacing: -0.01em;
  white-space: nowrap;
  width: max-content;
  max-width: min(290px, 85vw);
  text-align: center;
  pointer-events: none;
  opacity: 0;
  /* Default hidden spring state */
  transform: translate(calc(-50% + var(--bubble-nudge, 0px)), 6px) scale(0.78);
  transform-origin: 50% 115%;
  transition: opacity 0.22s ease, transform 0.32s cubic-bezier(0.34, 1.56, 0.64, 1);
}

/* Downward speech bubble pointer arrow (Pure White) */
.companion-roam-bubble::after {
  content: "";
  position: absolute;
  top: 100%;
  left: 50%;
  width: 8px;
  height: 8px;
  margin: -4px 0 0 calc(-4px - var(--bubble-nudge, 0px));
  border-right: 1px solid rgba(0, 0, 0, 0.08);
  border-bottom: 1px solid rgba(0, 0, 0, 0.08);
  background: rgba(255, 255, 255, 0.95);
  transform: rotate(45deg);
}

/* When near top of viewport, flip bubble below */
.companion-roam-bubble[data-below="true"] {
  bottom: auto;
  top: calc(100% + 10px);
  transform: translate(calc(-50% + var(--bubble-nudge, 0px)), -6px) scale(0.78);
  transform-origin: 50% -15%;
}

.companion-roam-bubble[data-below="true"]::after {
  top: auto;
  bottom: 100%;
  margin: 0 0 -4px calc(-4px - var(--bubble-nudge, 0px));
  border-right: none;
  border-bottom: none;
  border-top: 1px solid rgba(0, 0, 0, 0.08);
  border-left: 1px solid rgba(0, 0, 0, 0.08);
  background: rgba(255, 255, 255, 0.95);
}

/* Shown state with lively spring bounce */
.companion-roam-bubble[data-show="true"] {
  opacity: 1;
  transform: translate(calc(-50% + var(--bubble-nudge, 0px)), 0) scale(1);
}

/* Sparkle trail particles emitted during jump */
.companion-sparkle-mote {
  position: absolute;
  width: 5px;
  height: 5px;
  border-radius: 50%;
  background: #4ade80;
  box-shadow: 0 0 8px #4ade80, 0 0 16px #5ce1e6;
  pointer-events: none;
  animation: companionMoteFade 0.7s cubic-bezier(0.2, 0.8, 0.2, 1) forwards;
}

@keyframes companionMoteFade {
  0% {
    opacity: 1;
    transform: translate(0, 0) scale(1);
  }

  100% {
    opacity: 0;
    transform: translate(var(--mx, 0px), var(--my, -20px)) scale(0.2);
  }
}

/* Pulse hint on brand logo when companion is active */
.brand-link.companion-summoned .brand-icon {
  animation: logoSummonPulse 0.6s ease;
  filter: drop-shadow(0 0 10px #4ade80);
}

@keyframes logoSummonPulse {
  0% {
    transform: scale(1);
  }

  50% {
    transform: scale(1.22);
  }

  100% {
    transform: scale(1);
  }
}

/* Mobile responsive sizing */
@media (max-width: 640px) {
  .companion-roam-stray {
    width: 52px;
    height: 52px;
  }

  .companion-roam-bubble {
    font-size: 11.5px;
    padding: 6px 12px;
  }
}