#bgLayer {
  position: fixed;
  left: 50%;
  top: 64px;
  bottom: 20px;
  transform: translateX(-50%);
  width: min(1120px, calc(100% - 32px));
  border-radius: 20px;
  overflow: hidden;
  background-size: cover;
  background-position: center;
  background-repeat: no-repeat;
  z-index: 0;
  pointer-events: none;
  filter: blur(9px) saturate(1.12) brightness(1.14);
  transition: opacity .6s ease;
}
#bgLayer::after {
  content: '';
  position: absolute;
  inset: 0;
  background: linear-gradient(180deg, rgba(250,247,240,.30) 0%, rgba(250,247,240,.62) 55%, rgba(250,247,240,.92) 100%);
}
#bgLayer.off { opacity: 0; }


:root{
  --ink:#1f2328; --muted:#6b7280; --line:#e5e1d8; --paper:#faf7f0;
  --accent:#8a6b4f; --card:#fff; --shadow:0 2px 10px rgba(60,45,30,.08);
}
*{box-sizing:border-box}
html{background:var(--paper)}
body{
  margin:0;background:transparent;color:var(--ink);
  font:16px/1.7 "PingFang SC","Microsoft YaHei",system-ui,sans-serif;
}
header{
  position:sticky;top:0;z-index:20;background:rgba(250,247,240,.92);
  backdrop-filter:blur(8px);border-bottom:1px solid var(--line);
  padding:14px 18px 0;
}
h1{margin:0 0 10px;font-size:22px;letter-spacing:2px;font-weight:600;color:var(--accent)}
nav{display:flex;gap:6px}
.tab{
  border:0;background:transparent;padding:9px 16px;font-size:15px;color:var(--muted);
  cursor:pointer;border-bottom:2px solid transparent;
}
.tab.active{color:var(--ink);border-bottom-color:var(--accent);font-weight:600}
main{max-width:1080px;margin:0 auto;padding:20px 16px 60px}
.panel{display:none}
.panel.active{display:block}
.bar{display:flex;align-items:center;gap:12px;margin-bottom:18px;flex-wrap:wrap}
.btn{
  display:inline-flex;align-items:center;gap:6px;border:1px solid var(--accent);
  background:var(--accent);color:#fff;padding:8px 16px;border-radius:999px;
  font-size:14px;cursor:pointer;
}
.btn.ghost{background:transparent;color:var(--accent)}
.tip{color:var(--muted);font-size:13px}

/* 照片 */
.grid{display:grid;grid-template-columns:repeat(auto-fill,minmax(180px,1fr));gap:14px}
.card{
  background:var(--card);border-radius:12px;overflow:hidden;box-shadow:var(--shadow);
  cursor:pointer;transition:transform .15s;
}
.card:hover{transform:translateY(-2px)}
.card img{width:100%;height:150px;object-fit:cover;display:block;background:#eee}
.card .meta{padding:8px 10px;font-size:12px;color:var(--muted)}
.empty{color:var(--muted);text-align:center;padding:40px 0}

/* 灯箱 */
.lightbox{
  position:fixed;inset:0;background:rgba(20,16,12,.92);display:none;
  align-items:center;justify-content:center;flex-direction:column;z-index:50;padding:20px;
}
.lightbox.show{display:flex}
.lightbox img{max-width:92vw;max-height:82vh;border-radius:8px}
.lightbox .cap{color:#f0e8dc;margin-top:12px;font-size:14px}

/* 家谱 */
.tree-wrap{background:var(--card);border-radius:14px;box-shadow:var(--shadow);padding:10px;overflow:auto}
#treeSvg{display:block;width:100%;height:560px;touch-action:none;cursor:grab}
.node rect{fill:#fff;stroke:var(--accent);stroke-width:1.6;rx:8}
.node text{font-size:14px;fill:var(--ink);dominant-baseline:middle;text-anchor:middle;pointer-events:none}
.node.sel rect{stroke-width:3;fill:#fdf6ec}
.link{stroke:#c9bfae;stroke-width:1.6;fill:none}

/* 文档 */
.doc-list{display:grid;gap:14px}
.doc{background:var(--card);border-radius:12px;padding:16px 18px;box-shadow:var(--shadow)}
.doc h4{margin:0 0 6px;font-size:17px}
.doc .d{color:var(--muted);font-size:12px;margin-bottom:8px}
.doc p{margin:0;white-space:pre-wrap;color:#333}

/* 弹窗 */
.modal{position:fixed;inset:0;background:rgba(0,0,0,.45);display:none;align-items:center;justify-content:center;z-index:60;padding:16px}
.modal.show{display:flex}
.modal-box{background:#fff;border-radius:14px;padding:20px;width:min(560px,92vw)}
.modal-box h3{margin:0 0 12px;font-size:17px}
.modal-box input,.modal-box textarea{
  width:100%;border:1px solid var(--line);border-radius:8px;padding:10px;
  font:inherit;margin-bottom:10px;background:#fcfaf6;
}
.modal-actions{display:flex;justify-content:flex-end;gap:10px}
@media(max-width:600px){
  .card img{height:120px}
  h1{font-size:19px}
}

/* 家谱：禁止选中文字（否则拖动变选字） */
#treeSvg text, #treeSvg rect { user-select: none; -webkit-user-select: none; -ms-user-select: none; }
#treeSvg { touch-action: none; }
#treeBar { flex-wrap: wrap; gap: 8px; }
#treeBar select {
  font: inherit; padding: 4px 8px; border-radius: 6px;
  border: 1px solid #d8cbb6; background: #fff; color: #4b3b2a;
}
.link.spouse { stroke: #c9a86a; stroke-width: 3; }

/* ---- 背景图层 ---- */
html { background: #faf7f0; }
body.has-bg body.has-bg header, body.has-bg main, body.has-bg .wrap, body.has-bg .tabs {
  position: relative; z-index: 1;
}

/* ---- 音乐按钮 ---- */
button.music {
  position: fixed; right: 22px; bottom: 22px; z-index: 60;
  width: 46px; height: 46px; border-radius: 50%;
  border: 1px solid #d8c9b0; background: #fff8ec; color: #8a6a45;
  font-size: 20px; cursor: pointer; box-shadow: 0 4px 14px rgba(120,90,60,.18);
}
button.music.playing { background: #8a6a45; color: #fff8ec; border-color: #8a6a45; }
button.music:hover { transform: translateY(-1px); }
/* 有背景时，内容卡片半透明，让照片透出来 */
body.has-bg .tree-wrap,
body.has-bg .panel > .card,
body.has-bg .doc-list {
  background: rgba(255,252,246,.84);
  backdrop-filter: blur(3px);
}
/* 照片卡片上的删除按钮 */
.card { position: relative; }
.card .del {
  position: absolute; top: 6px; right: 6px;
  width: 26px; height: 26px; line-height: 22px;
  border: none; border-radius: 50%;
  background: rgba(40,32,26,.55); color: #fff;
  font-size: 17px; cursor: pointer; padding: 0;
  opacity: .5; transition: opacity .15s, background .15s;
}
.card:hover .del { opacity: 1; }
.card .del:hover { background: #b23b3b; }
@media (hover: none) { .card .del { opacity: .85; } }
/* ===== 背景图层（最终版：限制在站内宽度，轻虚化） ===== */
body.has-bg body.has-bg header, body.has-bg main { position: relative; z-index: 1; }
body.has-bg { background: #f3ede2; }
/* 背景开关按钮 */
button.bgtog {
  margin-left: auto;
  border: 1px solid #d8c9b0; background: #fff8ec; color: #8a6a45;
  border-radius: 999px; padding: 6px 14px; font-size: 13px; cursor: pointer;
}
button.bgtog:hover { background: #f6ecdb; }
/* 顶栏排成一行：标题 / 标签 / 背景开关 */
header { display: flex; align-items: center; gap: 18px; flex-wrap: wrap; }
header h1 { margin: 0; }
header nav { margin: 0; }
button.bgtog { margin-left: auto; margin-top: 0; }
/* ================= 照片描述 ================= */
.card .meta { display: flex; flex-direction: column; gap: 2px; }
.card .meta b { font-weight: 600; color: #4b3b2a; font-size: 13px; }
.card .meta span { color: #8a7a66; font-size: 12px; }

.cap { display: flex; flex-direction: column; align-items: center; gap: 8px; }
.lb-title { font-weight: 600; font-size: 17px; color: #fff; text-align: center; }
.lb-note {
  max-width: 640px; color: #e8e0d4; font-size: 14px; line-height: 1.7;
  text-align: center; white-space: pre-wrap;
}
.lb-time { color: #b9ab9a; font-size: 12px; }
.lb-edit { margin-top: 6px; }

#metaModal textarea { margin-top: 10px; }
/* 大图页：图片限高 + 说明区留白 */
#lightbox { display: none; }
#lightbox.show { display: flex; flex-direction: column; align-items: center; justify-content: center; padding: 24px 16px; overflow-y: auto; }
#lightbox img { max-height: 62vh; max-width: 92vw; width: auto; border-radius: 10px; }
#lightbox .cap { margin-top: 14px; padding-bottom: 18px; }
/* 内容层压在背景层之上 */
header, main { position: relative; z-index: 1; }

/* ===== 只读版：隐藏所有编辑入口 ===== */
body.readonly #photos .bar,
body.readonly #addPerson,
body.readonly #editMode,
body.readonly #newDoc,
body.readonly #lbEdit,
body.readonly .card .del,
body.readonly #treeBar { display: none !important; }
.readonly-note {
  margin: 22px 0 10px; max-width: 560px; padding: 8px 14px;
  color: #7c6f5e; font-size: 13px; line-height: 1.6;
  background: rgba(255,252,246,.86); border: 1px solid rgba(180,160,130,.28);
  border-radius: 10px;
}
