:root {
  --ink: #29251f;
  --muted: #817667;
  --paper: #f3efe4;
  --paper-deep: #e8dfce;
  --red: #8c2f25;
  --red-dark: #692019;
  --gold: #a9884c;
  --line: #9b8c76;
  --card: rgba(255, 253, 247, .96);
}
* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; overflow: hidden; }
body {
  color: var(--ink);
  font-family: "Noto Serif SC", "Songti SC", SimSun, serif;
  background: var(--paper);
}
body::before {
  content: ""; position: fixed; inset: 0; pointer-events: none; opacity: .2;
  background-image: url("data:image/svg+xml,%3Csvg width='120' height='120' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='.7' numOctaves='3' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)' opacity='.12'/%3E%3C/svg%3E");
}
button, input, select, textarea { font: inherit; }
button { cursor: pointer; }
.topbar {
  height: 116px; display: flex; align-items: center; justify-content: space-between;
  padding: 0 28px 34px; background: rgba(247,243,233,.96); border-bottom: 1px solid #d5c9b5;
  position: relative; z-index: 20; box-shadow: 0 4px 18px rgba(62,48,31,.06);
}
.brand { display: flex; gap: 13px; align-items: center; }
.seal {
  width: 46px; height: 46px; display: grid; place-items: center; color: #fff;
  background: var(--red); border: 2px solid var(--red-dark); font-size: 25px;
  box-shadow: inset 0 0 0 3px var(--red), inset 0 0 0 4px rgba(255,255,255,.45);
}
.brand h1 { margin: 1px 0 0; font-size: 23px; letter-spacing: .2em; font-weight: 600; }
.brand p { margin: 0; color: var(--muted); font-size: 11px; letter-spacing: .25em; }
.toolbar { display: flex; align-items: center; gap: 9px; height: 38px; }
.toolbar > * { flex: none; margin-top: 0; margin-bottom: 0; }
.user-badge { height: 38px; display: inline-flex; align-items: center; padding: 0 9px; border: 1px solid #cdbfa9; color: var(--muted); font-size: 11px; white-space: nowrap; }
.user-badge.admin { color: var(--red); border-color: rgba(140,47,37,.45); background: rgba(140,47,37,.06); }
.search { display: flex; align-items: center; width: 210px; height: 38px; padding: 0 12px; background: #fffdf8; border: 1px solid #d7cbb8; }
.search input { width: 100%; height: 36px; margin: 0; border: 0; outline: 0; background: transparent; padding: 0 0 0 7px; color: var(--ink); }
.icon-btn, .ghost-btn, .primary-btn, .danger-btn {
  border: 1px solid #cdbfa9; background: transparent; color: var(--ink); height: 38px; padding: 0 14px;
}
.icon-btn { width: 38px; padding: 0; font-size: 20px; }
.primary-btn { color: #fff; border-color: var(--red); background: var(--red); }
.primary-btn:hover { background: var(--red-dark); }
.ghost-btn:hover, .icon-btn:hover { background: #ebe3d5; }
#zoomLabel { min-width: 42px; text-align: center; font: 12px Arial; color: var(--muted); }
.announcement-bar {
  position: absolute; left: 0; right: 0; bottom: 0; height: 34px; display: flex; align-items: center;
  padding: 0 28px; color: #675b4d; background: rgba(234,226,212,.78); border-top: 1px solid rgba(205,191,169,.72);
}
.announcement-icon { width: 20px; height: 20px; flex: none; display: grid; place-items: center; color: var(--red); }
.announcement-icon svg { width: 17px; height: 17px; fill: currentColor; }
.announcement-window { flex: 1; min-width: 0; height: 28px; overflow: hidden; position: relative; }
.announcement-text {
  position: absolute; top: 6px; white-space: nowrap; font-size: 12px; letter-spacing: .08em;
  animation: announcement-scroll 22s linear infinite;
}
@keyframes announcement-scroll { from { transform: translateX(100vw); } to { transform: translateX(-100%); } }
.announcement-action { height: 26px; margin-left: 8px; padding: 0 9px; border: 1px solid #c8b99f; color: #776958; background: rgba(255,253,247,.65); font-size: 11px; }
.viewport { position: relative; height: calc(100vh - 116px); overflow: hidden; cursor: default; }
.viewport.panning { cursor: grabbing; }
.viewport.space-ready { cursor: grab; }
.canvas { position: absolute; transform-origin: 0 0; width: 100px; height: 100px; }
.links { position: absolute; inset: 0; overflow: visible; pointer-events: none; }
.blood-link { fill: none; stroke: var(--line); stroke-width: 1.5; stroke-linecap: square; stroke-linejoin: miter; }
.blood-link-bg { fill: none; stroke: var(--paper); stroke-width: 5; stroke-linecap: square; stroke-linejoin: miter; }
.marriage-link { stroke: var(--red); stroke-width: 1.4; stroke-dasharray: 4 3; }
.person {
  position: absolute; width: 64px; height: 84px; padding: 7px 7px 6px 9px;
  background: var(--card); border: 1px solid #cfc2ad; box-shadow: 0 4px 12px rgba(55,42,27,.08);
  transition: border-color .15s, box-shadow .15s, opacity .15s; user-select: none;
}
.person.spouse { width: 48px; padding-left: 8px; padding-right: 6px; background: rgba(250,247,239,.9); }
.person::before { content: ""; position: absolute; left: 0; top: 0; bottom: 0; width: 4px; background: #536b62; }
.person.female::before { background: #a45d58; }
.person.deceased {
  background: linear-gradient(155deg, rgba(224,220,209,.98), rgba(244,239,228,.97) 62%, rgba(231,225,212,.98));
  border-color: #aa9d85; box-shadow: 0 4px 12px rgba(68,61,49,.11), inset 0 0 18px rgba(96,91,76,.06);
}
.person.deceased::after {
  content: ""; position: absolute; z-index: 1; top: 1px; left: 7px; right: 1px; height: 7px; opacity: .34; pointer-events: none;
  background:
    linear-gradient(90deg, rgba(151,113,52,.7) 0 1px, transparent 1px 8px),
    linear-gradient(90deg, transparent 0 3px, rgba(151,113,52,.62) 3px 4px, transparent 4px 8px),
    linear-gradient(90deg, transparent 0 4px, rgba(140,47,37,.45) 4px 8px, transparent 8px 12px),
    linear-gradient(180deg, rgba(151,113,52,.55), rgba(151,113,52,.18));
  background-size: 12px 7px, 12px 7px, 12px 1px, 100% 1px;
  background-repeat: repeat-x, repeat-x, repeat-x, no-repeat;
  background-position: 0 0, 0 5px, 0 3px, 0 0;
}
.person.deceased .person-name { color: #5e584e; }
.person:hover, .person.selected { border-color: var(--red); box-shadow: 0 6px 18px rgba(100,38,28,.15); z-index: 3; }
.person.search-dim { opacity: .22; }
.person.search-hit { border-color: var(--red); box-shadow: 0 0 0 3px rgba(140,47,37,.15); }
.person-top { position: relative; height: 53px; display: flex; flex-direction: row-reverse; justify-content: space-between; align-items: flex-start; }
.person.deceased .person-top::after {
  content: ""; position: absolute; z-index: 1; top: -6px; right: -6px; bottom: -23px; width: 7px; opacity: .32; pointer-events: none;
  background:
    linear-gradient(180deg, rgba(151,113,52,.7) 0 1px, transparent 1px 8px),
    linear-gradient(180deg, transparent 0 3px, rgba(151,113,52,.62) 3px 4px, transparent 4px 8px),
    linear-gradient(180deg, transparent 0 4px, rgba(140,47,37,.45) 4px 8px, transparent 8px 12px),
    linear-gradient(90deg, rgba(151,113,52,.18), rgba(151,113,52,.55));
  background-size: 7px 12px, 7px 12px, 1px 12px, 1px 100%;
  background-repeat: repeat-y, repeat-y, repeat-y, no-repeat;
  background-position: 0 0, 5px 0, 3px 0, right top;
}
.person-name, .zi-badge { position: relative; z-index: 2; }
.person-name { writing-mode: vertical-rl; font-size: 14px; font-weight: 600; letter-spacing: .08em; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.person.spouse .person-name { font-size: 13px; }
.zi-badge { flex: none; color: var(--red); font-size: 10px; border: 1px solid rgba(140,47,37,.35); padding: 2px 3px; line-height: 1; }
.person-tags {
  position: absolute; z-index: 3; left: 6px; right: 5px; bottom: 4px; display: flex; flex-direction: column;
  justify-content: flex-end; align-items: stretch; gap: 2px;
}
.person-tag {
  display: block; min-width: 0; width: 100%; height: 10px; padding: 1px 2px; color: #fff; font-size: 6px; line-height: 8px;
  text-align: center; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; border-radius: 1px;
}
.person.spouse .person-tag { font-size: 5px; padding-left: 1px; padding-right: 1px; }
.person-tooltip {
  position: absolute; z-index: 20; left: calc(100% + 10px); top: 0; width: 210px; padding: 12px 14px;
  color: var(--ink); background: rgba(251,247,238,.96); border: 1px solid #cdbfa9;
  box-shadow: 0 10px 30px rgba(49,37,24,.18); font-size: 11px; line-height: 1.7;
  opacity: 0; visibility: hidden; transform: translateY(4px); pointer-events: none;
  transition: opacity .15s ease, transform .15s ease, visibility 0s linear 1.15s;
}
.person:hover .person-tooltip { opacity: 1; visibility: visible; transform: translateY(0); transition-delay: 1s; }
.person-tooltip b { color: var(--red); font-weight: 500; }
.tag-editor { margin: 0 0 16px; }
.tag-editor-title { display: block; margin-bottom: 8px; color: var(--muted); font-size: 12px; }
.tag-rows { display: grid; grid-template-columns: 1fr 92px; gap: 8px 10px; }
.tag-rows label { margin-bottom: 0; }
.tag-rows input, .tag-rows select { margin-top: 5px; padding: 8px 9px; font-size: 12px; }
.tag-rows select { color: #fff; border-color: rgba(140,47,37,.25); text-shadow: 0 1px 1px rgba(0,0,0,.18); }
.generation-rail { position: absolute; left: 8px; top: 0; bottom: 0; z-index: 12; pointer-events: none; }
.gen-tag {
  position: absolute; width: 78px; min-height: 62px; padding: 8px 7px; color: #695d4e;
  border: 1px solid rgba(185,170,145,.48); border-left: 3px solid rgba(140,47,37,.55);
  background: rgba(247,242,232,.55); backdrop-filter: blur(9px) saturate(125%);
  box-shadow: 0 5px 18px rgba(74,57,37,.08);
}
.gen-order { display: block; font-size: 11px; letter-spacing: .08em; }
.gen-zi { display: block; margin-top: 1px; white-space: nowrap; font-size: 13px; color: var(--muted); }
.gen-zi b {
  display: inline-block; margin: 0 2px; font-size: 27px; line-height: 1; font-family: "STKaiti","KaiTi",serif;
  font-weight: 700; background: linear-gradient(110deg,#6a211a 5%,#c59a52 38%,#fff1be 50%,#8c2f25 64%,#6a211a 95%);
  background-size: 220% 100%; -webkit-background-clip: text; background-clip: text; color: transparent;
  filter: drop-shadow(0 1px 1px rgba(86,42,25,.2)); animation: zi-shimmer 3.4s linear infinite;
}
@keyframes zi-shimmer { to { background-position: -220% 0; } }
.canvas-tip, .legend {
  position: absolute; z-index: 9; bottom: 18px; background: rgba(255,253,247,.9);
  border: 1px solid #d3c6b1; color: var(--muted); font-size: 12px; padding: 9px 12px;
}
.canvas-tip { left: 18px; }
.legend { right: 18px; display: flex; gap: 16px; }
kbd { border: 1px solid #c8baa5; background: #fff; padding: 1px 5px; box-shadow: 0 1px 0 #c8baa5; }
.dot { display: inline-block; width: 8px; height: 8px; margin-right: 5px; background: #536b62; border-radius: 50%; }
.dot.female { background: #a45d58; }
.line-sample { display: inline-block; width: 19px; border-top: 2px solid var(--line); margin: 0 5px 3px 0; }
.line-sample.marriage { border-color: var(--red); border-top-style: dashed; }
.drawer {
  position: fixed; z-index: 40; right: 0; top: 0; width: 390px; height: 100%; padding: 28px;
  background: #f7f2e8; border-left: 1px solid #cfc0aa; transform: translateX(105%); transition: transform .25s ease;
  box-shadow: -12px 0 35px rgba(48,34,20,.12); overflow-y: auto;
}
.drawer.open { transform: translateX(0); }
.backdrop { display: none; position: fixed; z-index: 30; inset: 0; background: rgba(39,31,22,.18); }
.backdrop.show { display: block; }
.drawer-head { display: flex; justify-content: space-between; align-items: flex-start; margin-bottom: 24px; }
.drawer-head h2 { margin: 4px 0 0; font-size: 23px; font-weight: 500; }
.eyebrow { font-size: 11px; letter-spacing: .28em; color: var(--red); }
.close-btn { border: 0; background: transparent; font-size: 28px; color: var(--muted); }
label { display: block; margin-bottom: 16px; font-size: 12px; color: var(--muted); }
input, select, textarea {
  display: block; width: 100%; margin-top: 7px; padding: 10px 11px; color: var(--ink);
  background: rgba(255,255,255,.65); border: 1px solid #cfc2ad; outline: none; resize: vertical;
}
input:focus, select:focus, textarea:focus { border-color: var(--red); }
input[readonly] { color: #766d60; background: #eee8dd; }
.switch-row { display: flex; align-items: center; justify-content: space-between; padding: 9px 0 16px; }
.switch-row input { width: 17px; height: 17px; margin: 0; accent-color: var(--red); }
.unknown-date { display: flex; align-items: center; gap: 6px; margin-top: 8px; color: var(--muted); font-size: 11px; }
.unknown-date input { width: 15px; height: 15px; margin: 0; accent-color: var(--red); }
.date-hint { display: block; min-height: 16px; margin-top: 5px; color: #8a6a35; font-size: 10px; line-height: 1.45; }
.date-hint.error { color: var(--red); }
.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 13px; }
.relation-box { border-top: 1px solid #d5c9b5; border-bottom: 1px solid #d5c9b5; padding: 18px 0; margin: 6px 0 22px; }
.relation-box h3 { font-size: 14px; margin: 0 0 10px; font-weight: 500; }
.relation-actions { display: grid; grid-template-columns: repeat(3, 1fr); gap: 7px; }
.relation-actions button { border: 1px solid #cdbfa9; background: #fffaf1; padding: 8px 4px; font-size: 12px; }
.relation-list { margin: 13px 0 0; font-size: 12px; color: var(--muted); line-height: 1.9; }
.form-actions { display: flex; justify-content: space-between; }
.danger-btn { color: var(--red); }
dialog { width: 380px; margin: auto; padding: 26px; border: 1px solid #c9baa3; background: #f7f2e8; color: var(--ink); box-shadow: 0 24px 80px rgba(25,18,12,.25); }
dialog::backdrop { background: rgba(39,31,22,.35); }
.wide { width: 100%; margin-top: 5px; }
.auth-dialog { width: min(480px, calc(100vw - 40px)); }
.auth-tabs { display: grid; grid-template-columns: 1fr 1fr; margin: -4px 0 22px; border: 1px solid #cdbfa9; background: rgba(255,250,241,.58); }
.auth-tab { height: 40px; border: 0; border-right: 1px solid #cdbfa9; color: var(--muted); background: transparent; }
.auth-tab:last-child { border-right: 0; }
.auth-tab.active { color: #fff; background: var(--red); }
.auth-panels h3 { margin: 0 0 18px; font-size: 16px; font-weight: 500; }
.auth-panels form[hidden] { display: none; }
.auth-note, .form-message { color: var(--muted); font-size: 11px; }
.form-message { min-height: 16px; color: var(--red); }
.history-dialog { width: min(960px, calc(100vw - 40px)); }
.history-table-wrap { max-height: 60vh; overflow: auto; margin-bottom: 18px; border: 1px solid #d5c9b5; }
.history-table { width: 100%; border-collapse: collapse; font-size: 12px; background: rgba(255,255,255,.45); }
.history-table th, .history-table td { padding: 10px 12px; border-bottom: 1px solid #ddd1be; text-align: left; vertical-align: top; }
.history-table th { position: sticky; top: 0; background: #eee6d8; color: var(--muted); font-weight: 500; }
.history-empty { padding: 30px !important; text-align: center !important; color: var(--muted); }
.history-section-title { margin: 14px 0 8px; font-size: 14px; font-weight: 500; color: var(--ink); }
.request-table-wrap { max-height: 32vh; }
.review-actions { display: flex; gap: 6px; }
.review-actions button { height: 28px; padding: 0 9px; font-size: 11px; }
.status-tag { display: inline-block; padding: 3px 7px; font-size: 10px; border: 1px solid #cdbfa9; color: var(--muted); }
.status-tag.pending { color: #8a631f; border-color: #c4a15d; }
.status-tag.approved { color: #416458; border-color: #74988c; }
.status-tag.rejected { color: var(--red); border-color: #b97971; }
.announcement-dialog { width: min(700px, calc(100vw - 40px)); }
.message-board-dialog { width: min(760px, calc(100vw - 40px)); }
.message-board-dialog form { margin-bottom: 16px; }
.message-board-dialog form button { margin-top: 0; }
.message-board-list { max-height: 54vh; overflow: auto; margin-top: 18px; }
.board-message {
  padding: 15px 16px; margin-bottom: 12px; border: 1px solid #d5c9b5;
  background: rgba(255,255,255,.38);
}
.board-message header, .board-reply header {
  display: flex; justify-content: space-between; gap: 12px; align-items: baseline;
  color: var(--muted); font-size: 11px;
}
.board-message header strong, .board-reply header strong { color: var(--red); font-weight: 500; }
.board-message p, .board-reply p { margin: 8px 0 0; font-size: 13px; line-height: 1.8; white-space: pre-wrap; }
.board-replies { margin: 12px 0 0 18px; border-left: 2px solid rgba(140,47,37,.18); }
.board-reply { padding: 10px 0 10px 14px; border-bottom: 1px solid rgba(213,201,181,.7); }
.board-reply-form { display: grid; grid-template-columns: 1fr auto; gap: 10px; align-items: start; margin-top: 12px; }
.board-reply-form textarea { min-height: 58px; margin-top: 0; }
.board-reply-form button { height: 58px; }
.board-empty { padding: 34px; color: var(--muted); text-align: center; border: 1px dashed #cdbfa9; }
.announcement-history { max-height: 52vh; overflow: auto; margin-top: 18px; }
.announcement-item { padding: 13px 14px; border-bottom: 1px solid #ddd1be; background: rgba(255,255,255,.35); }
.announcement-item time { display: block; margin-bottom: 5px; color: var(--muted); font-size: 10px; }
.announcement-item p { margin: 0; line-height: 1.7; font-size: 13px; }
.announcement-item img { display: block; max-width: min(100%, 520px); max-height: 260px; margin-top: 10px; border: 1px solid #d5c9b5; object-fit: contain; background: #eee8dc; }
.announcement-preview { display: block; max-width: 100%; max-height: 220px; margin: -4px 0 16px; border: 1px solid #d5c9b5; object-fit: contain; }
.announcement-empty { padding: 30px; color: var(--muted); text-align: center; }
.data-port-dialog { width: min(520px, calc(100vw - 40px)); }
.data-port-note { margin: -8px 0 18px; color: var(--muted); font-size: 12px; line-height: 1.8; }
.data-port-actions { display: flex; gap: 12px; align-items: center; }
.import-file {
  height: 38px; margin: 0; padding: 0 14px; display: inline-flex; align-items: center;
  border: 1px solid #cdbfa9; background: #fffaf1; color: var(--ink); cursor: pointer;
}
.import-file input { display: none; }
.message-dialog {
  width: min(420px, calc(100vw - 40px)); padding: 0; overflow: hidden;
  background: linear-gradient(145deg, rgba(255,252,244,.98), rgba(239,231,216,.98));
  border: 1px solid #c8b99f; box-shadow: 0 28px 90px rgba(35,25,14,.32), inset 0 0 0 4px rgba(255,255,255,.28);
}
.message-dialog[open] { animation: dialog-pop .18s ease-out; }
@keyframes dialog-pop {
  from { opacity: 0; transform: translateY(10px) scale(.96); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}
.message-dialog::before {
  content: ""; position: absolute; inset: 9px; pointer-events: none;
  border: 1px solid rgba(169,136,76,.34);
}
.message-ornament {
  height: 8px; background: linear-gradient(90deg, var(--red), #b4853f, var(--red));
  box-shadow: 0 1px 0 rgba(255,255,255,.5) inset;
}
.message-close { position: absolute; right: 14px; top: 12px; z-index: 2; font-size: 24px; }
.message-body { position: relative; padding: 28px 30px 14px; text-align: center; }
.message-body h2 { margin: 6px 0 10px; font-size: 22px; font-weight: 500; letter-spacing: .12em; }
.message-body p { margin: 0; color: #655b4e; font-size: 13px; line-height: 1.9; white-space: pre-line; }
.message-actions {
  display: flex; justify-content: center; gap: 12px; padding: 0 30px 28px;
}
.message-actions button { min-width: 92px; }
.message-dialog.alert .messageCancelHidden { display: none; }
.drawer.readonly input, .drawer.readonly select, .drawer.readonly textarea { color: #766d60; background: #eee8dd; }
@media (max-width: 800px) {
  .topbar { padding: 0 12px; }
  .brand p, .toolbar .search, #zoomLabel { display: none; }
  .brand h1 { font-size: 18px; }
  .drawer { width: min(390px, 100vw); }
  #userBadge, #historyBtn, #messageBoardBtn { display: none; }
}
