:root {
  --bg: #050811;
  --panel: #0e1524;
  --panel-alt: #182236;
  --accent: #12bdeb;
  --accent-glow: rgba(18, 189, 235, 0.45);
  --avatar-filter: hue-rotate(0deg) saturate(1.1) brightness(1.06);
  --text: #e2e8f0;
  --muted: #8b9bb4;
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  font-family: 'Segoe UI', system-ui, -apple-system, sans-serif;
}

body {
  background: radial-gradient(circle at 50% 15%, #111f38 0%, var(--bg) 68%);
  color: var(--text);
  height: 100dvh;
  overflow: hidden;
  display: flex;
  justify-content: center;
  -webkit-user-select: none;
  user-select: none;
}

.bubble, input, select {
  -webkit-user-select: text;
  user-select: text;
}

.app-container {
  position: relative;
  display: flex;
  flex-direction: column;
  width: 100%;
  max-width: 540px;
  height: 100dvh;
  padding: 12px 14px 14px;
  gap: 8px;
  border-left: 1px solid rgba(255, 255, 255, 0.05);
  border-right: 1px solid rgba(255, 255, 255, 0.05);
}

.app-container.voice-focus .avatar-stage {
  flex: 1;
  min-height: 0;
}

.app-container.voice-focus .avatar-frame,
.app-container.voice-focus .avatar-canvas {
  width: 265px;
  height: 265px;
}

.app-container.voice-focus .chat-section {
  display: none;
}

.app-container.voice-focus .live-subtitle {
  display: block !important;
}

/* Header */
.hud-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  border-bottom: 1px solid rgba(255, 255, 255, 0.08);
  padding-bottom: 7px;
  z-index: 5;
}

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

.brand-logo {
  width: 24px;
  height: 24px;
  object-fit: contain;
  filter: drop-shadow(0 0 6px rgba(124, 92, 255, 0.75));
}

.brand h1 {
  font-size: 15px;
  letter-spacing: 2px;
  font-weight: 700;
}

.brand h1 span {
  color: var(--accent);
  transition: color 0.4s;
}

.header-actions {
  display: flex;
  gap: 5px;
}

.icon-btn {
  background: var(--panel);
  color: var(--text);
  border: 1px solid rgba(255, 255, 255, 0.14);
  padding: 4px 8px;
  border-radius: 7px;
  cursor: pointer;
  font-size: 11px;
  transition: border-color 0.2s, background 0.2s;
}

.icon-btn.active {
  border-color: var(--accent);
  background: rgba(18, 189, 235, 0.16);
  color: #fff;
}

/* Settings Overlay */
.settings-panel {
  position: absolute;
  top: 46px;
  left: 12px;
  right: 12px;
  bottom: 12px;
  background: rgba(9, 14, 26, 0.98);
  border: 1px solid var(--accent);
  border-radius: 14px;
  padding: 12px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  box-shadow: 0 14px 40px rgba(0, 0, 0, 0.85);
  z-index: 30;
}

.settings-panel.hidden,
.hidden {
  display: none !important;
}

.settings-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  border-bottom: 1px solid rgba(255, 255, 255, 0.1);
  padding-bottom: 8px;
}

.settings-title {
  font-size: 12px;
  font-weight: 700;
  color: var(--accent);
  letter-spacing: 1.2px;
  text-transform: none;
}

.close-x {
  background: transparent;
  border: none;
  color: var(--muted);
  font-size: 16px;
  cursor: pointer;
}

.settings-scroll {
  flex: 1;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding-right: 4px;
}

.setting-group {
  display: flex;
  flex-direction: column;
  gap: 7px;
  background: rgba(255, 255, 255, 0.03);
  border: 1px solid rgba(255, 255, 255, 0.07);
  padding: 10px;
  border-radius: 10px;
}

.group-label {
  font-size: 10px;
  text-transform: none;
  letter-spacing: 1px;
  color: var(--accent);
  font-weight: 700;
}

.sub-label {
  font-size: 10.5px;
  color: var(--muted);
  margin-top: 2px;
}

.seg-row,
.voice-pick-row {
  display: flex;
  gap: 6px;
  align-items: center;
}

.voice-pick-row select {
  flex: 1;
  min-width: 0;
}

.test-voice-btn {
  background: rgba(18, 189, 235, 0.18);
  color: #fff;
  border: 1px solid var(--accent);
  padding: 7px 10px;
  border-radius: 7px;
  cursor: pointer;
  font-size: 11px;
  font-weight: 700;
  white-space: nowrap;
}

.seg-btn {
  flex: 1;
  background: var(--panel);
  color: var(--muted);
  border: 1px solid rgba(255, 255, 255, 0.12);
  padding: 7px;
  border-radius: 8px;
  cursor: pointer;
  font-size: 12px;
  font-weight: 600;
}

.seg-btn.active {
  color: #fff;
  border-color: var(--accent);
  background: rgba(18, 189, 235, 0.16);
}

.switch-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 12px;
  color: var(--text);
  cursor: pointer;
}

.switch-row input[type="checkbox"] {
  width: 16px;
  height: 16px;
  accent-color: var(--accent);
  cursor: pointer;
}

.setting-group input[type="range"] {
  width: 100%;
  accent-color: var(--accent);
  cursor: pointer;
}

.setting-group input[type="password"],
.setting-group input[type="text"],
.setting-group select {
  background: #060a13;
  color: #fff;
  border: 1px solid rgba(255, 255, 255, 0.16);
  padding: 7px 9px;
  border-radius: 7px;
  font-size: 12px;
  outline: none;
}

.danger-btn {
  background: rgba(255, 59, 48, 0.15);
  color: #ff6b6b;
  border: 1px solid rgba(255, 59, 48, 0.4);
  padding: 7px;
  border-radius: 7px;
  cursor: pointer;
  font-size: 12px;
  font-weight: 600;
}

.save-btn {
  background: var(--accent);
  color: #050811;
  font-weight: 700;
  border: none;
  padding: 9px;
  border-radius: 8px;
  cursor: pointer;
  font-size: 13px;
}

/* Character Stage */
.avatar-stage {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 4px 0;
  min-height: 224px;
  border-radius: 16px;
  overflow: hidden;
  background: radial-gradient(circle at 50% 48%, rgba(18, 189, 235, 0.08) 0%, transparent 72%);
  transition: all 0.3s ease;
}

.particle-canvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  z-index: 1;
}

.avatar-aura {
  position: absolute;
  width: 175px;
  height: 175px;
  border-radius: 50%;
  background: radial-gradient(circle, var(--accent-glow) 0%, transparent 72%);
  filter: blur(22px);
  z-index: 1;
  opacity: 0.65;
  transition: all 0.4s ease;
  animation: auraBreath 4s ease-in-out infinite;
}

.cam-preview {
  position: absolute;
  top: 6px;
  right: 6px;
  width: 54px;
  height: 40px;
  object-fit: cover;
  border-radius: 8px;
  border: 1px solid var(--accent);
  opacity: 0.88;
  z-index: 6;
  transform: scaleX(-1);
}

.cam-badge {
  position: absolute;
  top: 6px;
  left: 6px;
  font-size: 10.5px;
  font-weight: 600;
  letter-spacing: 0.3px;
  color: #38f9d7;
  background: rgba(0, 0, 0, 0.55);
  border: 1px solid rgba(56, 249, 215, 0.4);
  padding: 2px 7px;
  border-radius: 10px;
  z-index: 6;
}

.screen-badge {
  position: absolute;
  top: 28px;
  left: 6px;
  font-size: 10px;
  font-weight: 600;
  color: #a78bfa;
  background: rgba(0, 0, 0, 0.58);
  border: 1px solid rgba(167, 139, 250, 0.45);
  padding: 2px 7px;
  border-radius: 10px;
  z-index: 6;
}

.live-voice-badge {
  position: absolute;
  bottom: 24px;
  left: 8px;
  font-size: 9px;
  font-weight: 700;
  letter-spacing: 0.7px;
  color: #fbbf24;
  background: rgba(251, 191, 36, 0.14);
  border: 1px solid rgba(251, 191, 36, 0.45);
  padding: 2px 7px;
  border-radius: 10px;
  z-index: 6;
}

.avatar-stage.listening .screen-badge {
  position: absolute;
  top: 28px;
  left: 6px;
  font-size: 10px;
  font-weight: 600;
  color: #a78bfa;
  background: rgba(0, 0, 0, 0.58);
  border: 1px solid rgba(167, 139, 250, 0.45);
  padding: 2px 7px;
  border-radius: 10px;
  z-index: 6;
}

.live-voice-badge {
  color: #4ade80;
  background: rgba(74, 222, 128, 0.16);
  border-color: rgba(74, 222, 128, 0.5);
}

.avatar-frame {
  position: relative;
  width: 196px;
  height: 196px;
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 2;
  background: transparent;
  transition: width 0.3s ease, height 0.3s ease;
}

.avatar-canvas {
  width: 196px;
  height: 196px;
  background: transparent;
  filter: var(--avatar-filter) drop-shadow(0 0 14px var(--accent-glow));
  transition: width 0.3s ease, height 0.3s ease, filter 0.45s ease;
}

/* Non-Hue-Rotated Emotion Overlay (True Pink Hearts — never turns green!) */
.emo-overlay {
  position: absolute;
  inset: 0;
  pointer-events: none;
  z-index: 4;
}

.love-hearts {
  position: absolute;
  inset: 0;
  opacity: 0;
  transition: opacity 0.4s ease;
}

.avatar-stage.emo-love .love-hearts {
  opacity: 1;
}

.love-hearts span {
  position: absolute;
  color: #ff4da6;
  font-size: 14px;
  text-shadow: 0 0 8px rgba(255, 77, 166, 0.85);
  animation: floatHeart 3s ease-out infinite;
}

.love-hearts span:nth-child(1) { left: 18%; bottom: 22%; animation-delay: 0s; }
.love-hearts span:nth-child(2) { left: 76%; bottom: 26%; animation-delay: 1s; }
.love-hearts span:nth-child(3) { left: 48%; bottom: 14%; animation-delay: 2s; }

@keyframes floatHeart {
  0% { transform: translateY(0) scale(0.75); opacity: 0; }
  25% { opacity: 0.95; }
  100% { transform: translateY(-85px) scale(1.2); opacity: 0; }
}

.avatar-stage.speaking .avatar-aura {
  opacity: 1;
  transform: scale(1.22);
}

@keyframes auraBreath {
  0%, 100% { transform: scale(0.95); opacity: 0.52; }
  50% { transform: scale(1.08); opacity: 0.82; }
}

/* Voice Waveform */
.voice-wave {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 4px;
  height: 14px;
  margin-top: -6px;
  z-index: 3;
  opacity: 0.25;
}

.voice-wave span {
  display: block;
  width: 3px;
  height: 4px;
  border-radius: 3px;
  background: var(--accent);
  box-shadow: 0 0 6px var(--accent);
}

.avatar-stage.speaking .voice-wave,
.avatar-stage.listening .voice-wave { opacity: 1; }

.avatar-stage.speaking .voice-wave span { animation: waveBar 0.42s ease-in-out infinite alternate; }
.avatar-stage.listening .voice-wave span { animation: waveBar 0.82s ease-in-out infinite alternate; }

.voice-wave span:nth-child(1) { animation-delay: 0.05s; }
.voice-wave span:nth-child(2) { animation-delay: 0.18s; }
.voice-wave span:nth-child(3) { animation-delay: 0.30s; }
.voice-wave span:nth-child(4) { animation-delay: 0.12s; }
.voice-wave span:nth-child(5) { animation-delay: 0.26s; }
.voice-wave span:nth-child(6) { animation-delay: 0.15s; }
.voice-wave span:nth-child(7) { animation-delay: 0.04s; }

@keyframes waveBar {
  0% { height: 4px; }
  100% { height: 14px; }
}

.status-text {
  margin-top: 2px;
  font-size: 11px;
  letter-spacing: 0.6px;
  color: var(--accent);
  text-transform: none;
  font-weight: 600;
  z-index: 3;
}

.live-subtitle {
  margin-top: 14px;
  max-width: 90%;
  padding: 10px 14px;
  border-radius: 12px;
  background: rgba(14, 21, 36, 0.85);
  border: 1px solid rgba(255, 255, 255, 0.1);
  color: var(--text);
  font-size: 13px;
  line-height: 1.5;
  text-align: center;
  z-index: 4;
}

/* Chat Section */
.chat-section {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.chat-box {
  flex: 1;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 8px 4px;
  border-top: 1px solid rgba(255, 255, 255, 0.07);
  border-bottom: 1px solid rgba(255, 255, 255, 0.07);
}

.chat-box::-webkit-scrollbar { width: 5px; }
.chat-box::-webkit-scrollbar-thumb {
  background: rgba(255, 255, 255, 0.16);
  border-radius: 10px;
}

.msg { display: flex; }
.msg.user { justify-content: flex-end; }
.msg.ai { justify-content: flex-start; }

.bubble {
  max-width: 86%;
  padding: 8px 12px;
  border-radius: 14px;
  font-size: 13px;
  line-height: 1.5;
  white-space: pre-wrap;
  word-wrap: break-word;
}

.msg.user .bubble {
  background: var(--accent);
  color: #050811;
  font-weight: 600;
  border-bottom-right-radius: 4px;
}

.msg.ai .bubble {
  background: var(--panel);
  border: 1px solid rgba(255, 255, 255, 0.1);
  color: var(--text);
  border-bottom-left-radius: 4px;
}

/* Input Area */
.input-area {
  display: flex;
  gap: 6px;
  align-items: center;
}

.input-area input {
  flex: 1;
  min-width: 0;
  background: var(--panel);
  color: #fff;
  border: 1px solid rgba(255, 255, 255, 0.15);
  padding: 9px 12px;
  border-radius: 22px;
  font-size: 13px;
  outline: none;
}

.input-area input:focus { border-color: var(--accent); }

.mic-btn,
.voice-toggle-btn,
.send-btn {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  border: none;
  cursor: pointer;
  font-size: 15px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.mic-btn {
  background: var(--panel);
  color: #fff;
  border: 1px solid var(--accent);
}

.mic-btn.listening {
  background: #22c55e;
  border-color: #22c55e;
  color: #050811;
}

.voice-toggle-btn {
  background: var(--panel);
  color: var(--muted);
  border: 1px solid rgba(255, 255, 255, 0.14);
}

.voice-toggle-btn.active {
  color: #fff;
  border-color: var(--accent);
  background: rgba(18, 189, 235, 0.16);
}

.send-btn {
  background: var(--accent);
  color: #050811;
  font-weight: bold;
}


/* Self-Update Approval Card */
.update-card {
  margin-top: 8px;
  padding: 9px 10px;
  border-radius: 10px;
  background: rgba(18, 189, 235, 0.1);
  border: 1px solid var(--accent);
  display: flex;
  flex-direction: column;
  gap: 7px;
}

.update-card-title {
  font-size: 11px;
  font-weight: 700;
  color: var(--accent);
}

.update-card-actions {
  display: flex;
  gap: 6px;
}

.approve-btn {
  flex: 1;
  background: var(--accent);
  color: #050811;
  border: none;
  padding: 6px 8px;
  border-radius: 7px;
  font-size: 11.5px;
  font-weight: 700;
  cursor: pointer;
}

.reject-btn {
  background: rgba(255, 59, 48, 0.18);
  color: #ff8080;
  border: 1px solid rgba(255, 59, 48, 0.45);
  padding: 6px 10px;
  border-radius: 7px;
  font-size: 11.5px;
  font-weight: 600;
  cursor: pointer;
}


/* Stop Music Floating Pill */
.stop-music-badge {
  position: absolute;
  bottom: 24px;
  right: 8px;
  font-size: 9.5px;
  font-weight: 700;
  color: #fff;
  background: rgba(236, 72, 153, 0.28);
  border: 1px solid #ec4899;
  padding: 3px 8px;
  border-radius: 10px;
  cursor: pointer;
  z-index: 7;
}

/* Attachment Preview Bar */
.attach-preview {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 5px 10px;
  border-radius: 10px;
  background: rgba(18, 189, 235, 0.12);
  border: 1px solid rgba(18, 189, 235, 0.4);
  font-size: 11.5px;
  color: #e2e8f0;
}

/* Generated Media, File & Music Player Cards */
.gen-media-card {
  margin-top: 8px;
  display: flex;
  flex-direction: column;
  gap: 7px;
  padding: 8px;
  border-radius: 11px;
  background: rgba(6, 10, 19, 0.78);
  border: 1px solid rgba(18, 189, 235, 0.35);
}

.gen-media-card img {
  width: 100%;
  max-height: 240px;
  object-fit: cover;
  border-radius: 8px;
  border: 1px solid rgba(255, 255, 255, 0.12);
}

.gen-media-actions {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
}

.dl-btn {
  flex: 1;
  background: rgba(18, 189, 235, 0.18);
  color: #fff;
  border: 1px solid var(--accent);
  padding: 6px 8px;
  border-radius: 7px;
  font-size: 11px;
  font-weight: 700;
  cursor: pointer;
  text-align: center;
  text-decoration: none;
}

.dl-btn:hover {
  background: var(--accent);
  color: #050811;
}

.file-card-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  font-size: 12px;
}

.music-card-header {
  display: flex;
  align-items: center;
  gap: 8px;
}

.music-cover {
  width: 46px !important;
  height: 46px !important;
  border-radius: 7px !important;
  flex-shrink: 0;
}

.music-meta {
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
}

.music-title {
  font-size: 12px;
  font-weight: 700;
  color: #fff;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.music-artist {
  font-size: 11px;
  color: var(--muted);
}

.music-audio {
  width: 100%;
  height: 32px;
  outline: none;
}

.delete-confirm-box {
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding: 8px;
  border-radius: 8px;
  background: rgba(255, 59, 48, 0.08);
  border: 1px solid rgba(255, 59, 48, 0.45);
  margin-top: 4px;
}


/* Preserve 100% Natural Human Skin Color on Custom Uploaded Photos (NO blue/hue-rotate tint!) */
.avatar-stage.custom-avatar-active .avatar-canvas {
  filter: drop-shadow(0 0 16px var(--accent-glow)) !important;
}

.install-btn {
  background: rgba(34, 197, 94, 0.2) !important;
  border-color: #22c55e !important;
  color: #4ade80 !important;
  font-weight: 700;
}


/* Live Face Calibration Preview inside Settings */
.face-calib-box {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-top: 6px;
  padding: 9px;
  border-radius: 10px;
  background: rgba(18, 189, 235, 0.06);
  border: 1px solid rgba(18, 189, 235, 0.35);
}

.calib-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 6px;
}

.calib-preview-wrap {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 5px;
  padding: 6px 0 2px;
}

.calib-preview-canvas {
  width: 170px;
  height: 170px;
  border-radius: 50%;
  border: 2px solid var(--accent);
  background: #060a13;
  box-shadow: 0 0 16px var(--accent-glow);
}

.calib-legend {
  font-size: 10px;
  color: #cbd5e1;
  text-align: center;
}

/* Full Responsive Layout: Mobile Phones, Tablets, Laptops & Desktops */
.app-container {
  padding-bottom: max(12px, env(safe-area-inset-bottom));
  padding-top: max(10px, env(safe-area-inset-top));
}

@media (max-width: 480px) {
  .app-container {
    max-width: 100%;
    padding: max(8px, env(safe-area-inset-top)) 10px max(10px, env(safe-area-inset-bottom));
    gap: 6px;
    border-left: none;
    border-right: none;
  }

  .hud-header {
    flex-wrap: wrap;
    gap: 6px;
    padding-bottom: 6px;
  }

  .brand h1 {
    font-size: 13.5px;
    letter-spacing: 1.4px;
  }

  .header-actions {
    gap: 4px;
  }

  .icon-btn {
    padding: 5px 7px;
    font-size: 11px;
    min-height: 32px;
  }

  .avatar-stage {
    min-height: 176px;
    padding: 2px 0;
  }

  .avatar-frame,
  .avatar-canvas {
    width: 158px;
    height: 158px;
  }

  .app-container.voice-focus .avatar-frame,
  .app-container.voice-focus .avatar-canvas {
    width: 230px;
    height: 230px;
  }

  .input-area {
    gap: 5px;
  }

  .input-area input {
    padding: 9px 11px;
    font-size: 14px;
  }

  .mic-btn,
  .voice-toggle-btn,
  .send-btn {
    width: 38px;
    height: 38px;
    font-size: 15px;
  }

  .settings-panel {
    top: 44px;
    left: 6px;
    right: 6px;
    bottom: 6px;
    padding: 10px;
  }

  .calib-preview-canvas {
    width: 150px;
    height: 150px;
  }
}

@media (max-height: 640px) {
  .avatar-stage {
    min-height: 148px;
  }
  .avatar-frame,
  .avatar-canvas {
    width: 134px;
    height: 134px;
  }
}

@media (min-width: 768px) {
  body {
    padding: 14px 0;
  }
  .app-container {
    height: calc(100dvh - 28px);
    max-width: 560px;
    border-radius: 20px;
    border: 1px solid rgba(18, 189, 235, 0.18);
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.65);
    background: rgba(7, 11, 22, 0.72);
    backdrop-filter: blur(12px);
  }
}
