:root {
  --bg-dark: #090a0f;
  --bg-surface: rgba(18, 20, 29, 0.75);
  --bg-card: rgba(24, 27, 39, 0.85);
  --border-glass: rgba(255, 255, 255, 0.08);
  --border-glass-glow: rgba(236, 72, 153, 0.25);
  
  --primary-gradient: linear-gradient(135deg, #ec4899 0%, #8b5cf6 50%, #6366f1 100%);
  --bubble-user-gradient: linear-gradient(135deg, #6366f1 0%, #a855f7 100%);
  --bubble-assistant: rgba(24, 27, 40, 0.9);
  
  --accent-pink: #ec4899;
  --accent-purple: #a855f7;
  --accent-glow: rgba(236, 72, 153, 0.35);
  
  --text-primary: #f8fafc;
  --text-secondary: #94a3b8;
  --text-muted: #64748b;
  --success: #10b981;
  --danger: #f43f5e;
  
  --font-family: 'Plus Jakarta Sans', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
}

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

body {
  font-family: var(--font-family);
  background-color: var(--bg-dark);
  color: var(--text-primary);
  height: 100dvh;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  position: relative;
}

/* Ambient glow background */
.ambient-glow {
  position: fixed;
  top: -15%;
  left: 50%;
  transform: translateX(-50%);
  width: 500px;
  height: 350px;
  background: radial-gradient(circle, rgba(168, 85, 247, 0.18) 0%, rgba(236, 72, 153, 0.12) 40%, transparent 70%);
  filter: blur(60px);
  pointer-events: none;
  z-index: 0;
}

#app {
  display: flex;
  flex-direction: column;
  height: 100%;
  position: relative;
  z-index: 1;
}

/* Header */
header {
  background: var(--bg-surface);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  border-bottom: 1px solid var(--border-glass);
  padding: calc(10px + env(safe-area-inset-top, 0px)) 16px 12px 16px;
  display: flex;
  align-items: center;
  gap: 12px;
  z-index: 10;
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.3);
}

.avatar-container {
  position: relative;
  width: 44px;
  height: 44px;
}

.avatar {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  overflow: hidden;
  background: var(--primary-gradient);
  display: flex;
  align-items: center;
  justify-content: center;
  border: 2px solid rgba(255, 255, 255, 0.15);
  box-shadow: 0 2px 12px var(--accent-glow);
  position: relative;
}

.avatar img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.avatar-fallback {
  font-weight: 700;
  font-size: 18px;
  color: #fff;
}

.online-indicator {
  position: absolute;
  bottom: 0px;
  right: 0px;
  width: 12px;
  height: 12px;
  border-radius: 50%;
  background-color: var(--success);
  border: 2px solid var(--bg-dark);
  box-shadow: 0 0 8px rgba(16, 185, 129, 0.8);
}

.header-info {
  flex: 1;
  display: flex;
  flex-direction: column;
}

.name-row {
  display: flex;
  align-items: center;
  gap: 6px;
}

.name-row h1 {
  font-size: 17px;
  font-weight: 700;
  letter-spacing: -0.3px;
  background: linear-gradient(180deg, #ffffff 0%, #cbd5e1 100%);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
}

.sparkle {
  font-size: 14px;
  animation: shimmer 2s infinite ease-in-out;
}

@keyframes shimmer {
  0%, 100% { transform: scale(1) rotate(0deg); opacity: 0.8; }
  50% { transform: scale(1.15) rotate(15deg); opacity: 1; }
}

.status {
  font-size: 11.5px;
  font-weight: 500;
  color: var(--accent-pink);
  letter-spacing: 0.2px;
}

.status.offline {
  color: var(--text-muted);
}

.btn-icon {
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid var(--border-glass);
  color: var(--text-secondary);
  width: 40px;
  height: 40px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  border-radius: 50%;
  transition: all 0.2s ease;
}

.btn-icon:hover, .btn-icon:active {
  background: rgba(255, 255, 255, 0.12);
  color: #fff;
  transform: scale(1.05);
}

/* Chat Area */
#chat-container {
  flex: 1;
  overflow-y: auto;
  padding: 16px 16px calc(85px + env(safe-area-inset-bottom, 0px)) 16px;
  display: flex;
  flex-direction: column;
  scroll-behavior: smooth;
}

#messages {
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.message {
  display: flex;
  flex-direction: column;
  max-width: 82%;
  animation: popIn 0.3s cubic-bezier(0.16, 1, 0.3, 1) forwards;
}

@keyframes popIn {
  0% { opacity: 0; transform: translateY(12px) scale(0.97); }
  100% { opacity: 1; transform: translateY(0) scale(1); }
}

.message.user {
  align-self: flex-end;
}

.message.assistant {
  align-self: flex-start;
}

.bubble {
  padding: 12px 16px;
  border-radius: 20px;
  position: relative;
  word-wrap: break-word;
  font-size: 15px;
  line-height: 1.5;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.25);
}

.message.user .bubble {
  background: var(--bubble-user-gradient);
  color: #ffffff;
  border-bottom-right-radius: 4px;
  box-shadow: 0 4px 20px rgba(99, 102, 241, 0.3);
}

.message.assistant .bubble {
  background: var(--bubble-assistant);
  color: var(--text-primary);
  border-bottom-left-radius: 4px;
  border: 1px solid var(--border-glass);
  backdrop-filter: blur(10px);
}

.bubble .text {
  white-space: pre-wrap;
  font-weight: 400;
}

.bubble .text strong {
  color: #fff;
  font-weight: 600;
}

.bubble .meta {
  display: flex;
  justify-content: flex-end;
  align-items: center;
  margin-top: 6px;
  gap: 8px;
}

.time {
  font-size: 10.5px;
  color: rgba(255, 255, 255, 0.5);
  font-weight: 500;
}

/* Audio Player Button in Bubble */
.btn-play-audio {
  background: rgba(236, 72, 153, 0.15);
  border: 1px solid rgba(236, 72, 153, 0.3);
  color: #f472b6;
  font-size: 13px;
  cursor: pointer;
  padding: 4px 10px;
  border-radius: 20px;
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-weight: 600;
  transition: all 0.2s ease;
}

.btn-play-audio:hover, .btn-play-audio:active {
  background: rgba(236, 72, 153, 0.3);
  transform: scale(1.05);
}

.btn-play-audio.playing {
  background: var(--accent-pink);
  color: #fff;
  box-shadow: 0 0 14px var(--accent-glow);
  animation: audioPulse 1.2s infinite ease-in-out;
}

@keyframes audioPulse {
  0%, 100% { transform: scale(1); box-shadow: 0 0 10px var(--accent-glow); }
  50% { transform: scale(1.08); box-shadow: 0 0 20px var(--accent-glow); }
}

/* Typing Indicator */
#typing-indicator {
  align-self: flex-start;
  display: flex;
  align-items: center;
  gap: 10px;
  margin-top: 6px;
  animation: popIn 0.3s ease;
}

.typing-avatar img {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  object-fit: cover;
  border: 1.5px solid var(--accent-pink);
}

.typing-bubble {
  background: var(--bubble-assistant);
  border: 1px solid var(--border-glass);
  padding: 8px 14px;
  border-radius: 18px;
  display: flex;
  align-items: center;
  gap: 8px;
}

.typing-dots {
  display: flex;
  gap: 4px;
}

.typing-dots span {
  width: 5px;
  height: 5px;
  background-color: var(--accent-pink);
  border-radius: 50%;
  animation: typingBounce 1.4s infinite ease-in-out both;
}

.typing-dots span:nth-child(1) { animation-delay: -0.32s; }
.typing-dots span:nth-child(2) { animation-delay: -0.16s; }

@keyframes typingBounce {
  0%, 80%, 100% { transform: scale(0.6); opacity: 0.4; }
  40% { transform: scale(1.2); opacity: 1; }
}

.typing-label {
  font-size: 12px;
  color: var(--text-secondary);
}

.hidden {
  display: none !important;
}

/* Floating Input Bar */
footer {
  position: fixed;
  bottom: 0;
  left: 0;
  width: 100%;
  z-index: 15;
  pointer-events: none;
  padding: 0 12px calc(12px + env(safe-area-inset-bottom, 0px)) 12px;
}

.input-wrapper {
  max-width: 700px;
  margin: 0 auto;
  pointer-events: auto;
}

.input-container {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  background: rgba(22, 25, 37, 0.92);
  backdrop-filter: blur(24px);
  -webkit-backdrop-filter: blur(24px);
  border: 1px solid var(--border-glass);
  border-radius: 28px;
  padding: 6px 8px 6px 18px;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.5), 0 0 1px rgba(255, 255, 255, 0.15);
  transition: border-color 0.2s ease, box-shadow 0.2s ease;
}

.input-container:focus-within {
  border-color: rgba(236, 72, 153, 0.4);
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.6), 0 0 16px rgba(236, 72, 153, 0.2);
}

#message-input {
  flex: 1;
  background: transparent;
  border: none;
  color: var(--text-primary);
  font-size: 15px;
  font-family: inherit;
  resize: none;
  padding: 10px 0;
  max-height: 120px;
  outline: none;
  line-height: 1.4;
}

#message-input::placeholder {
  color: var(--text-muted);
}

.btn-action {
  width: 42px;
  height: 42px;
  border-radius: 50%;
  border: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s ease;
  flex-shrink: 0;
}

.btn-voice {
  background: rgba(255, 255, 255, 0.06);
  color: var(--accent-pink);
  border: 1px solid rgba(236, 72, 153, 0.2);
}

.btn-voice:hover, .btn-voice:active {
  background: rgba(236, 72, 153, 0.2);
  transform: scale(1.05);
}

.btn-voice.recording {
  background: var(--danger) !important;
  color: #fff !important;
  box-shadow: 0 0 20px rgba(244, 63, 94, 0.7);
  animation: recordPulse 1s infinite alternate;
}

@keyframes recordPulse {
  0% { transform: scale(1); }
  100% { transform: scale(1.15); }
}

.btn-send {
  background: var(--primary-gradient);
  color: #ffffff;
  box-shadow: 0 2px 12px var(--accent-glow);
}

.btn-send:hover, .btn-send:active {
  transform: scale(1.05);
  box-shadow: 0 4px 18px var(--accent-glow);
}

/* Settings Drawer */
#settings-panel {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: #090a0f;
  z-index: 50;
  display: flex;
  flex-direction: column;
  transform: translateX(0);
  transition: transform 0.35s cubic-bezier(0.16, 1, 0.3, 1);
}

#settings-panel.hidden {
  display: flex !important;
  transform: translateX(100%);
  pointer-events: none;
}

.settings-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: calc(14px + env(safe-area-inset-top, 0px)) 16px 14px 16px;
  background: var(--bg-surface);
  border-bottom: 1px solid var(--border-glass);
  backdrop-filter: blur(20px);
}

.settings-title-row {
  display: flex;
  align-items: center;
  gap: 12px;
}

.settings-avatar {
  width: 46px;
  height: 46px;
  border-radius: 50%;
  object-fit: cover;
  border: 2px solid var(--accent-pink);
  box-shadow: 0 2px 10px var(--accent-glow);
}

.settings-header h2 {
  font-size: 17px;
  font-weight: 700;
}

.settings-subtitle {
  font-size: 12px;
  color: var(--text-muted);
}

.settings-content {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
  padding-bottom: calc(30px + env(safe-area-inset-bottom, 0px));
  display: flex;
  flex-direction: column;
  gap: 16px;
  max-width: 650px;
  margin: 0 auto;
  width: 100%;
}

.settings-card {
  background: var(--bg-card);
  border: 1px solid var(--border-glass);
  border-radius: 18px;
  padding: 16px;
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.3);
}

.settings-card h3 {
  font-size: 13.5px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.8px;
  color: var(--accent-pink);
  margin-bottom: 14px;
}

.section-header-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 6px;
}

.section-header-row h3 {
  margin-bottom: 0;
}

.section-info {
  font-size: 12px;
  color: var(--text-muted);
  margin-bottom: 12px;
}

.badge {
  background: rgba(236, 72, 153, 0.15);
  color: #f472b6;
  font-size: 11px;
  padding: 2px 8px;
  border-radius: 12px;
  font-weight: 600;
}

.input-group {
  margin-bottom: 14px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.input-group:last-child {
  margin-bottom: 0;
}

.input-group.toggle-group {
  flex-direction: row;
  justify-content: space-between;
  align-items: center;
  margin-top: 10px;
}

.toggle-title {
  font-size: 14px;
  font-weight: 600;
  display: block;
}

.toggle-desc {
  font-size: 11.5px;
  color: var(--text-muted);
  display: block;
}

label {
  font-size: 13px;
  font-weight: 500;
  color: var(--text-secondary);
}

input[type="text"], select {
  background: rgba(10, 12, 18, 0.8);
  border: 1px solid var(--border-glass);
  color: var(--text-primary);
  padding: 12px 14px;
  border-radius: 12px;
  font-size: 14.5px;
  font-family: inherit;
  outline: none;
  transition: border-color 0.2s;
}

input[type="text"]:focus, select:focus {
  border-color: var(--accent-pink);
  box-shadow: 0 0 10px var(--accent-glow);
}

/* Switch */
.switch {
  position: relative;
  display: inline-block;
  width: 48px;
  height: 26px;
  flex-shrink: 0;
}

.switch input { opacity: 0; width: 0; height: 0; }

.slider {
  position: absolute;
  cursor: pointer;
  top: 0; left: 0; right: 0; bottom: 0;
  background-color: rgba(255, 255, 255, 0.15);
  transition: .3s cubic-bezier(0.16, 1, 0.3, 1);
  border-radius: 34px;
}

.slider:before {
  position: absolute;
  content: "";
  height: 20px;
  width: 20px;
  left: 3px;
  bottom: 3px;
  background-color: white;
  transition: .3s cubic-bezier(0.16, 1, 0.3, 1);
  border-radius: 50%;
}

input:checked + .slider {
  background: var(--primary-gradient);
}

input:checked + .slider:before {
  transform: translateX(22px);
}

/* Memories list */
#memory-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
  max-height: 260px;
  overflow-y: auto;
}

.memory-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 10px 12px;
  background: rgba(10, 12, 18, 0.6);
  border: 1px solid var(--border-glass);
  border-radius: 12px;
  gap: 10px;
}

.memory-text {
  flex: 1;
  font-size: 13px;
  color: var(--text-primary);
  line-height: 1.4;
}

.btn-delete {
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  padding: 4px;
  font-size: 14px;
  border-radius: 6px;
  transition: color 0.2s, transform 0.2s;
}

.btn-delete:hover {
  color: var(--danger);
  transform: scale(1.15);
}

.info-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 13.5px;
}

.badge-status {
  padding: 4px 10px;
  border-radius: 12px;
  font-size: 11.5px;
  font-weight: 600;
}

.badge-status.online {
  background: rgba(16, 185, 129, 0.15);
  color: #34d399;
}
