:root {
  --bg: #fbf6f5;
  --surface: #ffffff;
  --surface-2: #f5ebe9;
  --text: #2a1f1d;
  --text-soft: #8a6f6b;
  --accent: #8b1a1a;
  --accent-soft: #f7e9e9;
  --accent-2: #b8862f;
  --warn: #f59e0b;
  --danger: #c0392b;
  --line: #ecdcd9;
  --radius: 14px;
  --shadow: 0 2px 12px rgba(42, 31, 29, 0.06);
  --nav-h: 60px;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body {
  margin: 0; padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "PingFang SC", "Microsoft YaHei", "Segoe UI", Roboto, sans-serif;
  font-size: 15px; line-height: 1.5;
}
#app-shell { max-width: 480px; margin: 0 auto; min-height: 100vh; background: var(--bg);
  display: flex; flex-direction: column; position: relative; }
#topbar {
  position: sticky; top: 0; z-index: 20;
  background: linear-gradient(135deg, #8b1a1a, #a83232);
  color: #fff; padding: 12px 16px; box-shadow: var(--shadow);
}
.brand { display: flex; align-items: center; gap: 10px; }
.brand .logo { font-size: 26px; }
.brand-title { font-size: 18px; font-weight: 700; letter-spacing: 1px; }
.brand-sub { font-size: 11px; opacity: 0.85; }

/* 家族切换药丸 */
.family-pill { display: flex; align-items: center; gap: 6px; background: rgba(255,255,255,0.18);
  border: 1px solid rgba(255,255,255,0.35); color: #fff; border-radius: 999px; padding: 6px 12px;
  font-size: 12px; cursor: pointer; max-width: 46%; }
.family-pill .fp-name { font-weight: 700; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 90px; }
.family-pill .fp-role { background: rgba(255,255,255,0.25); border-radius: 999px; padding: 1px 7px; font-size: 11px; }
.family-pill .fp-caret { opacity: 0.8; }

/* 登录注册 */
.auth-wrap { padding: 36px 18px 0; }
.auth-tabs { display: flex; gap: 8px; margin-bottom: 18px; }
.auth-tabs button { flex: 1; padding: 10px; border-radius: 10px; border: 1px solid var(--line); background: var(--surface); color: var(--text-soft); font-weight: 600; cursor: pointer; }
.auth-tabs button.active { background: var(--accent); color: #fff; border-color: var(--accent); }
.auth-card { background: var(--surface); border-radius: var(--radius); padding: 20px 16px; box-shadow: var(--shadow); }
.auth-brand { text-align: center; margin-bottom: 18px; }
.auth-brand .logo { font-size: 46px; }
.auth-brand .t { font-size: 22px; font-weight: 800; letter-spacing: 1px; margin-top: 6px; }
.auth-brand .s { font-size: 12px; color: var(--text-soft); margin-top: 4px; }

/* 回忆录章节 */
.chapter { background: var(--surface); border-radius: 12px; padding: 14px; box-shadow: var(--shadow); margin-bottom: 12px; border-left: 4px solid var(--accent-2); }
.chapter .ch-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 6px; }
.chapter .ch-title { font-weight: 700; font-size: 15px; }
.chapter .ch-vis { font-size: 11px; padding: 2px 8px; border-radius: 999px; background: var(--surface-2); color: var(--text-soft); }
.chapter .ch-summary { font-size: 13px; color: var(--text); line-height: 1.6; }
.chapter .ch-excerpt { font-size: 12px; color: var(--text-soft); margin-top: 6px; font-style: italic; border-top: 1px dashed var(--line); padding-top: 6px; }
.vis-self { background: #fde8e8 !important; color: #c0392b !important; }
.vis-public { background: #f7efe2 !important; color: #b8862f !important; }

/* 认领条目 */
.claim-row { display: flex; align-items: center; gap: 10px; background: var(--surface); border-radius: 12px; padding: 12px 14px; box-shadow: var(--shadow); margin-bottom: 10px; }
.claim-row .cr-info { flex: 1; min-width: 0; }
.copy-btn { font-size: 12px; padding: 6px 10px; border-radius: 8px; background: var(--accent-soft); color: var(--accent); border: none; cursor: pointer; font-weight: 600; }

/* 段标题小按钮 */
.section-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 8px; }
.section-head .section-title { margin: 0; }
.section-head .btn.small { padding: 5px 10px; }

#app { flex: 1; padding: 16px 14px calc(var(--nav-h) + 24px); }

#bottomnav {
  position: fixed; bottom: 0; left: 50%; transform: translateX(-50%);
  width: 100%; max-width: 480px; height: var(--nav-h);
  background: var(--surface); border-top: 1px solid var(--line);
  display: flex; z-index: 30;
}
#bottomnav button {
  flex: 1; border: none; background: none; cursor: pointer;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 2px; color: var(--text-soft); font-size: 11px; padding: 4px;
}
#bottomnav button span { font-size: 20px; line-height: 1; }
#bottomnav button.active { color: var(--accent); }
#bottomnav button.active span { transform: translateY(-1px); }

/* 通用卡片 */
.card { background: var(--surface); border-radius: var(--radius); padding: 16px; box-shadow: var(--shadow); margin-bottom: 14px; }
.card h3 { margin: 0 0 12px; font-size: 15px; }
.muted { color: var(--text-soft); font-size: 13px; }
.section-title { font-size: 13px; color: var(--text-soft); margin: 4px 0 8px; font-weight: 600; }

/* 按钮 */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  border: none; border-radius: 10px; padding: 11px 16px; font-size: 14px; font-weight: 600;
  cursor: pointer; background: var(--accent); color: #fff; transition: opacity .15s; }
.btn:active { opacity: 0.85; }
.btn.block { width: 100%; }
.btn.ghost { background: var(--surface-2); color: var(--text); }
.btn.soft { background: var(--accent-soft); color: var(--accent); }
.btn.danger { background: #fef2f2; color: var(--danger); }
.btn.small { padding: 7px 12px; font-size: 13px; border-radius: 8px; }
.btn-row { display: flex; gap: 10px; flex-wrap: wrap; }

/* 统计看板 */
.stats { display: flex; gap: 10px; }
.stat { flex: 1; background: var(--surface); border-radius: var(--radius); padding: 16px 10px; text-align: center; box-shadow: var(--shadow); }
.stat .num { font-size: 26px; font-weight: 800; color: var(--accent); }
.stat .lbl { font-size: 12px; color: var(--text-soft); margin-top: 4px; }

/* 列表 */
.list { display: flex; flex-direction: column; gap: 10px; }
.row { background: var(--surface); border-radius: 12px; padding: 12px 14px; box-shadow: var(--shadow);
  display: flex; align-items: center; gap: 12px; cursor: pointer; }
.row:active { background: var(--surface-2); }
.avatar { width: 42px; height: 42px; border-radius: 50%; background: var(--accent-soft); color: var(--accent);
  display: flex; align-items: center; justify-content: center; font-weight: 700; font-size: 16px; flex-shrink: 0; }
.row .info { flex: 1; min-width: 0; }
.row .name { font-weight: 600; }
.row .meta { font-size: 12px; color: var(--text-soft); }

/* 徽标 */
.badge { display: inline-block; font-size: 11px; padding: 2px 8px; border-radius: 999px; font-weight: 600; }
.badge.active { background: var(--accent-soft); color: var(--accent); }
.badge.stub { background: #fff4e0; color: var(--warn); }
.badge.dim { background: var(--surface-2); color: var(--text-soft); }

/* 输入框 */
.field { margin-bottom: 12px; }
.field label { display: block; font-size: 12px; color: var(--text-soft); margin-bottom: 5px; }
.input, textarea.input, select.input {
  width: 100%; border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px;
  font-size: 14px; background: var(--surface); color: var(--text); font-family: inherit;
}
.input:focus { outline: 2px solid var(--accent-soft); border-color: var(--accent); }
/* 微信 X5 内核：防止输入时页面被顶起/缩放、文本自动放大，减少焦点抖动 */
.input, textarea.input, select.input {
  -webkit-user-select: text; user-select: text;
  -webkit-touch-callout: default;
  -webkit-text-size-adjust: 100%; text-size-adjust: 100%;
  font-size: 16px;
}
textarea.input { resize: vertical; min-height: 64px; }

/* 搜索 */
.search { width: 100%; border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px; font-size: 14px; margin-bottom: 12px; }

/* 访谈聊天 */
.chat-wrap { display: flex; flex-direction: column; height: calc(100vh - var(--nav-h) - 130px); }
.chat-head { background: var(--surface); border-radius: 12px; padding: 10px 14px; margin-bottom: 10px; box-shadow: var(--shadow);
  display: flex; align-items: center; justify-content: space-between; }
.chat-head .t-name { font-weight: 700; }
.chat-scroll { flex: 1; overflow-y: auto; padding: 6px 2px; display: flex; flex-direction: column; gap: 10px; }
.bubble { max-width: 78%; padding: 10px 13px; border-radius: 14px; font-size: 14px; line-height: 1.5; word-break: break-word; }
.bubble.assistant { background: var(--surface); align-self: flex-start; border-bottom-left-radius: 4px; box-shadow: var(--shadow); }
.bubble.user { background: var(--accent); color: #fff; align-self: flex-end; border-bottom-right-radius: 4px; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; margin: 4px 0 10px; }
.chip { font-size: 12px; padding: 4px 10px; border-radius: 999px; background: var(--accent-soft); color: var(--accent); }
.chip.add { background: #f7efe2; color: #b8862f; }
.chat-input { display: flex; gap: 8px; margin-top: 8px; }
.chat-input .input { flex: 1; }
.btn.recording { background: var(--danger); color: #fff; animation: pulse 1.2s infinite; }
@keyframes pulse { 0% { opacity: 1; } 50% { opacity: 0.6; } 100% { opacity: 1; } }
.bubble-tools { display: flex; gap: 4px; margin-top: 6px; }
.bubble-speak { border: none; background: var(--surface-2); color: var(--accent); border-radius: 6px;
  font-size: 11px; padding: 2px 7px; cursor: pointer; }
.bubble-speak:active { opacity: 0.8; }

/* 图谱 */
.tree-toolbar { display: flex; gap: 8px; margin-bottom: 10px; align-items: center; }
.tree-toolbar .spacer { flex: 1; }
.icon-btn { width: 34px; height: 34px; border-radius: 9px; border: 1px solid var(--line); background: var(--surface);
  font-size: 16px; cursor: pointer; display: inline-flex; align-items: center; justify-content: center; }
.tree-canvas { background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow); overflow: hidden; touch-action: none; }
.tree-node text { font-size: 12px; fill: var(--text); }
.tree-node .nm { font-weight: 600; }
.node-circle { stroke-width: 2; }
.node-active .node-circle { fill: var(--accent); stroke: #6e1414; }
.node-stub .node-circle { fill: #fff; stroke: var(--warn); stroke-dasharray: 4 3; }
.node-stub text { fill: var(--text-soft); }
.edge { stroke: #c7cbe0; stroke-width: 1.6; fill: none; }
.edge.spouse { stroke: #f0a93b; stroke-dasharray: 5 4; }

/* 关系展示 */
.rel-group { margin-bottom: 10px; }
.rel-tag { display: inline-block; font-size: 12px; padding: 5px 11px; border-radius: 999px; background: var(--surface-2); margin: 0 6px 6px 0; cursor: pointer; }
.rel-tag:hover { background: var(--accent-soft); color: var(--accent); }

/* 照片网格 */
.photo-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.photo-grid .ph { aspect-ratio: 1; background: var(--surface-2); border-radius: 10px; display: flex; align-items: center; justify-content: center; color: var(--text-soft); font-size: 12px; overflow: hidden; }
.photo-grid .ph img { width: 100%; height: 100%; object-fit: cover; }

/* 模态框 */
.modal-mask { position: fixed; inset: 0; background: rgba(20,22,33,0.45); display: flex; align-items: flex-end; justify-content: center; z-index: 100; }
.modal { width: 100%; max-width: 480px; background: var(--surface); border-radius: 18px 18px 0 0; padding: 18px 16px 24px; max-height: 86vh; overflow-y: auto; }
.modal h3 { margin: 0 0 14px; }
.modal .modal-close { float: right; font-size: 20px; color: var(--text-soft); cursor: pointer; border: none; background: none; }

/* Toast */
#toast-layer { position: fixed; top: 14px; left: 50%; transform: translateX(-50%); z-index: 200; display: flex; flex-direction: column; gap: 8px; align-items: center; pointer-events: none; }
.toast { background: rgba(31,35,48,0.92); color: #fff; padding: 9px 16px; border-radius: 10px; font-size: 13px; box-shadow: var(--shadow); animation: toastIn .2s ease; }
@keyframes toastIn { from { opacity: 0; transform: translateY(-8px); } to { opacity: 1; transform: none; } }

.loading { text-align: center; color: var(--text-soft); padding: 30px 0; }
.error { color: var(--danger); padding: 14px; }
.empty { text-align: center; color: var(--text-soft); padding: 30px 0; font-size: 14px; }
.hint { font-size: 12px; color: var(--text-soft); margin-top: 6px; }
.divider { height: 1px; background: var(--line); margin: 14px 0; }
.guide li { margin-bottom: 6px; }
