* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

:root {
    --bg-paper: #f8efe2;
    --bg-soft: #fbf6ed;
    --line-gold: #d5bf8b;
    --ink-main: #2f2417;
    --ink-sub: #6d5a3e;
    --accent-gold: #8b6914;
    --accent-red: #7f1124;
    --card-shadow: 0 8px 18px rgba(102, 76, 27, 0.10);
}

html,
body {
    height: 100%;
}

body {
    font-family: 'FangSong', 'STFangsong', 'PingFang SC', 'Microsoft YaHei', sans-serif;
    background: linear-gradient(180deg, #f6eadb 0%, #faf5ec 100%);
    color: var(--ink-main);
    overflow: hidden;
    touch-action: manipulation;
}

button,
input {
    font: inherit;
}

button {
    border: 0;
    background: none;
}

#app {
    width: 100vw;
    height: 100vh;
}

.screen {
    width: 100%;
    height: 100%;
}

.hidden {
    display: none !important;
}

.screen-home {
    display: flex;
    flex-direction: column;
    background: #f7f0df;
    overflow-y: auto;
}

.home-hero {
    display: flex;
    align-items: center;
    justify-content: flex-start;
    gap: 18px;
    padding: 22px 20px 20px;
    background: linear-gradient(180deg, #9f1627 0%, #931323 100%);
    border-bottom: 1px solid #6f0f1b;
}

.home-emblem {
    flex: 0 0 74px;
    width: 74px;
    height: 74px;
    margin: 0;
    border-radius: 50%;
    display: grid;
    place-items: center;
    background: linear-gradient(180deg, #fffdf6 0%, #f9f0df 100%);
    border: 2px solid rgba(255, 216, 223, 0.72);
    color: #d31912;
    font-family: 'FZXiaoZhuanTi-S13T', '方正小篆体', 'HanYi Xiao Zhuan', 'STKaiti', serif;
    font-size: 46px;
    font-weight: 700;
    line-height: 1;
    box-shadow: 0 8px 18px rgba(67, 9, 18, 0.24);
}

.home-hero h1 {
    font-size: 22px;
    font-weight: 700;
    letter-spacing: 1px;
    color: #fffef7;
    text-shadow: 0 1px 0 rgba(66, 8, 18, 0.24);
    white-space: nowrap;
}

.home-actions {
    display: flex;
    flex-direction: column;
}

.home-item {
    min-height: 88px;
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 0 10px 0 12px;
    background: #f8ebba;
    border-bottom: 1px solid #4b4b4b;
}

.home-item:first-child {
    border-top: 1px solid #4b4b4b;
}

.home-item-icon {
    flex: 0 0 24px;
    width: 24px;
    height: 24px;
    display: grid;
    place-items: center;
    background:
        radial-gradient(circle at 50% 50%, rgba(154, 84, 14, 0.55) 0 12%, transparent 13%),
        radial-gradient(circle at 25% 28%, rgba(191, 120, 30, 0.92) 0 16%, transparent 17%),
        radial-gradient(circle at 75% 28%, rgba(191, 120, 30, 0.92) 0 16%, transparent 17%),
        radial-gradient(circle at 28% 76%, rgba(191, 120, 30, 0.92) 0 16%, transparent 17%),
        radial-gradient(circle at 72% 76%, rgba(191, 120, 30, 0.92) 0 16%, transparent 17%),
        linear-gradient(180deg, #ffd463 0%, #efb93f 100%);
    border: 1px solid #d4a42e;
    box-shadow: inset 0 0 0 1px rgba(255, 244, 196, 0.55);
}

.home-item-icon span {
    font-size: 9px;
    color: rgba(135, 75, 14, 0.65);
    line-height: 1;
}

.home-item-copy {
    flex: 1;
    min-width: 0;
    display: flex;
    flex-direction: column;
    justify-content: center;
}

.home-item-title {
    font-size: 17px;
    font-weight: 700;
    line-height: 1.35;
    color: #1e1811;
}

.home-item-subtitle {
    margin-top: 2px;
    font-size: 12px;
    line-height: 1.35;
    color: #302820;
}

.home-item-link {
    flex: 0 0 auto;
    min-width: 108px;
    min-height: 48px;
    padding: 0 10px;
    display: grid;
    place-items: center;
}

.home-arrow {
    font-size: 13px;
    font-weight: 700;
    line-height: 1;
    letter-spacing: 0;
    color: #3f3f3f;
    white-space: nowrap;
}

.home-item-link:active .home-arrow,
.home-item-link:focus .home-arrow {
    color: #7a5a18;
}

.screen-content,
.screen-tree {
    display: flex;
    flex-direction: column;
    background: linear-gradient(180deg, #fbf7ef 0%, #f6efe1 100%);
}

.page-header {
    flex: 0 0 auto;
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 12px 14px;
    background: linear-gradient(180deg, #f8ead4 0%, #f3dec0 100%);
    border-bottom: 1px solid var(--line-gold);
    box-shadow: 0 2px 8px rgba(92, 67, 27, 0.08);
}

.page-header h2 {
    font-size: 19px;
    font-weight: 500;
    letter-spacing: 1px;
    color: #3b2a16;
}

.back-btn {
    flex: 0 0 auto;
    padding: 6px 12px;
    border-radius: 999px;
    background: #ffffff;
    border: 1px solid #d1bb88;
    color: #5f4a21;
    box-shadow: 0 2px 5px rgba(92, 67, 27, 0.08);
}

.content-body {
    flex: 1;
    overflow-y: auto;
    padding: 18px 16px 28px;
}

.content-card {
    max-width: 760px;
    margin: 0 auto;
    padding: 18px 16px;
    border: 1px solid #ead9b1;
    border-radius: 18px;
    background: rgba(255, 252, 246, 0.92);
    box-shadow: var(--card-shadow);
}

.content-card h3 {
    margin-bottom: 14px;
    font-size: 20px;
    font-weight: 500;
    color: #5d4317;
}

.content-card p {
    margin-bottom: 12px;
    line-height: 1.9;
    font-size: 17px;
    color: #33271a;
    text-indent: 2em;
}

.placeholder-box {
    min-height: 220px;
    display: flex;
    align-items: center;
    justify-content: center;
    text-align: center;
    line-height: 1.8;
    color: var(--ink-sub);
    font-size: 18px;
}

.relationship-card {
    display: flex;
    flex-direction: column;
    gap: 16px;
}

.relationship-form {
    display: grid;
    gap: 12px;
}

.relationship-input {
    width: 100%;
    padding: 12px 14px;
    border: 1px solid #d8c79f;
    border-radius: 14px;
    background: #fffdfa;
    color: #2f2417;
    outline: none;
}

.relationship-input:focus {
    border-color: var(--accent-gold);
    box-shadow: 0 0 0 3px rgba(139, 105, 20, 0.12);
}

.relationship-submit-btn {
    align-self: flex-start;
    padding: 10px 18px;
    border-radius: 14px;
    background: linear-gradient(180deg, #a17d1f 0%, #8b6914 100%);
    color: #fff;
}

.relationship-result {
    display: grid;
    gap: 12px;
}

.relationship-result-card {
    display: grid;
    gap: 10px;
}

.relationship-item {
    padding: 12px 14px;
    border: 1px solid #eadfc7;
    border-radius: 14px;
    background: rgba(255, 252, 246, 0.92);
}

.relationship-label {
    margin-bottom: 6px;
    color: #8a775b;
    font-size: 13px;
}

.relationship-value {
    color: #2d2318;
    font-size: 16px;
    line-height: 1.7;
}

.relationship-subvalue {
    margin-top: 6px;
    color: #7a6750;
    font-size: 13px;
    line-height: 1.7;
}

.relationship-path {
    word-break: break-word;
}

.relationship-note,
.relationship-empty {
    padding: 12px 14px;
    border-radius: 14px;
    background: #fbf3e1;
    color: #6d5a3e;
    line-height: 1.7;
    font-size: 14px;
}

.generation-stats-card {
    display: flex;
    flex-direction: column;
    gap: 14px;
}

.generation-stats-note {
    padding: 12px 14px;
    border-radius: 14px;
    background: #fbf3e1;
    color: #6d5a3e;
    line-height: 1.7;
    font-size: 14px;
}

.generation-stats-list {
    display: grid;
    gap: 12px;
}

.generation-details-card {
    border: 1px solid #eadfc7;
    border-radius: 16px;
    background: rgba(255, 252, 246, 0.92);
    overflow: hidden;
}

.generation-summary-row {
    list-style: none;
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 14px 14px;
    cursor: pointer;
}

.generation-summary-row::-webkit-details-marker {
    display: none;
}

.generation-chip {
    flex: 0 0 auto;
    min-width: 56px;
    padding: 8px 10px;
    border-radius: 12px;
    background: linear-gradient(180deg, #b88c1c 0%, #9c7314 100%);
    color: #fff9ef;
    text-align: center;
    font-size: 15px;
    font-weight: 700;
}

.generation-summary-text {
    flex: 1;
    min-width: 0;
    color: #2d2318;
    font-size: 15px;
    line-height: 1.6;
}

.generation-summary-action {
    flex: 0 0 auto;
    color: #8b6914;
    font-size: 13px;
    white-space: nowrap;
}

.generation-details-card[open] .generation-summary-action::after {
    content: ' ▲';
}

.generation-details-card:not([open]) .generation-summary-action::after {
    content: ' ▼';
}

.generation-detail-panel {
    padding: 0 14px 14px;
    border-top: 1px solid #f0e2c4;
}

.generation-name-list {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    padding-top: 12px;
}

.generation-name-pill {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 7px 12px;
    border-radius: 999px;
    background: #fff7e6;
    border: 1px solid #ead39e;
    color: #4a3920;
    font-size: 14px;
    line-height: 1.4;
}

.locate-query {
    flex: 0 0 auto;
    display: flex;
    gap: 10px;
    padding: 12px 14px;
    background: #f8f1e3;
    border-bottom: 1px solid #ead7b1;
}

.locate-query input {
    flex: 1;
    min-width: 0;
    padding: 10px 14px;
    border: 1px solid #d8c79f;
    border-radius: 14px;
    background: #fffdfa;
    color: #2f2417;
    outline: none;
}

.locate-query input:focus {
    border-color: var(--accent-gold);
    box-shadow: 0 0 0 3px rgba(139, 105, 20, 0.12);
}

.locate-query button {
    flex: 0 0 auto;
    padding: 10px 16px;
    border-radius: 14px;
    background: linear-gradient(180deg, #a17d1f 0%, #8b6914 100%);
    color: #fff;
}

.locate-back-btn {
    padding: 10px 14px;
    background: #fffaf0;
    color: #6b531f;
    border: 1px solid #d8c79f;
}

.panel-header {
    flex: 0 0 auto;
    display: flex;
    flex-direction: column;
    gap: 4px;
    padding: 12px 14px 10px;
    background: linear-gradient(180deg, #f5e4c7 0%, #f0dab7 100%);
    border-bottom: 1px solid rgba(139, 105, 20, 0.16);
}

.panel-header h3 {
    font-size: 17px;
    font-weight: 500;
    color: #4f3815;
}

.detail-hint {
    font-size: 13px;
    color: #7b6440;
}

.detail-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.30);
    z-index: 1100;
}

.detail-modal {
    position: fixed;
    left: 50%;
    top: 50%;
    transform: translate(-50%, -50%);
    width: min(92vw, 420px);
    max-height: min(78vh, 640px);
    display: flex;
    flex-direction: column;
    background: linear-gradient(180deg, #fffef9 0%, #f8efdf 100%);
    border: 1px solid #e0cda2;
    border-radius: 18px;
    box-shadow: 0 14px 36px rgba(0, 0, 0, 0.22);
    z-index: 1110;
    overflow: hidden;
}

.detail-modal-header {
    flex-direction: row;
    align-items: center;
    justify-content: space-between;
}

.detail-close-btn {
    flex: 0 0 auto;
    width: 34px;
    height: 34px;
    border-radius: 50%;
    display: grid;
    place-items: center;
    background: rgba(255, 255, 255, 0.65);
    color: #6d4f18;
    font-size: 24px;
    line-height: 1;
}

.panel-content {
    flex: 1;
    overflow-y: auto;
    padding: 10px 12px 12px;
}

.detail-empty {
    height: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    text-align: center;
    color: #846e4a;
    line-height: 1.8;
    font-size: 15px;
    padding: 12px;
}

.detail-item {
    margin-bottom: 10px;
    padding: 10px 12px;
    background: rgba(255, 252, 246, 0.92);
    border: 1px solid #eadfc7;
    border-radius: 12px;
}

.detail-label {
    margin-bottom: 4px;
    color: #8a775b;
    font-size: 13px;
}

.detail-value {
    color: #2d2318;
    font-size: 16px;
    line-height: 1.6;
}

.detail-note {
    color: #4d3a23;
    font-size: 15px;
    line-height: 1.7;
    white-space: pre-wrap;
}

.main-content {
    flex: 1;
    min-height: 0;
    position: relative;
}

#tree {
    width: 100%;
    height: 100%;
    overflow: auto;
    cursor: grab;
    touch-action: none;
    background:
        radial-gradient(circle at 1px 1px, rgba(139, 105, 20, 0.07) 1px, transparent 0) 0 0/24px 24px,
        #fdfbf5;
    scrollbar-color: #d8cba4 #fdfbf5;
    scrollbar-width: thin;
}

#tree::-webkit-scrollbar {
    width: 10px;
    height: 10px;
}

#tree::-webkit-scrollbar-track {
    background: #fdfbf5;
}

#tree::-webkit-scrollbar-thumb {
    background-color: #d8cba4;
    border-radius: 6px;
    border: 2px solid #fdfbf5;
}

#tree.is-panning {
    cursor: grabbing;
    user-select: none;
}

#tree svg,
.tree-svg {
    display: block;
    width: auto;
    height: auto;
}

.tree-loading,
.tree-message,
.tree-error {
    padding: 20px;
    text-align: center;
    font-size: 15px;
    line-height: 1.8;
}

.tree-loading,
.tree-message {
    color: #71592d;
}

.tree-error {
    color: #9a1f1f;
}

.tree-line {
    stroke: #b7a06b;
    stroke-width: 1.2;
    stroke-linecap: round;
    opacity: 0.85;
    fill: none;
    shape-rendering: geometricPrecision;
}

.tree-couple-line {
    stroke-width: 2.1;
    opacity: 0.95;
}

.tree-adoption-line {
    stroke-dasharray: 5 4;
}

.tree-node {
    cursor: pointer;
    outline: none;
}

.tree-node-box {
    fill: #fffefb;
    stroke: #c7a542;
    stroke-width: 1.1;
    filter: drop-shadow(0 1px 2px rgba(139, 105, 20, 0.22));
    transition: stroke 0.15s ease, filter 0.15s ease, transform 0.15s ease;
    transform-box: fill-box;
    transform-origin: center;
}

.tree-spouse-box {
    fill: transparent;
    stroke: #c9b07a;
    stroke-width: 1;
    filter: drop-shadow(0 1px 2px rgba(139, 105, 20, 0.16));
}

.tree-node-box.male-node {
    fill: #e6f1ff;
    stroke: #6d9bd6;
}

.tree-node-box.female-node {
    fill: #ffe4ef;
    stroke: #d892b1;
}

.tree-node-box.has-story-node {
    fill: #ffe36a;
    stroke: #c79d14;
}

.tree-node:active .tree-node-box,
.tree-node.is-focused .tree-node-box,
.tree-node:focus .tree-node-box {
    stroke: #8b6914;
    stroke-width: 2;
    filter: drop-shadow(0 0 6px rgba(139, 105, 20, 0.35));
    transform: scale(1.08);
}

.tree-node-name-char {
    font-family: 'SimSun', 'Microsoft YaHei', sans-serif;
    font-size: 11px;
    fill: #111111;
}

.tree-spouse-name-char {
    font-family: 'SimSun', 'Microsoft YaHei', sans-serif;
    font-size: 10px;
    fill: #111111;
}

.tree-node-title {
    font-family: 'Microsoft YaHei', sans-serif;
    font-size: 7px;
    fill: #222222;
}

.tree-node-corner-badge {
    pointer-events: none;
}

.tree-node-corner-badge-shape {
    fill: #d8b24a;
    stroke: #b2871f;
    stroke-width: 0.8;
}

.tree-node-corner-badge-text {
    font-family: 'Microsoft YaHei', sans-serif;
    font-size: 7px;
    font-weight: 700;
    fill: #fff9ea;
    pointer-events: none;
}

.tree-relation-badge-box {
    fill: #fff8e8;
    stroke: #c49a39;
    stroke-width: 0.8;
}

.tree-relation-badge-text {
    fill: #8a6112;
    font-family: 'Microsoft YaHei', sans-serif;
    font-size: 8px;
    font-weight: 700;
    pointer-events: none;
}

.tree-expand-control {
    cursor: pointer;
    outline: none;
}

.tree-expand-circle {
    fill: #fff8e8;
    stroke: #b79237;
    stroke-width: 1.2;
    filter: drop-shadow(0 1px 2px rgba(116, 83, 21, 0.18));
}

.tree-expand-text {
    fill: #7c5914;
    font-size: 13px;
    font-weight: 700;
    pointer-events: none;
}

.tree-expand-control:active .tree-expand-circle,
.tree-expand-control:focus .tree-expand-circle {
    fill: #f6e2a4;
    stroke: #8b6914;
}

.mobile-tree-tools {
    flex: 0 0 auto;
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 6px;
    padding: 8px 10px calc(8px + env(safe-area-inset-bottom));
    border-top: 1px solid rgba(139, 105, 20, 0.3);
    background: #fffaf0;
    box-shadow: 0 -2px 8px rgba(0, 0, 0, 0.08);
}

.mobile-tree-tools button,
.mobile-tree-tools span {
    min-width: 44px;
    min-height: 42px;
    border: 0;
    border-radius: 21px;
    background: transparent;
    color: #4a3a16;
    font-size: 15px;
    font-weight: 600;
    text-align: center;
}

.mobile-tree-tools button:active {
    background: #eee6d0;
}

.mobile-tree-tools span {
    min-width: 56px;
    padding: 12px 2px;
    color: #8b6914;
    font-size: 12px;
}
