* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

html, body {
  width: 100%;
  height: 100%;
  overflow: hidden;
  background: #0a0a0a;
  font-family: 'Segoe UI', system-ui, -apple-system, sans-serif;
}

/* ======================================================
   FASE 4 — Sistema de fondos AI + Efectos de emocion
   ====================================================== */

/* --- Fondo AI (Stable Diffusion backgrounds) --- */
#ai-background {
  position: absolute;
  inset: 0;
  z-index: 0;
  background: linear-gradient(135deg, #0d0d1a 0%, #111127 40%, #0a0a18 100%);
  background-size: cover;
  background-position: center;
  transition: background-image 2s ease-in-out, background 2s ease-in-out;
}

/* Efecto de fade entre backgrounds */
#ai-background.fading {
  animation: bgFade 2s ease-in-out;
}

/* --- Luz ambient (cambia segun emocion del avatar) --- */
#ambient-fx {
  position: absolute;
  inset: 0;
  z-index: 1;
  pointer-events: none;
  /* Gradiente radial desde abajo — simula luz de estudio */
  background: radial-gradient(ellipse 80% 50% at 50% 110%,
    var(--ambient-color, rgba(30, 30, 80, 0.4)) 0%,
    transparent 70%);
  transition: background 1.2s ease-in-out;
}

/* --- Emociones: variables CSS aplicadas dinamicamente via JS --- */
/* neutral */
.emotion-neutral  { --ambient-color: rgba(30, 30, 80, 0.4); }
/* happy — luz amarilla calida */
.emotion-happy    { --ambient-color: rgba(120, 90, 20, 0.45); }
/* excited — naranja intensa */
.emotion-excited  { --ambient-color: rgba(160, 60, 0, 0.5); }
/* surprised — cian brillante */
.emotion-surprised{ --ambient-color: rgba(0, 120, 160, 0.45); }
/* thinking — azul profundo */
.emotion-thinking { --ambient-color: rgba(10, 30, 130, 0.5); }

/* --- Filtro CSS sobre el canvas del avatar segun emocion --- */
#avatar {
  width: 100%;
  height: 100%;
  position: absolute;
  top: 0;
  left: 0;
  z-index: 2;
  transition: filter 1.0s ease-in-out;
}

/* Filtros por emocion — aplicados por JS via clase en #avatar */
#avatar.emotion-neutral  { filter: brightness(1.0) saturate(1.0); }
#avatar.emotion-happy    { filter: brightness(1.08) saturate(1.25) sepia(0.08); }
#avatar.emotion-excited  { filter: brightness(1.12) saturate(1.4) contrast(1.05); }
#avatar.emotion-surprised{ filter: brightness(1.1) saturate(1.2) hue-rotate(5deg); }
#avatar.emotion-thinking { filter: brightness(0.95) saturate(0.9) hue-rotate(-8deg); }

/* --- Product Overlay --- */
#product-overlay {
  position: absolute;
  bottom: 30px;
  left: 30px;
  background: rgba(0, 0, 0, 0.85);
  backdrop-filter: blur(12px);
  color: #fff;
  padding: 20px;
  border-radius: 16px;
  max-width: 420px;
  display: none;
  border: 1px solid rgba(255, 255, 255, 0.1);
  animation: slideUp 0.4s ease-out;
}

#product-close {
  position: absolute;
  top: 10px;
  right: 14px;
  background: none;
  border: none;
  color: #888;
  font-size: 22px;
  cursor: pointer;
}

#product-image-container {
  width: 100%;
  border-radius: 10px;
  overflow: hidden;
  margin-bottom: 12px;
}

#product-image {
  width: 100%;
  height: 200px;
  object-fit: cover;
  display: block;
}

#product-name {
  font-size: 18px;
  font-weight: 700;
  margin-bottom: 6px;
}

#product-price {
  font-size: 24px;
  font-weight: 800;
  color: #00e676;
  margin-bottom: 10px;
}

#product-features {
  list-style: none;
  padding: 0;
}

#product-features li {
  padding: 4px 0;
  font-size: 14px;
  color: #ccc;
}

#product-features li::before {
  content: "✓ ";
  color: #00e676;
  font-weight: bold;
}

/* --- QR Code --- */
#product-qr {
  display: flex;
  flex-direction: column;
  align-items: center;
  margin-top: 14px;
  padding-top: 14px;
  border-top: 1px solid rgba(255, 255, 255, 0.1);
}

#product-qr-img {
  width: 110px;
  height: 110px;
  border-radius: 8px;
  background: #fff;
  padding: 4px;
}

#product-qr-label {
  font-size: 11px;
  color: #888;
  margin-top: 6px;
  text-transform: uppercase;
  letter-spacing: 1px;
}

/* --- Chat Overlay --- */
#chat-overlay {
  position: absolute;
  top: 20px;
  right: 20px;
  background: rgba(0, 0, 0, 0.6);
  backdrop-filter: blur(8px);
  color: #fff;
  border-radius: 14px;
  width: 320px;
  max-height: 380px;
  overflow: hidden;
  border: 1px solid rgba(255, 255, 255, 0.08);
}

#chat-header {
  padding: 10px 16px;
  font-size: 13px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 1px;
  color: #888;
  border-bottom: 1px solid rgba(255, 255, 255, 0.08);
}

#chat-messages {
  padding: 10px 16px;
  max-height: 330px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.chat-msg {
  font-size: 14px;
  line-height: 1.4;
  animation: fadeIn 0.3s ease-out;
}

.chat-msg .chat-user {
  font-weight: 700;
  color: #7c4dff;
  margin-right: 6px;
}

.chat-msg .chat-text {
  color: #e0e0e0;
}

.chat-msg.gift {
  background: rgba(255, 215, 0, 0.1);
  padding: 6px 10px;
  border-radius: 8px;
  border-left: 3px solid #ffd700;
}

.chat-msg.gift .chat-user {
  color: #ffd700;
}

/* --- Status Bar --- */
#status-bar {
  position: absolute;
  top: 20px;
  left: 20px;
  background: rgba(0, 0, 0, 0.6);
  backdrop-filter: blur(8px);
  padding: 8px 16px;
  border-radius: 20px;
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  color: #ccc;
}

#status-indicator {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: #ff5252;
}

#status-indicator.connected {
  background: #00e676;
  box-shadow: 0 0 8px rgba(0, 230, 118, 0.6);
}

/* --- Animations --- */
@keyframes slideUp {
  from { transform: translateY(30px); opacity: 0; }
  to { transform: translateY(0); opacity: 1; }
}

@keyframes fadeIn {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: translateY(0); }
}

@keyframes bgFade {
  0%   { opacity: 1; }
  40%  { opacity: 0.2; }
  100% { opacity: 1; }
}

/* Pulso sutil cuando el avatar esta excited */
@keyframes ambientPulse {
  0%  { opacity: 1; }
  50% { opacity: 0.6; }
  100%{ opacity: 1; }
}

#ambient-fx.pulsing {
  animation: ambientPulse 1.5s ease-in-out 3;
}

/* --- Scrollbar --- */
#chat-messages::-webkit-scrollbar {
  width: 4px;
}

#chat-messages::-webkit-scrollbar-thumb {
  background: rgba(255, 255, 255, 0.2);
  border-radius: 2px;
}
