/* Avatar Animations and Styles */

/* Idle bob animation */
@keyframes avatar-bob {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-1.5px); }
}

/* Eye blink animation */
@keyframes avatar-blink {
  0%, 92%, 100% { transform: scaleY(1); }
  95% { transform: scaleY(0.1); }
}

/* Legacy mouth open/close cycle (fallback if viseme system not loaded) */
@keyframes avatar-mouth-1 {
  0%, 100% { transform: scaleY(0.6) scaleX(0.8); }
  50% { transform: scaleY(1.2) scaleX(1); }
}

@keyframes avatar-mouth-2 {
  0%, 100% { transform: scaleY(1.1) scaleX(1); }
  50% { transform: scaleY(0.5) scaleX(0.9); }
}

/* Thinking pulse */
@keyframes avatar-think {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.7; }
}

/* Avatar container */
.avatar-container {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.avatar-container svg {
  animation: avatar-bob 3s ease-in-out infinite;
}

/* Eye blink */
.avatar-container .avatar-eyes {
  animation: avatar-blink 4s ease-in-out infinite;
}

/* ── Viseme mouth shapes ── */

/* All viseme groups hidden by default except rest */
.avatar-container .avatar-viseme {
  display: none;
}
.avatar-container .avatar-viseme-rest {
  display: block;
}

/* Nasal indicator hidden by default (toggled by JS) */
.avatar-container .avatar-nasal {
  display: none;
}

/* Legacy mouth elements hidden by default (kept for fallback) */
.avatar-container .avatar-mouth-open-1,
.avatar-container .avatar-mouth-open-2 {
  display: none;
}

/* ── Speaking state ── */

/* When speaking, hide rest viseme (scheduler will show the active viseme via JS) */
.avatar-container.speaking .avatar-viseme-rest {
  display: none;
}

/* Legacy fallback: if viseme scheduler isn't running, show ee shape as default open mouth */
.avatar-container.speaking .avatar-viseme-ee {
  display: block;
}

/* Thinking state */
.avatar-container.thinking svg {
  animation: avatar-think 1.5s ease-in-out infinite;
}

/* Happy state - slightly bigger smile */
.avatar-container.happy .avatar-viseme-rest {
  transform: scaleX(1.15) scaleY(1.1);
}

/* Floating avatar for simplifier */
.avatar-floating {
  position: fixed;
  bottom: 1.5rem;
  left: 1.5rem;
  z-index: 40;
  transition: opacity 0.3s ease, transform 0.3s ease;
}
.avatar-floating.hidden {
  opacity: 0;
  transform: scale(0.8);
  pointer-events: none;
}

/* ── Hero avatar (video-call layout) ── */

.avatar-hero {
  display: flex;
  justify-content: center;
  padding: 1rem 0 0.5rem;
}

.avatar-hero .avatar-container {
  filter: drop-shadow(0 4px 12px rgba(0, 0, 0, 0.1));
}

/* Responsive hero sizing */
.avatar-hero svg {
  width: 200px;
  height: 200px;
}

@media (min-width: 640px) {
  .avatar-hero svg {
    width: 280px;
    height: 280px;
  }
}

@media (min-width: 1024px) {
  .avatar-hero svg {
    width: 320px;
    height: 320px;
  }
}

/* Short screens: shrink hero avatar */
@media (max-height: 500px) {
  .avatar-hero svg {
    width: 150px;
    height: 150px;
  }
}

/* Maximized chat: larger hero */
.chat-maximized .avatar-hero svg {
  width: 260px;
  height: 260px;
}

@media (min-width: 640px) {
  .chat-maximized .avatar-hero svg {
    width: 340px;
    height: 340px;
  }
}

@media (min-width: 1024px) {
  .chat-maximized .avatar-hero svg {
    width: 380px;
    height: 380px;
  }
}

/* Status indicator */
.avatar-status {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.375rem;
  padding: 0.25rem 0 0.5rem;
  font-size: 0.75rem;
  color: #64748b;
}

.avatar-status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #22c55e;
  animation: status-pulse 2s ease-in-out infinite;
}

.avatar-status-dot.thinking {
  background: #f59e0b;
}

.avatar-status-dot.speaking {
  background: #22c55e;
}

@keyframes status-pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.5; }
}

/* Viseme label log */
.viseme-label {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  padding: 0.5rem 1rem;
  min-height: 0;
  max-height: 8rem;
  overflow-y: auto;
}

.viseme-word-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 4px 6px;
}

.viseme-word-chip {
  display: inline-block;
  font-family: 'Courier New', monospace;
  font-size: 1.05rem;
  font-weight: 700;
  color: #1e40af;
  background: #dbeafe;
  border: 2px solid #93c5fd;
  border-radius: 8px;
  padding: 4px 12px;
  white-space: nowrap;
  line-height: 1.5;
  cursor: pointer;
  transition: background 0.15s;
}

.viseme-word-chip:hover {
  background: #bfdbfe;
  border-color: #60a5fa;
}

.viseme-tag {
  display: inline-block;
  font-family: 'Courier New', monospace;
  font-size: 1rem;
  font-weight: 600;
  color: #475569;
  background: #f1f5f9;
  border: 1px solid #e2e8f0;
  border-radius: 6px;
  padding: 4px 10px;
  white-space: nowrap;
  line-height: 1.5;
  cursor: pointer;
  transition: background 0.15s;
}

.viseme-tag:hover {
  background: #dbeafe;
  border-color: #93c5fd;
}

.viseme-tag.nasal {
  border-color: #c4b5fd;
  background: #f5f3ff;
}


/* ── Reduced motion: disable all animations, static indicator ── */
@media (prefers-reduced-motion: reduce) {
  .avatar-container svg,
  .avatar-container .avatar-eyes {
    animation: none !important;
  }

  /* Static open mouth (ah shape) when speaking */
  .avatar-container.speaking .avatar-viseme-rest {
    display: none;
  }
  .avatar-container.speaking .avatar-viseme-ee {
    display: none;
  }
  .avatar-container.speaking .avatar-viseme-ah {
    display: block;
  }

  /* Hide legacy elements */
  .avatar-container .avatar-mouth-open-1,
  .avatar-container .avatar-mouth-open-2 {
    display: none !important;
  }
}
