/*
 * Look: a vamshawali kept like a family heirloom. Paper surfaces, ink text, Dhaka-cloth crimson
 * for the app's own chrome, marigold for "me". One decorative element only: the Dhaka band under
 * the header. Names are set in a Devanagari serif; everything else in a plain sans.
 */
:root {
  --paper: #f3f1ec;
  --surface: #ffffff;
  --surface-2: #faf8f4;
  --ink: #1e1a17;
  --muted: #6a625a;
  --line: #e1dbd1;
  --line-strong: #c9c0b2;
  --crimson: #8f1428;
  --crimson-deep: #5e0d1b;
  --crimson-soft: #f6e4e6;
  --on-crimson: #ffffff;
  --marigold: #e0a020;
  --marigold-soft: #fbefd2;
  --marigold-ink: #7a5306;
  --male: #3e6489;
  --male-soft: #e3ebf3;
  --female: #a8456a;
  --female-soft: #f5e3ea;
  --danger: #b0261f;
  --danger-soft: #fbe6e3;
  --tree-line: #b9ad9c;
  /* Branch colours: each line of descent has a hue (set per node as --h); these are saturation and lightness. */
  --br-acc: 54% 36%;
  --br-line: 58% 52%;
  --br-tint: 75% 95%;
  --br-chip: 70% 86%;
  --br-edge: 50% 78%;
  --gen-band: rgba(110, 80, 40, .045);
  --br-root: 54% 36%;
  --on-root: #ffffff;
  --shadow-1: 0 1px 2px rgba(40, 25, 10, .06);
  --shadow-2: 0 2px 6px rgba(40, 25, 10, .07), 0 10px 28px rgba(40, 25, 10, .08);
  --r-s: 8px;
  --r-m: 12px;
  --r-l: 20px;
  --font-ui: "Mukta", system-ui, "Segoe UI", "Nirmala UI", "Noto Sans Devanagari", Roboto, sans-serif;
  --font-name: "Tiro Devanagari Hindi", "Noto Serif Devanagari", "Nirmala UI", Georgia, serif;
  --topbar-h: 54px;
  --band-h: 8px;
  --tabbar-h: 64px;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --paper: #161311;
    --surface: #211d1a;
    --surface-2: #1b1816;
    --ink: #f1ebe3;
    --muted: #a9a094;
    --line: #36302a;
    --line-strong: #4b433b;
    --crimson: #e2697c;
    --crimson-deep: #3a0a13;
    --crimson-soft: #3a1a20;
    --on-crimson: #1b0d10;
    --marigold: #f0b84a;
    --marigold-soft: #3a2d12;
    --marigold-ink: #f3cf85;
    --male: #94b6db;
    --male-soft: #1f2a36;
    --female: #e59ab5;
    --female-soft: #36202a;
    --danger: #ff8d82;
    --danger-soft: #3c1c19;
    --tree-line: #5b5148;
    --br-acc: 70% 74%;
    --br-line: 50% 55%;
    --br-tint: 28% 17%;
    --br-chip: 38% 28%;
    --br-edge: 32% 34%;
    --gen-band: rgba(255, 255, 255, .03);
    --br-root: 45% 30%;
    --on-root: #f7ecee;
    --shadow-1: none;
    --shadow-2: 0 0 0 1px var(--line);
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --paper: #161311;
  --surface: #211d1a;
  --surface-2: #1b1816;
  --ink: #f1ebe3;
  --muted: #a9a094;
  --line: #36302a;
  --line-strong: #4b433b;
  --crimson: #e2697c;
  --crimson-deep: #3a0a13;
  --crimson-soft: #3a1a20;
  --on-crimson: #1b0d10;
  --marigold: #f0b84a;
  --marigold-soft: #3a2d12;
  --marigold-ink: #f3cf85;
  --male: #94b6db;
  --male-soft: #1f2a36;
  --female: #e59ab5;
  --female-soft: #36202a;
  --danger: #ff8d82;
  --danger-soft: #3c1c19;
  --tree-line: #5b5148;
  --br-acc: 70% 74%;
  --br-line: 50% 55%;
  --br-tint: 28% 17%;
  --br-chip: 38% 28%;
  --br-edge: 32% 34%;
  --gen-band: rgba(255, 255, 255, .03);
  --br-root: 45% 30%;
  --on-root: #f7ecee;
  --shadow-1: none;
  --shadow-2: 0 0 0 1px var(--line);
  color-scheme: dark;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; }
html { -webkit-text-size-adjust: 100%; text-size-adjust: 100%; }
button, a, label, input, select, textarea { touch-action: manipulation; }
svg { flex: none; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

body {
  font-family: var(--font-ui);
  font-size: 17px;
  line-height: 1.5;
  background: var(--paper);
  color: var(--ink);
  min-height: 100dvh;
  padding-bottom: calc(var(--tabbar-h) + env(safe-area-inset-bottom));
}
body.no-tabs { padding-bottom: 0; }
h1, h2, h3, h4 { line-height: 1.25; margin: 0; font-weight: 600; }
h2 { font-size: 1.3rem; }
h3 { font-size: 1.05rem; }
h4 { font-size: .9rem; color: var(--muted); font-weight: 500; }
p { margin: 0; }
.muted { color: var(--muted); }
.small { font-size: .875rem; }
.err { color: var(--danger); font-weight: 600; }
.pname, .focus-name, .pc-head h2, .node-name, .welcome h1, .kul-name { font-family: var(--font-name); font-weight: 400; }
.ord { color: var(--muted); font-size: .8em; }

:focus-visible { outline: 2.5px solid var(--marigold); outline-offset: 2px; }
h2[tabindex="-1"]:focus { outline: none; }

/* ---------- shell ---------- */
.topbar {
  position: sticky; top: 0; z-index: 6;
  padding: env(safe-area-inset-top) 16px var(--band-h);
  height: calc(var(--topbar-h) + var(--band-h) + env(safe-area-inset-top));
  display: flex; align-items: center;
  background: var(--crimson-deep); color: #fff;
}
/* The Dhaka band: the one ornament in the app. */
.topbar::after {
  content: ""; position: absolute; left: 0; right: 0; bottom: 0; height: var(--band-h);
  background: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='32' height='8' viewBox='0 0 32 8'%3E%3Crect width='32' height='8' fill='%231e1a17'/%3E%3Cpath d='M0 4L4 0L8 4L4 8Z' fill='%23c4162f'/%3E%3Cpath d='M8 4L12 0L16 4L12 8Z' fill='%23f3f1ec'/%3E%3Cpath d='M16 4L20 0L24 4L20 8Z' fill='%23e0a020'/%3E%3Cpath d='M24 4L28 0L32 4L28 8Z' fill='%23f3f1ec'/%3E%3Cpath d='M10.5 4L12 2.5L13.5 4L12 5.5Z' fill='%23c4162f'/%3E%3Cpath d='M26.5 4L28 2.5L29.5 4L28 5.5Z' fill='%231e1a17'/%3E%3C/svg%3E") repeat-x left center / 32px 8px;
}
.brand { display: flex; align-items: center; gap: 10px; font-family: var(--font-name); font-size: 1.35rem; letter-spacing: .01em; }
.brand-mark { border-radius: 8px; }

.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 6;
  height: calc(var(--tabbar-h) + env(safe-area-inset-bottom));
  padding-bottom: env(safe-area-inset-bottom);
  display: grid; grid-template-columns: repeat(4, 1fr);
  background: var(--surface); border-top: 1px solid var(--line);
}
.tabbar button {
  border: 0; background: none; color: var(--muted); font: inherit; font-size: .82rem; cursor: pointer;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 1px; position: relative;
}
@media (min-width: 720px) { .tabbar { grid-template-columns: repeat(4, minmax(0, 150px)); justify-content: center; } }
.tabbar svg { width: 24px; height: 24px; fill: none; stroke: currentColor; stroke-width: 1.7; stroke-linecap: round; stroke-linejoin: round; }
.tabbar button.active { color: var(--crimson); font-weight: 600; }
.tabbar button.active::before { content: ""; position: absolute; top: 0; left: 30%; right: 30%; height: 3px; border-radius: 0 0 3px 3px; background: var(--crimson); }

.page { max-width: 720px; margin: 0 auto; padding: 20px 16px 28px; display: grid; grid-template-columns: minmax(0, 1fr); gap: 14px; align-content: start; }
.page > h2 { font-size: 1.45rem; }

#banner { padding: 0 16px; }
#banner:empty { display: none; }
.banner {
  max-width: 720px; margin: 12px auto 0; padding: 12px 14px;
  display: flex; flex-wrap: wrap; align-items: center; gap: 8px 12px;
  background: var(--marigold-soft); color: var(--marigold-ink); border-radius: var(--r-m); font-size: .92rem;
}
.banner p { flex: 1 1 220px; }
.banner-acts { display: flex; gap: 6px; margin-left: auto; }

/* ---------- controls ---------- */
.btn {
  font: inherit; font-size: .95rem; font-weight: 600; cursor: pointer;
  min-height: 44px; padding: 6px 16px; border-radius: var(--r-s);
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  border: 1px solid var(--line-strong); background: var(--surface); color: var(--ink);
}
.btn svg { width: 16px; height: 16px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.btn:hover { border-color: var(--muted); }
.btn.primary { background: var(--crimson); border-color: var(--crimson); color: var(--on-crimson); }
.btn.primary:hover { background: var(--crimson-deep); }
.btn.danger { background: transparent; border-color: transparent; color: var(--danger); }
.btn.danger:hover { background: var(--danger-soft); }
.btn.danger.solid { background: var(--danger); border-color: var(--danger); color: #fff; }
.btn.ghost { background: transparent; border-color: transparent; }
.btn.ghost:hover { background: var(--surface-2); }
.btn.small { min-height: 36px; padding: 4px 12px; font-size: .88rem; }
.btn.icon { width: 40px; padding: 0; }
.btn.big { width: 100%; min-height: 54px; font-size: 1.05rem; }
.btn-row { display: flex; flex-wrap: wrap; gap: 8px; }
.btn-row.end { justify-content: flex-end; }
.btn-row.quiet { margin-top: -4px; }

.seg { display: inline-flex; padding: 3px; gap: 2px; border-radius: 10px; background: var(--line); }
.seg button {
  font: inherit; font-size: .92rem; border: 0; background: transparent; color: var(--muted);
  padding: 4px 14px; min-height: 36px; border-radius: 8px; cursor: pointer;
}
.seg button[aria-pressed="true"] { background: var(--surface); color: var(--ink); font-weight: 600; box-shadow: var(--shadow-1); }
.seg.wide { display: flex; width: 100%; max-width: 420px; }
.seg.wide button { flex: 1; }

.add-slot {
  font: inherit; font-size: .92rem; font-weight: 600; cursor: pointer;
  min-height: 44px; padding: 6px 14px; border-radius: var(--r-m);
  border: 1.5px dashed var(--line-strong); background: transparent; color: var(--crimson);
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
}
.add-slot span { font-size: 1.15em; line-height: 1; }
.add-slot:hover { border-color: var(--crimson); background: var(--crimson-soft); }
.add-slot.wide { width: 100%; }
.add-slot.quiet { border: 0; min-height: 36px; padding: 4px 8px; font-size: .88rem; justify-self: start; }

.me-tag {
  display: inline-block; font-family: var(--font-ui); font-size: .72rem; font-weight: 700; line-height: 1.6;
  padding: 0 8px; border-radius: 999px; background: var(--marigold); color: #2b1d02; vertical-align: middle;
}

/* Avatars: initial letter, tinted by sex; a late person's is outlined only. */
.av {
  flex: none; display: inline-grid; place-items: center; border-radius: 50%;
  font-family: var(--font-name); color: var(--male); background: var(--male-soft);
}
.av.sex-F { color: var(--female); background: var(--female-soft); }
.av.sex-U, .av.sex-O { color: var(--muted); background: var(--surface-2); }
.av.late { background: transparent; box-shadow: inset 0 0 0 1.5px currentColor; }
.av-s { width: 34px; height: 34px; font-size: 1rem; }
.av-m { width: 40px; height: 40px; font-size: 1.1rem; }
.av-l { width: 64px; height: 64px; font-size: 1.75rem; }

/* ---------- welcome ---------- */
.welcome { max-width: 440px; margin: 0 auto; padding: 48px 20px 32px; display: grid; justify-items: center; gap: 16px; text-align: center; }
.welcome img { border-radius: 24px; box-shadow: var(--shadow-2); }
.welcome h1 { font-size: 2rem; line-height: 1.2; margin-top: 8px; }
.welcome > p { color: var(--muted); max-width: 34ch; }
.welcome-acts { width: 100%; display: grid; gap: 10px; margin: 12px 0 8px; }

/* ---------- tree: shared ---------- */
.toolbar { padding: 12px 16px 4px; display: flex; justify-content: center; }
.view-tree.mode-chart { display: flex; flex-direction: column; height: calc(100dvh - var(--topbar-h) - var(--band-h) - var(--tabbar-h) - env(safe-area-inset-top) - env(safe-area-inset-bottom)); }
.view-tree.mode-chart .toolbar { padding-bottom: 10px; border-bottom: 1px solid var(--line); background: var(--paper); }

/* ---------- tree: family view ---------- */
.family { max-width: 640px; margin: 0 auto; padding: 8px 16px 32px; display: grid; grid-template-columns: minmax(0, 1fr); }
.crumbs { overflow-x: auto; scrollbar-width: none; margin: 4px -16px 12px; padding: 0 16px; }
.crumbs::-webkit-scrollbar { display: none; }
.crumbs ol { list-style: none; margin: 0; padding: 0; display: flex; align-items: center; gap: 2px; white-space: nowrap; }
.crumbs li { display: flex; align-items: center; font-size: .9rem; }
.crumbs li + li::before { content: ""; width: 6px; height: 6px; margin: 0 8px 0 4px; border-right: 1.5px solid var(--line-strong); border-top: 1.5px solid var(--line-strong); transform: rotate(45deg); }
.crumbs button { font: inherit; border: 0; background: none; color: var(--crimson); padding: 6px 4px; min-height: 36px; cursor: pointer; text-decoration: underline; text-decoration-color: var(--line-strong); text-underline-offset: 3px; }
.crumbs [aria-current] span { color: var(--muted); padding: 6px 4px; }

.fam-parents { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.stem { width: 2px; height: 22px; margin: 0 auto; background: var(--tree-line); }

.pcard {
  font: inherit; color: var(--ink); text-align: left; cursor: pointer; min-width: 0;
  display: flex; align-items: center; gap: 10px; padding: 10px 12px; min-height: 60px;
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-m); box-shadow: var(--shadow-1);
}
.pcard:hover { border-color: var(--line-strong); }
.pcard.is-me { box-shadow: 0 0 0 2px var(--marigold); }
.pcard-text { display: grid; min-width: 0; }
.pcard .pname { font-size: 1.05rem; line-height: 1.3; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.pcard .ord { line-height: 1.2; }
.psub { font-size: .8rem; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.fam-parents .add-slot, .kid-grid .add-slot { min-height: 60px; }

.focus {
  background: var(--surface); border-radius: var(--r-l); padding: 18px 18px 16px;
  box-shadow: var(--shadow-2); border-top: 4px solid var(--male);
  display: grid; gap: 12px;
}
.focus.sex-F { border-top-color: var(--female); }
.focus.is-me { box-shadow: var(--shadow-2), 0 0 0 2px var(--marigold); }
.focus.arrive { animation: arrive .28s ease-out; }
@keyframes arrive { from { opacity: .3; transform: translateY(8px); } to { opacity: 1; transform: none; } }
.focus-meta { font-size: .88rem; color: var(--muted); }
.focus-main { display: flex; align-items: center; gap: 14px; }
.focus-name { font-size: 1.9rem; line-height: 1.15; }
.focus-sub { color: var(--muted); margin-top: 2px; }
.focus-acts { display: flex; gap: 6px; }
.focus-spouses { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 8px; padding-top: 12px; border-top: 1px solid var(--line); }
.focus-spouses .pcard { box-shadow: none; background: var(--surface-2); }

.fam-kids h3, .fam-sibs h3 { margin: 4px 0 10px; }
.kid-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 8px; }
.fam-sibs { margin-top: 24px; padding-top: 16px; border-top: 1px solid var(--line); }
.sib-row { display: flex; gap: 8px; overflow-x: auto; padding-bottom: 6px; scrollbar-width: thin; }
.sib-row .pcard { flex: 0 0 auto; max-width: 220px; box-shadow: none; }

/* ---------- tree: list view ---------- */
.outline, .outline ul { list-style: none; margin: 0; padding: 0; }
.outline { max-width: 720px; margin: 0 auto; padding: 12px 12px 96px 8px; } /* room at the end to scroll the last row clear of the options button */
.outline ul { margin-left: 21px; padding-left: 10px; border-left: 2px solid hsl(var(--h, 30) var(--br-edge)); }
.outline .row { display: flex; align-items: baseline; flex-wrap: wrap; column-gap: 8px; min-height: 44px; padding: 4px 0; }
.outline .fold { width: 32px; height: 32px; border: 0; background: none; color: hsl(var(--h, 30) var(--br-acc)); cursor: pointer; flex: none; align-self: center; display: grid; place-items: center; border-radius: 8px; }
.outline button.fold:hover { background: var(--surface); }
.outline .fold svg { width: 14px; height: 14px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.row-main { font: inherit; border: 0; background: none; color: var(--ink); padding: 4px 2px; cursor: pointer; text-align: left; font-size: 1.08rem; }
.row-main.sex-F .pname { color: var(--female); }
.row-main:hover .pname { text-decoration: underline; text-underline-offset: 4px; text-decoration-color: var(--line-strong); }
.outline .row.is-me .pname { box-shadow: inset 0 -3px 0 var(--marigold); }
.row-sub, .row-more { font-size: .82rem; color: var(--muted); }
.row-spouse {
  display: inline-flex; align-items: center; gap: 6px; align-self: center;
  font: inherit; font-size: .95rem; color: var(--ink); cursor: pointer;
  padding: 3px 12px 3px 0; min-height: 34px; border-radius: 999px;
  background: var(--surface); border: 1px dashed hsl(var(--h, 30) var(--br-edge));
}
.row-spouse:hover { border-style: solid; }
.row-spouse .wed-mark {
  width: 18px; height: 6px; margin-left: -1px; flex: none;
  border-top: 2px solid hsl(var(--h, 30) var(--br-line)); border-bottom: 2px solid hsl(var(--h, 30) var(--br-line));
}
.row-spouse .sp-role { font-size: .75rem; color: var(--muted); }
.row-spouse.sex-F .pname { color: var(--female); }
.row-spouse.sex-M .pname { color: var(--male); }
.row-spouse.is-me { border: 2px solid var(--marigold); }
.row-more { font-weight: 600; }

/* ---------- tree: chart ---------- */
.canvas { position: relative; flex: 1; overflow: hidden; touch-action: none; cursor: grab; user-select: none; -webkit-user-select: none; background: var(--paper); }
.canvas:active { cursor: grabbing; }
.world { position: absolute; left: 0; top: 0; transform-origin: 0 0; }
.links { position: absolute; left: 0; top: 0; pointer-events: none; }
.links path { fill: none; stroke: hsl(var(--h, 30) var(--br-line)); stroke-width: 2.5; stroke-linecap: round; }
.links path.mine { stroke: var(--marigold); stroke-width: 3.5; }
.links .gen { fill: var(--gen-band); }

.rail {
  position: absolute; left: 0; top: 0; bottom: 0; width: 60px; z-index: 1; pointer-events: none; overflow: hidden;
  background: linear-gradient(to right, var(--paper) 70%, transparent);
}
.rail-label {
  position: absolute; left: 6px; right: 6px; top: 0; margin-top: -11px; text-align: center;
  font-size: .72rem; font-weight: 600; line-height: 22px; color: var(--muted); white-space: nowrap;
  background: var(--surface); border: 1px solid var(--line); border-radius: 999px;
}

/* A node is a card with the person's initial sitting on its top edge; colours come from the branch hue --h. */
.node { position: absolute; width: 148px; height: 112px; --h: 30; }
.node-main {
  position: absolute; left: 0; right: 0; top: 20px; bottom: 0; padding: 24px 8px 6px; cursor: pointer;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  font: inherit; color: var(--ink); text-align: center;
  background: hsl(var(--h) var(--br-tint));
  border: 1px solid hsl(var(--h) var(--br-edge)); border-bottom: 4px solid hsl(var(--h) var(--br-line)); border-radius: 16px;
  box-shadow: 0 1px 2px hsl(var(--h) 40% 30% / .08), 0 6px 18px -8px hsl(var(--h) 50% 30% / .25);
  transition: transform .15s ease, box-shadow .15s ease;
}
.node-main:hover { transform: translateY(-2px); box-shadow: 0 2px 4px hsl(var(--h) 40% 30% / .1), 0 12px 24px -10px hsl(var(--h) 50% 30% / .35); }
.node .av-n {
  position: absolute; left: 50%; top: -20px; transform: translateX(-50%);
  width: 40px; height: 40px; font-size: 1.15rem;
  background: hsl(var(--h) var(--br-chip)); color: hsl(var(--h) var(--br-acc));
  box-shadow: 0 0 0 3px var(--surface), 0 0 0 5px var(--male);
}
.node .av-n.sex-F { box-shadow: 0 0 0 3px var(--surface), 0 0 0 5px var(--female); }
.node .av-n.sex-U, .node .av-n.sex-O { box-shadow: 0 0 0 3px var(--surface), 0 0 0 5px var(--line-strong); }
.node .av-n.late { background: var(--surface); color: var(--muted); }
.node-ord, .node-name, .node-sp, .node-yr { max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; line-height: 1.3; }
.node-ord { font-size: .7rem; font-weight: 600; color: hsl(var(--h) var(--br-acc)); }
.node-name { font-size: 1.05rem; color: hsl(var(--h) 45% 22%); }
:root[data-theme="dark"] .node-name { color: var(--ink); }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) .node-name { color: var(--ink); } }
.node-sp { font-size: .74rem; color: var(--muted); }
.node-yr { font-size: .72rem; color: var(--muted); }
.node.late .node-name { color: var(--muted); }

/* The oldest person drawn is the seed of the chart: a solid card. */
.node.root .node-main { background: hsl(var(--h) var(--br-root)); border-color: transparent; color: var(--on-root); }
.node.root .node-name { color: inherit; }
.node.root .node-ord, .node.root .node-sp, .node.root .node-yr, .node.root.late .node-name { color: inherit; opacity: .85; }
.node.root .av-n { background: var(--surface); }

.node.is-me .node-main { border: 2px solid var(--marigold); box-shadow: 0 0 0 4px hsl(40 85% 55% / .25), 0 8px 20px -8px hsl(40 80% 35% / .45); }
.node.is-me .av-n { box-shadow: 0 0 0 3px var(--surface), 0 0 0 5px var(--marigold); }

.node-fold {
  position: absolute; transform: translate(-50%, -50%); z-index: 1;
  min-width: 28px; height: 24px; padding: 0 7px; border-radius: 12px;
  font: inherit; font-size: .78rem; font-weight: 700; line-height: 1; cursor: pointer;
  background: var(--surface); color: hsl(var(--h) var(--br-acc)); border: 1px solid hsl(var(--h) var(--br-edge));
}
@media (hover: hover) and (pointer: fine) {
  .node-fold[aria-expanded="true"] { opacity: 0; }
  .world:hover .node-fold, .node-fold:focus-visible { opacity: 1; }
}
.node-fold[aria-expanded="false"] { background: hsl(var(--h) var(--br-acc)); border-color: transparent; color: var(--surface); }

/* A husband or wife who married in: a plain card beside the person, joined by the marriage mark. */
.links path.wed { stroke: hsl(var(--h) var(--br-line)); stroke-width: 2; stroke-linecap: butt; }
.node.spouse .node-main {
  background: var(--surface); border: 1px dashed hsl(var(--h) var(--br-edge));
  box-shadow: var(--shadow-1);
}
.node.spouse .node-ord { color: var(--muted); font-weight: 400; }
.node.spouse .node-name { color: var(--ink); }
.node.spouse .av-n { background: var(--female-soft); color: var(--female); }
.node.spouse .av-n.sex-M { background: var(--male-soft); color: var(--male); }
.node.spouse.late .node-name { color: var(--muted); }
.node.spouse .av-n.late { background: var(--surface); color: var(--muted); }
.node.spouse.is-me .node-main { border: 2px solid var(--marigold); }
@media (prefers-reduced-motion: reduce) { .node-main { transition: none; } .node-main:hover { transform: none; } }

.fold-all { display: inline-flex; align-items: center; gap: 5px; }
.fold-all svg { width: 16px; height: 16px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; flex: none; }
.fold-all:disabled { opacity: .4; cursor: default; }

/*
 * All of the chart's controls sit behind one round button in the bottom corner, so the chart keeps the
 * whole screen. The panel opens above the button.
 */
.chart-menu {
  position: absolute; right: 14px; bottom: 16px; z-index: 3;
  display: flex; flex-direction: column; align-items: flex-end; gap: 10px;
}
/* The list scrolls with the page, so its button stays put above the tab bar. */
.mode-list .chart-menu { position: fixed; bottom: calc(var(--tabbar-h) + 16px + env(safe-area-inset-bottom)); }
.cm-toggle {
  width: 52px; height: 52px; padding: 0; border: 0; border-radius: 50%; cursor: pointer;
  display: grid; place-items: center; background: var(--surface); color: var(--ink); box-shadow: var(--shadow-2);
}
.cm-toggle:hover { background: var(--surface-2); }
.cm-toggle[aria-expanded="true"] { background: var(--crimson); color: var(--on-crimson); }
.cm-toggle svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; }
.cm-toggle circle { fill: var(--surface); }
.cm-toggle:hover circle { fill: var(--surface-2); }

.cm-panel {
  width: 264px; max-width: calc(100vw - 28px); max-height: 65vh; overflow: auto; padding: 12px;
  display: grid; gap: 10px; background: var(--surface); border-radius: 18px; box-shadow: var(--shadow-2);
  transform-origin: bottom right; animation: cm-in .14s ease-out;
}
.cm-panel[hidden] { display: none; }
@keyframes cm-in { from { opacity: 0; transform: translateY(6px) scale(.96); } }
@media (prefers-reduced-motion: reduce) { .cm-panel { animation: none; } }
.cm-head { margin: 0 2px; font-size: .85rem; color: var(--muted); }

.cm-seg { display: grid; grid-template-columns: 1fr 1fr; gap: 4px; padding: 4px; background: var(--surface-2); border-radius: 12px; }
.cm-seg button {
  display: flex; flex-direction: column; align-items: center; gap: 4px; padding: 8px 4px; border: 0; border-radius: 9px;
  background: none; color: var(--muted); font: inherit; font-size: .82rem; cursor: pointer;
}
.cm-seg button:hover { color: var(--ink); }
.cm-seg button[aria-pressed="true"] { background: var(--surface); color: var(--crimson); box-shadow: 0 0 0 1px var(--line), var(--shadow-1); }
.cm-seg svg, .cm-zoom svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.cm-seg circle { fill: currentColor; stroke: none; }

.cm-zoom { display: grid; grid-template-columns: repeat(3, 1fr); border: 1px solid var(--line); border-radius: 12px; overflow: hidden; }
.cm-zoom button {
  height: 44px; border: 0; background: none; color: var(--ink); font: inherit; font-size: 1.35rem; cursor: pointer;
  display: grid; place-items: center;
}
.cm-zoom button + button { border-left: 1px solid var(--line); }
.cm-zoom button:hover { background: var(--surface-2); }

.cm-acts { display: grid; gap: 2px; padding-top: 8px; border-top: 1px solid var(--line); }
.cm-acts:empty { display: none; }
.cm-acts .btn { width: 100%; justify-content: flex-start; }
/* An action that would do nothing is left out rather than greyed. */
.cm-acts .fold-all:disabled { display: none; }

/* Sideways: generations run left to right; each card's initial sits on its left edge. */
.dir-right .rail {
  right: 0; bottom: auto; width: auto; height: 40px;
  background: linear-gradient(var(--paper) 70%, transparent);
}
.dir-right .rail-label { left: 0; right: auto; top: 9px; margin: 0 0 0 -46px; width: 92px; }
.dir-right .node { width: 184px; height: 78px; }
.dir-right .node-main {
  top: 0; left: 20px; padding: 6px 12px 6px 30px; align-items: flex-start; text-align: left;
  border-bottom: 1px solid hsl(var(--h) var(--br-edge)); border-right: 4px solid hsl(var(--h) var(--br-line));
}
.dir-right .node.is-me .node-main { border: 2px solid var(--marigold); }
.dir-right .node.root .node-main { border-color: transparent; }
.dir-right .node .av-n { left: -20px; top: 50%; transform: translateY(-50%); }

/* ---------- people ---------- */
.search { position: sticky; top: calc(var(--topbar-h) + var(--band-h) + env(safe-area-inset-top)); z-index: 3; background: var(--paper); padding: 14px 16px 6px; }
.search > * { max-width: 688px; margin-left: auto; margin-right: auto; }
.search-box { display: flex; align-items: center; gap: 8px; padding: 0 12px; background: var(--surface); border: 1px solid var(--line-strong); border-radius: var(--r-m); }
.search-box:focus-within { outline: 2.5px solid var(--marigold); outline-offset: 1px; }
.search-box svg { width: 20px; height: 20px; fill: none; stroke: var(--muted); stroke-width: 1.8; stroke-linecap: round; }
.search-box input { border: 0; outline: 0; background: transparent; padding: 0; min-height: 48px; }
.search p { margin-top: 6px; }
.people { list-style: none; margin: 0 auto; padding: 6px 16px 28px; max-width: 720px; }
.empty { padding: 24px 4px; color: var(--muted); }

.prow {
  width: 100%; font: inherit; color: var(--ink); text-align: left; cursor: pointer;
  display: flex; align-items: center; gap: 12px; padding: 10px 6px; min-height: 60px;
  background: transparent; border: 0; border-bottom: 1px solid var(--line);
}
.prow:hover { background: var(--surface); }
.prow-text { flex: 1; min-width: 0; display: grid; }
.prow-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.prow-name .pname { font-size: 1.08rem; }
.prow-sub { font-size: .82rem; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chev { width: 16px; height: 16px; fill: none; stroke: var(--line-strong); stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }

/* ---------- kul ---------- */
.kul-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 10px; }
.kul-card {
  width: 100%; font: inherit; color: var(--ink); text-align: left; cursor: pointer;
  display: grid; gap: 8px; padding: 14px 16px;
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-m); box-shadow: var(--shadow-1);
}
.kul-card:hover { border-color: var(--line-strong); }
.kul-name { font-size: 1.25rem; }
.kul-facts { margin: 0; display: grid; grid-template-columns: repeat(auto-fill, minmax(130px, 1fr)); gap: 6px 14px; }
.kul-facts dt { font-size: .78rem; color: var(--muted); }
.kul-facts dd { margin: 0; font-weight: 600; }
.kul-count { font-size: .85rem; color: var(--muted); }

/* ---------- forms ---------- */
input, select, textarea {
  font: inherit; color: var(--ink); background: var(--surface);
  border: 1px solid var(--line-strong); border-radius: var(--r-s); padding: 8px 10px; min-height: 46px; width: 100%;
}
input::placeholder, textarea::placeholder { color: var(--muted); opacity: .75; }
textarea { min-height: 84px; resize: vertical; }
input:focus-visible, select:focus-visible, textarea:focus-visible { outline: 2.5px solid var(--marigold); outline-offset: 0; border-color: transparent; }
.form { display: grid; gap: 18px; }
.form > h2 { font-size: 1.4rem; font-family: var(--font-name); font-weight: 400; }
.form-sec { display: grid; gap: 12px; padding-top: 16px; border-top: 1px solid var(--line); }
.form-sec > h3 { font-size: .95rem; color: var(--crimson); }
.field { display: grid; gap: 4px; border: 0; padding: 0; margin: 0; min-width: 0; }
.field > span, .field > legend { font-size: .88rem; color: var(--muted); font-weight: 500; padding: 0; margin-bottom: 2px; }
.two { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.check { display: inline-flex; align-items: center; gap: 8px; min-height: 40px; cursor: pointer; font-size: .92rem; }
.check input { width: 20px; height: 20px; min-height: 0; margin: 0; accent-color: var(--crimson); }
.checks { display: flex; flex-wrap: wrap; gap: 0 16px; }

.pills { display: flex; flex-wrap: wrap; gap: 6px; }
.pills label { position: relative; cursor: pointer; }
.pills input { position: absolute; opacity: 0; inset: 0; margin: 0; min-height: 0; cursor: pointer; }
.pills span {
  display: inline-flex; align-items: center; min-height: 42px; padding: 4px 16px; border-radius: 999px;
  border: 1px solid var(--line-strong); background: var(--surface); font-size: .95rem;
}
.pills input:checked + span { background: var(--ink); border-color: var(--ink); color: var(--paper); font-weight: 600; }
.pills input:focus-visible + span { outline: 2.5px solid var(--marigold); outline-offset: 2px; }

.picks { display: flex; flex-wrap: wrap; gap: 6px; }
.pick { font: inherit; font-size: .9rem; cursor: pointer; min-height: 36px; padding: 2px 12px; border-radius: 999px; border: 1px solid var(--line); background: var(--surface-2); color: var(--ink); }
.pick[aria-pressed="true"] { border-color: var(--ink); background: var(--ink); color: var(--paper); }

.date { gap: 8px; }
.date-row { display: grid; grid-template-columns: 5.4rem 1fr 1.5fr 4.2rem; gap: 6px; }
.date-row2 { display: grid; grid-template-columns: 1fr auto; gap: 10px; align-items: center; }
.more { border-top: 1px solid var(--line); padding-top: 12px; }
.more summary { cursor: pointer; color: var(--crimson); font-weight: 600; min-height: 36px; display: flex; align-items: center; }
.more .field { margin-top: 10px; }

.form-bar {
  position: sticky; bottom: 0; z-index: 2; margin: 0 -18px; padding: 12px 18px calc(12px + env(safe-area-inset-bottom));
  display: flex; justify-content: flex-end; gap: 8px; background: var(--surface); border-top: 1px solid var(--line);
}
.form-bar .btn.primary { min-width: 140px; }

/* ---------- sheet ---------- */
dialog { color: var(--ink); background: var(--surface); border: 0; padding: 0; }
dialog::backdrop { background: rgba(25, 12, 8, .5); }
.sheet {
  width: 100%; max-width: 100%; max-height: 94dvh;
  margin: auto 0 0; border-radius: var(--r-l) var(--r-l) 0 0; overflow-x: hidden; overflow-y: auto; overscroll-behavior: contain;
}
.sheet[open] { animation: sheet-up .22s ease-out; }
@keyframes sheet-up { from { transform: translateY(24px); opacity: .4; } to { transform: none; opacity: 1; } }
@media (min-width: 720px) {
  .sheet { width: min(600px, calc(100vw - 48px)); margin: auto; border-radius: var(--r-l); max-height: 90dvh; }
}
.sheet-head {
  position: sticky; top: 0; z-index: 3; display: flex; align-items: center; justify-content: space-between;
  padding: 6px 8px; min-height: 52px; background: var(--surface); border-bottom: 1px solid var(--line);
}
.grip { width: 40px; height: 4px; border-radius: 2px; background: var(--line-strong); margin-left: calc(50% - 20px - 8px); }
@media (min-width: 720px) { .grip { visibility: hidden; } }
.sheet-body { padding: 18px 18px 0; }
.sheet-body > article { padding-bottom: calc(24px + env(safe-area-inset-bottom)); }

.pc { display: grid; gap: 14px; }
.pc-head { display: flex; gap: 14px; align-items: flex-start; }
.pc-title { display: grid; gap: 2px; min-width: 0; }
.pc-meta { font-size: .88rem; color: var(--muted); }
.pc-head h2 { font-size: 1.9rem; line-height: 1.15; }
.pc.sex-F .pc-head h2 { color: var(--female); }
.pc-life { font-size: .95rem; }
.pc-sec { display: grid; gap: 10px; padding-top: 16px; border-top: 1px solid var(--line); }
.pc-sec > h3 { font-size: 1.05rem; }
.pc-sec.end { justify-items: start; }
.fam-group { display: grid; }
.fam-group + .fam-group { margin-top: 10px; }
.fam-group h4 { margin-bottom: 2px; }
.fam-group .prow { padding: 8px 2px; min-height: 54px; }
.add-row { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 8px; }
.kv { margin: 0; display: grid; }
.kv > div { display: grid; grid-template-columns: 8rem 1fr; gap: 10px; padding: 7px 0; border-bottom: 1px solid var(--line); }
.kv dt { color: var(--muted); font-size: .9rem; }
.kv dd { margin: 0; }
.pc-sec .btn.small { justify-self: start; }

.confirm { width: min(420px, calc(100vw - 32px)); border-radius: var(--r-l); padding: 22px; box-shadow: var(--shadow-2); }
.confirm p { margin: 0 0 18px; font-size: 1.02rem; }

.toast {
  position: fixed; left: 50%; bottom: calc(var(--tabbar-h) + 18px + env(safe-area-inset-bottom)); transform: translateX(-50%);
  z-index: 50; max-width: calc(100vw - 32px); padding: 10px 18px; border-radius: 999px;
  background: var(--ink); color: var(--paper); font-weight: 600; box-shadow: var(--shadow-2);
}
.toast.bad { background: var(--danger); color: #fff; }

/* ---------- settings ---------- */
.panel { background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-m); padding: 16px; display: grid; gap: 12px; }
.panel h3 { margin-top: 8px; }
.panel .prow { border: 0; padding: 4px 0; }
.set-row { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 8px; padding: 6px 0; }
.set-row + .set-row { border-top: 1px solid var(--line); padding-top: 12px; }
.danger-zone { border-color: var(--danger-soft); }
.danger-zone .btn { justify-self: start; }
.about { text-align: center; padding-top: 8px; }

@media (max-width: 420px) {
  .kv > div { grid-template-columns: 6.5rem 1fr; }
  .date-row { grid-template-columns: 4.8rem 1fr 1.3fr 3.6rem; }
  .focus-name, .pc-head h2 { font-size: 1.65rem; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}
