:root {
  --bg: #efe3c9;
  --bg-2: #e7d6b0;
  --ink: #1a120c;
  --ink-soft: #3d2e20;
  --muted: #5c4a36;
  --paper: #fffaf2;
  --paper-edge: #cbb892;
  --header: #3b2416;
  --header-ink: #f8efdc;
  --accent: #8b3a2a;
  --gold: #9a7840;
  --male: #3d6a88;
  --male-soft: #d3e3ee;
  --female: #8d4450;
  --female-soft: #f3d9dd;
  --unknown: #6a5b4a;
  --unknown-soft: #e6ddd0;
  --confirmed: #1f5a32;
  --confirmed-bg: #d9eedd;
  --likely: #7a4e0c;
  --likely-bg: #f6e4c0;
  --possible: #4d4942;
  --possible-bg: #e6e2d8;
  --line: #7a6548;
  --shadow: 0 2px 10px rgba(40, 24, 8, 0.14);
  --font-ui: "Segoe UI", "Helvetica Neue", system-ui, -apple-system, sans-serif;
  --font-name: Palatino, "Palatino Linotype", "Iowan Old Style", "Book Antiqua", Georgia, serif;
  --card-w: 236px;
  --card-h: 122px;
}

*, *::before, *::after { box-sizing: border-box; }
html, body { margin: 0; padding: 0; min-height: 100%; }
html { height: 100%; }
body {
  font-family: var(--font-ui);
  color: var(--ink);
  background:
    radial-gradient(circle at 10% 0%, rgba(255,255,255,0.35), transparent 40%),
    radial-gradient(circle at 90% 100%, rgba(139, 58, 42, 0.06), transparent 45%),
    linear-gradient(180deg, var(--bg) 0%, var(--bg-2) 100%);
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
}

.sr-only {
  position: absolute;
  width: 1px; height: 1px;
  padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0,0,0,0);
  border: 0;
}

.top {
  background: var(--header);
  color: var(--header-ink);
  padding: calc(10px + env(safe-area-inset-top)) 16px 12px;
  display: grid;
  grid-template-columns: 1fr;
  gap: 10px;
  position: sticky;
  top: 0;
  z-index: 20;
  box-shadow: 0 2px 8px rgba(0,0,0,0.25);
}
.eyebrow {
  margin: 0;
  font-size: 12px;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: #e3c99a;
}
.brand h1 {
  margin: 2px 0 0;
  font-family: var(--font-name);
  font-size: 1.55rem;
  font-weight: 700;
  line-height: 1.15;
  color: var(--header-ink);
}
.tabs {
  display: flex;
  gap: 6px;
}
.tab, .tree-toolbar button, .gens select, .profile-close, .rel-link, .story-jump {
  font: inherit;
  cursor: pointer;
}
.tab {
  background: transparent;
  color: var(--header-ink);
  border: 1px solid rgba(248, 239, 220, 0.35);
  border-radius: 999px;
  padding: 8px 16px;
  font-size: 15px;
  font-weight: 600;
}
.tab.is-active {
  background: var(--paper);
  color: var(--header);
  border-color: var(--paper);
}
.search-wrap { position: relative; }
#search {
  width: 100%;
  font-size: 16px;
  padding: 10px 12px;
  border: 1px solid #c9b48a;
  border-radius: 8px;
  background: #fffaf2;
  color: var(--ink);
}
.search-results {
  position: absolute;
  left: 0; right: 0; top: calc(100% + 4px);
  background: var(--paper);
  color: var(--ink);
  border: 1px solid var(--paper-edge);
  border-radius: 8px;
  max-height: 280px;
  overflow: auto;
  z-index: 30;
  box-shadow: var(--shadow);
}
.search-results button {
  display: block;
  width: 100%;
  text-align: left;
  background: none;
  border: 0;
  border-bottom: 1px solid #efe3c9;
  padding: 10px 12px;
  font: inherit;
  color: inherit;
  cursor: pointer;
}
.search-results button:hover,
.search-results button:focus { background: #f3e7cf; }
.search-results .dates { color: var(--muted); font-size: 13px; margin-left: 6px; }

main { flex: 1; display: flex; flex-direction: column; min-height: 0; }
.view { display: none; flex: 1; min-height: 0; flex-direction: column; }
.view.is-active { display: flex; }
.page-view { overflow: auto; }
.page-inner {
  max-width: 760px;
  margin: 0 auto;
  padding: 20px 16px 64px;
}

.tree-toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
  padding: 8px 12px;
  background: rgba(255, 250, 242, 0.72);
  border-bottom: 1px solid var(--paper-edge);
}
.tool-group { display: flex; gap: 4px; }
.tree-toolbar button, .gens select {
  background: var(--paper);
  color: var(--ink);
  border: 1px solid var(--paper-edge);
  border-radius: 8px;
  padding: 8px 12px;
  font-size: 15px;
  font-weight: 600;
  min-height: 40px;
}
#zoom-out, #zoom-in { width: 40px; font-size: 20px; line-height: 1; }
.gens {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 14px;
  color: var(--ink-soft);
  font-weight: 600;
}
.hint {
  margin: 0;
  color: var(--muted);
  font-size: 13px;
  flex: 1 1 180px;
}

.viewport {
  flex: 1;
  position: relative;
  overflow: hidden;
  touch-action: none;
  cursor: grab;
  background:
    repeating-linear-gradient(0deg, transparent, transparent 27px, rgba(90, 70, 40, 0.04) 28px),
    repeating-linear-gradient(90deg, transparent, transparent 27px, rgba(90, 70, 40, 0.04) 28px);
  min-height: 60dvh;
}
.viewport.is-dragging { cursor: grabbing; }
.world {
  position: absolute;
  left: 0; top: 0;
  transform-origin: 0 0;
  will-change: transform;
}
#edges { position: absolute; left: 0; top: 0; overflow: visible; pointer-events: none; }
#cards { position: relative; }

.person-card {
  position: absolute;
  width: var(--card-w);
  min-height: var(--card-h);
  background: var(--paper);
  border: 1px solid var(--paper-edge);
  border-left-width: 7px;
  border-radius: 8px;
  box-shadow: var(--shadow);
  display: flex;
  gap: 8px;
  padding: 8px 8px 8px 7px;
  text-align: left;
  color: var(--ink);
  font: inherit;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}
.person-card.male { border-left-color: var(--male); }
.person-card.female { border-left-color: var(--female); }
.person-card.unknown { border-left-color: var(--unknown); }
.person-card.is-selected {
  outline: 3px solid var(--accent);
  box-shadow: 0 0 0 3px rgba(139, 58, 42, 0.15), var(--shadow);
  z-index: 2;
}
.person-card.is-root { outline: 3px solid var(--gold); }
.avatar {
  flex: 0 0 44px;
  width: 44px; height: 44px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  color: #fff;
  font-weight: 700;
  font-size: 14px;
  letter-spacing: 0.02em;
  position: relative;
}
.avatar.male { background: var(--male); }
.avatar.female { background: var(--female); }
.avatar.unknown { background: var(--unknown); }
.avatar svg { width: 28px; height: 28px; fill: currentColor; opacity: 0.95; }
.card-body { min-width: 0; flex: 1; }
.card-body .name {
  font-family: var(--font-name);
  font-size: 16px;
  font-weight: 700;
  line-height: 1.2;
  margin: 0;
}
.card-body .dates, .card-body .place {
  margin: 2px 0 0;
  font-size: 13px;
  line-height: 1.3;
  color: var(--ink-soft);
}
.card-body .place { color: var(--muted); }
.badge {
  display: inline-block;
  margin-top: 5px;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  border-radius: 999px;
  padding: 2px 7px;
}
.badge.confirmed { background: var(--confirmed-bg); color: var(--confirmed); }
.badge.likely { background: var(--likely-bg); color: var(--likely); }
.badge.possible { background: var(--possible-bg); color: var(--possible); }
.adoptive-tag {
  display: block;
  margin-top: 3px;
  font-size: 11px;
  font-weight: 700;
  color: var(--accent);
  letter-spacing: 0.03em;
  text-transform: uppercase;
}

.backdrop {
  position: fixed;
  inset: 0;
  background: rgba(26, 18, 12, 0.45);
  z-index: 40;
}
.profile {
  position: fixed;
  z-index: 50;
  background: var(--paper);
  color: var(--ink);
  box-shadow: -4px 0 24px rgba(0,0,0,0.2);
  overflow: auto;
  -webkit-overflow-scrolling: touch;
}
@media (max-width: 799px) {
  .profile {
    left: 0; right: 0; bottom: 0;
    top: 12vh;
    border-radius: 16px 16px 0 0;
    padding-bottom: env(safe-area-inset-bottom);
  }
}
@media (min-width: 800px) {
  .profile {
    top: 0; right: 0; bottom: 0;
    width: min(440px, 100%);
    padding-top: env(safe-area-inset-top);
  }
  .top {
    grid-template-columns: minmax(180px, auto) auto minmax(200px, 280px);
    align-items: end;
  }
}
.profile-inner { padding: 16px 18px 40px; }
.profile-close {
  float: right;
  background: var(--header);
  color: var(--header-ink);
  border: 0;
  border-radius: 8px;
  padding: 8px 12px;
  font-weight: 600;
}
.profile-head { margin-bottom: 16px; padding-right: 80px; }
.profile-head h2 {
  font-family: var(--font-name);
  font-size: 1.7rem;
  margin: 0 0 4px;
  line-height: 1.15;
}
.profile-head .life { margin: 0; font-size: 1.05rem; color: var(--ink-soft); }
.story {
  font-family: var(--font-name);
  font-size: 1.08rem;
  line-height: 1.55;
  margin: 0 0 20px;
}
.story p { margin: 0 0 0.8em; }
.living-note {
  background: #f3e7cf;
  border-left: 4px solid var(--gold);
  padding: 10px 12px;
  margin: 0 0 16px;
  font-size: 0.95rem;
}
.section-h {
  font-size: 0.82rem;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--accent);
  margin: 22px 0 8px;
  font-weight: 700;
}
.facts { list-style: none; margin: 0; padding: 0; }
.facts li {
  display: grid;
  grid-template-columns: 92px 1fr;
  gap: 10px;
  padding: 10px 0;
  border-bottom: 1px solid #eadcc0;
}
.facts .when { font-weight: 700; color: var(--ink-soft); font-size: 0.92rem; }
.facts .what { font-size: 0.98rem; }
.facts .what .place { display: block; color: var(--muted); margin-top: 2px; }
.facts .what .src { display: block; color: var(--muted); font-size: 0.85rem; margin-top: 4px; }

.rel-list { display: flex; flex-direction: column; gap: 6px; }
.rel-link, .story-jump {
  display: block;
  width: 100%;
  text-align: left;
  background: #f7f0e2;
  border: 1px solid var(--paper-edge);
  border-radius: 8px;
  padding: 10px 12px;
  color: var(--ink);
  text-decoration: none;
  font-size: 1rem;
}
.rel-link:hover, .story-jump:hover, .rel-link:focus, .story-jump:focus {
  background: #eee2c8;
}
.rel-link .role {
  display: block;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--accent);
}
.sources { list-style: none; margin: 0; padding: 0; }
.sources li { padding: 8px 0; border-bottom: 1px solid #eadcc0; font-size: 0.95rem; line-height: 1.4; }
.sources a { color: var(--accent); font-weight: 600; }

.story-card, .q-card {
  background: var(--paper);
  border: 1px solid var(--paper-edge);
  border-radius: 12px;
  padding: 18px 18px 16px;
  margin: 0 0 16px;
  box-shadow: var(--shadow);
}
.story-card h2, .page-inner h2, .q-card h3 {
  font-family: var(--font-name);
  margin: 0 0 8px;
}
.story-card p, .page-inner p, .q-card p { font-size: 1.05rem; line-height: 1.55; }
.tl { list-style: none; margin: 0; padding: 0; }
.tl li {
  display: grid;
  grid-template-columns: 72px 1fr;
  gap: 14px;
  padding: 0 0 18px;
  position: relative;
}
.tl li::before {
  content: "";
  position: absolute;
  left: 62px;
  top: 8px;
  bottom: -8px;
  width: 2px;
  background: #cbb892;
}
.tl li:last-child::before { display: none; }
.tl .yr {
  font-weight: 800;
  color: var(--accent);
  font-size: 1.05rem;
}
.tl h3 { font-size: 1.1rem; margin: 0 0 4px; font-family: var(--font-name); }
.tl p { margin: 0; color: var(--ink-soft); }
.line-tag {
  display: inline-block;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--accent);
}

.site-foot {
  padding: 10px 16px calc(10px + env(safe-area-inset-bottom));
  font-size: 13px;
  color: var(--muted);
  text-align: center;
}
.site-foot p { margin: 0; }

a { color: var(--accent); }
