/* ==========================================================================
   Tokens
   ========================================================================== */
:root {
  --bg: #f6f4ef;
  --surface: #ffffff;
  --surface-2: #f0ede6;
  --text: #1b2230;
  --muted: #5d6676;
  --faint: #8a92a0;
  --border: #e2ddd3;
  --border-strong: #cfc8bb;
  --accent: #1f4e8c;
  --accent-contrast: #ffffff;
  --accent-soft: rgba(31, 78, 140, .10);
  --highlight: #d99a00;
  --ok: #1d8a63;
  --warn: #b7860b;
  --bad: #c2413b;
  --link-stroke: #c9c2b4;
  --halo: #f6f4ef;
  --shadow: 0 1px 2px rgba(20, 24, 33, .06), 0 8px 24px rgba(20, 24, 33, .08);

  /* generation palette (root, 1st, 2nd, 3rd, 4th+) */
  --gen-0: #1b2230;
  --gen-1: #1f4e8c;
  --gen-2: #2a8a7a;
  --gen-3: #c26a1d;
  --gen-4: #8a4fb0;

  --radius: 10px;
  --radius-sm: 6px;
  --font-sans: "Inter", system-ui, -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  --font-serif: "Source Serif 4", Georgia, "Times New Roman", serif;
  --header-h: 56px;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0f1318;
    --surface: #161b22;
    --surface-2: #1c222b;
    --text: #e6e9ef;
    --muted: #a3acba;
    --faint: #6f7987;
    --border: #262d38;
    --border-strong: #343c49;
    --accent: #7fa9e8;
    --accent-contrast: #0f1318;
    --accent-soft: rgba(127, 169, 232, .14);
    --highlight: #f2c14e;
    --ok: #3cc28f;
    --warn: #e0b445;
    --bad: #ec6c66;
    --link-stroke: #39414e;
    --halo: #0f1318;
    --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 8px 24px rgba(0, 0, 0, .35);
    --gen-0: #e6e9ef;
    --gen-1: #7fa9e8;
    --gen-2: #5cc6b2;
    --gen-3: #eb9b55;
    --gen-4: #b98ade;
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #0f1318;
  --surface: #161b22;
  --surface-2: #1c222b;
  --text: #e6e9ef;
  --muted: #a3acba;
  --faint: #6f7987;
  --border: #262d38;
  --border-strong: #343c49;
  --accent: #7fa9e8;
  --accent-contrast: #0f1318;
  --accent-soft: rgba(127, 169, 232, .14);
  --highlight: #f2c14e;
  --ok: #3cc28f;
  --warn: #e0b445;
  --bad: #ec6c66;
  --link-stroke: #39414e;
  --halo: #0f1318;
  --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 8px 24px rgba(0, 0, 0, .35);
  --gen-0: #e6e9ef;
  --gen-1: #7fa9e8;
  --gen-2: #5cc6b2;
  --gen-3: #eb9b55;
  --gen-4: #b98ade;
  color-scheme: dark;
}

/* ==========================================================================
   Base
   ========================================================================== */
* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  font-family: var(--font-sans);
  font-size: 15px;
  line-height: 1.5;
  background: var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
}
a { color: var(--accent); }
h1, h2, h3 { font-family: var(--font-serif); font-weight: 600; line-height: 1.2; margin: 0 0 12px; }
h1 { font-size: 28px; letter-spacing: -.01em; }
p { margin: 0 0 12px; }
button, input, select { font: inherit; color: inherit; }
[hidden] { display: none !important; }
.visually-hidden {
  position: absolute; width: 1px; height: 1px; overflow: hidden;
  clip: rect(0 0 0 0); white-space: nowrap;
}
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

.container { width: min(1120px, 100%); margin: 0 auto; padding: 0 16px; }

/* ==========================================================================
   Header / nav
   ========================================================================== */
.site-header {
  position: sticky; top: 0; z-index: 30;
  height: var(--header-h);
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--border);
}
.site-header .bar {
  height: 100%;
  display: flex; align-items: center; gap: 16px;
  padding: 0 16px;
}
.brand {
  display: flex; align-items: center; gap: 10px;
  color: var(--text); text-decoration: none;
  font-family: var(--font-serif); font-weight: 600; font-size: 18px;
  white-space: nowrap; min-width: 0;
}
.brand-mark { flex: none; color: var(--accent); }
.brand-text { overflow: hidden; text-overflow: ellipsis; }
.nav { display: flex; align-items: center; gap: 4px; margin-left: auto; }
.nav a {
  color: var(--muted); text-decoration: none; white-space: nowrap;
  padding: 6px 10px; border-radius: var(--radius-sm); font-size: 14px; font-weight: 500;
}
.nav a:hover { color: var(--text); background: var(--surface-2); }
.nav a[aria-current="page"] { color: var(--text); background: var(--surface-2); }

.icon-btn {
  display: inline-grid; place-items: center;
  width: 34px; height: 34px; padding: 0;
  border: 1px solid var(--border); border-radius: var(--radius-sm);
  background: var(--surface); color: var(--muted); cursor: pointer;
}
.icon-btn:hover { color: var(--text); border-color: var(--border-strong); }
.icon-btn svg { width: 18px; height: 18px; }

@media (max-width: 640px) {
  .brand-text .long { display: none; }
  .site-header .bar { gap: 8px; }
}
@media (max-width: 440px) {
  .brand-text { display: none; }
  .nav a { padding: 6px 7px; font-size: 13px; }
}

/* ==========================================================================
   Buttons, inputs, panels
   ========================================================================== */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  padding: 7px 12px; border-radius: var(--radius-sm);
  border: 1px solid var(--border); background: var(--surface); color: var(--text);
  font-size: 14px; font-weight: 500; text-decoration: none; cursor: pointer; white-space: nowrap;
}
.btn:hover { border-color: var(--border-strong); background: var(--surface-2); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-contrast); }
.btn.primary:hover { filter: brightness(1.08); }
.btn.small { padding: 4px 9px; font-size: 13px; }
.btn[disabled] { opacity: .45; cursor: not-allowed; }
.btn svg { width: 16px; height: 16px; }

.input {
  width: 100%;
  background: var(--surface); color: var(--text);
  border: 1px solid var(--border-strong); border-radius: var(--radius-sm);
  padding: 8px 11px;
}
.input:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }

.page { padding: 28px 0 48px; }
.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; flex-wrap: wrap; margin-bottom: 20px; }
.page-head h1 { margin: 0; }
.page-head .sub { color: var(--muted); margin: 4px 0 0; }

.panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 24px;
}
.badge {
  display: inline-block; vertical-align: middle;
  background: var(--accent-soft); color: var(--accent);
  border-radius: 999px; padding: 1px 8px; font-size: 11px; font-weight: 600; margin-left: 6px;
}

/* ==========================================================================
   Tables (directory / manage)
   ========================================================================== */
.table-tools { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.table-tools .input { width: min(320px, 100%); }
.count { color: var(--muted); font-size: 13px; }
.table-wrap { overflow-x: auto; border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface); }
.table { width: 100%; border-collapse: collapse; font-size: 14px; }
.table th, .table td { text-align: left; padding: 10px 14px; border-bottom: 1px solid var(--border); vertical-align: middle; }
.table tbody tr:last-child td { border-bottom: 0; }
.table tbody tr:hover { background: var(--surface-2); }
.table th {
  position: sticky; top: 0; background: var(--surface-2);
  font-size: 12px; font-weight: 600; text-transform: uppercase; letter-spacing: .04em; color: var(--muted);
  white-space: nowrap; user-select: none;
}
.table th[data-key] { cursor: pointer; }
.table th[data-key]:hover { color: var(--text); }
.table th.sorted-asc::after { content: " ↑"; }
.table th.sorted-desc::after { content: " ↓"; }
.table td.num, .table th.num { text-align: right; font-variant-numeric: tabular-nums; }
.table td.actions { white-space: nowrap; text-align: right; }
.table .person-name { font-weight: 600; color: var(--text); text-decoration: none; }
.table a.person-name:hover { color: var(--accent); text-decoration: underline; }
.table .muted { color: var(--muted); }
.gen-dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; margin-right: 8px; vertical-align: middle; }

/* ==========================================================================
   Viewer
   ========================================================================== */
body.viewer { overflow: hidden; }
.viewer-shell {
  position: relative;
  height: calc(100dvh - var(--header-h));
  display: grid;
  grid-template-columns: 1fr auto;
}
.stage { position: relative; min-width: 0; overflow: hidden; }

.toolbar {
  position: absolute; top: 16px; left: 16px; right: 16px; z-index: 5;
  display: flex; gap: 10px; align-items: flex-start; flex-wrap: wrap;
  pointer-events: none;
}
.toolbar > * { pointer-events: auto; }

.search { position: relative; width: min(380px, 100%); }
.search-box {
  display: flex; align-items: center; gap: 8px;
  background: var(--surface); border: 1px solid var(--border-strong); border-radius: var(--radius);
  padding: 0 10px; box-shadow: var(--shadow);
}
.search-box:focus-within { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft), var(--shadow); }
.search-box svg { width: 16px; height: 16px; color: var(--faint); flex: none; }
.search-box input { flex: 1; min-width: 0; border: 0; background: none; padding: 10px 0; outline: none; }
.search-box kbd {
  font: 500 11px var(--font-sans); color: var(--faint);
  border: 1px solid var(--border); border-radius: 4px; padding: 1px 6px;
}
.search-results {
  position: absolute; left: 0; right: 0; top: calc(100% + 6px);
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  box-shadow: var(--shadow); list-style: none; margin: 0; padding: 6px; max-height: 360px; overflow-y: auto;
}
.search-results li {
  display: grid; grid-template-columns: auto 1fr; gap: 0 10px; align-items: center;
  padding: 7px 10px; border-radius: var(--radius-sm); cursor: pointer;
}
.search-results li[aria-selected="true"] { background: var(--accent-soft); }
.search-results .r-name { font-weight: 600; font-size: 14px; }
.search-results .r-meta { grid-column: 2; color: var(--muted); font-size: 12px; }
.search-results mark { background: none; color: var(--accent); }
.search-results .empty { color: var(--muted); cursor: default; display: block; }

.seg {
  display: inline-flex; background: var(--surface); border: 1px solid var(--border-strong);
  border-radius: var(--radius); padding: 3px; box-shadow: var(--shadow);
}
.seg button {
  border: 0; background: none; padding: 6px 12px; border-radius: 7px; cursor: pointer;
  font-size: 13px; font-weight: 500; color: var(--muted);
}
.seg button[aria-pressed="true"] { background: var(--accent); color: var(--accent-contrast); }
.tool-group { display: inline-flex; gap: 6px; }
.storybar {
  display: inline-flex; align-items: center; gap: 4px;
  background: var(--surface); border: 1px solid var(--border-strong);
  border-radius: var(--radius); padding: 3px; box-shadow: var(--shadow);
}
.storybar .btn { border: 0; padding: 6px 10px; font-size: 13px; min-width: 32px; }
.storybar .btn[aria-pressed="true"] { background: var(--accent); color: var(--accent-contrast); }
.speed { display: inline-flex; gap: 2px; padding: 0 4px; margin: 0 2px; border-left: 1px solid var(--border); border-right: 1px solid var(--border); }
.speed button {
  border: 0; background: none; cursor: pointer; padding: 5px 7px; border-radius: 6px;
  font-size: 12px; font-weight: 600; color: var(--muted); font-variant-numeric: tabular-nums;
}
.speed button:hover { color: var(--text); }
.speed button[aria-pressed="true"] { background: var(--accent-soft); color: var(--accent); }
.story-pos { font-size: 12px; color: var(--muted); padding: 0 8px 0 4px; font-variant-numeric: tabular-nums; min-width: 64px; }
.story-pos:empty { display: none; }
.tool-group .btn { box-shadow: var(--shadow); padding: 8px 12px; }

.stats {
  position: absolute; left: 16px; bottom: 16px; z-index: 5;
  background: color-mix(in srgb, var(--surface) 92%, transparent);
  border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow);
  padding: 12px 14px; font-size: 12px; color: var(--muted);
  display: grid; gap: 10px; max-width: calc(100% - 32px);
}
.stats-nums { display: flex; gap: 18px; }
.stats-nums b { display: block; font: 600 20px/1.1 var(--font-serif); color: var(--text); font-variant-numeric: tabular-nums; }
.legend { display: flex; gap: 12px; flex-wrap: wrap; }
.legend span { display: inline-flex; align-items: center; gap: 5px; }
.legend i { width: 9px; height: 9px; border-radius: 50%; display: inline-block; }

.zoom-ctl {
  position: absolute; right: 16px; bottom: 16px; z-index: 5;
  display: grid; background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); box-shadow: var(--shadow); overflow: hidden;
}
.zoom-ctl button {
  width: 36px; height: 36px; border: 0; background: none; cursor: pointer; color: var(--muted);
  display: grid; place-items: center;
}
.zoom-ctl button + button { border-top: 1px solid var(--border); }
.zoom-ctl button:hover { color: var(--text); background: var(--surface-2); }
.zoom-ctl svg { width: 16px; height: 16px; }

.stats .hint { color: var(--faint); font-size: 11px; }
@media (max-width: 640px) {
  #foldTools { display: none; }
  .stats-nums b { font-size: 16px; }
  .stats .legend, .stats .hint { display: none; }
}

.tree-canvas { position: absolute; inset: 0; }
.tree-canvas svg { display: block; width: 100%; height: 100%; cursor: grab; touch-action: none; }
.tree-canvas svg:active { cursor: grabbing; }
.loading { position: absolute; inset: 0; display: grid; place-items: center; color: var(--muted); }

/* SVG elements */
.link { fill: none; stroke: var(--link-stroke); stroke-width: 1.2px; transition: stroke .2s, stroke-width .2s, opacity .2s; }
.link.on-path { stroke: var(--highlight); stroke-width: 2.5px; }
.node { cursor: pointer; }
.node circle { stroke: var(--bg); stroke-width: 2px; transition: r .2s; }
.node circle.collapsed-ring { fill: none; stroke: currentColor; stroke-width: 1.5px; stroke-dasharray: 2 2; opacity: .8; }
.node text { fill: var(--text); paint-order: stroke; stroke: var(--halo); stroke-width: 3.5px; stroke-linejoin: round; }
.node .label-name { font-size: 13px; font-weight: 600; }
.node .label-meta { font-size: 11px; fill: var(--muted); font-weight: 400; }
.node .count-pill { font-size: 10px; font-weight: 600; fill: var(--muted); }
.node:hover .label-name { fill: var(--accent); }
.node.on-path .label-name { fill: var(--text); }
.node.selected circle.dot { stroke: var(--highlight); stroke-width: 3px; }
.node.match .label-name { fill: var(--accent); }
.dimmed .node:not(.on-path):not(.related) { opacity: .35; }
.dimmed .link:not(.on-path) { opacity: .4; }
.story .node.selected .label-name { font-family: var(--font-serif); font-size: 20px; }
.story .node.selected .label-meta { font-size: 13px; }
.story .node:not(.on-path):not(.related) .label-name { font-size: 12px; }

.tooltip {
  position: absolute; z-index: 6; pointer-events: none;
  background: var(--surface); color: var(--text);
  border: 1px solid var(--border); border-radius: var(--radius-sm); box-shadow: var(--shadow);
  padding: 7px 10px; font-size: 12px; max-width: 280px;
  opacity: 0; transition: opacity .12s;
}
.tooltip strong { display: block; font-size: 13px; }
.tooltip span { color: var(--muted); }

/* Slideshow (Storybook while playing) */
.slide-year {
  position: absolute; left: 24px; top: 120px; z-index: 0; pointer-events: none;
  font: 600 clamp(96px, 15vw, 220px)/1 var(--font-serif); letter-spacing: -.03em;
  color: var(--text); opacity: .07; display: none;
}
.slideshow .slide-year { display: block; }
.slide-year span { display: inline-block; animation: year-in calc(.9s / var(--speed, 1)) ease-out both; }
@keyframes year-in { from { opacity: 0; transform: translateY(24px); } }
.tree-canvas { z-index: 1; }
.slide-host {
  position: absolute; right: 24px; top: 50%; transform: translateY(-50%); z-index: 6;
  width: min(360px, calc(100% - 32px)); pointer-events: none;
}
.slide-card {
  pointer-events: auto;
  background: var(--surface); border: 1px solid var(--border); border-radius: 14px;
  box-shadow: 0 2px 4px rgba(0, 0, 0, .06), 0 18px 48px rgba(0, 0, 0, .16);
  padding: 22px 24px 18px;
  animation: card-in calc(.6s / var(--speed, 1)) cubic-bezier(.2, 1.35, .4, 1) calc(.3s / var(--speed, 1)) both;
}
@keyframes card-in { from { opacity: 0; transform: translateY(16px) scale(.94); } }
.slide-chapter {
  display: flex; align-items: center; gap: 8px;
  font-size: 12px; font-weight: 600; letter-spacing: .08em; text-transform: uppercase; color: var(--muted);
}
.slide-chapter i { width: 9px; height: 9px; border-radius: 50%; }
.slide-card h2 { font-size: 30px; margin: 8px 0 4px; }
.slide-head { display: flex; align-items: center; gap: 16px; }
.slide-photo {
  width: 84px; height: 84px; flex: none; border-radius: 50%; object-fit: cover; object-position: center 25%;
  box-shadow: 0 0 0 3px var(--surface), 0 0 0 4px var(--highlight);
  animation: photo-in calc(.6s / var(--speed, 1)) cubic-bezier(.2, 1.5, .4, 1) calc(.45s / var(--speed, 1)) both;
}
@keyframes photo-in { from { opacity: 0; transform: scale(.6); } }
.slide-inst { color: var(--muted); margin-bottom: 10px; }
.slide-card p { font-family: var(--font-serif); font-size: 16px; line-height: 1.5; margin: 0; }
.slide-progress { height: 3px; background: var(--surface-2); border-radius: 2px; overflow: hidden; margin-top: 16px; }
.slide-progress i {
  display: block; height: 100%; background: var(--highlight); transform-origin: left;
  animation: slide-progress var(--play-ms, 4500ms) linear both;
}
@keyframes slide-progress { from { transform: scaleX(0); } }
.slideshow .stats { display: none; }

.node .pulse { display: none; fill: none; stroke: var(--highlight); stroke-width: 2px; }
.slideshow .node.selected .pulse {
  display: block; transform-box: fill-box; transform-origin: center;
  animation: pulse calc(1.5s / var(--speed, 1)) ease-out calc(.45s / var(--speed, 1)) 2 both;
}
@keyframes pulse { from { transform: scale(1); opacity: .9; } to { transform: scale(4.5); opacity: 0; } }
.node.pop circle.dot {
  transform-box: fill-box; transform-origin: center;
  animation: dot-pop calc(.5s / var(--speed, 1)) cubic-bezier(.3, 1.8, .5, 1) both;
  animation-delay: calc((350ms + var(--pop-i, 0) * 45ms) / var(--speed, 1));
}
@keyframes dot-pop { from { transform: scale(0); } }
.node.pop .label {
  animation: label-pop calc(.45s / var(--speed, 1)) ease-out both;
  animation-delay: calc((450ms + var(--pop-i, 0) * 45ms) / var(--speed, 1));
}
@keyframes label-pop { from { opacity: 0; } }

@media (max-width: 900px) {
  .slide-host { top: auto; bottom: 16px; left: 16px; right: 16px; transform: none; width: auto; }
  .slide-card { padding: 16px 18px 14px; }
  .slide-card h2 { font-size: 22px; }
  .slide-photo { width: 60px; height: 60px; }
  .slide-year { top: 170px; }
  .slideshow .node.selected .label { display: none; } /* the slide card already names them */
}
@media (prefers-reduced-motion: reduce) {
  .slide-card, .slide-year span, .node.pop circle.dot, .node.pop .label { animation: none; }
  .slideshow .node.selected .pulse { animation: none; display: none; }
}

/* Details drawer */
.details {
  width: 380px; height: 100%; overflow-y: auto;
  background: var(--surface); border-left: 1px solid var(--border);
  padding: 22px 22px 32px;
  animation: drawer-in .2s ease-out;
}
@keyframes drawer-in { from { opacity: 0; transform: translateX(16px); } }
.details-top { display: flex; align-items: center; justify-content: space-between; margin-bottom: 14px; }
.gen-chip {
  display: inline-flex; align-items: center; gap: 6px;
  font-size: 12px; font-weight: 600; color: var(--muted);
  text-transform: uppercase; letter-spacing: .05em;
}
.gen-chip i { width: 9px; height: 9px; border-radius: 50%; }
.details h2 { font-size: 26px; margin: 0 0 6px; }
.person-head { display: flex; align-items: center; gap: 14px; margin-bottom: 4px; }
.person-head h2 { margin: 0; }
.person-head .position { color: var(--muted); font-size: 14px; margin-top: 2px; }
.avatar {
  width: 72px; height: 72px; flex: none; border-radius: 50%; object-fit: cover; object-position: center 25%;
  border: 2px solid var(--surface); box-shadow: 0 0 0 1px var(--border); background: var(--surface-2);
}
.bio-summary { font-size: 14px; line-height: 1.55; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; margin: 0 0 12px; }
.chip { font-size: 12px; padding: 2px 9px; border-radius: 999px; background: var(--accent-soft); color: var(--accent); }
.facts { margin: 0 0 12px; font-size: 13px; display: grid; grid-template-columns: auto 1fr; gap: 6px 12px; }
.facts dt { color: var(--muted); }
.facts dd { margin: 0; }
.facts ul { margin: 0; padding-left: 16px; }
.sources { font-size: 12px; color: var(--muted); margin-bottom: 22px; }
.sources a { color: var(--muted); }
.story-text { font-family: var(--font-serif); font-weight: 400; font-size: 16px; line-height: 1.5; color: var(--text); margin: 4px 0 14px; }
.details .meta { color: var(--muted); margin-bottom: 16px; }
.details .meta div { display: flex; gap: 8px; align-items: center; }
.details .meta svg { width: 15px; height: 15px; flex: none; color: var(--faint); }
.details-actions { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 22px; }
.metric-row { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-bottom: 22px; }
.metric { background: var(--surface-2); border-radius: var(--radius-sm); padding: 10px 12px; }
.metric b { display: block; font: 600 22px/1.1 var(--font-serif); font-variant-numeric: tabular-nums; }
.metric span { font-size: 12px; color: var(--muted); }
.details h3 {
  font-family: var(--font-sans); font-size: 12px; font-weight: 600; color: var(--muted);
  text-transform: uppercase; letter-spacing: .05em; margin: 0 0 8px;
}
.lineage { list-style: none; margin: 0 0 22px; padding: 0; }
.lineage li { position: relative; padding: 0 0 8px 20px; }
.lineage li::before {
  content: ""; position: absolute; left: 4px; top: 7px; width: 7px; height: 7px; border-radius: 50%;
  background: var(--border-strong);
}
.lineage li:not(:last-child)::after {
  content: ""; position: absolute; left: 7px; top: 16px; bottom: -2px; width: 1px; background: var(--border-strong);
}
.lineage li:last-child::before { background: var(--highlight); }
.lineage li:last-child { font-weight: 600; }
.person-link {
  background: none; border: 0; padding: 0; cursor: pointer; color: var(--text);
  text-align: left; font-size: 14px;
}
.person-link:hover { color: var(--accent); text-decoration: underline; }
.advisee-list { list-style: none; margin: 0; padding: 0; border-top: 1px solid var(--border); }
.advisee-list li { display: flex; justify-content: space-between; gap: 10px; padding: 8px 0; border-bottom: 1px solid var(--border); font-size: 14px; }
.advisee-list .yr { color: var(--muted); font-variant-numeric: tabular-nums; white-space: nowrap; }
.advisee-list .sub { display: block; color: var(--muted); font-size: 12px; }
.empty-note { color: var(--muted); font-size: 14px; }

@media (max-width: 900px) {
  .viewer-shell { grid-template-columns: 1fr; }
  .details {
    position: absolute; left: 0; right: 0; bottom: 0; z-index: 10;
    width: auto; height: auto; max-height: 62%;
    border-left: 0; border-top: 1px solid var(--border);
    border-radius: 14px 14px 0 0; box-shadow: var(--shadow);
    animation-name: sheet-in;
  }
  @keyframes sheet-in { from { opacity: 0; transform: translateY(24px); } }
}

/* ==========================================================================
   Initials avatars, sources, correction link
   ========================================================================== */
.initials {
  display: grid; place-items: center;
  color: #fff; font-family: var(--font-sans); font-weight: 600; letter-spacing: .02em;
  user-select: none;
}
.avatar.initials { font-size: 24px; }
.slide-photo.initials { font-size: 28px; }
.intro-photo.initials { font-size: 30px; }
.slide-lineage { font-size: 12px; color: var(--muted); margin: -2px 0 10px; }
.source-list { list-style: none; margin: 0 0 16px; padding: 0; font-size: 13px; }
.source-list li { display: flex; justify-content: space-between; gap: 10px; padding: 5px 0; border-bottom: 1px solid var(--border); }
.source-list li span { color: var(--muted); }
.source-list a { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.btn.correction { font-size: 13px; }
.table .sub { display: block; color: var(--faint); font-size: 12px; }

/* Search: result count */
.search-results li.count {
  display: block; cursor: default; padding: 2px 10px 6px;
  font-size: 11px; font-weight: 600; text-transform: uppercase; letter-spacing: .05em; color: var(--faint);
}

/* Colour-by control and clickable legend */
.color-by { display: flex; align-items: center; gap: 8px; font-size: 12px; }
.color-by select {
  font-size: 12px; padding: 3px 6px; border-radius: var(--radius-sm);
  border: 1px solid var(--border-strong); background: var(--surface); color: var(--text);
}
.legend { max-width: 420px; }
.legend button {
  display: inline-flex; align-items: center; gap: 5px;
  border: 0; background: none; padding: 1px 4px; margin: 0 -4px; border-radius: 4px;
  font-size: 12px; color: var(--muted); cursor: pointer;
}
.legend button:hover { color: var(--text); }
.legend button[aria-pressed="true"] { color: var(--text); background: var(--accent-soft); font-weight: 600; }
.filtering .node:not(.in-focus) { opacity: .15; }
.filtering .node.in-focus .label-name { fill: var(--text); }

/* Narrow screens: layout + playback controls fold behind one button */
.tools-toggle { display: none; box-shadow: var(--shadow); padding: 9px 10px; }
.tools-toggle svg { width: 18px; height: 18px; }
@media (max-width: 640px) {
  .toolbar { left: 12px; right: 12px; top: 12px; gap: 8px; }
  .search { flex: 1; width: auto; }
  .tools-toggle { display: inline-flex; }
  .toolbar .seg, .toolbar .storybar { display: none; }
  .toolbar.tools-open .seg, .toolbar.tools-open .storybar { display: inline-flex; }
  .storybar { flex-wrap: wrap; }
  .speed { border: 0; }
  .search-box kbd { display: none; }
  .stats .color-by { display: none; }
}

/* Intro card */
.intro {
  position: fixed; inset: 0; z-index: 40;
  display: grid; place-items: center; padding: 16px;
  background: color-mix(in srgb, var(--bg) 55%, transparent);
  backdrop-filter: blur(3px);
  animation: fade-in .25s ease-out;
}
@keyframes fade-in { from { opacity: 0; } }
.intro-card {
  width: min(520px, 100%); max-height: calc(100dvh - 32px); overflow-y: auto;
  background: var(--surface); border: 1px solid var(--border); border-radius: 16px;
  box-shadow: 0 2px 4px rgba(0, 0, 0, .06), 0 24px 64px rgba(0, 0, 0, .2);
  padding: 28px 28px 24px; text-align: center;
  animation: card-in .5s cubic-bezier(.2, 1.35, .4, 1) both;
}
.intro-photo {
  width: 96px; height: 96px; border-radius: 50%; object-fit: cover; object-position: center 25%;
  margin: 0 auto 14px; box-shadow: 0 0 0 3px var(--surface), 0 0 0 4px var(--highlight);
}
.intro-card h2 { font-size: 26px; margin-bottom: 10px; }
.intro-card p { color: var(--muted); font-size: 15px; }
.intro-nums { display: flex; justify-content: center; gap: 22px; flex-wrap: wrap; margin: 18px 0; font-size: 12px; color: var(--muted); }
.intro-nums b { display: block; font: 600 26px/1.1 var(--font-serif); color: var(--text); font-variant-numeric: tabular-nums; }
.intro-hint { font-size: 13px !important; }
.intro-actions { display: flex; justify-content: center; gap: 10px; flex-wrap: wrap; margin-top: 18px; }
.intro-actions .btn { padding: 10px 18px; font-size: 15px; }
@media (prefers-reduced-motion: reduce) { .intro, .intro-card { animation: none; } }
