:root {
  --paper: #f3efe5;
  --paper-light: #faf7f0;
  --ink: #28241f;
  --muted: #746c62;
  --line: #c9bfae;
  --cinnabar: #963a2e;
  --pine: #405448;
  --serif: "Songti SC", "Noto Serif CJK SC", "STSong", serif;
  --sans: -apple-system, BlinkMacSystemFont, "PingFang SC", "Microsoft YaHei", sans-serif;
}

* { box-sizing: border-box; }
html, body { min-height: 100%; margin: 0; }
body { color: var(--ink); background: var(--paper); font-family: var(--sans); }
button, input, select, textarea { font: inherit; }
button, a { -webkit-tap-highlight-color: transparent; }

.genealogy-shell { display: grid; grid-template-rows: auto minmax(calc(100dvh - 132px), auto) auto; min-height: 100dvh; }
.genealogy-header { position: sticky; top: 0; z-index: 10; display: flex; justify-content: space-between; align-items: center; min-height: 72px; padding: 12px clamp(18px, 4vw, 48px); border-bottom: 1px solid rgba(82, 68, 51, .13); background: rgba(243, 239, 229, .92); backdrop-filter: blur(16px); }
.genealogy-header > div { display: flex; align-items: center; gap: 13px; }
.genealogy-header h1 { margin: 0; font: 600 23px/1.2 var(--serif); letter-spacing: 0; }
.seal { display: grid; width: 36px; height: 36px; place-items: center; color: #f6e6d4; border: 1px solid #7f2d24; background: var(--cinnabar); font: 20px/1 var(--serif); }
.edit-button { display: inline-flex; align-items: center; gap: 7px; min-height: 40px; padding: 0 12px; color: #514a42; border: 1px solid rgba(78, 65, 50, .18); border-radius: 5px; background: var(--paper-light); cursor: pointer; }
.edit-icon { width: 16px; height: 16px; background: currentColor; mask: url("/prototype-v03/assets/icons/plus.svg") center/contain no-repeat; -webkit-mask: url("/prototype-v03/assets/icons/plus.svg") center/contain no-repeat; }

.tree-viewport { position: relative; display: grid; overflow: auto; align-items: center; padding: clamp(36px, 7vw, 92px) clamp(18px, 5vw, 72px); background: linear-gradient(rgba(69, 55, 38, .035) 1px, transparent 1px), linear-gradient(90deg, rgba(69, 55, 38, .035) 1px, transparent 1px), var(--paper); background-size: 48px 48px; }
.tree { display: grid; gap: 56px; min-width: min-content; width: min(1100px, 100%); margin: auto; }
.tree-level { position: relative; display: flex; justify-content: center; gap: 32px; min-width: max-content; }
.tree-level + .tree-level::before { position: absolute; top: -56px; left: 50%; width: 1px; height: 34px; content: ""; background: var(--line); }
.tree-level + .tree-level::after { position: absolute; top: -22px; left: 18%; right: 18%; height: 1px; content: ""; background: var(--line); }
.person-node { position: relative; width: 154px; min-height: 92px; padding: 15px 13px; color: var(--ink); border: 1px solid var(--line); border-radius: 4px; background: rgba(250, 247, 240, .94); box-shadow: 0 8px 24px rgba(61, 47, 33, .07); text-align: center; cursor: pointer; }
.tree-level:not(:first-child) .person-node::before { position: absolute; top: -23px; left: 50%; width: 1px; height: 22px; content: ""; background: var(--line); }
.person-node.root { color: #f5ecdb; border-color: #283a31; background: var(--pine); box-shadow: 0 12px 32px rgba(40, 55, 47, .18); }
.person-node strong { display: block; overflow-wrap: anywhere; font: 600 19px/1.35 var(--serif); }
.person-node small { display: block; margin-top: 8px; color: var(--muted); font-size: 11px; }
.person-node.root small { color: #d6cdbc; }
.person-node em { display: block; margin-top: 6px; color: #897d6d; font: normal 11px/1.35 var(--sans); }
.loading, .empty { margin: auto; color: var(--muted); font: 16px/1.8 var(--serif); }
.genealogy-footer { display: flex; justify-content: center; min-height: 60px; padding: 20px; border-top: 1px solid rgba(82, 68, 51, .1); }
.genealogy-footer a { color: #746b60; font: 13px/1.5 var(--serif); text-decoration: none; }

dialog { width: min(560px, calc(100% - 28px)); padding: 22px; color: var(--ink); border: 1px solid var(--line); border-radius: 7px; background: var(--paper-light); box-shadow: 0 26px 80px rgba(31, 25, 19, .3); }
dialog::backdrop { background: rgba(28, 24, 20, .56); backdrop-filter: blur(4px); }
dialog header { display: flex; justify-content: space-between; gap: 18px; align-items: start; margin-bottom: 18px; }
dialog header small { color: var(--cinnabar); font: 12px/1.4 var(--serif); }
dialog h2 { margin: 4px 0 0; font: 600 24px/1.35 var(--serif); }
dialog header button { width: 38px; height: 38px; padding: 0; color: #665d52; border: 0; border-radius: 50%; background: transparent; font-size: 24px; cursor: pointer; }
.person-dialog dl { display: grid; grid-template-columns: 72px 1fr; gap: 10px 16px; margin: 0; font-size: 14px; line-height: 1.7; }
.person-dialog dt { color: var(--muted); }
.person-dialog dd { margin: 0; white-space: pre-wrap; }
.editor-dialog form { display: grid; gap: 14px; }
.editor-dialog label { display: grid; gap: 7px; }
.editor-dialog label > span { color: #62594f; font-size: 13px; }
.editor-dialog input, .editor-dialog select, .editor-dialog textarea { width: 100%; padding: 10px 11px; color: var(--ink); border: 1px solid var(--line); border-radius: 4px; outline: 0; background: #fffdf8; }
.editor-dialog input:focus, .editor-dialog select:focus, .editor-dialog textarea:focus { border-color: #8a7460; box-shadow: 0 0 0 3px rgba(138, 116, 96, .11); }
.date-row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.save-button { min-height: 46px; color: #f7eedf; border: 0; border-radius: 4px; background: var(--pine); cursor: pointer; }
.save-button:disabled { opacity: .55; cursor: wait; }
.editor-status { min-height: 20px; margin: 0; color: var(--cinnabar); font-size: 13px; }

@media (max-width: 620px) {
  .genealogy-header { min-height: 64px; padding: 10px 14px; }
  .genealogy-header h1 { font-size: 20px; }
  .seal { width: 34px; height: 34px; }
  .edit-button { width: 40px; padding: 0; justify-content: center; }
  .edit-button > span:last-child { position: absolute; overflow: hidden; width: 1px; height: 1px; clip: rect(0 0 0 0); }
  .tree-viewport { align-items: start; padding: 42px 22px; }
  .tree { gap: 48px; }
  .tree-level { gap: 18px; }
  .tree-level + .tree-level::before { top: -48px; height: 30px; }
  .tree-level + .tree-level::after { top: -18px; }
  .person-node { width: 132px; min-height: 84px; padding: 13px 10px; }
  .tree-level:not(:first-child) .person-node::before { top: -19px; height: 18px; }
  .date-row { grid-template-columns: 1fr; }
}
