/* Family Tree Keeper styles */
:root { color-scheme: light; padding-top: env(safe-area-inset-top, 0px); padding-bottom: env(safe-area-inset-bottom, 0px); }
html, body { margin: 0; }
img { max-width: 100%; }
/* Layout: an app shell. Sticky top bar, then one working view: family shelf, member register + record, or the tree canvas. */
:root {
  --bg: #f3f6f3;
  --surface: #ffffff;
  --surface-2: #e9efea;
  --canvas: #f8faf8;
  --dot: #d9e2db;
  --ink: #17211d;
  --muted: #5a6962;
  --line: #d3dcd5;
  --tree-line: #8c9c94;
  --accent: #2c6a4e;
  --accent-ink: #ffffff;
  --accent-soft: #dbeae1;
  --male: #3c6a9e;
  --female: #a24e6d;
  --other: #85733a;
  --danger: #b3261e;
  --danger-soft: #f8e1df;
  --warn-soft: #f6ecd2;
  --shadow: 0 1px 2px rgba(23, 33, 29, .06), 0 6px 20px rgba(23, 33, 29, .06);
  --font-display: "Bricolage Grotesque", "Inter", "Noto Sans Telugu", "Noto Sans Devanagari", system-ui, sans-serif;
  --font-body: "Inter", "Noto Sans Telugu", "Noto Sans Devanagari", system-ui, -apple-system, "Segoe UI", sans-serif;
  --radius: 12px;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0e1412; --surface: #161e1b; --surface-2: #1d2824; --canvas: #121a17; --dot: #24302b;
    --ink: #e3ebe6; --muted: #94a59c; --line: #2c3934; --tree-line: #6a7c73;
    --accent: #72c198; --accent-ink: #0b1a12; --accent-soft: #1d3a2b;
    --male: #8aaedb; --female: #dc8eab; --other: #cdb878;
    --danger: #f2786d; --danger-soft: #3a1d1b; --warn-soft: #36301c;
    --shadow: 0 1px 2px rgba(0,0,0,.3), 0 6px 20px rgba(0,0,0,.25);
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #0e1412; --surface: #161e1b; --surface-2: #1d2824; --canvas: #121a17; --dot: #24302b;
  --ink: #e3ebe6; --muted: #94a59c; --line: #2c3934; --tree-line: #6a7c73;
  --accent: #72c198; --accent-ink: #0b1a12; --accent-soft: #1d3a2b;
  --male: #8aaedb; --female: #dc8eab; --other: #cdb878;
  --danger: #f2786d; --danger-soft: #3a1d1b; --warn-soft: #36301c;
  --shadow: 0 1px 2px rgba(0,0,0,.3), 0 6px 20px rgba(0,0,0,.25);
  color-scheme: dark;
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { min-height: 100%; }
body { background: var(--bg); color: var(--ink); font-family: var(--font-body); font-size: 14px; line-height: 1.5; }
body::before { content: ""; position: fixed; inset: 0 0 auto; height: env(safe-area-inset-top, 0px); z-index: 30; background: var(--surface); }
h1, h2, h3 { font-family: var(--font-display); font-weight: 700; line-height: 1.15; text-wrap: balance; margin: 0; letter-spacing: -0.01em; }
h1 { font-size: 1.85rem; }
h2 { font-size: 1.25rem; }
h3 { font-size: 1.02rem; }
p { margin: 0; }
button, input, select, textarea { font: inherit; color: inherit; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.muted { color: var(--muted); }
.small { font-size: 12.5px; }
.label { font-size: 11px; text-transform: uppercase; letter-spacing: .08em; font-weight: 600; color: var(--muted); }

/* top bar */
.topbar { position: sticky; top: env(safe-area-inset-top, 0px); z-index: 20; background: var(--surface); border-bottom: 1px solid var(--line); }
.topbar-in { max-width: 1320px; margin: 0 auto; padding-left: max(16px, env(safe-area-inset-left, 0px)); padding-right: max(16px, env(safe-area-inset-right, 0px)); padding-block: 10px; display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
.brand { display: flex; align-items: center; gap: 9px; font-family: var(--font-display); font-weight: 700; font-size: 1.08rem; color: var(--ink); text-decoration: none; background: none; border: 0; padding: 0; cursor: pointer; }
.brand svg { width: 26px; height: 26px; color: var(--accent); flex: none; }
.crumbs { display: flex; align-items: center; gap: 6px; min-width: 0; flex: 1; color: var(--muted); }
.crumbs a { color: var(--ink); text-decoration: none; font-weight: 500; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.crumbs a:hover { text-decoration: underline; }
.top-actions { display: flex; align-items: center; gap: 8px; margin-left: auto; }
.sync { display: inline-flex; align-items: center; gap: 6px; font-size: 12px; color: var(--muted); white-space: nowrap; }
.sync i { width: 8px; height: 8px; border-radius: 50%; background: var(--accent); display: inline-block; }
.sync.busy i { background: var(--other); }
.sync.local i { background: var(--other); }
.sync.err i { background: var(--danger); }

.wrap { max-width: 1320px; margin: 0 auto; padding-left: max(16px, env(safe-area-inset-left, 0px)); padding-right: max(16px, env(safe-area-inset-right, 0px)); padding-block: 24px 48px; }
.banner { border-radius: 10px; padding: 10px 14px; background: var(--warn-soft); color: var(--ink); font-size: 13px; margin-bottom: 18px; display: flex; gap: 10px; align-items: flex-start; }
.banner[hidden] { display: none !important; }

/* buttons */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 7px; padding: 8px 14px; border-radius: 9px; border: 1px solid var(--line); background: var(--surface); color: var(--ink); font-weight: 500; cursor: pointer; white-space: nowrap; min-height: 36px; text-decoration: none; }
.btn:hover { background: var(--surface-2); }
.btn:disabled { opacity: .45; cursor: default; }
.btn-primary { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
.btn-primary:hover { background: var(--accent); filter: brightness(1.06); }
.btn-ghost { background: transparent; border-color: transparent; }
.btn-ghost:hover { background: var(--surface-2); }
.btn-danger { color: var(--danger); }
.btn-danger-solid { background: var(--danger); border-color: var(--danger); color: #fff; }
.btn-sm { padding: 5px 10px; min-height: 30px; font-size: 13px; border-radius: 8px; }
.btn svg { width: 16px; height: 16px; flex: none; }
.icon-btn { width: 34px; height: 34px; padding: 0; }
.row { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }

/* forms */
.field { display: grid; gap: 5px; }
.field > span { font-size: 12.5px; font-weight: 600; color: var(--muted); }
.input, select.input, textarea.input { width: 100%; padding: 8px 11px; border-radius: 9px; border: 1px solid var(--line); background: var(--surface); min-height: 38px; }
textarea.input { min-height: 76px; resize: vertical; }
.input:focus { outline: 2px solid var(--accent); outline-offset: -1px; border-color: transparent; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.form { display: grid; gap: 14px; }
.seg { display: inline-flex; border: 1px solid var(--line); border-radius: 9px; overflow: hidden; }
.seg label { position: relative; }
.seg input { position: absolute; opacity: 0; pointer-events: none; }
.seg span { display: block; padding: 7px 14px; cursor: pointer; font-weight: 500; border-right: 1px solid var(--line); }
.seg label:last-child span { border-right: 0; }
.seg input:checked + span { background: var(--accent-soft); color: var(--ink); }
.seg input:focus-visible + span { outline: 2px solid var(--accent); outline-offset: -2px; }
.check { display: inline-flex; gap: 8px; align-items: center; cursor: pointer; }
.check input { width: 16px; height: 16px; accent-color: var(--accent); }
details.more { border-top: 1px dashed var(--line); padding-top: 10px; }
details.more summary { cursor: pointer; font-weight: 600; color: var(--accent); list-style: none; }
details.more summary::-webkit-details-marker { display: none; }
details.more[open] summary { margin-bottom: 12px; }
.hint { font-size: 12.5px; color: var(--muted); }
.err-text { color: var(--danger); font-size: 13px; }
.photo-pick { display: flex; align-items: center; gap: 12px; }

/* avatars */
.av { width: 40px; height: 40px; border-radius: 50%; display: grid; place-items: center; font-weight: 600; font-size: 13px; flex: none; background: var(--surface-2); color: var(--ink); overflow: hidden; border: 2px solid var(--line); }
.av img { width: 100%; height: 100%; object-fit: cover; }
.av.male { border-color: var(--male); }
.av.female { border-color: var(--female); }
.av.other { border-color: var(--other); }
.av.lg { width: 72px; height: 72px; font-size: 22px; border-width: 3px; }
.av.sm { width: 26px; height: 26px; font-size: 10.5px; border-width: 1.5px; }

/* home */
.page-head { display: flex; justify-content: space-between; align-items: flex-end; gap: 16px; flex-wrap: wrap; margin-bottom: 20px; }
.page-head .sub { margin-top: 6px; }
.fam-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(270px, 1fr)); gap: 16px; }
.fam-card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 18px; display: grid; gap: 14px; align-content: start; box-shadow: var(--shadow); }
.fam-card .top { display: flex; gap: 12px; align-items: flex-start; }
.fam-card .mono { width: 44px; height: 44px; border-radius: 10px; background: var(--accent-soft); color: var(--accent); display: grid; place-items: center; font-family: var(--font-display); font-weight: 700; font-size: 1.2rem; flex: none; }
.fam-card h2 { font-size: 1.15rem; overflow-wrap: anywhere; }
.stats { display: flex; gap: 18px; font-variant-numeric: tabular-nums; }
.stats b { display: block; font-family: var(--font-display); font-size: 1.35rem; line-height: 1.1; }
.stats span { font-size: 12px; color: var(--muted); }
.fam-card .row { margin-top: 2px; }
.new-card { border: 1.5px dashed var(--line); border-radius: var(--radius); display: grid; place-items: center; gap: 8px; padding: 26px; background: transparent; cursor: pointer; color: var(--muted); min-height: 180px; text-align: center; }
.new-card:hover { border-color: var(--accent); color: var(--accent); }
.new-card b { font-size: 1rem; color: var(--ink); }
.section { margin-top: 40px; display: grid; gap: 14px; }
.panel { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 18px; }
.empty { text-align: center; padding: 56px 20px; display: grid; gap: 14px; justify-items: center; }
.empty .sprig { width: 84px; height: 84px; color: var(--accent); }
.sprig { width: 84px; height: 84px; color: var(--accent); flex: none; }
.new-card svg { width: 28px; height: 28px; }
.empty p { max-width: 46ch; }

/* family editor */
.split { display: grid; grid-template-columns: minmax(280px, 360px) minmax(0, 1fr); gap: 20px; align-items: start; }
.register { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; position: sticky; top: calc(env(safe-area-inset-top, 0px) + 72px); max-height: calc(100dvh - 100px); display: flex; flex-direction: column; }
.register-head { padding: 12px; display: grid; gap: 10px; border-bottom: 1px solid var(--line); }
.register-list { overflow-y: auto; padding: 6px; }
.gen-head { font-size: 11px; text-transform: uppercase; letter-spacing: .08em; font-weight: 600; color: var(--muted); padding: 12px 10px 4px; display: flex; justify-content: space-between; }
.member { display: flex; gap: 10px; align-items: center; width: 100%; padding: 7px 10px; border-radius: 9px; border: 0; background: transparent; cursor: pointer; text-align: left; }
.member:hover { background: var(--surface-2); }
.member.on { background: var(--accent-soft); }
.member .nm { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.member .yr { font-size: 12px; color: var(--muted); font-variant-numeric: tabular-nums; }
.member > div { min-width: 0; }
.record { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 22px; display: grid; gap: 22px; min-width: 0; }
.rec-head { display: flex; gap: 16px; align-items: center; flex-wrap: wrap; }
.rec-head .who { flex: 1; min-width: 200px; }
.rec-head h2 { font-size: 1.55rem; overflow-wrap: anywhere; }
.tag { display: inline-flex; align-items: center; gap: 5px; font-size: 12px; padding: 2px 9px; border-radius: 99px; background: var(--surface-2); color: var(--muted); font-weight: 500; }
.tag.warn { background: var(--warn-soft); color: var(--ink); }
.facts { display: grid; grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); gap: 14px 20px; }
.facts div { display: grid; gap: 2px; min-width: 0; }
.facts b { font-weight: 500; overflow-wrap: anywhere; }
.notes { white-space: pre-wrap; overflow-wrap: anywhere; }
.rels { display: grid; grid-template-columns: repeat(auto-fill, minmax(250px, 1fr)); gap: 14px; }
.rel-box { border: 1px solid var(--line); border-radius: 10px; padding: 12px; display: grid; gap: 8px; align-content: start; }
.rel-box header { display: flex; justify-content: space-between; align-items: center; gap: 8px; }
.chip { display: flex; align-items: center; gap: 8px; padding: 4px 4px 4px 6px; border-radius: 9px; background: var(--surface-2); min-width: 0; }
.chip button.go { flex: 1; min-width: 0; background: none; border: 0; padding: 0; display: flex; align-items: center; gap: 8px; cursor: pointer; text-align: left; }
.chip .nm { font-weight: 500; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chip .yr { font-size: 12px; color: var(--muted); white-space: nowrap; font-variant-numeric: tabular-nums; }
.chip .x { width: 26px; height: 26px; border-radius: 7px; border: 0; background: transparent; color: var(--muted); cursor: pointer; display: grid; place-items: center; flex: none; }
.chip .x:hover { background: var(--danger-soft); color: var(--danger); }
.none { font-size: 13px; color: var(--muted); }

/* tree */
.tree-tools { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; margin-bottom: 12px; }
.tree-tools .grow { flex: 1; }
.tree-tools select.input { width: auto; max-width: 240px; }
.tree-tools .search { width: 200px; }
.stage { position: relative; height: max(440px, calc(100dvh - 210px)); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; background-color: var(--canvas); background-image: radial-gradient(var(--dot) 1px, transparent 1.2px); background-size: 22px 22px; touch-action: none; cursor: grab; user-select: none; -webkit-user-select: none; }
.stage.dragging { cursor: grabbing; }
.stage svg { display: block; width: 100%; height: 100%; }
.stage .node { cursor: pointer; }
.zoom { position: absolute; right: 12px; bottom: 12px; display: grid; gap: 6px; }
.zoom .btn { width: 38px; height: 38px; padding: 0; box-shadow: var(--shadow); }
.legend { position: absolute; left: 12px; bottom: 12px; display: flex; gap: 12px; flex-wrap: wrap; background: var(--surface); border: 1px solid var(--line); border-radius: 9px; padding: 6px 10px; font-size: 12px; color: var(--muted); max-width: calc(100% - 80px); }
.legend i { display: inline-block; width: 10px; height: 10px; border-radius: 50%; margin-right: 5px; vertical-align: -1px; border: 2px solid; }
.pop { position: absolute; z-index: 5; width: 270px; max-width: calc(100% - 24px); background: var(--surface); border: 1px solid var(--line); border-radius: 12px; box-shadow: var(--shadow); padding: 14px; display: grid; gap: 10px; cursor: default; }
.pop .hd { display: flex; gap: 10px; align-items: center; }
.pop .hd b { display: block; font-size: 15px; overflow-wrap: anywhere; }

/* modal */
.overlay { position: fixed; inset: 0; z-index: 50; background: rgba(10, 16, 13, .45); display: grid; place-items: center; padding: max(16px, env(safe-area-inset-top, 0px)) max(16px, env(safe-area-inset-right, 0px)) max(16px, env(safe-area-inset-bottom, 0px)) max(16px, env(safe-area-inset-left, 0px)); }
.modal { background: var(--surface); color: var(--ink); border-radius: 16px; width: min(560px, 100%); max-height: calc(100dvh - 32px); display: flex; flex-direction: column; box-shadow: 0 20px 60px rgba(0,0,0,.25); }
.modal.wide { width: min(680px, 100%); }
.modal-head { padding: 18px 20px 12px; display: flex; justify-content: space-between; gap: 12px; align-items: flex-start; }
.modal-body { padding: 4px 20px 16px; overflow-y: auto; display: grid; gap: 14px; }
.modal-foot { padding: 14px 20px; border-top: 1px solid var(--line); display: flex; justify-content: flex-end; gap: 8px; flex-wrap: wrap; }
.tabs { display: flex; gap: 4px; background: var(--surface-2); padding: 4px; border-radius: 10px; }
.tabs button { flex: 1; border: 0; background: transparent; padding: 7px 10px; border-radius: 7px; cursor: pointer; font-weight: 500; color: var(--muted); }
.tabs button.on { background: var(--surface); color: var(--ink); box-shadow: var(--shadow); }
.pick-list { display: grid; gap: 4px; max-height: 300px; overflow-y: auto; border: 1px solid var(--line); border-radius: 10px; padding: 4px; }
.pick { display: flex; align-items: center; gap: 10px; padding: 7px 9px; border: 0; border-radius: 8px; background: transparent; cursor: pointer; text-align: left; width: 100%; }
.pick:hover { background: var(--surface-2); }
.pick.on { background: var(--accent-soft); }
.pick > div { min-width: 0; }
.pick .nm { font-weight: 600; }
.pick .yr { font-size: 12px; color: var(--muted); }
.choice { display: grid; gap: 8px; }
.choice label { display: flex; gap: 10px; align-items: flex-start; padding: 10px 12px; border: 1px solid var(--line); border-radius: 10px; cursor: pointer; }
.choice input { margin-top: 3px; accent-color: var(--accent); }
.choice label:has(input:checked) { border-color: var(--accent); background: var(--accent-soft); }
.plan { font-variant-numeric: tabular-nums; padding: 12px 14px; border-radius: 10px; background: var(--surface-2); font-size: 13px; }
.progress { height: 6px; border-radius: 6px; background: var(--surface-2); overflow: hidden; }
.progress i { display: block; height: 100%; width: 0; background: var(--accent); transition: width .2s; }

/* read-only viewers */
.ro #undoBtn, .ro .rel-box header .btn, .ro .chip .x, .ro .rec-head .row .btn:not(.keep), .ro .new-card, .ro .ed { display: none !important; }
/* form steps */
.steps { list-style: none; padding: 0; margin: 0; display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 14px; }
.steps li { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; display: grid; gap: 6px; align-content: start; }
.steps .n { width: 28px; height: 28px; border-radius: 50%; background: var(--accent-soft); color: var(--accent); display: grid; place-items: center; font-weight: 700; font-family: var(--font-display); }
.mono { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: 12px; }
.match { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 10px; align-items: center; padding: 10px; border: 1px solid var(--line); border-radius: 10px; }
.match .who { display: flex; gap: 10px; align-items: center; min-width: 0; }
.match .who > div { min-width: 0; }
.match-list { display: grid; gap: 8px; max-height: 340px; overflow-y: auto; }
@media (max-width: 560px) { .match { grid-template-columns: minmax(0, 1fr); } }
/* toast */
.toasts { position: fixed; z-index: 60; left: 50%; transform: translateX(-50%); bottom: calc(18px + env(safe-area-inset-bottom, 0px)); display: grid; gap: 8px; width: min(460px, calc(100% - 32px)); }
.toast { background: var(--ink); color: var(--bg); border-radius: 10px; padding: 10px 12px 10px 14px; display: flex; gap: 12px; align-items: center; box-shadow: 0 10px 30px rgba(0,0,0,.2); font-size: 13.5px; }
.toast.error { background: var(--danger); color: #fff; }
.toast span { flex: 1; min-width: 0; overflow-wrap: anywhere; }
.toast button { background: transparent; border: 1px solid currentColor; color: inherit; border-radius: 7px; padding: 4px 10px; cursor: pointer; font-weight: 600; }

@media (max-width: 860px) {
  .split { grid-template-columns: minmax(0, 1fr); }
  .register { position: static; max-height: 380px; }
  h1 { font-size: 1.5rem; }
}
@media (max-width: 520px) {
  .grid2 { grid-template-columns: 1fr; }
  .tree-tools .search { width: 100%; }
  .tree-tools select.input { max-width: 100%; flex: 1; }
  .sync span { display: none; }
  .record { padding: 16px; }
  .stage { height: max(420px, calc(100dvh - 300px)); }
}
@media (prefers-reduced-motion: reduce) { * { transition: none !important; animation: none !important; } }
