:root {
  --bg: #f6f5fb;
  --surface: #ffffff;
  --surface-2: #f0eefb;
  --ink: #1b1733;
  --ink-soft: #6b6685;
  --brand: #6d4aff;
  --brand-soft: #efe9ff;
  --line: #e7e3f4;
  --user-bubble: #6d4aff;
  --ai-bubble: #f3f1fa;
  --warn: #b76b00;
  --warn-bg: #fff5e6;
  --shadow: 0 6px 24px rgba(40, 26, 99, 0.08);
  --radius: 16px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Microsoft YaHei", Roboto, Helvetica, Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
}

a { color: var(--brand); }

.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 14px 20px;
  background: rgba(255, 255, 255, 0.86);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--line);
}

.brand { display: flex; align-items: center; gap: 12px; }
.brand-logo { font-size: 28px; line-height: 1; }
.brand-text h1 { margin: 0; font-size: 18px; letter-spacing: 0.5px; }
.brand-text p { margin: 2px 0 0; font-size: 12px; color: var(--ink-soft); }

.disclaimer-pill {
  font-size: 12px;
  padding: 6px 12px;
  border-radius: 999px;
  background: var(--warn-bg);
  color: var(--warn);
  border: 1px solid #f3e0bd;
  white-space: nowrap;
}

.view { max-width: 1080px; margin: 0 auto; padding: 20px; }

/* ---- Hero ---- */
.hero { text-align: center; padding: 18px 0 6px; }
.hero h2 { margin: 0 0 6px; font-size: 26px; }
.hero p { margin: 0; color: var(--ink-soft); }

/* ---- Controls ---- */
.controls { margin: 18px auto 22px; max-width: 720px; }
.search-wrap {
  display: flex; align-items: center; gap: 8px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 10px 14px;
  box-shadow: var(--shadow);
}
.search-icon { opacity: 0.6; }
#search {
  border: none; outline: none; flex: 1;
  font-size: 15px; background: transparent; color: var(--ink);
}
.chips {
  display: flex; flex-wrap: wrap; gap: 8px;
  margin-top: 14px; justify-content: center;
}
.chip {
  font-size: 13px;
  padding: 7px 14px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--ink-soft);
  cursor: pointer;
  transition: all 0.15s ease;
}
.chip:hover { border-color: var(--brand); color: var(--brand); }
.chip.active { background: var(--brand); color: #fff; border-color: var(--brand); }

/* ---- Grid ---- */
.grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
  gap: 16px;
}
.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 18px;
  cursor: pointer;
  box-shadow: var(--shadow);
  transition: transform 0.15s ease, box-shadow 0.15s ease, border-color 0.15s ease;
  display: flex; flex-direction: column; gap: 10px;
  position: relative;
  overflow: hidden;
}
.card:hover { transform: translateY(-3px); border-color: var(--brand); box-shadow: 0 12px 30px rgba(109, 74, 255, 0.16); }
.card:focus-visible { outline: 2px solid var(--brand); outline-offset: 2px; border-color: var(--brand); }
.card-avatar {
  width: 52px; height: 52px; border-radius: 14px;
  display: grid; place-items: center;
  font-size: 28px;
  background: linear-gradient(135deg, var(--brand-soft), #ffffff);
  border: 1px solid var(--line);
}
.card-name { font-size: 17px; font-weight: 700; }
.card-name .en { font-size: 12px; color: var(--ink-soft); font-weight: 500; margin-left: 6px; }
.card-title { font-size: 12.5px; color: var(--ink-soft); }
.card-blurb { font-size: 13px; color: #4a4566; line-height: 1.5; flex: 1; }
.card-foot { display: flex; align-items: center; gap: 8px; margin-top: 4px; }
.cat-tag {
  font-size: 11px; padding: 3px 9px; border-radius: 999px;
  background: var(--surface-2); color: #5b5486; border: 1px solid var(--line);
}
.fidelity {
  font-size: 11px; padding: 3px 9px; border-radius: 999px; margin-left: auto;
}
.fidelity.verified { background: #e8f7ee; color: #1f8a4c; border: 1px solid #bfe6cf; }
.fidelity.beta { background: var(--warn-bg); color: var(--warn); border: 1px solid #f3e0bd; }

.empty-hint { text-align: center; color: var(--ink-soft); margin-top: 40px; }

/* ---- Chat ---- */
#chat { display: flex; flex-direction: column; min-height: calc(100vh - 64px); padding: 0; max-width: none; }
#chat[hidden] { display: none; }
.chat-header {
  display: flex; align-items: center; gap: 12px;
  padding: 12px 18px; background: var(--surface);
  border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 10;
}
.back-btn {
  border: none; background: var(--surface-2); color: var(--ink);
  width: 38px; height: 38px; border-radius: 10px; font-size: 20px; cursor: pointer;
}
.back-btn:hover { background: var(--brand-soft); }
.chat-avatar {
  width: 44px; height: 44px; border-radius: 12px; display: grid; place-items: center;
  font-size: 24px; background: linear-gradient(135deg, var(--brand-soft), #fff); border: 1px solid var(--line);
}
.chat-id { flex: 1; min-width: 0; }
.chat-name { font-weight: 700; font-size: 16px; }
.chat-title { font-size: 12px; color: var(--ink-soft); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.chat-disclaimer {
  margin: 12px auto 0; max-width: 760px; width: calc(100% - 36px);
  font-size: 12.5px; color: var(--warn); background: var(--warn-bg);
  border: 1px solid #f3e0bd; border-radius: 10px; padding: 8px 14px;
}

.messages {
  flex: 1; width: 100%; max-width: 760px; margin: 0 auto;
  padding: 18px 18px 8px; display: flex; flex-direction: column; gap: 14px;
  overflow-y: auto;
}
.msg { display: flex; gap: 10px; max-width: 100%; }
.msg.user { flex-direction: row-reverse; }
.bubble {
  padding: 12px 15px; border-radius: 14px; line-height: 1.6; font-size: 14.5px;
  white-space: pre-wrap; word-break: break-word; max-width: 78%;
}
.msg.ai .bubble { background: var(--ai-bubble); border: 1px solid var(--line); border-top-left-radius: 4px; }
.msg.user .bubble { background: var(--user-bubble); color: #fff; border-top-right-radius: 4px; }
.msg .avatar-mini {
  width: 32px; height: 32px; border-radius: 9px; flex-shrink: 0;
  display: grid; place-items: center; font-size: 18px;
  background: var(--surface-2); border: 1px solid var(--line);
}
.msg.user .avatar-mini { background: var(--brand); color: #fff; }
.bubble strong { font-weight: 700; }
.bubble code {
  background: rgba(109, 74, 255, 0.1); padding: 1px 6px; border-radius: 5px;
  font-family: ui-monospace, Menlo, Consolas, monospace; font-size: 13px;
}
.bubble pre {
  background: #201a3a; color: #f3f1fa; padding: 12px; border-radius: 10px;
  overflow-x: auto; font-size: 13px; white-space: pre; margin: 8px 0;
}
.bubble pre code { background: transparent; color: inherit; padding: 0; }
.cursor { display: inline-block; width: 8px; height: 16px; background: var(--brand); border-radius: 2px; animation: blink 1s steps(2) infinite; vertical-align: middle; margin-left: 2px; }
@keyframes blink { 0%, 50% { opacity: 1; } 50.01%, 100% { opacity: 0; } }

/* ---- Composer ---- */
.composer { max-width: 760px; margin: 0 auto; width: calc(100% - 36px); padding: 10px 0 20px; }
.samples { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 10px; }
.sample {
  font-size: 13px; padding: 7px 12px; border-radius: 999px;
  background: var(--surface); border: 1px solid var(--line); color: var(--brand); cursor: pointer;
}
.sample:hover { background: var(--brand-soft); }
.input-row {
  display: flex; gap: 10px; align-items: flex-end;
  background: var(--surface); border: 1px solid var(--line);
  border-radius: 14px; padding: 8px 8px 8px 14px; box-shadow: var(--shadow);
}
#input {
  flex: 1; border: none; outline: none; resize: none;
  font-size: 15px; font-family: inherit; line-height: 1.5; max-height: 140px;
  background: transparent; color: var(--ink); padding: 6px 0;
}
.send-btn {
  border: none; background: var(--brand); color: #fff; font-size: 14px;
  padding: 10px 18px; border-radius: 10px; cursor: pointer; white-space: nowrap;
}
.send-btn:disabled { opacity: 0.5; cursor: not-allowed; }
.stop-btn {
  border: 1px solid var(--line); background: var(--surface-2); color: var(--ink-soft);
  font-size: 14px; padding: 10px 16px; border-radius: 10px; cursor: pointer; white-space: nowrap;
}
.stop-btn:hover { border-color: var(--brand); color: var(--brand); }

.retry-btn {
  display: block; margin-top: 10px;
  font-size: 13px; padding: 6px 14px; border-radius: 999px;
  border: 1px solid var(--line); background: var(--surface); color: var(--brand); cursor: pointer;
}
.retry-btn:hover { background: var(--brand-soft); }
.err { color: #c0392b; }
.muted-note { color: var(--ink-soft); }
.stopped { font-size: 12px; color: var(--ink-soft); font-style: normal; margin-left: 8px; }

.foot {
  text-align: center; font-size: 12px; color: var(--ink-soft);
  padding: 18px; border-top: 1px solid var(--line);
}

@media (max-width: 560px) {
  .grid { grid-template-columns: 1fr 1fr; gap: 12px; }
  .card { padding: 14px; }
  .card-avatar { width: 44px; height: 44px; font-size: 24px; }
  .card-name { font-size: 15px; }
  .bubble { max-width: 86%; }
  .hero h2 { font-size: 22px; }
}
