:root {
  --bg: #f5f1e8;
  --card: #fffdf8;
  --ink: #2b2620;
  --muted: #8a7f6e;
  --line: #e4dccb;
  --accent: #9c6b3f;
  --accent2: #3f6b9c;
  --self: #c49b2a;
}
* { box-sizing: border-box; }
body {
  margin: 0;
  font-family: "PingFang SC", "Microsoft YaHei", system-ui, sans-serif;
  background: var(--bg);
  color: var(--ink);
  line-height: 1.6;
}
header.top {
  background: linear-gradient(135deg, #6b4a2b, #9c6b3f);
  color: #fff;
  padding: 22px 18px;
  text-align: center;
  position: relative;
}
/* 右上角操作区：寿星开关 + 导出按钮，横排对齐 */
.top-actions {
  position: absolute; top: 16px; right: 18px;
  display: flex; flex-direction: column; align-items: flex-end; gap: 10px;
}
/* 导出族谱图按钮，风格与搜索框按钮一致 */
.export-btn {
  padding: 6px 14px; border-radius: 20px;
  border: 1px solid rgba(255,255,255,.5); background: rgba(255,255,255,.12);
  color: #fff; font-size: 13px; cursor: pointer; transition: .15s;
}
.export-btn:hover:not(:disabled) { background: rgba(255,255,255,.28); }
.export-btn:disabled { opacity: .6; cursor: progress; }
header.top h1 { margin: 0; font-size: 26px; letter-spacing: 4px; }
header.top p { margin: 6px 0 0; opacity: .85; font-size: 13px; }
nav.tabs { display: flex; gap: 8px; justify-content: center; margin-top: 12px; }
nav.tabs a, nav.tabs button {
  color: #fff; text-decoration: none; border: 1px solid rgba(255,255,255,.4);
  padding: 5px 14px; border-radius: 20px; font-size: 13px; background: transparent; cursor: pointer;
}
nav.tabs a:hover, nav.tabs button:hover { background: rgba(255,255,255,.15); }
.wrap { max-width: 960px; margin: 0 auto; padding: 18px; }

.branch { margin: 22px 0; }
.branch > h2 {
  font-size: 18px; border-left: 4px solid var(--accent); padding-left: 10px; margin: 0 0 12px;
}
.gens { display: flex; flex-direction: column; gap: 14px; }
.gen-row { }
.gen-row .glabel {
  font-size: 12px; color: var(--muted); margin-bottom: 6px;
}
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(120px, 1fr)); gap: 12px; }

.card {
  background: var(--card); border: 1px solid var(--line); border-radius: 12px;
  padding: 10px; text-align: center; cursor: pointer; transition: .15s;
  position: relative;
}
.card:hover { transform: translateY(-3px); box-shadow: 0 6px 16px rgba(0,0,0,.08); border-color: var(--accent); }
.card.self { border-color: var(--self); box-shadow: 0 0 0 2px rgba(196,155,42,.2); }
.card .no { position: absolute; top: 6px; left: 8px; font-size: 11px; color: var(--muted); }
.card img {
  width: 64px; height: 64px; border-radius: 50%; object-fit: cover; background: #e9e2d2;
  display: block; margin: 4px auto 8px;
}
.card .avatar {
  width: 64px; height: 64px; border-radius: 50%; background: var(--accent); color: #fff;
  display: flex; align-items: center; justify-content: center; font-size: 16px; margin: 4px auto 8px;
  text-align: center; line-height: 1.1; padding: 4px; box-sizing: border-box; word-break: break-all;
}
.card .nm { font-size: 14px; font-weight: 600; }
.card .rel { font-size: 11px; color: var(--accent2); margin-top: 2px; }
.card .rel.inf { color: var(--muted); }
.card .flag {
  position: absolute; top: 6px; right: 8px; font-size: 11px; color: var(--self);
}

/* 详情弹窗 */
.overlay {
  position: fixed; inset: 0; background: rgba(0,0,0,.5); display: none;
  align-items: center; justify-content: center; padding: 16px; z-index: 50;
}
.overlay.show { display: flex; }
.modal {
  background: var(--card); border-radius: 16px; max-width: 460px; width: 100%;
  max-height: 90vh; overflow: auto; padding: 22px; position: relative;
}
.modal .close { position: absolute; top: 12px; right: 14px; font-size: 24px; cursor: pointer; color: var(--muted); border: none; background: none; }
.modal .mhead { display: flex; gap: 16px; align-items: center; margin-bottom: 14px; }
.modal .mhead img { width: 88px; height: 88px; border-radius: 50%; object-fit: cover; background: #e9e2d2; }
.modal .mhead .avatar { width: 88px; height: 88px; border-radius: 50%; background: var(--accent); color: #fff; display: flex; align-items: center; justify-content: center; font-size: 24px; text-align: center; line-height: 1.1; padding: 6px; box-sizing: border-box; word-break: break-all; }
.modal .mhead h3 { margin: 0; font-size: 22px; }
.modal .mhead .sub { color: var(--muted); font-size: 13px; }
.modal .mrel { background: #f0ece1; border-radius: 10px; padding: 8px 12px; font-size: 14px; margin-bottom: 12px; }
.modal .mrel b { color: var(--accent2); }
.kv { display: flex; border-bottom: 1px dashed var(--line); padding: 8px 0; font-size: 14px; }
.kv .k { width: 84px; color: var(--muted); flex: none; }
.kv .v { flex: 1; }
.links { display: flex; flex-wrap: wrap; gap: 6px; }
.chip {
  background: #f0ece1; border: 1px solid var(--line); border-radius: 14px;
  padding: 2px 10px; font-size: 13px; cursor: pointer; color: var(--ink);
}
.chip:hover { border-color: var(--accent); color: var(--accent); }
.bio { white-space: pre-wrap; }
.rev { color: var(--self); font-size: 12px; }
.modal .setself-btn {
  display: block; width: 100%; margin: -4px 0 14px; padding: 10px 12px;
  background: var(--accent); color: #fff; border: none; border-radius: 10px;
  font-size: 14px; font-weight: 600; cursor: pointer;
}
.modal .setself-btn:hover { background: var(--accent2); }
.self-drop .item.clear { color: var(--muted); justify-content: center; border-top: 1px dashed var(--line); margin-top: 2px; }
footer { text-align: center; color: var(--muted); font-size: 12px; padding: 24px; }

/* 搜索框 */
.self-pick {
  margin-top: 10px; position: relative; display: inline-block;
}
.self-pick label {
  font-size: 13px; opacity: .85;
}
.self-pick input {
  padding: 6px 12px; border-radius: 20px; border: 1px solid rgba(255,255,255,.5);
  background: rgba(255,255,255,.15); color: #fff; font-size: 13px; width: 200px;
  outline: none; transition: .2s;
}
.self-pick input::placeholder { color: rgba(255,255,255,.5); }
.self-pick input:focus { border-color: #fff; background: rgba(255,255,255,.25); }
.self-pick .clear-self {
  margin-left: 8px; padding: 6px 14px; border-radius: 20px;
  border: 1px solid rgba(255,255,255,.5); background: rgba(255,255,255,.12);
  color: #fff; font-size: 13px; cursor: pointer; transition: .15s;
}
.self-pick .clear-self:hover:not(:disabled) { background: rgba(255,255,255,.28); }
.self-pick .clear-self:disabled { opacity: .4; cursor: not-allowed; }
.self-drop {
  position: absolute; top: 100%; left: 0; right: 0; background: #fff; color: var(--ink);
  border-radius: 8px; box-shadow: 0 4px 16px rgba(0,0,0,.15); max-height: 200px;
  overflow: auto; display: none; z-index: 100; margin-top: 4px;
}
.self-drop.show { display: block; }
.self-drop .item {
  padding: 8px 12px; cursor: pointer; font-size: 14px; border-bottom: 1px solid var(--line);
  display: flex; justify-content: space-between;
}
.self-drop .item:hover { background: #f0ece1; }
.self-drop .item .sname { font-weight: 600; }
.self-drop .item .sinfo { color: var(--muted); font-size: 12px; }
.self-drop .empty { padding: 10px 12px; color: var(--muted); font-size: 13px; text-align: center; }

/* 家族树 */
.tree-scroll { overflow-x: auto; overflow-y: visible; padding: 20px 0 10px 0; }
@media (max-width: 768px) {
  .tree-scroll { overflow-x: hidden; }
  /* 手机端：本月寿星、导出族谱图 换到"我是谁/重置称呼"下一行，避免挤连 */
  .top-actions {
    position: static;
    flex-direction: row;
    align-items: center;
    flex-wrap: wrap;
    gap: 12px;
    margin-top: 10px;
  }
}
.tree-wrap { position: relative; margin: 0 auto; }
.tree-svg { position: absolute; left: 0; top: 0; z-index: 2; overflow: visible; }
.tree-svg .ln-child { stroke: #c4a87c; stroke-width: 2.5; fill: none; stroke-dasharray: 6 4; }
.tree-svg .ln-marry { stroke: #9c6b3f; stroke-width: 2.5; fill: none; stroke-dasharray: 6 4; }
.tree-svg .ln-label { fill: var(--muted); font-size: 12px; font-family: inherit; text-anchor: middle; dominant-baseline: middle; paint-order: stroke; stroke: #fffdf8; stroke-width: 4px; stroke-linejoin: round; }
.tnode {
  position: absolute; z-index: 3;
  background: #fffef9; border: 1.5px solid #d4c8b0; border-radius: 14px;
  padding: 10px 6px 8px; text-align: center; cursor: pointer; transition: .15s;
  box-shadow: 0 2px 6px rgba(0,0,0,.04);
}
.tnode:hover { transform: translateY(-3px); box-shadow: 0 8px 20px rgba(0,0,0,.1); border-color: var(--accent); }
.tnode.self { border-color: var(--self); border-width: 3px; transform: scale(1.18); box-shadow: 0 0 0 4px rgba(196,155,42,.25), 0 0 16px rgba(196,155,42,.18); z-index: 10; }
.tnode.self:hover { transform: scale(1.18) translateY(-3px); box-shadow: 0 8px 20px rgba(0,0,0,.1), 0 0 0 4px rgba(196,155,42,.3), 0 0 18px rgba(196,155,42,.22); }
.tnode .no { position: absolute; top: 4px; left: 6px; font-size: 10px; color: var(--muted); }
.tnode img {
  width: 64px; height: 64px; border-radius: 50%; object-fit: cover; background: #e9e2d2;
  display: block; margin: 2px auto 6px;
}
.tnode .avatar {
  width: 64px; height: 64px; border-radius: 50%; background: var(--accent); color: #fff;
  display: flex; align-items: center; justify-content: center; font-size: 16px; margin: 2px auto 6px;
  text-align: center; line-height: 1.1; padding: 4px; box-sizing: border-box; word-break: break-all;
}
.tnode .nm { font-size: 14px; font-weight: 600; line-height: 1.2; }
.tnode .rel { font-size: 11px; color: var(--accent2); margin-top: 2px; }
.tnode .rel.inf { color: var(--muted); }
.tnode .bday { font-size: 11px; color: var(--muted); margin-top: 2px; line-height: 1.2; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.tnode .bday .lunar { color: #c0392b; font-size: 10px; }
/* 本月寿星生日帽 */
.tnode .bday-hat {
  position: absolute; top: -14px; left: 50%; transform: translateX(-50%);
  font-size: 22px; z-index: 3; pointer-events: none; line-height: 1;
  filter: drop-shadow(0 1px 2px rgba(0,0,0,.2));
}
/* 设为「我」后定位高亮 */
@keyframes focusFlash {
  0%   { box-shadow: 0 0 0 0 rgba(196,155,42,.0), 0 0 0 0 rgba(196,155,42,.55); }
  25%  { box-shadow: 0 0 0 6px rgba(196,155,42,.55), 0 0 22px rgba(196,155,42,.35); }
  100% { box-shadow: 0 0 0 0 rgba(196,155,42,.0), 0 0 0 0 rgba(196,155,42,.0); }
}
.tnode.focus-flash {
  animation: focusFlash 1.6s ease-out 1;
  border-color: var(--self);
  z-index: 20;
}

  animation: bdayBounce 1.5s ease-in-out infinite;
}
@keyframes bdayBounce {
  0%, 100% { transform: translateX(-50%) translateY(0); }
  50% { transform: translateX(-50%) translateY(-4px); }
}




/* 视图A：连线 */
.ln-marry.ln-a { stroke: #9c6b3f; stroke-width: 1.5; fill: none; stroke-dasharray: 6 4; }
.ln-child.ln-a { stroke: #c4a87c; stroke-width: 1.2; fill: none; stroke-dasharray: 6 4; }
.ln-label.ln-a { fill: #9c6b3f; font-size: 12px; font-family: inherit; font-weight: 600; text-anchor: middle; dominant-baseline: middle; paint-order: stroke; stroke: #fffdf8; stroke-width: 4px; stroke-linejoin: round; }

/* 夫妻底图 */
.couple-frame { position: absolute; z-index: 1; border: 2.5px solid #c9b896; border-radius: 14px; background: rgba(156,107,63,0.06); pointer-events: none; }

/* 本月寿星开关 */
.bday-toggle { display: flex; align-items: center; gap: 8px; }
.bday-toggle .toggle-label { font-size: 13px; opacity: 0.9; }
.toggle-switch { position: relative; display: inline-block; width: 40px; height: 22px; }
.toggle-switch input { opacity: 0; width: 0; height: 0; }
.toggle-slider { position: absolute; cursor: pointer; inset: 0; background: rgba(255,255,255,.3); border-radius: 22px; transition: .25s; }
.toggle-slider::before { content: ""; position: absolute; left: 3px; bottom: 3px; width: 16px; height: 16px; background: #fff; border-radius: 50%; transition: .25s; }
.toggle-switch input:checked + .toggle-slider { background: #c49b2a; }
.toggle-switch input:checked + .toggle-slider::before { transform: translateX(18px); }

/* 寿星弹窗 */
.bday-popup { position: fixed; left: 50%; top: 50%; transform: translate(-50%, -50%); background: #fffdf8; border-radius: 16px; box-shadow: 0 12px 40px rgba(0,0,0,.25); z-index: 10000; padding: 24px; min-width: 320px; max-width: 420px; max-height: 70vh; overflow-y: auto; }
.bday-popup h3 { margin: 0 0 16px; font-size: 18px; text-align: center; color: #9c6b3f; }
.bday-popup .bday-item { display: flex; justify-content: space-between; align-items: center; padding: 8px 12px; border-radius: 8px; margin-bottom: 4px; background: #faf6ed; }
.bday-popup .bday-name { font-weight: 600; }
.bday-popup .bday-date { color: #8a7f6e; font-size: 13px; }
.bday-popup .bday-lunar { color: #c0392b; font-size: 11px; margin-left: 4px; }
.bday-popup .bday-empty { text-align: center; color: #8a7f6e; padding: 12px; }
.bday-popup .bday-close { display: block; margin: 16px auto 0; padding: 8px 28px; border: none; border-radius: 20px; background: #9c6b3f; color: #fff; font-size: 14px; cursor: pointer; }
.bday-popup .bday-close:hover { background: #7a4f2a; }
.bday-overlay { position: fixed; inset: 0; background: rgba(0,0,0,.4); z-index: 9999; }

/* 前台主视图 Tab：族谱树 / 族谱表格 */
.main-tabs { display: flex; gap: 6px; justify-content: center; margin-top: 12px; }
.mtab {
  color: #fff; border: 1px solid rgba(255,255,255,.4);
  padding: 5px 18px; border-radius: 20px; font-size: 13px; background: transparent; cursor: pointer; transition: .15s;
}
.mtab:hover { background: rgba(255,255,255,.15); }
.mtab.active { background: #fff; color: #6b4a2b; font-weight: 600; border-color: #fff; }

/* 族谱表格（与后台"🌳 族谱"视图一致，只读同步） */
.table-view { max-width: 960px; margin: 0 auto; padding: 18px; overflow-x: auto; }
.table-view .tree-wrap { overflow-x: auto; }
.tree-table { border-collapse: collapse; width: 100%; table-layout: auto; }
.tree-table thead th { position: sticky; top: 0; z-index: 10; }
.tree-table th, .tree-table td {
  padding: 6px 10px; border: 1px solid #c8bfaa; font-size: 13px;
  text-align: center; vertical-align: middle; white-space: pre-line;
}
.tree-table .th-h { background: #1F4E79; color: #fff; font-weight: 700; }
.tree-table .th-h2 { background: #1F4E79; color: #fff; font-size: 12px; }
.tree-table .col-br { width: 70px; font-weight: 700; background: #f0ece1; }
.tree-table .anc-fill { background: #D9D9D9; }
.tree-table .g1-fill { background: #FFF2CC; }
.tree-table .g2-fill { background: #D9EAD3; }
.tree-table .g3-fill { background: #FCE4D6; }
.tree-name-link { cursor: pointer; text-decoration: underline; text-decoration-color: #3f6b9c; text-underline-offset: 3px; }
.tree-name-link:hover { color: #3f6b9c; background: #e8f0fe; border-radius: 3px; padding: 1px 4px; }

