/* ============================================================
   THEO — SideQuest AI Spirit Guide
   Floating avatar + conversation component
   ============================================================ */

/* ============ FONTS ============ */
@import url('https://fonts.googleapis.com/css2?family=Cinzel:wght@400;700&family=Cormorant+Garamond:ital,wght@0,300;0,400;0,600;1,400&family=Space+Mono:wght@400;700&display=swap');

/* ============ VARIABLES ============ */
:root {
  --theo-primary: #FFB800;
  --theo-primary-dim: rgba(255,184,0,0.5);
  --theo-purple: #9b5de5;
  --theo-cyan: #00f5d4;
  --theo-magenta: #f15bb5;
  --theo-bg: #07060b;
  --theo-text: #e8e2d8;
  --theo-dim: #5a5468;
  --theo-accent: #9b5de5;
}

/* ============ THEO WRAPPER ============ */
.theo-zone {
  position: fixed;
  bottom: 28px;
  right: 28px;
  z-index: 9999;
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 10px;
  pointer-events: none;
}

.theo-zone > * {
  pointer-events: auto;
}

/* ============ THEO AVATAR ============ */
.theo-avatar {
  position: relative;
  width: 120px;
  height: 120px;
  cursor: pointer;
  animation: theoHover 5s ease-in-out infinite;
  transition: transform 0.3s;
}

.theo-avatar:hover {
  transform: scale(1.05);
}

.theo-avatar:active {
  transform: scale(0.97);
}

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

/* Portrait image */
.theo-portrait {
  width: 100%;
  height: 100%;
  border-radius: 50%;
  object-fit: cover;
  position: relative;
  z-index: 2;
  border: 2px solid rgba(155,93,229,0.4);
  box-shadow:
    0 0 20px rgba(155,93,229,0.25),
    0 0 40px rgba(155,93,229,0.1),
    inset 0 0 20px rgba(0,0,0,0.3);
  transition: border-color 0.6s, box-shadow 0.6s;
}

.theo-avatar:hover .theo-portrait {
  border-color: rgba(255,184,0,0.6);
  box-shadow:
    0 0 25px rgba(255,184,0,0.3),
    0 0 50px rgba(155,93,229,0.15),
    inset 0 0 20px rgba(0,0,0,0.2);
}

/* Rotating dashed gold ring */
.theo-ring {
  position: absolute;
  inset: -6px;
  border-radius: 50%;
  border: 1px dashed rgba(255,184,0,0.35);
  animation: ringRotate 20s linear infinite;
  z-index: 1;
  transition: border-color 0.6s;
}

/* Second outer ring, reverse */
.theo-ring-2 {
  position: absolute;
  inset: -14px;
  border-radius: 50%;
  border: 1px solid rgba(155,93,229,0.15);
  animation: ringRotate 30s linear infinite reverse;
  z-index: 0;
  transition: border-color 0.6s;
}

@keyframes ringRotate {
  from { transform: rotate(0deg); }
  to { transform: rotate(360deg); }
}

/* Glow pulse behind avatar */
.theo-glow {
  position: absolute;
  inset: -20px;
  border-radius: 50%;
  background: radial-gradient(circle, rgba(155,93,229,0.15) 0%, rgba(241,91,181,0.05) 50%, transparent 70%);
  animation: glowPulse 4s ease-in-out infinite;
  z-index: 0;
  pointer-events: none;
  transition: background 0.6s;
}

@keyframes glowPulse {
  0%, 100% { opacity: 0.5; transform: scale(1); }
  50% { opacity: 0.9; transform: scale(1.08); }
}

/* Orbiting particles */
.orbit-particle {
  position: absolute;
  width: var(--size);
  height: var(--size);
  border-radius: 50%;
  background: var(--color);
  box-shadow: 0 0 8px var(--color);
  z-index: 3;
  animation: orbitAround var(--dur) var(--delay) linear infinite;
  pointer-events: none;
}

@keyframes orbitAround {
  from {
    transform: rotate(var(--start)) translateX(var(--radius)) rotate(calc(-1 * var(--start)));
    opacity: 0.7;
  }
  to {
    transform: rotate(calc(var(--start) + 360deg)) translateX(var(--radius)) rotate(calc(-1 * (var(--start) + 360deg)));
    opacity: 0.7;
  }
}

/* THEO label */
.theo-name {
  position: absolute;
  bottom: -20px;
  left: 50%;
  transform: translateX(-50%);
  font-family: 'Space Mono', monospace;
  font-size: 9px;
  letter-spacing: 4px;
  color: var(--theo-dim);
  text-transform: uppercase;
  z-index: 5;
}

/* Status indicator (green dot) */
.theo-status {
  position: absolute;
  bottom: 6px;
  right: 6px;
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: #48BB78;
  border: 2px solid var(--theo-bg);
  z-index: 5;
  animation: statusPulse 3s ease-in-out infinite;
}

@keyframes statusPulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(72,187,120,0.4); }
  50% { box-shadow: 0 0 0 5px rgba(72,187,120,0); }
}

/* ============ CONVERSATION BUBBLES ============ */
.theo-convo {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 8px;
  max-width: 320px;
  opacity: 0;
  transform: translateY(10px) scale(0.97);
  transition: all 0.4s cubic-bezier(0.22, 1, 0.36, 1);
  pointer-events: none;
}

.theo-convo.open {
  opacity: 1;
  transform: translateY(0) scale(1);
  pointer-events: all;
}

/* Message bubble */
.theo-msg {
  padding: 12px 16px;
  border-radius: 14px;
  font-size: 14.5px;
  line-height: 1.55;
  backdrop-filter: blur(24px);
  -webkit-backdrop-filter: blur(24px);
  opacity: 0;
  transform: translateY(6px);
  animation: theoMsgIn 0.35s ease forwards;
  max-width: 290px;
}

.theo-msg:nth-child(1) { animation-delay: 0s; }
.theo-msg:nth-child(2) { animation-delay: 0.12s; }
.theo-msg:nth-child(3) { animation-delay: 0.24s; }
.theo-msg:nth-child(4) { animation-delay: 0.36s; }

@keyframes theoMsgIn {
  to { opacity: 1; transform: translateY(0); }
}

/* Theo's messages */
.theo-msg.from-theo {
  background: rgba(12,10,20,0.85);
  border: 1px solid rgba(155,93,229,0.2);
  color: #d4c8f0;
  align-self: flex-end;
  border-bottom-right-radius: 4px;
  font-family: 'Cormorant Garamond', serif;
  position: relative;
}

.theo-msg .theo-tag {
  font-family: 'Space Mono', monospace;
  font-size: 8px;
  letter-spacing: 2px;
  color: var(--theo-purple);
  text-transform: uppercase;
  display: block;
  margin-bottom: 4px;
  opacity: 0.7;
}

/* User's messages */
.theo-msg.from-user {
  background: rgba(255,255,255,0.05);
  border: 1px solid rgba(255,255,255,0.07);
  color: var(--theo-text);
  align-self: flex-start;
  border-bottom-left-radius: 4px;
  font-family: 'Cormorant Garamond', serif;
}

/* Typing dots */
.theo-typing-dots {
  display: flex;
  gap: 5px;
  padding: 4px 0;
}

.theo-typing-dots span {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--theo-purple);
  animation: theoDotBounce 1.4s ease-in-out infinite;
}

.theo-typing-dots span:nth-child(2) { animation-delay: 0.15s; }
.theo-typing-dots span:nth-child(3) { animation-delay: 0.3s; }

@keyframes theoDotBounce {
  0%, 80%, 100% { opacity: 0.3; transform: translateY(0); }
  40% { opacity: 1; transform: translateY(-5px); }
}

/* ============ INPUT BAR ============ */
.theo-input-bar {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
  max-width: 290px;
  opacity: 0;
  transform: translateY(6px);
  transition: all 0.4s 0.15s cubic-bezier(0.22, 1, 0.36, 1);
  pointer-events: none;
}

.theo-input-bar.open {
  opacity: 1;
  transform: translateY(0);
  pointer-events: all;
}

.theo-text-input {
  flex: 1;
  background: transparent;
  border: none;
  border-bottom: 1px solid rgba(155,93,229,0.3);
  padding: 10px 2px;
  color: var(--theo-text);
  font-family: 'Cormorant Garamond', serif;
  font-size: 15px;
  outline: none;
  transition: border-color 0.3s;
}

.theo-text-input::placeholder {
  color: var(--theo-dim);
  font-style: italic;
  font-size: 13px;
}

.theo-text-input:focus {
  border-color: var(--theo-purple);
}

.theo-icon-btn {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  border: 1px solid rgba(155,93,229,0.25);
  background: rgba(155,93,229,0.06);
  color: var(--theo-purple);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 13px;
  transition: all 0.3s;
  padding: 0;
}

.theo-icon-btn:hover {
  background: rgba(155,93,229,0.15);
  border-color: rgba(155,93,229,0.5);
  box-shadow: 0 0 16px rgba(155,93,229,0.2);
}

/* ============ SPEAKING / LISTENING STATES ============ */
.theo-avatar.speaking .theo-portrait {
  border-color: var(--theo-purple);
  box-shadow:
    0 0 20px rgba(155,93,229,0.4),
    0 0 40px rgba(155,93,229,0.2);
  animation: theoHover 5s ease-in-out infinite, theoSpeakPulse 0.6s ease-in-out infinite;
}

@keyframes theoSpeakPulse {
  0%, 100% { border-width: 2px; }
  50% { border-width: 3px; }
}

.theo-avatar.listening .theo-ring {
  border-color: rgba(0,245,212,0.5);
  animation-duration: 8s;
}

.theo-avatar.thinking .theo-ring {
  animation-duration: 4s;
}

.theo-avatar.thinking .theo-ring-2 {
  animation-duration: 6s;
}

/* ============ CLOSE BUTTON ============ */
.theo-close-btn {
  position: absolute;
  top: -8px;
  right: -8px;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: rgba(12,10,20,0.8);
  border: 1px solid rgba(155,93,229,0.2);
  color: var(--theo-dim);
  font-size: 10px;
  cursor: pointer;
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 10;
  transition: all 0.2s;
}

.theo-convo.open ~ .theo-input-bar.open ~ .theo-avatar .theo-close-btn {
  display: flex;
}

.theo-close-btn:hover {
  color: var(--theo-text);
  border-color: rgba(155,93,229,0.5);
}

/* ============ REDUCED MOTION ============ */
@media (prefers-reduced-motion: reduce) {
  .theo-avatar,
  .theo-ring,
  .theo-ring-2,
  .theo-glow,
  .orbit-particle,
  .theo-status {
    animation: none !important;
  }
  .theo-msg {
    animation: none !important;
    opacity: 1 !important;
    transform: none !important;
  }
}

/* ============ RESPONSIVE ============ */
@media (max-width: 768px) {
  .theo-zone {
    right: 16px;
    bottom: 72px;
  }
  .theo-avatar {
    width: 80px;
    height: 80px;
  }
  .theo-msg {
    max-width: 200px;
    font-size: 13px;
    padding: 10px 12px;
  }
  .theo-convo {
    max-width: 220px;
  }
  .theo-input-bar {
    max-width: 200px;
  }
  .theo-name {
    font-size: 7px;
    letter-spacing: 3px;
  }
}
