:root {
  --bg: #f5f1e8;
  --surface: #fffcf5;
  --surface-2: #efe9dc;
  --ink: #22302a;
  --ink-2: #56625a;
  --ink-3: #848c84;
  --line: #ddd5c4;
  --line-2: #c9bfab;
  --accent: #a4532f;
  --accent-soft: #f3e1d4;
  --ok: #3f6b4f;
  --ok-soft: #dfeadf;
  --warn: #8a6414;
  --warn-soft: #f4e8c8;
  --b-nik: #4f6f8f;
  --b-shu: #8f6a3c;
  --b-kri: #6a7f45;
  --b-cve: #8a4f6c;
  --b-pop: #a4532f;
  --b-near: #22302a;
  --b-other: #848c84;
  --shadow: 0 1px 2px rgb(40 30 10 / .06), 0 6px 20px rgb(40 30 10 / .06);
  --serif: 'Cormorant Garamond', Georgia, serif;
  --sans: 'Manrope', system-ui, sans-serif;
  --r: 10px;
  --panel-w: 400px;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #161a17; --surface: #1e2420; --surface-2: #262d28; --ink: #ece6d8; --ink-2: #b8b4a8; --ink-3: #8a8a80;
    --line: #333b35; --line-2: #45504a; --accent: #e08a5f; --accent-soft: #3a2a20; --ok: #8fc29d; --ok-soft: #22352a;
    --warn: #e0bd6a; --warn-soft: #3a3220; --b-nik: #8fb0d0; --b-shu: #d1a874; --b-kri: #a9c27f; --b-cve: #cf93b1;
    --b-pop: #e08a5f; --b-near: #ece6d8; --shadow: 0 1px 2px rgb(0 0 0 / .3), 0 8px 24px rgb(0 0 0 / .25);
  }
}
:root[data-theme="dark"] {
  --bg: #161a17; --surface: #1e2420; --surface-2: #262d28; --ink: #ece6d8; --ink-2: #b8b4a8; --ink-3: #8a8a80;
  --line: #333b35; --line-2: #45504a; --accent: #e08a5f; --accent-soft: #3a2a20; --ok: #8fc29d; --ok-soft: #22352a;
  --warn: #e0bd6a; --warn-soft: #3a3220; --b-nik: #8fb0d0; --b-shu: #d1a874; --b-kri: #a9c27f; --b-cve: #cf93b1;
  --b-pop: #e08a5f; --b-near: #ece6d8; --shadow: 0 1px 2px rgb(0 0 0 / .3), 0 8px 24px rgb(0 0 0 / .25);
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; background: var(--bg); color: var(--ink); font: 15px/1.55 var(--sans); }
button, input { font: inherit; color: inherit; }
button { cursor: pointer; }
a { color: inherit; text-underline-offset: 3px; }
h1, h2, h3 { margin: 0; font-weight: 600; }
h1 { font: 600 clamp(30px, 4vw, 42px)/1.1 var(--serif); letter-spacing: -.01em; }
h2 { font: 600 26px/1.2 var(--serif); }
h3 { font-size: 15px; }
p { margin: 0; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 4px; }
svg { flex: none; }
.skip { position: fixed; left: 12px; top: -60px; z-index: 50; background: var(--surface); padding: 8px 12px; border-radius: 6px; }
.skip:focus { top: 12px; }
.ghost { background: none; border: 1px solid var(--line); border-radius: 7px; padding: 4px 10px; color: var(--ink-2); font-size: 13px; }
.ghost:hover { background: var(--surface-2); }
.muted { color: var(--ink-2); }
.small { font-size: 13px; }

/* Header */
.top { position: sticky; top: 0; z-index: 20; background: color-mix(in srgb, var(--bg) 88%, transparent); backdrop-filter: blur(10px); border-bottom: 1px solid var(--line); }
.top-inner { max-width: 1440px; margin: 0 auto; padding: 10px 24px; display: flex; align-items: center; gap: 24px; }
.brand { display: flex; align-items: center; gap: 10px; text-decoration: none; }
.brand-mark { width: 34px; height: 34px; border-radius: 50%; display: grid; place-items: center; background: var(--ink); color: var(--bg); font: 600 20px/1 var(--serif); }
.brand-text { display: flex; flex-direction: column; line-height: 1.15; }
.brand-text b { font: 600 19px/1.1 var(--serif); }
.brand-text small { font-size: 11px; color: var(--ink-3); letter-spacing: .04em; text-transform: uppercase; }
.tabs { display: flex; gap: 2px; margin-right: auto; }
.tabs a { text-decoration: none; padding: 7px 12px; border-radius: 8px; color: var(--ink-2); font-weight: 500; font-size: 14px; }
.tabs a:hover { background: var(--surface-2); color: var(--ink); }
.tabs a[aria-current="page"] { background: var(--ink); color: var(--bg); }
.search-btn { display: flex; align-items: center; gap: 8px; background: var(--surface); border: 1px solid var(--line); border-radius: 9px; padding: 7px 10px 7px 12px; color: var(--ink-2); min-width: 180px; }
.search-btn:hover { border-color: var(--line-2); }
.search-btn svg, .search-head svg { width: 17px; height: 17px; stroke: currentColor; fill: none; stroke-width: 1.8; stroke-linecap: round; }
.search-btn kbd { margin-left: auto; font: 11px var(--sans); border: 1px solid var(--line); border-radius: 4px; padding: 0 5px; color: var(--ink-3); }

main { max-width: 1440px; margin: 0 auto; padding: 28px 24px 64px; transition: padding-right .2s; }
body.panel-open main { padding-right: calc(var(--panel-w) + 32px); }
.view-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 24px; flex-wrap: wrap; margin-bottom: 20px; }
.view-head p { color: var(--ink-2); margin-top: 6px; max-width: 70ch; }

/* Stats */
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 10px; margin-bottom: 20px; }
.stat { background: var(--surface); border: 1px solid var(--line); border-radius: var(--r); padding: 12px 14px; }
.stat b { display: block; font: 600 28px/1.1 var(--serif); }
.stat span { font-size: 12.5px; color: var(--ink-2); }

/* Segmented controls & chips */
.seg { display: inline-flex; background: var(--surface-2); border-radius: 9px; padding: 3px; gap: 2px; flex-wrap: wrap; }
.seg button { border: 0; background: none; padding: 6px 12px; border-radius: 7px; font-size: 13.5px; font-weight: 500; color: var(--ink-2); }
.seg button[aria-pressed="true"] { background: var(--surface); color: var(--ink); box-shadow: var(--shadow); }
.chip { display: inline-flex; align-items: center; gap: 6px; font-size: 12px; font-weight: 500; padding: 2px 8px; border-radius: 99px; background: var(--surface-2); color: var(--ink-2); white-space: nowrap; }
.chip i { width: 8px; height: 8px; border-radius: 50%; background: var(--c, var(--ink-3)); }
.badge { display: inline-block; font-size: 11.5px; font-weight: 600; padding: 2px 8px; border-radius: 5px; }
.badge.family { background: var(--surface-2); color: var(--ink-2); }
.badge.oral { background: var(--warn-soft); color: var(--warn); }
.badge.cand { background: var(--accent-soft); color: var(--accent); }
.badge.ok { background: var(--ok-soft); color: var(--ok); }

/* Tree */
.tree-bar { display: flex; flex-wrap: wrap; gap: 12px; align-items: center; justify-content: space-between; margin-bottom: 12px; }
.tree-wrap { position: relative; background: var(--surface); border: 1px solid var(--line); border-radius: 14px; overflow: auto; min-height: 420px; max-height: calc(100vh - 230px); overscroll-behavior: contain; }
.tree-canvas { position: relative; margin: 0 auto; }
.tree-canvas svg.links { position: absolute; inset: 0; pointer-events: none; overflow: visible; }
.links path { fill: none; stroke: var(--line-2); stroke-width: 1.4; }
.links path.marriage { stroke: var(--accent); stroke-width: 1.6; stroke-dasharray: 3 4; }
.gen-label { position: absolute; top: 10px; font-size: 11px; letter-spacing: .06em; text-transform: uppercase; color: var(--ink-3); text-align: center; }
.node { position: absolute; display: flex; align-items: center; gap: 10px; padding: 8px 10px 8px 8px; background: var(--surface); border: 1px solid var(--line); border-left: 3px solid var(--c, var(--line-2)); border-radius: 9px; text-align: left; box-shadow: var(--shadow); transition: border-color .15s, transform .15s; }
.node:hover { border-color: var(--line-2); transform: translateY(-1px); }
.node[aria-current="true"] { outline: 2px solid var(--accent); outline-offset: 1px; }
.node.root { background: var(--ink); color: var(--bg); border-color: var(--ink); }
.node.root .n-sub { color: color-mix(in srgb, var(--bg) 75%, transparent); }
.node.ghost { background: transparent; border-style: dashed; border-left-width: 1px; box-shadow: none; color: var(--ink-3); cursor: default; justify-content: center; font-size: 12.5px; }
.node.ghost:hover { transform: none; }
.av { width: 38px; height: 38px; border-radius: 50%; flex: none; display: grid; place-items: center; font: 600 15px/1 var(--serif); background: var(--surface-2); color: var(--ink-2); overflow: hidden; }
.av img { width: 100%; height: 100%; object-fit: cover; }
.node.root .av { background: color-mix(in srgb, var(--bg) 18%, transparent); color: var(--bg); }
.n-text { min-width: 0; }
.n-name { font-weight: 600; font-size: 13.5px; line-height: 1.25; overflow: hidden; text-overflow: ellipsis; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; }
.n-sub { font-size: 12px; color: var(--ink-2); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.n-flag { position: absolute; top: -7px; right: 8px; font-size: 10.5px; font-weight: 700; padding: 0 6px; border-radius: 4px; background: var(--warn-soft); color: var(--warn); border: 1px solid var(--surface); }
.legend { display: flex; flex-wrap: wrap; gap: 6px 14px; margin-top: 12px; font-size: 12.5px; color: var(--ink-2); }
.legend span { display: inline-flex; align-items: center; gap: 6px; }
.legend i { width: 10px; height: 10px; border-radius: 3px; background: var(--c); }

/* Branch overview */
.branches { display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); gap: 12px; margin-top: 24px; }
.branch { background: var(--surface); border: 1px solid var(--line); border-top: 3px solid var(--c); border-radius: var(--r); padding: 14px 16px; }
.branch h3 { font: 600 21px/1.2 var(--serif); }
.branch p { font-size: 13.5px; color: var(--ink-2); margin-top: 6px; }
.branch .meta { display: flex; gap: 12px; font-size: 12.5px; color: var(--ink-3); margin-top: 10px; }
.branch button { margin-top: 10px; }

/* People */
.filters { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; margin-bottom: 16px; }
.filters input { flex: 1 1 260px; background: var(--surface); border: 1px solid var(--line); border-radius: 9px; padding: 8px 12px; }
.people-group { margin-bottom: 24px; }
.people-group > h2 { display: flex; align-items: center; gap: 10px; font-size: 22px; margin-bottom: 10px; }
.people-group > h2 i { width: 12px; height: 12px; border-radius: 3px; background: var(--c); }
.people-group > h2 small { font: 500 13px var(--sans); color: var(--ink-3); }
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 8px; }
.person { display: flex; gap: 10px; align-items: center; text-align: left; background: var(--surface); border: 1px solid var(--line); border-radius: var(--r); padding: 9px 12px 9px 9px; }
.person:hover { border-color: var(--line-2); }
.person .p-rel { font-size: 11.5px; color: var(--accent); font-weight: 600; }
.empty { padding: 32px; text-align: center; color: var(--ink-2); background: var(--surface); border: 1px dashed var(--line); border-radius: var(--r); }

/* Timeline */
.decade { display: grid; grid-template-columns: 90px 1fr; gap: 16px; padding: 14px 0; border-top: 1px solid var(--line); }
.decade > b { font: 600 24px/1 var(--serif); color: var(--ink-3); padding-top: 6px; }
.events { display: grid; gap: 6px; }
.event { display: grid; grid-template-columns: 96px 1fr; gap: 12px; align-items: baseline; text-align: left; background: none; border: 0; padding: 6px 8px; border-radius: 7px; }
.event:hover { background: var(--surface); }
.event time { font-size: 13px; color: var(--ink-2); font-variant-numeric: tabular-nums; }
.event span b { font-weight: 600; }
.event.hist { cursor: default; }
.event.hist span { color: var(--ink-2); font-style: italic; }
.event .dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; background: var(--c); margin-right: 8px; }

/* Research */
.cols { display: grid; grid-template-columns: 1.4fr 1fr; gap: 16px; align-items: start; }
.card { background: var(--surface); border: 1px solid var(--line); border-radius: 14px; padding: 18px 20px; }
.card + .card { margin-top: 16px; }
.card h2 { margin-bottom: 4px; }
.card h3 { margin: 16px 0 6px; font-size: 13px; letter-spacing: .04em; text-transform: uppercase; color: var(--ink-3); }
.card ul { margin: 0; padding-left: 18px; }
.card li { margin: 4px 0; font-size: 14px; }
.facts { display: grid; grid-template-columns: max-content 1fr; gap: 6px 16px; font-size: 14px; margin-top: 10px; }
.facts dt { color: var(--ink-3); }
.facts dd { margin: 0; }
.verdict { margin-top: 14px; padding: 12px 14px; border-radius: 9px; background: var(--accent-soft); font-size: 14px; }
.check { display: flex; gap: 10px; padding: 10px 0; border-top: 1px solid var(--line); font-size: 14px; }
.check:first-of-type { border-top: 0; }
.check b { display: block; }
.check .st { flex: none; width: 22px; height: 22px; border-radius: 50%; display: grid; place-items: center; font-size: 12px; font-weight: 700; }
.st.no { background: var(--surface-2); color: var(--ink-3); }
.st.block { background: var(--warn-soft); color: var(--warn); }
.st.yes { background: var(--ok-soft); color: var(--ok); }
.steps { counter-reset: s; list-style: none; padding: 0 !important; }
.steps li { counter-increment: s; position: relative; padding-left: 34px !important; margin: 12px 0 !important; }
.steps li::before { content: counter(s); position: absolute; left: 0; top: 0; width: 24px; height: 24px; border-radius: 50%; background: var(--ink); color: var(--bg); display: grid; place-items: center; font-size: 12px; font-weight: 700; }

/* Sources */
.src { display: flex; gap: 14px; align-items: flex-start; padding: 14px 0; border-top: 1px solid var(--line); }
.src:first-of-type { border-top: 0; }
.src code { font-size: 12px; color: var(--ink-3); background: var(--surface-2); padding: 1px 6px; border-radius: 4px; flex: none; }
.src div { flex: 1; min-width: 0; }
.src p { font-size: 13.5px; color: var(--ink-2); margin-top: 2px; }
.linkish { background: none; border: 0; padding: 0; color: var(--accent); font-weight: 600; text-decoration: underline; text-underline-offset: 3px; text-align: left; }

/* Panel */
.panel { position: fixed; top: 57px; right: 0; bottom: 0; width: var(--panel-w); background: var(--surface); border-left: 1px solid var(--line); z-index: 15; overflow-y: auto; box-shadow: -10px 0 30px rgb(0 0 0 / .04); }
.panel-inner { padding: 20px 22px 40px; }
.p-top { display: flex; justify-content: space-between; align-items: center; margin-bottom: 14px; }
.p-photo { width: 100%; aspect-ratio: 4 / 3; object-fit: cover; border-radius: 10px; margin-bottom: 14px; background: var(--surface-2); }
.p-name { font: 600 28px/1.1 var(--serif); }
.p-orig { font-size: 12.5px; color: var(--ink-3); margin-top: 4px; }
.p-badges { display: flex; gap: 6px; flex-wrap: wrap; margin: 10px 0 4px; }
.p-sec { margin-top: 18px; }
.p-sec > h3 { font-size: 11.5px; letter-spacing: .06em; text-transform: uppercase; color: var(--ink-3); margin-bottom: 6px; font-weight: 600; }
.p-sec .facts { margin-top: 0; font-size: 13.5px; }
.note { font-size: 13.5px; color: var(--ink-2); background: var(--surface-2); border-radius: 8px; padding: 10px 12px; }
.note.warn { background: var(--warn-soft); color: var(--warn); }
.rel-list { display: grid; gap: 4px; }
.rel { display: flex; gap: 10px; align-items: center; text-align: left; background: none; border: 1px solid transparent; border-radius: 8px; padding: 5px 6px; }
.rel:hover { background: var(--surface-2); }
.rel .av { width: 30px; height: 30px; font-size: 13px; }
.rel small { display: block; color: var(--ink-3); font-size: 12px; }
.p-actions { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 14px; }
.btn { border: 1px solid var(--line); background: var(--surface); border-radius: 8px; padding: 7px 12px; font-size: 13.5px; font-weight: 600; }
.btn:hover { background: var(--surface-2); }
.btn.primary { background: var(--ink); color: var(--bg); border-color: var(--ink); }
.scrim { position: fixed; inset: 0; background: rgb(0 0 0 / .35); z-index: 14; }

/* Dialogs */
dialog { border: 1px solid var(--line); border-radius: 14px; background: var(--surface); color: var(--ink); padding: 0; box-shadow: 0 20px 60px rgb(0 0 0 / .25); }
dialog::backdrop { background: rgb(20 20 15 / .45); }
.search { width: min(620px, calc(100vw - 32px)); margin-top: 10vh; }
.search-head { display: flex; align-items: center; gap: 10px; padding: 12px 14px; border-bottom: 1px solid var(--line); }
.search-head input { flex: 1; border: 0; background: none; font-size: 17px; outline: none; }
.search-results { max-height: 60vh; overflow-y: auto; padding: 6px; }
.search-results .person { width: 100%; border: 0; border-radius: 8px; }
.search-results .person:hover, .search-results .person:focus-visible { background: var(--surface-2); }
.doc { width: min(860px, calc(100vw - 32px)); height: min(86vh, 1000px); }
.doc[open] { display: flex; flex-direction: column; }
.doc-head { display: flex; align-items: center; gap: 14px; padding: 14px 18px; border-bottom: 1px solid var(--line); }
.doc-head h2 { flex: 1; font-size: 22px; }
.doc-head a { font-size: 13px; font-weight: 600; color: var(--accent); }
.prose { padding: 20px 26px 40px; overflow-y: auto; font-size: 14.5px; line-height: 1.7; }
.prose h1, .prose h2, .prose h3 { font-family: var(--serif); margin: 22px 0 8px; }
.prose h1 { font-size: 30px; } .prose h2 { font-size: 24px; } .prose h3 { font-size: 19px; }
.prose p, .prose ul, .prose ol, .prose blockquote { margin: 0 0 12px; }
.prose table { border-collapse: collapse; width: 100%; font-size: 13px; margin: 0 0 14px; display: block; overflow-x: auto; }
.prose th, .prose td { border: 1px solid var(--line); padding: 5px 8px; text-align: left; vertical-align: top; }
.prose blockquote { border-left: 3px solid var(--line-2); padding-left: 14px; color: var(--ink-2); }
.prose code { background: var(--surface-2); padding: 1px 5px; border-radius: 4px; font-size: 12.5px; }
.prose pre { background: var(--surface-2); padding: 12px; border-radius: 8px; overflow-x: auto; font-size: 12.5px; }
.noscript { padding: 24px; }

/* Responsive */
@media (max-width: 1100px) {
  body.panel-open main { padding-right: 24px; }
  .panel { top: 0; z-index: 30; width: min(var(--panel-w), 100vw); }
  .cols { grid-template-columns: 1fr; }
}
@media (max-width: 760px) {
  .top-inner { flex-wrap: wrap; gap: 8px 12px; padding: 10px 16px; }
  .tabs { order: 3; width: 100%; overflow-x: auto; margin-right: 0; }
  .tabs a { padding: 6px 10px; white-space: nowrap; }
  .search-btn { min-width: 0; margin-left: auto; }
  .search-btn kbd { display: none; }
  main { padding: 20px 16px 48px; }
  body.panel-open main { padding-right: 16px; }
  .panel { width: 100vw; }
  .tree-wrap { max-height: 70vh; }
  .stats { grid-template-columns: repeat(2, 1fr); }
  .stat b { font-size: 24px; }
  .decade { grid-template-columns: 1fr; gap: 6px; }
  .event { grid-template-columns: 78px 1fr; }
  .facts { grid-template-columns: 1fr; gap: 0 0; }
  .facts dt { margin-top: 6px; }
}
@media print {
  .top, .panel, .scrim { display: none !important; }
  main { padding: 0 !important; }
}
