:root {
  --paper: #faf6ef;
  --paper-2: #f3ece0;
  --ink: #2b2723;
  --ink-2: #6b6156;
  --ink-3: #9a9086;
  --red: #9c2b23;
  --red-soft: #b8544a;
  --line: #e3d9c8;
  --card: #fffdf8;
  --shadow: 0 2px 10px rgba(60, 45, 30, .08);
}

* { box-sizing: border-box; }

/* 浏览/编辑权限：非编辑态（body 无 .editor 类）隐藏所有编辑入口；写接口另有后端令牌强制拦截 */
body:not(.editor) .edit-only { display: none !important; }

body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font-family: "Noto Serif SC", "Songti SC", "SimSun", "PingFang SC", serif;
  -webkit-font-smoothing: antialiased;
}

.hidden { display: none !important; }

/* 登录 */
.login {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(#faf6ef, #f0e7d8);
}
.login-card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 40px 36px;
  width: min(360px, 90vw);
  text-align: center;
  box-shadow: var(--shadow);
}
.login-title { font-size: 24px; margin: 0 0 6px; letter-spacing: 4px; color: var(--red); }
.login-sub { color: var(--ink-2); font-size: 14px; margin: 0 0 24px; }
.login-input {
  width: 100%; padding: 12px 14px; font-size: 15px;
  border: 1px solid var(--line); border-radius: 8px;
  background: #fff; color: var(--ink); outline: none; font-family: inherit;
}
.login-input:focus { border-color: var(--red-soft); }
.login-btn {
  margin-top: 14px; width: 100%; padding: 12px; font-size: 15px;
  background: var(--red); color: #fff; border: none; border-radius: 8px;
  cursor: pointer; font-family: inherit; letter-spacing: 2px;
}
.login-btn:hover { background: #8a251e; }
.login-err { color: var(--red); font-size: 13px; margin-top: 12px; min-height: 18px; }

/* 顶栏 */
.topbar {
  background: var(--card); border-bottom: 1px solid var(--line);
  padding: 14px 20px; display: flex; flex-wrap: wrap; gap: 12px;
  align-items: center; justify-content: space-between;
}
.site-title { font-size: 20px; margin: 0; letter-spacing: 4px; color: var(--red); }
.stats { font-size: 13px; color: var(--ink-2); margin-top: 4px; }
.stats span { margin-right: 14px; }
.topbar-actions { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.sync-info { font-size: 12px; color: var(--ink-3); display: inline-flex; align-items: center; gap: 6px; white-space: nowrap; }
.sync-info .dot { width: 8px; height: 8px; border-radius: 50%; background: #2e9e5b; box-shadow: 0 0 0 3px rgba(46,158,91,.18); animation: syncpulse 2s ease-in-out infinite; }
.sync-info.stale .dot { background: var(--ink-3); box-shadow: none; animation: none; }
@keyframes syncpulse { 0%,100% { opacity: 1; } 50% { opacity: .45; } }
.search {
  padding: 8px 12px; border: 1px solid var(--line); border-radius: 8px;
  background: #fff; font-size: 14px; min-width: 200px; font-family: inherit; color: var(--ink);
}
.ghost-btn {
  padding: 8px 14px; border: 1px solid var(--line); background: #fff;
  border-radius: 8px; cursor: pointer; font-size: 13px; color: var(--ink-2);
  font-family: inherit;
}
.ghost-btn:hover { border-color: var(--red-soft); color: var(--red); }
/* 开关型按钮（显示/隐藏配偶、外系）：保持与其他按钮完全同款，仅用小红点指示开启状态 */
.ghost-btn.active {
  border-color: var(--line); background: #fff; color: var(--ink-2);
}
.ghost-btn.active::before {
  content: ''; display: inline-block; width: 7px; height: 7px; border-radius: 50%;
  background: var(--red, #b5342a); margin-right: 6px; vertical-align: 1px;
}

/* 标签 */
.tabs { display: flex; gap: 4px; padding: 0 20px; border-bottom: 1px solid var(--line); background: var(--card); }
.tab {
  padding: 12px 20px; border: none; background: none; cursor: pointer;
  font-size: 15px; color: var(--ink-2); border-bottom: 2px solid transparent;
  font-family: inherit;
}
.tab.active { color: var(--red); border-bottom-color: var(--red); }

.main { padding: 16px 20px 40px; }

/* 世系树 */
.toolbar { display: flex; gap: 8px; align-items: center; margin-bottom: 10px; flex-wrap: wrap; }
.zoom-label { font-size: 13px; color: var(--ink-2); min-width: 46px; text-align: center; }
.tree-wrap {
  background: var(--card); border: 1px solid var(--line); border-radius: 12px;
  overflow: auto; height: calc(100vh - 260px); min-height: 380px;
  cursor: grab; position: relative;
}
.tree-wrap:active { cursor: grabbing; }
.tree-canvas { transform-origin: 0 0; padding: 24px; display: inline-block; }
.node-box {
  fill: var(--card); stroke: var(--line); stroke-width: 1;
  cursor: pointer;
}
.node-box.male { fill: #fdf6ec; }
.node-box.female { fill: #fdeff0; }
.node-box.spouse { stroke: #e2d5ba; stroke-width: 1; }
.node-box.has-children { stroke: var(--red-soft); stroke-width: 1.4; }
.node-name { font-size: 15px; fill: var(--ink); text-anchor: middle; dominant-baseline: central; pointer-events: none; }
.node-meta { font-size: 11px; fill: var(--ink-3); text-anchor: middle; dominant-baseline: central; pointer-events: none; }
.node-badge { font-size: 10px; fill: #fff; text-anchor: middle; dominant-baseline: central; pointer-events: none; }
.link { fill: none; stroke: #cfc3ad; stroke-width: 1.2; }
.spouse-link { fill: none; stroke: #b9a888; stroke-width: 1.2; }
/* 外系亲属（外姓亲友）：大圆形磨砂徽标 + 弱化虚线节点/连线 */
.kin-badge {
  fill: rgba(255, 255, 255, 0.55);
  stroke: rgba(180, 130, 90, 0.75);
  stroke-width: 1.5;
  cursor: pointer;
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
}
.kin-badge:hover { fill: rgba(255, 255, 255, 0.75); }
.kin-badge-text {
  font-size: 15px;
  font-weight: 700;
  fill: #9c2b23;
  text-anchor: middle;
  dominant-baseline: central;
  pointer-events: none;
}
.kin-link { fill: none; stroke: #d4b89a; stroke-width: 1.5; stroke-dasharray: 6 4; vector-effect: non-scaling-stroke; }
.node-box.kin { stroke: #d8c4a8; stroke-dasharray: 5 3; }
.hint { font-size: 12px; color: var(--ink-3); margin: 8px 0 0; }

/* 待挂接成员区 */
.loose-box {
  margin-top: 12px; padding: 14px 16px;
  background: #fbf7ee; border: 1px dashed #d8c9a8; border-radius: 12px;
}
.loose-title {
  font-size: 14px; font-weight: 600; color: var(--ink-2);
  display: flex; align-items: baseline; gap: 8px; flex-wrap: wrap;
}
.loose-tip { font-size: 12px; font-weight: 400; color: var(--ink-3); }
.loose-list { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 10px; }
.loose-chip {
  display: inline-flex; align-items: center; gap: 6px;
  border: 1px solid var(--line); background: #fff; color: var(--ink);
  border-radius: 20px; padding: 6px 8px 6px 14px; font-size: 13px; cursor: pointer;
  transition: border-color .15s, color .15s;
}
.loose-chip:hover { border-color: var(--red-soft); color: var(--red); }
.loose-chip-text { line-height: 1.4; }
.loose-del {
  width: 20px; height: 20px; border-radius: 50%; border: none;
  background: #eee; color: #999; font-size: 14px; line-height: 1;
  cursor: pointer; display: flex; align-items: center; justify-content: center;
  flex-shrink: 0; padding: 0; transition: background .15s, color .15s;
}
.loose-del:hover { background: #e53935; color: #fff; }

/* 名录 */
.gen-block { margin-bottom: 26px; }
.gen-title {
  font-size: 15px; color: var(--red); border-left: 3px solid var(--red);
  padding-left: 10px; margin: 0 0 12px;
}
.branch-stats { display: flex; flex-direction: column; gap: 8px; }
.branch-row { display: flex; align-items: center; gap: 10px; cursor: pointer; padding: 6px 8px; border-radius: 8px; transition: .15s; }
.branch-row:hover { background: var(--bg-soft); }
.branch-name { width: 50px; font-size: 13px; color: var(--ink-2); flex-shrink: 0; }
.branch-bar { flex: 1; height: 10px; background: var(--bg-soft); border-radius: 5px; overflow: hidden; }
.branch-bar-fill { height: 100%; background: linear-gradient(90deg, var(--red-soft), var(--red)); border-radius: 5px; transition: width .3s; }
.branch-count { width: 80px; font-size: 12px; color: var(--ink-3); text-align: right; flex-shrink: 0; }
.member-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 10px; }
.member-card {
  background: var(--card); border: 1px solid var(--line); border-radius: 10px;
  padding: 12px; cursor: pointer; transition: .15s;
}
.member-card:hover { border-color: var(--red-soft); box-shadow: var(--shadow); }
.member-name { font-size: 15px; margin-bottom: 4px; }
.member-sub { font-size: 12px; color: var(--ink-3); }
.empty { color: var(--ink-3); font-size: 14px; padding: 30px 0; text-align: center; }

/* 字辈 */
.zibei-item {
  display: flex; gap: 16px; padding: 12px 14px; background: var(--card);
  border: 1px solid var(--line); border-radius: 10px; margin-bottom: 8px;
}
.zibei-gen { color: var(--red); min-width: 64px; }
.zibei-word { font-size: 18px; letter-spacing: 6px; }

/* 详情面板 */
.panel {
  position: fixed; top: 0; right: 0; width: min(380px, 92vw); height: 100vh;
  background: var(--card); border-left: 1px solid var(--line); z-index: 66;
  padding: 24px; overflow-y: auto; box-shadow: -4px 0 18px rgba(60,45,30,.08);
}
.panel-mask { position: fixed; inset: 0; background: rgba(40,30,20,.25); z-index: 65; }
.panel-close {
  position: absolute; top: 12px; right: 14px; background: none; border: none;
  font-size: 26px; color: var(--ink-3); cursor: pointer; line-height: 1;
}

/* 外系关系窗口：外系的外挂关系树独立运行（规则与本族一致，不显示世代） */
.kin-window-overlay {
  position: fixed; inset: 0; background: rgba(40, 30, 20, 0.45);
  z-index: 60; display: flex; align-items: center; justify-content: center; padding: 20px;
}
.kin-window {
  background: var(--card); border-radius: 14px; border: 1px solid var(--line);
  width: min(1180px, 96vw); height: min(860px, 92vh);
  display: flex; flex-direction: column; overflow: hidden;
  box-shadow: 0 12px 48px rgba(40, 25, 10, 0.3);
}
.kin-window-head {
  display: flex; align-items: center; gap: 10px;
  padding: 10px 16px; border-bottom: 1px solid var(--line); flex-shrink: 0;
}
.kin-window-title {
  font-size: 16px; font-weight: 700; color: var(--red-strong, #9c2b23);
  flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.kin-window-actions { display: flex; align-items: center; gap: 6px; }
.kin-window-actions .zoom-label { min-width: 42px; }
.kin-window .panel-close { position: static; flex-shrink: 0; }
.kin-window-wrap {
  flex: 1; overflow: hidden; position: relative; cursor: grab;
  touch-action: none; /* 让指针事件接管拖拽/双指缩放，避免浏览器默认手势抢占 */
  background: repeating-linear-gradient(0deg, rgba(180, 150, 110, 0.05) 0 1px, transparent 1px 28px),
              repeating-linear-gradient(90deg, rgba(180, 150, 110, 0.05) 0 1px, transparent 1px 28px),
              var(--card);
}
.kin-window-wrap.grabbing { cursor: grabbing; }
.kin-window-canvas { transform-origin: 0 0; display: inline-block; padding: 0; margin: 0; }
.kin-window .hint { padding: 8px 16px; margin: 0; border-top: 1px solid var(--line); flex-shrink: 0; }
.panel-name { font-size: 24px; margin: 0 0 4px; }
.panel-sub { color: var(--ink-3); font-size: 13px; margin-bottom: 18px; }
.panel-row { display: flex; padding: 9px 0; border-bottom: 1px dashed var(--line); font-size: 14px; }
.panel-key { color: var(--ink-3); min-width: 76px; }
.panel-val { flex: 1; }
.panel-bio { margin-top: 16px; font-size: 14px; line-height: 1.8; color: var(--ink-2); }

/* 个人详情页增强样式 */
.panel-header { display: flex; gap: 16px; align-items: center; margin-bottom: 20px; padding-bottom: 16px; border-bottom: 1px solid var(--line); }
.panel-avatar { width: 80px; height: 80px; border-radius: 12px; flex-shrink: 0; overflow: hidden; display: flex; align-items: center; justify-content: center; }
.panel-avatar-img { width: 100%; height: 100%; object-fit: cover; }
.panel-avatar-char { width: 100%; height: 100%; display: flex; align-items: center; justify-content: center; font-size: 32px; color: #fff; }
.panel-avatar-char.male { background: linear-gradient(#a8c4e0, #87a8c8); }
.panel-avatar-char.female { background: linear-gradient(#e8c8d0, #d0a8b4); }
.panel-header-info { flex: 1; min-width: 0; }
.panel-tags { display: flex; flex-wrap: wrap; gap: 6px; margin: 6px 0; }
.panel-tag { font-size: 11px; padding: 2px 8px; border-radius: 10px; background: #f0ebe3; color: var(--ink-2); }
.panel-tag.tag-alive { background: #e8f5e9; color: #2e7d32; }
.panel-tag.tag-dead { background: #fafafa; color: #999; }
.panel-section { margin-bottom: 20px; }
.panel-section-title { font-size: 15px; font-weight: 600; color: var(--ink); margin: 0 0 10px; padding-left: 8px; border-left: 3px solid var(--red-soft); }
.panel-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 0 16px; }
.panel-grid .panel-row { padding: 7px 0; }
.rel-group { margin-bottom: 12px; }
.rel-label { font-size: 12px; color: var(--ink-3); margin-bottom: 6px; }
.rel-list { display: flex; flex-wrap: wrap; gap: 8px; }
.rel-empty { font-size: 13px; color: #bbb; font-style: italic; }
.rel-warn { font-size: 12px; color: #e65100; background: #fff3e0; border-radius: 6px; padding: 6px 10px; margin-top: 6px; width: 100%; }
.rel-note { font-size: 12px; color: #8a7a5c; background: #f5f0e6; border-radius: 6px; padding: 6px 10px; margin-top: 6px; width: 100%; }
.mini-person { display: flex; align-items: center; gap: 8px; background: #faf7f2; border: 1px solid var(--line); border-radius: 8px; padding: 6px 10px; cursor: pointer; transition: background .15s; min-width: 120px; }
.mini-person:hover { background: #f3ede3; }
.mini-avatar { width: 32px; height: 32px; border-radius: 50%; object-fit: cover; flex-shrink: 0; }
.mini-avatar-char { width: 32px; height: 32px; border-radius: 50%; display: flex; align-items: center; justify-content: center; font-size: 14px; color: #fff; flex-shrink: 0; }
.mini-avatar-char.male { background: linear-gradient(#a8c4e0, #87a8c8); }
.mini-avatar-char.female { background: linear-gradient(#e8c8d0, #d0a8b4); }
.mini-info { min-width: 0; }
.mini-name { font-size: 13px; font-weight: 500; color: var(--ink); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.mini-meta { font-size: 11px; color: var(--ink-3); }
.mini-extra { font-size: 10px; color: var(--red); }
.panel-photos { display: flex; flex-wrap: wrap; gap: 8px; }
.panel-photo { width: 80px; height: 80px; border-radius: 8px; object-fit: cover; cursor: pointer; border: 1px solid var(--line); transition: transform .15s; }
.panel-photo:hover { transform: scale(1.05); }
.photo-overlay { position: fixed; inset: 0; background: rgba(0,0,0,.85); z-index: 100; display: flex; align-items: center; justify-content: center; cursor: zoom-out; }
.photo-overlay-img { max-width: 90vw; max-height: 90vh; border-radius: 8px; }

.toast {
  position: fixed; left: 50%; bottom: 40px; transform: translateX(-50%);
  background: rgba(43,39,35,.92); color: #fff; padding: 10px 20px;
  border-radius: 20px; font-size: 14px; z-index: 60;
}

@media (max-width: 640px) {
  .topbar { padding: 12px 14px; }
  .main { padding: 12px 14px 30px; }
  .tabs { padding: 0 14px; }
  .search { min-width: 130px; }
  .tree-wrap { height: calc(100vh - 300px); }
  .site-title { font-size: 18px; }
}

/* ---------- 首页门户 ---------- */
.home-hero {
  background: linear-gradient(135deg, var(--card), var(--paper-2));
  border: 1px solid var(--line); border-radius: 14px;
  padding: 30px 26px; text-align: center; margin-bottom: 18px;
}
.home-family { font-size: 28px; margin: 0 0 6px; letter-spacing: 8px; color: var(--red); }
.home-sub { color: var(--ink-2); margin: 0 0 16px; font-size: 14px; }
.home-form-link { text-decoration: none; margin-left: 8px; display: inline-block; }
.stat-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(110px, 1fr)); gap: 10px; margin-bottom: 18px; }
.stat-card {
  background: var(--card); border: 1px solid var(--line); border-radius: 12px;
  text-align: center; padding: 16px 8px;
}
.stat-num { font-size: 26px; color: var(--red); }
.stat-label { font-size: 12px; color: var(--ink-3); margin-top: 4px; }
.home-intro { display: grid; grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); gap: 10px; margin-bottom: 18px; }
.intro-card { background: var(--card); border: 1px solid var(--line); border-radius: 12px; padding: 16px 18px; }
.intro-card h3 { margin: 0 0 8px; font-size: 15px; color: var(--red); }
.intro-card p { margin: 0; font-size: 13px; line-height: 1.9; color: var(--ink-2); }
.home-section { margin-bottom: 22px; }
.home-h3 { font-size: 15px; color: var(--red); border-left: 3px solid var(--red); padding-left: 10px; margin: 0 0 12px; }
.lineage { background: var(--card); border: 1px solid var(--line); border-radius: 12px; padding: 14px 16px; font-size: 15px; line-height: 2.2; }
.lineage-node { color: var(--ink); cursor: pointer; border-bottom: 1px dashed var(--ink-3); padding-bottom: 2px; }
.lineage-node:hover { color: var(--red); border-color: var(--red); }
.lineage-arrow { color: var(--ink-3); margin: 0 8px; }
.lineage-multi { border-bottom: none; color: var(--ink-2); font-size: 14px; cursor: default; }
.home-zibei { display: flex; flex-wrap: wrap; gap: 10px; }
.zibei-chip {
  background: var(--card); border: 1px solid var(--line); border-radius: 10px;
  min-width: 52px; text-align: center; padding: 10px 12px; font-size: 20px;
  letter-spacing: 0; cursor: pointer;
}
.zibei-chip:hover { border-color: var(--red-soft); color: var(--red); }

/* 名录筛选 */
.filter-bar { display: flex; gap: 8px; margin-bottom: 14px; flex-wrap: wrap; }
.filter {
  padding: 8px 10px; border: 1px solid var(--line); border-radius: 8px;
  background: #fff; font-size: 13px; font-family: inherit; color: var(--ink);
}

/* ---------- 族记式成员卡 ---------- */
.member-overlay {
  position: fixed; inset: 0; background: rgba(60, 50, 40, .55); z-index: 70;
  display: flex; align-items: center; justify-content: center; padding: 16px;
  overflow-y: auto;
}
.member-stage { width: min(640px, 96vw); }
.rel-row { display: flex; justify-content: center; gap: 14px; }
.rel-mid { display: flex; align-items: center; justify-content: center; gap: 14px; }
.rel-right { display: flex; flex-direction: column; gap: 14px; }
.rel-btn {
  width: 84px; padding: 8px 6px; border: 1px solid var(--line); border-radius: 10px;
  background: #fff; cursor: pointer; font-family: inherit; font-size: 12px; color: var(--ink-2);
  display: flex; flex-direction: column; align-items: center; gap: 4px; position: relative;
  box-shadow: var(--shadow);
}
.rel-btn:hover { transform: translateY(-1px); }
.rel-btn.male { background: #eef3f8; border-color: #cdd9e6; }
.rel-btn.female { background: #f8f0f2; border-color: #e4d0d6; }
.rel-btn.dim { opacity: .45; }
.rel-plus {
  position: absolute; top: -7px; left: -7px; width: 18px; height: 18px; border-radius: 50%;
  background: var(--red); color: #fff; font-size: 13px; line-height: 18px; text-align: center;
}
.rel-avatar { width: 34px; height: 34px; border-radius: 8px; }
.rel-btn.male .rel-avatar { background: linear-gradient(#a8c4e0, #87a8c8); }
.rel-btn.female .rel-avatar { background: linear-gradient(#e8c8d0, #d0a8b4); }
.member-card2 {
  background: #fff; border-radius: 12px; box-shadow: 0 8px 30px rgba(40,30,20,.25);
  width: min(320px, 86vw); overflow: hidden; flex-shrink: 0;
}
.mc-head { display: flex; gap: 12px; padding: 16px 16px 10px; }
.mc-avatar {
  width: 64px; height: 64px; border-radius: 10px; flex-shrink: 0;
  display: flex; align-items: center; justify-content: center;
  font-size: 26px; color: #fff;
}
.mc-avatar.male { background: linear-gradient(#a8c4e0, #87a8c8); }
.mc-avatar.female { background: linear-gradient(#e8c8d0, #d0a8b4); }
.mc-avatar-img { width: 100%; height: 100%; border-radius: 10px; object-fit: cover; }
.mc-photos { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 6px; }
.mc-photo { width: 72px; height: 72px; border-radius: 8px; object-fit: cover; cursor: pointer; border: 1px solid var(--line); }
.upload-preview { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 8px; }
.preview-item { position: relative; width: 64px; height: 64px; }
.preview-item img { width: 100%; height: 100%; border-radius: 8px; object-fit: cover; border: 1px solid var(--line); }
.preview-del {
  position: absolute; top: -6px; right: -6px; width: 20px; height: 20px;
  border-radius: 50%; background: #e53935; color: #fff; border: none;
  font-size: 14px; line-height: 1; cursor: pointer; display: flex; align-items: center; justify-content: center;
}
.mc-headinfo { flex: 1; }
.mc-name { font-size: 20px; }
.mc-gender { font-size: 13px; color: var(--ink-2); margin-top: 6px; display: flex; align-items: center; gap: 8px; }
.mc-tag {
  background: #f0ebe0; color: #8a7a5c; font-size: 11px; border-radius: 4px;
  padding: 2px 6px;
}
.mc-fields { padding: 4px 16px 10px; }
.mc-row { font-size: 13px; padding: 7px 0; border-bottom: 1px dashed var(--line); color: var(--ink); }
.mc-k { color: var(--ink-3); }
.mc-link { color: var(--red); cursor: pointer; }
.mc-link:hover { text-decoration: underline; }
.mc-actions { display: flex; border-top: 1px solid var(--line); }
.mc-actions button {
  flex: 1; padding: 11px 0; background: none; border: none; cursor: pointer;
  font-size: 14px; color: var(--ink); font-family: inherit;
}
.mc-actions button + button { border-left: 1px solid var(--line); }
.mc-actions button:hover { background: var(--paper-2); color: var(--red); }

/* 表单浮层 */
.form-overlay {
  position: fixed; inset: 0; background: rgba(60, 50, 40, .55); z-index: 80;
  display: flex; align-items: center; justify-content: center; padding: 16px;
}
.form-card {
  background: #fff; border-radius: 14px; padding: 22px;
  width: min(400px, 94vw); max-height: 92vh; overflow-y: auto;
}
.form-title { margin: 0 0 4px; font-size: 18px; color: var(--red); }
.form-sub { margin: 0 0 14px; font-size: 12px; color: var(--ink-3); }
.form-label { display: block; font-size: 13px; color: var(--ink-2); margin-bottom: 10px; }
.form-label .req { color: var(--red); }
.form-input {
  width: 100%; margin-top: 4px; padding: 9px 10px; font-size: 14px;
  border: 1px solid var(--line); border-radius: 8px; font-family: inherit;
  background: #fff; color: var(--ink);
}
.form-input:focus { outline: none; border-color: var(--red-soft); }
.form-textarea { resize: none; overflow: hidden; min-height: 38px; line-height: 1.5; }
.form-err { color: var(--red); font-size: 13px; min-height: 16px; margin: 6px 0; }
.form-hint { display: block; margin-top: 6px; font-size: 12px; color: var(--ink-2); line-height: 1.5; }
.form-hint:empty { display: none; }
/* 可搜索的人员下拉：输入框本身即搜索框，下方浮出匹配名单 */
.combo-label { position: relative; }
.combo-wrap { position: relative; display: block; }
.combo-search { cursor: text; }
.combo-panel {
  display: block; position: absolute; left: 0; right: 0; top: 100%; margin-top: -2px;
  max-height: 232px; overflow-y: auto; z-index: 5;
  background: #fff; border: 1px solid var(--line); border-radius: 8px;
  box-shadow: 0 8px 20px rgba(60, 50, 40, .16); padding: 4px;
}
.combo-item {
  display: flex; flex-direction: column; gap: 1px;
  padding: 7px 9px; border-radius: 6px; cursor: pointer; font-size: 14px; color: var(--ink);
}
.combo-item:hover, .combo-item.active { background: var(--bg-soft, #f3ece0); }
.combo-item.combo-clear { color: var(--ink-2); font-size: 13px; }
.combo-sub { font-size: 12px; color: var(--ink-2); }
.combo-empty { padding: 10px; font-size: 13px; color: var(--ink-2); text-align: center; }
.form-actions { display: flex; gap: 10px; justify-content: flex-end; margin-top: 8px; }
.primary-btn {
  padding: 9px 22px; background: var(--red); color: #fff; border: none;
  border-radius: 8px; cursor: pointer; font-size: 14px; font-family: inherit;
  text-decoration: none; display: inline-block;
}
.primary-btn:hover { background: #8a251e; }
.primary-btn:disabled { opacity: .6; cursor: default; }

@media (max-width: 640px) {
  .rel-btn { width: 72px; min-height: 56px; font-size: 11px; }
  .member-stage { width: 100%; }
  .rel-mid { flex-wrap: wrap; }
  .rel-right { flex-direction: row; }
  /* 输入框字体≥16px，避免iOS自动缩放 */
  .form-input, .search, .filter, .login-input { font-size: 16px; }
  /* 按钮触摸区域≥44px */
  .ghost-btn, .primary-btn, .mc-actions button { min-height: 44px; font-size: 14px; }
  /* 成员详情卡移动端更宽 */
  .member-card2 { width: min(360px, 94vw); }
  .mc-avatar { width: 56px; height: 56px; font-size: 22px; }
  .mc-name { font-size: 18px; }
  /* 个人详情面板全宽 */
  .panel { width: 100vw; padding: 16px; }
  .panel-avatar { width: 64px; height: 64px; }
  .panel-avatar-char { font-size: 26px; }
  .panel-name { font-size: 20px; }
  .panel-grid { grid-template-columns: 1fr; }
  /* 谱树容器移动端更高 */
  .tree-wrap { height: calc(100vh - 280px); min-height: 360px; }
  /* 顶部导航紧凑 */
  .tabs button { padding: 10px 14px; font-size: 14px; }
  .site-title { font-size: 17px; }
  .stats { font-size: 11px; }
  /* 首页 */
  .home-family { font-size: 22px; letter-spacing: 4px; }
  .stat-num { font-size: 22px; }
  .member-grid { grid-template-columns: repeat(auto-fill, minmax(130px, 1fr)); }
  /* 待挂接区 */
  .loose-chip { padding: 8px 10px 8px 14px; font-size: 14px; }
  .loose-del { width: 24px; height: 24px; font-size: 16px; }
  /* 表单 */
  .form-card { padding: 16px; width: 96vw; max-height: 94vh; }
  .form-label { font-size: 14px; }
  /* 照片预览 */
  .panel-photo { width: 70px; height: 70px; }
  .mini-person { min-width: 100%; padding: 8px 10px; }
}

/* ===== 首页可编辑配置 ===== */
.section-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 10px;
}
.edit-config-btn {
  font-size: 12px;
  padding: 3px 10px;
  border: 1px solid #c8b89a;
  background: #fff;
  color: #8a7a5c;
  border-radius: 4px;
  cursor: pointer;
  transition: all 0.2s;
}
.edit-config-btn:hover {
  background: #f5efe4;
  border-color: #a89878;
}
.edit-config-btn.small {
  font-size: 11px;
  padding: 2px 8px;
}
.config-hint {
  font-size: 11px;
  color: #b0a090;
  font-style: italic;
}
.home-motto .motto-content {
  font-size: 15px;
  line-height: 1.8;
  color: #5a4a3a;
  text-align: center;
  padding: 16px 20px;
  background: linear-gradient(135deg, #fdf8f0 0%, #f8f0e0 100%);
  border-left: 3px solid #c8a96e;
  border-radius: 6px;
  font-style: italic;
}
.home-origin .origin-content {
  font-size: 14px;
  line-height: 1.8;
  color: #5a4a3a;
  padding: 12px 16px;
  background: #fdfaf5;
  border-radius: 6px;
  margin-bottom: 12px;
}
.lineage-mini {
  font-size: 13px;
  color: #8a7a5c;
  padding: 8px 0;
}
.empty-hint {
  color: #b0a090;
  font-style: italic;
}

/* 制作信息 */
.home-credits {
  margin-top: 24px;
  padding-top: 20px;
  border-top: 1px dashed #d8c8a8;
}
.credits-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
  margin-bottom: 16px;
}
.credit-item {
  text-align: center;
  padding: 12px;
  background: #fdfaf5;
  border-radius: 8px;
}
.credit-label {
  font-size: 12px;
  color: #a09070;
  margin-bottom: 4px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
}
.credit-value {
  font-size: 16px;
  font-weight: 600;
  color: #5a4a3a;
  margin-bottom: 6px;
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  justify-content: center;
}
.credit-name {
  display: inline-block;
  padding: 2px 10px;
  background: #f0e8d8;
  border-radius: 12px;
  font-size: 14px;
  color: #6b5a4a;
}
.credit-changelog {
  padding: 12px 16px;
  background: #fdfaf5;
  border-radius: 8px;
}
.changelog-content {
  font-size: 13px;
  line-height: 1.7;
  color: #6b6156;
}

/* 配置编辑弹窗 */
.config-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.4);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  backdrop-filter: blur(2px);
}
.config-modal {
  background: #fff;
  border-radius: 12px;
  padding: 24px;
  width: 90%;
  max-width: 480px;
  box-shadow: 0 12px 40px rgba(0,0,0,0.15);
}
.config-title {
  font-size: 18px;
  font-weight: 600;
  color: #3a3028;
  margin-bottom: 16px;
}
.config-input, .config-textarea {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid #d8c8a8;
  border-radius: 6px;
  font-size: 14px;
  color: #3a3028;
  background: #fdfaf5;
  box-sizing: border-box;
  font-family: inherit;
}
.config-textarea {
  min-height: 120px;
  resize: vertical;
  line-height: 1.6;
}
.config-input:focus, .config-textarea:focus {
  outline: none;
  border-color: #a89060;
  box-shadow: 0 0 0 2px rgba(168,144,96,0.15);
}
.config-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  margin-top: 16px;
}

/* ===== 谱书打印（生成族谱PDF） ===== */
/* 谱书排版：平时 #printBook 隐藏，仅打印或测量页码时显示。
   版式样式作用到 #printBook 作用域（打印与屏幕测量共用），保证测量出的页码与打印一致。 */
#printBook {
  display: none;
  font-family: "Songti SC", "SimSun", "Noto Serif CJK SC", "Source Han Serif SC", serif;
  color: #1a1a1a;
  font-size: 12pt;
  line-height: 1.7;
}
/* 测量页码时临时在屏幕外渲染，复用与打印一致的排版（A4 内容宽度 182mm） */
#printBook.measuring {
  display: block !important;
  position: fixed;
  left: -10000px;
  top: 0;
  width: 182mm;
  background: #fff;
}
#printBook .book-cover {
  break-after: page;
  page-break-after: always;
  text-align: center;
  padding-top: 55mm;
}
#printBook .book-toc {
  break-after: page;
  page-break-after: always;
}
#printBook .book-chapter {
  break-before: page;
  page-break-before: always;
}
#printBook .gen-block, #printBook .bm-detail, #printBook .bb-row, #printBook .bz,
#printBook .book-prose, #printBook .book-lineage, #printBook .bm-line {
  break-inside: avoid;
  page-break-inside: avoid;
}
#printBook .book-title {
  font-size: 28pt;
  letter-spacing: 8px;
  margin-bottom: 12mm;
}
#printBook .book-sub {
  font-size: 14pt;
  color: #555;
  margin-bottom: 10mm;
}
#printBook .book-stats {
  font-size: 12pt;
  margin-bottom: 8mm;
}
#printBook .book-make {
  font-size: 11pt;
  color: #555;
  margin-bottom: 4mm;
}
#printBook .book-date {
  font-size: 10pt;
  color: #888;
}
#printBook .book-h2 {
  font-size: 18pt;
  border-bottom: 2px solid #8a251e;
  padding-bottom: 6px;
  margin: 0 0 8mm;
  color: #8a251e;
}
#printBook .book-h3 {
  font-size: 14pt;
  margin: 8mm 0 3mm;
  color: #333;
}
#printBook .toc-list {
  list-style: none;
  padding: 0;
  font-size: 13pt;
}
#printBook .toc-list li {
  margin: 5mm 0;
}
#printBook .toc-list a {
  color: #1a1a1a;
  text-decoration: none;
  display: flex;
  align-items: baseline;
}
#printBook .toc-label {
  white-space: nowrap;
}
#printBook .toc-dots {
  flex: 1 1 auto;
  border-bottom: 1px dotted #999;
  margin: 0 6px;
  transform: translateY(-4px);
}
#printBook .toc-page {
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
}
#printBook .book-prose {
  white-space: normal;
}
#printBook .book-zibei {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}
#printBook .bz {
  display: inline-block;
  padding: 4px 14px;
  border: 1px solid #c8a96e;
  border-radius: 4px;
  font-size: 13pt;
}
#printBook .book-branch {
  margin-top: 4mm;
}
#printBook .bb-row {
  display: flex;
  justify-content: space-between;
  border-bottom: 1px dotted #ccc;
  padding: 4px 0;
}
#printBook .gen-block {
  margin-bottom: 4mm;
}
#printBook .bm-line {
  margin: 2px 0;
}
#printBook .bm-name {
  font-weight: 700;
  margin-right: 8px;
}
#printBook .bm-gen, #printBook .bm-branch, #printBook .bm-life, #printBook .bm-reside, #printBook .bm-zibei {
  color: #444;
  margin-right: 10px;
  font-size: 11pt;
}
#printBook .bm-detail {
  border: 1px solid #e0d8c8;
  border-radius: 6px;
  padding: 6px 12px;
  margin: 4px 0;
}
#printBook .bm-d-name {
  font-size: 13pt;
  font-weight: 700;
  margin-bottom: 2px;
}
#printBook .bm-d-meta, #printBook .bm-d-life, #printBook .bm-d-reside {
  font-size: 11pt;
  color: #444;
  margin: 1px 0;
}
#printBook .bm-d-rel {
  font-size: 11pt;
  color: #333;
  margin: 2px 0;
  display: flex;
  flex-wrap: wrap;
  gap: 4px 16px;
}
#printBook .bm-d-bio {
  font-size: 11pt;
  color: #222;
  margin-top: 4px;
}
#printBook .empty {
  color: #999;
}
#printBook .lineage-node {
  color: #1a1a1a;
}
#printBook .lineage-arrow {
  margin: 0 6px;
  color: #999;
}
#printBook a {
  color: #1a1a1a;
}

@media print {
  @page {
    size: A4;
    margin: 16mm 14mm;
  }
  html, body {
    background: #fff !important;
    color: #000 !important;
  }
  /* 隐藏所有交互界面，只保留谱书区域 */
  #app, #login, #toast,
  #panel, #panelMask, #memberOverlay, #formOverlay, #kinWindowOverlay {
    display: none !important;
  }
  #printBook {
    display: block !important;
  }
}
