:root {
  /* Banyan look: pale sage page, white cards, teal and gold accents */
  --bg: #edf2ea;
  --surface: #ffffff;
  --surface-2: #e7eee4;
  --ink: #1e2a24;
  --muted: #5b6a61;
  --line: #cdd9cb;
  --bark: #6e5236;
  --leaf: #2f6b5a;
  --accent: #17706b;
  --accent-ink: #ffffff;
  --gold: #c49a3a;
  --male: #f6f9fb;
  --female: #fcf6f7;
  --warn-bg: #fff4d6;
  --warn-ink: #7a5300;
  --ok-bg: #e2f2e4;
  --ok-ink: #1f5a2a;
  --danger: #b3261e;
  --shadow: 0 1px 3px rgb(30 50 40 / 0.10), 0 4px 14px rgb(30 50 40 / 0.07);
  --radius: 10px;
  --topbar-h: 100px;
  --watermark-opacity: 0.11;
  /* Branch colours: one fixed order, largest branch first */
  --branch-1: #2a78d6; --branch-2: #eb6834; --branch-3: #1baf7a; --branch-4: #eda100;
  --branch-5: #e87ba4; --branch-6: #008300; --branch-7: #6250d6; --branch-8: #e34948; --branch-0: #9aa69e;
  /* Soft pastels for headers and tiles */
  --p-mint: #dcf2e6; --p-blush: #fae1e7; --p-sky: #dde9fa; --p-lavender: #e9e3f8; --p-butter: #faf1c8; --p-peach: #fde5d4;
  color-scheme: light;
}
/* Dark colours: follow the device unless the person picked Light or Dark
   with the switch in the menu (stored per device, see js/theme.js). */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #121815;
    --surface: #1b231f;
    --surface-2: #24302a;
    --ink: #e8efe9;
    --muted: #a3b2a8;
    --line: #33423a;
    --bark: #c79a6a;
    --leaf: #7fbfa8;
    --accent: #5cc0b5;
    --accent-ink: #0f1513;
    --gold: #d6b25a;
    --male: #1c272b;
    --female: #2a2226;
    --warn-bg: #3d3216;
    --warn-ink: #f2d27a;
    --ok-bg: #1f3524;
    --ok-ink: #9fd8a9;
    --danger: #ff8a80;
    --watermark-opacity: 0.13;
    --branch-1: #3987e5; --branch-2: #d95926; --branch-3: #199e70; --branch-4: #c98500;
    --branch-5: #d55181; --branch-6: #008300; --branch-7: #9085e9; --branch-8: #e66767; --branch-0: #6b776f;
    --p-mint: #1e3329; --p-blush: #3a252b; --p-sky: #1f2c3d; --p-lavender: #2b2639; --p-butter: #36311b; --p-peach: #3a2a1e;
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #121815;
  --surface: #1b231f;
  --surface-2: #24302a;
  --ink: #e8efe9;
  --muted: #a3b2a8;
  --line: #33423a;
  --bark: #c79a6a;
  --leaf: #7fbfa8;
  --accent: #5cc0b5;
  --accent-ink: #0f1513;
  --gold: #d6b25a;
  --male: #1c272b;
  --female: #2a2226;
  --warn-bg: #3d3216;
  --warn-ink: #f2d27a;
  --ok-bg: #1f3524;
  --ok-ink: #9fd8a9;
  --danger: #ff8a80;
  --watermark-opacity: 0.13;
  --branch-1: #3987e5; --branch-2: #d95926; --branch-3: #199e70; --branch-4: #c98500;
  --branch-5: #d55181; --branch-6: #008300; --branch-7: #9085e9; --branch-8: #e66767; --branch-0: #6b776f;
  --p-mint: #1e3329; --p-blush: #3a252b; --p-sky: #1f2c3d; --p-lavender: #2b2639; --p-butter: #36311b; --p-peach: #3a2a1e;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 15px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, "Noto Sans", sans-serif;
  -webkit-text-size-adjust: 100%;
}
h1 { font-size: 1.5rem; margin: 0.2em 0 0.6em; }
h2 { font-size: 1.15rem; margin: 1.4em 0 0.5em; }
h3 { font-size: 0.95rem; margin: 1em 0 0.3em; color: var(--muted); text-transform: uppercase; letter-spacing: 0.04em; }
a { color: var(--accent); }
.muted { color: var(--muted); }
.small { font-size: 0.85rem; }
[hidden] { display: none !important; }

/* ---------- header */
.topbar {
  position: relative; z-index: 20;
  display: flex; align-items: center; gap: 8px 12px; flex-wrap: wrap;
  min-height: var(--topbar-h);
  padding: 8px max(16px, env(safe-area-inset-left));
  background: var(--surface); border-bottom: 2px solid var(--gold);
}
.brand { display: flex; align-items: center; gap: 8px; flex: none; }
.brand-logo { position: relative; display: block; flex: none; line-height: 0; cursor: zoom-in; border-radius: 8px; }
.brand-logo:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
/* Hover (or tap on a phone) shows the logo large enough to read its words. */
.logo-pop { display: none; pointer-events: none; position: absolute; top: calc(100% + 8px); left: 0; z-index: 40; padding: 10px; background: var(--surface); border: 1px solid var(--line); border-radius: 14px; box-shadow: var(--shadow); }
.logo-pop img { display: block; width: min(500px, calc(100vw - 52px)); height: auto; }
.brand-logo:hover .logo-pop, .brand-logo:focus .logo-pop { display: block; }
.brand-logo > img { display: block; height: 88px; width: auto; margin: -2px 0; }
/* Footer: maker's mark and copyright, on every page. */
.site-foot { flex: none; display: flex; align-items: center; justify-content: center; gap: 8px; padding: 4px 16px calc(4px + env(safe-area-inset-bottom)); background: var(--surface); border-top: 1px solid var(--line); color: var(--muted); font-size: 0.75rem; }
.site-foot img { display: block; height: 22px; width: auto; border-radius: 4px; }
.page-foot { margin-top: 32px; padding: 16px; font-size: 0.85rem; border-top: 1px solid var(--line); background: none; }
.page-foot img { height: 36px; border-radius: 6px; }
.site-title { font-weight: 700; font-size: 1.05rem; color: var(--ink); text-decoration: none; white-space: nowrap; }
.search-wrap { position: relative; flex: 1 1 160px; min-width: 160px; max-width: 420px; }
#search {
  width: 100%; padding: 9px 12px; border-radius: 999px;
  border: 1px solid var(--line); background: var(--surface-2); color: var(--ink); font-size: 16px;
}
#search:focus { outline: 2px solid var(--accent); outline-offset: 1px; background: var(--surface); }
#search-results {
  position: absolute; top: calc(100% + 6px); left: 0; right: 0; z-index: 30;
  list-style: none; margin: 0; padding: 4px; max-height: 60vh; overflow: auto;
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow);
}
#search-results button, .pick-list button {
  display: block; width: 100%; text-align: left; padding: 9px 10px; border: 0; border-radius: 8px;
  background: none; color: var(--ink); font: inherit; cursor: pointer;
}
#search-results li.active button, #search-results button:hover, .pick-list button:hover { background: var(--surface-2); }
#search-results .none { padding: 10px; }
nav { display: flex; align-items: center; gap: 4px; margin-left: auto; flex-wrap: wrap; justify-content: flex-end; }
nav a, .linkish {
  padding: 6px 10px; border-radius: 8px; text-decoration: none; color: var(--ink);
  background: none; border: 0; font: inherit; cursor: pointer;
}
nav a:hover, .linkish:hover { background: var(--surface-2); }
nav a.active { background: var(--surface-2); font-weight: 600; }
.count { display: inline-block; margin-left: 5px; min-width: 20px; padding: 0 6px; border-radius: 999px; background: var(--accent); color: var(--accent-ink); font-size: 0.75rem; text-align: center; }
.banner { padding: 8px 16px; background: var(--warn-bg); color: var(--warn-ink); font-size: 0.9rem; }
/* Right side of the header: the menu, and under it the signed-in member's
   chip (photo, name, blessings, badges, "?"), inside the header's own space. */
.top-right { margin-left: auto; display: flex; flex-direction: column; align-items: flex-end; gap: 2px; min-width: 0; }
/* Signed out there's no chip: the menu sits in the header as before. */
.topbar:has(#who:empty) .top-right { display: contents; }
.who { display: flex; align-items: center; justify-content: flex-end; min-width: 0; max-width: 100%; padding: 0 4px 0 0; font-size: 0.8rem; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.who:empty { display: none; }
.who .me-chip { margin: 0; }
/* When the menu can't share the first row with the search box (main.js adds
   .stacked), it drops to a row of its own and the chip stays up on the first
   row, at the right, so it still takes no extra height. */
.topbar.stacked .top-right { display: contents; }
.topbar.stacked #who { order: 1; margin-left: auto; }
.topbar.stacked nav { order: 2; flex-basis: 100%; }
/* Narrower screens: the chip drops the name (photo, points and badges stay). */
@media (max-width: 900px) { .who .me-name { display: none; } .me-chip { gap: 6px; } }

@media (max-width: 760px) {
  .topbar { flex-wrap: wrap; gap: 6px 10px; }
  .search-wrap { order: 3; flex-basis: 100%; max-width: none; }
  .top-right { display: contents; }
  .topbar #who { order: 0; margin-left: auto; }
  .topbar:has(#who:not(:empty)) nav { order: 2; flex-basis: 100%; }
  nav { gap: 0; }
  nav a, .linkish { padding: 6px 7px; font-size: 0.9rem; }
}

/* ---------- buttons and forms */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  padding: 9px 14px; min-height: 40px; border-radius: 8px; border: 1px solid var(--line);
  background: var(--surface); color: var(--ink); font: inherit; font-weight: 500; cursor: pointer;
}
.btn:hover { background: var(--surface-2); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.primary:hover { filter: brightness(1.08); }
.btn.danger { color: var(--danger); }
.btn.ghost { border-color: transparent; background: none; }
.btn.small { padding: 5px 10px; min-height: 32px; font-size: 0.88rem; }
.btn:disabled { opacity: 0.55; cursor: progress; }
.icon-btn {
  width: 40px; height: 40px; border-radius: 50%; border: 1px solid var(--line);
  background: var(--surface); color: var(--ink); font-size: 1.1rem; cursor: pointer; line-height: 1;
}
.icon-btn.small { width: 26px; height: 26px; font-size: 0.75rem; margin-left: 6px; vertical-align: middle; }
.link { background: none; border: 0; padding: 0; color: var(--accent); font: inherit; cursor: pointer; text-align: left; text-decoration: underline; text-underline-offset: 2px; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

.form { display: grid; gap: 12px; }
.form fieldset { border: 1px solid var(--line); border-radius: var(--radius); padding: 10px 12px 12px; margin: 0; display: grid; gap: 10px; }
.form legend { padding: 0 6px; font-weight: 600; color: var(--muted); font-size: 0.85rem; }
.field { display: grid; gap: 4px; }
.field-label { font-size: 0.85rem; font-weight: 600; }
.field select.missing { border-color: #c0392b; box-shadow: 0 0 0 2px rgba(192, 57, 43, 0.25); }
.field-hint { font-size: 0.8rem; color: var(--muted); }
.field input, .field select, .field textarea, .req-card input, .picker input, .member select {
  width: 100%; padding: 9px 10px; border-radius: 8px; border: 1px solid var(--line);
  background: var(--surface); color: var(--ink); font: inherit; font-size: 16px;
}
.row2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
@media (max-width: 480px) { .row2 { grid-template-columns: 1fr; } }
.form-note { margin: 0; color: var(--muted); }
.form-actions { display: flex; gap: 8px; justify-content: flex-end; flex-wrap: wrap; }
.picker { position: relative; }
.pick-list { list-style: none; margin: 4px 0 0; padding: 0; }
.photo-preview { min-height: 60px; display: grid; place-items: center; background: var(--surface-2); border-radius: var(--radius); padding: 8px; }
.photo-preview img { max-width: 100%; max-height: 260px; border-radius: 8px; }

/* ---------- modal */
.modal {
  width: min(560px, calc(100vw - 24px)); max-height: calc(100dvh - 24px);
  padding: 0; border: 0; border-radius: 14px; background: var(--surface); color: var(--ink); box-shadow: var(--shadow);
}
.modal::backdrop { background: rgb(20 12 4 / 0.45); }
.modal-head { position: sticky; top: 0; z-index: 1; display: flex; align-items: center; justify-content: space-between; padding: 12px 16px; background: var(--surface); border-bottom: 1px solid var(--line); }
.modal-head h2 { margin: 0; font-size: 1.1rem; }
.modal-body { padding: 16px; }
/* Keep a form's Save button in view while the dialog scrolls. */
.modal .form > .form-actions:last-child { position: sticky; bottom: 0; z-index: 1; margin: 4px -16px -16px; padding: 12px 16px; background: var(--surface); border-top: 1px solid var(--line); border-radius: 0 0 14px 14px; }

/* ---------- main layout */
body { display: flex; flex-direction: column; height: 100dvh; overflow: hidden; }
.topbar, .banner, .who { flex: none; }
main { position: relative; flex: 1; min-height: 0; display: flex; flex-direction: column; overflow: auto; }
#tree-area { flex: 1; min-height: 0; display: flex; flex-direction: column; }
.crumbs { flex: none; }
.tree-wrap { position: relative; flex: 1; min-height: 300px; }
/* Faint banyan tree behind the family tree */
.tree-wrap::before, .help::before {
  content: ""; position: absolute; inset: 0; pointer-events: none; z-index: 0;
  background: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 600 420' fill='none' stroke='%235e8f80' stroke-width='3' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M60 190Q40 150 80 130Q80 90 130 85Q150 50 200 60Q230 30 280 45Q320 25 360 48Q410 35 435 70Q485 70 495 110Q545 120 535 160Q560 195 520 210Q500 235 460 225Q430 245 390 230Q350 250 310 232Q270 250 230 232Q190 248 160 228Q120 240 100 220Q55 225 60 190Z'/%3E%3Cpath d='M120 160Q150 140 185 150M240 110Q270 95 300 105M350 100Q385 90 410 110M430 170Q460 160 480 175M170 200Q200 190 225 200M380 195Q410 185 440 197' stroke-width='2'/%3E%3Cpath d='M288 232C283 290 272 340 252 392M322 232C327 290 338 340 360 392M300 232C290 200 250 182 205 172M312 232C332 196 382 180 425 166M305 232L305 140'/%3E%3Cpath d='M130 222C127 280 134 340 130 392M165 230C168 290 160 340 166 392M200 238C197 300 204 350 200 392M232 236C236 300 228 350 232 392M382 234C379 300 386 350 382 392M415 232C418 290 410 350 416 392M448 228C445 290 452 345 448 392M482 222C485 285 478 345 482 392' stroke-width='2'/%3E%3Cpath d='M40 395Q300 383 560 395'/%3E%3C/svg%3E") no-repeat center 70% / min(900px, 92%) auto;
  opacity: var(--watermark-opacity);
}
.tree-canvas, .outline-wrap, .tree-tools { z-index: 1; }
.loading { padding: 40px 16px; text-align: center; color: var(--muted); }
.crumbs { display: flex; flex-wrap: wrap; align-items: center; gap: 4px 6px; padding: 8px 16px; font-size: 0.9rem; border-bottom: 1px solid var(--line); background: var(--surface); }
.crumbs .sep { color: var(--muted); }
.crumbs .btn { flex: none; }
#start-from { font: inherit; font-weight: 600; max-width: min(80vw, 300px); padding: 4px 8px; border-radius: 8px; border: 1px solid var(--line); background: var(--surface); color: var(--ink); }
.start-gen { border: 1.5px solid var(--gold); color: var(--ink); border-radius: 999px; padding: 0 10px; font-weight: 600; font-size: 0.78rem; white-space: nowrap; }
.start-path { display: inline-flex; flex-wrap: wrap; align-items: center; gap: 2px 6px; }
/* Phones: the path above, then the drop-down with its badge, then "you are
   here"; each one line that scrolls sideways rather than wrapping. */
@media (max-width: 600px) {
  .crumbs { padding: 6px 12px; gap: 6px; }
  .crumbs > .muted:first-child { display: none; }
  .start-path { flex: 1 0 100%; flex-wrap: nowrap; white-space: nowrap; overflow-x: auto; scrollbar-width: none; font-size: 0.85rem; }
  .start-path::-webkit-scrollbar { display: none; }
  #start-from { flex: 1 1 0; min-width: 0; max-width: none; }
  .crumbs .tree-trail { flex-basis: 100%; padding-left: 0; border-left: 0; font-size: 0.8rem; }
}
.tree-canvas { position: absolute; inset: 0; overflow: hidden; touch-action: none; }
.tree-svg { width: 100%; height: 100%; display: block; cursor: grab; }
.tree-svg:active { cursor: grabbing; }
.tree-tools { position: absolute; left: 12px; bottom: calc(12px + env(safe-area-inset-bottom)); display: flex; flex-direction: column; gap: 6px; }
.tree-tools .icon-btn { box-shadow: var(--shadow); }

/* tree cards */
.link { }
path.link { fill: none; stroke: var(--bark); stroke-opacity: 0.55; stroke-width: 1.6; }
path.link.uncertain { stroke-dasharray: 5 4; stroke-opacity: 0.8; }
path.link.nonbio { stroke-dasharray: 2 3; }
g.node { cursor: pointer; }
g.node rect.card { fill: var(--surface); stroke: var(--line); stroke-width: 1.2; filter: drop-shadow(0 1px 2px rgb(60 40 20 / 0.12)); }
g.node.male rect.card { fill: var(--male); }
g.node.female rect.card { fill: var(--female); }
g.node:hover rect.card, g.node:focus rect.card { stroke: var(--accent); }
g.node:focus { outline: none; }
g.node.selected rect.card { stroke: var(--accent); stroke-width: 3; }
g.node path.card-top { fill: none; stroke: var(--gold); stroke-width: 3; stroke-linecap: round; pointer-events: none; }
/* Each branch's colour on the top edge of its cards (see branches.js) */
g.node[data-branch] path.card-top { stroke: var(--branch-0); stroke-width: 4; }
g.node[data-branch="1"] path.card-top { stroke: var(--branch-1); }
g.node[data-branch="2"] path.card-top { stroke: var(--branch-2); }
g.node[data-branch="3"] path.card-top { stroke: var(--branch-3); }
g.node[data-branch="4"] path.card-top { stroke: var(--branch-4); }
g.node[data-branch="5"] path.card-top { stroke: var(--branch-5); }
g.node[data-branch="6"] path.card-top { stroke: var(--branch-6); }
g.node[data-branch="7"] path.card-top { stroke: var(--branch-7); }
g.node[data-branch="8"] path.card-top { stroke: var(--branch-8); }
g.node text { fill: var(--ink); font-size: 13px; }
g.node text.name { font-weight: 650; font-size: 13.5px; }
g.node text.sub { fill: var(--muted); font-size: 11.5px; }
g.node text.badge { fill: var(--warn-ink); font-weight: 700; font-size: 13px; }
.avatar-bg { fill: var(--surface-2); stroke: var(--line); }
.avatar-initials { fill: var(--muted) !important; font-weight: 700; font-size: 14px !important; }
path.marriage { fill: none; stroke: var(--gold); stroke-width: 2.2; }
path.marriage.divorced { stroke-dasharray: 4 3; stroke: var(--muted); }
g.ring circle { fill: var(--surface); stroke: var(--gold); stroke-width: 1.8; pointer-events: none; }
g.toggle path.stem { stroke: var(--bark); stroke-opacity: 0.55; stroke-width: 1.6; fill: none; }
g.node.spouse-card rect.card { stroke-dasharray: 5 3; }
g.edit-btn { cursor: pointer; }
g.edit-btn circle { fill: var(--surface); stroke: var(--accent); stroke-width: 1.3; }
g.edit-btn circle.edit-hit { fill: transparent; stroke: none; }
g.edit-btn path { fill: none; stroke: var(--accent); stroke-width: 1.4; stroke-linejoin: round; stroke-linecap: round; }
g.edit-btn:hover circle:not(.edit-hit), g.edit-btn:focus circle:not(.edit-hit) { fill: var(--accent); }
g.edit-btn:hover path, g.edit-btn:focus path { stroke: var(--surface); }
g.edit-btn:focus { outline: none; }
g.toggle circle { fill: var(--surface); stroke: var(--bark); stroke-width: 1.4; }
g.toggle text { font-size: 11px !important; font-weight: 700; fill: var(--bark) !important; }
g.toggle:hover circle { fill: var(--surface-2); }
/* The open/close circles under a card are teal, like the child-count pills:
   a number when the family is closed, − when it is open. */
g.toggle circle { fill: var(--accent); stroke: none; }
g.toggle text { fill: var(--accent-ink) !important; }
g.toggle:hover circle { fill: var(--accent); filter: brightness(1.12); }
g.toggle.pill { cursor: pointer; }
g.toggle.pill rect { fill: var(--accent); stroke: none; }
g.toggle.pill text { fill: var(--accent-ink) !important; font-size: 12px !important; }
g.toggle.pill:hover rect { filter: brightness(1.12); }

/* outline */
.outline-wrap { position: absolute; inset: 0; overflow: auto; padding: 8px 12px 80px; }
.outline, .outline ul { list-style: none; margin: 0; padding: 0; }
.outline ul { padding-left: 18px; border-left: 1px dashed var(--line); margin-left: 9px; }
.outline summary { display: flex; align-items: center; gap: 4px; cursor: pointer; }
.outline summary::marker { color: var(--bark); }
.outline-row {
  flex: 1; display: flex; flex-wrap: wrap; align-items: baseline; gap: 2px 8px; margin: 2px 0;
  padding: 7px 8px; text-align: left; border: 0; border-radius: 8px; background: none; color: var(--ink); font: inherit; cursor: pointer;
}
li > .outline-row { margin-left: 18px; width: calc(100% - 18px); }
.outline-row:hover, .outline-row.selected { background: var(--surface-2); }
.outline-row.selected { outline: 2px solid var(--accent); }
.o-name { font-weight: 600; }
.o-spouse, .o-life { color: var(--muted); font-size: 0.88rem; }
.o-count { font-size: 0.75rem; color: var(--muted); padding: 0 6px; border: 1px solid var(--line); border-radius: 999px; }

/* person panel */
.panel {
  position: fixed; z-index: 15; top: var(--panel-top, var(--topbar-h)); right: 0; bottom: 0; width: min(380px, 100vw);
  overflow: auto; padding: 8px 18px 28px; background: var(--surface); border-left: 1px solid var(--line); box-shadow: var(--shadow);
}
@media (max-width: 760px) {
  .panel { top: auto; left: 0; width: 100%; max-height: 55dvh; border-left: 0; border-top: 1px solid var(--line); border-radius: 16px 16px 0 0; padding-bottom: calc(28px + env(safe-area-inset-bottom)); }
}
.panel-head { position: sticky; top: 0; display: flex; justify-content: flex-end; margin: 0 -8px; }
.panel-head .icon-btn { width: 34px; height: 34px; }
.panel-photo { display: flex; flex-direction: column; align-items: center; gap: 8px; }
.panel-photo img { width: 132px; height: 132px; object-fit: cover; border-radius: 50%; border: 3px solid var(--surface-2); }
.avatar-lg { width: 108px; height: 108px; border-radius: 50%; display: grid; place-items: center; font-size: 2rem; font-weight: 700; color: var(--muted); background: var(--surface-2); }
.panel-name { text-align: center; margin: 10px 0 2px; font-size: 1.3rem; }
.panel > .muted { text-align: center; margin: 0; }
.tags { display: flex; flex-wrap: wrap; gap: 6px; justify-content: center; }
.tag { display: inline-block; padding: 2px 8px; border-radius: 999px; background: var(--surface-2); font-size: 0.78rem; color: var(--muted); }
.tag.warn { background: var(--warn-bg); color: var(--warn-ink); }
.tag.ok { background: var(--ok-bg); color: var(--ok-ink); }
.tag.lock::before { content: "🔒 "; }
.details { margin: 12px 0; display: grid; gap: 4px; }
.dl-row { display: grid; grid-template-columns: 110px 1fr; gap: 8px; }
.dl-row dt { color: var(--muted); }
.dl-row dd { margin: 0; }
.notice { padding: 10px 12px; border-radius: var(--radius); background: var(--surface-2); color: var(--muted); font-size: 0.9rem; }
.uncertain { padding: 10px 12px; border-radius: var(--radius); background: var(--warn-bg); color: var(--warn-ink); font-size: 0.92rem; margin: 10px 0; }
.notes { white-space: pre-wrap; margin: 10px 0; }
.notes-box { margin: 10px 0; }
.notes-box .notes { margin: 4px 0 0; }
.family ul { list-style: none; margin: 0; padding: 0; }
.family li { padding: 3px 0; }
.sources { margin: 12px 0; font-size: 0.88rem; color: var(--muted); }
.sources p { white-space: pre-wrap; }
.panel-actions { display: grid; gap: 8px; margin-top: 16px; padding-top: 14px; border-top: 1px solid var(--line); }
.panel-actions.panel-top { margin: 4px 0 14px; padding: 0 0 14px; border-top: 0; border-bottom: 1px solid var(--line); }
.panel-top .main-row { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.add-row { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.btn.danger.ghost { justify-self: start; }
.hint { text-align: center; margin-top: 14px; }

/* pages */
.page { max-width: 820px; width: 100%; min-width: 0; margin: 0 auto; padding: 16px 16px 60px; }
.req-card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px 14px; margin: 0 0 12px; display: grid; gap: 8px; box-shadow: var(--shadow); }
.req-card h3 { margin: 0; text-transform: none; letter-spacing: 0; color: var(--ink); font-size: 1rem; }
.review-photo { max-width: 220px; border-radius: 8px; }
.history, .members { list-style: none; margin: 0; padding: 0; }
.history li { padding: 8px 0; border-bottom: 1px solid var(--line); }
.history .btn { margin-left: 8px; }
.member { display: grid; grid-template-columns: 1.2fr 1.2fr 1.4fr 0.8fr; gap: 10px; align-items: start; padding: 10px 0; border-bottom: 1px solid var(--line); }
@media (max-width: 700px) { .member { grid-template-columns: 1fr; } }
.empty { padding: 18px; text-align: center; background: var(--surface); border-radius: var(--radius); }
.invite-form { background: var(--surface); padding: 14px; border-radius: var(--radius); border: 1px solid var(--line); }

/* toast */
.toast {
  position: fixed; left: 50%; bottom: calc(20px + env(safe-area-inset-bottom)); z-index: 50; transform: translate(-50%, 30px);
  max-width: min(520px, calc(100vw - 32px)); padding: 11px 16px; border-radius: 10px;
  background: var(--ink); color: var(--bg); opacity: 0; pointer-events: none; transition: 0.2s;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }
.toast.error { background: var(--danger); color: #fff; }
.toast.ok { background: var(--leaf); color: #fff; }

/* Desktop: the person panel sits beside the tree instead of over it. */
@media (min-width: 761px) {
  body.panel-open #tree-area { margin-right: min(380px, 100vw); }
}

@media (max-width: 760px) {
  .brand-logo > img { height: 48px; margin: 0; }
  .site-title { font-size: 0.98rem; }
  .brand { flex: 1; min-width: 0; }
  nav { margin-left: 0; flex: none; }
  .banner { font-size: 0.8rem; padding: 6px 16px; }
  .tree-tools .icon-btn { width: 36px; height: 36px; font-size: 1rem; }
  .tree-tools { gap: 5px; }
}

/* Small phones: keep the header on one line; export is available on larger screens. */
@media (max-width: 480px) {
  .wide-only { display: none; }
  .site-title { white-space: normal; line-height: 1.15; }
  /* Signed in, the menu is too long to share a line with the title: give it
     its own row, scrolling sideways if needed. */
  .topbar:has(nav > :nth-child(5)) .site-title { white-space: nowrap; }
  .topbar:has(nav > :nth-child(5)) .brand { flex: 1 0 100%; }
  /* Signed in: the chip shares the logo's row, so the title may wrap. */
  .topbar:has(#who:not(:empty)) .brand { flex: 1 1 0; min-width: 0; }
  .topbar:has(#who:not(:empty)) .site-title { white-space: normal; min-width: 0; }
  /* Phone: the chip shares the logo's row; just photo, points and badges. */
  .me-chip { gap: 5px; padding-right: 7px; }
  .me-chip .me-name { display: none; }
  .me-photo { width: 26px; height: 26px; }
  .me-help { margin-left: 3px; width: 22px; height: 22px; font-size: 0.7rem; }
  .topbar:has(nav > :nth-child(5)) nav {
    order: 2; flex-basis: 100%; justify-content: flex-start; flex-wrap: nowrap;
    overflow-x: auto; scrollbar-width: none; margin: 0 -6px;
  }
  .topbar:has(nav > :nth-child(5)) nav > * { flex: none; }
}

/* Invite a relative */
.notice.ok { background: var(--ok-bg); color: var(--ok-ink); }
.notice p { margin: 0 0 8px; }
.send-invite { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 6px; }
.send-invite .btn { text-decoration: none; }

/* Photo framing */
.photo-editor { display: flex; flex-direction: column; align-items: center; gap: 8px; }
.photo-frame { border-radius: 8px; touch-action: none; cursor: grab; background: var(--surface-2); max-width: 100%; }
.photo-frame:active { cursor: grabbing; }
.zoom-row { display: flex; align-items: center; gap: 8px; width: 260px; max-width: 100%; }
.zoom-row input { flex: 1; }
.photo-actions { display: flex; flex-wrap: wrap; gap: 6px; justify-content: center; }

/* A member's own changes waiting for approval */
.pending-mine { border: 1px dashed var(--warn-ink); background: var(--warn-bg); border-radius: var(--radius); padding: 10px 12px; margin: 10px 0; }
.pending-mine h3 { margin: 0 0 4px; font-size: 0.95rem; }
.pending-mine details { margin: 6px 0; }
.pending-mine summary, .pending-detail summary { cursor: pointer; }

/* Dashboard */
.page:has(.stats) { max-width: 1100px; }
.stats { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 10px; margin: 0 0 12px; }
.stats:empty { display: none; }
.stat { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; box-shadow: var(--shadow); color: var(--ink); text-decoration: none; display: flex; flex-direction: column; }
.stat-label { background: var(--p-mint); padding: 6px 12px; font-size: 0.74rem; font-weight: 700; text-transform: uppercase; letter-spacing: 0.05em; color: var(--ink); }
.stat:nth-child(6n+2) .stat-label { background: var(--p-blush); }
.stat:nth-child(6n+3) .stat-label { background: var(--p-sky); }
.stat:nth-child(6n+4) .stat-label { background: var(--p-lavender); }
.stat:nth-child(6n+5) .stat-label { background: var(--p-butter); }
.stat:nth-child(6n+6) .stat-label { background: var(--p-peach); }
.stat-value { font-size: 1.7rem; font-weight: 700; color: var(--accent); line-height: 1.1; padding: 10px 12px 0; font-variant-numeric: tabular-nums; }
.stat-sub { font-size: 0.8rem; color: var(--muted); padding: 2px 12px 10px; }
.stat-link:hover { border-color: var(--accent); }
.dash-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); gap: 12px; margin: 12px 0; }
.dash-card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px 16px 16px; box-shadow: var(--shadow); min-width: 0; }
.dash-card { padding-top: 0; overflow: hidden; }
.dash-card > h2 { margin: 0 -16px 10px; padding: 9px 16px; font-size: 1rem; background: var(--p-sky); border-bottom: 1px solid var(--line); }
.dash-grid > .dash-card:nth-child(6n+2) > h2 { background: var(--p-mint); }
.dash-grid > .dash-card:nth-child(6n+3) > h2 { background: var(--p-butter); }
.dash-grid > .dash-card:nth-child(6n+4) > h2 { background: var(--p-blush); }
.dash-grid > .dash-card:nth-child(6n+5) > h2 { background: var(--p-lavender); }
.dash-grid > .dash-card:nth-child(6n+6) > h2 { background: var(--p-peach); }
.dash-wide > h2 { background: var(--p-lavender); }
.dash-people.single { columns: 1; }
.dash-table { width: 100%; border-collapse: collapse; font-size: 0.92rem; }
.dash-table th { text-align: left; font-size: 0.75rem; text-transform: uppercase; letter-spacing: 0.04em; color: var(--muted); border-bottom: 2px solid var(--gold); padding: 6px 6px; }
.dash-table td { border-bottom: 1px solid var(--line); padding: 7px 6px; vertical-align: top; }
.dash-table .num { text-align: right; font-variant-numeric: tabular-nums; width: 5.5em; }
.dash-table .row-toggle { color: var(--accent); padding: 0; text-align: left; }
.dash-table .row-toggle::before { content: "▸ "; }
.dash-table .row-toggle[aria-expanded="true"]::before { content: "▾ "; }
.dash-table .names-row td { background: var(--surface-2); }
@media (max-width: 520px) { .dash-table .area, .dash-table th:last-child { display: none; } }
.dash-people { margin: 6px 0 2px; padding-left: 1.1em; columns: 2 180px; font-size: 0.88rem; }
.dash-people li { break-inside: avoid; margin: 2px 0; }
.dupe-pairs { list-style: none; margin: 6px 0 2px; padding: 0; font-size: 0.88rem; }
.dupe-pairs > li { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 6px 12px; padding: 8px 0; border-top: 1px solid var(--line); }
.dupe-pairs > li:first-child { border-top: 0; }
.dupe-two { display: flex; flex-direction: column; gap: 2px; flex: 1 1 260px; min-width: 0; }
.dupe-person { min-width: 0; }
.dupe-and { color: var(--muted); font-size: 0.8rem; }
.bars { display: grid; gap: 6px; margin-top: 6px; }
.bar-row { display: grid; grid-template-columns: minmax(110px, 38%) 1fr; gap: 8px; align-items: center; font-size: 0.88rem; }
.bar-label { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.bar-track { display: flex; align-items: center; gap: 6px; min-width: 0; }
.bar { height: 14px; min-width: 2px; background: var(--accent); border-radius: 0 4px 4px 0; }
.bar-row:hover .bar { filter: brightness(1.15); }
.bar-value { font-variant-numeric: tabular-nums; color: var(--ink); }
.q-list { list-style: none; padding: 0; margin: 0 0 8px; }
.q { border-left: 3px solid var(--gold); padding: 6px 10px; margin: 8px 0; background: var(--surface-2); border-radius: 0 8px 8px 0; }
.q-text { font-weight: 600; }
.q-actions { display: flex; gap: 6px; margin-top: 6px; flex-wrap: wrap; }
.q-actions input { flex: 1; min-width: 160px; padding: 6px 8px; border: 1px solid var(--line); border-radius: 8px; background: var(--surface); color: var(--ink); }
.dash-wide { margin-top: 12px; }

/* Export */
.export-choices { display: grid; grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); gap: 12px; margin: 8px 0 12px; }
.export-choices .dash-card > h2 { background: var(--p-mint); }
.export-choices .dash-card + .dash-card > h2 { background: var(--p-butter); }
.book-preview:empty { display: none; }
.book { background: #fff; color: #1e2a24; padding: 24px; border-radius: var(--radius); box-shadow: var(--shadow); margin-top: 16px; font-size: 13px; }
.book h2 { font-size: 1.3rem; color: #17706b; border-bottom: 2px solid #c49a3a; padding-bottom: 4px; margin: 0 0 12px; }
.book h3 { color: #6e5236; text-transform: none; letter-spacing: 0; font-size: 1rem; background: #faf1c8; padding: 4px 8px; border-radius: 6px; }
.bk-cover { text-align: center; padding: 40px 0 30px; }
.bk-cover h1 { font-size: 2.2rem; color: #17706b; margin: 12px 0 4px; }
.bk-sub { font-size: 1.1rem; margin: 0 0 18px; }
.bk-meta { color: #5b6a61; margin: 4px 0; }
.bk-cover-logo { display: block; width: min(100%, 420px); height: auto; margin: 0 auto; }
.bk-cover-foot, .bk-run-foot { display: flex; align-items: center; justify-content: center; gap: 8px; color: #5b6a61; font-size: 11px; }
.bk-cover-foot { margin-top: 28px; }
.bk-qn { width: 32px; height: auto; }
.bk-run-head, .bk-run-foot { display: none; }
.bk-pages { width: 100%; border-collapse: collapse; }
.bk-pages > * > tr > td { padding: 0; }
.bk-tree, .bk-tree ul { list-style: none; margin: 0; padding-left: 18px; }
.bk-tree { padding-left: 0; }
.bk-tree li { position: relative; padding: 1px 0 1px 12px; border-left: 1px solid #cdd9cb; }
.bk-tree .bk-name { break-inside: avoid; }
.bk-tree li::before { content: ""; position: absolute; left: 0; top: 0.75em; width: 8px; border-top: 1px solid #cdd9cb; }
.bk-tree li[data-branch] > .bk-name { border-bottom: 2px solid var(--branch-0); }
.bk-tree li[data-branch="1"] > .bk-name { border-bottom-color: #2a78d6; }
.bk-tree li[data-branch="2"] > .bk-name { border-bottom-color: #eb6834; }
.bk-tree li[data-branch="3"] > .bk-name { border-bottom-color: #1baf7a; }
.bk-tree li[data-branch="4"] > .bk-name { border-bottom-color: #eda100; }
.bk-tree li[data-branch="5"] > .bk-name { border-bottom-color: #e87ba4; }
.bk-tree li[data-branch="6"] > .bk-name { border-bottom-color: #008300; }
.bk-tree li[data-branch="7"] > .bk-name { border-bottom-color: #6250d6; }
.bk-tree li[data-branch="8"] > .bk-name { border-bottom-color: #e34948; }
.bk-name { font-weight: 650; }
.bk-years, .bk-spouse { color: #5b6a61; }
.bk-people { display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: 10px; }
.bk-person { display: flex; gap: 10px; border: 1px solid #cdd9cb; border-top: 3px solid #c49a3a; border-radius: 8px; padding: 8px 10px; break-inside: avoid; }
.bk-photo, .bk-initials { width: 52px; height: 52px; border-radius: 50%; flex: none; object-fit: cover; }
.bk-initials { display: grid; place-items: center; background: #e7eee4; color: #2f6b5a; font-weight: 700; }
.bk-pname { font-weight: 700; margin-bottom: 2px; }
.bk-person dl { display: grid; grid-template-columns: auto 1fr; gap: 1px 8px; margin: 0; font-size: 12px; }
.bk-person dt { color: #5b6a61; }
.bk-person dd { margin: 0; }

@media print {
  @page { size: A4; margin: 10mm 12mm; }
  html, body { height: auto !important; overflow: visible !important; display: block !important; background: #fff !important; }
  body.printing > *:not(main), body.printing main > *:not(#page), body.printing #page > *:not(.book-preview) { display: none !important; }
  body.printing main, body.printing #page { display: block !important; overflow: visible !important; max-width: none !important; padding: 0 !important; }
  .book { box-shadow: none; padding: 0; margin: 0; border-radius: 0; }
  /* Cover: the big logo fills page 1 and hides the small running header. */
  .bk-cover { position: relative; z-index: 2; background: #fff; height: 276mm; box-sizing: border-box; padding: 6mm 0 0; display: flex; flex-direction: column; justify-content: center; break-after: page; }
  .bk-cover-logo { width: 150mm; max-width: 100%; }
  .bk-cover h1 { font-size: 30pt; margin-top: 8mm; }
  .bk-cover-foot { margin-top: auto; padding-top: 3mm; border-top: 1px solid #c49a3a; }
  /* Running header (small logo) and footer (copyright) on every other page. */
  .bk-run-head, .bk-run-foot { display: flex; position: fixed; left: 0; right: 0; z-index: 1; background: #fff; }
  .bk-run-head { top: 0; height: 15mm; align-items: center; gap: 10px; border-bottom: 1px solid #c49a3a; }
  .bk-run-logo { height: 13mm; width: auto; }
  .bk-run-title { margin-left: auto; color: #17706b; font-weight: 700; font-size: 11pt; }
  .bk-run-title span { color: #5b6a61; font-weight: 400; }
  .bk-run-foot { bottom: 0; height: 9mm; border-top: 1px solid #c49a3a; font-size: 9pt; }
  .bk-run-foot .bk-qn { width: 9mm; }
  .bk-head-space { height: 19mm; }
  .bk-foot-space { height: 12mm; }
  .bk-dir { break-before: page; }
  .bk-people { grid-template-columns: 1fr 1fr; }
  .bk-gen h3 { break-after: avoid; }
  * { -webkit-print-color-adjust: exact; print-color-adjust: exact; }
}
.person-history ul { margin: 6px 0 0; padding-left: 18px; }
.person-history li { margin: 2px 0; }
.person-history h4 { margin: 10px 0 0; font-size: 0.85rem; color: var(--ink); }
.person-history .form-note { margin-top: 2px; }

/* Balloon with key facts when hovering (or long-pressing) a box in the tree */
.hovercard { position: absolute; z-index: 20; width: min(320px, calc(100% - 16px)); background: var(--surface); color: var(--ink);
  border: 1px solid var(--line); border-radius: 14px; box-shadow: 0 10px 28px rgb(30 40 30 / 0.22); padding: 12px; pointer-events: none; }
.hc-inner { display: flex; gap: 12px; align-items: flex-start; }
.hc-photo { flex: 0 0 76px; width: 76px; height: 76px; border-radius: 50%; overflow: hidden; background: var(--surface-2);
  display: grid; place-items: center; font-weight: 700; font-size: 1.3rem; color: var(--muted); border: 2px solid var(--gold); }
.hc-photo img { width: 100%; height: 100%; object-fit: cover; }
.hc-text { min-width: 0; font-size: 0.86rem; line-height: 1.35; }
.hc-rel { display: inline-block; background: var(--p-butter); color: var(--ink); border-radius: 999px; padding: 1px 8px; font-size: 0.76rem; font-weight: 650; margin-bottom: 4px; }
.hc-name { font-weight: 700; font-size: 1rem; }
.hc-muted { color: var(--muted); font-size: 0.8rem; }
.hc-life { color: var(--accent); font-weight: 600; margin: 2px 0 4px; }
.hc-facts { display: grid; grid-template-columns: auto 1fr; gap: 1px 8px; margin: 4px 0 0; }
.hc-facts dt { color: var(--muted); }
.hc-facts dd { margin: 0; overflow-wrap: anywhere; }
.hc-tags { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 6px; }
.hc-branch, .hc-gen { font-size: 0.74rem; border-radius: 999px; padding: 1px 8px; background: var(--surface-2); border-left: 4px solid var(--branch-0); }
.hc-branch[data-branch="1"] { border-left-color: var(--branch-1); } .hc-branch[data-branch="2"] { border-left-color: var(--branch-2); }
.hc-branch[data-branch="3"] { border-left-color: var(--branch-3); } .hc-branch[data-branch="4"] { border-left-color: var(--branch-4); }
.hc-branch[data-branch="5"] { border-left-color: var(--branch-5); } .hc-branch[data-branch="6"] { border-left-color: var(--branch-6); }
.hc-branch[data-branch="7"] { border-left-color: var(--branch-7); } .hc-branch[data-branch="8"] { border-left-color: var(--branch-8); }
.hc-gen { border-left: none; }

/* Reminder to claim your own box */
.claim-banner { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 14px; background: #fdf3d6; color: #5b4310; border-bottom: 2px solid var(--gold, #c49a3a); }
.claim-banner[hidden] { display: none; }
.claim-banner.waiting { background: #eef6f4; color: #1d4d49; border-bottom-color: #9cc9c2; }
.claim-banner .claim-actions { display: inline-flex; gap: 8px; align-items: center; margin-left: auto; }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) .claim-banner { background: #3a3018; color: #f3e3b8; } :root:not([data-theme="light"]) .claim-banner.waiting { background: #1e3633; color: #cfe8e3; } }
:root[data-theme="dark"] .claim-banner { background: #3a3018; color: #f3e3b8; } :root[data-theme="dark"] .claim-banner.waiting { background: #1e3633; color: #cfe8e3; }
.hovercard .hc-hint { font-size: 0.75rem; color: var(--muted); font-style: italic; margin-bottom: 4px; }

/* Admin: visits report */
.dash-card.wide { margin: 16px 0; }
.dash-card.wide h3 { font-size: 1rem; margin: 16px 0 6px; }
.dash-card.wide .dash-table td { vertical-align: top; }
.dash-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; }
.dash-head select { font: inherit; padding: 4px 8px; border-radius: 8px; border: 1px solid var(--line); background: var(--surface); color: var(--ink); }
.dash-card > .dash-head { margin: 0 -16px 10px; padding: 6px 16px; background: var(--p-sky); border-bottom: 1px solid var(--line); }
.dash-head h2 { margin: 0; font-size: 1rem; }

.theme-toggle { font-size: 0.95rem; }

/* Scroll view (?view=scroll): "you are here" bar across the top of the tree */
.tree-trail { display: flex; flex: 1 1 14rem; min-width: 14rem; flex-wrap: nowrap; align-items: center; gap: 2px 6px; white-space: nowrap; overflow-x: auto; scrollbar-width: none; padding-left: 10px; border-left: 1px solid var(--line); }
.tree-trail::-webkit-scrollbar { display: none; }
.tree-trail .gen { background: var(--gold); color: #fff; border-radius: 999px; padding: 1px 8px; font-weight: 600; font-size: 0.75rem; flex: none; position: sticky; left: 0; z-index: 1; box-shadow: 4px 0 0 var(--surface); }
.tree-trail .sep { color: var(--muted); }
.tree-trail .linkish { color: var(--accent); padding: 2px 4px; font-weight: 500; flex: none; }
.tree-trail[hidden] { display: none; }
.tree-trail:empty { display: none; }

/* ---------- blessings */
.coin { display: inline-grid; place-items: center; width: 18px; height: 18px; border-radius: 50%; background: radial-gradient(circle at 35% 30%, #f3dc95, #c49a3a 60%, #9c7623); color: #3d2b06; font-size: 10px; font-weight: 700; vertical-align: -3px; box-shadow: inset 0 0 0 1px rgb(0 0 0 / .15); flex: none; }
.mini-medal { width: 16px; height: 16px; display: inline-block; vertical-align: -3px; flex: none; }
.me-chip { display: inline-flex; align-items: center; gap: 8px; margin: 4px 0; padding: 3px 10px 3px 3px; border: 1px solid var(--line); border-radius: 999px; background: var(--surface); color: var(--ink); text-decoration: none; font-size: 0.85rem; max-width: 100%; }
.me-chip:hover { border-color: var(--gold); }
.me-photo { width: 30px; height: 30px; border-radius: 50%; object-fit: cover; border: 2px solid var(--gold); flex: none; }
.me-initials { display: grid; place-items: center; background: var(--surface-2); color: var(--muted); font-weight: 700; font-size: 0.75rem; }
.me-name { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; min-width: 0; }
.me-points { display: inline-flex; align-items: center; gap: 4px; font-weight: 700; font-variant-numeric: tabular-nums; }
.me-badges { display: inline-flex; gap: 2px; }
.page:has(.bless-grid) { max-width: 1100px; }
.bless-title { margin-bottom: 4px; }
.bless-grid { display: grid; grid-template-columns: 1.3fr 1fr; gap: 16px; align-items: start; margin: 16px 0; }
@media (max-width: 760px) { .bless-grid { grid-template-columns: 1fr; } }
.bless-side { display: grid; gap: 16px; min-width: 0; }
.bless-card { background: var(--surface); border: 1px solid var(--line); border-radius: 14px; padding: 16px; min-width: 0; margin-bottom: 16px; }
.bless-grid .bless-card { margin-bottom: 0; }
.bless-card h2 { font-size: 1.05rem; margin: 0 0 8px; }
.seg { display: inline-flex; background: var(--surface-2); border-radius: 10px; padding: 3px; gap: 2px; margin-bottom: 12px; }
.seg button { border: 0; background: none; padding: 6px 12px; border-radius: 8px; cursor: pointer; font: inherit; color: inherit; }
.seg button[aria-pressed="true"] { background: var(--surface); box-shadow: 0 1px 2px rgb(0 0 0 / .12); font-weight: 600; }
.board { list-style: none; margin: 0; padding: 0; display: grid; gap: 4px; }
.board li { display: grid; grid-template-columns: 28px 38px minmax(0, 1fr) auto; gap: 10px; align-items: center; padding: 7px 8px; border-radius: 12px; border: 1px solid transparent; }
.board li.me { border-color: var(--accent); }
.board li.empty { display: block; color: var(--muted); }
.board .rank { font-weight: 700; text-align: center; color: var(--muted); font-variant-numeric: tabular-nums; }
.board li:first-child .rank { color: var(--gold); font-size: 1.15rem; }
.board .av { width: 38px; height: 38px; border-radius: 50%; display: grid; place-items: center; background: var(--surface-2); color: var(--muted); font-weight: 700; font-size: 0.8rem; border: 2px solid var(--line); object-fit: cover; }
.board li:first-child .av { border-color: var(--gold); }
.who-cell { min-width: 0; }
.who-cell b, .who-cell small { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.who-cell small { color: var(--muted); }
.board .pts { display: flex; align-items: center; gap: 6px; font-weight: 700; font-variant-numeric: tabular-nums; }
.mini-badges { display: inline-flex; gap: 2px; }
.badges { display: grid; grid-template-columns: repeat(auto-fill, minmax(130px, 1fr)); gap: 8px; }
.badge { display: grid; justify-items: center; text-align: center; gap: 4px; padding: 12px 8px; border-radius: 12px; border: 1px solid var(--line); }
.badge.locked { opacity: .55; }
.badge .medal { width: 48px; height: 48px; }
.badge b { font-size: 0.85rem; }
.badge small { color: var(--muted); font-size: 0.75rem; line-height: 1.3; }
.prog { width: 100%; height: 6px; border-radius: 4px; background: var(--surface-2); overflow: hidden; }
.prog i { display: block; height: 100%; background: var(--accent); }
.branch-bars { display: grid; gap: 8px; }
.br-row { display: grid; grid-template-columns: 1fr auto; gap: 2px 8px; font-size: 0.9rem; }
.br-row .bar { grid-column: 1 / -1; height: 8px; border-radius: 6px; background: var(--surface-2); overflow: hidden; }
.br-row .bar i { display: block; height: 100%; border-radius: 6px; }
.ledger { list-style: none; margin: 0; padding: 0; font-size: 0.9rem; }
.ledger li { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 8px; padding: 6px 0; border-bottom: 1px dashed var(--line); }
table.rules { width: 100%; border-collapse: collapse; font-size: 0.9rem; }
.rules td { padding: 6px 4px; border-bottom: 1px solid var(--line); }
.rules td.n { text-align: right; white-space: nowrap; font-weight: 700; }
.rules th { padding: 6px 4px; border-bottom: 2px solid var(--line); text-align: left; font-size: 0.8rem; color: var(--muted); font-weight: 600; }
.rules th.n { text-align: right; }
table.rules.mult { margin-top: 12px; }
.bless-card table.rules.mult { margin-top: 16px; }

/* Blessings: "How it works" (shown once after sign-in, and on request). */
.bless-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; }
.bless-intro { display: grid; gap: 14px; max-width: 560px; }
.bless-intro p { margin: 0; }
.intro-lead { font-size: 1rem; line-height: 1.5; }
.intro-step { display: grid; gap: 6px; }
.intro-step h3 { display: flex; align-items: center; gap: 8px; margin: 0; font-size: 1.02rem; text-transform: none; letter-spacing: normal; color: var(--ink); }
.intro-n { display: inline-grid; place-items: center; width: 24px; height: 24px; border-radius: 50%; background: var(--accent); color: var(--accent-ink); font-size: 0.8rem; font-weight: 700; flex: none; }
.intro-step table.rules.mult { margin-top: 0; }
.intro-badges { list-style: none; margin: 0; padding: 0; display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 8px; }
.intro-badges li { display: flex; align-items: center; gap: 10px; padding: 8px; border: 1px solid var(--line); border-radius: 10px; }
.intro-badges .medal { width: 34px; height: 34px; flex: none; }
.intro-badges span { display: grid; line-height: 1.3; }
.intro-badges small { color: var(--muted); font-size: 0.8rem; }
.me-help { margin-left: 6px; width: 26px; height: 26px; border-radius: 50%; border: 1px solid var(--line); background: var(--surface); color: var(--muted); font: inherit; font-weight: 700; font-size: 0.8rem; cursor: pointer; vertical-align: middle; }
.me-help:hover { border-color: var(--gold); color: var(--ink); }
.row-fields { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
@media (max-width: 560px) { .row-fields { grid-template-columns: 1fr; } }

/* ---------- reminder emails (Members page) */
.rem-quick { margin: 8px 0; }
.reminder-list { list-style: none; margin: 0 0 12px; padding: 0; max-height: 320px; overflow: auto; border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface); }
.reminder-list li + li { border-top: 1px solid var(--line); }
.reminder-list label { display: grid; grid-template-columns: auto minmax(0, 1fr) auto; gap: 10px; align-items: center; padding: 8px 12px; cursor: pointer; }
.reminder-list label > span:nth-child(2) { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.rem-tag { font-size: 0.75rem; padding: 2px 8px; border-radius: 999px; background: var(--surface-2); color: var(--muted); white-space: nowrap; }
.rem-tag.ok { color: var(--leaf); }
.rem-tag.no { color: var(--danger); }
.reminders textarea { width: 100%; }
.rem-preview { margin-top: 12px; }
.rem-preview iframe { width: 100%; height: 460px; border: 1px solid var(--line); border-radius: var(--radius); background: #fff; }
@media (max-width: 560px) { .rem-tag { display: none; } }
/* ---------- missing details (Members page, admin) */
.cmp-list { list-style: none; margin: 8px 0 12px; padding: 0; display: grid; gap: 8px; }
.cmp-card { border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface); padding: 10px 12px; }
.cmp-head { display: grid; grid-template-columns: auto minmax(0, 1fr) auto; gap: 10px; align-items: center; cursor: pointer; }
.cmp-who { min-width: 0; overflow-wrap: anywhere; }
.cmp-bar { height: 6px; border-radius: 999px; background: var(--surface-2); margin: 8px 0 4px; overflow: hidden; }
.cmp-bar span { display: block; height: 100%; background: var(--leaf); border-radius: 999px; }
.cmp-gaps summary { cursor: pointer; font-size: 0.9rem; color: var(--muted); padding: 4px 0; }
.cmp-gaps ul { margin: 4px 0 0; padding-left: 20px; font-size: 0.92rem; }
.cmp-gaps li { margin: 2px 0; }
.cmp-row { display: flex; flex-wrap: wrap; gap: 8px; align-items: flex-start; justify-content: space-between; }
.cmp-row .cmp-gaps { flex: 1 1 240px; min-width: 0; }
.cmp-write { flex: none; }
.cmp-slot:not(:empty) { margin-top: 10px; }
.cmp-draft .form-actions { flex-wrap: wrap; }
.cmp-draft { border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface-2); padding: 12px; }
.cmp-draft-head { display: flex; flex-wrap: wrap; gap: 8px; justify-content: space-between; align-items: center; margin-bottom: 6px; }
.cmp-draft input[type=text], .cmp-draft textarea { width: 100%; }


/* Family Historian congratulations. */
.historian-pop { display: grid; justify-items: center; text-align: center; gap: 10px; max-width: 420px; }
.historian-pop p { margin: 0; }
.historian-pop .big-medal { width: 96px; height: 96px; filter: drop-shadow(0 4px 10px rgb(196 154 58 / .45)); }
.historian-pop .hp-title { font-size: 1.35rem; font-weight: 700; color: var(--ink); }
.historian-pop .form-actions { justify-content: center; width: 100%; }
.historian-pop .founder-medal { filter: drop-shadow(0 4px 12px rgb(23 112 107 / .45)); }
.badge.special { grid-column: 1 / -1; border-color: var(--gold); background: linear-gradient(180deg, rgb(196 154 58 / .12), transparent); }
.badge.special .medal { width: 60px; height: 60px; }
.founder-ribbon { display: flex; align-items: center; gap: 12px; margin: 8px 0 10px; padding: 10px 12px; border: 1px solid var(--gold); border-radius: 12px; background: linear-gradient(180deg, rgb(196 154 58 / .14), rgb(196 154 58 / .04)); text-align: left; }
.founder-ribbon .medal { width: 46px; height: 46px; flex: none; }
.founder-ribbon div { display: grid; gap: 2px; line-height: 1.35; }
.founder-ribbon small { color: var(--muted); font-size: 0.82rem; }
svg.tree-medal { overflow: visible; filter: drop-shadow(0 1px 2px rgb(0 0 0 / .3)); pointer-events: none; }

/* "First, claim your own box" before making changes */
.claim-gate { display: grid; gap: 12px; }
.claim-gate p { margin: 0; }
.claim-linked, .claim-pick { display: grid; gap: 10px; padding: 12px; border-radius: 10px; background: var(--surface-2); border: 1px solid var(--gold, #c49a3a); }
.claim-pick[hidden], .claim-gate-none[hidden], .claim-gate-foot button[hidden] { display: none; }
.claim-linked .btn, .claim-pick .btn { justify-self: start; }
.claim-gate-foot { border-top: 1px solid var(--line, #ddd); padding-top: 10px; }
.claim-gate-none { display: grid; gap: 10px; }

/* ---------------------------------------------------------------- family library */
.page:has(.lib-grid) { max-width: 1100px; }
.lib-head { display: flex; gap: 12px; align-items: flex-start; justify-content: space-between; flex-wrap: wrap; }
.lib-head h1 { margin-bottom: 4px; }
.lib-head > div { flex: 1 1 320px; }
.lib-head > .btn { margin-top: 14px; }
.lib-notice { margin: 12px 0; background: var(--warn-bg); color: var(--warn-ink); }
.lib-about { margin: 14px 0 4px; padding: 8px 12px; background: var(--p-mint); border-radius: var(--radius); }
.lib-filters { display: grid; gap: 10px; margin: 16px 0 6px; }
.lib-search { width: 100%; max-width: 420px; padding: 10px 12px; border: 1px solid var(--line); border-radius: 10px; background: var(--surface); color: var(--ink); font: inherit; }
.lib-topics { display: flex; flex-wrap: wrap; gap: 6px; }
.lib-topics button { border: 1px solid var(--line); background: var(--surface); color: var(--ink); border-radius: 999px; padding: 5px 12px; font: inherit; font-size: 0.9rem; cursor: pointer; }
.lib-topics button small { color: var(--muted); }
.lib-topics button[aria-pressed="true"] { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); font-weight: 600; }
.lib-topics button[aria-pressed="true"] small { color: inherit; opacity: 0.8; }
.lib-count { margin: 4px 0 10px; }
.lib-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 16px; }
.lib-grid > .lib-empty { grid-column: 1 / -1; }
.lib-mine { margin: 16px 0 8px; padding: 12px; border: 1px dashed var(--gold); border-radius: 14px; }
.lib-mine h2 { font-size: 1.05rem; margin: 0 0 2px; }
.lib-card { display: flex; flex-direction: column; background: var(--surface); border: 1px solid var(--line); border-radius: 14px; overflow: hidden; box-shadow: var(--shadow); min-width: 0; }
.lib-media { position: relative; aspect-ratio: 16 / 9; background: linear-gradient(135deg, var(--p-mint), var(--p-sky)); overflow: hidden; }
.lib-media img, .lib-media iframe { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; border: 0; display: block; }
.lib-media .lib-tile { position: absolute; inset: 0; display: none; flex-direction: column; align-items: center; justify-content: center; gap: 6px; color: var(--leaf); font-size: 0.85rem; font-weight: 600; padding: 8px; text-align: center; overflow-wrap: anywhere; }
.lib-media.no-thumb .lib-tile { display: flex; }
.lib-tile-icon { font-size: 2rem; line-height: 1; }
.lib-media-link { position: absolute; inset: 0; }
.lib-play { position: absolute; inset: 0; width: 100%; border: 0; background: rgb(0 0 0 / 0.12); cursor: pointer; display: grid; place-items: center; }
.lib-play span { width: 62px; height: 44px; border-radius: 12px; background: #c4302b; color: #fff; display: grid; place-items: center; font-size: 1.2rem; box-shadow: 0 2px 8px rgb(0 0 0 / 0.3); transition: transform .15s; }
.lib-play:hover span, .lib-play:focus-visible span { transform: scale(1.08); }
.lib-body { padding: 10px 14px 12px; display: flex; flex-direction: column; gap: 4px; flex: 1; }
.lib-tags { margin: 0; display: flex; flex-wrap: wrap; gap: 4px; }
.lib-topic { background: var(--p-butter); color: var(--warn-ink); }
.lib-title { margin: 4px 0 0; font-size: 1.02rem; line-height: 1.3; text-transform: none; letter-spacing: 0; color: var(--ink); }
.lib-title a { color: inherit; text-decoration: none; }
.lib-title a:hover { text-decoration: underline; }
.lib-source { margin: 0; font-size: 0.82rem; color: var(--muted); }
.lib-note { margin: 4px 0 0; font-size: 0.92rem; white-space: pre-wrap; display: -webkit-box; -webkit-line-clamp: 4; -webkit-box-orient: vertical; overflow: hidden; }
.lib-people { margin: 4px 0 0; font-size: 0.88rem; }
.lib-foot { margin-top: auto; padding-top: 8px; display: flex; align-items: center; gap: 8px; flex-wrap: wrap; justify-content: space-between; }
.lib-open { font-size: 0.9rem; font-weight: 600; }
.lib-actions { display: inline-flex; gap: 4px; }
.lib-form-preview img { width: 100%; max-width: 240px; aspect-ratio: 16 / 9; object-fit: cover; border-radius: 8px; display: block; }
.lib-chips { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 6px; }
.lib-chip { display: inline-flex; align-items: center; gap: 4px; background: var(--p-mint); border-radius: 999px; padding: 3px 4px 3px 10px; font-size: 0.88rem; }
.lib-chip button { border: 0; background: none; color: var(--muted); cursor: pointer; font-size: 0.8rem; padding: 2px 6px; }
.lib-more summary { cursor: pointer; color: var(--muted); font-size: 0.9rem; margin: 4px 0; }
.lib-review { margin-top: 20px; }
.lib-req .lib-card { box-shadow: none; max-width: 420px; }
.lib-person { margin: 12px 0; }
.lib-person-list { list-style: none; padding: 0; margin: 4px 0 6px; }
.lib-person-list li { padding: 3px 0; display: flex; gap: 6px; align-items: baseline; flex-wrap: wrap; }
.lib-k { width: 1.3em; text-align: center; flex: none; }
.lib-person .btn { margin-top: 4px; }
@media (max-width: 560px) { .lib-grid { grid-template-columns: 1fr; } .lib-head > .btn { margin-top: 0; } }
.dash-table.branch-admins { display: block; max-width: 100%; overflow-x: auto; }

/* Warning under "Who can see" when a living person's details or photo are set to Public */
.vis-warn { margin: 6px 0 0; padding: 8px 10px; border-radius: 8px; background: var(--warn-bg); color: var(--warn-ink); font-size: 0.9rem; }
.vis-warn[hidden] { display: none; }

/* "View as" (admin only): strip across the top while previewing a member's view,
   and the member picker. */
.viewas-banner { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 14px; background: #e9e4f7; color: #3b2a6b; border-bottom: 2px solid #7c63c7; }
.viewas-banner[hidden] { display: none; }
.viewas-banner .claim-actions { display: inline-flex; gap: 8px; align-items: center; margin-left: auto; }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) .viewas-banner { background: #2c2545; color: #e2dbff; border-bottom-color: #9d88e6; } }
:root[data-theme="dark"] .viewas-banner { background: #2c2545; color: #e2dbff; border-bottom-color: #9d88e6; }
.viewas-pick input[type="search"] { width: 100%; margin: 4px 0 10px; }
.viewas-list { list-style: none; margin: 0; padding: 0; max-height: min(60vh, 460px); overflow-y: auto; }
.viewas-list li + li { border-top: 1px solid var(--line); }
.viewas-row { display: grid; grid-template-columns: 1fr auto; gap: 2px 10px; width: 100%; padding: 9px 6px; background: none; border: 0; color: inherit; font: inherit; text-align: left; cursor: pointer; border-radius: 6px; }
.viewas-row:hover, .viewas-row:focus-visible { background: var(--hover, rgba(23, 112, 107, 0.08)); }
.viewas-row .muted { grid-column: 1; overflow-wrap: anywhere; }
.viewas-tag { grid-column: 2; grid-row: 1 / span 2; align-self: center; font-size: 0.75rem; padding: 2px 8px; border-radius: 999px; background: var(--warn-bg, #fdf3d6); color: var(--warn-ink, #5b4310); max-width: 15em; text-align: center; }
.viewas-tag.ok { background: rgba(23, 112, 107, 0.14); color: var(--accent); }
@media (max-width: 560px) {
  .viewas-row { grid-template-columns: 1fr; }
  .viewas-tag { grid-column: 1; grid-row: auto; justify-self: start; max-width: none; }
  .viewas-banner .viewas-note { display: none; }
}
