:root {
  --bg: #0d0d12;
  --bg-2: #14141c;
  --bg-3: #1c1c28;
  --bg-hover: #242434;
  --border: #2a2a3a;
  --text: #ececf2;
  --text-dim: #9a9aae;
  --text-faint: #65657a;
  --accent: #8b7cf6;
  --accent-2: #6d5ee8;
  --radius: 14px;
  --sidebar-w: 280px;
}

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

html, body { height: 100%; }

body {
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
  background: var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
  overflow: hidden;
}

#app { display: flex; height: 100vh; }

.hidden { display: none !important; }

/* ---------------- Sidebar ---------------- */
#sidebar {
  width: var(--sidebar-w);
  flex-shrink: 0;
  background: var(--bg-2);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  padding: 18px 14px;
  gap: 12px;
}

.brand { display: flex; align-items: center; gap: 10px; padding: 4px 6px 10px; }
.brand-logo { font-size: 26px; }
.brand-name { font-size: 20px; font-weight: 800; letter-spacing: -0.02em; }

.btn-primary {
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  color: #fff; border: none; border-radius: 11px;
  padding: 11px 14px; font-size: 14px; font-weight: 600;
  cursor: pointer; font-family: inherit; transition: filter .15s, transform .05s;
}
.btn-primary:hover { filter: brightness(1.08); }
.btn-primary:active { transform: scale(.985); }

.btn-ghost {
  background: var(--bg-3); color: var(--text); border: 1px solid var(--border);
  border-radius: 11px; padding: 10px 14px; font-size: 14px; font-weight: 500;
  cursor: pointer; font-family: inherit; transition: background .15s;
}
.btn-ghost:hover { background: var(--bg-hover); }

.sidebar-section-title {
  font-size: 11px; font-weight: 700; letter-spacing: .08em; text-transform: uppercase;
  color: var(--text-faint); padding: 8px 6px 2px;
}

.recent-list { flex: 1; overflow-y: auto; display: flex; flex-direction: column; gap: 2px; }

.recent-item {
  display: flex; align-items: center; gap: 10px;
  padding: 9px 10px; border-radius: 10px; cursor: pointer;
  transition: background .12s; position: relative;
}
.recent-item:hover { background: var(--bg-3); }
.recent-item.active { background: var(--bg-hover); }
.recent-avatar {
  width: 30px; height: 30px; border-radius: 50%; flex-shrink: 0;
  display: grid; place-items: center; font-size: 16px;
}
.recent-meta { min-width: 0; flex: 1; }
.recent-name { font-size: 13.5px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.recent-sub { font-size: 11.5px; color: var(--text-faint); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.recent-del {
  opacity: 0; border: none; background: transparent; color: var(--text-faint);
  cursor: pointer; font-size: 15px; padding: 2px 4px; border-radius: 6px;
}
.recent-item:hover .recent-del { opacity: 1; }
.recent-del:hover { background: #3a2030; color: #ff8585; }

.sidebar-foot { border-top: 1px solid var(--border); padding-top: 10px; }
.disclosure-mini { font-size: 10.5px; color: var(--text-faint); line-height: 1.5; padding: 0 6px; }

/* ---- account row ---- */
.account { padding: 0 6px 10px; display: flex; flex-direction: column; gap: 8px; }
.acct-free { font-size: 12px; color: var(--text-dim); }
.acct-email { font-size: 12.5px; color: var(--text); font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.acct-status { font-size: 11px; color: var(--text-faint); }
.acct-status.member { color: #f9c74f; font-weight: 600; }
.acct-btn {
  border: 1px solid var(--border); background: var(--bg-3); color: var(--text);
  border-radius: 9px; padding: 8px 10px; font-size: 12.5px; font-weight: 600;
  font-family: inherit; cursor: pointer; transition: background .15s, filter .15s;
}
.acct-btn:hover { background: var(--bg-hover); }
.acct-btn.primary { background: linear-gradient(135deg, var(--accent), var(--accent-2)); border: none; color: #fff; }
.acct-btn.primary:hover { filter: brightness(1.08); }

/* ---- modal ---- */
.modal-overlay {
  position: fixed; inset: 0; z-index: 200; display: grid; place-items: center;
  background: rgba(6, 6, 12, .68); backdrop-filter: blur(4px); padding: 20px;
}
.modal {
  position: relative; width: 100%; max-width: 380px;
  background: var(--bg-2); border: 1px solid var(--border); border-radius: 18px;
  padding: 26px 24px 20px; box-shadow: 0 24px 70px rgba(0, 0, 0, .5);
}
.modal-close {
  position: absolute; top: 12px; right: 14px; background: transparent; border: none;
  color: var(--text-faint); font-size: 22px; cursor: pointer; line-height: 1;
}
.modal-close:hover { color: var(--text); }
.auth-head { display: flex; align-items: center; gap: 10px; }
.auth-logo { font-size: 24px; }
.auth-head h2 { font-size: 20px; font-weight: 800; letter-spacing: -0.01em; }
.auth-intro {
  margin-top: 12px; font-size: 13px; line-height: 1.5; color: var(--text-dim);
  background: rgba(244,114,182,.1); border: 1px solid rgba(244,114,182,.25);
  padding: 10px 12px; border-radius: 11px;
}
.auth-tabs { display: flex; gap: 6px; margin: 18px 0 14px; background: var(--bg-3); padding: 4px; border-radius: 11px; }
.auth-tab {
  flex: 1; border: none; background: transparent; color: var(--text-dim);
  padding: 8px; border-radius: 8px; font-size: 13.5px; font-weight: 600; font-family: inherit; cursor: pointer;
}
.auth-tab.active { background: var(--bg-hover); color: var(--text); }
#auth-form { display: flex; flex-direction: column; gap: 10px; }
#auth-form input {
  background: var(--bg); border: 1px solid var(--border); border-radius: 10px;
  padding: 11px 13px; color: var(--text); font-family: inherit; font-size: 14px; outline: none;
  transition: border-color .15s;
}
#auth-form input:focus { border-color: var(--accent); }
#auth-form .btn-primary { margin-top: 4px; padding: 12px; }
.auth-error { font-size: 12.5px; color: #ff8585; }
.auth-foot { margin-top: 14px; font-size: 11.5px; color: var(--text-faint); text-align: center; }

/* ---- paywall ---- */
.pay-card { max-width: 400px; text-align: center; }
.pay-badge {
  display: inline-block; font-size: 12px; font-weight: 700; letter-spacing: .03em;
  color: #f9c74f; background: rgba(249,199,79,.12); border: 1px solid rgba(249,199,79,.3);
  padding: 5px 12px; border-radius: 999px; margin-bottom: 12px;
}
.pay-title { font-size: 22px; font-weight: 800; letter-spacing: -0.01em; }
.pay-price { margin: 10px 0 4px; }
.pay-price span:first-child { font-size: 38px; font-weight: 800; }
.pay-per { font-size: 15px; color: var(--text-dim); margin-left: 2px; }
.pay-sub { font-size: 13.5px; color: var(--text-dim); line-height: 1.55; margin: 6px auto 16px; max-width: 320px; }
.pay-perks { list-style: none; text-align: left; display: flex; flex-direction: column; gap: 9px; margin: 0 auto 18px; max-width: 300px; }
.pay-perks li { font-size: 13.5px; color: var(--text); }
.pay-cta { width: 100%; padding: 13px; font-size: 15px; }
.pay-foot { margin-top: 12px; font-size: 11.5px; color: var(--text-faint); }

/* ---------------- Main ---------------- */
#main { flex: 1; min-width: 0; display: flex; flex-direction: column; position: relative; }
.view { flex: 1; min-height: 0; display: flex; flex-direction: column; }

/* ---------------- Discover ---------------- */
#view-discover { overflow-y: auto; padding: 0; }
.discover-hero {
  padding: 46px 48px 26px;
  background: radial-gradient(1200px 300px at 30% -40%, rgba(139,124,246,.18), transparent);
}
.discover-hero h1 { font-size: 34px; font-weight: 800; letter-spacing: -0.03em; }
.discover-hero h1 span { background: linear-gradient(120deg, #a594ff, #6d5ee8); -webkit-background-clip: text; background-clip: text; -webkit-text-fill-color: transparent; }
.discover-hero p { color: var(--text-dim); margin-top: 10px; font-size: 15px; max-width: 560px; }
.ai-banner {
  margin-top: 18px; display: inline-block; font-size: 12.5px; color: var(--text-dim);
  background: var(--bg-3); border: 1px solid var(--border);
  padding: 7px 13px; border-radius: 999px;
}

.character-grid { padding: 6px 48px 60px; display: flex; flex-direction: column; gap: 30px; }
.gallery-section { display: flex; flex-direction: column; gap: 14px; }
.section-head h2 { font-size: 18px; font-weight: 800; letter-spacing: -0.01em; }
.section-head p { font-size: 13px; color: var(--text-dim); margin-top: 3px; }
.section-grid {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(250px, 1fr)); gap: 16px;
}
.char-tag {
  font-size: 10px; font-weight: 700; vertical-align: middle;
  color: #f472b6; background: rgba(244,114,182,.13); border: 1px solid rgba(244,114,182,.3);
  padding: 1px 6px; border-radius: 6px; margin-left: 6px;
}

.char-card {
  background: var(--bg-2); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 18px; cursor: pointer;
  transition: transform .12s, border-color .15s, background .15s;
  display: flex; flex-direction: column; gap: 10px; position: relative; overflow: hidden;
}
.char-card:hover { transform: translateY(-3px); border-color: var(--accent); background: var(--bg-3); }
.char-card::before {
  content: ''; position: absolute; inset: 0 0 auto 0; height: 3px;
  background: var(--card-accent, var(--accent));
}
.char-top { display: flex; align-items: center; gap: 12px; }
.char-avatar {
  width: 48px; height: 48px; border-radius: 50%; flex-shrink: 0;
  display: grid; place-items: center; font-size: 26px;
}
.char-name { font-size: 16px; font-weight: 700; }
.char-creator { font-size: 11px; color: var(--text-faint); margin-top: 1px; }
.char-tagline { font-size: 13px; color: var(--text-dim); line-height: 1.5; flex: 1; }
.char-foot { display: flex; align-items: center; justify-content: space-between; }
.char-chats { font-size: 11.5px; color: var(--text-faint); }
.char-delete {
  border: none; background: transparent; color: var(--text-faint); cursor: pointer;
  font-size: 13px; padding: 3px 7px; border-radius: 7px;
}
.char-delete:hover { background: #3a2030; color: #ff8585; }

/* ---------------- Chat ---------------- */
.chat-header {
  display: flex; align-items: center; gap: 13px;
  padding: 14px 22px; border-bottom: 1px solid var(--border);
  background: var(--bg-2); flex-shrink: 0;
}
.chat-header .ch-avatar {
  width: 42px; height: 42px; border-radius: 50%; display: grid; place-items: center; font-size: 22px;
}
.chat-header .ch-info { flex: 1; min-width: 0; }
.chat-header .ch-name { font-size: 16px; font-weight: 700; display: flex; align-items: center; gap: 8px; }
.ch-badge {
  font-size: 10px; font-weight: 700; letter-spacing: .04em; text-transform: uppercase;
  color: var(--accent); background: rgba(139,124,246,.14); border: 1px solid rgba(139,124,246,.3);
  padding: 2px 7px; border-radius: 6px;
}
.chat-header .ch-tagline { font-size: 12.5px; color: var(--text-dim); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.ch-back { display: none; background: transparent; border: none; color: var(--text); font-size: 22px; cursor: pointer; }

.messages {
  flex: 1; overflow-y: auto; padding: 26px 0 14px;
  display: flex; flex-direction: column; gap: 18px;
}
.msg-row { display: flex; gap: 12px; padding: 0 24px; max-width: 820px; width: 100%; margin: 0 auto; }
.msg-row.user { flex-direction: row-reverse; }
.msg-avatar {
  width: 34px; height: 34px; border-radius: 50%; flex-shrink: 0;
  display: grid; place-items: center; font-size: 18px;
}
.msg-avatar.user-av { background: var(--bg-hover); }
.msg-main { display: flex; flex-direction: column; gap: 5px; max-width: 76%; min-width: 0; }
.msg-row.user .msg-main { align-items: flex-end; }
.msg-bubble {
  padding: 11px 15px; border-radius: 16px; font-size: 14.5px; line-height: 1.62;
  max-width: 100%; word-wrap: break-word; white-space: pre-wrap;
}
.msg-row.assistant .msg-bubble { background: var(--bg-3); border-top-left-radius: 5px; }
.msg-row.user .msg-bubble { background: linear-gradient(135deg, var(--accent), var(--accent-2)); color: #fff; border-top-right-radius: 5px; }
.msg-bubble em { color: var(--text-dim); font-style: italic; }
.msg-row.user .msg-bubble em { color: rgba(255,255,255,.82); }

.msg-actions { display: flex; gap: 6px; padding-left: 4px; opacity: 0; transition: opacity .15s; }
.msg-row:hover .msg-actions { opacity: 1; }
.msg-act {
  background: transparent; border: none; color: var(--text-faint); cursor: pointer;
  font-family: inherit; font-size: 12px; padding: 2px 6px; border-radius: 7px; transition: background .12s, color .12s;
}
.msg-act:hover { background: var(--bg-3); color: var(--text); }

.typing { display: inline-flex; gap: 4px; align-items: center; padding: 4px 2px; }
.typing span { width: 7px; height: 7px; border-radius: 50%; background: var(--text-faint); animation: blink 1.3s infinite both; }
.typing span:nth-child(2) { animation-delay: .2s; }
.typing span:nth-child(3) { animation-delay: .4s; }
@keyframes blink { 0%, 60%, 100% { opacity: .25; } 30% { opacity: 1; } }

.cursor-blink::after { content: '▋'; margin-left: 1px; animation: cursorBlink 1s steps(2) infinite; color: var(--accent); }
@keyframes cursorBlink { 50% { opacity: 0; } }

.chat-suggestions {
  display: flex; flex-wrap: wrap; gap: 8px; justify-content: center;
  padding: 4px 24px 12px; max-width: 820px; margin: 0 auto; width: 100%;
}
.suggestion-chip {
  background: var(--bg-3); border: 1px solid var(--border); color: var(--text-dim);
  border-radius: 999px; padding: 8px 14px; font-size: 13px; font-family: inherit;
  cursor: pointer; transition: background .15s, color .15s, border-color .15s;
}
.suggestion-chip:hover { background: var(--bg-hover); color: var(--text); border-color: var(--accent); }

.composer { padding: 14px 24px 16px; border-top: 1px solid var(--border); background: var(--bg-2); flex-shrink: 0; }
#composer-form {
  display: flex; align-items: flex-end; gap: 10px;
  background: var(--bg-3); border: 1px solid var(--border); border-radius: 16px;
  padding: 8px 8px 8px 16px; max-width: 820px; margin: 0 auto;
  transition: border-color .15s;
}
#composer-form:focus-within { border-color: var(--accent); }
#composer-input {
  flex: 1; background: transparent; border: none; outline: none; resize: none;
  color: var(--text); font-family: inherit; font-size: 14.5px; line-height: 1.5;
  max-height: 160px; padding: 6px 0;
}
#send-btn {
  width: 38px; height: 38px; border-radius: 11px; border: none; flex-shrink: 0;
  background: linear-gradient(135deg, var(--accent), var(--accent-2)); color: #fff;
  font-size: 16px; cursor: pointer; transition: filter .15s, opacity .15s;
}
#send-btn:hover { filter: brightness(1.1); }
#send-btn:disabled { opacity: .4; cursor: default; }
#send-btn.stopping { background: var(--bg-hover); color: var(--text); font-size: 13px; }
#send-btn.stopping:hover { background: #3a2030; color: #ff8585; filter: none; }
.composer-foot { text-align: center; font-size: 11px; color: var(--text-faint); margin-top: 9px; max-width: 820px; margin-left: auto; margin-right: auto; }

/* ---------------- Create ---------------- */
#view-create { overflow-y: auto; }
.create-wrap { display: flex; gap: 36px; padding: 36px 48px 60px; max-width: 1000px; }
.create-form { flex: 1; max-width: 540px; }
.create-form h2 { font-size: 24px; font-weight: 800; }
.muted { color: var(--text-dim); font-size: 14px; margin-top: 6px; margin-bottom: 18px; }
.create-form label { display: block; font-size: 13px; font-weight: 600; color: var(--text-dim); margin-top: 16px; }
.create-form input, .create-form textarea, .create-form select {
  width: 100%; margin-top: 7px; background: var(--bg-2); border: 1px solid var(--border);
  border-radius: 10px; padding: 10px 12px; color: var(--text); font-family: inherit; font-size: 14px;
  outline: none; transition: border-color .15s; resize: vertical;
}
.create-form select { cursor: pointer; }
.create-form input:focus, .create-form textarea:focus, .create-form select:focus { border-color: var(--accent); }
.create-form input[type=color] { height: 42px; padding: 4px; cursor: pointer; }
.create-actions { display: flex; gap: 10px; margin-top: 26px; }
.create-actions button { flex: 1; padding: 12px; }

.create-preview { width: 280px; flex-shrink: 0; position: sticky; top: 0; }
.preview-label { font-size: 11px; font-weight: 700; letter-spacing: .08em; text-transform: uppercase; color: var(--text-faint); margin-bottom: 12px; }
.preview-card { cursor: default; }
.preview-card:hover { transform: none; border-color: var(--border); background: var(--bg-2); }

/* ---------------- Toast ---------------- */
#toast {
  position: fixed; bottom: 26px; left: 50%; transform: translateX(-50%) translateY(20px);
  background: var(--bg-hover); border: 1px solid var(--border); color: var(--text);
  padding: 11px 18px; border-radius: 11px; font-size: 13.5px; font-weight: 500;
  opacity: 0; pointer-events: none; transition: opacity .2s, transform .2s; z-index: 100;
}
#toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 10px; border: 2px solid transparent; background-clip: padding-box; }
::-webkit-scrollbar-thumb:hover { background: #3a3a4e; background-clip: padding-box; }

/* ---------------- Mobile ---------------- */
@media (max-width: 760px) {
  #sidebar { position: absolute; z-index: 30; height: 100%; transform: translateX(-100%); transition: transform .2s; box-shadow: 0 0 40px rgba(0,0,0,.5); }
  #sidebar.open { transform: translateX(0); }
  .ch-back { display: block; }
  .discover-hero { padding: 28px 20px 18px; }
  .discover-hero h1 { font-size: 26px; }
  .character-grid { padding: 14px 20px 50px; grid-template-columns: 1fr; }
  .create-wrap { flex-direction: column-reverse; padding: 24px 20px 50px; }
  .create-preview { width: 100%; position: static; }
  .msg-bubble { max-width: 84%; }
}
