:root {
    --dai-blue: #8E6F4D;
    --line-color: #8E6F4D;
    --bg-color: #F8F6F2;
    --accent-color: #C23A37;
    --rice-paper: #F9F7F2;
}

body, html {
    margin: 0; padding: 0; width: 100%; height: 100%;
    background-color: var(--bg-color);
    font-family: "KaiTi", "STKaiti", "BiauKai", "楷体", serif;
    color: #4A3B32;
    overflow: hidden;
}

/* --- 导航与搜索 --- */
.top-nav-area {
    position: fixed;
    top: 0; left: 0; right: 0;
    background: linear-gradient(to bottom, rgba(249, 247, 242, 1) 80%, rgba(249, 247, 242, 0));
    z-index: 1000; padding: 15px;
}

.search-bar {
    width: 90%; margin: 0 auto;
    background: rgba(255, 255, 255, 0.9);
    height: 32px; border-radius: 16px;
    display: flex; align-items: center; padding: 0 15px;
    box-shadow: 0 2px 8px rgba(0,0,0,0.08);
    border: 1px solid #eee;
    position: relative;
    box-sizing: border-box; /* 核心：防止宽度溢出 */
}

.search-input { flex: 1; border: none; outline: none; font-size: 13px; margin-left: 8px; background: transparent; color: #4A3B32; }

.search-results {
    position: absolute; top: 40px; left: 0; right: 0;
    background: white; border-radius: 10px; max-height: 200px;
    box-shadow: 0 5px 15px rgba(0,0,0,0.15);
    z-index: 1000; border: 1px solid #eee;
    overflow-y: auto; display: none;
}
.search-item { padding: 12px 15px; border-bottom: 1px solid #f5f5f5; display: flex; flex-direction: column; align-items: center; cursor: pointer; }
.search-item:active { background: #f9f7f2; }
.s-name { font-size: 14px; font-weight: bold; color: var(--dai-blue); }
.s-info { font-size: 11px; color: #999; margin-top: 4px; display: flex; gap: 3px; flex-wrap: wrap; justify-content: center; }

/* --- 树形容器 --- */
#viewport { width: 100vw; height: 100vh; overflow: hidden; }
#tree-wrapper { display: inline-block; transform-origin: 0 0; padding: 1000px; min-width: 100%; }

.node { display: flex; flex-direction: column; align-items: center; flex-shrink: 0; }
.virtual-root-header { display: flex; flex-direction: column; align-items: center; padding: 30px 0 10px 0; width: 100%; }
.root-title-box { display: flex; align-items: center; }
.root-name { font-size: 32px; font-weight: 900; color: var(--dai-blue); letter-spacing: 8px; padding: 0 20px; white-space: nowrap; }
.title-decoration { width: 60px; height: 2px; background: linear-gradient(to right, transparent, var(--dai-blue)); }
.line-right { transform: rotate(180deg); }
.root-subtitle { font-size: 13px; color: #999; margin-top: 12px; border: 1px solid #d4c4a8; padding: 2px 20px; border-radius: 20px; background: white; }

.person-card {
    width: 110px; height: 72px; padding: 4px 6px;
    background-color: white; border: 1px solid #d4c4a8; border-radius: 4px;
    display: flex; flex-direction: column; align-items: center; justify-content: space-evenly;
    position: relative; z-index: 10;
    transition: transform 0.1s;
    box-sizing: border-box;
}
.person-card:active { transform: scale(0.95); }
.p-word { font-size: 9px; color: white; background-color: var(--dai-blue); padding: 0px 5px; border-radius: 2px; min-width: 10px; text-align: center; line-height: 1.3; transform: scale(0.9); }

.tag-village { background-color: #8E6F4D !important; }
.tag-house { background-color: #B0967A !important; }
.tag-gen { background-color: #D4C4A8 !important; }

/* 占位节点专用样式 (FROZEN) */
.person-card.is-placeholder {
    border-style: dashed;
    opacity: 0.8;
    background-color: #FAFAFA;
}
.tag-placeholder {
    background-color: #AAA !important;
    border-color: #AAA !important;
    color: white !important;
}

.p-name { font-size: 17px; font-weight: 900; color: #333; text-align: center; line-height: 1.1; margin: 1px 0; }.p-title { 
    font-size: 13px; 
    color: #222; 
    font-weight: bold;
    text-align: center; 
    width: 100%; 
    white-space: nowrap; 
    overflow: hidden; 
    text-overflow: ellipsis; 
    min-height: 1.1em; 
    line-height: 1.1;
}

.spouse-box {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    vertical-align: top; /* 配合 flex 使用 */
}
.spouse-box.is-shadow {
    opacity: 0.55;
}
.spouse-box.is-shadow .p-seal-mini {
    border-style: dashed;
}

.p-seal-mini {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 12px;
    height: 12px;
    border: 1px solid #8E6F4D;
    color: #8E6F4D;
    font-size: 8px; /* 进一步缩小，增加呼吸感 */
    font-weight: bold;
    border-radius: 1px;
    margin-right: 4px;
    line-height: 1;
    box-sizing: border-box;
}
.children-box { display: flex; flex-direction: column; align-items: center; width: 100%; }
.line-down { width: 1px; height: 20px; background-color: var(--line-color); }
.children-flex { display: flex; justify-content: center; align-items: flex-start; padding: 0; margin: 0; }
.virtual-children > .child-wrapper { padding: 0 30px; }
.child-wrapper { display: flex; flex-direction: column; align-items: center; position: relative; padding: 0 5px; }
.line-up { width: 1px; height: 20px; background-color: var(--line-color); }
.virtual-branch-line { height: 40px; background-color: #d4c4a8; }
.line-cross-box { position: absolute; top: 0; left: 0; right: 0; height: 1px; display: flex; z-index: 1; }
.cross-left, .cross-right { flex: 1; height: 1px; background-color: var(--line-color); }
.hidden { visibility: hidden; }

/* --- 弹窗基础 --- */
.modal {
    display: none; position: fixed; top: 0; left: 0; width: 100%; height: 100%;
    z-index: 2000; justify-content: center; align-items: center; backdrop-filter: blur(4px);
    background: rgba(0, 0, 0, 0.6);
}
.modal-card {
    position: relative; width: 85%; max-width: 400px; background: #fdfaf2;
    border-radius: 20px; overflow: hidden; box-shadow: 0 10px 30px rgba(0, 0, 0, 0.3);
    border: 2px solid #d4c4a8; display: flex; flex-direction: column;
}
.card-close { position: absolute; top: 10px; right: 15px; font-size: 28px; color: #8E6F4D; cursor: pointer; z-index: 100; line-height: 1; }
.card-back { position: absolute; top: 10px; left: 15px; font-size: 28px; color: #8E6F4D; cursor: pointer; z-index: 100; line-height: 1; display: none; } /* 初始隐藏 */
.card-close:hover, .card-back:hover { color: #C23A37; }

.card-header { height: 50px; display: flex; justify-content: center; align-items: center; background: #f0e6d6; border-bottom: 1px solid #d4c4a8; }
.card-title { font-size: 17px; font-weight: bold; color: var(--dai-blue); letter-spacing: 5px; }
.scroll-decoration { width: 30px; height: 2px; background: var(--dai-blue); margin: 0 10px; }
.card-body { padding: 20px; max-height: 65vh; overflow-y: auto; }

.p-identity-line { display: flex; flex-wrap: wrap; gap: 4px; margin-bottom: 8px; }
.p-name-line { display: block; margin-bottom: 15px; }
.modal-p-name { font-size: 28px; font-weight: bold; color: #4A3B32; line-height: 1.2; }
.p-gen-tag { font-size: 11px; background: var(--dai-blue); color: white; padding: 2px 8px; border-radius: 10px; white-space: nowrap; }

.life-item { display: flex; flex-direction: column; align-items: flex-start; margin-bottom: 12px; }
.life-header { display: flex; align-items: center; margin-bottom: 4px; }
.life-label { background: #f0e6d6; color: var(--dai-blue); padding: 1px 8px; border-radius: 3px; font-weight: bold; margin-right: 8px; font-size: 11px; }
.life-row { color: #666; line-height: 1.6; font-size: 13px; padding-left: 4px; }

.p-item { display: flex; margin-bottom: 8px; font-size: 14px; border-bottom: 1px dashed #EAE6DF; padding-bottom: 4px; }
.p-label { color: #999; width: 70px; flex-shrink: 0; }
.p-value { flex: 1; color: #333; }
.p-divider { height: 1px; background: #eee; margin: 15px 0; }
.card-footer { padding: 15px; background: #fdfaf2; display: flex; justify-content: space-between; gap: 5px; flex-wrap: wrap; }
.footer-btn { background: var(--dai-blue); color: white; flex: 1; border-radius: 25px; font-size: 11px; font-weight: bold; height: 35px; border: none; cursor: pointer; min-width: 80px; }
.footer-btn.secondary { background: #f0e6d6; color: var(--dai-blue); border: 1px solid #d4c4a8; }
.footer-btn.danger { background: #fdf0f0; color: #C93838; border: 1px solid #fbcaca; }
.footer-btn.action { background: #C23A37; color: white; }
.contact-link { color: var(--dai-blue); text-decoration: underline; font-weight: bold; cursor: pointer; }

/* 关系选择列表 */
.choice-list { display: flex; flex-direction: column; gap: 12px; padding: 10px 0; }
.choice-item { background: white; border: 1.5px solid #d4c4a8; border-radius: 12px; padding: 15px; display: flex; align-items: center; cursor: pointer; transition: all 0.2s; }
.choice-item:active { transform: scale(0.98); background: #f9f7f2; border-color: var(--dai-blue); }
.choice-icon { width: 40px; height: 40px; background: #f0e6d6; border-radius: 50%; display: flex; align-items: center; justify-content: center; margin-right: 15px; font-size: 18px; color: var(--dai-blue); }
.choice-info { flex: 1; }
.choice-name { font-size: 16px; font-weight: bold; color: #4A3B32; margin-bottom: 2px; }
.choice-desc { font-size: 12px; color: #999; }

/* --- 录入表单核心样式 (FROZEN) --- */
#editModal .modal-card { width: 92%; max-width: 450px; background: #F9F7F2; border: none; border-radius: 12px; }
#editModal .card-header { background: transparent; border: none; flex-direction: column; height: auto; padding: 20px 0 10px; }
.form-title { font-size: 20px; font-weight: bold; color: var(--dai-blue); margin-bottom: 5px; }
.form-subtitle { font-size: 12px; color: #999; }
.form-section { background: white; border-radius: 10px; padding: 15px; margin-bottom: 15px; box-shadow: 0 2px 8px rgba(142, 111, 77, 0.08); }
.section-title { font-size: 15px; font-weight: bold; color: var(--dai-blue); margin-bottom: 15px; border-bottom: 1px solid #eee; padding-bottom: 5px; }
.form-item { display: flex; align-items: center; padding: 12px 0; border-bottom: 1px solid #f5f5f5; width: 100%; box-sizing: border-box; position: relative; }
.form-item.vertical { flex-direction: column; align-items: flex-start; }
.form-label { width: 90px; font-size: 14px; color: #666; flex-shrink: 0; cursor: pointer; }
.form-input { flex: 1; border: none; font-size: 14px; color: #333; outline: none; background: transparent; width: 100%; box-sizing: border-box; }
.form-textarea { width: 100%; min-height: 80px; border: none; font-size: 14px; padding: 10px; background: #fcfcfc; border-radius: 5px; box-sizing: border-box; resize: none; }
.radio-group { display: flex; gap: 20px; flex: 1; }
.radio-label { font-size: 14px; display: flex; align-items: center; cursor: pointer; }

.label-row { display: flex; justify-content: space-between; align-items: center; width: 100%; margin-bottom: 10px; position: relative; }
.calendar-switch { display: flex; background: #e8e8e8; padding: 2px; border-radius: 20px; width: 100px; border: 1px solid #ddd; }
.calendar-switch div { flex: 1; text-align: center; font-size: 11px; padding: 4px 0; border-radius: 18px; color: #888; cursor: pointer; }
.calendar-switch div.active { background: #fff; color: var(--dai-blue); font-weight: bold; }

.triple-input-group { display: flex; align-items: center; gap: 4px; width: 100%; box-sizing: border-box; }
.input-with-unit { display: flex; align-items: center; flex: 1; background: #f9f9f9; border-radius: 5px; padding: 0 4px; border: 1px solid #eee; min-width: 0; }

.year-input { flex: 2.2 !important; }
.md-input { flex: 1 !important; }

/* 气泡定位 (FROZEN) */
.hint-box { 
    display: none; position: absolute; left: 95px; bottom: 38px; 
    width: max-content; max-width: calc(100% - 105px); height: auto;
    background: rgba(255, 251, 230, 0.96); 
    border: 1px solid #ffe58f; 
    padding: 6px 10px; border-radius: 8px; 
    z-index: 2500; box-shadow: 0 4px 15px rgba(0,0,0,0.12); 
    pointer-events: none;
    backdrop-filter: blur(2px);
    white-space: normal; word-wrap: break-word; line-height: 1.2;
    flex: none !important;
    min-height: 0 !important;
}
.form-item.vertical .hint-box { left: 10px; bottom: calc(100% - 30px); max-width: calc(100% - 20px); top: auto; } 
.desc-wrapper { position: relative; width: 100%; margin-top: 8px; }
.desc-wrapper .hint-box { left: 10px; bottom: calc(100% - 5px); max-width: calc(100% - 20px); top: auto; }

.hint-box::after { content: ''; position: absolute; top: 100%; left: 20px; border: 6px solid transparent; border-top-color: rgba(255, 251, 230, 0.96); }

.hint-text { font-size: 11px; color: #d48806; font-weight: bold; line-height: 1.4 !important; }
.hint-example { display: block; font-weight: normal; color: #888; margin-top: 2px; font-size: 10px; line-height: 1.3 !important; }

.date-sub-input { border: none; background: transparent; width: 100%; height: 32px; text-align: center; font-size: 12px; outline: none; min-width: 0; }
.outer-unit { font-size: 11px; color: #999; margin-left: 1px; flex-shrink: 0; }

.convert-btn-mini { width: 55px; height: 32px; font-size: 10px; background: #f0e6d6; color: var(--dai-blue); border: 1px solid #d4c4a8; border-radius: 5px; margin-left: 2px; cursor: pointer; flex-shrink: 0; outline: none; }
.convert-btn-mini:active { background: #e0d6c6; }

.date-summary { width: 100%; background: #fdfaf2; border: 1px dashed #d4c4a8; border-radius: 8px; padding: 10px; margin-top: 10px; box-sizing: border-box; }
.form-submit-btn { width: 100%; height: 45px; background: var(--dai-blue); color: white; border-radius: 25px; border: none; font-weight: bold; font-size: 16px; margin-top: 10px; cursor: pointer; }

/* 悬浮按钮组 */
.controls { position: fixed; bottom: 30px; right: 20px; display: flex; flex-direction: column; gap: 15px; z-index: 1500; }
.fab { width: 55px; height: 55px; border-radius: 50%; background: #FFF; border: 1px solid #e0e0e0; box-shadow: 0 3px 8px rgba(142, 111, 77, 0.3); display: flex; flex-direction: column; align-items: center; justify-content: center; cursor: pointer; }
.fab.gold { background: var(--dai-blue); color: white; border: 3px solid rgba(255,255,255,0.8); }
.seal-mini { width: 22px; height: 22px; border: 1.5px solid var(--dai-blue); color: var(--dai-blue); display: flex; align-items: center; justify-content: center; font-size: 13px; font-weight: bold; border-radius: 3px; margin-bottom: 3px; line-height: 1; flex-shrink: 0; }
.fab.gold .seal-mini { border-color: white; color: white; }
.fab span { font-size: 10px; font-weight: bold; }

.menu-modal { display: none; position: fixed; bottom: 100px; right: 25px; width: 160px; background: white; border-radius: 15px; box-shadow: 0 5px 25px rgba(0,0,0,0.2); z-index: 1600; overflow: hidden; border: 1px solid #eee; }
.menu-item { padding: 15px; border-bottom: 1px solid #f5f5f5; display: flex; align-items: center; gap: 10px; font-size: 14px; color: #4A3B32; cursor: pointer; }
.menu-item:active { background: #f9f7f2; }

/* 论辈排称 */
.compare-person { text-align: center; }
.compare-label { font-size: 12px; color: #999; margin-bottom: 6px; }
.compare-name { font-size: 18px; font-weight: 900; color: #4A3B32; }
.compare-person .form-input { text-align: center; border: 1.5px solid #e0d8c8; border-radius: 8px; padding: 8px 12px; background: #fdfaf5; font-size: 15px; color: #4A3B32; }
.compare-person .form-input::placeholder { color: #c4b8a4; }
.compare-person .form-input:focus { border-color: #8E6F4D; outline: none; background: #fff; }
.compare-person .search-results { text-align: center; }
.compare-vs { text-align: center; font-size: 20px; color: #d4c4a8; margin: 12px 0; font-weight: bold; }
.compare-divider { height: 1px; background: #e8e0d4; margin: 20px 0; }
.compare-info { font-size: 13px; color: #666; line-height: 1.8; text-align: center; margin-bottom: 15px; }
.compare-titles { display: flex; flex-direction: column; gap: 10px; }
.compare-title-row { display: flex; justify-content: space-between; align-items: center; padding: 10px 15px; background: #fdfaf2; border-radius: 8px; border: 1px solid #e8e0d4; }
.compare-title-label { font-size: 13px; color: #999; }
.compare-title-value { font-size: 16px; font-weight: 700; color: #8E6F4D; }
.menu-item:last-child { border-bottom: none; }

#loading { position: fixed; top: 0; left: 0; width: 100%; height: 100%; background: var(--bg-color); z-index: 3000; display: flex; justify-content: center; align-items: center; flex-direction: column; }
