:root {
  --bg: #f5f0e8;
  --surface: #faf6ef;
  --surface-alt: #f0ebe2;
  --text: #18181b;
  --text-mid: #52525b;
  --text-dim: #a1a1aa;
  --text-faint: #d4d4d8;
  --accent: #18181b;
  --accent-soft: rgba(24, 24, 27, 0.06);
  --border: rgba(0, 0, 0, 0.06);
  --border-hover: rgba(0, 0, 0, 0.12);
  --radius: 14px;

  /* Soul — set by JS based on score */
  --soul-color: #3a7d5c;
  --soul-glow: rgba(58, 125, 92, 0.15);
  --soul-speed: 3s;
}

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

html, body {
  height: 100%;
  overflow: hidden;
}

body {
  background: var(--bg);
  color: var(--text);
  font-family: 'DM Sans', system-ui, sans-serif;
  font-weight: 400;
  -webkit-font-smoothing: antialiased;
  display: flex;
  flex-direction: column;
  line-height: 1.6;
}

/* ══════════ TOP BAR ══════════ */
.topbar {
  position: relative;
  z-index: 10;
  padding: 14px 20px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-bottom: 1px solid var(--border);
  background: rgba(245, 240, 232, 0.85);
  backdrop-filter: blur(24px);
  -webkit-backdrop-filter: blur(24px);
  flex-shrink: 0;
}

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

.topbar-logo {
  font-size: 0.85rem;
  font-weight: 400;
  letter-spacing: -0.01em;
  color: var(--text-dim);
  text-decoration: none;
  transition: color 0.3s;
}
.topbar-logo:hover { color: var(--text-mid); }

.topbar-sep {
  color: var(--text-faint);
  font-size: 0.7rem;
}

.topbar-user {
  font-size: 0.85rem;
  font-weight: 500;
  color: var(--text-mid);
}

.topbar-create {
  font-size: 0.65rem;
  font-weight: 500;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--text);
  text-decoration: none;
  padding: 6px 14px;
  border: 1px solid var(--border-hover);
  border-radius: 100px;
  transition: all 0.35s cubic-bezier(0.16, 1, 0.3, 1);
  background: transparent;
}
.topbar-create:hover {
  background: var(--accent-soft);
  border-color: rgba(0, 0, 0, 0.2);
  transform: translateY(-1px);
}

/* ══════════ PROFILE CARD ══════════ */
.profile {
  position: relative;
  z-index: 1;
  padding: 28px 24px 20px;
  text-align: center;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
  background: var(--surface);
}

/* ── Avatar ── */
.avatar-container {
  position: relative;
  width: 64px;
  height: 64px;
  margin: 0 auto 12px;
  opacity: 0;
  animation: fade-up 0.7s cubic-bezier(0.16, 1, 0.3, 1) 0.2s forwards;
}

.profile-avatar {
  width: 64px;
  height: 64px;
  border-radius: 50%;
  background: var(--accent);
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 500;
  font-size: 1.3rem;
  color: var(--bg);
  overflow: hidden;
  cursor: pointer;
}

.profile-avatar.has-image img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

/* ── Name Row ── */
.profile-name-row {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  margin-bottom: 2px;
}

.profile-name {
  font-size: 1.2rem;
  font-weight: 500;
  letter-spacing: -0.01em;
  opacity: 0;
  animation: fade-up 0.6s ease 0.4s forwards;
}

.verified-badge {
  display: inline-flex;
  opacity: 0;
  animation: fade-up 0.6s ease 0.45s forwards;
}
.verified-badge svg { width: 20px; height: 20px; }

/* ── Tagline & About ── */
.profile-tagline {
  font-size: 0.75rem;
  color: var(--text-mid);
  margin-bottom: 4px;
  opacity: 0;
  animation: fade-up 0.5s ease 0.5s forwards;
}

.profile-about {
  font-size: 0.82rem;
  color: var(--text-mid);
  line-height: 1.65;
  max-width: 380px;
  margin: 0 auto;
  opacity: 0;
  animation: fade-up 0.6s ease 0.55s forwards;
}

/* ── Soul Bar ── */
.soul-bar-wrap {
  max-width: 200px;
  margin: 16px auto 0;
  opacity: 0;
  animation: fade-up 0.5s ease 0.65s forwards;
}

.soul-bar-header {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  margin-bottom: 6px;
}

.soul-bar-label {
  font-family: 'DM Mono', monospace;
  font-size: 0.52rem;
  font-weight: 500;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: var(--text-dim);
}

.soul-bar-value {
  font-family: 'DM Mono', monospace;
  font-size: 0.52rem;
  font-weight: 500;
  letter-spacing: 0.05em;
  color: var(--text-dim);
  transition: color 0.6s ease;
}

.soul-bar-track {
  position: relative;
  width: 100%;
  height: 3px;
  background: var(--border);
  border-radius: 3px;
  overflow: visible;
}

.soul-bar-fill {
  position: absolute;
  top: 0;
  left: 0;
  height: 100%;
  width: 100%;
  border-radius: 3px;
  background: var(--soul-color);
  transform: scaleX(0);
  transform-origin: left center;
  will-change: transform;
}

/* ══════════ CHAT AREA ══════════ */
.chat {
  flex: 1;
  overflow-y: auto;
  padding: 24px 20px;
  display: flex;
  flex-direction: column;
  gap: 4px;
  position: relative;
  z-index: 1;
  scrollbar-width: thin;
  scrollbar-color: var(--text-faint) transparent;
}

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

/* ─── Messages ─── */
.msg-group {
  display: flex;
  flex-direction: column;
  gap: 3px;
  margin-bottom: 12px;
  max-width: 85%;
}
.msg-group.visitor { align-self: flex-end; }
.msg-group.clone { align-self: flex-start; }

.msg-label {
  font-size: 0.58rem;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--text-dim);
  margin-bottom: 4px;
  padding-left: 2px;
  font-weight: 500;
}
.msg-group.visitor .msg-label {
  text-align: right;
  padding-right: 2px;
  padding-left: 0;
}

.bubble {
  font-size: 0.88rem;
  line-height: 1.6;
  padding: 12px 16px;
  border-radius: var(--radius);
  animation: bubble-in 0.4s cubic-bezier(0.16, 1, 0.3, 1) both;
  word-wrap: break-word;
}

@keyframes bubble-in {
  from { opacity: 0; transform: translateY(8px) scale(0.97); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}

.msg-group.visitor .bubble {
  background: var(--accent);
  color: var(--bg);
  font-weight: 500;
  border-bottom-right-radius: 4px;
}

.msg-group.clone .bubble {
  background: var(--surface-alt);
  color: var(--text);
  border: 1px solid var(--border);
  border-bottom-left-radius: 4px;
}

/* ─── Typing Indicator ─── */
.typing {
  display: none;
  align-self: flex-start;
  padding: 14px 20px;
  background: var(--surface-alt);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  border-bottom-left-radius: 4px;
  margin-bottom: 12px;
}
.typing.visible { display: flex; gap: 5px; align-items: center; }

.typing-dot {
  width: 5px;
  height: 5px;
  border-radius: 50%;
  background: var(--text-dim);
  animation: typing-bounce 1.4s ease-in-out infinite;
}
.typing-dot:nth-child(2) { animation-delay: 0.15s; }
.typing-dot:nth-child(3) { animation-delay: 0.3s; }

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

/* ══════════ INPUT BAR ══════════ */
.input-area {
  position: relative;
  z-index: 10;
  padding: 12px 16px 16px;
  border-top: 1px solid var(--border);
  background: rgba(245, 240, 232, 0.9);
  backdrop-filter: blur(24px);
  -webkit-backdrop-filter: blur(24px);
  flex-shrink: 0;
}

.input-row {
  display: flex;
  align-items: flex-end;
  gap: 10px;
  max-width: 700px;
  margin: 0 auto;
}

.input-wrap {
  flex: 1;
  background: var(--surface-alt);
  border: 1px solid var(--border);
  border-radius: 100px;
  padding: 4px;
  transition: border-color 0.3s;
  display: flex;
  align-items: flex-end;
}
.input-wrap:focus-within {
  border-color: var(--border-hover);
}

.input-wrap textarea {
  flex: 1;
  background: none;
  border: none;
  outline: none;
  color: var(--text);
  font-family: 'DM Sans', system-ui, sans-serif;
  font-size: 0.88rem;
  font-weight: 400;
  padding: 10px 16px;
  resize: none;
  min-height: 20px;
  max-height: 120px;
  line-height: 1.4;
  scrollbar-width: none;
}
.input-wrap textarea::-webkit-scrollbar { display: none; }
.input-wrap textarea::placeholder { color: var(--text-dim); }

.send-btn {
  width: 38px;
  height: 38px;
  border-radius: 50%;
  border: none;
  background: var(--text-faint);
  color: var(--bg);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.35s cubic-bezier(0.16, 1, 0.3, 1);
  flex-shrink: 0;
  opacity: 0.4;
}
.send-btn.active {
  background: var(--accent);
  opacity: 1;
}
.send-btn.active:hover {
  transform: scale(1.06);
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.1);
}
.send-btn svg {
  width: 16px;
  height: 16px;
  fill: currentColor;
  margin-left: 1px;
}

.input-hint {
  text-align: center;
  margin-top: 8px;
  font-size: 0.6rem;
  color: var(--text-dim);
  letter-spacing: 0.06em;
}
.input-hint a {
  color: var(--text-dim);
  text-decoration: none;
  transition: color 0.3s;
}
.input-hint a:hover { color: var(--text-mid); }

/* ══════════ FOOTER CTA ══════════ */
.footer-cta {
  display: none;
  position: relative;
  z-index: 1;
  text-align: center;
  padding: 16px 20px 20px;
  border-top: 1px solid var(--border);
  background: rgba(245, 240, 232, 0.9);
  backdrop-filter: blur(24px);
  flex-shrink: 0;
}
.footer-cta.visible { display: block; }

.footer-cta-btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-family: 'DM Sans', system-ui, sans-serif;
  font-size: 0.82rem;
  font-weight: 500;
  color: var(--bg);
  background: var(--accent);
  padding: 10px 22px;
  border-radius: 100px;
  text-decoration: none;
  transition: all 0.35s cubic-bezier(0.16, 1, 0.3, 1);
}
.footer-cta-btn:hover {
  transform: translateY(-2px);
  box-shadow: 0 8px 30px rgba(0, 0, 0, 0.12);
}
.footer-cta-btn svg {
  width: 16px;
  height: 16px;
  fill: currentColor;
}

/* ══════════ AVATAR LIGHTBOX ══════════ */
.avatar-lightbox {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: none;
  align-items: center;
  justify-content: center;
  background: rgba(0, 0, 0, 0.6);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  cursor: pointer;
}
.avatar-lightbox.open { display: flex; }

.avatar-lightbox img {
  max-width: 80vw;
  max-height: 80vh;
  border-radius: var(--radius);
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.3);
}

.lightbox-close {
  position: absolute;
  top: 20px;
  right: 24px;
  background: none;
  border: none;
  color: white;
  font-size: 2rem;
  cursor: pointer;
  opacity: 0.7;
  transition: opacity 0.3s;
}
.lightbox-close:hover { opacity: 1; }

/* ══════════ ANIMATIONS ══════════ */
@keyframes fade-up {
  from { opacity: 0; transform: translateY(12px); }
  to { opacity: 1; transform: translateY(0); }
}

/* ══════════ DESKTOP ══════════ */
@media (min-width: 768px) {
  body {
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--bg);
    padding: 24px;
  }

  .page-shell {
    width: 100%;
    max-width: 480px;
    height: min(92vh, 820px);
    display: flex;
    flex-direction: column;
    border-radius: var(--radius);
    border: 1px solid var(--border);
    overflow: hidden;
    background: var(--bg);
    box-shadow:
      0 0 0 1px rgba(0, 0, 0, 0.04),
      0 40px 100px rgba(0, 0, 0, 0.1);
  }

  .topbar { border-radius: var(--radius) var(--radius) 0 0; }
}

@media (max-width: 767px) {
  .page-shell {
    width: 100%;
    height: 100%;
    display: flex;
    flex-direction: column;
  }

  .profile { padding: 22px 20px 16px; }
  .avatar-container { width: 56px; height: 56px; }
  .profile-avatar { width: 56px; height: 56px; font-size: 1.1rem; }
  .profile-name { font-size: 1.05rem; }
}
