/* ------------------------------------------------------------------ tokens */
:root {
  --green-900: #143427;
  --green-800: #1f4d3a;
  --green-700: #2b6a50;
  --green-100: #e3efe8;
  --gold-500: #c9a227;
  --gold-300: #e2c25a;
  --cream: #f7f4ee;
  --paper: #ffffff;
  --ink: #1b1f1d;
  --ink-soft: #55605b;
  --ink-faint: #8a948f;
  --line: #d8d2c4;
  --line-strong: #b8ae98;
  --male: #3a6ea5;
  --female: #c2567a;
  --other: #7a6bb5;
  --danger: #c0392b;
  --radius: 14px;
  --shadow-sm: 0 1px 2px rgba(20, 30, 25, 0.06), 0 2px 8px rgba(20, 30, 25, 0.06);
  --shadow-md: 0 6px 24px rgba(20, 30, 25, 0.12);
  --font-display: 'Playfair Display', Georgia, serif;
  --font-body: 'Inter', system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: var(--font-body);
  color: var(--ink);
  background: var(--cream);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  -webkit-font-smoothing: antialiased;
}
button { font-family: inherit; cursor: pointer; }
input { font-family: inherit; }
a { color: var(--green-700); }
.muted { color: var(--ink-soft); }
[hidden] { display: none !important; }

/* ------------------------------------------------------------------ header */
.site-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 14px 20px;
  background: var(--green-800);
  color: #fff;
  position: sticky;
  top: 0;
  z-index: 30;
  box-shadow: 0 2px 12px rgba(0, 0, 0, 0.18);
}
.brand { display: flex; align-items: center; gap: 12px; color: #fff; text-decoration: none; min-width: 0; }
.brand-mark { width: 44px; height: 44px; flex: 0 0 auto; border-radius: 50%; box-shadow: 0 0 0 2px var(--gold-300); }
.brand-mark svg { width: 100%; height: 100%; display: block; }
.brand-text { display: flex; flex-direction: column; min-width: 0; }
.brand-title { font-family: var(--font-display); font-weight: 700; font-size: 1.35rem; line-height: 1.1; letter-spacing: 0.2px; }
.brand-tagline { font-size: 0.78rem; opacity: 0.8; margin-top: 3px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.site-nav { display: flex; gap: 8px; }
.nav-link {
  color: #fff; text-decoration: none; font-size: 0.85rem; font-weight: 600;
  padding: 8px 14px; border-radius: 999px; border: 1px solid rgba(255, 255, 255, 0.35);
}
.nav-link:hover { background: rgba(255, 255, 255, 0.12); }

/* ------------------------------------------------------------------- app */
.app { flex: 1; display: flex; flex-direction: column; padding: 16px 20px 20px; gap: 14px; max-width: 1600px; width: 100%; margin: 0 auto; }

.toolbar {
  display: grid;
  grid-template-columns: minmax(220px, 1fr) auto auto;
  gap: 12px;
  align-items: center;
}
.search-wrap { position: relative; }
.search-icon { position: absolute; left: 12px; top: 50%; transform: translateY(-50%); width: 18px; height: 18px; color: var(--ink-faint); pointer-events: none; }
#searchInput {
  width: 100%; padding: 11px 14px 11px 40px; border-radius: 999px; border: 1px solid var(--line);
  background: var(--paper); font-size: 0.95rem; outline: none; transition: border-color 0.15s, box-shadow 0.15s;
}
#searchInput:focus { border-color: var(--green-700); box-shadow: 0 0 0 3px rgba(43, 106, 80, 0.15); }
.search-results {
  position: absolute; top: calc(100% + 6px); left: 0; right: 0; background: var(--paper); border: 1px solid var(--line);
  border-radius: 12px; box-shadow: var(--shadow-md); z-index: 25; max-height: 320px; overflow: auto; padding: 6px;
}
.search-item { display: flex; align-items: center; gap: 10px; padding: 8px 10px; border-radius: 8px; cursor: pointer; border: none; background: none; width: 100%; text-align: left; }
.search-item:hover, .search-item.active { background: var(--green-100); }
.search-item .avatar { width: 34px; height: 34px; font-size: 0.8rem; }
.search-item .si-name { font-weight: 600; font-size: 0.92rem; }
.search-item .si-sub { font-size: 0.78rem; color: var(--ink-soft); }
.search-empty { padding: 12px; color: var(--ink-soft); font-size: 0.9rem; }

.view-modes { display: inline-flex; background: var(--paper); border: 1px solid var(--line); border-radius: 999px; padding: 4px; gap: 2px; }
.chip {
  border: none; background: transparent; padding: 8px 16px; border-radius: 999px; font-weight: 600; font-size: 0.86rem; color: var(--ink-soft);
  transition: background 0.15s, color 0.15s; white-space: nowrap;
}
.chip.active { background: var(--green-800); color: #fff; }
.chip:disabled { opacity: 0.45; cursor: not-allowed; }

.toolbar-actions { display: flex; gap: 8px; }
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px; padding: 10px 16px; border-radius: 999px; font-weight: 600; font-size: 0.88rem;
  border: 1px solid transparent; text-decoration: none; white-space: nowrap; transition: transform 0.08s, background 0.15s, box-shadow 0.15s;
}
.btn:active { transform: translateY(1px); }
.btn svg { width: 18px; height: 18px; }
.btn-primary { background: var(--gold-500); color: var(--green-900); }
.btn-primary:hover { background: #d9b23a; }
.btn-secondary { background: var(--paper); color: var(--green-800); border-color: var(--line); }
.btn-secondary:hover { background: var(--green-100); }
.btn-ghost { background: transparent; color: var(--green-800); }
.btn-ghost:hover { background: var(--green-100); }
.btn-danger { background: var(--danger); color: #fff; }
.btn-sm { padding: 7px 12px; font-size: 0.8rem; }
.btn:disabled { opacity: 0.55; cursor: not-allowed; }

/* ------------------------------------------------------------- focus bar */
.focus-bar {
  display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 10px 14px;
  background: var(--green-100); border: 1px solid #c9dfd2; border-radius: var(--radius);
}
.focus-text { display: flex; align-items: center; gap: 12px; min-width: 0; }
.focus-avatar { flex: 0 0 auto; }
.focus-title { font-weight: 700; font-size: 0.98rem; }
.focus-sub { font-size: 0.82rem; color: var(--ink-soft); }

/* ----------------------------------------------------------------- stats */
.stats { display: flex; gap: 10px; flex-wrap: wrap; }
.stat {
  display: flex; flex-direction: column; padding: 10px 16px; background: var(--paper); border: 1px solid var(--line); border-radius: 12px; min-width: 110px;
}
.stat b { font-family: var(--font-display); font-size: 1.35rem; color: var(--green-800); line-height: 1; }
.stat span { font-size: 0.74rem; color: var(--ink-soft); margin-top: 4px; text-transform: uppercase; letter-spacing: 0.6px; }

/* --------------------------------------------------------------- stage */
.tree-stage {
  position: relative; flex: 1; min-height: 60vh; background: var(--paper); border: 1px solid var(--line); border-radius: var(--radius);
  overflow: hidden; box-shadow: var(--shadow-sm);
  background-image: radial-gradient(circle, #e8e2d4 1px, transparent 1px);
  background-size: 22px 22px;
}
.viewport { position: absolute; inset: 0; overflow: hidden; touch-action: none; cursor: grab; user-select: none; -webkit-user-select: none; }
.viewport.dragging { cursor: grabbing; }
.canvas { position: absolute; top: 0; left: 0; transform-origin: 0 0; will-change: transform; padding: 32px; width: max-content; }
.print-header, .print-footer { display: none; }
.hint { position: absolute; left: 14px; bottom: 10px; margin: 0; font-size: 0.74rem; color: var(--ink-faint); z-index: 2; pointer-events: none; }

.zoom-controls { position: absolute; right: 12px; top: 12px; z-index: 3; display: flex; flex-direction: column; gap: 6px; }
.zoom-btn {
  width: 38px; height: 38px; border-radius: 10px; border: 1px solid var(--line); background: var(--paper); color: var(--green-800);
  font-size: 1.2rem; font-weight: 600; display: inline-flex; align-items: center; justify-content: center; box-shadow: var(--shadow-sm);
}
.zoom-btn svg { width: 18px; height: 18px; }
.zoom-btn:hover { background: var(--green-100); }

/* ----------------------------------------------------------------- tree */
.tree ul { display: flex; justify-content: center; padding: 28px 0 0; margin: 0; position: relative; }
.tree > ul { padding-top: 0; }
.tree li { list-style: none; position: relative; padding: 28px 10px 0; text-align: center; display: flex; flex-direction: column; align-items: center; }
.tree > ul > li { padding-top: 0; }
.tree li::before, .tree li::after {
  content: ''; position: absolute; top: 0; right: 50%; width: 50%; height: 28px; border-top: 2px solid var(--line-strong);
}
.tree li::after { right: auto; left: 50%; border-left: 2px solid var(--line-strong); }
.tree li:only-child::before { display: none; }
.tree li:only-child::after { border-top: none; left: 50%; margin-left: -1px; }
.tree li:first-child::before { border: none; }
.tree li:last-child::after { border-top: none; }
.tree li:last-child::before { border-right: 2px solid var(--line-strong); border-radius: 0 10px 0 0; }
.tree li:first-child::after { border-radius: 10px 0 0 0; }
.tree > ul > li::before, .tree > ul > li::after { display: none; }
.tree ul ul::before { content: ''; position: absolute; top: 0; left: 50%; margin-left: -1px; height: 28px; border-left: 2px solid var(--line-strong); }
.tree li.collapsed > ul { display: none; }
.tree li.on-path::after { border-color: var(--gold-500); }
.tree li.on-path:last-child::before { border-color: var(--gold-500); }
.tree li.on-path:only-child::after, .tree li.on-path:first-child::after { border-color: var(--gold-500); }
.tree ul.path-ul::before { border-color: var(--gold-500); }

.node {
  position: relative; width: 168px; background: var(--paper); border: 1.5px solid var(--line); border-radius: 16px; padding: 14px 12px 12px;
  box-shadow: var(--shadow-sm); cursor: pointer; transition: transform 0.12s, box-shadow 0.12s, border-color 0.12s; text-align: center;
}
.node:hover { transform: translateY(-2px); box-shadow: var(--shadow-md); border-color: var(--green-700); }
.node.selected { border-color: var(--gold-500); box-shadow: 0 0 0 3px rgba(201, 162, 39, 0.3), var(--shadow-md); }
.node.on-path { border-color: var(--gold-500); }
.node.root { border-color: var(--green-700); background: linear-gradient(180deg, #f3faf6 0%, #ffffff 60%); }
.node .gen { position: absolute; top: -10px; left: 50%; transform: translateX(-50%); font-size: 0.64rem; font-weight: 700; letter-spacing: 0.6px; text-transform: uppercase;
  background: var(--green-800); color: #fff; padding: 2px 8px; border-radius: 999px; }
.node.root .gen { background: var(--gold-500); color: var(--green-900); }
.avatar {
  width: 58px; height: 58px; border-radius: 50%; margin: 2px auto 8px; display: flex; align-items: center; justify-content: center; font-weight: 700; font-size: 1.1rem;
  color: #fff; background: var(--male); border: 3px solid #fff; box-shadow: 0 0 0 2px var(--male); overflow: hidden; flex: 0 0 auto;
}
.avatar img { width: 100%; height: 100%; object-fit: cover; display: block; }
.avatar.female { background: var(--female); box-shadow: 0 0 0 2px var(--female); }
.avatar.other { background: var(--other); box-shadow: 0 0 0 2px var(--other); }
.node .name { font-weight: 700; font-size: 0.92rem; line-height: 1.25; word-wrap: break-word; }
.node .years { font-size: 0.74rem; color: var(--ink-soft); margin-top: 3px; }
.node .spouse { font-size: 0.72rem; color: var(--ink-faint); margin-top: 3px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.node .spouse::before { content: '♥ '; color: var(--female); }
.node .toggle {
  position: absolute; bottom: -14px; left: 50%; transform: translateX(-50%); width: 28px; height: 28px; border-radius: 50%; border: 1.5px solid var(--line-strong);
  background: var(--paper); color: var(--green-800); font-size: 0.72rem; font-weight: 700; display: flex; align-items: center; justify-content: center; z-index: 2;
}
.node .toggle:hover { background: var(--green-100); }
li.collapsed .node .toggle { background: var(--green-800); color: #fff; border-color: var(--green-800); }

.empty-state { padding: 60px 20px; text-align: center; color: var(--ink-soft); width: 70vw; max-width: 520px; }
.empty-state h2 { font-family: var(--font-display); color: var(--green-800); }

/* ----------------------------------------------------------- lineage view */
.lineage-wrap { display: flex; flex-direction: column; align-items: center; padding: 10px 24px 24px; }
.lineage-title { font-family: var(--font-display); color: var(--green-800); font-size: 1.3rem; margin: 0 0 4px; text-align: center; }
.lineage-sub { font-size: 0.82rem; color: var(--ink-soft); margin: 0 0 18px; text-align: center; }
.lineage-step { display: flex; flex-direction: column; align-items: center; }
.lineage-connector { width: 2px; height: 34px; background: var(--gold-500); position: relative; }
.lineage-connector::after { content: ''; position: absolute; bottom: -2px; left: 50%; transform: translateX(-50%); border: 6px solid transparent; border-top: 8px solid var(--gold-500); }
.lineage-step .node { width: 220px; }
.lineage-step .node .gen { background: var(--gold-500); color: var(--green-900); }
.lineage-step.me .node { border-color: var(--green-700); border-width: 2px; }
.lineage-rel { font-size: 0.72rem; color: var(--ink-faint); margin-top: 8px; text-transform: uppercase; letter-spacing: 0.6px; }

/* ----------------------------------------------------------- detail panel */
.detail-panel {
  position: fixed; top: 0; right: 0; height: 100%; width: 380px; max-width: 100%; background: var(--paper); box-shadow: -8px 0 30px rgba(0, 0, 0, 0.15);
  transform: translateX(100%); transition: transform 0.25s ease; z-index: 50; overflow-y: auto; padding: 20px 20px 28px;
}
.detail-panel.open { transform: translateX(0); }
.detail-handle { display: none; }
.detail-close { position: absolute; top: 10px; right: 12px; width: 36px; height: 36px; border-radius: 50%; border: none; background: var(--cream); font-size: 1.3rem; color: var(--ink-soft); }
.detail-hero { text-align: center; padding-top: 10px; }
.detail-hero .avatar { width: 96px; height: 96px; font-size: 1.8rem; margin-bottom: 10px; }
.detail-hero h2 { font-family: var(--font-display); margin: 4px 0 2px; font-size: 1.45rem; color: var(--green-900); }
.detail-hero .badge { display: inline-block; background: var(--green-100); color: var(--green-800); font-size: 0.72rem; font-weight: 700; padding: 3px 10px; border-radius: 999px; text-transform: uppercase; letter-spacing: 0.6px; margin-top: 4px; }
.detail-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin: 18px 0; }
.detail-actions .btn { padding: 10px 8px; font-size: 0.8rem; }
.detail-actions .btn.full { grid-column: 1 / -1; }
.detail-section { margin-top: 16px; }
.detail-section h4 { margin: 0 0 8px; font-size: 0.74rem; text-transform: uppercase; letter-spacing: 0.8px; color: var(--ink-faint); }
.kv { display: grid; grid-template-columns: 110px 1fr; gap: 6px 10px; font-size: 0.9rem; }
.kv dt { color: var(--ink-soft); margin: 0; }
.kv dd { margin: 0; font-weight: 500; }
.bio { font-size: 0.92rem; line-height: 1.55; color: var(--ink); white-space: pre-wrap; }
.person-link { display: flex; align-items: center; gap: 10px; padding: 8px 10px; border-radius: 10px; border: 1px solid var(--line); background: var(--cream); cursor: pointer; width: 100%; text-align: left; margin-bottom: 6px; }
.person-link:hover { border-color: var(--green-700); }
.person-link .avatar { width: 34px; height: 34px; font-size: 0.8rem; margin: 0; }
.person-link .pl-name { font-weight: 600; font-size: 0.9rem; }
.person-link .pl-sub { font-size: 0.76rem; color: var(--ink-soft); }
.backdrop { position: fixed; inset: 0; background: rgba(0, 0, 0, 0.35); z-index: 45; }

/* ------------------------------------------------------------- share sheet */
.share-sheet { position: fixed; inset: 0; z-index: 60; background: rgba(0, 0, 0, 0.45); display: flex; align-items: center; justify-content: center; padding: 20px; }
.share-card { background: var(--paper); border-radius: 18px; padding: 24px; width: 100%; max-width: 440px; box-shadow: var(--shadow-md); }
.share-card h3 { margin: 0 0 6px; font-family: var(--font-display); color: var(--green-900); }
.share-card p { margin: 0 0 14px; font-size: 0.88rem; }
.share-link-row { display: flex; gap: 8px; margin-bottom: 12px; }
.share-link-row input { flex: 1; min-width: 0; padding: 10px 12px; border-radius: 10px; border: 1px solid var(--line); font-size: 0.82rem; background: var(--cream); }
.share-buttons { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 10px; }
.share-buttons .btn { flex: 1; }

/* ------------------------------------------------------------------ toast */
.toast { position: fixed; left: 50%; bottom: 24px; transform: translate(-50%, 20px); background: var(--green-900); color: #fff; padding: 11px 18px; border-radius: 999px; font-size: 0.88rem; opacity: 0; pointer-events: none; transition: opacity 0.2s, transform 0.2s; z-index: 80; box-shadow: var(--shadow-md); max-width: 90vw; text-align: center; }
.toast.show { opacity: 1; transform: translate(-50%, 0); }
.loader { position: fixed; inset: 0; z-index: 90; background: rgba(247, 244, 238, 0.85); display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 14px; font-weight: 600; color: var(--green-800); }
.spinner { width: 42px; height: 42px; border-radius: 50%; border: 4px solid var(--green-100); border-top-color: var(--green-800); animation: spin 0.8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ----------------------------------------------------------------- footer */
.site-footer { padding: 16px 20px; text-align: center; font-size: 0.78rem; color: var(--ink-faint); }

/* ----------------------------------------------------------- export mode */
.canvas.exporting { background: var(--cream); padding: 40px 48px; border-radius: 0; }
.canvas.exporting .print-header { display: block; text-align: center; margin-bottom: 26px; }
.canvas.exporting .print-header h1 { font-family: var(--font-display); color: var(--green-800); margin: 0 0 4px; font-size: 2rem; }
.canvas.exporting .print-header p { margin: 0; color: var(--ink-soft); font-size: 0.95rem; }
.canvas.exporting .print-footer { display: block; text-align: center; margin-top: 26px; color: var(--ink-faint); font-size: 0.8rem; }
.canvas.exporting .node .toggle { display: none; }
.canvas.exporting .node:hover { transform: none; }

/* --------------------------------------------------------------- mobile */
@media (max-width: 900px) {
  .toolbar { grid-template-columns: 1fr; }
  .view-modes { justify-content: center; }
  .chip { flex: 1; padding: 8px 10px; font-size: 0.82rem; text-align: center; }
  .toolbar-actions .btn { flex: 1; }
}
@media (max-width: 640px) {
  .site-header { padding: 10px 14px; }
  .brand-title { font-size: 1.1rem; }
  .brand-tagline { display: none; }
  .brand-mark { width: 38px; height: 38px; }
  .app { padding: 12px 12px 16px; gap: 10px; }
  .stats { gap: 6px; }
  .stat { min-width: 0; flex: 1; padding: 8px 10px; }
  .stat b { font-size: 1.1rem; }
  .tree-stage { min-height: 62vh; }
  .hint { font-size: 0.68rem; right: 60px; }
  .zoom-controls { right: 8px; top: 8px; }
  .zoom-btn { width: 34px; height: 34px; }
  .focus-bar { flex-direction: column; align-items: stretch; }
  .focus-bar .btn { width: 100%; }
  .detail-panel {
    top: auto; bottom: 0; left: 0; right: 0; width: 100%; height: auto; max-height: 86vh; border-radius: 20px 20px 0 0;
    transform: translateY(100%); padding-top: 14px;
  }
  .detail-panel.open { transform: translateY(0); }
  .detail-handle { display: block; width: 44px; height: 5px; border-radius: 3px; background: var(--line); margin: 0 auto 8px; }
  .share-sheet { align-items: flex-end; padding: 0; }
  .share-card { border-radius: 20px 20px 0 0; max-width: none; }
}

/* --------------------------------------------------- overflow safety */
html, body { max-width: 100%; overflow-x: hidden; }
.app, .toolbar, .toolbar > *, .brand, .brand-text { min-width: 0; }
.view-modes { display: flex; }
.view-modes .chip { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; }
@media (max-width: 640px) {
  .stats { display: grid; grid-template-columns: repeat(2, 1fr); gap: 8px; }
  .toolbar-actions .btn { min-width: 0; padding: 10px 12px; }
}

/* --------------------------------------------------------------- lightbox */
.avatar.has-photo { cursor: zoom-in; }
.lightbox {
  position: fixed; inset: 0; z-index: 100; background: rgba(10, 20, 15, 0.92); display: flex; flex-direction: column;
  align-items: center; justify-content: center; padding: 24px; gap: 14px; animation: fadeIn 0.15s ease;
}
.lightbox.preview { pointer-events: none; }
.lightbox img { max-width: 100%; max-height: calc(100vh - 120px); object-fit: contain; border-radius: 12px; box-shadow: 0 20px 60px rgba(0, 0, 0, 0.5); background: #fff; }
.lightbox-caption { color: #fff; text-align: center; display: flex; flex-direction: column; gap: 2px; }
.lightbox-caption strong { font-family: var(--font-display); font-size: 1.3rem; }
.lightbox-caption span { font-size: 0.85rem; opacity: 0.75; }
.lightbox-close {
  position: absolute; top: 14px; right: 14px; width: 44px; height: 44px; border-radius: 50%; border: none;
  background: rgba(255, 255, 255, 0.15); color: #fff; font-size: 1.6rem; display: flex; align-items: center; justify-content: center;
}
.lightbox-close:hover { background: rgba(255, 255, 255, 0.3); }
.lightbox.preview .lightbox-close { display: none; }
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }

/* ------------------------------------------------ branch view: ancestor line */
.tree li.ancestor > .node { opacity: 0.82; background: var(--cream); }
.tree li.ancestor > .node::after {
  content: 'Direct line'; position: absolute; bottom: -9px; left: 50%; transform: translateX(-50%);
  font-size: 0.58rem; font-weight: 700; letter-spacing: 0.6px; text-transform: uppercase; color: var(--green-800);
  background: var(--paper); border: 1px solid var(--gold-500); border-radius: 999px; padding: 1px 7px; white-space: nowrap;
}
.tree li.ancestor > .node.root::after { content: 'Founder · Direct line'; }

/* ================================================================ toolbar v2 */
.toolbar {
  display: flex; align-items: center; gap: 12px; padding: 10px; background: var(--paper); border: 1px solid var(--line);
  border-radius: 20px; box-shadow: var(--shadow-sm);
}
.toolbar .search-wrap { flex: 1 1 320px; }
.toolbar .view-modes { flex: 0 0 auto; border: none; background: var(--cream); }
.toolbar .toolbar-actions { flex: 0 0 auto; }
#searchInput {
  height: 46px; padding: 0 44px 0 44px; border-radius: 999px; border: 1px solid transparent; background: var(--cream); font-size: 0.95rem;
}
#searchInput::placeholder { color: var(--ink-faint); }
#searchInput:focus { background: var(--paper); border-color: var(--green-700); box-shadow: 0 0 0 4px rgba(43, 106, 80, 0.14); }
#searchInput::-webkit-search-cancel-button { display: none; }
.search-icon { left: 16px; width: 19px; height: 19px; }
.search-clear {
  position: absolute; right: 8px; top: 50%; transform: translateY(-50%); width: 30px; height: 30px; border-radius: 50%; border: none;
  background: var(--line); color: var(--ink-soft); font-size: 1.1rem; line-height: 1; display: flex; align-items: center; justify-content: center;
}
.search-clear:hover { background: var(--line-strong); color: #fff; }
.search-results { border-radius: 16px; padding: 8px; }
.search-item { padding: 9px 10px; border-radius: 10px; }
.chip { display: inline-flex; align-items: center; gap: 7px; padding: 9px 16px; }
.chip svg { width: 17px; height: 17px; flex: 0 0 auto; }
.chip.active { box-shadow: 0 2px 8px rgba(31, 77, 58, 0.3); }
.btn .long { display: inline; }
.toolbar-actions .btn { height: 44px; }

/* ------------------------------------------------------------- disclaimer */
.disclaimer { background: #fff8e6; border: 1px solid #f1dc9a; border-radius: var(--radius); padding: 0; overflow: hidden; }
.disclaimer-toggle {
  display: flex; align-items: center; gap: 8px; width: 100%; padding: 10px 14px; border: none; background: transparent; color: #7a5a00;
  font-weight: 700; font-size: 0.82rem; text-transform: uppercase; letter-spacing: 0.6px; text-align: left; cursor: pointer;
}
.disclaimer-toggle svg { width: 18px; height: 18px; }
.disclaimer-caret { margin-left: auto; transition: transform 0.2s; }
.disclaimer.open .disclaimer-caret { transform: rotate(180deg); }
.disclaimer-body { padding: 0 14px 12px; font-size: 0.88rem; line-height: 1.55; color: #5a4600; }
.disclaimer-body p { margin: 0 0 6px; }
.disclaimer-body p:last-child { margin-bottom: 0; }
.disclaimer:not(.open) .disclaimer-body { display: none; }
@media (min-width: 641px) {
  /* on larger screens the disclaimer is always open */
  .disclaimer .disclaimer-body { display: block !important; }
  .disclaimer-toggle { cursor: default; }
  .disclaimer-caret { display: none; }
}

/* ------------------------------------------------------------ member picker */
.picker-card { max-width: 480px; display: flex; flex-direction: column; max-height: 80vh; }
.picker-search { margin-bottom: 10px; }
.picker-list { overflow-y: auto; flex: 1; min-height: 160px; border: 1px solid var(--line); border-radius: 14px; padding: 6px; margin-bottom: 10px; }
.picker-list .search-item { width: 100%; }
.picker-list .search-empty { padding: 20px; text-align: center; }
.picker-card .btn-ghost { align-self: center; }

/* ---------------------------------------------------- mobile: bottom toolbar */
.mobile-spacer { display: none; }
@media (max-width: 640px) {
  .app { padding: 0; gap: 0; }
  .tree-stage {
    border-radius: 0; border-left: none; border-right: none; min-height: 0;
    height: calc(100dvh - 58px - 118px); /* header and bottom bar */
  }
  .hint { display: none; }
  .stats { display: none; }
  .site-footer { display: none; }
  .focus-bar {
    position: absolute; z-index: 4; left: 10px; right: 58px; top: 8px; margin: 0; padding: 8px 10px; border-radius: 14px;
    flex-direction: row; align-items: center; box-shadow: var(--shadow-md); background: rgba(227, 239, 232, 0.96);
  }
  .focus-bar .focus-avatar .avatar { width: 36px; height: 36px; font-size: 0.8rem; margin: 0; }
  .focus-bar .btn { width: auto; padding: 6px 10px; font-size: 0.74rem; flex: 0 0 auto; }
  .focus-title { font-size: 0.86rem; }
  .focus-sub { font-size: 0.72rem; }
  .app { position: relative; }
  .disclaimer { margin: 8px 10px; border-radius: 12px; }
  .disclaimer-toggle { padding: 8px 12px; font-size: 0.76rem; }

  .toolbar {
    position: fixed; left: 0; right: 0; bottom: 0; z-index: 40; border-radius: 20px 20px 0 0; border-bottom: none;
    padding: 10px 12px calc(10px + env(safe-area-inset-bottom)); box-shadow: 0 -8px 30px rgba(0, 0, 0, 0.14);
    display: grid; grid-template-columns: 1fr auto; grid-template-areas: "search search" "modes actions"; gap: 8px;
  }
  .toolbar .search-wrap { grid-area: search; }
  .toolbar .view-modes { grid-area: modes; display: flex; min-width: 0; }
  .toolbar .toolbar-actions { grid-area: actions; }
  .chip { flex: 1; padding: 8px 8px; font-size: 0.78rem; gap: 5px; }
  .chip svg { width: 15px; height: 15px; }
  .chip span { overflow: hidden; text-overflow: ellipsis; }
  .btn .long { display: none; }
  .toolbar-actions .btn { height: 38px; padding: 0 12px; font-size: 0.8rem; }
  #searchInput { height: 42px; }
  .search-results { top: auto; bottom: calc(100% + 8px); max-height: 50vh; }
  .mobile-spacer { display: block; height: 118px; }
  .detail-panel { max-height: 80vh; z-index: 50; }
  .toast { bottom: 130px; }
}

/* ---------------------------------------------------- fixes: picker + rows */
.search-item .avatar, .picker-list .avatar { margin: 0; flex: 0 0 auto; }
.search-item > div { min-width: 0; }
.picker-search input {
  width: 100%; height: 44px; padding: 0 14px 0 44px; border-radius: 999px; border: 1px solid var(--line); background: var(--cream);
  font-size: 0.95rem; outline: none;
}
.picker-search input:focus { background: var(--paper); border-color: var(--green-700); box-shadow: 0 0 0 4px rgba(43, 106, 80, 0.14); }
.picker-search input::-webkit-search-cancel-button { display: none; }

/* mobile: everything above the bottom bar is one column; the tree fills what is left */
@media (max-width: 640px) {
  .app { height: calc(100dvh - 58px - 118px); display: flex; flex-direction: column; overflow: hidden; }
  .tree-stage { flex: 1 1 auto; min-height: 0; height: auto; }
  .focus-bar {
    position: static; margin: 0 10px 8px; left: auto; right: auto; top: auto; box-shadow: none; background: var(--green-100);
    padding: 7px 10px; gap: 8px;
  }
  .focus-bar .focus-text { flex: 1; min-width: 0; }
  .focus-title { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
  .focus-sub { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
  .disclaimer { margin: 8px 10px; flex: 0 0 auto; }
  .mobile-spacer { display: none; }
}

@media (max-width: 640px) {
  .focus-bar .focus-text > div { min-width: 0; flex: 1; }
  .focus-bar .btn { flex: 0 0 auto; white-space: nowrap; }
  .toolbar-actions .btn > span { display: none; }
  .toolbar-actions .btn { width: 44px; padding: 0; justify-content: center; }
  .toolbar-actions .btn svg { width: 20px; height: 20px; }
  .chip svg { display: none; }
  .chip { padding: 9px 6px; font-size: 0.8rem; }
}

/* ======================================================= adjustable lines */
:root { --line-w: 2px; --line-color: var(--line-strong); --card-w: 1.5px; }
.tree li::before, .tree li::after { border-top-width: var(--line-w); border-top-color: var(--line-color); }
.tree li::after { border-left-width: var(--line-w); border-left-color: var(--line-color); }
.tree li:only-child::after { margin-left: calc(var(--line-w) / -2); }
.tree li:last-child::before { border-right-width: var(--line-w); border-right-color: var(--line-color); }
.tree ul ul::before { border-left-width: var(--line-w); border-left-color: var(--line-color); margin-left: calc(var(--line-w) / -2); }
.lineage-connector { width: var(--line-w); }
.node { border-width: var(--card-w); }
.node .toggle { border-width: var(--card-w); }

.line-panel {
  position: absolute; right: 46px; top: 0; width: 230px; background: var(--paper); border: 1px solid var(--line); border-radius: 14px;
  box-shadow: var(--shadow-md); padding: 12px 14px 12px; z-index: 6; text-align: left;
}
.line-panel-title { font-weight: 700; font-size: 0.86rem; color: var(--green-900); margin-bottom: 8px; }
.line-panel-label { font-size: 0.68rem; text-transform: uppercase; letter-spacing: 0.7px; color: var(--ink-faint); font-weight: 700; margin: 8px 0 6px; }
.line-widths { display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; }
.line-w { height: 34px; border-radius: 8px; border: 1px solid var(--line); background: var(--cream); display: flex; align-items: center; padding: 0 8px; }
.line-w span { display: block; width: 100%; background: var(--line-color); border-radius: 2px; }
.line-w.active { border-color: var(--green-700); background: var(--green-100); box-shadow: 0 0 0 2px rgba(43, 106, 80, 0.2); }
.line-colors { display: grid; grid-template-columns: repeat(8, 1fr); gap: 6px; }
.line-c { width: 100%; aspect-ratio: 1; border-radius: 50%; border: 2px solid #fff; background: var(--c); box-shadow: 0 0 0 1px var(--line); cursor: pointer; }
.line-c.active { box-shadow: 0 0 0 2px var(--green-700); transform: scale(1.1); }
.line-panel-note { font-size: 0.72rem; color: var(--ink-soft); margin: 10px 0 6px; line-height: 1.4; }
.zoom-controls { position: absolute; }
.zoom-btn.active { background: var(--green-800); color: #fff; border-color: var(--green-800); }
@media (max-width: 640px) {
  .line-panel { right: 42px; width: min(230px, calc(100vw - 70px)); }
}

/* ---------------------------------------------------------- spouse links */
.links { position: absolute; inset: 0; width: 100%; height: 100%; pointer-events: none; overflow: visible; z-index: 1; }
.links path { fill: none; stroke: var(--female); stroke-dasharray: 7 5; stroke-linecap: round; opacity: 0.85; }
.links text { fill: var(--female); font-size: 16px; font-family: var(--font-body); }
.links circle { fill: var(--paper); stroke: var(--female); }
.node .spouse.linked { color: var(--female); font-weight: 600; cursor: pointer; text-decoration: underline dotted; text-underline-offset: 2px; }
.node .spouse.linked:hover { color: #a03d62; }
.tree { position: relative; z-index: 2; }
.links path, .links circle { stroke-width: var(--line-w); }
