/* =========================================================
   Design tokens
   ========================================================= */
:root {
  --bg:          #0E0C16;
  --surface:     #17141F;
  --surface-2:   #201C2C;
  --surface-3:   #2A2438;
  --border:      #2E2A3F;
  --accent:      #8B5CF6;
  --accent-dim:  #6D4FC4;
  --accent-2:    #F472B6;
  --accent-glow: rgba(139, 92, 246, .35);
  --text:        #F3F1FA;
  --text-muted:  #9C96B4;
  --text-faint:  #6B6584;
  --success:     #34D399;
  --danger:      #F87171;
  --radius-s:    10px;
  --radius-m:    16px;
  --radius-l:    24px;
  --nav-h:       64px;
  --safe-b:      env(safe-area-inset-bottom, 0px);
  font-size: 16px;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  background: radial-gradient(120% 100% at 50% -10%, #201A32 0%, var(--bg) 55%);
  color: var(--text);
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
}
h1, h2, h3, h4, .display {
  font-family: 'Sora', 'Inter', sans-serif;
  font-weight: 600;
  letter-spacing: -0.01em;
  margin: 0;
}
a { color: inherit; text-decoration: none; }
button { font-family: inherit; }
img { max-width: 100%; display: block; }
::selection { background: var(--accent-glow); }

/* =========================================================
   App shell
   ========================================================= */
.app-shell {
  max-width: 560px;
  margin: 0 auto;
  min-height: 100vh;
  padding-bottom: calc(var(--nav-h) + var(--safe-b) + 12px);
  position: relative;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 18px 20px 12px;
  background: linear-gradient(180deg, var(--bg) 60%, transparent);
}
.topbar .brand {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 1.05rem;
  font-weight: 700;
}
.topbar .brand .mark {
  width: 30px; height: 30px;
  border-radius: 9px;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  display: flex; align-items: center; justify-content: center;
  font-size: 15px;
}
.diamond-pill {
  display: flex; align-items: center; gap: 6px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  padding: 7px 12px;
  border-radius: 999px;
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--text);
}
.diamond-pill .icon { color: var(--accent-2); }

/* =========================================================
   Category chips
   ========================================================= */
.chip-row {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  padding: 4px 20px 14px;
  scrollbar-width: none;
}
.chip-row::-webkit-scrollbar { display: none; }
.chip {
  flex: 0 0 auto;
  padding: 8px 16px;
  border-radius: 999px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  color: var(--text-muted);
  font-size: 0.85rem;
  font-weight: 600;
  white-space: nowrap;
}
.chip.active {
  background: linear-gradient(135deg, var(--accent), var(--accent-dim));
  color: #fff;
  border-color: transparent;
}

/* =========================================================
   Character grid + cards
   ========================================================= */
.section-title {
  padding: 6px 20px 12px;
  font-size: 1.2rem;
}
.char-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  padding: 0 20px 20px;
}
.char-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-m);
  overflow: hidden;
  display: flex;
  flex-direction: column;
  transition: transform .15s ease, border-color .15s ease;
}
.char-card:active { transform: scale(.97); }
.char-card .thumb {
  aspect-ratio: 1 / 1;
  width: 100%;
  background: var(--surface-2);
  position: relative;
  overflow: hidden;
}
.char-card .thumb img { width: 100%; height: 100%; object-fit: cover; }
.char-card .thumb .cat-tag {
  position: absolute; top: 8px; left: 8px;
  background: rgba(14,12,22,.7);
  backdrop-filter: blur(4px);
  padding: 3px 9px;
  border-radius: 999px;
  font-size: 0.65rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .04em;
  color: var(--accent-2);
}
.char-card .body { padding: 10px 12px 12px; }
.char-card .name { font-size: 0.95rem; font-weight: 700; margin-bottom: 3px; }
.char-card .tagline {
  font-size: 0.78rem;
  color: var(--text-muted);
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
  line-height: 1.35;
  min-height: 2.6em;
}
.char-card .stats {
  display: flex; align-items: center; gap: 4px;
  margin-top: 8px;
  font-size: 0.72rem;
  color: var(--text-faint);
}

/* list style row (chat history / search results) */
.char-row {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 20px;
  border-bottom: 1px solid var(--border);
}
.char-row .avatar {
  width: 52px; height: 52px;
  border-radius: 16px;
  object-fit: cover;
  background: var(--surface-2);
  flex-shrink: 0;
}
.char-row .info { flex: 1; min-width: 0; }
.char-row .info .name { font-weight: 700; font-size: 0.95rem; }
.char-row .info .preview {
  font-size: 0.82rem;
  color: var(--text-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.char-row .meta { font-size: 0.7rem; color: var(--text-faint); flex-shrink: 0; }

/* =========================================================
   Buttons & forms
   ========================================================= */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  padding: 13px 20px;
  border-radius: var(--radius-s);
  border: none;
  font-weight: 700;
  font-size: 0.92rem;
  cursor: pointer;
}
.btn-primary {
  background: linear-gradient(135deg, var(--accent), var(--accent-dim));
  color: #fff;
  box-shadow: 0 6px 20px var(--accent-glow);
}
.btn-block { width: 100%; }
.btn-ghost {
  background: var(--surface-2);
  color: var(--text);
  border: 1px solid var(--border);
}

.field { margin-bottom: 16px; }
.field label {
  display: block;
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--text-muted);
  margin-bottom: 6px;
}
.field input, .field textarea, .field select {
  width: 100%;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-s);
  padding: 12px 14px;
  color: var(--text);
  font-size: 0.92rem;
  font-family: inherit;
  resize: vertical;
}
.field input:focus, .field textarea:focus, .field select:focus {
  outline: none;
  border-color: var(--accent);
}
.field .hint { font-size: 0.72rem; color: var(--text-faint); margin-top: 5px; }

/* =========================================================
   Bottom navigation
   ========================================================= */
.bottom-nav {
  position: fixed;
  bottom: 0; left: 0; right: 0;
  z-index: 30;
  max-width: 560px;
  margin: 0 auto;
  height: calc(var(--nav-h) + var(--safe-b));
  padding-bottom: var(--safe-b);
  background: rgba(23, 20, 31, .92);
  backdrop-filter: blur(14px);
  border-top: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-around;
}
.bottom-nav a {
  display: flex; flex-direction: column; align-items: center; gap: 4px;
  color: var(--text-faint);
  font-size: 0.62rem;
  font-weight: 600;
  width: 20%;
  padding: 6px 0;
}
.bottom-nav a svg { width: 23px; height: 23px; }
.bottom-nav a.active { color: var(--accent-2); }
.bottom-nav a.fab-link { position: relative; top: -14px; }
.bottom-nav a.fab-link .fab {
  width: 46px; height: 46px;
  border-radius: 15px;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  display: flex; align-items: center; justify-content: center;
  box-shadow: 0 8px 22px var(--accent-glow);
  color: #fff;
}
.bottom-nav a.fab-link .fab svg { width: 24px; height: 24px; }

/* =========================================================
   Chat page
   ========================================================= */
.chat-page { max-width: 560px; margin: 0 auto; display: flex; flex-direction: column; height: 100vh; }
.chat-header {
  display: flex; align-items: center; gap: 12px;
  padding: 14px 16px;
  border-bottom: 1px solid var(--border);
  background: var(--bg);
  position: sticky; top: 0; z-index: 15;
}
.chat-header .back { font-size: 1.3rem; color: var(--text-muted); padding: 4px; }
.chat-header .avatar { width: 38px; height: 38px; border-radius: 12px; object-fit: cover; }
.chat-header .info { flex: 1; min-width: 0; }
.chat-header .info .name { font-weight: 700; font-size: 0.95rem; }
.chat-header .info .status { font-size: 0.72rem; color: var(--success); }

.chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 16px 16px 8px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.msg-row { display: flex; }
.msg-row.user { justify-content: flex-end; }
.bubble {
  max-width: 78%;
  padding: 11px 14px;
  border-radius: 18px;
  font-size: 0.9rem;
  line-height: 1.45;
  white-space: pre-wrap;
  word-wrap: break-word;
}
.msg-row.assistant .bubble {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-bottom-left-radius: 4px;
}
.msg-row.user .bubble {
  background: linear-gradient(135deg, var(--accent), var(--accent-dim));
  color: #fff;
  border-bottom-right-radius: 4px;
}
.typing-dots { display: flex; gap: 4px; padding: 6px 4px; }
.typing-dots span {
  width: 6px; height: 6px; border-radius: 50%;
  background: var(--text-faint);
  animation: bounce 1.2s infinite ease-in-out;
}
.typing-dots span:nth-child(2) { animation-delay: .15s; }
.typing-dots span:nth-child(3) { animation-delay: .3s; }
@keyframes bounce { 0%,60%,100% { transform: translateY(0); opacity:.5; } 30% { transform: translateY(-4px); opacity:1; } }

.ai-disclaimer {
  text-align: center;
  font-size: 0.68rem;
  color: var(--text-faint);
  padding: 6px 24px 2px;
}

.chat-input-bar {
  display: flex;
  align-items: flex-end;
  gap: 10px;
  padding: 10px 14px calc(12px + var(--safe-b));
  border-top: 1px solid var(--border);
  background: var(--bg);
}
.chat-input-bar textarea {
  flex: 1;
  max-height: 120px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: 11px 16px;
  color: var(--text);
  font-family: inherit;
  font-size: 0.9rem;
  resize: none;
}
.chat-input-bar textarea:focus { outline: none; border-color: var(--accent); }
.send-btn {
  width: 42px; height: 42px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  color: #fff;
  border: none;
  flex-shrink: 0;
  display: flex; align-items: center; justify-content: center;
}
.send-btn:disabled { opacity: .5; }

.out-of-diamonds {
  margin: 10px 16px;
  padding: 14px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-m);
  text-align: center;
  font-size: 0.85rem;
}

/* =========================================================
   Profile page
   ========================================================= */
.profile-header { text-align: center; padding: 24px 20px 10px; }
.profile-header .avatar-lg {
  width: 88px; height: 88px; border-radius: 26px;
  object-fit: cover;
  margin: 0 auto 12px;
  border: 3px solid var(--surface-2);
}
.profile-header .name { font-size: 1.15rem; }
.profile-header .username { color: var(--text-muted); font-size: 0.85rem; margin-top: 2px; }
.stat-row { display: flex; justify-content: center; gap: 28px; padding: 18px 0; }
.stat-row .stat { text-align: center; }
.stat-row .stat .num { font-size: 1.15rem; font-weight: 700; }
.stat-row .stat .label { font-size: 0.7rem; color: var(--text-faint); }

/* =========================================================
   Empty states / misc
   ========================================================= */
.empty-state { text-align: center; padding: 60px 30px; color: var(--text-muted); }
.empty-state .glyph { font-size: 2.2rem; margin-bottom: 10px; }
.search-bar { padding: 4px 20px 14px; }
.search-bar input {
  width: 100%;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 12px 16px;
  color: var(--text);
  font-size: 0.9rem;
}
.search-bar input:focus { outline: none; border-color: var(--accent); }

/* =========================================================
   Auth page
   ========================================================= */
.auth-page {
  min-height: 100vh;
  display: flex; align-items: center; justify-content: center;
  padding: 20px;
}
.auth-card { width: 100%; max-width: 380px; text-align: center; }
.auth-logo { display: flex; align-items: center; justify-content: center; gap: 10px; margin-bottom: 6px; }
.auth-logo-mark {
  width: 40px; height: 40px; border-radius: 12px;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  display: flex; align-items: center; justify-content: center;
  font-size: 20px;
}
.auth-logo h1 { font-size: 1.4rem; }
.auth-tagline { color: var(--text-muted); margin-bottom: 32px; font-size: 0.9rem; }
.google-btn {
  display: flex; align-items: center; justify-content: center; gap: 10px;
  background: #fff;
  color: #1F1F1F;
  padding: 13px;
  border-radius: var(--radius-s);
  font-weight: 700;
  font-size: 0.92rem;
}
.auth-fine-print { font-size: 0.72rem; color: var(--text-faint); margin-top: 22px; line-height: 1.6; }
.auth-fine-print a { color: var(--accent-2); }
.auth-fine-print code { background: var(--surface-2); padding: 1px 5px; border-radius: 4px; }
.auth-error { color: var(--danger); font-size: 0.85rem; margin-bottom: 16px; }
.dev-login-badge {
  background: rgba(255, 193, 7, 0.12);
  border: 1px solid rgba(255, 193, 7, 0.35);
  color: #ffc966;
  font-size: 0.75rem; font-weight: 600;
  padding: 8px 12px; border-radius: var(--radius-s);
  margin-bottom: 16px;
}
.dev-login-form { display: flex; flex-direction: column; gap: 12px; text-align: left; }
.dev-login-form label {
  font-size: 0.75rem; color: var(--text-muted); font-weight: 600;
  display: flex; flex-direction: column; gap: 6px;
}
.dev-login-form input {
  background: var(--surface-2); border: 1px solid var(--border);
  color: var(--text); border-radius: var(--radius-s);
  padding: 12px 14px; font-size: 0.92rem; font-family: inherit;
}
.dev-login-form input:focus { outline: none; border-color: var(--accent-2); }
.dev-login-btn { width: 100%; border: none; cursor: pointer; margin-top: 4px; }

/* =========================================================
   Terms page
   ========================================================= */
.legal-page { max-width: 640px; margin: 0 auto; padding: 30px 22px 60px; line-height: 1.7; }
.legal-page h1 { font-size: 1.4rem; margin-bottom: 6px; }
.legal-page .updated { color: var(--text-faint); font-size: 0.8rem; margin-bottom: 28px; }
.legal-page h2 { font-size: 1rem; margin: 28px 0 8px; color: var(--accent-2); }
.legal-page p, .legal-page li { color: var(--text-muted); font-size: 0.9rem; }
.legal-page a { color: var(--accent-2); }

/* Toast */
.toast {
  position: fixed; left: 50%; bottom: calc(var(--nav-h) + 20px);
  transform: translateX(-50%);
  background: var(--surface-3);
  border: 1px solid var(--border);
  padding: 10px 18px;
  border-radius: 999px;
  font-size: 0.82rem;
  z-index: 50;
  opacity: 0;
  pointer-events: none;
  transition: opacity .2s ease;
}
.toast.show { opacity: 1; }

@media (min-width: 561px) {
  body { background: var(--bg); }
  .app-shell { border-left: 1px solid var(--border); border-right: 1px solid var(--border); }
}
