:root {
  color-scheme: light;
  --ink: #24312d;
  --muted: #6c7772;
  --paper: #f6f3ec;
  --panel: #fffcf6;
  --line: #ded8cd;
  --moss: #536f61;
  --moss-dark: #334b40;
  --sage: #dfe9e2;
  --gold: #b58b45;
  --rust: #ad664e;
  --shadow: 0 14px 45px rgba(45, 55, 50, .10);
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

html, body { height: 100%; }

body {
  margin: 0;
  overflow: hidden;
  background:
    radial-gradient(circle at 17% 10%, rgba(187, 207, 190, .18), transparent 24rem),
    var(--paper);
  color: var(--ink);
  font: 14px/1.5 Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

button, input, select { font: inherit; }
button, select { cursor: pointer; }
textarea { font: inherit; }

.topbar {
  height: 72px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 24px;
  border-bottom: 1px solid var(--line);
  background: rgba(255, 252, 246, .88);
  backdrop-filter: blur(12px);
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  color: inherit;
  text-decoration: none;
}

.brand-mark {
  width: 40px;
  height: 40px;
  display: grid;
  place-items: center;
  border-radius: 50% 50% 46% 54%;
  background: var(--moss-dark);
  color: white;
  font: 600 22px/1 Georgia, serif;
  box-shadow: inset 0 0 0 3px rgba(255,255,255,.12);
}

.brand strong, .brand small { display: block; }
.brand strong { font: 600 20px/1.1 Georgia, serif; letter-spacing: .01em; }
.brand small { margin-top: 4px; color: var(--muted); font-size: 11px; letter-spacing: .06em; text-transform: uppercase; }

.header-actions { display: flex; align-items: center; gap: 16px; }

.privacy-switch {
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--muted);
  font-size: 12px;
}

.privacy-switch input { accent-color: var(--moss); }

.quiet-button, .zoom-controls button, .icon-button {
  border: 1px solid var(--line);
  background: var(--panel);
  color: var(--ink);
  border-radius: 9px;
}

.quiet-button { padding: 8px 12px; }
.quiet-button:hover, .zoom-controls button:hover { border-color: var(--moss); }

.workspace {
  height: calc(100vh - 72px);
  display: grid;
  grid-template-columns: 248px minmax(420px, 1fr) 356px;
}

.controls-panel, .detail-panel {
  overflow-y: auto;
  background: rgba(255, 252, 246, .8);
}

.controls-panel {
  padding: 24px 18px;
  border-right: 1px solid var(--line);
}

.controls-panel section + section {
  margin-top: 26px;
  padding-top: 23px;
  border-top: 1px solid var(--line);
}

.eyebrow {
  margin: 0 0 8px;
  color: var(--moss);
  font-size: 10px;
  font-weight: 750;
  letter-spacing: .13em;
  text-transform: uppercase;
}

.field-label {
  display: block;
  margin: 12px 0 6px;
  color: var(--muted);
  font-size: 11px;
}

select, input[type="search"] {
  width: 100%;
  padding: 9px 10px;
  border: 1px solid var(--line);
  border-radius: 9px;
  outline: none;
  background: #fffefa;
  color: var(--ink);
}

input[type="text"], textarea {
  width: 100%;
  padding: 9px 10px;
  border: 1px solid var(--line);
  border-radius: 9px;
  outline: none;
  background: #fffefa;
  color: var(--ink);
}

textarea { resize: vertical; }

select:focus, input[type="search"]:focus, input[type="text"]:focus, textarea:focus { border-color: var(--moss); box-shadow: 0 0 0 3px rgba(83,111,97,.10); }

.search-results {
  max-height: 220px;
  margin-top: 5px;
  overflow-y: auto;
  border: 1px solid var(--line);
  border-radius: 9px;
  background: white;
  box-shadow: var(--shadow);
}

.search-result {
  width: 100%;
  padding: 9px 10px;
  display: block;
  border: 0;
  border-bottom: 1px solid #eeeae2;
  background: transparent;
  color: var(--ink);
  text-align: left;
}

.search-result:hover { background: var(--sage); }
.search-result small { display: block; color: var(--muted); }

.view-options { display: grid; gap: 7px; margin-top: 14px; }
.view-options label { display: flex; align-items: center; gap: 8px; color: var(--ink); font-size: 11px; cursor: pointer; }
.view-options input { accent-color: var(--moss); }
.context-note { margin: 10px 0 0; padding: 9px; border-radius: 8px; background: #edf3ee; color: var(--muted); font-size: 10px; line-height: 1.4; }
.context-note strong { display: block; color: var(--moss-dark); }
.panel-button { width: 100%; margin-top: 12px; padding: 8px 10px; border: 1px solid #d8c28f; border-radius: 9px; background: #fff7df; color: #674f16; font-size: 11px; font-weight: 700; }
.panel-button:hover { border-color: var(--gold); }

.metric-card strong, .metric-card span { display: block; }
.metric-card strong { font: 600 18px/1.25 Georgia, serif; }
.metric-card span:last-child { margin-top: 5px; color: var(--muted); font-size: 12px; }

.section-heading { display: flex; align-items: start; justify-content: space-between; }
.count-pill { min-width: 22px; padding: 2px 7px; border-radius: 12px; background: var(--sage); color: var(--moss-dark); font-size: 11px; text-align: center; }

.hypothesis-card {
  margin-top: 10px;
  padding: 11px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: rgba(255,255,255,.55);
}

.hypothesis-card strong { display: block; font-size: 12px; }
.hypothesis-card p { margin: 5px 0 8px; color: var(--muted); font-size: 11px; }
.hypothesis-option { display: flex; align-items: start; gap: 6px; margin-top: 6px; font-size: 11px; }
.hypothesis-option input { margin-top: 3px; accent-color: var(--moss); }
.unresolved-option { color: var(--rust); font-style: italic; }
.default-marker { display: inline-block; margin-left: 3px; padding: 1px 4px; border-radius: 5px; background: var(--sage); color: var(--moss-dark); font-size: 9px; font-style: normal; }
.branch-actions { display: flex; gap: 5px; margin-top: 10px; }
.branch-actions button { padding: 5px 7px; border: 1px solid var(--line); border-radius: 7px; background: #fffefa; color: var(--moss-dark); font-size: 9px; }
.branch-actions button:hover { border-color: var(--moss); }
.branch-help { display: block; margin-top: 5px; color: var(--muted); font-size: 9px; line-height: 1.3; }

.legend span { display: flex; align-items: center; gap: 7px; margin: 7px 0; color: var(--muted); font-size: 11px; }
.confidence-dot { width: 9px; height: 9px; flex: none; border-radius: 50%; }
.confidence-dot.high { background: #34735c; }
.confidence-dot.strong { background: #719069; }
.confidence-dot.plausible { background: var(--gold); }
.confidence-dot.speculative { background: var(--rust); }
.legend .line-key { margin-top: 9px; }
.line-sample { width: 22px; height: 0; flex: none; border-top: 2px solid var(--moss); }
.line-sample.dashed { border-color: var(--rust); border-top-style: dashed; }
.line-sample.context { border-color: #8b9691; border-top-style: dotted; }

.tree-shell { min-width: 0; min-height: 0; display: flex; flex-direction: column; }
.tree-toolbar { min-height: 78px; display: flex; align-items: center; justify-content: space-between; padding: 14px 20px; border-bottom: 1px solid var(--line); }
.tree-toolbar h1 { margin: 0; font: 500 23px/1.1 Georgia, serif; }
.zoom-controls { display: flex; gap: 4px; }
.zoom-controls button { min-width: 34px; height: 32px; padding: 0 9px; }

.tree-viewport {
  position: relative;
  flex: 1;
  min-height: 0;
  overflow: auto;
  overscroll-behavior: contain;
  touch-action: none;
  cursor: grab;
  background-image:
    linear-gradient(rgba(75, 94, 83, .045) 1px, transparent 1px),
    linear-gradient(90deg, rgba(75, 94, 83, .045) 1px, transparent 1px);
  background-size: 32px 32px;
}

.tree-viewport.is-panning { cursor: grabbing; }
.tree-viewport.is-panning, .tree-viewport.is-panning * { user-select: none; }
.gesture-help {
  position: sticky;
  left: 12px;
  top: 12px;
  z-index: 3;
  width: max-content;
  max-width: calc(100% - 24px);
  margin: 12px 0 -39px 12px;
  padding: 5px 8px;
  border: 1px solid rgba(222, 216, 205, .8);
  border-radius: 7px;
  background: rgba(255, 252, 246, .86);
  color: var(--muted);
  font-size: 9px;
  pointer-events: none;
  backdrop-filter: blur(5px);
}

.tree-canvas {
  position: relative;
  flex: none;
}

#tree-svg {
  position: absolute;
  display: block;
}

.tree-edge { fill: none; stroke-width: 2; opacity: .72; }
.tree-edge.high { stroke: #34735c; }
.tree-edge.strong { stroke: #719069; }
.tree-edge.plausible { stroke: var(--gold); }
.tree-edge.speculative { stroke: var(--rust); stroke-dasharray: 6 5; }
.tree-edge.context { stroke: #8b9691; stroke-width: 1.5; stroke-dasharray: 2 5; opacity: .58; }
.context-rail-label { fill: #7f8b85; font-size: 9px; font-weight: 750; letter-spacing: .12em; }

.person-node { cursor: pointer; filter: drop-shadow(0 7px 11px rgba(41, 54, 47, .10)); }
.person-node .card-bg { fill: #fffefa; stroke: #d8d2c8; stroke-width: 1; }
.person-node.sex-f .card-bg { fill: #fff0f6; }
.person-node.sex-m .card-bg { fill: #eef6ff; }
.person-node:hover .card-bg { stroke: var(--moss); stroke-width: 2; }
.person-node.selected { filter: drop-shadow(0 12px 18px rgba(38, 67, 53, .28)); }
.person-node.selected .card-bg { fill: #f0f7f1; stroke: var(--moss-dark); stroke-width: 3; }
.person-node.selected.sex-f .card-bg { fill: #ffe6f0; }
.person-node.selected.sex-m .card-bg { fill: #e2f0ff; }
.person-node.user-added .card-bg { fill: #fff7df; stroke: #d7ae4f; stroke-width: 1.5; }
.person-node.user-added.selected .card-bg { fill: #fff0c6; stroke: #9b741d; stroke-width: 3; }
.person-node .selection-halo { fill: rgba(83,111,97,.12); stroke: rgba(83,111,97,.42); stroke-width: 2; }
.person-node .accent { fill: var(--moss); }
.person-node.private .accent { fill: #756b80; }
.person-node.user-added .accent { fill: var(--gold); }
.person-node.context-node .card-bg { fill: #fbfaf6; }
.person-node.context-node .accent { fill: #99a49e; }
.person-node foreignObject, .person-node foreignObject * { pointer-events: none; }
.person-node .node-added-badge { margin-bottom: 2px; color: #7b5b13; font-size: 8px; font-weight: 800; letter-spacing: .08em; text-transform: uppercase; }
.person-node .node-context-kind { margin-bottom: 2px; color: #87908c; font-size: 8px; font-weight: 750; letter-spacing: .08em; text-transform: uppercase; }
.person-node .node-name { color: var(--ink); font: 600 13px/1.25 Georgia, serif; }
.person-node .node-dates { margin-top: 6px; color: var(--muted); font-size: 10px; }
.person-node .node-place { margin-top: 2px; color: #87908c; font-size: 9px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.person-node .node-profession { margin-top: 5px; color: var(--moss-dark); font-size: 9px; font-weight: 650; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.person-node .confidence-badge { fill: var(--sage); }
.person-node .confidence-text { fill: var(--moss-dark); font-size: 9px; font-weight: 700; }
.person-node .extra-indicator rect { fill: #eee7d8; }
.person-node .extra-indicator text { fill: #7d6335; font-size: 10px; font-weight: 800; font-style: italic; }
.person-node .child-chip.boy { fill: #dbeaf6; stroke: #a9c9df; }
.person-node .child-chip.girl { fill: #f6dfe9; stroke: #dfb4c8; }
.person-node .child-chip.unknown { fill: #eceae5; stroke: #cbc7bd; }
.person-node .child-chip { stroke-width: .7; }
.person-node .child-chip-text { font-size: 8.5px; font-weight: 750; }
.person-node .child-chip-text.boy { fill: #365f7b; }
.person-node .child-chip-text.girl { fill: #85516a; }
.person-node .child-chip-text.unknown { fill: #746f66; }

.empty-state { position: absolute; inset: 0; display: grid; place-items: center; color: var(--muted); }

.detail-panel { padding: 24px; border-left: 1px solid var(--line); }
.detail-placeholder { max-width: 240px; margin: 24vh auto 0; text-align: center; color: var(--muted); }
.detail-placeholder h2 { margin: 8px 0; color: var(--ink); font: 500 22px Georgia, serif; }
.placeholder-mark { color: var(--moss); font-size: 34px; }

.person-header { padding-bottom: 18px; border-bottom: 1px solid var(--line); }
.person-header h2 { margin: 3px 0 5px; font: 500 28px/1.12 Georgia, serif; }
.person-header p { margin: 0; color: var(--muted); }
.privacy-label, .status-label { display: inline-block; margin-top: 10px; padding: 3px 7px; border-radius: 12px; background: #ece6f0; color: #675b70; font-size: 10px; }
.user-added-label { display: inline-block; margin-top: 10px; margin-left: 5px; padding: 3px 7px; border-radius: 12px; background: #fff0c6; color: #785912; font-size: 10px; }

.detail-section { padding: 20px 0; border-bottom: 1px solid var(--line); }
.detail-section h3 { margin: 0 0 12px; font-size: 12px; text-transform: uppercase; letter-spacing: .08em; }

.timeline-item { position: relative; margin-left: 7px; padding: 0 0 16px 19px; border-left: 1px solid #ccd5ce; }
.timeline-item::before { content: ""; position: absolute; left: -4px; top: 5px; width: 7px; height: 7px; border-radius: 50%; background: var(--moss); }
.timeline-item:last-child { padding-bottom: 0; }
.timeline-item strong, .timeline-item span { display: block; }
.timeline-item strong { font-size: 12px; text-transform: capitalize; }
.timeline-item span { color: var(--muted); font-size: 11px; }
.timeline-item .event-rationale { margin-top: 4px; color: #7b837f; }

.relationship-row { display: grid; grid-template-columns: 1fr auto; gap: 8px; padding: 8px 0; border-bottom: 1px dashed #e3ded6; }
.relationship-row:last-child { border: 0; }
.relationship-row button { padding: 0; border: 0; background: transparent; color: var(--moss-dark); text-align: left; }
.relationship-row small { display: block; color: var(--muted); }
.private-connections { margin-top: 10px; padding: 10px; border: 1px solid #d8cfdf; border-radius: 9px; background: #f5f0f7; }
.private-connections strong, .private-connections span { display: block; }
.private-connections span { margin: 2px 0 7px; color: var(--muted); font-size: 10px; }
.private-connections button { padding: 5px 8px; border: 1px solid #c8bbd0; border-radius: 7px; background: white; color: #675b70; font-size: 10px; }

.occupation-row { display: grid; grid-template-columns: 22px 1fr; gap: 7px; padding: 7px 0; border-bottom: 1px dashed #e3ded6; }
.occupation-row:last-child { border-bottom: 0; }
.occupation-row > span { color: var(--moss); }
.occupation-row strong, .occupation-row small { display: block; }
.occupation-row small { color: var(--muted); font-size: 10px; }

.score { min-width: 34px; align-self: start; padding: 3px 6px; border-radius: 10px; color: white; font-size: 10px; text-align: center; }
.score.high { background: #34735c; }
.score.strong { background: #719069; }
.score.plausible { background: var(--gold); }
.score.speculative { background: var(--rust); }

.claim-card { margin: 10px 0; padding: 12px; border: 1px solid var(--line); border-radius: 10px; background: rgba(255,255,255,.55); }
.claim-card.disputed { border-color: #d9a18e; background: #fff8f5; }
.claim-heading { display: flex; justify-content: space-between; gap: 8px; }
.claim-card h4 { margin: 0; font-size: 12px; }
.claim-card > p { margin: 6px 0; color: var(--muted); font-size: 11px; }
.evidence-item { margin-top: 9px; padding-top: 9px; border-top: 1px dashed var(--line); font-size: 11px; }
.evidence-item a { color: var(--moss-dark); font-weight: 650; text-decoration-thickness: 1px; text-underline-offset: 2px; }
.evidence-item blockquote { margin: 6px 0 0; padding-left: 9px; border-left: 2px solid var(--sage); color: var(--muted); }
.evidence-translation { margin: 7px 0 0; color: var(--ink); line-height: 1.45; }

.research-mini { margin: 10px 0; }
.research-mini strong { display: block; font-size: 12px; }
.research-mini p { margin: 3px 0; color: var(--muted); font-size: 11px; }

dialog {
  width: min(720px, calc(100vw - 40px));
  max-height: min(760px, calc(100vh - 40px));
  padding: 0;
  border: 1px solid var(--line);
  border-radius: 16px;
  background: var(--panel);
  color: var(--ink);
  box-shadow: 0 30px 90px rgba(30, 38, 34, .26);
}
dialog::backdrop { background: rgba(29, 37, 33, .42); backdrop-filter: blur(3px); }
.dialog-heading { position: sticky; top: 0; display: flex; align-items: center; justify-content: space-between; padding: 20px 24px 15px; border-bottom: 1px solid var(--line); background: var(--panel); }
.dialog-heading h2 { margin: 0; font: 500 25px Georgia, serif; }
.icon-button { width: 34px; height: 34px; font-size: 21px; }
.padded-dialog-body { padding: 18px 24px; }
.person-form { margin: 0; }
.form-note { margin: 0 0 12px; color: var(--muted); font-size: 11px; line-height: 1.45; }
.dialog-actions { display: flex; justify-content: flex-end; gap: 8px; padding: 14px 24px 20px; border-top: 1px solid var(--line); }
.primary-button { border-color: #d8c28f; background: #fff0c6; color: #674f16; font-weight: 700; }
.research-log { padding: 8px 24px 24px; overflow-y: auto; }
.research-entry { padding: 15px 0; border-bottom: 1px solid var(--line); }
.research-entry:last-child { border: 0; }
.research-entry h3 { margin: 3px 0; font-size: 13px; }
.research-entry p { margin: 4px 0; color: var(--muted); }
.research-entry a { color: var(--moss-dark); }
.outcome { display: inline-block; padding: 2px 7px; border-radius: 10px; background: var(--sage); color: var(--moss-dark); font-size: 10px; }
.outcome.partial, .outcome.queued { background: #f1e4cd; color: #755b2b; }

@media (max-width: 1100px) {
  .workspace { grid-template-columns: 220px 1fr 320px; }
}

@media (max-width: 850px) {
  body { overflow: auto; }
  .topbar { position: sticky; top: 0; z-index: 4; }
  .privacy-switch span { display: none; }
  .workspace { height: auto; min-height: calc(100vh - 72px); grid-template-columns: 1fr; }
  .controls-panel { border-right: 0; border-bottom: 1px solid var(--line); }
  .tree-shell {
    height: min(760px, calc(100vh - 72px));
    height: min(760px, calc(100svh - 72px));
    min-height: 560px;
  }
  .detail-panel { min-height: 50vh; border-left: 0; border-top: 1px solid var(--line); }
  .detail-placeholder { margin-top: 60px; }
}
