/* Voice control: floating mic FAB + status pill + first-time cue */

/* ---------- FAB ---------------------------------------------------------- */
#voiceBtn {
  position: fixed;
  bottom: 24px;
  right: 24px;
  z-index: 10001;

  width: 60px;
  height: 60px;
  border-radius: 50%;
  border: 2px solid rgba(255, 211, 101, 0.55);
  background: linear-gradient(135deg, #FF9E42 0%, #FFD365 100%);
  color: #1a1a1a;
  cursor: pointer;
  padding: 0;
  display: flex;
  align-items: center;
  justify-content: center;

  box-shadow:
    0 8px 28px rgba(0, 0, 0, 0.55),
    0 0 0 0 rgba(255, 158, 66, 0.45);

  transition: transform 0.15s ease, box-shadow 0.2s ease, background 0.2s ease;
  animation: voice-fab-idle-pulse 8s ease-in-out infinite;
}

#voiceBtn .mic-glyph {
  font-size: 26px;
  line-height: 1;
  pointer-events: none;
}

#voiceBtn:hover {
  transform: translateY(-2px);
}

#voiceBtn:active {
  transform: translateY(0);
}

/* Subtle attention pulse when idle — fires gently every 8s */
@keyframes voice-fab-idle-pulse {
  0%, 88%, 100% { box-shadow: 0 8px 28px rgba(0, 0, 0, 0.55), 0 0 0 0 rgba(255, 158, 66, 0.45); }
  92%           { box-shadow: 0 8px 28px rgba(0, 0, 0, 0.55), 0 0 0 14px rgba(255, 158, 66, 0); }
}

/* Listening state: stronger pulse, scaled up, brighter rings */
#voiceBtn[data-state="listening"] {
  animation: voice-fab-listening 1.3s ease-in-out infinite;
  background: linear-gradient(135deg, #FFD365 0%, #FF9E42 100%);
  border-color: #FFD365;
}

@keyframes voice-fab-listening {
  0%, 100% {
    transform: scale(1);
    box-shadow:
      0 8px 28px rgba(0, 0, 0, 0.55),
      0 0 0 0 rgba(255, 158, 66, 0.55),
      0 0 0 0 rgba(255, 211, 101, 0.35);
  }
  50% {
    transform: scale(1.06);
    box-shadow:
      0 8px 28px rgba(0, 0, 0, 0.55),
      0 0 0 14px rgba(255, 158, 66, 0),
      0 0 0 28px rgba(255, 211, 101, 0);
  }
}

#voiceBtn[data-state="processing"] {
  opacity: 0.8;
  cursor: wait;
}

/* ---------- Status pill ------------------------------------------------- */
#voiceStatus {
  position: fixed;
  bottom: 100px; /* sits above the FAB (FAB is 60px + 24px bottom + gap) */
  right: 24px;
  transform: translateY(8px);
  z-index: 10000;

  background: linear-gradient(135deg, rgba(20, 20, 30, 0.97) 0%, rgba(40, 30, 50, 0.97) 100%);
  border: 1px solid rgba(255, 158, 66, 0.35);
  border-radius: 999px;
  padding: 11px 22px;
  color: #fff;
  font-size: 14px;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  font-weight: 600;
  white-space: nowrap;
  max-width: calc(100vw - 40px);
  overflow: hidden;
  text-overflow: ellipsis;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.55);

  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s ease, transform 0.2s ease;
}

#voiceStatus.visible {
  opacity: 1;
  transform: translateY(0);
}

#voiceStatus[data-kind="listening"] {
  border-color: rgba(255, 211, 101, 0.7);
  color: #FFD365;
}

#voiceStatus[data-kind="success"] {
  border-color: rgba(110, 220, 140, 0.7);
  color: #c0f5cf;
}

#voiceStatus[data-kind="unknown"] {
  border-color: rgba(255, 211, 101, 0.4);
  color: rgba(255, 255, 255, 0.85);
}

#voiceStatus[data-kind="error"] {
  border-color: rgba(255, 100, 100, 0.55);
  color: #ffb3b3;
}

/* ---------- First-time discovery cue ------------------------------------ */
/* Tooltip-style bubble pointing down-right at the FAB. Auto-dismissing. */
#voiceCue {
  position: fixed;
  bottom: 100px; /* above the FAB */
  right: 24px;
  transform: translateY(8px) scale(0.96);
  transform-origin: bottom right;
  z-index: 10002;

  background: linear-gradient(135deg, #FF9E42 0%, #FFD365 100%);
  color: #1a1a1a;
  border-radius: 14px;
  padding: 14px 22px;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  font-weight: 800;
  font-size: 16px;
  letter-spacing: 0.3px;
  white-space: nowrap;
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.6);

  opacity: 0;
  pointer-events: none;
  transition: opacity 0.25s ease, transform 0.25s ease;
}

#voiceCue.visible {
  opacity: 1;
  transform: translateY(0) scale(1);
}

/* Down-arrow pointing at the FAB (right-aligned) */
#voiceCue::after {
  content: '';
  position: absolute;
  top: 100%;
  right: 22px; /* aligned over the FAB center */
  width: 0;
  height: 0;
  border-left: 9px solid transparent;
  border-right: 9px solid transparent;
  border-top: 9px solid #FFD365;
}

/* ---------- Responsive tweaks ------------------------------------------ */
/* Slightly smaller FAB on desktop where 60px feels chunky next to a mouse */
@media (min-width: 900px) {
  #voiceBtn { width: 52px; height: 52px; }
  #voiceBtn .mic-glyph { font-size: 22px; }
}

/* Lift the FAB above iOS home indicator and avoid colliding with the
   YouTube iframe player (which sits at bottom: 90px right: 20px when
   active). Default 24px from edge; when YT is showing we'd want to lift
   higher — handled by JS adding a class if needed. */
@supports (padding: max(0px)) {
  #voiceBtn {
    bottom: max(24px, calc(24px + env(safe-area-inset-bottom, 0px)));
  }
}

/* Mobile: now-playing bar takes the bottom of the screen and on phones
   it's the only place volume / YT iframe / track controls live. Push the
   FAB above the bar so it doesn't sit on top of those controls. */
@media (max-width: 768px) {
  #voiceBtn {
    bottom: max(96px, calc(96px + env(safe-area-inset-bottom, 0px))) !important;
    right: 16px;
  }
}

/* When the YouTube iframe is visible, lift the FAB above it so they don't
   overlap. Player.html doesn't currently toggle this class — JS or a
   future change can add #voiceBtn.yt-active when ytPlayer is showing. */
#voiceBtn.yt-active {
  bottom: 310px; /* YT iframe is ~200px tall starting at bottom: 90px */
}
#voiceBtn.yt-active ~ #voiceStatus,
#voiceBtn.yt-active ~ #voiceCue {
  bottom: 386px;
}
