/* GUS STYLES -- REVISED */

/* --- Default Hidden State --- */
#chat {
  display: flex;
  flex-direction: column;
  position: fixed;
  width: 90%;
  max-width: 400px;
  max-height: 85vh; /* Taller for less scrolling */
  background: rgba(30, 30, 30, 0.95);
  border-radius: 12px;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.4);
  padding: 1rem;
  z-index: 1000;
  text-align: left;
  bottom: 20px;
  right: 20px;

  /* The Fix: Start hidden and invisible */
  opacity: 0;
  visibility: hidden; /* Add this */
  transform: translateY(20px) scale(0.95);
  transition: opacity 0.3s ease, transform 0.3s ease, visibility 0s 0.3s; /* Delay hiding visibility until after transition */
}

/* --- Toggle Button --- */
#chat-toggle {
  position: fixed;
  bottom: 20px;
  right: 20px;
  font-size: 2rem;
  z-index: 1001; /* Higher than chat window so it's on top initially */
  background: #1e1e1e;
  color: white;
  border-radius: 50%;
  padding: 0.4rem 0.6rem;
  cursor: pointer;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.4);
  display: block;
  transition: opacity 0.3s ease, transform 0.3s ease;
}

/* --- Lift GUS Toggle Above Footer --- */
#chat-toggle.lifted {
  bottom: 100px; /* Lift it up higher to clear footer links */
  transition: bottom 0.3s ease;
}

/* --- THE MAGIC: Styles for when Chat is OPEN --- */

/* This will be the blurred background overlay */
body.chat-open::before {
  content: '';
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0, 0, 0, 0.3);
  /* PERFORMANCE FIX: backdrop-filter is heavy.
     Try commenting it out to see if performance improves.
     You can also try a smaller blur value like blur(4px). */
  /* backdrop-filter: blur(5px); */
  /* -webkit-backdrop-filter: blur(5px); */
  z-index: 999;
}

/* 2. Hide the Toggle Button When Chat is Open */
body.chat-open #chat-toggle {
  opacity: 0;
  pointer-events: none;
  transform: scale(0.8);
}

/* 3. Show and Position the Chat Window */
body.chat-open #chat {
  opacity: 1;
  pointer-events: auto;
  visibility: visible; /* Make it visible */
  transform: translateY(0) scale(1);
  transition: opacity 0.3s ease, transform 0.3s ease, visibility 0s; /* No delay on making visible */

  /* Desktop Sizing (Problem #2 Fix) */
  width: 90%;
  max-width: 400px; /* A bit wider for better layout */
  height: auto;
  max-height: 85vh; /* Taller: 85% of viewport height */
  bottom: 20px;
  right: 20px;
}


/* --- Internal Chat Elements --- */

/* --- PERFORMANCE FIX: Simplified Pulse Animation --- */
/* Your floatEntrance keyframes are fine. */
/* Replace your 'pulseGlow' with this more performant version. */
@keyframes pulseGlow {
  0% { transform: scale(1); }
  50% { transform: scale(1.03); }
  100% { transform: scale(1); }
}

#chat-avatar {
  width: 100%;
  height: auto;
  aspect-ratio: 2 / 3;
  border-radius: 12px;
  display: block;
  margin: 0 auto 1rem;
  object-fit: cover;
  box-shadow: 0 0 16px 4px rgba(124, 198, 255, 0.25);
  transition: transform 0.3s ease, box-shadow 0.3s ease;
}
#chat-avatar:hover {
  transform: scale(1.08);
  box-shadow: 0 0 24px 6px rgba(124, 198, 255, 0.35);
}

#chat-avatar.floating {
  /* ... your other floating styles ... */
  animation: floatEntrance 0.4s ease-out, pulseGlow 2.5s ease-in-out infinite; /* Updated animation name */
}

/* This makes the content area scrollable if it overflows */
.chat-content-wrapper {
    overflow-y: auto;
    padding-right: 10px; /* for scrollbar */
    margin-right: -10px; /* to hide scrollbar visually */
}

#chat-box {
  margin-bottom: 0.75rem;
  font-size: 1rem;
  line-height: 1.5;
  white-space: pre-line;
}

#chat-choices {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  margin-top: auto; /* Pushes choices to the bottom */
  padding-top: 1rem; /* Space above choices */
}

.chat-choice {
  background-color: #444;
  color: white;
  border: none;
  padding: 0.75rem;
  border-radius: 8px;
  cursor: pointer;
  font-size: 0.9rem;
  transition: background 0.3s ease;
}
.chat-choice:hover {
  background-color: #666;
}

#chat-shards {
  margin-top: 0.75rem;
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
}

.shard-link {
  font-size: 0.85rem;
  color: #58a6ff;
  text-decoration: none;
}
.shard-link:hover {
  text-decoration: underline;
}

/* --- Mobile Fullscreen Experience (Problem #3 Fix) --- */
@media (max-width: 600px) {
  body.chat-open #chat {
    width: 100%;
    height: 100%;
    /* Use dynamic viewport height (dvh) if available, with a fallback */
    height: 100vh; /* Fallback for older browsers */
    height: 100dvh; /* Best for modern mobile browsers */
    max-height: 100%;
    bottom: 0;
    right: 0;
    border-radius: 0;
    padding: 1.5rem 1rem;
  }
}