/* ===== Buddy Character System ===== */

.buddy-container {
  position: fixed;
  bottom: 20px;
  right: 20px;
  z-index: 9999;
  pointer-events: none;
  font-family: 'Inter', sans-serif;
}
.buddy-container * { pointer-events: auto; }

/* Character wrapper */
.buddy-character {
  position: relative;
  width: 140px;
  height: 170px;
  cursor: pointer;
  animation: buddy-entrance 0.6s cubic-bezier(0.34, 1.56, 0.64, 1) forwards;
  transform-origin: bottom center;
  transition: transform 0.2s;
}
.buddy-character::after {
  content: '';
  position: absolute;
  bottom: 20px;
  left: 25%;
  width: 90%;
  height: 100%;
  background: radial-gradient(ellipse at 50% 80%, rgba(0,0,0,0.25) 0%, rgba(0,0,0,0.08) 40%, transparent 70%);
  border-radius: 50%;
  transform: skewX(-15deg) skewY(-10deg) scaleY(0.6);
  transform-origin: bottom center;
  pointer-events: none;
  z-index: -1;
}
.buddy-character:hover {
  transform: scale(1.08);
}
.buddy-character.buddy-exit {
  animation: buddy-exit 0.4s ease-in forwards;
}
.buddy-character svg {
  width: 100%;
  height: 100%;
}

/* Floating idle animation */
.buddy-character.buddy-idle {
  animation: buddy-float 3s ease-in-out infinite;
}

/* Speech bubble */
.buddy-speech {
  position: absolute;
  bottom: 175px;
  right: 0;
  background: #fff;
  border: 2px solid #e8e4df;
  border-radius: 16px 16px 4px 16px;
  padding: 14px 18px;
  max-width: 260px;
  min-width: 160px;
  box-shadow: 0 8px 32px rgba(0,0,0,0.12);
  animation: buddy-bubble-in 0.35s cubic-bezier(0.34, 1.56, 0.64, 1) forwards;
  transform-origin: bottom right;
}
.buddy-speech::after {
  content: '';
  position: absolute;
  bottom: -10px;
  right: 20px;
  width: 0; height: 0;
  border-left: 10px solid transparent;
  border-right: 10px solid transparent;
  border-top: 10px solid #fff;
  filter: drop-shadow(0 2px 2px rgba(0,0,0,0.06));
}
.buddy-speech-text {
  font-size: 14px;
  line-height: 1.5;
  color: #2c2c2c;
  font-weight: 500;
}
.buddy-speech-name {
  font-size: 11px;
  font-weight: 700;
  color: #c4b8a5;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin-bottom: 4px;
}
.buddy-speech-close {
  position: absolute;
  top: 6px;
  right: 10px;
  background: none;
  border: none;
  font-size: 16px;
  color: #ccc;
  cursor: pointer;
  line-height: 1;
}
.buddy-speech-close:hover { color: #888; }

/* Pulsing glow to invite hover/interaction */
.buddy-speech {
  animation: buddy-bubble-in 0.35s cubic-bezier(0.34, 1.56, 0.64, 1) forwards,
             buddy-speech-glow 2s ease-in-out 1s infinite;
}
@keyframes buddy-speech-glow {
  0%, 100% { box-shadow: 0 8px 32px rgba(0,0,0,0.12); }
  50% { box-shadow: 0 8px 32px rgba(0,0,0,0.12), 0 0 16px rgba(196,184,165,0.5); }
}

/* Chat panel */
.buddy-chat {
  position: absolute;
  bottom: 175px;
  right: 0;
  width: 320px;
  max-height: 420px;
  background: #fff;
  border: 2px solid #e8e4df;
  border-radius: 16px;
  box-shadow: 0 12px 48px rgba(0,0,0,0.15);
  display: flex;
  flex-direction: column;
  animation: buddy-bubble-in 0.3s cubic-bezier(0.34, 1.56, 0.64, 1) forwards;
  transform-origin: bottom right;
  overflow: hidden;
}
.buddy-chat-header {
  padding: 12px 16px;
  background: linear-gradient(135deg, #2c2c2c, #3d3d3d);
  color: #f5f0eb;
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-shrink: 0;
}
.buddy-chat-header-info {
  display: flex;
  align-items: center;
  gap: 8px;
}
.buddy-chat-avatar {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  overflow: hidden;
}
.buddy-chat-avatar svg {
  width: 100%;
  height: 100%;
}
.buddy-chat-name {
  font-size: 13px;
  font-weight: 700;
}
.buddy-chat-close {
  background: none;
  border: none;
  color: #999;
  font-size: 18px;
  cursor: pointer;
  line-height: 1;
  padding: 0;
}
.buddy-chat-close:hover { color: #fff; }

.buddy-chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 12px 16px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  max-height: 260px;
  min-height: 100px;
}
.buddy-msg {
  max-width: 85%;
  padding: 10px 14px;
  border-radius: 14px;
  font-size: 13px;
  line-height: 1.5;
  word-wrap: break-word;
}
.buddy-msg-char {
  align-self: flex-start;
  background: #f5f0eb;
  color: #2c2c2c;
  border-bottom-left-radius: 4px;
}
.buddy-msg-user {
  align-self: flex-end;
  background: #2c2c2c;
  color: #f5f0eb;
  border-bottom-right-radius: 4px;
}
.buddy-msg-typing {
  align-self: flex-start;
  background: #f5f0eb;
  color: #999;
  font-style: italic;
  border-bottom-left-radius: 4px;
}

.buddy-chat-input {
  display: flex;
  gap: 6px;
  padding: 10px 12px;
  border-top: 1px solid #e8e4df;
  background: #faf8f5;
  flex-shrink: 0;
  align-items: center;
}
.buddy-chat-input input {
  flex: 1;
  border: 1px solid #e0dcd7;
  border-radius: 20px;
  padding: 8px 14px;
  font-size: 13px;
  font-family: 'Inter', sans-serif;
  outline: none;
  background: #fff;
  color: #2c2c2c;
}
.buddy-chat-input input:focus {
  border-color: #c4b8a5;
}
.buddy-chat-input button {
  width: 32px;
  height: 32px;
  border: none;
  border-radius: 50%;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s;
  flex-shrink: 0;
}
.buddy-btn-send {
  background: #2c2c2c;
  color: #f5f0eb;
}
.buddy-btn-send:hover { background: #444; }
.buddy-btn-mic {
  background: #e8e4df;
  color: #888;
}
.buddy-btn-mic:hover { background: #d4cfc8; color: #555; }
.buddy-btn-mic.buddy-mic-active {
  background: #ef4444;
  color: #fff;
  animation: buddy-pulse 1.5s ease-in-out infinite;
}
.buddy-btn-cam {
  background: #e8e4df;
  color: #888;
}
.buddy-btn-cam:hover { background: #d4cfc8; color: #555; }

/* Mic prompt */
.buddy-mic-prompt {
  font-size: 11px;
  color: #c4b8a5;
  text-align: center;
  padding: 4px 12px 8px;
  background: #faf8f5;
}

/* Dismiss button */
.buddy-dismiss {
  position: absolute;
  top: -8px;
  left: -8px;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  border: 2px solid #e8e4df;
  background: #fff;
  color: #999;
  font-size: 12px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  line-height: 1;
  opacity: 0;
  transition: opacity 0.2s;
}
.buddy-character:hover .buddy-dismiss { opacity: 1; }
.buddy-dismiss:hover { background: #ef4444; color: #fff; border-color: #ef4444; }

/* Sound indicator */
.buddy-sound-icon {
  position: absolute;
  top: 10px;
  right: 10px;
  font-size: 16px;
  animation: buddy-sound-pop 0.5s ease forwards;
  pointer-events: none;
}

/* ===== Wing animation for fairy ===== */
.buddy-wing-l { animation: buddy-wing-flap-l 0.8s ease-in-out infinite; transform-origin: 55px 65px; }
.buddy-wing-r { animation: buddy-wing-flap-r 0.8s ease-in-out infinite; transform-origin: 65px 65px; }
.buddy-sparkle { animation: buddy-sparkle-twinkle 1.2s ease-in-out infinite; }
.buddy-sparkle:nth-child(2) { animation-delay: 0.4s; }
.buddy-sparkle:nth-child(3) { animation-delay: 0.8s; }

/* ===== Robot eye blink ===== */
.buddy-robot-eye { animation: buddy-blink 4s ease-in-out infinite; }

/* ===== Wizard staff glow ===== */
.buddy-staff-glow { animation: buddy-glow-pulse 2s ease-in-out infinite; }

/* ===== Animations ===== */
@keyframes buddy-entrance {
  0% { transform: translateY(100px) scale(0.3); opacity: 0; }
  60% { transform: translateY(-10px) scale(1.05); opacity: 1; }
  100% { transform: translateY(0) scale(1); opacity: 1; }
}
@keyframes buddy-exit {
  0% { transform: translateY(0) scale(1); opacity: 1; }
  100% { transform: translateY(80px) scale(0.3); opacity: 0; }
}
@keyframes buddy-float {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-8px); }
}
@keyframes buddy-bubble-in {
  0% { transform: scale(0.5); opacity: 0; }
  100% { transform: scale(1); opacity: 1; }
}
@keyframes buddy-pulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(239,68,68,0.4); }
  50% { box-shadow: 0 0 0 8px rgba(239,68,68,0); }
}
@keyframes buddy-wing-flap-l {
  0%, 100% { transform: rotate(0deg) scaleX(1); }
  50% { transform: rotate(-15deg) scaleX(0.85); }
}
@keyframes buddy-wing-flap-r {
  0%, 100% { transform: rotate(0deg) scaleX(1); }
  50% { transform: rotate(15deg) scaleX(0.85); }
}
@keyframes buddy-sparkle-twinkle {
  0%, 100% { opacity: 1; r: 2; }
  50% { opacity: 0.2; r: 0.5; }
}
@keyframes buddy-blink {
  0%, 44%, 48%, 100% { transform: scaleY(1); }
  46% { transform: scaleY(0.1); }
}
@keyframes buddy-glow-pulse {
  0%, 100% { opacity: 0.5; }
  50% { opacity: 1; }
}

/* Enelin wink (one eye) */
.buddy-wink { animation: buddy-wink 5s ease-in-out infinite; }
@keyframes buddy-wink {
  0%, 38%, 42%, 100% { transform: scaleY(1); }
  40% { transform: scaleY(0.05); }
}

/* Ace eyebrow raise (both) */
.buddy-brow-raise { animation: buddy-brow-raise 4s ease-in-out infinite; }
@keyframes buddy-brow-raise {
  0%, 40%, 55%, 100% { transform: translateY(0); }
  45%, 50% { transform: translateY(-3px); }
}

/* Josef hand wave */
.buddy-wave { animation: buddy-wave 2.5s ease-in-out infinite; transform-origin: 116px 62px; }
@keyframes buddy-wave {
  0%, 100% { transform: rotate(0deg); }
  25% { transform: rotate(-10deg); }
  50% { transform: rotate(10deg); }
  75% { transform: rotate(-5deg); }
}

/* Reel head slow spin */
.buddy-reel-spin { animation: buddy-reel-spin 8s linear infinite; transform-origin: 60px 44px; }
@keyframes buddy-reel-spin {
  0% { transform: rotate(0deg); }
  100% { transform: rotate(360deg); }
}

@keyframes buddy-sound-pop {
  0% { transform: scale(0); opacity: 1; }
  50% { transform: scale(1.3); }
  100% { transform: scale(1) translateY(-20px); opacity: 0; }
}

/* Cosmo floating effect — shadow lower to suggest hovering */
.buddy-character[data-buddy-type="alien"]::after {
  bottom: -12px;
}

/* ===== Responsive ===== */
@media (max-width: 600px) {
  .buddy-container { bottom: 12px; right: 12px; }
  .buddy-character { width: 100px; height: 120px; }
  .buddy-speech { bottom: 125px; max-width: 200px; }
  .buddy-chat { bottom: 125px; width: 280px; }
}
