/* Davis Family Tree - styles */
:root {
  --paper: #f3efe7;
  --paper-2: #e9e3d6;
  --ink: #1f2429;
  --ink-2: #4b535b;
  --ink-3: #7c848c;
  --river: #2f4b5c;
  --river-2: #3f6577;
  --sash: #a9403b;
  --ochre: #b6742c;
  --spruce: #3a5a45;
  --line: #d6cfc1;
  --focus: #b6742c;

  --r-rupert: #a9403b;   /* Red River / Rupert's Land / Canada */
  --r-england: #2f4b5c;
  --r-scotland: #3a5a45;
  --r-france: #6c4c8a;
  --r-usa: #b6742c;
  --r-indig: #c99a2e;
  --r-ireland: #4f8a6f;
  --r-unknown: #9aa2a9;

  --serif: "Literata", Georgia, "Times New Roman", serif;
  --sans: "Source Sans 3", "Segoe UI", system-ui, sans-serif;
  --maxw: 1120px;
  color-scheme: light dark;
  box-sizing: border-box;
  padding-top: env(safe-area-inset-top, 0px);
  padding-bottom: env(safe-area-inset-bottom, 0px);
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --paper: #1a1d21; --paper-2: #23272c; --ink: #ece7dc; --ink-2: #bcb5a8; --ink-3: #8b857a;
    --river: #7fa5b8; --river-2: #9dbfd0; --sash: #d4655f; --ochre: #d59a4f; --spruce: #7fae8f; --line: #343a40;
    --r-england: #7fa5b8; --r-scotland: #7fae8f; --r-france: #a88bc6; --r-usa: #d59a4f; --r-indig: #e2b84a; --r-rupert: #d4655f; --r-ireland: #6fb894;
  }
}
:root[data-theme="dark"] {
  --paper: #1a1d21; --paper-2: #23272c; --ink: #ece7dc; --ink-2: #bcb5a8; --ink-3: #8b857a;
  --river: #7fa5b8; --river-2: #9dbfd0; --sash: #d4655f; --ochre: #d59a4f; --spruce: #7fae8f; --line: #343a40;
  --r-england: #7fa5b8; --r-scotland: #7fae8f; --r-france: #a88bc6; --r-usa: #d59a4f; --r-indig: #e2b84a; --r-rupert: #d4655f; --r-ireland: #6fb894;
}
html { scroll-padding-top: calc(64px + env(safe-area-inset-top, 0px)); }
* { box-sizing: inherit; }
body {
  margin: 0; background: var(--paper); color: var(--ink);
  font-family: var(--serif); font-size: 17px; line-height: 1.55;
  -webkit-font-smoothing: antialiased;
}
a { color: var(--river); text-decoration-thickness: 1px; text-underline-offset: 3px; }
a:hover { color: var(--sash); }
:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; border-radius: 2px; }
button { font: inherit; cursor: pointer; }
h1, h2, h3, h4 { font-weight: 500; line-height: 1.15; margin: 0; letter-spacing: -0.01em; }
h2 { font-size: 1.9rem; margin-bottom: .4rem; }
h3 { font-size: 1.25rem; }
p { margin: .4rem 0 .9rem; max-width: 68ch; }
.muted { color: var(--ink-2); }
.small { font-size: .92rem; }
.sans { font-family: var(--sans); }
.wrap { max-width: var(--maxw); margin: 0 auto; padding: 0 20px; }
.hidden { display: none !important; }
.sr { position: absolute; left: -9999px; }

/* ---------- top bar ---------- */
.top {
  position: sticky; top: env(safe-area-inset-top, 0px); z-index: 20;
  background: color-mix(in srgb, var(--paper) 92%, transparent);
  backdrop-filter: blur(8px); border-bottom: 1px solid var(--line);
}
.top .wrap { display: flex; align-items: center; gap: 18px; height: 60px; }
.brand { font-size: 1.15rem; font-weight: 600; color: var(--ink); text-decoration: none; white-space: nowrap; }
.brand em { font-style: normal; color: var(--sash); }
.nav { display: flex; gap: 4px; margin-left: auto; font-family: var(--sans); font-size: .98rem; }
.nav a { color: var(--ink-2); text-decoration: none; padding: 8px 10px; border-radius: 6px; }
.nav a.on, .nav a:hover { color: var(--ink); background: var(--paper-2); }
.search { position: relative; }
.search input {
  font: inherit; font-family: var(--sans); font-size: .98rem; width: 240px; max-width: 46vw;
  padding: 8px 12px; border: 1px solid var(--line); border-radius: 8px; background: var(--paper-2); color: var(--ink);
}
.search-results {
  position: absolute; top: 42px; right: 0; width: 360px; max-width: 90vw; max-height: 60vh; overflow: auto;
  background: var(--paper); border: 1px solid var(--line); border-radius: 10px; box-shadow: 0 12px 30px rgba(0,0,0,.14);
  font-family: var(--sans); z-index: 30;
}
.search-results button { display: block; width: 100%; text-align: left; background: none; border: 0; border-bottom: 1px solid var(--line); padding: 10px 14px; color: var(--ink); }
.search-results button:hover, .search-results button:focus { background: var(--paper-2); }
.search-results .yrs { color: var(--ink-3); font-size: .88rem; }

/* ---------- hero ---------- */
.hero { padding: 56px 0 36px; }
.hero h1 { font-size: clamp(2.2rem, 5vw, 3.6rem); font-weight: 400; max-width: 22ch; }
.hero h1 b { font-weight: 600; }
.hero .lede { font-size: 1.15rem; max-width: 60ch; color: var(--ink-2); margin-top: 18px; }
.hero .lede a { white-space: nowrap; }
.river-wrap { margin-top: 30px; border-top: 1px solid var(--line); border-bottom: 1px solid var(--line); padding: 14px 0 8px; }
.river-head { display: flex; justify-content: space-between; align-items: baseline; gap: 12px; flex-wrap: wrap; font-family: var(--sans); font-size: .95rem; color: var(--ink-2); }
.river-head strong { color: var(--ink); font-weight: 600; }
.legend { display: flex; flex-wrap: wrap; gap: 4px 16px; }
.legend span::before { content: ""; display: inline-block; width: 10px; height: 10px; border-radius: 50%; background: var(--c); margin-right: 6px; vertical-align: -1px; }
#river { width: 100%; height: auto; display: block; margin-top: 6px; }
#river circle { cursor: pointer; transition: r .12s; }
#river circle:hover { stroke: var(--ink); stroke-width: 2; }
#river text { font-family: var(--sans); fill: var(--ink-3); font-size: 11px; }
#river .axis { stroke: var(--line); }
#river .root { stroke: var(--ink); stroke-width: 2; }
.river-hint { font-family: var(--sans); font-size: .9rem; color: var(--ink-3); margin: 6px 0 0; min-height: 1.4em; }

/* ---------- sections ---------- */
section.block { padding: 56px 0; border-top: 1px solid var(--line); }
section.block:first-of-type { border-top: 0; }
.section-head { display: flex; align-items: baseline; justify-content: space-between; gap: 20px; flex-wrap: wrap; margin-bottom: 20px; }
.section-head p { margin: 0; }

/* ---------- explorer ---------- */
.explorer { display: grid; grid-template-columns: 1fr; gap: 20px; }
.pedigree { display: grid; grid-template-columns: repeat(4, minmax(0,1fr)); gap: 10px; align-items: stretch; }
.pedigree .col { display: flex; flex-direction: column; justify-content: space-around; gap: 8px; }
.pcard {
  border: 1px solid var(--line); border-left: 4px solid var(--c, var(--ink-3)); border-radius: 6px; padding: 10px 12px;
  background: var(--paper-2); text-align: left; color: var(--ink); width: 100%; font-family: var(--sans); line-height: 1.3;
}
.pcard:hover { border-color: var(--ink-2); }
.pcard .nm { font-family: var(--serif); font-size: 1rem; font-weight: 500; }
.pcard .yrs { color: var(--ink-2); font-size: .88rem; margin-top: 3px; }
.pcard .rel { color: var(--ink-3); font-size: .78rem; }
.pcard.empty { border-style: dashed; color: var(--ink-3); background: transparent; }
.pcard.focus { background: var(--paper); border-left-width: 6px; box-shadow: 0 6px 20px rgba(0,0,0,.08); }
.pcard.focus .nm { font-size: 1.2rem; }

.person { border: 1px solid var(--line); border-radius: 10px; background: var(--paper-2); padding: 22px 24px; }
.person header { display: flex; flex-wrap: wrap; gap: 8px 16px; align-items: baseline; }
.person h3 { font-size: 1.7rem; font-weight: 500; }
.badge { font-family: var(--sans); font-size: .78rem; padding: 2px 8px; border-radius: 999px; border: 1px solid var(--line); color: var(--ink-2); white-space: nowrap; }
.badge.high { border-color: var(--spruce); color: var(--spruce); }
.badge.medium { border-color: var(--river); color: var(--river); }
.badge.low { border-color: var(--sash); color: var(--sash); }
.badge.unverified { border-color: var(--ink-3); color: var(--ink-3); }
.facts { display: grid; grid-template-columns: max-content 1fr; gap: 6px 18px; font-family: var(--sans); margin: 14px 0; max-width: 70ch; }
.facts dt { color: var(--ink-3); }
.facts dd { margin: 0; }
.facts dd .raw { color: var(--ink-3); font-size: .85rem; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip { font-family: var(--sans); font-size: .9rem; border: 1px solid var(--line); border-radius: 999px; padding: 4px 11px; background: var(--paper); color: var(--ink); }
.chip:hover { border-color: var(--ink-2); }
.chip.warn { border-color: var(--sash); color: var(--sash); }
.person .actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 16px; }
.btn { font-family: var(--sans); font-size: .95rem; padding: 8px 14px; border-radius: 8px; border: 1px solid var(--line); background: var(--paper); color: var(--ink); }
.btn.primary { background: var(--river); border-color: var(--river); color: #fff; }
.btn.primary:hover { background: var(--river-2); }
:root[data-theme="dark"] .btn.primary, :root:not([data-theme="light"]) .btn.primary { color: var(--paper); }
@media (prefers-color-scheme: light) { :root:not([data-theme="dark"]) .btn.primary { color: #fff; } }
.note { white-space: pre-wrap; font-size: .95rem; color: var(--ink-2); border-left: 2px solid var(--line); padding-left: 12px; margin: 8px 0; }

/* ---------- people index ---------- */
.filters { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 14px; font-family: var(--sans); }
.filters select, .filters input { font: inherit; font-family: var(--sans); padding: 7px 10px; border: 1px solid var(--line); border-radius: 8px; background: var(--paper-2); color: var(--ink); }
.table-wrap { overflow-x: auto; border: 1px solid var(--line); border-radius: 8px; }
table { border-collapse: collapse; width: 100%; font-family: var(--sans); font-size: .95rem; }
th, td { text-align: left; padding: 9px 12px; border-bottom: 1px solid var(--line); vertical-align: top; }
th { background: var(--paper-2); font-weight: 600; position: sticky; top: 0; }
tbody tr:hover { background: var(--paper-2); }
td button.link { background: none; border: 0; padding: 0; color: var(--river); text-align: left; font: inherit; font-family: var(--serif); }
td button.link:hover { color: var(--sash); text-decoration: underline; }
.dot { display: inline-block; width: 9px; height: 9px; border-radius: 50%; background: var(--c); margin-right: 6px; }
.more { margin-top: 12px; }

/* ---------- stories ---------- */
.stories { display: grid; grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)); gap: 18px; }
.story { border-top: 3px solid var(--c, var(--river)); padding-top: 14px; }
.story h3 { font-size: 1.3rem; }
.story .when { font-family: var(--sans); color: var(--ink-2); font-size: .92rem; margin: 4px 0 10px; }
.story p { font-size: 1rem; }
.story .links { font-family: var(--sans); font-size: .9rem; }
.story .links a { margin-right: 12px; }
.mystery { margin-top: 30px; border: 1px solid var(--sash); border-radius: 10px; padding: 20px 24px; background: color-mix(in srgb, var(--sash) 7%, var(--paper)); }
.mystery h3 { color: var(--sash); }

/* ---------- ask ---------- */
.ask { display: grid; grid-template-columns: 300px 1fr; gap: 24px; }
.reports { display: flex; flex-direction: column; gap: 6px; }
.reports button { text-align: left; font-family: var(--sans); font-size: .95rem; padding: 9px 12px; border: 1px solid var(--line); background: var(--paper-2); border-radius: 8px; color: var(--ink); line-height: 1.3; }
.reports button:hover { border-color: var(--ink-2); }
.reports h4 { font-family: var(--sans); font-weight: 600; font-size: .9rem; color: var(--ink-3); margin: 8px 0 2px; }
.chat { border: 1px solid var(--line); border-radius: 10px; display: flex; flex-direction: column; min-height: 520px; max-height: 78vh; background: var(--paper-2); }
.msgs { flex: 1; overflow: auto; padding: 18px 20px; display: flex; flex-direction: column; gap: 14px; }
.msg { max-width: 72ch; }
.msg.user { align-self: flex-end; background: var(--river); color: #fff; padding: 10px 14px; border-radius: 12px 12px 2px 12px; font-family: var(--sans); }
.msg.ai { font-size: 1rem; }
.msg.ai h1, .msg.ai h2, .msg.ai h3 { font-size: 1.15rem; margin: 12px 0 4px; }
.msg.ai table { font-size: .92rem; margin: 8px 0; }
.msg.ai code { font-family: ui-monospace, Menlo, monospace; font-size: .88em; background: var(--paper); padding: 1px 4px; border-radius: 3px; }
.msg.ai ul, .msg.ai ol { padding-left: 1.3em; }
.msg.ai p { margin: .3rem 0 .7rem; }
.msg.err { color: var(--sash); font-family: var(--sans); }
.composer { display: flex; gap: 8px; padding: 12px; border-top: 1px solid var(--line); }
.composer textarea { flex: 1; font: inherit; font-family: var(--sans); font-size: 1rem; resize: none; padding: 10px 12px; border: 1px solid var(--line); border-radius: 8px; background: var(--paper); color: var(--ink); min-height: 44px; max-height: 160px; }
.empty-chat { color: var(--ink-3); font-family: var(--sans); }
.ai-tools { display: flex; gap: 8px; flex-wrap: wrap; padding: 0 12px 10px; font-family: var(--sans); font-size: .85rem; color: var(--ink-3); align-items: center; }
.ai-tools button { background: none; border: 0; color: var(--river); padding: 0; font: inherit; }

/* ---------- data ---------- */
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 12px; font-family: var(--sans); margin-bottom: 20px; }
.stat { border: 1px solid var(--line); border-radius: 8px; padding: 12px 14px; }
.stat b { display: block; font-family: var(--serif); font-size: 1.7rem; font-weight: 500; }
.stat span { color: var(--ink-2); font-size: .9rem; }
.two { display: grid; grid-template-columns: 1fr 1fr; gap: 28px; }
.issues li { margin-bottom: 4px; font-size: .95rem; }

footer { border-top: 1px solid var(--line); padding: 28px 0 40px; font-family: var(--sans); color: var(--ink-3); font-size: .9rem; }

@media (max-width: 860px) {
  .ask, .two { grid-template-columns: 1fr; }
  .pedigree { grid-template-columns: 1fr 1fr; }
  .pedigree .col.gp { display: none; }
  .nav { display: none; }
  .search input { width: 170px; }
  .top .wrap { gap: 10px; }
}
@media (prefers-reduced-motion: reduce) { * { transition: none !important; } }
