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

:root {
  --bg:          #0d0812;
  --bg2:         #130d1e;
  --bg3:         #1c1230;
  --surface:     #1e1430;
  --surface2:    #261a3d;
  --border:      rgba(255,255,255,0.07);
  --accent:      #e91e8c;
  --accent2:     #c2185b;
  --accent-glow: rgba(233,30,140,0.25);
  --purple:      #7c3aed;
  --purple-dim:  rgba(124,58,237,0.18);
  --text:        #f0e6ff;
  --text-dim:    rgba(240,230,255,0.5);
  --text-muted:  rgba(240,230,255,0.3);
  --bubble-ai:   #1e1430;
  --bubble-user: linear-gradient(135deg, #e91e8c, #c2185b);
  --radius-bubble: 20px;
  --composer-h: 72px;
}

html, body { height: 100%; }

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  overflow: hidden;
}

/* ── App shell ─────────────────────────────────────────────────────────── */

.app {
  display: flex;
  flex-direction: column;
  height: 100dvh;
  max-width: 480px;
  margin: 0 auto;
  position: relative;
}

/* ── Header ─────────────────────────────────────────────────────────────── */

.header {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 14px 18px 12px;
  background: linear-gradient(180deg, var(--bg2) 0%, transparent 100%);
  border-bottom: 1px solid var(--border);
  position: relative;
  z-index: 10;
  flex-shrink: 0;
}

.header__avatar {
  width: 42px;
  height: 42px;
  border-radius: 50%;
  object-fit: cover;
  flex-shrink: 0;
  box-shadow: 0 0 12px var(--accent-glow);
}

.header__info { flex: 1; min-width: 0; }

.header__name {
  font-size: 16px;
  font-weight: 700;
  letter-spacing: 0.01em;
  color: var(--text);
  line-height: 1.2;
}

.header__status {
  font-size: 11px;
  color: var(--accent);
  display: flex;
  align-items: center;
  gap: 4px;
  margin-top: 2px;
}

.header__status-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--accent);
  animation: pulse 2s infinite;
}

@keyframes pulse {
  0%, 100% { opacity: 1; transform: scale(1); }
  50%       { opacity: 0.5; transform: scale(0.85); }
}

.header__clear {
  background: none;
  border: none;
  cursor: pointer;
  color: rgba(240,230,255,0.55);
  padding: 6px;
  border-radius: 8px;
  transition: color 0.2s, background 0.2s;
  display: flex;
  align-items: center;
}
.header__clear:hover { color: var(--text); background: var(--surface); }

/* ── Chat area ──────────────────────────────────────────────────────────── */

.chat {
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
  padding: 16px 16px 8px;
  scroll-behavior: smooth;
  -webkit-overflow-scrolling: touch;
}

.chat::-webkit-scrollbar { width: 4px; }
.chat::-webkit-scrollbar-track { background: transparent; }
.chat::-webkit-scrollbar-thumb { background: var(--surface2); border-radius: 4px; }

/* ── Welcome screen ─────────────────────────────────────────────────────── */

.welcome {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 48px 24px 24px;
  text-align: center;
  gap: 12px;
}

.welcome__avatar {
  width: 88px;
  height: 88px;
  border-radius: 50%;
  object-fit: cover;
  margin-bottom: 4px;
  box-shadow: 0 0 40px var(--accent-glow), 0 0 80px rgba(124,58,237,0.12);
}

.welcome__name {
  font-size: 26px;
  font-weight: 800;
  background: linear-gradient(135deg, #f472b6, #e91e8c, #7c3aed);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.welcome__bio {
  font-size: 14px;
  color: rgba(240,230,255,0.82);
  line-height: 1.5;
  max-width: 280px;
}

.welcome__starters {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  justify-content: center;
  margin-top: 8px;
}

.starter {
  background: var(--surface);
  border: 1px solid rgba(124,58,237,0.32);
  border-radius: 20px;
  padding: 9px 16px;
  font-size: 13px;
  color: rgba(240,230,255,0.92);
  cursor: pointer;
  transition: background 0.2s, border-color 0.2s, color 0.2s;
}
.starter:hover {
  background: var(--surface2);
  border-color: var(--accent);
  color: var(--text);
}

/* ── Messages ───────────────────────────────────────────────────────────── */

.messages { display: flex; flex-direction: column; gap: 6px; }

.msg { display: flex; gap: 8px; max-width: 100%; }

.msg--ai   { align-self: flex-start; align-items: flex-end; }
.msg--user { align-self: flex-end;   flex-direction: row-reverse; }

.msg__avatar {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  object-fit: cover;
  flex-shrink: 0;
  margin-bottom: 2px;
}

.msg__bubble {
  padding: 10px 14px;
  border-radius: var(--radius-bubble);
  max-width: min(300px, 78vw);
  font-size: 14px;
  line-height: 1.55;
  word-break: break-word;
}

.msg--ai .msg__bubble {
  background: var(--bubble-ai);
  border: 1px solid rgba(124,58,237,0.22);
  border-bottom-left-radius: 6px;
  color: var(--text);
  box-shadow: 0 2px 12px rgba(0,0,0,0.3);
}

.msg--user .msg__bubble {
  background: var(--bubble-user);
  border-bottom-right-radius: 6px;
  color: #fff;
  box-shadow: 0 2px 12px rgba(233,30,140,0.3);
}

.msg__col { display: flex; flex-direction: column; gap: 4px; min-width: 0; }

.msg__debug {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 10px;
  color: rgba(240,230,255,0.4);
  background: rgba(124,58,237,0.06);
  border: 1px dashed rgba(124,58,237,0.25);
  padding: 4px 8px;
  border-radius: 8px;
  word-break: break-all;
  align-self: flex-start;
  max-width: 100%;
}

/* Image-as-message bubble */
.msg__photo {
  border-radius: var(--radius-bubble);
  border-bottom-left-radius: 6px;
  overflow: hidden;
  max-width: min(260px, 70vw);
  border: 1px solid rgba(124,58,237,0.22);
  background: var(--bubble-ai);
  box-shadow: 0 2px 12px rgba(0,0,0,0.3), 0 0 24px rgba(233,30,140,0.08);
  line-height: 0;
  cursor: zoom-in;
  transition: transform 0.2s;
}
.msg__photo:hover { transform: scale(1.01); }
.msg__photo img {
  display: block;
  width: 100%;
  height: auto;
  object-fit: cover;
}

/* entrance animation */
.msg { animation: msgIn 0.22s ease-out both; }
@keyframes msgIn {
  from { opacity: 0; transform: translateY(10px) scale(0.97); }
  to   { opacity: 1; transform: none; }
}

/* ── Typing indicator ───────────────────────────────────────────────────── */

.typing { display: flex; gap: 8px; align-items: flex-end; align-self: flex-start; }
.typing__avatar {
  width: 28px; height: 28px; border-radius: 50%; object-fit: cover;
}
.typing__dots {
  background: var(--bubble-ai);
  border: 1px solid rgba(124,58,237,0.22);
  border-radius: var(--radius-bubble);
  border-bottom-left-radius: 6px;
  padding: 12px 16px;
  display: flex; gap: 4px; align-items: center;
}
.typing__dot {
  width: 6px; height: 6px; border-radius: 50%;
  background: var(--accent);
  animation: bounce 1.2s infinite;
}
.typing__dot:nth-child(2) { animation-delay: 0.2s; }
.typing__dot:nth-child(3) { animation-delay: 0.4s; }
@keyframes bounce {
  0%, 60%, 100% { transform: translateY(0);    opacity: 0.4; }
  30%           { transform: translateY(-5px); opacity: 1;   }
}

/* ── Spacer ─────────────────────────────────────────────────────────────── */
.spacer { height: 8px; }

/* ── Composer ───────────────────────────────────────────────────────────── */

.composer {
  flex-shrink: 0;
  padding: 10px 14px 14px;
  background: linear-gradient(0deg, var(--bg2) 80%, transparent 100%);
  border-top: 1px solid var(--border);
}

.composer__form { display: flex; gap: 10px; align-items: flex-end; }

.composer__input {
  flex: 1;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 24px;
  padding: 11px 18px;
  font-size: 14px;
  color: var(--text);
  resize: none;
  min-height: 44px;
  max-height: 120px;
  line-height: 1.45;
  outline: none;
  font-family: inherit;
  transition: border-color 0.2s, box-shadow 0.2s;
  overflow-y: auto;
}
.composer__input::placeholder { color: var(--text-muted); }
.composer__input:focus {
  border-color: rgba(233,30,140,0.45);
  box-shadow: 0 0 0 3px var(--accent-glow);
}

.composer__send {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  border: none;
  cursor: pointer;
  background: linear-gradient(135deg, #e91e8c, #7c3aed);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: opacity 0.2s, transform 0.15s, box-shadow 0.2s;
  box-shadow: 0 4px 14px var(--accent-glow);
}
.composer__send:hover  { opacity: 0.9; transform: scale(1.05); }
.composer__send:active { transform: scale(0.95); }
.composer__send:disabled { opacity: 0.4; cursor: not-allowed; transform: none; }
.composer__send svg { width: 18px; height: 18px; }

/* ── Error toast ────────────────────────────────────────────────────────── */
.error-toast {
  position: fixed;
  bottom: 90px;
  left: 50%;
  transform: translateX(-50%) translateY(12px);
  background: #3d1a2a;
  border: 1px solid rgba(233,30,140,0.35);
  color: #f9a8d4;
  font-size: 13px;
  padding: 8px 18px;
  border-radius: 20px;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.25s, transform 0.25s;
  white-space: nowrap;
  z-index: 50;
}
.error-toast.is-visible {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

/* ── Desktop centering backdrop ─────────────────────────────────────────── */
@media (min-width: 520px) {
  body { background: #080510; }
  .app {
    border-left:  1px solid var(--border);
    border-right: 1px solid var(--border);
    box-shadow: 0 0 80px rgba(124,58,237,0.08);
  }
}
