:root {
  --bg: #f6f3ee;
  --surface: #ffffff;
  --surface-2: #efeae2;
  --text: #22201c;
  --muted: #6f685e;
  --line: #e2dbcf;
  --accent: #2f5d50;
  --accent-ink: #ffffff;
  --accent-soft: #e3ece8;
  --m: #3d6a8f;
  --f: #9b4f6a;
  --u: #7a7466;
  --rel-bg: #fbf1d9;
  --rel-ink: #6b4c0f;
  --radius: 14px;
  --shadow: 0 1px 2px rgba(40, 30, 10, .06), 0 2px 8px rgba(40, 30, 10, .05);
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #171614;
    --surface: #211f1c;
    --surface-2: #2a2824;
    --text: #ece7df;
    --muted: #a39b8e;
    --line: #37342e;
    --accent: #7fb7a4;
    --accent-ink: #10201b;
    --accent-soft: #23332d;
    --m: #8db6d8;
    --f: #dc9ab1;
    --u: #aaa294;
    --rel-bg: #3a3120;
    --rel-ink: #f0d79c;
    --shadow: none;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  padding-bottom: env(safe-area-inset-bottom);
}
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

/* ---------- header */
.top {
  position: sticky; top: 0; z-index: 10;
  display: flex; align-items: center; gap: 10px;
  padding: 10px 14px;
  padding-top: calc(10px + env(safe-area-inset-top));
  background: var(--accent); color: var(--accent-ink);
}
.brand { display: flex; align-items: center; gap: 8px; color: var(--accent-ink); font-weight: 650; white-space: nowrap; }
.brand:hover { text-decoration: none; }
.brand img { border-radius: 7px; background: #fff; }
.brand span { display: none; }
@media (min-width: 560px) { .brand span { display: inline; } }
.topsearch { flex: 1; }
.topsearch input {
  width: 100%; border: 0; border-radius: 999px; padding: 9px 14px;
  font-size: 16px; background: rgba(255,255,255,.95); color: #22201c;
}
@media (prefers-color-scheme: dark) { .topsearch input { background: #efeae2; } }

main { max-width: 760px; margin: 0 auto; padding: 14px 14px 40px; }

/* ---------- cards & sections */
.card {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: 14px 16px; margin: 0 0 14px;
}
.card > h2, .section-title {
  font-size: 12px; letter-spacing: .08em; text-transform: uppercase; color: var(--muted);
  margin: 0 0 10px; font-weight: 650;
}
h1 { font-size: 24px; line-height: 1.2; margin: 0; }
.sub { color: var(--muted); margin-top: 4px; }
.muted { color: var(--muted); }
.small { font-size: 14px; }

/* ---------- person header */
.person-head { display: flex; gap: 14px; align-items: flex-start; }
.avatar {
  flex: none; width: 64px; height: 64px; border-radius: 50%;
  display: grid; place-items: center; font-size: 22px; font-weight: 650;
  background: var(--surface-2); color: var(--muted); overflow: hidden;
}
.avatar img { width: 100%; height: 100%; object-fit: cover; }
.avatar.m { color: var(--m); } .avatar.f { color: var(--f); }
.rel-banner {
  display: block; margin: 12px 0 0; padding: 9px 12px; border-radius: 10px;
  background: var(--rel-bg); color: var(--rel-ink); font-weight: 600;
}
.rel-banner small { display: block; font-weight: 400; opacity: .85; }
.rel-banner:hover { text-decoration: none; filter: brightness(.98); }
.actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 12px; }
.btn {
  display: inline-flex; align-items: center; gap: 6px;
  border: 1px solid var(--line); background: var(--surface-2); color: var(--text);
  padding: 7px 12px; border-radius: 999px; font-size: 14px; font-weight: 550; cursor: pointer;
  font-family: inherit;
}
.btn:hover { text-decoration: none; border-color: var(--accent); }
.btn.primary { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }

/* ---------- facts */
.facts { margin: 0; padding: 0; list-style: none; }
.facts li { padding: 8px 0; border-top: 1px solid var(--line); display: grid; grid-template-columns: 110px 1fr; gap: 10px; }
.facts li:first-child { border-top: 0; padding-top: 0; }
.facts .label { color: var(--muted); font-size: 14px; padding-top: 1px; }
.facts .val { min-width: 0; }
.facts .place { color: var(--muted); font-size: 14px; display: block; }
.facts .extra { font-size: 14px; color: var(--muted); display: block; }
.facts details { margin-top: 4px; font-size: 14px; }
@media (max-width: 380px) { .facts li { grid-template-columns: 1fr; gap: 0; } }

/* ---------- chips (people in lists) */
.chips { display: flex; flex-direction: column; gap: 6px; }
.chip {
  display: flex; flex-wrap: wrap; align-items: baseline; gap: 2px 10px;
  padding: 9px 12px; border-radius: 10px; background: var(--surface-2); color: var(--text);
  border-left: 4px solid var(--u);
}
.chip.m { border-left-color: var(--m); } .chip.f { border-left-color: var(--f); }
.chip:hover { text-decoration: none; filter: brightness(.97); }
.chip-name { font-weight: 600; }
.chip-years { color: var(--muted); font-size: 14px; font-variant-numeric: tabular-nums; }
.chip-extra { flex-basis: 100%; color: var(--muted); font-size: 13px; }
.fam + .fam { margin-top: 16px; padding-top: 14px; border-top: 1px dashed var(--line); }
.fam-head { margin-bottom: 8px; }
.fam-meta { color: var(--muted); font-size: 14px; margin: 6px 0 8px; }
.kids { margin-left: 14px; padding-left: 12px; border-left: 2px solid var(--line); }
.kids-label { font-size: 13px; color: var(--muted); margin: 8px 0 6px; }

/* ---------- notes, sources, media */
.note p { margin: 0 0 10px; }
.note p:last-child { margin-bottom: 0; }
.sources { margin: 0; padding-left: 18px; font-size: 14px; }
.sources li { margin-bottom: 6px; }
.gallery { display: grid; grid-template-columns: repeat(auto-fill, minmax(100px, 1fr)); gap: 8px; }
.gallery a { display: block; }
.gallery img { width: 100%; aspect-ratio: 1; object-fit: cover; border-radius: 8px; background: var(--surface-2); }
.gallery .cap { font-size: 12px; color: var(--muted); margin-top: 3px; line-height: 1.25; }
.gallery .file { display: grid; place-items: center; aspect-ratio: 1; border-radius: 8px; background: var(--surface-2); font-size: 12px; padding: 6px; text-align: center; word-break: break-all; }

/* ---------- home */
.hero { text-align: center; padding: 20px 6px 8px; }
.hero h1 { font-size: 26px; }
.bigsearch { display: flex; gap: 8px; margin: 16px 0 6px; }
.bigsearch input {
  flex: 1; min-width: 0; font-size: 17px; padding: 12px 16px; border-radius: 12px;
  border: 1px solid var(--line); background: var(--surface); color: var(--text);
}
.bigsearch button { border: 0; border-radius: 12px; padding: 0 16px; background: var(--accent); color: var(--accent-ink); font-size: 16px; font-weight: 600; }
.stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; text-align: center; }
.stats b { display: block; font-size: 20px; font-variant-numeric: tabular-nums; }
.stats span { font-size: 12px; color: var(--muted); }
.linkgrid { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.linkgrid a { background: var(--surface-2); padding: 12px; border-radius: 10px; font-weight: 600; color: var(--text); }
.linkgrid a small { display: block; font-weight: 400; color: var(--muted); }
.linkgrid a:hover { text-decoration: none; filter: brightness(.97); }

/* ---------- surnames */
.letters { display: flex; flex-wrap: wrap; gap: 4px; margin-bottom: 12px; }
.letters a { width: 32px; height: 32px; display: grid; place-items: center; border-radius: 8px; background: var(--surface-2); font-weight: 600; }
.surnames { columns: 2; column-gap: 16px; }
@media (min-width: 560px) { .surnames { columns: 3; } }
.surnames a { display: flex; justify-content: space-between; gap: 8px; padding: 5px 0; break-inside: avoid; color: var(--text); }
.surnames a span { color: var(--muted); font-variant-numeric: tabular-nums; }
.letter-head { column-span: all; font-weight: 700; color: var(--accent); margin: 12px 0 2px; }

/* ---------- pedigree */
.pedigree-wrap { overflow-x: auto; margin: 0 -14px; padding: 0 14px 6px; -webkit-overflow-scrolling: touch; }
.pedigree { display: grid; grid-auto-flow: column; grid-auto-columns: minmax(140px, 1fr); gap: 10px; }
.pcol { display: flex; flex-direction: column; gap: 6px; }
.pboxes { flex: 1; display: flex; flex-direction: column; justify-content: space-around; gap: 6px; }
.pbox {
  display: block; padding: 7px 9px; border-radius: 9px; background: var(--surface); border: 1px solid var(--line);
  border-left: 4px solid var(--u); font-size: 13px; line-height: 1.3; color: var(--text); box-shadow: var(--shadow);
}
.pbox.m { border-left-color: var(--m); } .pbox.f { border-left-color: var(--f); }
.pbox b { display: block; font-size: 14px; }
.pbox span { color: var(--muted); }
.pbox.empty { background: transparent; border-style: dashed; color: var(--muted); box-shadow: none; }
.pbox:hover { text-decoration: none; border-color: var(--accent); }
.gen-label { font-size: 11px; letter-spacing: .06em; text-transform: uppercase; color: var(--muted); text-align: center; }

/* ---------- descendants */
.desc { list-style: none; margin: 0; padding: 0; }
.desc .desc { margin-left: 12px; padding-left: 12px; border-left: 2px solid var(--line); }
.desc li { margin: 6px 0; }
.desc .spouse { font-size: 14px; color: var(--muted); margin: 3px 0 0 4px; }
.gens { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 12px; }
.gens a { padding: 5px 11px; border-radius: 999px; background: var(--surface-2); font-size: 14px; color: var(--text); }
.gens a.on { background: var(--accent); color: var(--accent-ink); }

/* ---------- relationship path */
.path { list-style: none; margin: 0; padding: 0; }
.path li { position: relative; padding-left: 26px; margin: 0 0 6px; }
.path li::before { content: ""; position: absolute; left: 8px; top: -8px; bottom: 50%; border-left: 2px solid var(--line); }
.path li:first-child::before { display: none; }
.path li .step { position: absolute; left: 0; top: 12px; width: 18px; height: 18px; border-radius: 50%; background: var(--surface-2); border: 2px solid var(--line); }
.path li.ca .step { background: var(--accent); border-color: var(--accent); }
.path .role { font-size: 12px; color: var(--muted); margin: 2px 0 0 2px; }
.big-rel { font-size: 22px; font-weight: 700; line-height: 1.25; }

/* ---------- forms / misc */
.login { max-width: 360px; margin: 10vh auto 0; }
.login input[type=password] {
  width: 100%; font-size: 17px; padding: 12px 14px; border-radius: 10px;
  border: 1px solid var(--line); background: var(--surface); color: var(--text); margin: 8px 0 12px;
}
.login button { width: 100%; padding: 12px; font-size: 16px; }
.error { background: #fbe3e1; color: #8a1f17; padding: 9px 12px; border-radius: 10px; margin-bottom: 10px; }
@media (prefers-color-scheme: dark) { .error { background: #4a2320; color: #ffd2cc; } }
.notice { background: var(--accent-soft); padding: 9px 12px; border-radius: 10px; margin-bottom: 12px; }
.empty-state { text-align: center; color: var(--muted); padding: 30px 10px; }
.footer-meta { text-align: center; color: var(--muted); font-size: 13px; margin-top: 18px; }
.footer-meta form { display: inline; }
.linkbtn { background: none; border: 0; color: var(--accent); font: inherit; cursor: pointer; padding: 0; }
.result-count { color: var(--muted); font-size: 14px; margin: 0 0 10px; }
