/* ==========================================================================
   SANNIVESHAM — PHOTOREALISTIC DUAL-FRAME WINGBEAT PEACOCK
   True Photorealistic Flapping Wings, Consistent Facing & Immediate Perch
   ========================================================================== */

#flyingPeacockRoot {
  position: fixed;
  top: 0;
  left: 0;
  width: 104px;
  height: 104px;
  pointer-events: auto;
  cursor: pointer;
  z-index: 930;
  will-change: transform;
  transform-origin: center bottom;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
  contain: layout paint;
  display: block;
}

/* Contact Ground Shadow */
.peacock-ground-shadow {
  position: absolute;
  bottom: 5px;
  left: 50%;
  width: 58px;
  height: 14px;
  border-radius: 50%;
  background: radial-gradient(ellipse at center, rgba(12, 4, 1, 0.88) 0%, rgba(22, 7, 2, 0.45) 50%, transparent 75%);
  transform: translateX(-50%) scale(1);
  filter: blur(2.2px);
  pointer-events: none;
  transition: transform 0.22s ease, opacity 0.22s ease;
  z-index: 1;
}

/* Shadow when airborne vs perched */
.is-flying .peacock-ground-shadow {
  opacity: 0.15;
  transform: translateX(-50%) translateY(38px) scale(0.65);
  filter: blur(8px);
}

.is-takeoff .peacock-ground-shadow {
  opacity: 0.5;
  transform: translateX(-50%) translateY(14px) scale(0.85);
  filter: blur(4px);
}

.is-landing .peacock-ground-shadow,
.is-perched .peacock-ground-shadow {
  opacity: 0.95;
  transform: translateX(-50%) translateY(0) scale(1);
  filter: blur(2px);
}

/* Tooltip Badge for Sannivesham AI */
.peacock-ai-tooltip {
  position: absolute;
  bottom: calc(100% + 8px);
  left: 50%;
  transform: translateX(-50%) translateY(8px);
  background: linear-gradient(135deg, rgba(28, 10, 4, 0.96), rgba(18, 6, 2, 0.98));
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border: 1.5px solid #ffd166;
  border-radius: 26px;
  padding: 7px 16px;
  white-space: nowrap;
  color: #ffd166;
  font-family: 'Noto Serif Telugu', serif;
  font-size: 0.86rem;
  font-weight: 700;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.8), 0 0 20px rgba(255, 209, 102, 0.4);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.25s cubic-bezier(0.16, 1, 0.3, 1), transform 0.25s cubic-bezier(0.16, 1, 0.3, 1);
  display: flex;
  align-items: center;
  gap: 8px;
  z-index: 10;
}

.peacock-ai-tooltip::after {
  content: '';
  position: absolute;
  top: 100%;
  left: 50%;
  transform: translateX(-50%);
  border: 6px solid transparent;
  border-top-color: #ffd166;
}

#flyingPeacockRoot:hover .peacock-ai-tooltip,
#flyingPeacockRoot:focus-visible .peacock-ai-tooltip {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

/* Edge-Safe Tooltip Placement for Side Gutters */
#flyingPeacockRoot.on-left .peacock-ai-tooltip {
  left: 0;
  right: auto;
  transform: translateX(0) translateY(8px);
}
#flyingPeacockRoot.on-left .peacock-ai-tooltip::after {
  left: 24px;
  right: auto;
  transform: none;
}
#flyingPeacockRoot.on-left:hover .peacock-ai-tooltip,
#flyingPeacockRoot.on-left:focus-visible .peacock-ai-tooltip {
  transform: translateX(0) translateY(0);
}

#flyingPeacockRoot.on-right .peacock-ai-tooltip {
  left: auto;
  right: 0;
  transform: translateX(0) translateY(8px);
}
#flyingPeacockRoot.on-right .peacock-ai-tooltip::after {
  left: auto;
  right: 24px;
  transform: none;
}
#flyingPeacockRoot.on-right:hover .peacock-ai-tooltip,
#flyingPeacockRoot.on-right:focus-visible .peacock-ai-tooltip {
  transform: translateX(0) translateY(0);
}

.peacock-inner-wrap {
  width: 100%;
  height: 100%;
  position: relative;
  transform-origin: center center;
  transition: filter 0.25s ease;
}

#flyingPeacockRoot:hover .peacock-inner-wrap {
  filter: drop-shadow(0 0 20px rgba(255, 209, 102, 0.9)) drop-shadow(0 0 35px rgba(212, 107, 43, 0.65));
}

/* -------------------------------------------------------------
   PHOTOREALISTIC PEACOCK IMAGE LAYERS
   ------------------------------------------------------------- */
.peacock-img-layer {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  object-fit: contain;
  pointer-events: none;
  filter: drop-shadow(0 6px 14px rgba(0, 0, 0, 0.65));
}

/* 1. SITTING / PERCHED STATE (WINGS COMPLETELY FOLDED, ZERO FLAPPING) */
.is-perched .peacock-img-perched {
  display: block !important;
  animation: photorealBreathe 4.8s cubic-bezier(0.4, 0, 0.2, 1) infinite alternate;
  transform-origin: 50% 68%;
}

.is-perched .peacock-img-wing-up,
.is-perched .peacock-img-wing-down {
  display: none !important;
}

/* 2. TAKEOFF STATE */
.is-takeoff .peacock-img-perched {
  display: none !important;
}

.is-takeoff .peacock-img-wing-up {
  display: block !important;
  animation: photorealTakeoff 0.24s ease-out infinite alternate;
}

.is-takeoff .peacock-img-wing-down {
  display: none !important;
}

/* 3. FULL FLIGHT STATE: REALISTIC DUAL-FRAME ALTERNATING WINGBEAT */
.is-flying .peacock-img-perched {
  display: none !important;
}

/* Alternating Up-Stroke and Down-Stroke Wingbeat Cycle at ~3.6Hz */
.is-flying .peacock-img-wing-up {
  display: block !important;
  animation: flapStrokeUp 0.28s steps(1, end) infinite;
}

.is-flying .peacock-img-wing-down {
  display: block !important;
  animation: flapStrokeDown 0.28s steps(1, end) infinite;
}

/* 4. LANDING TOUCHDOWN STATE */
.is-landing .peacock-img-perched {
  display: block !important;
  animation: photorealLandingSettle 0.35s cubic-bezier(0.34, 1.56, 0.64, 1) forwards;
}

.is-landing .peacock-img-wing-up,
.is-landing .peacock-img-wing-down {
  display: none !important;
}

/* CLICK GLOW BURST */
.peacock-click-aura {
  position: absolute;
  top: 50%;
  left: 50%;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: radial-gradient(circle, #ffd166 15%, rgba(255, 159, 28, 0.75) 45%, rgba(200, 106, 50, 0.4) 70%, transparent 85%);
  transform: translate(-50%, -50%) scale(0);
  pointer-events: none;
  opacity: 0;
  z-index: 5;
}

.peacock-click-aura.active {
  animation: divineClickFlare 0.62s cubic-bezier(0.12, 0.8, 0.32, 1) forwards;
}

/* Stardust Embers */
.peacock-particle-ember {
  position: absolute;
  pointer-events: none;
  border-radius: 50%;
  background: radial-gradient(circle, #fff3d1 20%, #ffd166 60%, transparent 85%);
  box-shadow: 0 0 10px #ffd166, 0 0 16px rgba(230, 126, 34, 0.7);
  z-index: 925;
  opacity: 1;
  transform: translate(-50%, -50%) scale(1);
  transition: opacity 0.6s ease-out, transform 0.6s ease-out;
}

/* -------------------------------------------------------------
   KEYFRAME ANIMATIONS (REALISTIC WING FLAPPING & BREATHING)
   ------------------------------------------------------------- */
@keyframes photorealBreathe {
  0% {
    transform: scale(1) translateY(0);
  }
  100% {
    transform: scale(1.02, 0.985) translateY(-2.2px);
  }
}

@keyframes photorealTakeoff {
  0% {
    transform: scale(0.96) translateY(2px);
  }
  100% {
    transform: scale(1.04) translateY(-4px);
  }
}

/* Visible Wing Flap: Up-Stroke (0-49%) and Down-Stroke (50-100%) */
@keyframes flapStrokeUp {
  0%, 49% {
    opacity: 1;
    transform: translateY(-2px) scale(1.02);
  }
  50%, 100% {
    opacity: 0;
    transform: translateY(2px) scale(0.98);
  }
}

@keyframes flapStrokeDown {
  0%, 49% {
    opacity: 0;
    transform: translateY(-2px) scale(1.02);
  }
  50%, 100% {
    opacity: 1;
    transform: translateY(2px) scale(0.98);
  }
}

@keyframes photorealLandingSettle {
  0% {
    transform: translateY(-8px) scale(0.96);
  }
  60% {
    transform: translateY(2px) scale(1.02);
  }
  100% {
    transform: translateY(0) scale(1);
  }
}

@keyframes divineClickFlare {
  0% {
    transform: translate(-50%, -50%) scale(0.2);
    opacity: 1;
  }
  65% {
    transform: translate(-50%, -50%) scale(16);
    opacity: 0.7;
  }
  100% {
    transform: translate(-50%, -50%) scale(26);
    opacity: 0;
  }
}

/* -------------------------------------------------------------
   RESPONSIVE ADAPTATION FOR MOBILE
   ------------------------------------------------------------- */
@media (max-width: 768px) {
  #flyingPeacockRoot {
    width: 68px;
    height: 68px;
  }

  .peacock-img-layer {
    filter: drop-shadow(0 2px 5px rgba(0, 0, 0, 0.45)) !important;
  }

  .peacock-ground-shadow {
    width: 38px;
    height: 9px;
    bottom: 3px;
  }

  .peacock-ai-tooltip {
    font-size: 0.72rem;
    padding: 4px 10px;
    bottom: calc(100% + 4px);
    max-width: 76vw;
  }

  #flyingPeacockRoot.on-left .peacock-ai-tooltip {
    left: 0;
    right: auto;
    transform: translateY(6px);
  }
  #flyingPeacockRoot.on-left .peacock-ai-tooltip::after {
    left: 16px;
    right: auto;
  }
  #flyingPeacockRoot.on-left:hover .peacock-ai-tooltip,
  #flyingPeacockRoot.on-left:focus-visible .peacock-ai-tooltip {
    transform: translateY(0);
  }

  #flyingPeacockRoot.on-right .peacock-ai-tooltip {
    left: auto;
    right: 0;
    transform: translateY(6px);
  }
  #flyingPeacockRoot.on-right .peacock-ai-tooltip::after {
    left: auto;
    right: 16px;
  }
  #flyingPeacockRoot.on-right:hover .peacock-ai-tooltip,
  #flyingPeacockRoot.on-right:focus-visible .peacock-ai-tooltip {
    transform: translateY(0);
  }
}

/* -------------------------------------------------------------
   ACCESSIBILITY & REDUCED MOTION
   ------------------------------------------------------------- */
@media (prefers-reduced-motion: reduce) {
  #flyingPeacockRoot {
    transition: none !important;
    animation: none !important;
  }

  .is-perched .peacock-img-perched,
  .is-flying .peacock-img-wing-up,
  .is-flying .peacock-img-wing-down {
    animation: none !important;
  }
}

.peacock-lightweight-mode .peacock-particle-ember {
  display: none !important;
}
