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

:root {
  --bg: #F5F2EC;
  --surface: #FDFCFA;
  --border: rgba(0,0,0,0.1);
  --border-hover: rgba(0,0,0,0.22);
  --text: #1A1916;
  --muted: #7A7670;
  --accent: #1A1916;
  --accent-inv: #FDFCFA;
  --bot-bg: #EEEAE2;
  --user-bg: #1A1916;
  --user-text: #F5F2EC;
  --radius: 16px;
  --radius-sm: 10px;
  --pill: 999px;
}

html, body {
  height: 100%;
  background: var(--bg);
  font-family: 'DM Sans', sans-serif;
  color: var(--text);
  -webkit-font-smoothing: antialiased;
}

/* ─── WELCOME SCREEN ─── */
#welcome-screen {
  position: fixed; inset: 0;
  display: flex; flex-direction: column;
  align-items: center; justify-content: center;
  gap: 32px;
  padding: 2rem;
  transition: opacity 0.4s ease, transform 0.4s ease;
}

#welcome-screen.hidden {
  opacity: 0; transform: translateY(-18px); pointer-events: none;
}

.headline {
  font-family: 'Instrument Serif', serif;
  font-size: clamp(28px, 5vw, 48px);
  font-weight: 400;
  line-height: 1.25;
  text-align: center;
  max-width: 520px;
  color: var(--text);
}

.headline em {
  font-style: italic;
  color: var(--muted);
}

.welcome-form {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
  max-width: 480px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--pill);
  padding: 6px 6px 6px 18px;
  transition: border-color 0.2s, box-shadow 0.2s;
}

.welcome-form:focus-within {
  border-color: var(--border-hover);
  box-shadow: 0 0 0 3px rgba(0,0,0,0.05);
}

.welcome-form textarea {
  flex: 1;
  background: none;
  border: none;
  outline: none;
  font-family: 'DM Sans', sans-serif;
  font-size: 15px;
  color: var(--text);
  line-height: 1.4;
  resize: none;
  overflow: hidden;
  min-height: 24px;
  max-height: 120px;
  padding: 6px 0;
}

.welcome-form textarea::placeholder { color: var(--muted); }

.welcome-form button {
  background: var(--accent);
  color: var(--accent-inv);
  border: none;
  border-radius: var(--pill);
  padding: 10px 20px;
  font-family: 'DM Sans', sans-serif;
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  white-space: nowrap;
  transition: opacity 0.15s;
}

.welcome-form button:hover { opacity: 0.82; }

/* ─── CHAT SCREEN ─── */
#chat-screen {
  position: fixed; inset: 0;
  display: none; flex-direction: column;
  opacity: 0; transform: translateY(14px);
  transition: opacity 0.4s ease, transform 0.4s ease;
}

#chat-screen.visible {
  display: flex;
}

#chat-screen.shown {
  opacity: 1; transform: translateY(0);
}

.chat-header {
  padding: 16px 24px;
  border-bottom: 1px solid var(--border);
  background: var(--bg);
  display: flex;
  align-items: center;
  gap: 10px;
}

.chat-header-dot {
  width: 8px; height: 8px;
  background: #4CAF81;
  border-radius: 50%;
}

.chat-header-name {
  font-size: 14px;
  font-weight: 500;
  color: var(--text);
}

.chat-header-status {
  font-size: 12px;
  color: var(--muted);
  margin-left: 2px;
}

.chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 28px 24px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  max-width: 680px;
  width: 100%;
  margin: 0 auto;
}

.chat-messages::-webkit-scrollbar { width: 4px; }
.chat-messages::-webkit-scrollbar-thumb { background: var(--border); border-radius: 2px; }

.msg {
  max-width: 72%;
  padding: 12px 16px;
  border-radius: var(--radius);
  font-size: 14px;
  line-height: 1.55;
  animation: msgIn 0.3s cubic-bezier(.22,.68,0,1.2) both;
}

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

.msg.user {
  align-self: flex-end;
  background: var(--user-bg);
  color: var(--user-text);
  border-bottom-right-radius: 4px;
}

.msg.bot {
  align-self: flex-start;
  background: var(--bot-bg);
  color: var(--text);
  border-bottom-left-radius: 4px;
}

.typing {
  align-self: flex-start;
  background: var(--bot-bg);
  border-radius: var(--radius);
  border-bottom-left-radius: 4px;
  padding: 14px 18px;
  display: flex; gap: 5px; align-items: center;
  animation: msgIn 0.25s ease both;
}

.typing span {
  width: 6px; height: 6px;
  background: var(--muted);
  border-radius: 50%;
  animation: bounce 1.1s infinite ease;
}

.typing span:nth-child(2) { animation-delay: 0.18s; }
.typing span:nth-child(3) { animation-delay: 0.36s; }

@keyframes bounce {
  0%, 60%, 100% { transform: translateY(0); }
  30% { transform: translateY(-5px); }
}

.msg-with-btns {
  align-self: flex-start;
  display: flex;
  flex-direction: column;
  gap: 10px;
  max-width: 80%;
  animation: msgIn 0.3s cubic-bezier(.22,.68,0,1.2) both;
}

.msg-with-btns .msg {
  max-width: 100%;
  animation: none;
}

.msg-btns-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.topic-btn {
  padding: 9px 18px;
  font-family: 'DM Sans', sans-serif;
  font-size: 13px;
  font-weight: 500;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--pill);
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s, transform 0.1s;
  animation: msgIn 0.3s ease both;
}

.topic-btn:hover {
  background: var(--bot-bg);
  border-color: var(--border-hover);
}

.topic-btn:active { transform: scale(0.96); }

.chat-input-area {
  padding: 16px 24px 20px;
  background: var(--bg);
  border-top: 1px solid var(--border);
}

.chat-form {
  display: flex;
  gap: 8px;
  max-width: 680px;
  margin: 0 auto;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--pill);
  padding: 6px 6px 6px 18px;
  transition: border-color 0.2s, box-shadow 0.2s;
}

.chat-form:focus-within {
  border-color: var(--border-hover);
  box-shadow: 0 0 0 3px rgba(0,0,0,0.05);
}

.chat-form input {
  flex: 1;
  background: none;
  border: none;
  outline: none;
  font-family: 'DM Sans', sans-serif;
  font-size: 14px;
  color: var(--text);
}

.chat-form input::placeholder { color: var(--muted); }

.chat-form button {
  background: var(--accent);
  color: var(--accent-inv);
  border: none;
  border-radius: var(--pill);
  width: 36px; height: 36px;
  display: flex; align-items: center; justify-content: center;
  cursor: pointer;
  font-size: 16px;
  transition: opacity 0.15s;
  flex-shrink: 0;
}

.chat-form button:hover { opacity: 0.8; }

/* ─── POPUP ─── */
#popup-overlay {
  position: fixed; inset: 0;
  background: rgba(26,25,22,0.45);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
  display: none; align-items: center; justify-content: center;
  padding: 1rem;
  z-index: 100;
}

#popup-overlay.open { display: flex; }

.popup-box {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 2rem;
  width: 100%;
  max-width: 360px;
  display: flex;
  flex-direction: column;
  gap: 16px;
  animation: popIn 0.3s cubic-bezier(.22,.68,0,1.2) both;
}

@keyframes popIn {
  from { opacity: 0; transform: scale(0.93) translateY(10px); }
  to   { opacity: 1; transform: scale(1) translateY(0); }
}

.popup-title {
  font-family: 'Instrument Serif', serif;
  font-size: 22px;
  font-weight: 400;
  color: var(--text);
  line-height: 1.3;
}

.popup-subtitle {
  font-size: 13px;
  color: var(--muted);
  line-height: 1.6;
  margin-top: -6px;
}

.popup-box input[type="email"] {
  width: 100%;
  padding: 11px 14px;
  font-family: 'DM Sans', sans-serif;
  font-size: 14px;
  color: var(--text);
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  outline: none;
  transition: border-color 0.2s;
}

.popup-box input[type="email"]:focus { border-color: var(--border-hover); }
.popup-box input[type="email"].error { border-color: #D85A30; }

.popup-box input[type="email"]::placeholder { color: var(--muted); }

.popup-submit {
  width: 100%;
  padding: 12px;
  background: var(--accent);
  color: var(--accent-inv);
  border: none;
  border-radius: var(--radius-sm);
  font-family: 'DM Sans', sans-serif;
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  transition: opacity 0.15s;
}

.popup-submit:hover { opacity: 0.82; }
.popup-submit:disabled { opacity: 0.65; cursor: wait; }

.popup-close-row {
  display: flex;
  justify-content: flex-end;
  margin-bottom: -6px;
}

.popup-close {
  background: none;
  border: none;
  font-size: 13px;
  color: var(--muted);
  cursor: pointer;
  font-family: 'DM Sans', sans-serif;
  padding: 2px 0;
}

.popup-close:hover { color: var(--text); }

/* ─── DECORATIVE BG ─── */
body::before {
  content: '';
  position: fixed;
  width: 500px; height: 500px;
  border-radius: 50%;
  background: radial-gradient(circle, rgba(210,200,180,0.35) 0%, transparent 70%);
  top: -120px; right: -100px;
  pointer-events: none;
}

body::after {
  content: '';
  position: fixed;
  width: 400px; height: 400px;
  border-radius: 50%;
  background: radial-gradient(circle, rgba(210,200,180,0.25) 0%, transparent 70%);
  bottom: -80px; left: -80px;
  pointer-events: none;
}
