/* ==========================================================================
   Avatar Widget — DiegoCuevas OS v2.0 — BonziBuddy Style
   Pixel-art SVG avatar with animated states, speech bubbles, and idle AI.
   ========================================================================== */

/* ── Container ────────────────────────────────────────────── */

.avatar-widget {
  position: fixed;
  bottom: 50px;
  right: 20px;
  z-index: 900;
  width: 280px;
  height: 360px;
  border-radius: 0;
  background: transparent;
  box-shadow: none;
  border: none;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-end;
  user-select: none;
  -webkit-user-select: none;
  padding: 0;
  transition: transform 0.2s ease;
}

.avatar-widget:hover {
  animation: avatarBounce 0.4s ease;
}

@keyframes avatarBounce {
  0%   { transform: translateY(0); }
  30%  { transform: translateY(-6px); }
  50%  { transform: translateY(-2px); }
  70%  { transform: translateY(-4px); }
  100% { transform: translateY(0); }
}

.avatar-widget::after {
  content: '';
  position: absolute;
  bottom: -5px;
  left: 50%;
  transform: translateX(-50%);
  width: 60%;
  height: 10px;
  background: radial-gradient(ellipse, rgba(0,0,0,0.3), transparent);
  border-radius: 50%;
}

.avatar-widget:active {
  transform: scale(0.95);
}

.avatar-widget.hidden {
  display: none;
}

/* ── Face (pixel-art SVG container) ──────────────────────── */

.avatar-face {
  width: 260px;
  height: 340px;
  display: flex;
  align-items: center;
  justify-content: center;
  image-rendering: pixelated;
  image-rendering: -moz-crisp-edges;
  image-rendering: crisp-edges;
  transition: all 0.3s ease;
  will-change: transform;
  overflow: hidden;
}

.avatar-face svg {
  width: 100%;
  height: 100%;
  image-rendering: pixelated;
  image-rendering: -moz-crisp-edges;
  image-rendering: crisp-edges;
  filter: brightness(1.3) saturate(1.2);
}

/* ── Name Label ─────────────────────────────────────────── */

.avatar-name-label {
  font-family: var(--font-pixel-readable);
  font-size: 12px;
  text-align: center;
  color: var(--win95-button-text);
  margin-top: 2px;
  pointer-events: none;
  white-space: nowrap;
  letter-spacing: 1px;
}

/* ── State Label (hidden by default, kept for API compat) ── */

.avatar-state-label {
  display: none;
}

/* ==========================================================================
   Speech Bubble — Win95 Tooltip Style
   ========================================================================== */

.avatar-speech-bubble {
  position: absolute;
  bottom: 100%;
  right: 0;
  margin-bottom: 8px;
  background: #FFFFCC;
  border: 2px solid #000000;
  padding: 8px 10px;
  font-family: var(--font-pixel-readable);
  font-size: 14px;
  line-height: 1.4;
  color: #000000;
  max-width: 220px;
  min-width: 120px;
  white-space: normal;
  word-wrap: break-word;
  box-shadow: 2px 2px 0 #000000;
  z-index: 901;
  opacity: 0;
  transform: translateY(8px);
  transition: opacity 0.25s ease, transform 0.25s ease;
  pointer-events: none;
}

.avatar-speech-bubble.visible {
  opacity: 1;
  transform: translateY(0);
}

/* Triangle pointer at bottom-right */
.avatar-speech-bubble::after {
  content: '';
  position: absolute;
  bottom: -10px;
  right: 20px;
  width: 0;
  height: 0;
  border-left: 8px solid transparent;
  border-right: 8px solid transparent;
  border-top: 10px solid #000000;
}

.avatar-speech-bubble::before {
  content: '';
  position: absolute;
  bottom: -7px;
  right: 22px;
  width: 0;
  height: 0;
  border-left: 6px solid transparent;
  border-right: 6px solid transparent;
  border-top: 8px solid #FFFFCC;
  z-index: 1;
}

/* ==========================================================================
   State Animations — each state gets a unique keyframe + visual treatment
   ========================================================================== */

/* ── Idle: gentle breathing pulse ─────────────────────────── */

.avatar--idle .avatar-face {
  animation: avatarIdle 3s infinite ease-in-out;
}

@keyframes avatarIdle {
  0%, 100% { transform: scaleY(1); }
  50%      { transform: scaleY(1.02); }
}

/* ── Idle micro-animations (applied via JS classes) ──────── */

.avatar--idle-look-left .avatar-face {
  animation: none;
  transform: translateX(-4px);
  transition: transform 0.4s ease;
}

.avatar--idle-look-right .avatar-face {
  animation: none;
  transform: translateX(4px);
  transition: transform 0.4s ease;
}

.avatar--idle-blink .avatar-face {
  animation: avatarBlink 0.3s ease;
}

@keyframes avatarBlink {
  0%, 100% { opacity: 1; }
  50%      { opacity: 0.7; }
}

/* ── Greeting: wave entrance ──────────────────────────────── */

.avatar--greeting .avatar-face {
  animation: avatarWave 0.6s infinite ease-in-out alternate;
}

@keyframes avatarWave {
  0%   { transform: rotate(-3deg); }
  100% { transform: rotate(3deg); }
}

/* ── Thinking: gentle float + thought pulse ───────────────── */

.avatar--thinking .avatar-face {
  animation: avatarThink 2s infinite ease-in-out;
}

@keyframes avatarThink {
  0%, 100% { transform: translateY(0) scale(1); }
  50%      { transform: translateY(-3px) scale(1.02); }
}

/* ── Pointing: slight lean toward target ──────────────────── */

.avatar--pointing .avatar-face {
  animation: avatarPoint 0.5s ease-out forwards;
}

@keyframes avatarPoint {
  0%   { transform: translateX(0) rotate(0deg); }
  100% { transform: translateX(-4px) rotate(-5deg); }
}

/* ── Talking: fast pulse + Y oscillation ─────────────────── */

.avatar--talking .avatar-face {
  animation: avatarTalking 0.5s infinite ease-in-out;
}

@keyframes avatarTalking {
  0%, 100% { transform: scale(1) translateY(0); }
  25%      { transform: scale(1.05) translateY(-2px); }
  75%      { transform: scale(0.97) translateY(1px); }
}

/* ── Photo: slight rotate oscillation ────────────────────── */

.avatar--photo .avatar-face {
  animation: avatarPhoto 2s infinite ease-in-out;
}

@keyframes avatarPhoto {
  0%, 100% { transform: rotate(0deg); }
  25%      { transform: rotate(-5deg); }
  75%      { transform: rotate(3deg); }
}

/* ── Drone: float up/down ────────────────────────────────── */

.avatar--drone .avatar-face {
  animation: avatarDrone 1.5s infinite ease-in-out;
}

@keyframes avatarDrone {
  0%, 100% { transform: translateY(0); }
  50%      { transform: translateY(-4px); }
}

/* ── FPV: tilt left-right ────────────────────────────────── */

.avatar--fpv .avatar-face {
  animation: avatarFPV 1s infinite ease-in-out;
}

@keyframes avatarFPV {
  0%, 100% { transform: rotate(0deg); }
  25%      { transform: rotate(-8deg); }
  75%      { transform: rotate(8deg); }
}

/* ── Video: slow pan left-right ──────────────────────────── */

.avatar--video .avatar-face {
  animation: avatarVideo 3s infinite ease-in-out;
}

@keyframes avatarVideo {
  0%, 100% { transform: translateX(0); }
  50%      { transform: translateX(4px); }
}

/* ── Scan (Tours): 360 rotation ──────────────────────────── */

.avatar--scan .avatar-face {
  animation: avatarScan 4s infinite linear;
}

@keyframes avatarScan {
  0%, 100% { transform: rotateY(0deg); }
  50%      { transform: rotateY(180deg); }
}

/* ── Work (AI): head bob ─────────────────────────────────── */

.avatar--work .avatar-face {
  animation: avatarWork 1s infinite ease-in-out;
}

@keyframes avatarWork {
  0%, 100% { transform: translateY(0); }
  50%      { transform: translateY(-2px); }
}

/* ── Skate: lateral oscillation ──────────────────────────── */

.avatar--skate .avatar-face {
  animation: avatarSkate 2s infinite ease-in-out;
}

@keyframes avatarSkate {
  0%, 100% { transform: translateX(0); }
  25%      { transform: translateX(-3px); }
  75%      { transform: translateX(3px); }
}

/* ── Dance: rotate + scale bounce ────────────────────────── */

.avatar--dance .avatar-face {
  animation: avatarDance 0.8s infinite ease-in-out;
}

@keyframes avatarDance {
  0%, 100% { transform: rotate(0deg) scale(1); }
  25%      { transform: rotate(-6deg) scale(1.06); }
  50%      { transform: rotate(0deg) scale(0.96); }
  75%      { transform: rotate(6deg) scale(1.06); }
}

/* ── Listening: ring pulse (box-shadow expand) ───────────── */

.avatar--listening .avatar-face {
  animation: avatarListening 1.5s infinite ease-out;
}

@keyframes avatarListening {
  0%   { box-shadow: 0 0 0 0 rgba(0, 200, 255, 0.5); }
  70%  { box-shadow: 0 0 0 12px rgba(0, 200, 255, 0); }
  100% { box-shadow: 0 0 0 0 rgba(0, 200, 255, 0); }
}

/* ── Speaking: pulse + cyan glow ─────────────────────────── */

.avatar--speaking .avatar-face {
  animation: avatarSpeaking 0.6s infinite ease-in-out;
}

@keyframes avatarSpeaking {
  0%, 100% {
    transform: scale(1);
    box-shadow: 0 0 6px 2px rgba(0, 200, 255, 0.3);
  }
  50% {
    transform: scale(1.05);
    box-shadow: 0 0 14px 4px rgba(0, 200, 255, 0.6);
  }
}

/* ==========================================================================
   Mobile Responsive — smaller widget on narrow viewports
   ========================================================================== */

@media (max-width: 768px) {
  .avatar-widget {
    width: 180px;
    height: 240px;
    bottom: 50px;
    right: 20px;
    padding: 0;
    background: transparent;
    box-shadow: none;
    border: none;
  }

  .avatar-face {
    width: 170px;
    height: 220px;
  }

  .avatar-name-label {
    font-size: 10px;
  }

  .avatar-speech-bubble {
    max-width: 180px;
    font-size: 12px;
    padding: 6px 8px;
  }
}


/* ==========================================================================
   SVG-Internal Animations — target elements inside inline SVGs by class
   ========================================================================== */

/* ── Drone: bob the drone group up/down ─────────────────────── */

.avatar--drone .drone-body {
  animation: droneBob 2s infinite ease-in-out;
  transform-origin: center top;
}

@keyframes droneBob {
  0%, 100% { transform: translateY(0); }
  50%      { transform: translateY(-3px); }
}

.avatar--drone .drone-led {
  animation: droneLedBlink 0.8s infinite steps(1);
}

@keyframes droneLedBlink {
  0%, 49%  { opacity: 1; }
  50%, 100% { opacity: 0.2; }
}

/* ── Photo: flash blink every 3s ────────────────────────────── */

.avatar--photo .camera-flash {
  animation: flashBlink 3s infinite ease-in-out;
}

@keyframes flashBlink {
  0%, 85%  { opacity: 0.3; fill: #FFD700; }
  90%      { opacity: 1; fill: #FFFFFF; }
  95%      { opacity: 1; fill: #FFFFCC; }
  100%     { opacity: 0.3; fill: #FFD700; }
}

/* ── Video: record light pulse + subtle sway ────────────────── */

.avatar--video .video-rec-light {
  animation: recLightPulse 1.5s infinite ease-in-out;
}

@keyframes recLightPulse {
  0%, 100% { opacity: 1; }
  50%      { opacity: 0.2; }
}

/* ── FPV: goggle LEDs blink ─────────────────────────────────── */

.avatar--fpv .goggle-led {
  animation: goggleLedBlink 1.2s infinite ease-in-out;
}

@keyframes goggleLedBlink {
  0%, 100% { fill: #2b7de9; opacity: 1; }
  50%      { fill: #00ffff; opacity: 0.6; }
}

/* ── Tour: camera on tripod slow rotate ─────────────────────── */

.avatar--scan .tour-camera {
  animation: tourCameraRotate 4s infinite ease-in-out;
  transform-origin: 12px 18px;
}

@keyframes tourCameraRotate {
  0%, 100% { transform: rotate(0deg); }
  25%      { transform: rotate(-6deg); }
  75%      { transform: rotate(6deg); }
}

.avatar--scan .tour-led {
  animation: tourLedBlink 2s infinite ease-in-out;
}

@keyframes tourLedBlink {
  0%, 100% { opacity: 1; }
  50%      { opacity: 0.2; }
}

/* ── AI: monitor screen flicker/pulse ───────────────────────── */

.avatar--work .monitor-screen {
  animation: screenFlicker 2s infinite ease-in-out;
}

@keyframes screenFlicker {
  0%, 100% { opacity: 1; fill: #2b7de9; }
  30%      { opacity: 0.8; fill: #1a6fd0; }
  50%      { opacity: 1; fill: #3399ff; }
  70%      { opacity: 0.85; fill: #2b7de9; }
  85%      { opacity: 0.95; fill: #44aaff; }
}
