:root {
  --bg: #f6f1e7;
  --paper: #fffdf8;
  --ink: #2b2620;
  --muted: #6f665a;
  --line: #e2d8c6;
  --accent: #2f5d50;
  --accent-ink: #ffffff;
  --accent-soft: #e3eee9;
  --warn: #9a4b1c;
  --warn-soft: #f8e9dc;
  --danger: #a3302a;
  --male: #dfe9f3;
  --female: #f5e1e6;
  --unknown: #ece6da;
  --shadow: 0 1px 2px rgba(60, 45, 20, .08), 0 4px 16px rgba(60, 45, 20, .06);
  --serif: "Iowan Old Style", "Palatino Linotype", Palatino, "Book Antiqua", Georgia, serif;
  --sans: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #1b1915; --paper: #24211c; --ink: #ece6da; --muted: #a99f90; --line: #3a352d;
    --accent: #7fb8a5; --accent-ink: #10201b; --accent-soft: #23352f; --warn: #e3a073; --warn-soft: #3a2a1f; --danger: #ef8a83;
    --male: #23303c; --female: #3a2a30; --unknown: #2e2a24; --shadow: 0 1px 2px rgba(0,0,0,.3), 0 4px 16px rgba(0,0,0,.25);
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body { background: var(--bg); color: var(--ink); font: 16px/1.5 var(--sans); -webkit-text-size-adjust: 100%; }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3 { font-family: var(--serif); font-weight: 600; line-height: 1.2; margin: 0 0 .5em; }
h1 { font-size: 1.9rem; }
h2 { font-size: 1.3rem; }
h3 { font-size: 1.05rem; }
p { margin: 0 0 .8em; }
.muted { color: var(--muted); }
.small { font-size: .875rem; }
.hidden { display: none !important; }

/* Header */
.top { position: sticky; top: 0; z-index: 20; background: var(--paper); border-bottom: 1px solid var(--line); }
.top-inner { max-width: 1180px; margin: 0 auto; padding: 10px 16px; display: flex; align-items: center; gap: 16px; }
.brand { font-family: var(--serif); font-size: 1.25rem; font-weight: 600; color: var(--ink); display: flex; align-items: center; gap: 8px; white-space: nowrap; }
.brand svg { color: var(--accent); }
.nav { display: flex; gap: 4px; flex-wrap: wrap; flex: 1; }
.nav a { color: var(--muted); padding: 6px 10px; border-radius: 8px; font-size: .95rem; }
.nav a:hover { background: var(--accent-soft); color: var(--ink); text-decoration: none; }
.nav a.on { color: var(--accent); background: var(--accent-soft); font-weight: 600; }
.who { display: flex; align-items: center; gap: 10px; font-size: .9rem; color: var(--muted); white-space: nowrap; }
.menu-btn { display: none; }
@media (max-width: 860px) {
  .top-inner { flex-wrap: wrap; }
  .menu-btn { display: inline-flex; margin-left: auto; }
  .nav { display: none; order: 3; flex-basis: 100%; flex-direction: column; }
  .nav.open { display: flex; }
  .who { order: 2; }
  .who .who-name { display: none; }
}

main { max-width: 1180px; margin: 0 auto; padding: 24px 16px 64px; }

/* Building blocks */
.card { background: var(--paper); border: 1px solid var(--line); border-radius: 12px; padding: 18px; box-shadow: var(--shadow); }
.card + .card { margin-top: 16px; }
.grid { display: grid; gap: 16px; }
.grid.two { grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)); }
.grid.stats { grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); }
.stat { font-family: var(--serif); font-size: 2rem; font-weight: 600; line-height: 1; }
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.row.between { justify-content: space-between; }
.stack > * + * { margin-top: 12px; }
.section-title { display: flex; justify-content: space-between; align-items: center; gap: 8px; margin-bottom: 10px; }
.section-title h2, .section-title h3 { margin: 0; }
.pill { display: inline-block; font-size: .75rem; padding: 2px 8px; border-radius: 99px; background: var(--unknown); color: var(--muted); font-weight: 600; letter-spacing: .02em; }
.pill.green { background: var(--accent-soft); color: var(--accent); }
.pill.warn { background: var(--warn-soft); color: var(--warn); }
.empty { color: var(--muted); font-style: italic; padding: 6px 0; }
hr { border: 0; border-top: 1px solid var(--line); margin: 16px 0; }

/* Forms */
label { display: block; font-size: .875rem; font-weight: 600; margin-bottom: 4px; }
.field { margin-bottom: 12px; }
.fields { display: grid; gap: 0 14px; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); }
input[type=text], input[type=email], input[type=password], input[type=search], input:not([type]), select, textarea {
  width: 100%; font: inherit; color: var(--ink); background: var(--paper); border: 1px solid var(--line); border-radius: 8px; padding: 9px 11px;
}
textarea { min-height: 120px; resize: vertical; }
input:focus, select:focus, textarea:focus, button:focus-visible, a:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
.check { display: flex; gap: 8px; align-items: center; font-weight: 400; margin: 0; }
.check input { width: 18px; height: 18px; }
.hint { font-size: .8rem; color: var(--muted); margin-top: 3px; }
.error { color: var(--danger); font-size: .9rem; margin: 8px 0; }

button, .btn {
  font: inherit; font-size: .95rem; font-weight: 600; cursor: pointer; border-radius: 8px; padding: 8px 14px; min-height: 38px;
  border: 1px solid var(--accent); background: var(--accent); color: var(--accent-ink); display: inline-flex; align-items: center; gap: 6px; text-decoration: none;
}
button:hover, .btn:hover { filter: brightness(1.06); text-decoration: none; }
button.ghost, .btn.ghost { background: transparent; color: var(--accent); border-color: var(--line); }
button.ghost:hover, .btn.ghost:hover { background: var(--accent-soft); }
button.danger { background: transparent; color: var(--danger); border-color: var(--line); }
button.danger:hover { background: var(--warn-soft); }
button.small, .btn.small { padding: 4px 10px; min-height: 30px; font-size: .85rem; }
button:disabled { opacity: .55; cursor: default; filter: none; }
.icon-btn { background: transparent; border: 1px solid var(--line); color: var(--ink); padding: 6px 8px; }

/* People */
.person-chip { display: flex; gap: 10px; align-items: center; padding: 8px 10px; border-radius: 10px; border: 1px solid var(--line); background: var(--paper); color: var(--ink); min-width: 0; }
.person-chip:hover { border-color: var(--accent); text-decoration: none; }
.person-chip .nm { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.person-chip .sub { font-size: .8rem; color: var(--muted); }
.person-chip .meta { min-width: 0; flex: 1; }
.chip-actions { display: flex; gap: 4px; }
.avatar { width: 40px; height: 40px; border-radius: 50%; flex: none; background: var(--unknown); display: grid; place-items: center; font-family: var(--serif); font-weight: 600; color: var(--muted); overflow: hidden; }
.avatar.M { background: var(--male); }
.avatar.F { background: var(--female); }
.avatar img { width: 100%; height: 100%; object-fit: cover; }
.avatar.big { width: 112px; height: 112px; font-size: 2.4rem; }
.people-list { display: grid; gap: 8px; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); }
.family-group + .family-group { margin-top: 14px; }
.family-group h3 { font-size: .8rem; font-family: var(--sans); text-transform: uppercase; letter-spacing: .06em; color: var(--muted); margin-bottom: 6px; }
.kin-list { display: grid; gap: 6px; }

.person-head { display: flex; gap: 20px; align-items: center; flex-wrap: wrap; }
.person-head .facts { flex: 1; min-width: 240px; }
.facts-table { display: grid; grid-template-columns: max-content 1fr; gap: 4px 14px; font-size: .95rem; }
.facts-table dt { color: var(--muted); }
.facts-table dd { margin: 0; }
.bio { white-space: pre-wrap; }
.layout { display: grid; gap: 16px; grid-template-columns: minmax(0, 1fr) 360px; align-items: start; }
@media (max-width: 960px) { .layout { grid-template-columns: 1fr; } }

.list-row { display: flex; gap: 10px; align-items: flex-start; justify-content: space-between; padding: 10px 0; border-bottom: 1px solid var(--line); }
.list-row:last-child { border-bottom: 0; }
.list-row .main { min-width: 0; flex: 1; overflow-wrap: anywhere; }

.photos { display: grid; gap: 8px; grid-template-columns: repeat(auto-fill, minmax(110px, 1fr)); }
.photo { position: relative; border-radius: 8px; overflow: hidden; border: 1px solid var(--line); aspect-ratio: 1; background: var(--unknown); display: grid; place-items: center; }
.photo img { width: 100%; height: 100%; object-fit: cover; display: block; }
.photo .cap { position: absolute; left: 0; right: 0; bottom: 0; font-size: .75rem; padding: 3px 6px; background: rgba(0,0,0,.55); color: #fff; }

/* Search results / picker */
.picker { position: relative; }
.picker-results { position: absolute; left: 0; right: 0; top: 100%; margin-top: 4px; z-index: 30; background: var(--paper); border: 1px solid var(--line); border-radius: 10px; box-shadow: var(--shadow); max-height: 300px; overflow: auto; }
.picker-results button { display: flex; width: 100%; background: transparent; color: var(--ink); border: 0; border-bottom: 1px solid var(--line); border-radius: 0; text-align: left; font-weight: 400; justify-content: flex-start; }
.picker-results button:hover, .picker-results button.active { background: var(--accent-soft); filter: none; }

/* Suggestions */
.sugg { border: 1px solid var(--line); border-radius: 10px; padding: 12px; background: var(--paper); }
.sugg + .sugg { margin-top: 10px; }
.sugg .title { font-weight: 600; overflow-wrap: anywhere; }
.compare { width: 100%; border-collapse: collapse; font-size: .875rem; margin: 8px 0; }
.compare th, .compare td { text-align: left; padding: 4px 6px; border-bottom: 1px solid var(--line); vertical-align: top; overflow-wrap: anywhere; }
.compare th { color: var(--muted); font-weight: 600; overflow-wrap: normal; }
.compare tr > th:first-child { white-space: nowrap; }
.compare td.new { color: var(--accent); font-weight: 600; }
.meter { height: 6px; border-radius: 99px; background: var(--line); overflow: hidden; width: 80px; display: inline-block; vertical-align: middle; }
.meter > span { display: block; height: 100%; background: var(--accent); }

/* Pedigree chart */
.chart-wrap { overflow-x: auto; padding: 8px 0 16px; }
.ped { display: flex; align-items: center; }
.ped-node { display: flex; align-items: center; }
.ped-parents { display: flex; flex-direction: column; justify-content: center; margin-left: 28px; position: relative; }
.ped-parents::before { content: ""; position: absolute; left: -28px; top: 50%; width: 14px; border-top: 2px solid var(--line); }
.ped-parents > .ped-node { position: relative; padding: 6px 0; }
.ped-parents > .ped-node::before { content: ""; position: absolute; left: -14px; width: 14px; top: 50%; border-top: 2px solid var(--line); }
.ped-parents > .ped-node:first-child::after { content: ""; position: absolute; left: -14px; top: 50%; bottom: 0; border-left: 2px solid var(--line); }
.ped-parents > .ped-node:last-child::after { content: ""; position: absolute; left: -14px; top: 0; bottom: 50%; border-left: 2px solid var(--line); }
.ped-parents > .ped-node:only-child::after { display: none; }
.ped-card { width: 200px; padding: 8px 10px; border-radius: 10px; border: 1px solid var(--line); background: var(--paper); color: var(--ink); box-shadow: var(--shadow); display: block; border-left: 4px solid var(--unknown); }
.ped-card.M { border-left-color: #7aa3c8; }
.ped-card.F { border-left-color: #c98ea0; }
.ped-card:hover { border-color: var(--accent); text-decoration: none; }
.ped-card .nm { font-weight: 600; font-size: .92rem; }
.ped-card .sub { font-size: .78rem; color: var(--muted); }
.ped-card.root { border-color: var(--accent); }
.ped-add { width: 200px; padding: 10px; border: 1px dashed var(--line); border-radius: 10px; color: var(--muted); font-size: .85rem; text-align: center; background: transparent; }

.desc ul { list-style: none; padding-left: 22px; margin: 0; border-left: 2px solid var(--line); }
.desc > ul { border-left: 0; padding-left: 0; }
.desc li { margin: 8px 0; position: relative; }
.desc li li::before { content: ""; position: absolute; left: -22px; top: 22px; width: 18px; border-top: 2px solid var(--line); }
.desc .couple { display: flex; gap: 6px; flex-wrap: wrap; align-items: center; }
.desc .couple .amp { color: var(--muted); font-family: var(--serif); }
.desc .person-chip { display: inline-flex; padding: 5px 9px; }
.desc .avatar { width: 28px; height: 28px; font-size: .8rem; }

/* Tabs */
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--line); margin-bottom: 14px; flex-wrap: wrap; }
.tabs button { background: transparent; color: var(--muted); border: 0; border-bottom: 2px solid transparent; border-radius: 0; }
.tabs button.on { color: var(--accent); border-bottom-color: var(--accent); }

/* History */
.batch { padding: 12px 0; border-bottom: 1px solid var(--line); }
.batch:last-child { border-bottom: 0; }
.batch.undone .summ { text-decoration: line-through; color: var(--muted); }
.batch .summ { margin: 4px 0 0; padding-left: 18px; font-size: .92rem; }
.diff { font-size: .82rem; border-collapse: collapse; width: 100%; }
.diff td { padding: 3px 6px; border-bottom: 1px solid var(--line); vertical-align: top; overflow-wrap: anywhere; }
.diff .was { color: var(--danger); text-decoration: line-through; }
.diff .now { color: var(--accent); }

/* Modal and toast */
.modal-back { position: fixed; inset: 0; background: rgba(20, 15, 8, .45); z-index: 50; display: grid; place-items: center; padding: 16px; }
.modal { background: var(--paper); border-radius: 14px; max-width: 640px; width: 100%; max-height: calc(100vh - 32px); overflow: auto; padding: 22px; box-shadow: 0 10px 40px rgba(0,0,0,.3); }
.modal.wide { max-width: 860px; }
.modal-actions { display: flex; gap: 8px; justify-content: flex-end; margin-top: 16px; flex-wrap: wrap; }
.toast { position: fixed; bottom: 18px; left: 50%; transform: translateX(-50%); background: var(--ink); color: var(--bg); padding: 10px 16px; border-radius: 10px; z-index: 60; box-shadow: var(--shadow); max-width: calc(100vw - 32px); display: flex; gap: 12px; align-items: center; }
.toast button { background: transparent; border-color: var(--bg); color: var(--bg); }

/* Sign-in pages */
.auth { max-width: 420px; margin: 8vh auto 0; }
.auth .card { padding: 28px; }
.auth h1 { text-align: center; }
.auth .lead { text-align: center; color: var(--muted); }
.link-box { display: flex; gap: 8px; }
.link-box input { font-family: ui-monospace, Menlo, monospace; font-size: .85rem; }

.spinner { width: 16px; height: 16px; border: 2px solid currentColor; border-right-color: transparent; border-radius: 50%; display: inline-block; animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) { .spinner { animation-duration: 3s; } }

/* Small utilities (the page's CSP allows no inline styles) */
.w-full { width: 100%; justify-content: center; }
.mt-6 { margin-top: 6px; } .mt-8 { margin-top: 8px; } .mt-10 { margin-top: 10px; } .mt-12 { margin-top: 12px; } .mt-14 { margin-top: 14px; } .mt-16 { margin-top: 16px; }
.mb-8 { margin-bottom: 8px; } .mb-12 { margin-bottom: 12px; }
.pad-8 { padding: 8px; }
.narrow { max-width: 820px; } .narrow-sm { max-width: 560px; }
.accent-text { color: var(--accent); }

/* Relatives from a record: name on the left, what to do on the right; stacked on phones */
.rel-row { display: grid; grid-template-columns: minmax(0, 1fr) minmax(180px, 280px); gap: 10px; align-items: center; padding: 10px 0; border-bottom: 1px solid var(--line); }
.rel-row .check { align-items: flex-start; }
.rel-row .check input { margin-top: 3px; flex: none; }
@media (max-width: 600px) { .rel-row { grid-template-columns: 1fr; } }

main:focus { outline: none; }
