#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();
}

