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

:root {
  --bg: #faf7f2;
  --ink: #3d3a37;
  --sub: #8a857e;
  --accent: #d47a6a;
  --bubble-her: #fff;
  --bubble-me: #f4e3d3;
  --line: #e8e2d9;
}

body {
  font-family: "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
  background: var(--bg);
  color: var(--ink);
  height: 100dvh;
}

#app { display: flex; flex-direction: column; height: 100%; max-width: 640px; margin: 0 auto; }

header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 18px; border-bottom: 1px solid var(--line);
  background: var(--bg);
}
.who { display: flex; align-items: center; gap: 8px; }
.name { font-weight: 600; font-size: 17px; }
.mood { font-size: 13px; color: var(--sub); }
.dot {
  width: 10px; height: 10px; border-radius: 50%;
  transition: background 0.8s, box-shadow 0.8s;
}
#drawer-btn {
  border: none; background: none; font-size: 20px; color: var(--accent); cursor: pointer;
}

main { flex: 1; overflow-y: auto; padding: 18px 14px; display: flex; flex-direction: column; gap: 10px; }

.msg {
  max-width: 78%; padding: 10px 14px; border-radius: 16px;
  font-size: 15px; line-height: 1.6; white-space: pre-wrap; word-break: break-word;
}
.msg.her { background: var(--bubble-her); border: 1px solid var(--line); border-bottom-left-radius: 4px; align-self: flex-start; }
.msg.me  { background: var(--bubble-me); border-bottom-right-radius: 4px; align-self: flex-end; }

.typing { padding: 4px 18px; }
.typing span {
  display: inline-block; width: 6px; height: 6px; margin-right: 4px;
  background: var(--sub); border-radius: 50%; opacity: 0.4;
  animation: blink 1.2s infinite;
}
.typing span:nth-child(2) { animation-delay: 0.2s; }
.typing span:nth-child(3) { animation-delay: 0.4s; }
@keyframes blink { 0%,100% { opacity: 0.25; } 50% { opacity: 0.8; } }

footer { border-top: 1px solid var(--line); padding: 12px 14px; background: var(--bg); }
#chat-form { display: flex; gap: 10px; }
#chat-input {
  flex: 1; padding: 11px 14px; border: 1px solid var(--line); border-radius: 22px;
  font-size: 15px; outline: none; background: #fff;
}
#chat-form button {
  padding: 10px 20px; border: none; border-radius: 22px;
  background: var(--accent); color: #fff; font-size: 15px; cursor: pointer;
}
#chat-form button:disabled { opacity: 0.5; cursor: default; }

#drawer {
  position: fixed; top: 0; right: 0; width: 300px; height: 100%;
  background: #fff; border-left: 1px solid var(--line);
  padding: 24px 20px; overflow-y: auto; z-index: 10;
  box-shadow: -6px 0 24px rgba(0,0,0,0.06);
}
#drawer.hidden { display: none; }
#drawer h3 { margin-bottom: 16px; }
#drawer h4 { margin: 20px 0 8px; color: var(--sub); font-weight: 500; font-size: 14px; }
.rel-row { display: flex; align-items: center; gap: 10px; margin-bottom: 12px; font-size: 14px; }
.rel-row label { width: 52px; color: var(--sub); }
.rel-row b { min-width: 38px; text-align: right; }
.bar { flex: 1; height: 8px; background: var(--line); border-radius: 4px; overflow: hidden; }
.bar i { display: block; height: 100%; background: var(--accent); width: 0; transition: width 0.6s; }
#fact-list { list-style: none; font-size: 13px; color: var(--sub); }
#fact-list li { padding: 6px 0; border-bottom: 1px dashed var(--line); line-height: 1.5; }

#user-setup {
  position: fixed; inset: 0; background: var(--bg); z-index: 20;
  display: flex; align-items: center; justify-content: center;
}
#user-setup.hidden { display: none; }

/* ===== 头部动作区 ===== */
.header-actions { display: flex; align-items: center; gap: 14px; }
.hlink { font-size: 13px; color: var(--sub); text-decoration: none; }
.hlink:hover { color: var(--accent); }
.drawer-link { margin-top: 14px; font-size: 13px; }
.drawer-link a { color: var(--accent); text-decoration: none; }
.setup-back { margin-top: 16px; font-size: 13px; }
.setup-back a { color: var(--sub); text-decoration: none; }

/* ===== 首页（角色选择） ===== */
#home { max-width: 860px; margin: 0 auto; padding: 20px; }
.home-header {
  display: flex; align-items: baseline; justify-content: space-between;
  padding: 18px 4px 22px;
}
.home-header h1 { font-size: 22px; }
.home-body { display: flex; gap: 22px; align-items: flex-start; }
.char-list {
  flex: 1.1; display: grid;
  grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
  gap: 12px;
}
.char-card {
  background: #fff; border: 1px solid var(--line); border-radius: 14px;
  padding: 16px 12px; text-align: center; cursor: pointer;
  transition: transform 0.15s, border-color 0.15s, box-shadow 0.15s;
}
.char-card:hover { transform: translateY(-2px); box-shadow: 0 6px 18px rgba(0,0,0,0.07); }
.char-card.active { border-color: var(--accent); box-shadow: 0 4px 14px rgba(0,0,0,0.08); }
.avatar {
  width: 52px; height: 52px; margin: 0 auto 10px;
  border-radius: 50%; border: 2px solid; font-size: 26px;
  display: flex; align-items: center; justify-content: center;
  background: #fff;
}
.avatar.big { width: 64px; height: 64px; font-size: 32px; margin: 0; }
.cname { font-weight: 600; font-size: 15px; }
.ctag { font-size: 12px; color: var(--sub); margin-top: 4px; line-height: 1.4; }

.char-detail {
  flex: 1; background: #fff; border: 1px solid var(--line); border-radius: 16px;
  padding: 24px; min-height: 320px; position: sticky; top: 20px;
}
.char-detail .placeholder { text-align: center; padding-top: 100px; color: var(--sub); }
.char-detail .placeholder .sub, .sub { font-size: 13px; color: var(--sub); }
.detail-head { display: flex; align-items: center; gap: 16px; margin-bottom: 14px; }
.detail-head h2 { font-size: 20px; }
.detail-intro { font-size: 14px; line-height: 1.8; margin-bottom: 20px; }
.char-detail button {
  padding: 10px 28px; border: none; border-radius: 22px;
  background: var(--accent); color: #fff; font-size: 15px; cursor: pointer;
}
.char-detail .danger { margin-top: 12px; }

/* ===== 说明页 / 记忆管理页 ===== */
#guide { max-width: 720px; margin: 0 auto; padding: 20px; }
.guide-body section { margin-bottom: 34px; }
.guide-body h2 {
  font-size: 18px; margin-bottom: 14px; padding-left: 10px;
  border-left: 4px solid var(--accent);
}
.guide-body h3 { font-size: 15px; margin: 18px 0 8px; }
.guide-body p, .guide-body li { font-size: 14px; line-height: 1.9; color: var(--ink); }
.guide-body ul { padding-left: 20px; margin: 8px 0; }
.guide-body li { margin-bottom: 6px; }
.guide-body a { color: var(--accent); }
.guide-body .back { margin-top: 30px; text-align: center; }

.legend {
  background: #fff; border: 1px solid var(--line); border-radius: 12px;
  padding: 14px 18px; margin: 14px 0; font-size: 13px; line-height: 2;
}
.legend b { color: var(--ink); }
.legend .kind {
  font-size: 11px; color: var(--accent);
  border: 1px solid; border-radius: 4px; padding: 1px 6px; margin: 0 2px;
}

.memory-list { list-style: none; padding: 0; margin: 16px 0; }
.memory-item {
  display: flex; align-items: center; gap: 12px;
  padding: 10px 18px; border: 1px solid var(--line); border-radius: 10px;
  margin-bottom: 8px; background: #fff; font-size: 13px;
}
.memory-item .kind {
  flex-shrink: 0; font-size: 11px; color: var(--accent);
  border: 1px solid; border-radius: 4px; padding: 1px 6px;
}
.memory-item .content { flex: 1; line-height: 1.5; }
.memory-item .meta { flex-shrink: 0; color: var(--sub); font-size: 11px; }
.memory-item .forget {
  flex-shrink: 0; border: none; background: none; color: #c05050;
  font-size: 12px; cursor: pointer; padding: 4px 6px 4px 10px;
}
.memory-item .forget:hover { text-decoration: underline; }

.danger-zone {
  border: 1px dashed #d9a0a0; border-radius: 12px; padding: 16px;
  margin-top: 30px; background: #fdf6f6;
}
.danger-zone h3 { color: #a04040; font-size: 14px; }
.wipe {
  margin-top: 10px; padding: 8px 20px; border: none; border-radius: 18px;
  background: #c05050; color: #fff; font-size: 13px; cursor: pointer;
}
.wipe:hover { background: #a84040; }
.setup-card { text-align: center; }
.setup-card h2 { margin-bottom: 8px; }
.setup-card p { color: var(--sub); margin-bottom: 18px; }
.setup-card input {
  padding: 10px 14px; border: 1px solid var(--line); border-radius: 10px;
  font-size: 15px; outline: none; width: 220px; text-align: center;
}
.setup-card button {
  display: block; margin: 14px auto 0; padding: 10px 34px;
  border: none; border-radius: 22px; background: var(--accent);
  color: #fff; font-size: 15px; cursor: pointer;
}

.hidden { display: none; }

/* ===== 赞助 ===== */
.sponsor {
  margin: 26px 4px 30px; font-size: 13px;
}
.sponsor a {
  color: var(--accent); text-decoration: none; font-weight: 500;
  border-bottom: 1px dashed var(--accent);
}
.sponsor a:hover { opacity: 0.8; }
.sponsor-inline {
  margin-top: 26px; padding-top: 14px; border-top: 1px dashed var(--line);
  font-size: 13px; text-align: center;
}
.sponsor-inline a {
  color: var(--accent); text-decoration: none; font-weight: 500;
  border-bottom: 1px dashed var(--accent);
}
