/* src/styles/solstice-presence.css
   The living Solstice companion — breathing glow, smooth movement, bubbles.
*/

/* ── The presence container ─────────────────────────────────────────────────── */
.solstice-presence {
  position: fixed;
  width: 64px;
  height: 64px;
  z-index: 8000;
  cursor: pointer;
  /* Promote the whole avatar to its own GPU compositing layer so its constant
     breathing/glow/ring animations composite in isolation and never force a
     repaint of the page content beneath it (which was making media cards flicker
     where the translucent glow overlapped them). */
  will-change: transform;
  transform: translateZ(0);
  contain: layout style;
  /* Smooth transitions for position (glide mode) */
  transition:
    left 1.5s cubic-bezier(0.4, 0, 0.2, 1),
    top 1.5s cubic-bezier(0.4, 0, 0.2, 1),
    opacity 0.4s ease,
    transform 3s ease-in-out;
}
.solstice-presence.hidden {
  opacity: 0;
  pointer-events: none;
}
.solstice-presence.sp-fading {
  opacity: 0;
}
.solstice-presence.sp-gliding {
  /* faster, more intentional glide */
  transition:
    left 1.5s cubic-bezier(0.34, 1.2, 0.64, 1),
    top 1.5s cubic-bezier(0.34, 1.2, 0.64, 1),
    transform 3s ease-in-out;
}
.solstice-presence.sp-arriving .sp-orb {
  animation: spArrive 1.2s ease-out;
}
@keyframes spArrive {
  0%   { transform: scale(0.2); opacity: 0; }
  60%  { transform: scale(1.1); opacity: 1; }
  100% { transform: scale(1); }
}

/* ── The orb ─────────────────────────────────────────────────────────────────── */
.sp-orb {
  position: relative;
  width: 64px;
  height: 64px;
  border-radius: 50%;
  /* Breathing animation on the whole orb. (Brightness comes from .sp-glow's
     gradient — no box-shadow here, which would repaint every frame as the orb
     scales and was thrashing paint on mobile.) */
  animation: spBreathe 4s ease-in-out infinite;
}
@keyframes spBreathe {
  0%, 100% { transform: scale(1); }
  50%      { transform: scale(1.06); }
}

.sp-avatar {
  position: absolute;
  inset: 3px;
  width: calc(100% - 6px);
  height: calc(100% - 6px);
  border-radius: 50%;
  object-fit: cover;
  z-index: 2;
}

/* Fallback if image fails to load — a glowing orb */
.sp-orb.sp-fallback {
  background: radial-gradient(circle at 40% 35%, #ff6bd6 0%, #a64fff 45%, #4a2b8f 100%);
}

/* ── The breathing glow ─────────────────────────────────────────────────────── */
.sp-glow {
  position: absolute;
  inset: -12px;
  border-radius: 50%;
  background: radial-gradient(circle, rgba(255,120,224,0.95) 0%, rgba(180,90,255,0.62) 40%, rgba(166,79,255,0.22) 60%, transparent 78%);
  z-index: 1;
  animation: spGlowPulse 4s ease-in-out infinite;
}
@keyframes spGlowPulse {
  0%, 100% { opacity: 0.8;  transform: scale(1); }
  50%      { opacity: 1;    transform: scale(1.14); }
}

/* ── The rotating ring ──────────────────────────────────────────────────────── */
.sp-ring {
  position: absolute;
  inset: -2px;
  border-radius: 50%;
  border: 2px solid transparent;
  border-top-color: rgba(255,107,214,0.8);
  border-right-color: rgba(166,79,255,0.5);
  z-index: 3;
  animation: spRingSpin 8s linear infinite;
}
@keyframes spRingSpin {
  from { transform: rotate(0deg); }
  to   { transform: rotate(360deg); }
}

/* When speaking, the glow intensifies */
.solstice-presence.sp-speaking .sp-glow {
  animation-duration: 2s;
}
.solstice-presence.sp-speaking .sp-orb {
  animation-duration: 2s;
}

/* ── Speech bubble ──────────────────────────────────────────────────────────── */
.sp-bubble {
  position: absolute;
  bottom: 78px;
  right: 0;
  min-width: 200px;
  max-width: 280px;
  background: rgba(20, 14, 38, 0.97);
  border: 1px solid rgba(180, 150, 255, 0.3);
  border-radius: 16px;
  padding: 14px 16px 14px 16px;
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.5), 0 0 24px rgba(166, 79, 255, 0.15);
  backdrop-filter: blur(8px);
  animation: spBubbleIn 0.35s cubic-bezier(0.34, 1.4, 0.64, 1);
  z-index: 10;
}
.sp-bubble[hidden] { display: none; }
@keyframes spBubbleIn {
  from { opacity: 0; transform: translateY(8px) scale(0.94); }
  to   { opacity: 1; transform: translateY(0) scale(1); }
}
/* little tail pointing to the orb */
.sp-bubble::after {
  content: "";
  position: absolute;
  bottom: -7px;
  right: 24px;
  width: 14px;
  height: 14px;
  background: rgba(20, 14, 38, 0.97);
  border-right: 1px solid rgba(180, 150, 255, 0.3);
  border-bottom: 1px solid rgba(180, 150, 255, 0.3);
  transform: rotate(45deg);
}
/* When bubble opens to the right (orb on left), tail points from the left */
.sp-bubble.sp-bubble-left::after {
  right: auto;
  left: 24px;
}
.sp-bubble.sp-bubble-right::after {
  right: 24px;
  left: auto;
}
/* When there isn't room above the orb, the bubble opens below it instead of
   clipping off the top of the window. */
.sp-bubble.sp-bubble-below {
  bottom: auto;
  top: 78px;
}
.sp-bubble.sp-bubble-below::after {
  bottom: auto;
  top: -7px;
  border-right: none;
  border-bottom: none;
  border-left: 1px solid rgba(180, 150, 255, 0.3);
  border-top: 1px solid rgba(180, 150, 255, 0.3);
}

.sp-bubble-text {
  color: #e8dcff;
  font-size: 0.88rem;
  line-height: 1.5;
  margin-bottom: 0;
}
.sp-bubble-action {
  margin-top: 10px;
  width: 100%;
  padding: 8px 12px;
  border-radius: 20px;
  border: none;
  background: linear-gradient(135deg, #5ec6ff 0%, #a64fff 100%);
  color: #fff;
  font-size: 0.82rem;
  font-weight: 600;
  cursor: pointer;
  transition: opacity 0.15s;
}
.sp-bubble-action:hover { opacity: 0.9; }
.sp-bubble-dismiss {
  position: absolute;
  top: 8px;
  right: 10px;
  background: none;
  border: none;
  color: rgba(255,255,255,0.4);
  font-size: 1.1rem;
  cursor: pointer;
  line-height: 1;
  padding: 2px;
}
.sp-bubble-dismiss:hover { color: rgba(255,255,255,0.8); }

/* ── Intro card ─────────────────────────────────────────────────────────────── */
.sp-intro-card {
  position: fixed;
  bottom: 24px;
  right: 24px;
  width: min(380px, calc(100vw - 48px));
  background: rgba(16, 11, 30, 0.98);
  border: 1px solid rgba(180, 150, 255, 0.28);
  border-radius: 20px;
  padding: 20px;
  display: flex;
  gap: 16px;
  align-items: flex-start;
  box-shadow: 0 24px 60px rgba(0,0,0,0.6), 0 0 40px rgba(166,79,255,0.18);
  z-index: 100050;
  pointer-events: auto;
  animation: spIntroIn 0.5s cubic-bezier(0.34, 1.3, 0.64, 1);
}
@keyframes spIntroIn {
  from { opacity: 0; transform: translateY(20px) scale(0.95); }
  to   { opacity: 1; transform: translateY(0) scale(1); }
}
.sp-intro-card.sp-intro-closing {
  animation: spIntroOut 0.5s ease forwards;
}
@keyframes spIntroOut {
  to { opacity: 0; transform: translateY(20px) scale(0.9); }
}
.sp-intro-avatar {
  flex-shrink: 0;
  width: 64px;
  height: 64px;
  border-radius: 50%;
  overflow: hidden;
  border: 2px solid rgba(255,107,214,0.5);
  box-shadow: 0 0 20px rgba(255,107,214,0.3);
  animation: spBreathe 4s ease-in-out infinite;
}
.sp-intro-avatar img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}
.sp-intro-title {
  margin: 0 0 6px;
  font-size: 1.1rem;
  font-weight: 700;
  color: #e8dcff;
}
.sp-intro-text {
  margin: 0 0 14px;
  font-size: 0.85rem;
  line-height: 1.5;
  color: rgba(220, 210, 255, 0.75);
}
.sp-intro-btn {
  padding: 9px 18px;
  border-radius: 22px;
  border: none;
  background: linear-gradient(135deg, #5ec6ff 0%, #a64fff 100%);
  color: #fff;
  font-size: 0.85rem;
  font-weight: 600;
  cursor: pointer;
  transition: opacity 0.15s, transform 0.15s;
  pointer-events: auto;
  position: relative;
  z-index: 100051;
}
.sp-intro-btn:hover { opacity: 0.92; transform: translateY(-1px); }


/* ── Question chips in bubble ───────────────────────────────────────────────── */
.sp-chips {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-top: 10px;
}
.sp-chip {
  text-align: left;
  padding: 8px 12px;
  border-radius: 12px;
  border: 1px solid rgba(180, 150, 255, 0.25);
  background: rgba(130, 100, 255, 0.08);
  color: rgba(220, 210, 255, 0.85);
  font-size: 0.8rem;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s;
}
.sp-chip:hover {
  background: rgba(130, 100, 255, 0.22);
  border-color: rgba(180, 150, 255, 0.5);
  color: #e8dcff;
}
.sp-bubble { max-width: 300px; }

/* ── Mobile adjustments ─────────────────────────────────────────────────────── */
@media (max-width: 600px) {
  .solstice-presence { width: 50px; height: 50px; }
  /* Pause the breathing scale on mobile (scaling repaints the orb every frame);
     the glow's opacity pulse below still keeps her feeling alive. */
  .sp-orb { width: 50px; height: 50px; animation: none; }
  /* Mobile glow: pulse opacity only, never scale — so it can't grow its paint
     area frame-to-frame and flicker where it overlaps the media cards. */
  .sp-glow { animation: spGlowLite 4s ease-in-out infinite; }
  @keyframes spGlowLite { 0%, 100% { opacity: 0.75; } 50% { opacity: 1; } }
  .sp-bubble {
    max-width: calc(100vw - 32px);
    min-width: 0;
  }
  .sp-chip { font-size: 0.82rem; padding: 9px 12px; }
}

/* Respect reduced-motion preferences */
@media (prefers-reduced-motion: reduce) {
  .sp-orb, .sp-glow, .sp-ring, .sp-intro-avatar {
    animation: none !important;
  }
  .solstice-presence {
    transition: opacity 0.4s ease;
  }
}
