:root {
  --bg-deep: #08080e;
  --bg-surface: #0f0f18;
  --bg-elevated: #161622;
  --bg-hover: #1c1c2e;
  --border: rgba(255, 255, 255, 0.06);
  --border-focus: rgba(232, 86, 127, 0.5);
  --text-primary: #ece8e1;
  --text-secondary: #7a7688;
  --text-muted: #4a4658;
  --accent: #e8567f;
  --accent-glow: rgba(232, 86, 127, 0.15);
  --accent-soft: #f0a0b8;
  --glass: rgba(15, 15, 24, 0.75);
  --glass-border: rgba(255, 255, 255, 0.08);
  --radius-sm: 12px;
  --radius-md: 18px;
  --radius-lg: 24px;
  --font-body: 'Outfit', sans-serif;
  --font-display: 'Playfair Display', serif;
}

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

html, body {
  height: 100%;
}

body {
  font-family: var(--font-body);
  background: var(--bg-deep);
  color: var(--text-primary);
  height: 100dvh;
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

/* --- Ambient background --- */
.bg-glow {
  position: fixed;
  border-radius: 50%;
  filter: blur(120px);
  opacity: 0.35;
  pointer-events: none;
  z-index: 0;
  animation: drift 20s ease-in-out infinite alternate;
}

.bg-glow--1 {
  width: 420px;
  height: 420px;
  background: radial-gradient(circle, #e8567f 0%, transparent 70%);
  top: -120px;
  right: -80px;
}

.bg-glow--2 {
  width: 350px;
  height: 350px;
  background: radial-gradient(circle, #7c3aed 0%, transparent 70%);
  bottom: -100px;
  left: -60px;
  animation-delay: -10s;
}

@keyframes drift {
  0%   { transform: translate(0, 0) scale(1); }
  100% { transform: translate(30px, 20px) scale(1.15); }
}

.noise-overlay {
  position: fixed;
  inset: 0;
  background-image: url("data:image/svg+xml,%3Csvg viewBox='0 0 256 256' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.9' numOctaves='4' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)' opacity='0.04'/%3E%3C/svg%3E");
  background-repeat: repeat;
  pointer-events: none;
  z-index: 0;
}

/* --- Layout --- */
.chat-container {
  position: relative;
  z-index: 1;
  display: flex;
  flex-direction: column;
  height: 100dvh;
  max-width: 520px;
  margin: 0 auto;
}

/* --- Header --- */
.chat-header {
  padding: 14px 16px;
  background: var(--glass);
  backdrop-filter: blur(24px);
  -webkit-backdrop-filter: blur(24px);
  border-bottom: 1px solid var(--glass-border);
}

.persona-selector {
  display: flex;
  gap: 10px;
}

.persona-btn {
  flex: 1;
  padding: 0;
  border: 1.5px solid var(--border);
  border-radius: var(--radius-sm);
  background: transparent;
  cursor: pointer;
  transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  outline: none;
}

.persona-btn:hover {
  border-color: rgba(255, 255, 255, 0.12);
  background: var(--bg-hover);
}

.persona-btn.active {
  border-color: var(--accent);
  background: var(--accent-glow);
  box-shadow: 0 0 20px rgba(232, 86, 127, 0.08), inset 0 0 20px rgba(232, 86, 127, 0.04);
}

.persona-card {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
}

.persona-avatar-wrap {
  position: relative;
  flex-shrink: 0;
}

.persona-avatar {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: var(--font-display);
  font-size: 16px;
  font-weight: 500;
  font-style: italic;
  color: #fff;
  background: linear-gradient(135deg, var(--accent), var(--accent2));
  box-shadow: 0 2px 12px rgba(0, 0, 0, 0.3);
}

.online-dot {
  position: absolute;
  bottom: 1px;
  right: 1px;
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: #34d399;
  border: 2px solid var(--bg-surface);
  animation: pulse-dot 3s ease-in-out infinite;
}

@keyframes pulse-dot {
  0%, 100% { box-shadow: 0 0 0 0 rgba(52, 211, 153, 0.4); }
  50%      { box-shadow: 0 0 0 4px rgba(52, 211, 153, 0); }
}

.persona-info {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 1px;
}

.persona-name {
  font-weight: 500;
  font-size: 14px;
  color: var(--text-primary);
  letter-spacing: 0.01em;
}

.persona-desc {
  font-size: 11.5px;
  color: var(--text-secondary);
  font-weight: 300;
}

/* Model badge */
.model-badge {
  margin-top: 8px;
  font-size: 10.5px;
  font-weight: 300;
  color: var(--text-muted);
  text-align: center;
  letter-spacing: 0.03em;
  min-height: 16px;
  opacity: 0;
  transition: opacity 0.3s;
}

.model-badge.visible {
  opacity: 1;
}

/* --- Messages --- */
.messages {
  flex: 1;
  overflow-y: auto;
  padding: 20px 16px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  scroll-behavior: smooth;
}

.messages::-webkit-scrollbar {
  width: 3px;
}

.messages::-webkit-scrollbar-track {
  background: transparent;
}

.messages::-webkit-scrollbar-thumb {
  background: rgba(255, 255, 255, 0.08);
  border-radius: 3px;
}

/* Welcome */
.welcome-message {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
  margin: auto 0;
  padding: 40px 20px;
  animation: fadeUp 0.6s ease-out;
}

.welcome-icon {
  color: var(--accent);
  opacity: 0.5;
  animation: heartbeat 4s ease-in-out infinite;
}

@keyframes heartbeat {
  0%, 100% { transform: scale(1); }
  5%       { transform: scale(1.12); }
  10%      { transform: scale(1); }
  15%      { transform: scale(1.08); }
  20%      { transform: scale(1); }
}

.welcome-title {
  font-family: var(--font-display);
  font-size: 22px;
  font-style: italic;
  color: var(--text-primary);
  opacity: 0.7;
}

.welcome-sub {
  font-size: 13px;
  color: var(--text-muted);
  font-weight: 300;
}

/* Message bubbles */
.message {
  max-width: 78%;
  padding: 10px 16px;
  line-height: 1.55;
  font-size: 14.5px;
  font-weight: 300;
  word-wrap: break-word;
  white-space: pre-wrap;
  animation: msgIn 0.3s cubic-bezier(0.16, 1, 0.3, 1);
  position: relative;
}

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

@keyframes fadeUp {
  0%   { opacity: 0; transform: translateY(16px); }
  100% { opacity: 1; transform: translateY(0); }
}

.message.user {
  align-self: flex-end;
  background: linear-gradient(135deg, #e8567f, #d44070);
  color: #fff;
  border-radius: var(--radius-md) var(--radius-md) 6px var(--radius-md);
  box-shadow: 0 2px 16px rgba(232, 86, 127, 0.2);
}

.message.assistant {
  align-self: flex-start;
  background: var(--bg-elevated);
  color: var(--text-primary);
  border-radius: var(--radius-md) var(--radius-md) var(--radius-md) 6px;
  border: 1px solid var(--border);
}

/* --- Typing indicator --- */
.typing-indicator {
  padding: 4px 16px 8px;
}

.typing-bubble {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 8px 14px;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius-md) var(--radius-md) var(--radius-md) 6px;
  animation: msgIn 0.3s cubic-bezier(0.16, 1, 0.3, 1);
}

.typing-bubble .dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--accent-soft);
  opacity: 0.5;
  animation: typingDot 1.4s ease-in-out infinite;
}

.typing-bubble .dot:nth-child(2) { animation-delay: 0.15s; }
.typing-bubble .dot:nth-child(3) { animation-delay: 0.3s; }

@keyframes typingDot {
  0%, 60%, 100% { transform: translateY(0); opacity: 0.3; }
  30%           { transform: translateY(-4px); opacity: 0.8; }
}

.typing-label {
  font-size: 11px;
  color: var(--text-muted);
  margin-left: 2px;
  font-weight: 300;
}

/* --- Input area --- */
.input-area {
  padding: 12px 16px 16px;
  background: var(--glass);
  backdrop-filter: blur(24px);
  -webkit-backdrop-filter: blur(24px);
  border-top: 1px solid var(--glass-border);
}

.input-wrap {
  display: flex;
  align-items: center;
  gap: 10px;
  background: var(--bg-surface);
  border: 1.5px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 4px 4px 4px 18px;
  transition: border-color 0.3s, box-shadow 0.3s;
}

.input-wrap:focus-within {
  border-color: var(--border-focus);
  box-shadow: 0 0 0 3px rgba(232, 86, 127, 0.08);
}

#messageInput {
  flex: 1;
  padding: 10px 0;
  border: none;
  background: transparent;
  color: var(--text-primary);
  font-family: var(--font-body);
  font-size: 14.5px;
  font-weight: 300;
  outline: none;
  min-width: 0;
}

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

#sendBtn {
  width: 40px;
  height: 40px;
  border: none;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--accent), #d44070);
  color: #fff;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: transform 0.2s, opacity 0.2s, box-shadow 0.2s;
  box-shadow: 0 2px 12px rgba(232, 86, 127, 0.25);
}

#sendBtn:hover {
  transform: scale(1.06);
  box-shadow: 0 4px 20px rgba(232, 86, 127, 0.35);
}

#sendBtn:active {
  transform: scale(0.95);
}

#sendBtn:disabled {
  opacity: 0.25;
  cursor: not-allowed;
  transform: none;
  box-shadow: none;
}

#sendBtn svg {
  transform: translate(1px, 0);
}

/* --- Mobile adjustments --- */
@media (max-width: 520px) {
  .chat-container {
    max-width: 100%;
  }

  .bg-glow--1 {
    width: 280px;
    height: 280px;
  }

  .bg-glow--2 {
    width: 240px;
    height: 240px;
  }
}

/* --- Safe area for notched phones --- */
@supports (padding-bottom: env(safe-area-inset-bottom)) {
  .input-area {
    padding-bottom: calc(16px + env(safe-area-inset-bottom));
  }
}
