:root {
  color-scheme: light;
  --page: #d6d0c4;
  --page-deep: #c6cfd0;
  --workspace: rgba(249, 247, 242, 0.94);
  --workspace-strong: rgba(255, 252, 246, 0.98);
  --canvas: #e2e5de;
  --canvas-grid: rgba(65, 82, 70, 0.08);
  --line: rgba(118, 88, 61, 0.18);
  --line-strong: rgba(118, 88, 61, 0.34);
  --ink: #261f1a;
  --muted: #64584c;
  --muted-strong: #4a4036;
  --accent: #7d4f2c;
  --accent-strong: #61361c;
  --accent-soft: #efe0cf;
  --green: #2f6153;
  --green-soft: #e6f0ec;
  --blue: #43637c;
  --blue-soft: #e8edf2;
  --shadow: 0 18px 38px rgba(34, 28, 23, 0.12);
  --shadow-strong: 0 28px 64px rgba(34, 28, 23, 0.18);
  --radius: 8px;
  --sidebar-width: 336px;
  --details-width: 400px;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* {
  box-sizing: border-box;
}

html,
body {
  height: 100%;
}

body {
  margin: 0;
  color: var(--ink);
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.32), transparent 28%),
    linear-gradient(90deg, var(--page), var(--page-deep) 52%, #d8d7cf);
  overflow: hidden;
}

body.people-collapsed {
  --sidebar-width: 0px;
}

body.profile-collapsed {
  --details-width: 0px;
}

button,
input {
  font: inherit;
}

button {
  appearance: none;
  border: 0;
}

button,
input,
a {
  transition:
    background-color 160ms ease,
    border-color 160ms ease,
    color 160ms ease,
    box-shadow 160ms ease,
    transform 160ms ease,
    opacity 160ms ease;
}

:focus-visible {
  outline: 2px solid rgba(47, 97, 83, 0.7);
  outline-offset: 2px;
}

h1,
h2,
h3,
p,
dt,
dd,
small,
span,
strong {
  overflow-wrap: anywhere;
}

h1,
h2 {
  margin: 0;
  line-height: 1.06;
  font-family: Georgia, "Times New Roman", serif;
}

h1 {
  font-size: 1.95rem;
}

h2 {
  font-size: 1.12rem;
}

h3 {
  margin: 0 0 8px;
  font-size: 0.82rem;
  font-weight: 800;
  color: var(--muted);
  text-transform: uppercase;
}

.app-shell {
  display: grid;
  grid-template-columns: var(--sidebar-width) minmax(0, 1fr) var(--details-width);
  height: 100dvh;
}

.sidebar,
.details {
  min-width: 0;
  background: var(--workspace);
  backdrop-filter: blur(14px);
  overflow: hidden;
  transition:
    opacity 180ms ease,
    transform 180ms ease,
    border-color 180ms ease;
}

.sidebar {
  border-right: 1px solid var(--line);
}

.details {
  border-left: 1px solid var(--line);
}

.sidebar-shell,
.details-shell {
  height: 100%;
  overflow-y: auto;
  padding: 28px 24px 32px;
  display: grid;
  align-content: start;
  gap: 24px;
  scrollbar-gutter: stable;
}

.people-collapsed .sidebar,
.profile-collapsed .details {
  opacity: 0;
  pointer-events: none;
}

.people-collapsed .sidebar {
  transform: translateX(-18px);
}

.profile-collapsed .details {
  transform: translateX(18px);
}

.tree-area {
  min-width: 0;
  min-height: 0;
  padding: 22px;
}

.tree-shell {
  height: 100%;
  min-height: 0;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  gap: 14px;
}

.brand-block {
  display: grid;
  gap: 8px;
}

.shell-copy,
.tree-subtitle {
  margin: 0;
  color: var(--muted);
  font-size: 0.92rem;
  line-height: 1.5;
}

.eyebrow {
  margin: 0;
  color: var(--accent);
  font-size: 0.72rem;
  font-weight: 900;
  text-transform: uppercase;
}

.workspace-section {
  display: grid;
  gap: 14px;
  padding-top: 20px;
  border-top: 1px solid var(--line);
}

.workspace-section-intro {
  padding-top: 0;
  border-top: 0;
}

.profile-section {
  gap: 16px;
}

.section-heading {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
}

.section-heading > div {
  min-width: 0;
}

.section-meta {
  margin: 0;
  color: var(--muted);
  font-size: 0.82rem;
  line-height: 1.4;
}

.section-heading > .section-meta {
  text-align: right;
}

.search {
  display: grid;
  gap: 8px;
  color: var(--muted-strong);
  font-size: 0.84rem;
  font-weight: 700;
}

.search input {
  width: 100%;
  height: 44px;
  border: 1px solid var(--line-strong);
  border-radius: var(--radius);
  padding: 0 14px;
  color: var(--ink);
  background: var(--workspace-strong);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.72);
}

.search input:hover {
  border-color: rgba(67, 99, 124, 0.4);
}

.search input:focus-visible {
  border-color: rgba(47, 97, 83, 0.7);
}

.toolbar {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
}

.file-input {
  position: absolute;
  width: 1px;
  height: 1px;
  opacity: 0;
  pointer-events: none;
}

.toolbar button,
.profile-actions button,
.view-actions button,
.window-close {
  min-height: 38px;
  border: 1px solid var(--line-strong);
  border-radius: var(--radius);
  padding: 0 12px;
  background: var(--workspace-strong);
  color: var(--ink);
  font-weight: 800;
  cursor: pointer;
  box-shadow: 0 1px 0 rgba(255, 255, 255, 0.7);
}

.toolbar button:hover,
.profile-actions button:hover,
.view-actions button:hover,
.window-close:hover,
.toolbar button:focus-visible,
.profile-actions button:focus-visible,
.view-actions button:focus-visible,
.window-close:focus-visible {
  border-color: rgba(67, 99, 124, 0.48);
  background: #fffdf8;
  box-shadow: 0 8px 16px rgba(34, 28, 23, 0.08);
}

.toolbar button:active,
.profile-actions button:active,
.view-actions button:active,
.window-close:active {
  transform: translateY(1px);
}

.toolbar button:disabled,
.profile-actions button:disabled,
.view-actions button:disabled,
.window-close:disabled {
  opacity: 0.52;
  cursor: default;
  box-shadow: none;
}

.data-status {
  padding: 12px 14px;
  border: 1px solid rgba(47, 97, 83, 0.26);
  border-radius: var(--radius);
  background: rgba(255, 252, 246, 0.9);
  color: var(--muted);
  font-size: 0.82rem;
  font-weight: 700;
  line-height: 1.45;
}

.data-status::before {
  content: "Local only";
  display: inline-block;
  margin-right: 8px;
  color: var(--green);
  font-weight: 900;
  text-transform: uppercase;
}

.data-status.success {
  border-color: rgba(47, 97, 83, 0.42);
  background: rgba(230, 240, 236, 0.88);
}

.data-status.error {
  border-color: rgba(125, 79, 44, 0.42);
  background: rgba(249, 233, 223, 0.92);
  color: var(--accent-strong);
}

.person-list,
.relation-list,
.source-list {
  display: grid;
  gap: 10px;
}

.person-group-header {
  position: sticky;
  top: 0;
  z-index: 2;
  margin: 4px 0 -4px;
  padding: 6px 2px 4px;
  background: #f9f7f2;
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted);
  border-bottom: 1px solid rgba(67, 99, 124, 0.16);
}

.person-row,
.relation-item,
.source-item {
  width: 100%;
  display: grid;
  gap: 6px;
  border: 1px solid rgba(67, 99, 124, 0.16);
  border-radius: var(--radius);
  padding: 12px 13px;
  background: rgba(255, 252, 246, 0.92);
  color: var(--ink);
  text-align: left;
  text-decoration: none;
  cursor: pointer;
}

.person-row:hover,
.relation-item:hover,
.source-item:hover,
.person-row:focus-visible,
.relation-item:focus-visible,
.source-item:focus-visible {
  border-color: rgba(67, 99, 124, 0.38);
  background: #fffdfa;
  box-shadow: 0 10px 18px rgba(34, 28, 23, 0.08);
}

.person-row {
  grid-template-columns: auto 1fr;
  column-gap: 11px;
  align-items: start;
}

.person-row-avatar {
  position: relative;
  width: 38px;
  height: 38px;
  margin-top: 2px;
  border-radius: 50%;
  overflow: hidden;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: rgba(67, 99, 124, 0.14);
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
  letter-spacing: 0.02em;
}

.person-row-avatar img {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.person-row-body {
  display: grid;
  gap: 6px;
  min-width: 0;
}

.person-row-main,
.relation-name {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 10px;
}

.person-row-name,
.relation-name strong,
.source-title {
  font-weight: 800;
}

.source-heading {
  display: flex;
  align-items: baseline;
  gap: 8px;
  min-width: 0;
}

.source-badge {
  flex: none;
  padding: 2px 7px;
  border-radius: 999px;
  border: 1px solid rgba(67, 99, 124, 0.24);
  background: rgba(67, 99, 124, 0.1);
  color: var(--muted);
  font-size: 10.5px;
  font-weight: 800;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  white-space: nowrap;
}

.source-badge.source-quality-record {
  background: var(--green-soft);
  border-color: rgba(42, 107, 80, 0.24);
  color: var(--green);
}

.source-badge.source-quality-lead,
.source-badge.source-quality-index,
.source-badge.source-quality-memorial {
  background: #f6ecd4;
  border-color: rgba(124, 90, 20, 0.24);
  color: #7c5a14;
}

.source-badge.source-quality-conflict {
  background: #f6e1dc;
  border-color: rgba(140, 49, 38, 0.22);
  color: #8c3126;
}

.source-badge.source-quality-note {
  background: rgba(90, 74, 140, 0.1);
  border-color: rgba(90, 74, 140, 0.24);
  color: #5a4a8c;
}

.source-badge.source-quality-photo {
  background: rgba(67, 99, 124, 0.1);
  color: var(--muted-strong);
}

.person-row-years,
.relation-meta,
.source-meta,
.source-item p,
.empty-state-copy,
.notes,
dd,
.profile-photo p {
  color: var(--muted);
}

.person-row-meta,
.person-row-flags,
.detail-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

/* Clickable chain from the tree focus to the selected person. */
.detail-path {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 2px 4px;
  margin: 2px 0 4px;
  font-size: 0.78rem;
  line-height: 1.5;
}

.path-step {
  border: none;
  background: none;
  padding: 0;
  font: inherit;
  color: var(--accent);
  cursor: pointer;
  text-decoration: underline;
  text-decoration-color: transparent;
  transition: text-decoration-color 120ms ease;
}

.path-step:hover,
.path-step:focus-visible {
  text-decoration-color: currentColor;
}

.path-step:disabled {
  color: var(--muted-strong);
  cursor: default;
  text-decoration: none;
  font-weight: 600;
}

.path-hop {
  color: var(--muted);
  font-size: 0.72rem;
}

.person-row-match {
  display: block;
  color: var(--muted);
  font-size: 11.5px;
  line-height: 1.4;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.person-row-match mark {
  background: rgba(125, 79, 44, 0.18);
  color: inherit;
  border-radius: 3px;
  padding: 0 2px;
  font-weight: 700;
}

.person-row.active {
  border-color: rgba(47, 97, 83, 0.56);
  background: var(--green-soft);
}

.person-row.focused {
  border-color: rgba(125, 79, 44, 0.44);
}

.person-row.active.focused {
  background:
    linear-gradient(135deg, rgba(230, 240, 236, 0.94), rgba(239, 224, 207, 0.96));
}

.person-pill,
.meta-pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-height: 24px;
  padding: 0 9px;
  border-radius: 999px;
  background: rgba(67, 99, 124, 0.1);
  color: var(--muted-strong);
  font-size: 0.74rem;
  font-weight: 800;
}

.person-pill.selected,
.meta-pill.selected {
  background: var(--green-soft);
  color: var(--green);
}

.person-pill.focused,
.meta-pill.focused {
  background: var(--accent-soft);
  color: var(--accent-strong);
}

.meta-pill.status-verified {
  background: var(--green-soft);
  color: var(--green);
}

.meta-pill.status-lead {
  background: #f6ecd4;
  color: #7c5a14;
}

.meta-pill.status-attention {
  background: #f6e1dc;
  color: #8c3126;
}

/* Clickable tag pills are buttons that run a tag search on click. */
.meta-pill.clickable {
  border: 0;
  font-family: inherit;
  cursor: pointer;
  transition: filter 120ms ease, box-shadow 120ms ease;
}

.meta-pill.clickable:hover,
.meta-pill.clickable:focus-visible {
  filter: brightness(0.94);
  box-shadow: inset 0 0 0 1px currentColor;
}

.fact-tags {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.evidence-coverage {
  display: grid;
  gap: 10px;
  padding: 12px 14px;
  border: 1px solid rgba(67, 99, 124, 0.18);
  border-radius: var(--radius);
  background: rgba(255, 252, 246, 0.68);
}

.evidence-summary {
  margin: -4px 0 0;
  color: var(--muted);
  font-size: 0.82rem;
  font-weight: 700;
}

.evidence-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 8px;
}

.evidence-item {
  display: grid;
  gap: 4px;
  min-width: 0;
  padding: 10px;
  border-left: 3px solid rgba(67, 99, 124, 0.26);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.48);
}

.evidence-item strong {
  color: var(--ink);
  font-size: 0.82rem;
}

.evidence-item small {
  color: var(--muted);
  font-size: 0.74rem;
  line-height: 1.35;
}

.evidence-status {
  justify-self: start;
  padding: 2px 7px;
  border-radius: 999px;
  font-size: 0.66rem;
  font-weight: 900;
  text-transform: uppercase;
}

.evidence-sourced {
  border-left-color: var(--green);
}

.evidence-sourced .evidence-status {
  background: var(--green-soft);
  color: var(--green);
}

.evidence-lead {
  border-left-color: #b88925;
}

.evidence-lead .evidence-status {
  background: #f6ecd4;
  color: #7c5a14;
}

.evidence-missing {
  border-left-color: rgba(100, 88, 76, 0.44);
}

.evidence-missing .evidence-status,
.evidence-not-applicable .evidence-status {
  background: rgba(67, 99, 124, 0.1);
  color: var(--muted-strong);
}

.evidence-attention {
  border-left-color: #b84f3e;
}

.evidence-attention .evidence-status {
  background: #f6e1dc;
  color: #8c3126;
}

.evidence-toggle {
  align-self: start;
  border: none;
  background: none;
  padding: 0;
  font: inherit;
  font-size: 0.76rem;
  color: var(--accent);
  cursor: pointer;
  text-decoration: underline;
  text-decoration-color: transparent;
  transition: text-decoration-color 120ms ease;
}

.evidence-toggle:hover,
.evidence-toggle:focus-visible {
  text-decoration-color: currentColor;
}

.empty-state {
  padding: 15px 14px;
  border: 1px dashed rgba(67, 99, 124, 0.28);
  border-radius: var(--radius);
  background: rgba(255, 252, 246, 0.58);
}

.empty-state strong {
  display: block;
  margin-bottom: 4px;
  font-size: 0.88rem;
}

.empty-state p {
  margin: 0;
  font-size: 0.82rem;
  line-height: 1.45;
}

.empty {
  margin: 0;
  font-size: 0.88rem;
}

.tree-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  padding: 16px 18px;
  border: 1px solid rgba(67, 99, 124, 0.18);
  border-radius: var(--radius);
  background: rgba(249, 247, 242, 0.88);
  backdrop-filter: blur(12px);
  box-shadow: var(--shadow);
}

.tree-heading {
  min-width: 0;
  display: grid;
  gap: 6px;
}

.tree-tools {
  display: flex;
  align-items: flex-start;
  justify-content: flex-end;
  gap: 14px;
  min-width: 0;
}

.tree-summary {
  display: grid;
  justify-items: end;
}

.legend {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 10px;
  color: var(--muted);
  font-size: 0.75rem;
  font-weight: 800;
}

.legend span {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.legend-swatch {
  width: 14px;
  height: 8px;
  border-radius: 999px;
  background: var(--green);
}

.legend-swatch.collateral {
  background: rgba(100, 88, 76, 0.56);
}

/* Ancestor branch sides: the stripe on ancestor cards and its legend swatch
   share these two tints — first-listed parent's branch, then the second's. */
.legend-branches {
  display: contents;
}

.legend-swatch.branch-0 {
  background: var(--blue);
}

.legend-swatch.branch-1 {
  background: #8a4a63;
}

.tree-node .branch-stripe {
  stroke: none;
  filter: none;
  pointer-events: none;
}

.tree-node.branch-side-0 .branch-stripe {
  fill: rgba(67, 99, 124, 0.8);
}

.tree-node.branch-side-1 .branch-stripe {
  fill: rgba(138, 74, 99, 0.75);
}

.tree-node.dimmed .branch-stripe {
  opacity: 0.5;
}

.view-actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 8px;
}

.view-actions button[aria-pressed="true"],
.view-actions .board-tab.active,
.profile-actions button[aria-expanded="true"],
.toolbar button.active {
  border-color: rgba(47, 97, 83, 0.5);
  background: var(--green-soft);
  color: var(--green);
}

.board-panel {
  min-height: 0;
  display: none;
}

.board-panel.active {
  display: grid;
}

.tree-stage {
  min-height: 0;
  grid-template-rows: auto minmax(0, 1fr);
  gap: 12px;
}

.map-board,
.research-board {
  grid-template-rows: auto minmax(0, 1fr);
  gap: 12px;
  min-height: 0;
}

.board-summary {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  min-width: 0;
  padding: 14px 16px;
  border: 1px solid rgba(67, 99, 124, 0.18);
  border-radius: var(--radius);
  background: rgba(249, 247, 242, 0.84);
  box-shadow: var(--shadow);
}

.map-grid {
  min-height: 0;
  display: grid;
  grid-template-columns: minmax(0, 1fr) 320px;
  gap: 12px;
}

.map-canvas,
.map-timeline,
.research-panel {
  min-height: 0;
  border: 1px solid rgba(67, 99, 124, 0.18);
  border-radius: var(--radius);
  background: rgba(255, 252, 246, 0.9);
  box-shadow: var(--shadow);
}

.map-canvas {
  overflow: hidden;
}

#map-svg {
  display: block;
  width: 100%;
  height: 100%;
  min-height: 520px;
}

.map-background {
  fill: rgba(232, 237, 242, 0.9);
}

.map-path {
  stroke: var(--blue);
  stroke-width: 2.5;
  stroke-dasharray: 8 7;
}

.map-dot {
  cursor: pointer;
}

.map-dot circle {
  fill: var(--accent);
  stroke: #fffaf3;
  stroke-width: 2;
  filter: drop-shadow(0 4px 6px rgba(34, 28, 23, 0.22));
}

.map-dot.active circle {
  fill: var(--green);
  stroke: var(--green-soft);
  stroke-width: 3;
}

.map-label {
  fill: var(--muted-strong);
  font-size: 11px;
  font-weight: 800;
  paint-order: stroke;
  stroke: rgba(255, 252, 246, 0.88);
  stroke-width: 4px;
}

.map-timeline,
.research-panel {
  overflow-y: auto;
  padding: 16px;
}

.research-grid {
  min-height: 0;
  display: grid;
  grid-template-columns: repeat(2, minmax(240px, 1fr));
  gap: 12px;
  overflow-y: auto;
}

.research-panel-wide {
  grid-column: 1 / -1;
}

.compact-facts {
  display: grid;
  grid-template-columns: minmax(76px, auto) 1fr;
  gap: 8px 12px;
  margin: 0;
}

.agent-list,
.claim-list {
  display: grid;
  gap: 8px;
}

.agent-item,
.claim-card {
  margin: 0;
  padding: 11px 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: rgba(249, 247, 242, 0.72);
}

.claim-card {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 10px;
  align-items: center;
}

.claim-card strong,
.claim-card small,
.claim-card p {
  display: block;
}

.claim-card small {
  margin-top: 4px;
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 800;
  text-transform: uppercase;
}

.claim-card p {
  margin: 8px 0 0;
  color: var(--muted);
  font-size: 0.86rem;
  line-height: 1.45;
}

.claim-card button {
  min-height: 34px;
  border: 1px solid var(--line-strong);
  border-radius: var(--radius);
  padding: 0 10px;
  background: var(--workspace-strong);
  color: var(--ink);
  font-weight: 800;
  cursor: pointer;
}

.claim-card--confirmed {
  border-left: 4px solid var(--green);
}

.claim-card--lead,
.claim-card--needs-review,
.claim-card--normal {
  border-left: 4px solid var(--accent);
}

.claim-card--conflict,
.claim-card--high {
  border-left: 4px solid #9f3d37;
}

.tree-focus-bar {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
}

.focus-card {
  display: grid;
  gap: 4px;
  min-width: 0;
  padding: 14px 16px;
  border: 1px solid rgba(67, 99, 124, 0.18);
  border-radius: var(--radius);
  background: rgba(249, 247, 242, 0.84);
  backdrop-filter: blur(10px);
  box-shadow: var(--shadow);
}

.focus-card-root {
  border-color: rgba(125, 79, 44, 0.28);
}

.focus-card-selected {
  border-color: rgba(47, 97, 83, 0.26);
}

.focus-label {
  color: var(--muted);
  font-size: 0.74rem;
  font-weight: 800;
  text-transform: uppercase;
}

.focus-card strong {
  font-size: 0.98rem;
}

.tree-count {
  color: var(--muted);
  font-size: 0.82rem;
  line-height: 1.45;
}

.tree-viewport {
  position: relative;
  min-height: 0;
  overflow: hidden;
  cursor: grab;
  touch-action: none;
  border: 1px solid rgba(67, 99, 124, 0.18);
  border-radius: var(--radius);
  background:
    linear-gradient(var(--canvas-grid) 1px, transparent 1px),
    linear-gradient(90deg, var(--canvas-grid) 1px, transparent 1px),
    linear-gradient(180deg, rgba(255, 255, 255, 0.2), rgba(255, 255, 255, 0)),
    var(--canvas);
  background-size: 36px 36px, 36px 36px, auto, auto;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.54);
}

.tree-viewport:active {
  cursor: grabbing;
}

.zoom-controls {
  position: absolute;
  right: 12px;
  bottom: 12px;
  display: grid;
  gap: 6px;
  z-index: 5;
}

.zoom-controls button {
  width: 38px;
  height: 38px;
  padding: 0;
  border: 1px solid var(--line-strong);
  border-radius: var(--radius);
  background: var(--workspace-strong);
  color: var(--ink);
  font-size: 1.2rem;
  font-weight: 800;
  line-height: 1;
  cursor: pointer;
  box-shadow: 0 1px 0 rgba(255, 255, 255, 0.7);
  /* Keep taps on the buttons from starting a tree pan underneath. */
  touch-action: manipulation;
}

.zoom-controls button:hover,
.zoom-controls button:focus-visible {
  border-color: rgba(67, 99, 124, 0.48);
  background: #fffdf8;
}

#tree-svg {
  display: block;
  width: 100%;
  height: 100%;
}

.tree-link {
  fill: none;
  stroke: rgba(47, 97, 83, 0.72);
  stroke-width: 2.5;
}

.tree-link.family-link {
  stroke: rgba(47, 97, 83, 0.82);
}

.tree-link.spouse-link {
  stroke: rgba(125, 79, 44, 0.58);
  stroke-dasharray: 5 5;
  stroke-width: 2;
}

.tree-link.dimmed {
  opacity: 0.24;
}

/* Connectors touching the selected person, so their card's links to parents,
   spouses, and children can be traced through the rest of the web. */
.tree-link.focused {
  stroke: var(--accent-strong);
  stroke-width: 3.25;
  opacity: 1;
}

.tree-link.spouse-link.focused {
  stroke-width: 2.75;
}

/* Connectors touching the hovered (or keyboard-focused) card, so any line in
   a crowded row can be traced without changing the selection. */
.tree-link.traced {
  stroke: rgba(125, 79, 44, 0.95);
  stroke-width: 3.25;
  opacity: 1;
}

.tree-link.spouse-link.traced {
  stroke-width: 2.75;
}

.family-unit {
  fill: rgba(255, 255, 255, 0.24);
  stroke: rgba(67, 99, 124, 0.14);
  stroke-width: 1;
}

.family-unit.dimmed {
  fill: rgba(255, 255, 255, 0.12);
  stroke: transparent;
}

.family-label {
  fill: rgba(125, 79, 44, 0.66);
  font-size: 10px;
  font-weight: 900;
  text-transform: uppercase;
}

.generation-label {
  fill: rgba(125, 79, 44, 0.6);
  font-size: 10px;
  font-weight: 900;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  pointer-events: none;
  paint-order: stroke;
  stroke: rgba(255, 253, 248, 0.9);
  stroke-width: 3px;
}

.overview-scale .family-label,
.overview-scale .node-years,
.overview-scale .node-photo,
.overview-scale .node-photo-placeholder,
.overview-scale .node-photo-initials {
  display: none;
}

.overview-scale .tree-node rect {
  filter: none;
}

.overview-scale .tree-link {
  stroke-width: 1.8;
}

.tree-node,
.ancestor-expander {
  cursor: pointer;
}

.ancestor-expander rect {
  fill: #f7fbf9;
  stroke: rgba(47, 97, 83, 0.42);
  stroke-width: 1.4;
  filter: drop-shadow(0 4px 8px rgba(34, 28, 23, 0.08));
}

.ancestor-expander:hover rect,
.ancestor-expander:focus-visible rect {
  fill: #eef6f3;
  stroke: #255649;
}

.ancestor-expander.collapse rect {
  fill: #faf6f1;
  stroke: rgba(125, 79, 44, 0.4);
}

.ancestor-expander.collapse:hover rect,
.ancestor-expander.collapse:focus-visible rect {
  fill: #f2e7db;
  stroke: #7d4f2c;
}

.ancestor-expander-text {
  fill: var(--green);
  font-size: 11px;
  font-weight: 900;
  pointer-events: none;
}

.ancestor-expander.collapse .ancestor-expander-text {
  fill: var(--accent-strong);
}

.tree-node.dimmed {
  opacity: 0.38;
}

.tree-node rect {
  fill: rgba(255, 252, 246, 0.96);
  stroke: rgba(67, 99, 124, 0.34);
  stroke-width: 1.6;
  filter: drop-shadow(0 8px 12px rgba(34, 28, 23, 0.12));
}

.tree-node:hover rect,
.tree-node:focus-visible rect {
  stroke: rgba(67, 99, 124, 0.6);
  transform-box: fill-box;
}

.tree-node.dimmed rect {
  fill: rgba(255, 252, 246, 0.68);
  stroke: rgba(67, 99, 124, 0.18);
  filter: none;
}

.tree-node.search-miss {
  opacity: 0.22;
}

.tree-node.search-miss rect {
  filter: none;
}

.tree-node.search-hit rect {
  fill: var(--blue-soft);
  stroke: var(--blue);
  stroke-width: 2.6;
}

.tree-node.selected rect {
  fill: var(--green-soft);
  stroke: var(--green);
  stroke-width: 2.5;
}

.tree-node.root rect {
  fill: rgba(255, 246, 237, 0.96);
  stroke: var(--accent);
  stroke-width: 2.4;
}

.tree-node.root.selected rect {
  fill: #f0e1cf;
  stroke: var(--accent);
}

.node-name {
  fill: var(--ink);
  font-size: 13px;
  font-weight: 800;
}

.node-years {
  fill: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

.node-photo-placeholder {
  fill: #e8ddd0;
  stroke: rgba(125, 79, 44, 0.24);
  stroke-width: 1.2;
}

.node-photo {
  pointer-events: none;
}

.node-photo-initials {
  fill: rgba(74, 64, 54, 0.72);
  font-size: 12px;
  font-weight: 900;
  pointer-events: none;
}

.window-close {
  justify-self: end;
  display: none;
}

.detail-meta {
  margin-top: -2px;
}

.profile-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

#copy-link.copy-failed {
  border-color: rgba(125, 79, 44, 0.42);
  background: rgba(249, 233, 223, 0.92);
  color: var(--accent-strong);
}

.profile-actions button:first-child {
  border-color: rgba(125, 79, 44, 0.42);
  background: var(--accent-soft);
  color: var(--accent-strong);
}

.profile-photo {
  display: grid;
  gap: 8px;
}

.profile-photo img,
.photo-placeholder {
  width: 100%;
  min-height: 240px;
  max-height: 320px;
  display: block;
  object-fit: cover;
  border: 1px solid rgba(67, 99, 124, 0.18);
  border-radius: var(--radius);
  background: rgba(233, 224, 210, 0.82);
}

.photo-placeholder {
  display: grid;
  place-items: center;
  color: rgba(74, 64, 54, 0.72);
  font-family: Georgia, "Times New Roman", serif;
  font-size: 2.4rem;
  font-weight: 700;
}

.profile-photo p {
  margin: 0;
  font-size: 0.78rem;
  line-height: 1.45;
}

/* No-photo state: compact avatar row instead of a large empty placeholder,
   so the life story gets space without hiding the initials affordance. */
.profile-photo.profile-photo--no-photo {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 10px 13px;
  background: rgba(233, 224, 210, 0.45);
  border: 1px solid rgba(67, 99, 124, 0.15);
  border-radius: var(--radius);
}

.profile-photo.profile-photo--no-photo .photo-placeholder {
  flex: none;
  width: 48px;
  min-height: 48px;
  max-height: 48px;
  border-radius: 50%;
  font-size: 1rem;
  border: none;
  background: rgba(200, 188, 172, 0.72);
}

.profile-photo.profile-photo--no-photo p {
  margin: 0;
  font-size: 0.78rem;
  color: var(--muted);
  line-height: 1.4;
}

.photo-thumbs {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.photo-thumb {
  padding: 0;
  border: 2px solid transparent;
  border-radius: 9px;
  background: none;
  cursor: pointer;
  line-height: 0;
}

.photo-thumb.active {
  border-color: rgba(47, 97, 83, 0.66);
  cursor: default;
}

.photo-thumb img {
  width: 56px;
  height: 56px;
  min-height: 0;
  max-height: none;
  object-fit: cover;
  border-radius: 6px;
}

.life-story {
  display: grid;
  gap: 12px;
  padding-top: 16px;
  border-top: 1px solid var(--line);
  font-family: Georgia, "Times New Roman", serif;
}

.life-story p {
  margin: 0;
  font-size: 0.98rem;
  line-height: 1.62;
}

.story-kickers {
  display: grid;
  gap: 5px;
  justify-items: start;
}

.story-kicker {
  color: var(--accent-strong);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  font-size: 0.76rem;
  font-weight: 900;
  text-transform: uppercase;
}

a.story-kicker {
  justify-self: start;
  text-decoration: underline;
  text-decoration-color: color-mix(in srgb, var(--accent-strong) 45%, transparent);
  text-underline-offset: 3px;
}

a.story-kicker:hover,
a.story-kicker:focus-visible {
  text-decoration-color: var(--accent-strong);
}

.story-person-link {
  color: var(--accent);
  font-weight: 700;
  text-decoration: underline;
  text-decoration-color: color-mix(in srgb, var(--accent-strong) 50%, transparent);
  text-underline-offset: 3px;
}

.story-person-link:hover,
.story-person-link:focus-visible {
  color: var(--accent-strong);
  text-decoration-color: var(--accent-strong);
}

dl {
  display: grid;
  grid-template-columns: minmax(88px, auto) 1fr;
  gap: 10px 14px;
  margin: 0;
}

dt {
  color: var(--muted-strong);
  font-weight: 800;
}

dd {
  margin: 0;
  line-height: 1.45;
}

.notes {
  display: grid;
  gap: 8px;
  padding: 12px 14px;
  border: 1px dashed rgba(125, 79, 44, 0.24);
  border-radius: var(--radius);
  background: rgba(255, 252, 246, 0.58);
  line-height: 1.5;
}

.notes-label {
  margin: 0;
  color: var(--accent-strong);
  font-size: 0.72rem;
  font-weight: 900;
  letter-spacing: 0.05em;
  text-transform: uppercase;
}

.notes-body {
  margin: 0;
}

.notes-toggle,
.relation-overflow-toggle {
  justify-self: start;
  padding: 4px 10px;
  border: 1px solid rgba(125, 79, 44, 0.3);
  border-radius: 999px;
  background: transparent;
  color: var(--muted-strong);
  font-size: 0.76rem;
  font-weight: 700;
  cursor: pointer;
}

.notes-toggle:hover,
.notes-toggle:focus-visible,
.relation-overflow-toggle:hover,
.relation-overflow-toggle:focus-visible {
  border-color: var(--accent-strong);
  color: var(--accent-strong);
}

.timeline {
  display: grid;
  gap: 8px;
  padding-top: 14px;
  border-top: 1px solid var(--line);
}

.timeline-list {
  display: grid;
  gap: 6px;
  margin: 0;
  padding: 0;
  list-style: none;
}

.timeline-item {
  display: grid;
  grid-template-columns: 44px 1fr;
  gap: 10px;
  align-items: baseline;
}

.timeline-year {
  color: var(--accent-strong);
  font-size: 0.78rem;
  font-weight: 900;
  text-align: right;
}

.timeline-body {
  display: grid;
  gap: 2px;
  padding-left: 10px;
  border-left: 2px solid rgba(125, 79, 44, 0.22);
}

.timeline-label {
  color: var(--ink);
  font-size: 0.85rem;
  font-weight: 700;
  line-height: 1.35;
}

a.timeline-label {
  justify-self: start;
  color: var(--accent-strong);
  text-decoration: underline;
  text-decoration-color: color-mix(in srgb, var(--accent-strong) 45%, transparent);
  text-underline-offset: 2px;
}

a.timeline-label:hover,
a.timeline-label:focus-visible {
  text-decoration-color: var(--accent-strong);
}

button.timeline-label {
  justify-self: start;
  padding: 0;
  border: none;
  background: transparent;
  text-align: left;
  cursor: pointer;
}

button.timeline-label:hover,
button.timeline-label:focus-visible {
  color: var(--accent-strong);
  text-decoration: underline;
}

.timeline-detail {
  color: var(--muted);
  font-size: 0.76rem;
  line-height: 1.35;
}

/* Birth and death milestones get a thicker, more prominent rail so they
   visually anchor the timeline — relative and record events stay subordinate. */
.timeline-item--birth .timeline-body,
.timeline-item--death .timeline-body {
  border-left-width: 3px;
}

.timeline-item--birth .timeline-body {
  border-left-color: var(--green);
}

.timeline-item--birth .timeline-year {
  color: var(--green);
}

.timeline-item--death .timeline-body {
  border-left-color: var(--muted-strong);
}

.timeline-item--death .timeline-year {
  color: var(--muted-strong);
}

/* Source records in the timeline get a subtly muted left rail and dimmer
   label so they read as documentary evidence rather than lived events. */
.timeline-item--marriage .timeline-body {
  border-left-color: var(--blue);
}

.timeline-item--marriage .timeline-year {
  color: var(--blue);
}

.timeline-item--record .timeline-body {
  border-left-color: var(--accent);
  opacity: 0.8;
}

.timeline-item--record .timeline-label {
  font-weight: 500;
}

.relation-item {
  gap: 4px;
}

.relation-meta,
.source-meta {
  font-size: 0.76rem;
  line-height: 1.35;
}

.source-item {
  gap: 8px;
  border-left: 3px solid var(--accent);
  background: rgba(255, 252, 246, 0.94);
}

.source-item.source-quality-record {
  border-left-color: var(--green);
}

.source-item.source-quality-lead,
.source-item.source-quality-index,
.source-item.source-quality-memorial {
  border-left-color: #b88925;
}

.source-item.source-quality-conflict {
  border-left-color: #b84f3e;
}

.source-item.source-quality-note {
  border-left-color: #7b68b5;
}

.source-item span,
.source-item small {
  display: block;
}

.source-item p {
  margin: 0;
  font-size: 0.82rem;
  line-height: 1.45;
}

.sources-panel[hidden],
.timeline[hidden],
.notes[hidden],
.profile-photo[hidden] {
  display: none;
}

.profile-photo > img.photo-open {
  cursor: zoom-in;
}

.photo-lightbox {
  position: fixed;
  inset: 0;
  z-index: 80;
  display: grid;
  place-items: center;
  padding: 24px;
  background: rgba(38, 31, 26, 0.78);
  backdrop-filter: blur(2px);
}

.photo-lightbox[hidden] {
  display: none;
}

.photo-lightbox-card {
  position: relative;
  margin: 0;
  display: grid;
  gap: 10px;
  justify-items: center;
  max-width: min(1100px, 100%);
}

.photo-lightbox-card img {
  max-width: 100%;
  max-height: calc(100vh - 120px);
  border-radius: var(--radius);
  background: var(--workspace-strong);
  box-shadow: var(--shadow-strong);
}

.photo-lightbox-card figcaption {
  color: rgba(255, 251, 244, 0.92);
  font-size: 0.85rem;
  line-height: 1.45;
  text-align: center;
}

.photo-lightbox-card figcaption:empty {
  display: none;
}

#photo-lightbox-close {
  position: absolute;
  top: 10px;
  right: 10px;
  z-index: 1;
  padding: 4px 12px;
  border: 1px solid rgba(255, 251, 244, 0.4);
  border-radius: 999px;
  background: rgba(38, 31, 26, 0.62);
  color: rgba(255, 251, 244, 0.95);
  font-size: 0.78rem;
  cursor: pointer;
}

.help-overlay {
  position: fixed;
  inset: 0;
  z-index: 70;
  display: grid;
  place-items: center;
  padding: 24px;
  background: rgba(38, 31, 26, 0.42);
  backdrop-filter: blur(2px);
}

.help-overlay[hidden] {
  display: none;
}

.help-card {
  display: grid;
  gap: 4px;
  width: min(440px, 100%);
  max-height: min(80vh, 640px);
  overflow-y: auto;
  padding: 20px 24px;
  border: 1px solid var(--line-strong, var(--accent));
  border-radius: var(--radius);
  background: var(--workspace-strong);
  box-shadow: var(--shadow-strong);
}

.help-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.help-head strong {
  font-size: 1.02rem;
  color: var(--accent-strong);
}

.help-body h3 {
  margin: 12px 0 4px;
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted);
}

.help-tip {
  display: grid;
  grid-template-columns: 118px minmax(0, 1fr);
  gap: 10px;
  align-items: baseline;
  padding: 3px 0;
  font-size: 0.85rem;
}

.help-keys {
  color: var(--muted);
  white-space: nowrap;
}

.help-keys kbd {
  display: inline-block;
  padding: 1px 6px;
  border: 1px solid var(--line, rgba(38, 31, 26, 0.2));
  border-bottom-width: 2px;
  border-radius: 5px;
  background: var(--workspace, #fff);
  font-family: inherit;
  font-size: 0.78rem;
}

.help-does {
  color: var(--ink, inherit);
}

.drop-overlay {
  position: fixed;
  inset: 0;
  z-index: 60;
  display: grid;
  place-items: center;
  padding: 24px;
  background: rgba(38, 31, 26, 0.42);
  backdrop-filter: blur(2px);
  pointer-events: none;
}

.drop-overlay[hidden] {
  display: none;
}

.drop-overlay-card {
  display: grid;
  gap: 6px;
  max-width: 380px;
  padding: 22px 28px;
  border: 2px dashed var(--accent);
  border-radius: var(--radius);
  background: var(--workspace-strong);
  box-shadow: var(--shadow-strong);
  text-align: center;
}

.drop-overlay-card strong {
  font-size: 1.02rem;
  color: var(--accent-strong);
}

.drop-overlay-card p {
  margin: 0;
  font-size: 0.85rem;
  color: var(--muted);
}

@media (max-width: 1180px) {
  .app-shell {
    grid-template-columns: minmax(0, 1fr);
  }

  .tree-area {
    grid-column: 1;
    padding: 14px;
  }

  .map-grid,
  .research-grid {
    grid-template-columns: 1fr;
  }

  .research-panel-wide {
    grid-column: auto;
  }

  .sidebar,
  .details {
    position: fixed;
    top: 12px;
    bottom: 12px;
    width: min(408px, calc(100vw - 24px));
    border: 1px solid rgba(67, 99, 124, 0.18);
    box-shadow: var(--shadow-strong);
    z-index: 20;
  }

  .sidebar {
    left: 12px;
  }

  .details {
    right: 12px;
  }

  .sidebar-shell,
  .details-shell {
    padding: 24px 18px 24px;
  }

  .people-collapsed .sidebar {
    transform: translateX(calc(-100% - 24px));
  }

  .profile-collapsed .details {
    transform: translateX(calc(100% + 24px));
  }

  .window-close {
    display: inline-flex;
    align-items: center;
  }

  .tree-header,
  .focus-card {
    box-shadow: none;
  }
}

@media (max-width: 860px) {
  .tree-header {
    display: grid;
    gap: 12px;
  }

  .tree-tools {
    width: 100%;
    display: grid;
    gap: 12px;
    grid-template-columns: minmax(0, 1fr);
  }

  .tree-tools,
  .tree-summary,
  .view-actions,
  .legend {
    justify-content: flex-start;
    justify-items: start;
  }

  .tree-focus-bar {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 640px) {
  .tree-area {
    padding: 10px;
  }

  .sidebar-shell,
  .details-shell {
    padding: 18px 14px 18px;
    gap: 18px;
  }

  h1 {
    font-size: 1.6rem;
  }

  .toolbar,
  .view-actions {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .view-actions {
    display: grid;
    width: 100%;
  }

  .view-actions button {
    width: 100%;
    min-width: 0;
    padding-inline: 8px;
    white-space: normal;
  }

  .profile-actions,
  .toolbar,
  .detail-meta {
    gap: 7px;
  }

  .tree-header {
    padding: 14px;
  }

  .focus-card {
    padding: 13px 14px;
  }

  .person-row-main,
  .relation-name {
    display: grid;
    gap: 4px;
  }

  dl {
    grid-template-columns: 1fr;
    gap: 4px;
  }
}

/* Printing (or save-as-PDF via the print dialog) turns the open profile into
   a clean document: the sidebar, tree, and controls disappear, the profile
   panel becomes the page, and Sources print even while collapsed on screen
   (the source list stays populated in the DOM when the panel is folded). */
@media print {
  html,
  body {
    height: auto;
    overflow: visible;
    background: #fff;
  }

  .sidebar,
  .tree-area,
  .window-close,
  .profile-actions,
  .notes-toggle,
  .help-overlay,
  .photo-lightbox,
  .drop-overlay {
    display: none !important;
  }

  .app-shell {
    display: block;
    height: auto;
  }

  .details,
  .profile-collapsed .details {
    opacity: 1;
    transform: none;
    border: 0;
    background: #fff;
    backdrop-filter: none;
    overflow: visible;
  }

  .details-shell {
    height: auto;
    overflow: visible;
    padding: 0;
  }

  .sources-panel[hidden] {
    display: grid !important;
  }

  .profile-photo img,
  .photo-placeholder {
    max-height: 3.4in;
    object-fit: contain;
    background: #fff;
  }

  .profile-photo.profile-photo--no-photo {
    display: none;
  }

  .workspace-section {
    break-inside: auto;
  }

  .source-item,
  .timeline-item,
  .relation-item,
  .profile-photo,
  .life-story p {
    break-inside: avoid;
  }

  .relation-item,
  .source-item {
    box-shadow: none;
  }

  a {
    color: inherit;
  }
}
