.ai-bubble {
  position: fixed;
  bottom: 20px;
  right: 20px;
  width: 64px;
  height: 64px;
  background: rgba(255,255,255,0.9);
  border-radius: 50%;
  box-shadow: 0 0 10px rgba(0,0,0,0.25);
  cursor: pointer;
  z-index: 5000;
  transition: transform 0.2s ease, box-shadow 0.2s ease;
}

.ai-bubble img {
  width: 100%;
  height: 100%;
  border-radius: 50%;
}

.ai-bubble:hover {
  transform: scale(1.07);
  box-shadow: 0 0 18px rgba(0,0,0,0.35);
}

/* Large modal sliding from right */
.modal-dialog-end {
  position: absolute;
  right: 0;
  margin: 0;
  height: 100%;
}

.ai-highlight {
    background: #fff5f8 !important;
    transition: background 0.4s ease;
}

#ai-panel {
  position: fixed;
  bottom: 80px;
  right: 30px;
  background: #fff;
  border: 2px solid #691929;
  border-radius: 12px;
  padding: 16px;
  box-shadow: 0 4px 20px rgba(0,0,0,0.15);
  width: 280px;
  display: none;
  z-index: 2000;
}

#ai-panel.open {
  display: block;
}

.ai-input-wrapper {
  display: flex;
  align-items: center;
  gap: 0.4rem;
}

#ai-input {
  flex: 1;
  border: 1px solid #ccc;
  border-radius: 6px;
  padding: 0.4rem 0.6rem;
  font-size: 0.95rem;
}

#ai-mic {
  background: #691929;
  border: none;
  color: white;
  font-size: 1rem;
  border-radius: 50%;
  width: 32px;
  height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: all 0.25s ease;
}

#ai-mic:hover {
  background: #8a1e2b;
  transform: scale(1.1);
}

#ai-mic.listening {
  background: #c33;
  box-shadow: 0 0 10px rgba(204, 51, 51, 0.6);
  transform: scale(1.2);
}

let currentUtterance = null;

function speak(text) {
  if (currentUtterance) synth.cancel(); // stop any ongoing speech
  currentUtterance = new SpeechSynthesisUtterance(text);
  currentUtterance.onend = () => (currentUtterance = null);
  synth.speak(currentUtterance);
}

function stopSpeaking() {
  if (synth.speaking) synth.cancel();
}

