/* ── Reset & base ─────────────────────────────────────────────────────────── */
*,
*::before,
*::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html,
body {
  width: 100%;
  height: 100%;
  overflow: hidden;
  background: linear-gradient(160deg, #0d0d1a 0%, #1a0a2e 60%, #0d1a2e 100%);
  font-family: 'Segoe UI', system-ui, sans-serif;
  color: #e8e8f0;
}

/* ── Avatar canvas fills the viewport ────────────────────────────────────── */
#avatar-container {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
}

#avatar-canvas {
  display: block;
  /* Pixi (with autoDensity + resizeTo) manages the exact CSS pixel size via inline styles.
     Using 'auto' prevents the 100% rule from fighting the logical-size values Pixi sets. */
  width: auto;
  height: auto;
}

/* ── Speech bubble ────────────────────────────────────────────────────────── */
#speech-bubble {
  position: fixed;
  bottom: 96px;
  left: 50%;
  transform: translateX(-50%);
  max-width: min(560px, 90vw);
  background: rgba(20, 10, 40, 0.88);
  border: 1px solid rgba(160, 100, 240, 0.45);
  border-radius: 16px;
  padding: 14px 22px;
  backdrop-filter: blur(10px);
  box-shadow: 0 4px 32px rgba(120, 60, 200, 0.3);
  transition: opacity 0.35s ease, transform 0.35s ease;
  z-index: 10;
}

#speech-bubble::after {
  content: '';
  position: absolute;
  bottom: -10px;
  left: 50%;
  transform: translateX(-50%);
  border-left: 10px solid transparent;
  border-right: 10px solid transparent;
  border-top: 10px solid rgba(160, 100, 240, 0.45);
}

#speech-text {
  font-size: 1rem;
  line-height: 1.55;
  color: #f0eaff;
  text-align: center;
}

#speech-bubble.hidden {
  opacity: 0;
  pointer-events: none;
  transform: translateX(-50%) translateY(8px);
}

/* ── Status bar ───────────────────────────────────────────────────────────── */
#status-bar {
  position: fixed;
  top: 14px;
  right: 18px;
  display: flex;
  align-items: center;
  gap: 8px;
  background: rgba(10, 5, 25, 0.7);
  border: 1px solid rgba(120, 80, 200, 0.3);
  border-radius: 20px;
  padding: 6px 14px;
  font-size: 0.8rem;
  backdrop-filter: blur(8px);
  z-index: 20;
  user-select: none;
}

/* Connection indicator dot */
.dot {
  display: inline-block;
  width: 9px;
  height: 9px;
  border-radius: 50%;
  flex-shrink: 0;
}

.dot.connected {
  background: #4ade80;
  box-shadow: 0 0 6px #4ade80;
  animation: pulse 2s infinite;
}

.dot.disconnected {
  background: #f87171;
  box-shadow: 0 0 6px #f87171;
}

.dot.connecting {
  background: #facc15;
  box-shadow: 0 0 6px #facc15;
}

@keyframes pulse {
  0%, 100% { opacity: 1; }
  50%       { opacity: 0.5; }
}

/* ── Model-load error banner ─────────────────────────────────────────────── */
#load-error {
  position: fixed;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  background: rgba(30, 0, 20, 0.92);
  border: 1px solid #f87171;
  border-radius: 12px;
  padding: 24px 32px;
  text-align: center;
  max-width: 420px;
  z-index: 30;
}

#load-error h2 {
  color: #f87171;
  margin-bottom: 8px;
}

#load-error p {
  font-size: 0.9rem;
  opacity: 0.8;
  line-height: 1.5;
}

/* ── iOS/iPadOS audio-unlock prompt ─────────────────────────────────────── */
#audio-unlock-prompt {
  position: fixed;
  bottom: 20px;
  left: 50%;
  transform: translateX(-50%);
  background: rgba(20, 10, 40, 0.9);
  border: 1px solid rgba(160, 100, 240, 0.55);
  border-radius: 24px;
  padding: 10px 22px;
  font-size: 0.9rem;
  color: #f0eaff;
  backdrop-filter: blur(10px);
  box-shadow: 0 4px 24px rgba(120, 60, 200, 0.35);
  z-index: 40;
  cursor: pointer;
  user-select: none;
  animation: pulse 2s infinite;
}

/* ── Message input bar ───────────────────────────────────────────────────── */
#message-form {
  position: fixed;
  bottom: 18px;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  align-items: center;
  gap: 8px;
  width: min(540px, 92vw);
  background: rgba(10, 5, 25, 0.82);
  border: 1px solid rgba(120, 80, 200, 0.4);
  border-radius: 32px;
  padding: 8px 8px 8px 18px;
  backdrop-filter: blur(12px);
  box-shadow: 0 4px 28px rgba(100, 50, 180, 0.3);
  z-index: 20;
}

#message-input {
  flex: 1;
  background: transparent;
  border: none;
  outline: none;
  font-size: 0.95rem;
  color: #f0eaff;
  line-height: 1.4;
  caret-color: #c084fc;
}

#message-input::placeholder {
  color: rgba(200, 180, 240, 0.45);
}

#message-send {
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  border: none;
  border-radius: 50%;
  background: linear-gradient(135deg, #7c3aed, #a855f7);
  color: #fff;
  cursor: pointer;
  transition: opacity 0.2s, transform 0.15s;
}

#message-send:hover {
  opacity: 0.88;
  transform: scale(1.07);
}

#message-send:active {
  transform: scale(0.96);
}

#message-send:disabled {
  opacity: 0.4;
  cursor: not-allowed;
  transform: none;
}

/* ── Send error toast ────────────────────────────────────────────────────── */
#send-error {
  position: fixed;
  bottom: 78px;
  left: 50%;
  transform: translateX(-50%);
  background: rgba(60, 10, 20, 0.92);
  border: 1px solid #f87171;
  border-radius: 12px;
  padding: 10px 18px;
  font-size: 0.85rem;
  color: #fca5a5;
  max-width: min(480px, 90vw);
  text-align: center;
  z-index: 25;
  transition: opacity 0.3s ease;
}

#send-error.hidden {
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
}

/* ── noscript fallback ───────────────────────────────────────────────────── */
.noscript-notice {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.2rem;
  color: #f87171;
  padding: 20px;
  text-align: center;
}
