/**
 * Learning Companion Styles
 * Animated character component with mood states and interactions
 */

/* Base Container */
.learning-companion {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.75rem;
}

/* Size Variants */
.companion-small {
  --companion-size: 60px;
}

.companion-medium {
  --companion-size: 100px;
}

.companion-large {
  --companion-size: 150px;
}

/* Avatar Container */
.companion-avatar {
  position: relative;
  width: var(--companion-size, 100px);
  height: var(--companion-size, 100px);
  transition: transform 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);
}

.companion-svg {
  width: 100%;
  height: 100%;
  filter: drop-shadow(0 8px 16px rgba(0, 0, 0, 0.15));
  transition: filter 0.3s ease;
}

/* Mood-Based Glow Effects */
.companion-owl[data-mood="happy"] .companion-svg,
.companion-owl[data-mood="excited"] .companion-svg {
  filter: drop-shadow(0 8px 20px rgba(139, 92, 246, 0.4));
}

.companion-fox[data-mood="happy"] .companion-svg,
.companion-fox[data-mood="excited"] .companion-svg {
  filter: drop-shadow(0 8px 20px rgba(249, 115, 22, 0.4));
}

.companion-robot[data-mood="happy"] .companion-svg,
.companion-robot[data-mood="excited"] .companion-svg {
  filter: drop-shadow(0 8px 20px rgba(59, 130, 246, 0.4));
}

/* Speech Bubble */
.companion-speech-bubble {
  position: absolute;
  bottom: calc(100% + 12px);
  left: 50%;
  transform: translateX(-50%);
  z-index: 10;
  opacity: 0;
  animation: speechBubbleIn 0.4s ease forwards;
  animation-delay: 0.5s;
}

.speech-content {
  position: relative;
  background: white;
  border-radius: 16px;
  padding: 0.75rem 1rem;
  min-width: 140px;
  max-width: 220px;
  box-shadow: 
    0 4px 12px rgba(0, 0, 0, 0.1),
    0 0 0 1px rgba(0, 0, 0, 0.05);
}

.speech-text {
  margin: 0;
  font-size: 0.9rem;
  color: #1c2325;
  text-align: center;
  line-height: 1.4;
  font-weight: 500;
}

.speech-tail {
  position: absolute;
  bottom: -8px;
  left: 50%;
  transform: translateX(-50%);
  width: 0;
  height: 0;
  border-left: 10px solid transparent;
  border-right: 10px solid transparent;
  border-top: 10px solid white;
}

.companion-speech-bubble.speaking {
  animation: speechBubblePop 0.3s ease;
}

/* Name Tag */
.companion-name-tag {
  background: linear-gradient(135deg, rgba(255, 255, 255, 0.95), rgba(255, 255, 255, 0.85));
  border-radius: 20px;
  padding: 0.4rem 1rem;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.08);
  border: 1px solid rgba(0, 0, 0, 0.05);
}

.companion-name {
  font-size: 0.85rem;
  font-weight: 600;
  color: #455255;
}

/* Particle Effects */
.companion-particles {
  position: absolute;
  inset: -20px;
  pointer-events: none;
  overflow: visible;
}

.particle {
  position: absolute;
  width: 6px;
  height: 6px;
  border-radius: 50%;
  opacity: 0;
  animation: particleFloat 3s ease-in-out infinite;
  animation-delay: var(--delay);
}

.companion-owl .particle {
  background: rgba(139, 92, 246, 0.6);
}

.companion-fox .particle {
  background: rgba(249, 115, 22, 0.6);
}

.companion-robot .particle {
  background: rgba(59, 130, 246, 0.6);
}

.particle-0 { top: 20%; left: 10%; }
.particle-1 { top: 10%; left: 40%; }
.particle-2 { top: 20%; right: 10%; }
.particle-3 { bottom: 20%; left: 15%; }
.particle-4 { bottom: 10%; left: 50%; }
.particle-5 { bottom: 20%; right: 15%; }

/* Confetti */
.confetti-piece {
  position: absolute;
  pointer-events: none;
  z-index: 100;
}

/* Animations */
@keyframes speechBubbleIn {
  0% {
    opacity: 0;
    transform: translateX(-50%) translateY(10px) scale(0.9);
  }
  100% {
    opacity: 1;
    transform: translateX(-50%) translateY(0) scale(1);
  }
}

@keyframes speechBubblePop {
  0% {
    transform: translateX(-50%) scale(1);
  }
  50% {
    transform: translateX(-50%) scale(1.1);
  }
  100% {
    transform: translateX(-50%) scale(1);
  }
}

@keyframes particleFloat {
  0%, 100% {
    opacity: 0;
    transform: translateY(0) scale(0.5);
  }
  50% {
    opacity: 0.8;
    transform: translateY(-20px) scale(1);
  }
}

@keyframes confettiFall {
  0% {
    opacity: 1;
    transform: translate(0, 0) rotate(0deg);
  }
  100% {
    opacity: 0;
    transform: translate(var(--x-offset), 150px) rotate(var(--rotation));
  }
}

/* Companion Mood Animations */
@keyframes idle {
  0%, 100% {
    transform: translateY(0);
  }
  50% {
    transform: translateY(-3px);
  }
}

@keyframes bounce {
  0%, 100% {
    transform: translateY(0) scale(1);
  }
  40% {
    transform: translateY(-15px) scale(1.05);
  }
  60% {
    transform: translateY(-8px) scale(1.02);
  }
}

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

@keyframes celebrate {
  0% {
    transform: scale(1) rotate(0deg);
  }
  25% {
    transform: scale(1.15) rotate(-5deg);
  }
  50% {
    transform: scale(1.2) rotate(5deg);
  }
  75% {
    transform: scale(1.15) rotate(-3deg);
  }
  100% {
    transform: scale(1) rotate(0deg);
  }
}

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

@keyframes pulse {
  0%, 100% {
    transform: scale(1);
  }
  50% {
    transform: scale(1.08);
  }
}

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

/* Mood-Specific Body Animations */
[data-mood="thinking"] .companion-head {
  animation: tilt 2s ease-in-out infinite;
}

[data-mood="happy"] .companion-body {
  animation: bounce 1s ease infinite;
}

[data-mood="excited"] .companion-avatar {
  animation: celebrate 0.8s ease;
}

[data-mood="encouraging"] .companion-avatar {
  animation: pulse 1.5s ease infinite;
}

/* Robot-Specific Animations */
.companion-robot .companion-antenna-light {
  animation: robotBlink 1s ease-in-out infinite;
}

@keyframes robotBlink {
  0%, 100% {
    opacity: 1;
  }
  50% {
    opacity: 0.3;
  }
}

.companion-robot[data-mood="thinking"] .companion-screen-text {
  animation: processingText 0.5s steps(3) infinite;
}

@keyframes processingText {
  0% {
    content: "PROCESSING";
  }
  33% {
    content: "PROCESSING.";
  }
  66% {
    content: "PROCESSING..";
  }
  100% {
    content: "PROCESSING...";
  }
}

/* Celebrating State */
.celebrating {
  animation: celebrate 1s ease !important;
}

.celebrating .companion-particles {
  animation: none;
}

/* Thinking State */
.thinking .companion-eyes {
  animation: lookAround 2s ease-in-out infinite;
}

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

/* Interactive Hover Effects */
@media (hover: hover) {
  .companion-avatar:hover {
    transform: scale(1.05);
    cursor: pointer;
  }
  
  .companion-avatar:hover .companion-svg {
    filter: drop-shadow(0 12px 24px rgba(0, 0, 0, 0.2));
  }
}

/* Companion in Check-in Panel */
.checkin-head .learning-companion {
  flex-direction: row-reverse;
  gap: 0.5rem;
}

.checkin-head .companion-speech-bubble {
  position: static;
  transform: none;
  opacity: 1;
  animation: none;
}

.checkin-head .speech-content {
  min-width: auto;
  padding: 0.5rem 0.75rem;
}

.checkin-head .speech-tail {
  display: none;
}

.checkin-head .companion-avatar {
  --companion-size: 60px;
}

/* Reduced Motion */
@media (prefers-reduced-motion: reduce) {
  .companion-avatar,
  .companion-speech-bubble,
  .companion-particles,
  .particle,
  .confetti-piece {
    animation: none !important;
    transition: none !important;
  }
  
  .companion-speech-bubble {
    opacity: 1;
    transform: translateX(-50%);
  }
}

/* Responsive */
@media (max-width: 600px) {
  .companion-medium {
    --companion-size: 80px;
  }
  
  .companion-large {
    --companion-size: 120px;
  }
  
  .speech-content {
    padding: 0.6rem 0.85rem;
    min-width: 120px;
  }
  
  .speech-text {
    font-size: 0.85rem;
  }
}

/* Dark Mode Support (if needed in future) */
@media (prefers-color-scheme: dark) {
  .speech-content {
    background: #2d3748;
    box-shadow: 
      0 4px 12px rgba(0, 0, 0, 0.3),
      0 0 0 1px rgba(255, 255, 255, 0.1);
  }
  
  .speech-tail {
    border-top-color: #2d3748;
  }
  
  .speech-text {
    color: #e2e8f0;
  }
}
