:root {
  --bg: #f7f4ef; --panel: #fffdfa; --ink: #221f1a; --muted: #6d665a;
  --line: #e6ded1; --accent: #9a5b2a; --accent-ink: #fff;
  --apex: #b23b2e; --blood: #8a5a2b; --spouse: #3f6d88; --chip: #efe7d9;
  --shadow: 0 1px 3px rgba(60,45,25,.08), 0 6px 20px rgba(60,45,25,.06);
  /* diagram node fills + a connector line tone that reads on the card bg */
  --node-bg: #fffdfa; --apex-bg: #f7e4df; --spouse-bg: #eef2f5;
  /* "you're viewing this person" — a gold highlight, deliberately unlike the warm apex red */
  --focus-bg: #fdf0c4; --focus-ring: #b5851a;
  --diagram-line: #a1917a;
}
@media (prefers-color-scheme: dark) { :root:not([data-theme=light]) {
  --bg: #16130d; --panel: #201c14; --ink: #ece6da; --muted: #a49a87;
  --line: #342d21; --accent: #d99a5c; --accent-ink: #1a1409;
  --apex: #e8776a; --blood: #d99a5c; --spouse: #7fb2d4; --chip: #2b2417;
  --shadow: 0 1px 3px rgba(0,0,0,.3), 0 8px 24px rgba(0,0,0,.25);
  --node-bg: #241f16; --apex-bg: #3a231f; --spouse-bg: #1e2831;
  --focus-bg: #3d3410; --focus-ring: #d9b24a;
  --diagram-line: #6f624a;
} }
* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg); color: var(--ink);
  font: 16px/1.55 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
}
a { color: var(--accent); text-decoration: none; cursor: pointer; }
a:hover { text-decoration: underline; }
button { font: inherit; cursor: pointer; }

header {
  position: sticky; top: 0; z-index: 10; background: var(--panel);
  border-bottom: 1px solid var(--line); padding: 12px 18px;
  display: flex; align-items: center; gap: 14px; flex-wrap: wrap;
}
header .brand { font-weight: 700; font-size: 18px; letter-spacing: -.01em; cursor: pointer; }
header .brand:hover { color: var(--accent); }
header .brand span { color: var(--accent); }
header nav { display: flex; gap: 4px; }
header nav button {
  background: none; border: 1px solid transparent; color: var(--muted);
  padding: 6px 12px; border-radius: 8px; font-weight: 600; font-size: 14px;
}
header nav button.active { background: var(--chip); color: var(--ink); }
header nav button:hover { color: var(--ink); }
header .who { margin-left: auto; color: var(--muted); font-size: 13px; }

main { max-width: 860px; margin: 0 auto; padding: 22px 18px 80px; }
.hidden { display: none !important; }

.hero { text-align: center; padding: 26px 0 10px; }
.hero h1 { font-size: 27px; margin: 0 0 6px; letter-spacing: -.02em; }
.hero p { color: var(--muted); margin: 0 0 20px; }

.search { position: relative; max-width: 520px; margin: 0 auto; }
.search input {
  width: 100%; padding: 13px 16px; font-size: 16px; border-radius: 12px;
  border: 1px solid var(--line); background: var(--panel); color: var(--ink);
  box-shadow: var(--shadow);
}
.search input:focus { outline: 2px solid var(--accent); border-color: transparent; }
.results {
  position: absolute; left: 0; right: 0; margin-top: 6px; background: var(--panel);
  border: 1px solid var(--line); border-radius: 12px; box-shadow: var(--shadow);
  max-height: 340px; overflow: auto; z-index: 5;
}
.results .row { padding: 10px 14px; border-bottom: 1px solid var(--line); }
.results .row:last-child { border-bottom: none; }
.results .row:hover, .results .row.sel { background: var(--chip); }
.results .row .nm { font-weight: 600; }
.results .row .sub { color: var(--muted); font-size: 13px; }

.card {
  background: var(--panel); border: 1px solid var(--line); border-radius: 14px;
  padding: 20px 22px; box-shadow: var(--shadow); margin: 0 0 16px;
}
.profile-top { display: flex; gap: 16px; align-items: flex-start; }
.avatar {
  width: 72px; height: 72px; border-radius: 16px; flex: 0 0 auto;
  object-fit: cover; border: 1px solid var(--line);
}
.avatar.ph {
  display: flex; align-items: center; justify-content: center;
  background: var(--chip); color: var(--muted); font-weight: 700; font-size: 24px;
}
.person-head { display: flex; align-items: baseline; gap: 12px; flex-wrap: wrap; }
.person-head h2 { margin: 0; font-size: 24px; letter-spacing: -.01em; }
.person-head .dates { color: var(--muted); font-size: 15px; }
.aka { color: var(--muted); font-size: 14px; margin-top: 3px; }
.aka b { color: var(--ink); font-weight: 600; }
.badge {
  font-size: 12px; font-weight: 700; padding: 3px 9px; border-radius: 999px;
  background: var(--chip); color: var(--muted);
}
.badge.apex { color: var(--apex); } .badge.blood { color: var(--blood); }
.badge.spouse { color: var(--spouse); }

.rel-grid { margin-top: 16px; display: grid; gap: 14px; }
.rel-block h3 {
  font-size: 12px; text-transform: uppercase; letter-spacing: .06em;
  color: var(--muted); margin: 0 0 7px; font-weight: 700;
}
.chips { display: flex; flex-wrap: wrap; gap: 7px; }
.chip {
  background: var(--chip); border: 1px solid var(--line); border-radius: 999px;
  padding: 5px 12px; font-size: 14px; font-weight: 500;
}
.chip .yr { color: var(--muted); font-size: 12px; margin-left: 5px; }

.actions { margin-top: 18px; display: flex; gap: 10px; flex-wrap: wrap; }
.btn {
  background: var(--accent); color: var(--accent-ink); border: none;
  padding: 10px 16px; border-radius: 10px; font-weight: 600; font-size: 15px;
}
.btn.ghost { background: transparent; color: var(--accent); border: 1px solid var(--line); }
.btn:hover { filter: brightness(1.05); }

.field { margin: 0 0 14px; }
.field label { display: block; font-weight: 600; font-size: 14px; margin-bottom: 5px; }
.field input, .field select, .field textarea {
  width: 100%; padding: 10px 12px; border-radius: 10px; font-size: 15px;
  border: 1px solid var(--line); background: var(--bg); color: var(--ink);
}
.field .hint { color: var(--muted); font-size: 13px; margin-top: 4px; }

.rel-result {
  text-align: center; padding: 20px; background: var(--chip);
  border-radius: 12px; margin-top: 16px;
}
.rel-result .verdict { font-size: 20px; font-weight: 700; margin-bottom: 6px; }
.rel-result .verdict b { color: var(--accent); }
.rel-result .gloss { color: var(--muted); font-size: 15px; margin-bottom: 4px; }
.reldiagram { overflow: auto; margin: 14px 0 4px; display: flex; justify-content: center; }
.reldiagram svg { max-width: 100%; height: auto; }
.reldiagram g[data-pid] rect { transition: filter .12s; }
.reldiagram g[data-pid]:hover rect { filter: brightness(0.96); }
.ex-legend { display: flex; gap: 16px; flex-wrap: wrap; margin-top: 10px; font-size: 13px; color: var(--muted); }
.ex-legend .sw { display: inline-block; width: 12px; height: 12px; border-radius: 3px; vertical-align: middle; margin-right: 5px; border: 1px solid; }
.ex-legend .sw.blood { background: var(--node-bg); border-color: var(--blood); }
.ex-legend .sw.spouse { background: var(--spouse-bg); border-color: var(--spouse); }
.ex-legend .sw.apex { background: var(--apex-bg); border-color: var(--apex); }
.ex-legend .sw.focus { background: var(--focus-bg); border-color: var(--focus-ring); }
.ex-legend .sw.formerbar { width: 16px; height: 0; border: 0; border-top: 2px dashed var(--muted); border-radius: 0; }
.explore { overflow: auto; margin-top: 14px; max-height: 74vh; }
.explore g[data-pid] rect { transition: filter .12s; }
.explore g[data-pid]:hover rect { filter: brightness(0.96); }
.explore g[data-expand]:hover circle { filter: brightness(1.08); }
.path { margin-top: 14px; text-align: left; font-size: 14px; color: var(--muted); }
.path ol { margin: 6px 0 0; padding-left: 18px; }
.path li { margin: 2px 0; }
.path .via { color: var(--muted); font-style: italic; }
.path .relword { color: var(--ink); font-weight: 700; font-style: normal; }

.notice {
  background: var(--chip); border: 1px dashed var(--line); border-radius: 10px;
  padding: 12px 14px; font-size: 14px; color: var(--muted); margin-top: 14px;
}
.preview {
  background: var(--bg); border: 1px solid var(--line); border-radius: 10px;
  padding: 12px; font: 13px/1.5 ui-monospace, Menlo, monospace;
  white-space: pre-wrap; color: var(--ink); margin-top: 8px; overflow-x: auto;
}
.muted { color: var(--muted); }
.center { text-align: center; }
.ex-zoom { display: flex; gap: 6px; flex-wrap: wrap; }
.ex-zoom .btn { padding: 6px 12px; font-size: 14px; }

/* ---- mobile ---- */
@media (max-width: 640px) {
  main { padding: 16px 12px 60px; }
  header { padding: 10px 12px; gap: 8px; }
  header .brand { font-size: 16px; }
  header nav { flex-wrap: wrap; }
  header nav button { padding: 5px 9px; font-size: 13px; }
  header .who { width: 100%; margin-left: 0; order: 3; font-size: 12px; }
  .hero { padding: 14px 0 6px; }
  .hero h1 { font-size: 22px; }
  .card { padding: 16px 15px; border-radius: 12px; }
  .person-head h2 { font-size: 21px; }
  .profile-top { gap: 12px; }
  .avatar { width: 60px; height: 60px; }
  .actions .btn { flex: 1 1 auto; text-align: center; }
  .explore { max-height: 66vh; }
}
.banner:not(:empty) {
  background: var(--chip); border-bottom: 1px solid var(--line);
  padding: 9px 18px; text-align: center; font-size: 14px; color: var(--muted);
}
.banner a { cursor: pointer; }
.credit {
  max-width: 860px; margin: 0 auto; padding: 22px 18px 40px;
  text-align: center; color: var(--muted); font-size: 13px;
  border-top: 1px solid var(--line);
}
.credit b { color: var(--ink); font-weight: 600; }
