/**
 * style.css
 * Mobile-first stylesheet for AI Desktop Buddy Live Voice Assistant
 * Optimized for iOS Safari (iPhone 6s Plus / iOS 15.8.4+) and PWA Fullscreen
 */

:root {
  --bg-color: #06080d;
  --surface-color: rgba(16, 22, 36, 0.85);
  --border-color: rgba(255, 255, 255, 0.08);
  
  /* Eye, Mouth & Accent Neon Colors */
  --cyan-glow: #00f0ff;
  --cyan-subtle: rgba(0, 240, 255, 0.25);
  --cute-pink: #ff2d75;
  --cute-glow: rgba(255, 45, 117, 0.5);
  --thinking-glow: #8e2de2;
  --speaking-glow: #00d2ff;
  --error-glow: #ff3b30;
  --interrupted-glow: #ff9500;
  
  --text-primary: #f2f6ff;
  --text-secondary: #8c9ba5;
  --text-muted: #536271;

  --safe-top: env(safe-area-inset-top, 16px);
  --safe-bottom: env(safe-area-inset-bottom, 16px);
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  -webkit-tap-highlight-color: transparent;
}

.hidden {
  display: none !important;
}

html, body {
  overscroll-behavior: none;
  overscroll-behavior-y: none;
  -webkit-touch-callout: none;
  touch-action: pan-x pan-y;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background-color: var(--bg-color);
  color: var(--text-primary);
  min-height: 100vh;
  min-height: -webkit-fill-available;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  user-select: none;
  -webkit-user-select: none;
  position: fixed;
  width: 100%;
  height: 100%;
}

#app-container {
  display: flex;
  flex-direction: column;
  height: 100vh;
  height: -webkit-fill-available;
  padding: var(--safe-top) 16px var(--safe-bottom) 16px;
  position: relative;
}

/* ====================================================
   Wake Overlay (One tap to activate Safari Web Audio)
   ==================================================== */
.wake-overlay {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(6, 8, 13, 0.92);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  cursor: pointer;
  transition: opacity 0.4s ease, visibility 0.4s ease;
}

.wake-overlay.hidden {
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
}

.wake-card {
  background: rgba(16, 22, 36, 0.9);
  border: 1.5px solid rgba(0, 240, 255, 0.4);
  border-radius: 28px;
  padding: 36px 24px;
  text-align: center;
  max-width: 320px;
  box-shadow: 0 0 40px rgba(0, 240, 255, 0.2);
  position: relative;
  overflow: hidden;
}

.wake-sparkle {
  font-size: 38px;
  margin-bottom: 12px;
  animation: wakeFloat 2s ease-in-out infinite;
}

.wake-title {
  font-size: 19px;
  font-weight: 700;
  color: #f2f6ff;
  margin-bottom: 10px;
  line-height: 1.35;
}

.wake-subtitle {
  font-size: 13px;
  color: #8c9ba5;
  line-height: 1.5;
}

@keyframes wakeFloat {
  0%, 100% { transform: translateY(0) scale(1); }
  50% { transform: translateY(-6px) scale(1.08); }
}

/* ====================================================
   Top Status Bar & Actions
   ==================================================== */
.top-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 4px 6px 10px 6px;
  z-index: 10;
  gap: 8px;
}

.network-badge {
  display: flex;
  align-items: center;
  gap: 6px;
  background: var(--surface-color);
  border: 1px solid var(--border-color);
  padding: 5px 10px;
  border-radius: 18px;
  font-size: 12px;
  font-weight: 500;
  color: var(--text-secondary);
}

.status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background-color: #ff9500;
  transition: background-color 0.3s ease;
}

.network-badge.online .status-dot {
  background-color: #34c759;
  box-shadow: 0 0 8px rgba(52, 199, 89, 0.6);
}

.network-badge.offline .status-dot {
  background-color: #ff3b30;
  box-shadow: 0 0 8px rgba(255, 59, 48, 0.6);
}

.robot-state-tag {
  background: rgba(0, 240, 255, 0.1);
  border: 1px solid rgba(0, 240, 255, 0.3);
  padding: 4px 10px;
  border-radius: 12px;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 1px;
  color: var(--cyan-glow);
  text-transform: uppercase;
  transition: all 0.3s ease;
}

.top-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

.voice-select {
  background: var(--surface-color);
  border: 1px solid var(--border-color);
  color: var(--text-primary);
  border-radius: 14px;
  padding: 4px 8px;
  font-size: 12px;
  outline: none;
  cursor: pointer;
  max-width: 140px;
}

.btn-icon {
  background: var(--surface-color);
  border: 1px solid var(--border-color);
  color: var(--text-secondary);
  width: 34px;
  height: 34px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 15px;
  cursor: pointer;
  touch-action: manipulation;
}

/* ====================================================
   Robot Face Stage
   ==================================================== */
.face-stage {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  position: relative;
}

.robot-face {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  width: 100%;
  max-width: 320px;
  height: 250px;
  position: relative;
  transition: transform 0.4s ease;
}

/* Eyes Container */
.eyes-container {
  display: flex;
  justify-content: center;
  gap: 46px;
  position: relative;
}

.eye {
  width: 90px;
  height: 135px;
  background: #000;
  border-radius: 45px;
  position: relative;
  overflow: hidden;
  box-shadow: inset 0 0 12px rgba(0, 0, 0, 0.95);
}

.eye-glow {
  position: absolute;
  top: 6px;
  left: 6px;
  right: 6px;
  bottom: 6px;
  border-radius: 39px;
  background: var(--cyan-glow);
  box-shadow: 0 0 28px var(--cyan-glow), inset 0 0 16px rgba(255, 255, 255, 0.85);
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

.pupil {
  width: 36px;
  height: 52px;
  background: #ffffff;
  border-radius: 20px;
  box-shadow: 0 0 12px #ffffff;
  transition: transform 0.2s ease;
}

.eyelid {
  position: absolute;
  left: 0;
  right: 0;
  background: var(--bg-color);
  z-index: 5;
  transition: transform 0.15s ease-out;
}

.eyelid-top {
  top: 0;
  height: 50%;
  transform-origin: top;
  transform: translateY(-100%);
}

.eyelid-bottom {
  bottom: 0;
  height: 50%;
  transform-origin: bottom;
  transform: translateY(100%);
}

/* ====================================================
   Cute Dynamic Animated Mouth
   ==================================================== */
.mouth-container {
  margin-top: 22px;
  display: flex;
  justify-content: center;
  align-items: center;
  height: 44px;
}

.robot-mouth {
  width: 36px;
  height: 12px;
  border-radius: 0 0 18px 18px;
  border: 3.5px solid var(--cyan-glow);
  border-top: none;
  background: transparent;
  box-shadow: 0 0 14px var(--cyan-subtle);
  transition: all 0.1s ease-out;
  transform-origin: center top;
}

/* Voice Wave Spectrum Bars */
.voice-wave {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 5px;
  height: 24px;
  margin-top: 10px;
}

.voice-wave .bar {
  width: 4px;
  height: 4px;
  border-radius: 2px;
  background: var(--cyan-glow);
  box-shadow: 0 0 8px var(--cyan-subtle);
  transition: height 0.06s ease-out, background-color 0.2s;
}

.robot-face[data-state="speaking"] .voice-wave .bar {
  background: var(--cute-pink);
  box-shadow: 0 0 10px var(--cute-glow);
}

.robot-face[data-state="thinking"] .voice-wave .bar {
  background: var(--thinking-glow);
  box-shadow: 0 0 8px #8e2de2;
}

.robot-face[data-state="interrupted"] .voice-wave .bar {
  background: var(--interrupted-glow);
  box-shadow: 0 0 8px var(--interrupted-glow);
}

/* ====================================================
   Robot Face States
   ==================================================== */

/* --- IDLE --- */
.robot-face[data-state="idle"] {
  animation: breathing 4s ease-in-out infinite;
}
.robot-face[data-state="idle"] .pupil {
  animation: idleGlance 6s ease-in-out infinite;
}
.robot-face[data-state="idle"] .eyelid-top {
  animation: blinkTop 4s infinite;
}
.robot-face[data-state="idle"] .eyelid-bottom {
  animation: blinkBottom 4s infinite;
}
.robot-face[data-state="idle"] .robot-mouth {
  width: 34px;
  height: 12px;
  border-radius: 0 0 18px 18px;
  border-color: var(--cyan-glow);
}

/* --- LISTENING (User Speaking) --- */
.robot-face[data-state="listening"] .eye-glow {
  background: #00f0ff;
  box-shadow: 0 0 35px #00f0ff, inset 0 0 18px #ffffff;
}
.robot-face[data-state="listening"] .pupil {
  transform: translate(0, 0) scale(1.1);
}
.robot-face[data-state="listening"] .robot-mouth {
  width: 20px;
  height: 20px;
  border-radius: 50%;
  border: 3px solid #00f0ff;
  background: rgba(0, 240, 255, 0.15);
  box-shadow: 0 0 15px rgba(0, 240, 255, 0.4);
}

/* --- THINKING (Animated Eye Motion & Cosmic Pulse) --- */
.robot-face[data-state="thinking"] .eye-glow {
  background: linear-gradient(135deg, #4a00e0, #8e2de2);
  box-shadow: 0 0 35px #8e2de2, inset 0 0 16px rgba(255, 255, 255, 0.7);
  animation: thinkingPulse 1s ease-in-out infinite alternate;
}
.robot-face[data-state="thinking"] .eyelid-top {
  transform: translateY(-55%);
}
.robot-face[data-state="thinking"] .eyelid-bottom {
  transform: translateY(55%);
}
.robot-face[data-state="thinking"] .pupil {
  animation: thinkingLookUp 1.4s ease-in-out infinite alternate;
}
.robot-face[data-state="thinking"] .voice-wave .bar {
  animation: thinkingWave 0.8s ease-in-out infinite alternate;
}
.robot-face[data-state="thinking"] .voice-wave .bar:nth-child(2) { animation-delay: 0.15s; }
.robot-face[data-state="thinking"] .voice-wave .bar:nth-child(3) { animation-delay: 0.3s; }
.robot-face[data-state="thinking"] .voice-wave .bar:nth-child(4) { animation-delay: 0.45s; }
.robot-face[data-state="thinking"] .voice-wave .bar:nth-child(5) { animation-delay: 0.6s; }

.robot-face[data-state="thinking"] .robot-mouth {
  width: 22px;
  height: 4px;
  border-radius: 2px;
  background: #8e2de2;
  border: none;
}

/* --- SPEAKING (Model Answering) --- */
.robot-face[data-state="speaking"] .eye-glow {
  background: var(--cute-pink);
  box-shadow: 0 0 35px var(--cute-pink), inset 0 0 20px #ffffff;
}
.robot-face[data-state="speaking"] .eye {
  animation: speakingBounce 0.4s ease-in-out infinite alternate;
}
.robot-face[data-state="speaking"] .robot-mouth {
  /* Real-time volume scaling driven by JS variables */
  border: 3px solid var(--cute-pink);
  background: rgba(255, 45, 117, 0.25);
  box-shadow: 0 0 20px var(--cute-glow);
  border-radius: 14px;
}

/* --- INTERRUPTED --- */
.robot-face[data-state="interrupted"] .eye-glow {
  background: var(--interrupted-glow);
  box-shadow: 0 0 30px var(--interrupted-glow);
}
.robot-face[data-state="interrupted"] .robot-mouth {
  width: 26px;
  height: 28px;
  border-radius: 14px;
  border: 3px solid var(--interrupted-glow);
  background: transparent;
}

/* --- ERROR --- */
.robot-face[data-state="error"] {
  animation: shakeHead 0.5s ease-in-out;
}
.robot-face[data-state="error"] .eye-glow {
  background: var(--error-glow);
  box-shadow: 0 0 30px var(--error-glow);
}
.robot-face[data-state="error"] .robot-mouth {
  width: 32px;
  height: 12px;
  border-radius: 18px 18px 0 0;
  border-color: var(--error-glow);
}

/* Animations */
@keyframes breathing {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-7px); }
}
@keyframes blinkTop {
  0%, 92%, 100% { transform: translateY(-100%); }
  95% { transform: translateY(0); }
}
@keyframes blinkBottom {
  0%, 92%, 100% { transform: translateY(100%); }
  95% { transform: translateY(0); }
}
@keyframes thinkingPulse {
  0% { transform: scale(0.96); opacity: 0.85; }
  100% { transform: scale(1.03); opacity: 1; }
}
@keyframes thinkingLookUp {
  0%, 100% { transform: translate(5px, -14px); }
  50% { transform: translate(-5px, -12px); }
}
@keyframes thinkingWave {
  0% { height: 4px; }
  100% { height: 20px; }
}
@keyframes idleGlance {
  0%, 100% { transform: translate(0, 0); }
  25%, 35% { transform: translate(-8px, -2px); }
  60%, 70% { transform: translate(8px, -2px); }
  85%, 92% { transform: translate(0, 3px); }
}
@keyframes speakingBounce {
  0% { transform: scaleY(0.95); }
  100% { transform: scaleY(1.05); }
}
@keyframes shakeHead {
  0%, 100% { transform: translateX(0); }
  20%, 60% { transform: translateX(-12px); }
  40%, 80% { transform: translateX(12px); }
}

/* ====================================================
   YouTube In-App Music Player Widget
   ==================================================== */
/* Sleek Floating YouTube Mini Player (Responsive, satisfies YouTube 200px limit) */
.youtube-mini-player {
  position: fixed;
  bottom: calc(var(--safe-bottom) + 55px);
  left: 16px;
  right: 16px;
  max-width: 360px;
  margin: 0 auto;
  background: rgba(14, 18, 28, 0.96);
  border: 1px solid rgba(255, 45, 117, 0.5);
  box-shadow: 0 8px 32px rgba(255, 45, 117, 0.25);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  border-radius: 18px;
  padding: 10px 12px;
  z-index: 120;
  display: flex;
  flex-direction: column;
  gap: 8px;
  transition: transform 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275), opacity 0.3s ease;
}

.youtube-mini-player.hidden {
  transform: translateY(120%);
  opacity: 0;
  pointer-events: none;
}

.mini-player-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.mini-music-icon {
  font-size: 15px;
}

.mini-music-title {
  font-size: 13px;
  font-weight: 600;
  color: #ff9ec6;
  flex: 1;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.btn-close-mini {
  background: rgba(255, 255, 255, 0.1);
  border: none;
  color: #8c9ba5;
  border-radius: 50%;
  width: 24px;
  height: 24px;
  font-size: 13px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.2s;
}

.btn-close-mini:hover {
  background: rgba(255, 255, 255, 0.2);
  color: #fff;
}

.mini-player-content {
  display: flex;
  flex-direction: column;
  gap: 8px;
  align-items: center;
}

/* Audio Track Card Mode */
.audio-track-card {
  width: 100%;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 8px;
  background: rgba(255, 255, 255, 0.04);
  border-radius: 12px;
  border: 1px solid rgba(255, 255, 255, 0.08);
}

.music-artwork-img {
  width: 64px;
  height: 64px;
  border-radius: 8px;
  object-fit: cover;
  background: #111;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.4);
  flex-shrink: 0;
}

.audio-track-meta {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 3px;
}

.audio-track-name {
  font-size: 14px;
  font-weight: 700;
  color: #fff;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.audio-track-artist {
  font-size: 12px;
  color: #a0aec0;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.audio-track-badge {
  font-size: 10px;
  color: #00f0ff;
  font-weight: 600;
  letter-spacing: 0.2px;
}

/* Equalizer Bars Animation */
.audio-equalizer-bars {
  display: flex;
  align-items: flex-end;
  gap: 3px;
  height: 24px;
  padding-right: 4px;
}

.audio-equalizer-bars span {
  width: 3px;
  background: #ff2d75;
  border-radius: 2px;
  animation: eqBounce 1s ease-in-out infinite alternate;
}

.audio-equalizer-bars .eq-b1 { height: 16px; animation-delay: 0.1s; }
.audio-equalizer-bars .eq-b2 { height: 22px; animation-delay: 0.3s; }
.audio-equalizer-bars .eq-b3 { height: 12px; animation-delay: 0.2s; }
.audio-equalizer-bars .eq-b4 { height: 18px; animation-delay: 0.4s; }

@keyframes eqBounce {
  0% { transform: scaleY(0.3); }
  100% { transform: scaleY(1.0); }
}

.youtube-frame-embed {
  width: 100%;
  height: 200px;
  min-height: 200px;
  border-radius: 12px;
  border: none;
  background: #000;
  flex-shrink: 0;
}

.btn-open-yt-app {
  width: 100%;
  text-align: center;
  background: linear-gradient(135deg, rgba(255, 0, 0, 0.25), rgba(255, 45, 117, 0.35));
  border: 1px solid rgba(255, 45, 117, 0.5);
  color: #fff;
  padding: 8px 12px;
  border-radius: 10px;
  font-size: 12px;
  font-weight: 600;
  text-decoration: none;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  transition: background 0.2s, transform 0.1s;
}

.btn-open-yt-app:active {
  transform: scale(0.98);
}

/* ====================================================
   Subtitle / Speech Card
   ==================================================== */
.subtitle-wrapper {
  margin-bottom: calc(var(--safe-bottom) + 8px);
  width: 100%;
}

.subtitle-card {
  background: var(--surface-color);
  border: 1px solid var(--border-color);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border-radius: 20px;
  padding: 14px 18px;
  min-height: 58px;
  max-height: 90px;
  overflow-y: auto;
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.4);
  text-align: center;
}

.subtitle-text {
  font-size: 15px;
  line-height: 1.45;
  color: var(--text-primary);
  word-break: break-word;
}

/* ====================================================
   Toast Error Notification
   ==================================================== */
.error-toast {
  position: absolute;
  top: calc(var(--safe-top) + 50px);
  left: 16px;
  right: 16px;
  background: rgba(40, 14, 16, 0.95);
  border: 1px solid rgba(255, 59, 48, 0.5);
  backdrop-filter: blur(12px);
  border-radius: 14px;
  padding: 10px 14px;
  display: flex;
  align-items: center;
  gap: 10px;
  z-index: 100;
}
.error-toast.hidden { display: none; }
.error-message { font-size: 13px; color: #ffb3b0; flex: 1; }
.btn-close-toast { background: none; border: none; color: #ff8080; font-size: 16px; cursor: pointer; }

