/* ── Variables ────────────────────────────────────────────────────────────── */
:root {
  --bg: #050508;
  --blue: #4ca8e8;
  --blue-glow: rgba(76, 168, 232, 0.5);
  --blue-dim: rgba(76, 168, 232, 0.15);
  --green: #22c55e;
  --green-glow: rgba(34, 197, 94, 0.5);
  --orange: #f59e0b;
  --orange-glow: rgba(245, 158, 11, 0.5);
  --cyan: #0ea5e9;
  --cyan-glow: rgba(14, 165, 233, 0.5);
  --red: #ef4444;
  --red-glow: rgba(239, 68, 68, 0.4);
  --text: rgba(255, 255, 255, 0.85);
  --text-dim: rgba(255, 255, 255, 0.35);
  --glass: rgba(5, 5, 8, 0.6);

  /* Orb colors par état */
  --orb-color: var(--blue);
  --orb-glow: var(--blue-glow);
}

/* ── Reset ────────────────────────────────────────────────────────────────── */
*, *::before, *::after {
  margin: 0; padding: 0; box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

html, body {
  width: 100%; height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  -webkit-font-smoothing: antialiased;
  overflow: hidden;
  user-select: none;
}

/* ── Étoiles ──────────────────────────────────────────────────────────────── */
#stars {
  position: fixed; inset: 0; pointer-events: none; z-index: 0;
  background:
    radial-gradient(1px 1px at 20% 15%, rgba(255,255,255,0.4) 0%, transparent 100%),
    radial-gradient(1px 1px at 75% 8%, rgba(255,255,255,0.3) 0%, transparent 100%),
    radial-gradient(1px 1px at 40% 70%, rgba(255,255,255,0.25) 0%, transparent 100%),
    radial-gradient(1px 1px at 85% 55%, rgba(255,255,255,0.2) 0%, transparent 100%),
    radial-gradient(1px 1px at 10% 88%, rgba(255,255,255,0.3) 0%, transparent 100%),
    radial-gradient(1px 1px at 60% 30%, rgba(255,255,255,0.15) 0%, transparent 100%),
    radial-gradient(1px 1px at 90% 80%, rgba(255,255,255,0.35) 0%, transparent 100%),
    radial-gradient(1px 1px at 55% 90%, rgba(255,255,255,0.2) 0%, transparent 100%),
    radial-gradient(1px 1px at 30% 45%, rgba(255,255,255,0.15) 0%, transparent 100%);
}

/* ── Badge de connexion ───────────────────────────────────────────────────── */
#connection-badge {
  position: fixed; top: 16px; right: 16px;
  display: flex; align-items: center; gap: 7px;
  padding: 7px 14px;
  border: 1px solid rgba(76,168,232,0.12);
  border-radius: 20px;
  background: var(--glass);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  z-index: 100;
}

#connection-dot {
  width: 7px; height: 7px; border-radius: 50%;
  background: rgba(255,255,255,0.15);
  flex-shrink: 0;
  transition: background 0.4s ease, box-shadow 0.4s ease;
}

#connection-badge.connected #connection-dot {
  background: var(--green);
  box-shadow: 0 0 8px var(--green-glow);
}

#connection-badge.disconnected #connection-dot {
  background: var(--red);
  box-shadow: 0 0 8px var(--red-glow);
  animation: pulse-red 1.4s ease-in-out infinite;
}

@keyframes pulse-red {
  0%, 100% { opacity: 1; } 50% { opacity: 0.35; }
}

#connection-label {
  font-size: 11px; letter-spacing: 1.5px; font-weight: 300;
  color: rgba(255,255,255,0.3); text-transform: lowercase;
  transition: color 0.4s ease;
}

#connection-badge.connected #connection-label { color: rgba(34,197,94,0.7); }
#connection-badge.disconnected #connection-label { color: rgba(239,68,68,0.6); }

/* ── Bouton STOP JARVIS ───────────────────────────────────────────────────── */
#stop-jarvis-btn {
  position: fixed; top: 16px; left: 16px;
  display: flex; align-items: center; gap: 6px;
  padding: 6px 14px;
  border: 1px solid rgba(239,68,68,0.3);
  border-radius: 20px;
  background: rgba(239,68,68,0.1);
  color: rgba(239,68,68,0.9);
  font-size: 11px; letter-spacing: 1.5px; font-weight: 500;
  cursor: pointer;
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  z-index: 100;
  transition: all 0.3s ease;
  font-family: inherit;
  display: none; /* Masqué par défaut, géré par JS */
}

#stop-jarvis-btn svg {
  width: 14px; height: 14px;
}

#stop-jarvis-btn:active {
  transform: scale(0.95);
  background: rgba(239,68,68,0.2);
}

/* ── Layout principal ─────────────────────────────────────────────────────── */
#app {
  position: fixed; inset: 0;
  display: flex; flex-direction: column; align-items: center;
  justify-content: space-between;
  padding: 80px 24px 40px;
  z-index: 10;
}

/* ── Orbe ─────────────────────────────────────────────────────────────────── */
#orb-container {
  position: relative;
  width: 100%;
  height: 250px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  pointer-events: none;
}

#orb-canvas {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: 100vw !important;
  height: 100vh !important;
  z-index: -1;
}

/* ── États de l'orbe ──────────────────────────────────────────────────────── */

/* Les animations de l'orbe sont maintenant gérées par Three.js dans orb.js */

/* ── Texte de statut ──────────────────────────────────────────────────────── */
#status-text {
  font-size: 12px; letter-spacing: 3px; text-transform: lowercase; font-weight: 300;
  color: rgba(76,168,232,0.6);
  text-align: center; min-height: 18px;
  transition: color 0.4s ease, opacity 0.4s ease;
}
body.state-listening #status-text { color: rgba(34,197,94,0.8); }
body.state-thinking  #status-text { color: rgba(245,158,11,0.8); }
body.state-speaking  #status-text { color: rgba(14,165,233,0.8); }

/* ── Bulles de dialogue ───────────────────────────────────────────────────── */
.speech-bubble {
  width: 100%; max-width: 400px;
  padding: 12px 16px;
  border-radius: 16px;
  font-size: 14px; line-height: 1.5; font-weight: 300;
  min-height: 44px;
  opacity: 0; transition: opacity 0.4s ease;
  word-wrap: break-word;
}

.speech-bubble:not(:empty) { opacity: 1; }

.user-bubble {
  background: rgba(76,168,232,0.08);
  border: 1px solid rgba(76,168,232,0.15);
  color: rgba(255,255,255,0.6);
  font-style: italic;
  text-align: right;
  font-size: 13px;
}

.jarvis-bubble {
  background: rgba(14,165,233,0.06);
  border: 1px solid rgba(14,165,233,0.12);
  color: rgba(255,255,255,0.85);
  font-size: 14px;
}

.jarvis-bubble::before {
  content: 'JARVIS  ';
  font-size: 10px; letter-spacing: 2px;
  color: rgba(14,165,233,0.5); font-weight: 400;
  display: block; margin-bottom: 4px;
}

/* ── Zone microphone ──────────────────────────────────────────────────────── */
#mic-area {
  display: flex; flex-direction: column; align-items: center; gap: 14px;
}

#mic-btn {
  width: 80px; height: 80px; border-radius: 50%;
  border: 1px solid rgba(76,168,232,0.25);
  background: rgba(5,5,8,0.5);
  color: rgba(76,168,232,0.7);
  display: flex; align-items: center; justify-content: center;
  cursor: pointer;
  transition: all 0.25s ease;
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  position: relative;
  -webkit-tap-highlight-color: transparent;
}

#mic-btn:active {
  transform: scale(0.93);
}

#mic-btn:hover {
  border-color: rgba(76,168,232,0.45);
  color: rgba(76,168,232,0.95);
  box-shadow: 0 0 20px rgba(76,168,232,0.2);
}

/* État écoute */
body.state-listening #mic-btn {
  border-color: rgba(34,197,94,0.5);
  color: var(--green);
  box-shadow: 0 0 30px var(--green-glow), 0 0 60px rgba(34,197,94,0.15);
  animation: btn-breathe 1s ease-in-out infinite;
}

/* État thinking/speaking - désactivé */
body.state-thinking #mic-btn,
body.state-speaking #mic-btn {
  opacity: 0.4; cursor: not-allowed; pointer-events: none;
}

@keyframes btn-breathe {
  0%, 100% { box-shadow: 0 0 20px var(--green-glow); }
  50% { box-shadow: 0 0 40px var(--green-glow), 0 0 70px rgba(34,197,94,0.2); }
}

.mic-icon, .stop-icon {
  width: 28px; height: 28px;
}

#mic-label {
  font-size: 10px; letter-spacing: 2.5px; text-transform: uppercase;
  color: rgba(255,255,255,0.2); font-weight: 300;
  transition: color 0.3s ease;
}

body.state-listening #mic-label { color: rgba(34,197,94,0.6); }

/* ── Label bas de page ────────────────────────────────────────────────────── */
#assistant-label {
  font-size: 10px; letter-spacing: 6px; text-transform: uppercase;
  font-weight: 300; color: rgba(76,168,232,0.15);
  pointer-events: none;
}

/* ── Responsive ───────────────────────────────────────────────────────────── */
@media (max-height: 600px) {
  #orb-container { height: 150px; }
  #app { padding: 60px 20px 28px; }
}
