:root {
  --bg: #fbf3e6;
  --paper: #ffffff;
  --ink: #2b1d14;
  --muted: #7d6b5d;
  --line: #c8a27a;
  --accent: #7a1f2b;
  --accent-ink: #ffffff;
  --saffron: #e5862a;
  --gold: #d9a441;
  --leaf: #2f7d4a;
  --male: #3f6fb0;
  --female: #b8336a;
  --neutral: #4f8a6a;
  --top: 60px;
  --shadow: 0 2px 10px rgba(60, 30, 10, .12);
  --radius: 12px;
  font-family: "Hind Vadodara", "Noto Sans Gujarati", "Shruti", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  color: var(--ink);
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { height: 100%; margin: 0; background: var(--bg); overflow: hidden; }
button { font: inherit; cursor: pointer; }
input, select, textarea { font: inherit; color: inherit; }

/* ================= layout: mobile first ================= */
:root { --nav: calc(64px + env(safe-area-inset-bottom)); }

/* ---------- top bar ---------- */
.topbar {
  position: fixed; inset: 0 0 auto 0; z-index: 20; min-height: 54px;
  display: flex; align-items: center; gap: 12px; padding: 6px 12px; padding-top: max(6px, env(safe-area-inset-top));
  background: linear-gradient(180deg, #8c2433 0%, #6e1a26 100%); color: var(--accent-ink);
  border-bottom: 3px solid var(--gold); box-shadow: var(--shadow);
}
/* toran: mango leaves and marigolds hanging below the header */
.topbar::after {
  content: ''; position: absolute; left: 0; right: 0; top: 100%; height: 26px; pointer-events: none;
  background: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='48' height='26'%3E%3Cpath d='M0 1 Q12 5 24 1 Q36 5 48 1' stroke='%23d9a441' stroke-width='2' fill='none'/%3E%3Cpath d='M12 3 C5 10 7 19 12 25 C17 19 19 10 12 3Z' fill='%232f7d4a'/%3E%3Cpath d='M12 6 L12 22' stroke='%231d5631' stroke-width='1'/%3E%3Ccircle cx='36' cy='8' r='5' fill='%23f39c1f'/%3E%3Ccircle cx='36' cy='8' r='2.2' fill='%23d9661a'/%3E%3Ccircle cx='36' cy='15.5' r='3.6' fill='%23f6b73c'/%3E%3Ccircle cx='36' cy='21' r='2.4' fill='%23e0442f'/%3E%3C/svg%3E") repeat-x;
}
.gu { font-family: "Hind Vadodara", "Noto Sans Gujarati", sans-serif; opacity: .85; font-weight: inherit; }
.btn .gu { opacity: .9; }
.brand { display: flex; align-items: center; gap: 8px; min-width: 0; flex: 1; }
.brand .logo { font-size: 26px; }
.brand > div { min-width: 0; }
.brand h1 { font-family: "Rasa", "Hind Vadodara", serif; font-size: 20px; margin: 0; line-height: 1.1; white-space: nowrap; letter-spacing: .01em; }
.brand .h1-gu { display: none; font-family: "Hind Vadodara", sans-serif; font-size: 15px; font-weight: 500; color: #ffd98a; }
.brand .sub { font-size: 12px; opacity: .8; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.actions { display: none; gap: 8px; }

/* search: hidden in the bar on phones, drops down from the Search tab */
.search { display: none; position: fixed; left: 0; right: 0; top: var(--top); z-index: 19; padding: 10px 12px; background: #6e1a26; }
.searching .search { display: block; }
.search input { width: 100%; padding: 11px 14px; border-radius: 999px; border: 0; background: #fff; font-size: 16px; }
.search-results {
  position: absolute; top: 100%; left: 8px; right: 8px; margin: 0; padding: 4px; list-style: none;
  background: var(--paper); color: var(--ink); border-radius: 12px; box-shadow: var(--shadow);
  max-height: calc(100vh - var(--top) - var(--nav) - 80px); overflow: auto;
}
.search-results li { display: flex; align-items: center; gap: 10px; padding: 9px 8px; border-radius: 8px; cursor: pointer; }
.search-results li:hover, .search-results li.active { background: #f3e9dc; }
.search-results img { width: 36px; height: 36px; border-radius: 50%; object-fit: cover; }
.search-results small { color: var(--muted); }

.btn {
  border: 1px solid rgba(0,0,0,.12); background: var(--paper); color: var(--ink);
  padding: 10px 14px; border-radius: 10px; white-space: nowrap; min-height: 42px;
}
.btn:hover { filter: brightness(.97); }
.btn.primary { background: var(--saffron); border-color: transparent; color: #fff; font-weight: 600; }
.btn.danger { color: #b3261e; border-color: #e5b8b3; }
.btn.small { padding: 7px 10px; font-size: 13px; min-height: 38px; }
.btn.wide { width: 100%; margin: 4px 0 6px; white-space: normal; }
.btn:disabled { opacity: .6; cursor: default; }
.read-only .add-only { display: none !important; }

.version-banner {
  position: fixed; top: var(--top); left: 0; right: 0; z-index: 16; display: flex; gap: 8px; align-items: center; flex-wrap: wrap;
  padding: 8px 12px; background: #fff3cd; border-bottom: 1px solid #ecd28b; font-size: 13px;
}
.version-banner span { flex: 1 1 100%; }

/* ---------- bottom navigation (phones) ---------- */
.bottomnav {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 25; height: var(--nav); padding-bottom: env(safe-area-inset-bottom);
  display: grid; grid-template-columns: repeat(5, 1fr); align-items: stretch;
  background: #fffaf2; border-top: 1px solid #ead7bb; box-shadow: 0 -2px 12px rgba(60, 30, 10, .1);
}
.bottomnav button {
  border: 0; background: none; color: var(--muted); font-size: 11px; line-height: 1.1;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 1px; padding: 4px 0;
}
.bottomnav button .i { font-size: 21px; line-height: 1.1; }
.bottomnav button .gu { font-size: 10px; }
.bottomnav button.on { color: var(--accent); font-weight: 700; }
.bottomnav button.on .i { transform: scale(1.1); }
.bottomnav .fab .i {
  width: 54px; height: 54px; margin-top: -22px; border-radius: 50%; display: flex; align-items: center; justify-content: center;
  background: var(--saffron); color: #fff; font-size: 30px; font-weight: 700; box-shadow: 0 4px 12px rgba(229, 134, 42, .5); border: 3px solid #fffaf2;
}

/* ---------- canvas ---------- */
.viewport { position: fixed; top: var(--top); left: 0; right: 0; bottom: var(--nav); overflow: hidden; touch-action: none; cursor: grab;
  background-color: var(--bg);
  /* bandhani-style tie-dye dots */
  background-image:
    radial-gradient(circle, #e7c9a4 1.6px, transparent 2.4px),
    radial-gradient(circle, #efd9bd 1.2px, transparent 2px);
  background-size: 26px 26px, 26px 26px;
  background-position: 0 0, 13px 13px; }
.viewport.dragging { cursor: grabbing; }
.canvas { position: absolute; top: 0; left: 0; transform-origin: 0 0; display: flex; gap: 80px; padding: 40px; align-items: flex-start; }
.viewing-old .canvas { filter: sepia(.25); }

/* breadcrumb + quick glance counts, floating at the top of the tree */
.scopebar { position: absolute; top: 28px; left: 8px; right: 8px; z-index: 3; display: flex; flex-direction: column; gap: 6px; pointer-events: none; }
.scopebar > * { pointer-events: auto; }
.crumbs { display: flex; align-items: center; gap: 2px; overflow-x: auto; white-space: nowrap; scrollbar-width: none; max-width: 100%; align-self: flex-start;
  background: rgba(255, 255, 255, .92); border: 1px solid #ead7bb; border-radius: 999px; padding: 3px; box-shadow: var(--shadow); }
.crumbs::-webkit-scrollbar, .glance::-webkit-scrollbar { display: none; }
.crumbs button { border: 0; background: none; padding: 6px 10px; border-radius: 999px; font-size: 13px; color: var(--muted); white-space: nowrap; }
.crumbs button.on { background: var(--accent); color: #fff; font-weight: 600; }
.crumbs .sep { color: #c7ab88; }
.glance { display: flex; gap: 6px; overflow-x: auto; scrollbar-width: none; cursor: pointer; }
.g-item { flex: none; background: #fff; border: 1px solid #ead7bb; border-radius: 10px; padding: 4px 9px; font-size: 12px; box-shadow: var(--shadow); white-space: nowrap; }
.g-item b { font-size: 15px; color: var(--accent); }
.g-item .gu { display: none; }

.empty { position: absolute; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; color: var(--muted); text-align: center; padding: 20px; }

.zoom { position: absolute; right: 10px; bottom: 12px; display: flex; flex-direction: column; gap: 8px; z-index: 3; }
.zoom button { width: 44px; height: 44px; border-radius: 50%; border: 1px solid #ead7bb; background: var(--paper); box-shadow: var(--shadow); font-size: 20px; }

/* ---------- tree connectors ---------- */
.tree ul { position: relative; display: flex; justify-content: center; padding: 26px 0 0; margin: 0; }
.tree > ul { padding-top: 0; }
.tree li { position: relative; list-style: none; padding: 26px 8px 0; display: flex; flex-direction: column; align-items: center; }
.tree > ul > li { padding-top: 0; }
.tree li::before, .tree li::after {
  content: ''; position: absolute; top: 0; right: 50%; width: 50%; height: 26px; border-top: 2px solid var(--line);
}
.tree li::after { right: auto; left: 50%; border-left: 2px solid var(--line); }
.tree li:only-child::before, .tree li:only-child::after { display: none; }
.tree li:only-child { padding-top: 0; }
.tree li:first-child::before, .tree li:last-child::after { border: 0 none; }
.tree li:last-child::before { border-right: 2px solid var(--line); border-radius: 0 8px 0 0; }
.tree li:first-child::after { border-radius: 8px 0 0 0; }
.tree ul ul::before { content: ''; position: absolute; top: 0; left: 50%; height: 26px; border-left: 2px solid var(--line); }
.tree > ul > li:only-child::before, .tree > ul > li:only-child::after { display: none; }

/* ---------- family unit & cards ---------- */
.unit {
  position: relative; display: flex; align-items: center; gap: 4px; padding: 6px;
  background: rgba(255, 250, 240, .75); border: 1px solid #e6cfa8; border-radius: 16px;
}
.unit .heart { color: #d0587a; font-size: 13px; }
.card {
  width: 112px; padding: 8px 6px 7px; background: var(--paper); border-radius: var(--radius);
  box-shadow: var(--shadow); text-align: center; cursor: pointer; border: 1px solid #efdcc0; border-top: 4px solid var(--neutral);
  transition: transform .12s, box-shadow .12s; user-select: none;
}
.card:hover { transform: translateY(-2px); box-shadow: 0 6px 16px rgba(60,30,10,.18); }
.card.male { border-top-color: var(--male); }
.card.female { border-top-color: var(--female); }
.card.selected { outline: 3px solid var(--saffron); outline-offset: 2px; }
.card.flash { animation: flash 1.2s ease-out 2; }
@keyframes flash { 50% { outline: 5px solid var(--saffron); outline-offset: 4px; } }
.card img { width: 72px; height: 72px; border-radius: 50%; object-fit: cover; display: block; margin: 0 auto 5px; background: #eee; }
.card.deceased img { box-shadow: 0 0 0 3px #f2a93b, 0 0 0 5px #fbe3b0; filter: saturate(.75); }
.card .nm { font-size: 13px; font-weight: 600; line-height: 1.2; word-break: break-word; }
.card .nm-gu { font-size: 13px; color: #8c2433; line-height: 1.25; margin-top: 1px; }
.card .yr { font-size: 11px; color: var(--muted); margin-top: 2px; }
.card.inlaw { width: 100px; }
.card.inlaw img { width: 60px; height: 60px; }
.card.link { opacity: .85; border-style: dashed; }
.card .tag { display: inline-block; font-size: 10px; color: var(--muted); background: #f3e9dc; border-radius: 6px; padding: 0 5px; margin-top: 3px; }

.toggle {
  position: absolute; left: 50%; bottom: -12px; transform: translateX(-50%); z-index: 2;
  min-width: 24px; height: 22px; padding: 0 6px; border-radius: 11px; border: 1px solid var(--line);
  background: var(--paper); color: var(--muted); font-size: 12px; line-height: 20px;
}
.collapsed-note { font-size: 11px; color: var(--muted); margin-top: 16px; }

/* ---------- sheets (bottom sheet on phones, side panel on desktop) ---------- */
.panel {
  position: fixed; left: 0; right: 0; bottom: var(--nav); z-index: 22; max-height: min(78%, calc(100% - var(--top) - var(--nav) - 20px));
  background: var(--paper); border-radius: 20px 20px 0 0; box-shadow: 0 -6px 24px rgba(0,0,0,.18);
  overflow: auto; overscroll-behavior: contain; padding: 22px 16px 20px; animation: up .18s ease-out;
}
.panel::before { content: ''; position: absolute; top: 8px; left: 50%; width: 40px; height: 4px; margin-left: -20px; border-radius: 2px; background: #e2d2bd; }
#panel { max-height: 56%; }
.panel.families, .panel.history { max-height: calc(100% - var(--top) - var(--nav) - 10px); height: calc(100% - var(--top) - var(--nav) - 10px); }
@keyframes up { from { transform: translateY(30px); opacity: .5; } }
.panel .close { position: absolute; right: 8px; top: 10px; width: 40px; height: 40px; border: 0; background: none; font-size: 26px; color: var(--muted); z-index: 2; }
.panel h2 { margin: 6px 40px 2px 0; font-size: 20px; }
.panel .hero { text-align: center; }
.panel .hero img { width: 112px; height: 112px; border-radius: 50%; object-fit: cover; box-shadow: var(--shadow); }
.panel .meta { color: var(--muted); font-size: 14px; }
.panel .hero-gu { font-size: 18px; color: #8c2433; font-weight: 600; margin-bottom: 2px; }
.panel .notes { white-space: pre-wrap; background: #faf4ec; border-radius: 10px; padding: 10px; font-size: 14px; }
.panel h3 { font-size: 13px; letter-spacing: .03em; color: var(--muted); margin: 16px 0 6px; }
.panel .hero h2 { margin-right: 0; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip { display: inline-flex; align-items: center; gap: 6px; padding: 4px 12px 4px 4px; border-radius: 999px; background: #f3e9dc; border: 0; font-size: 14px; min-height: 36px; }
.chip img { width: 28px; height: 28px; border-radius: 50%; object-fit: cover; }
.chip .x { margin-left: 2px; color: var(--muted); }
.quick { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; }
.quick .btn { white-space: normal; line-height: 1.25; }
.row { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 12px; }
.row .btn { flex: 1 1 auto; white-space: normal; }
.mini-stats { display: flex; flex-wrap: wrap; gap: 6px; }
.mini-stats .g-item { box-shadow: none; }

/* families screen */
.crumbs.in-panel { box-shadow: none; margin: 6px 0 10px; background: #faf4ec; }
.stats { display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; margin-bottom: 10px; }
.stat { background: #fbf3e6; border: 1px solid #ecd9bb; border-radius: 12px; padding: 8px 4px; text-align: center; }
.stat .v { font-size: 22px; font-weight: 700; color: var(--accent); line-height: 1.1; }
.stat .l { font-size: 11px; color: var(--muted); line-height: 1.25; }
.fam-list { display: flex; flex-direction: column; gap: 8px; }
.fam-row {
  display: flex; align-items: center; gap: 10px; width: 100%; text-align: left; padding: 10px; border-radius: 14px;
  background: #fff; border: 1px solid #ead7bb; box-shadow: var(--shadow); color: var(--ink);
}
.fam-row:active { background: #fdf3e4; }
.fam-faces { display: flex; flex: none; }
.fam-faces img { width: 40px; height: 40px; border-radius: 50%; object-fit: cover; border: 2px solid #fff; background: #eee; }
.fam-faces img + img { margin-left: -14px; }
.fam-faces.big img { width: 56px; height: 56px; }
.fam-main { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.fam-name { font-weight: 600; font-size: 15px; line-height: 1.25; }
.fam-gu { color: #8c2433; font-size: 14px; }
.fam-meta { color: var(--muted); font-size: 12px; margin-top: 2px; }
.fam-count { flex: none; display: flex; flex-direction: column; align-items: center; background: #fbf3e6; border-radius: 10px; padding: 4px 8px; min-width: 44px; }
.fam-count b { font-size: 18px; color: var(--accent); line-height: 1.1; }
.chev { color: #c7ab88; font-size: 22px; }
.fam-head { display: flex; align-items: center; gap: 12px; margin: 6px 0 4px; }
.fam-head .fam-name { font-size: 17px; }

.history .item { border-bottom: 1px solid #eee1d2; padding: 10px 0; font-size: 14px; }
.history .item .who { font-weight: 600; }
.history .item .when { color: var(--muted); font-size: 12px; }
.history .item .what { margin: 3px 0; }
.history .item .note { font-style: italic; color: var(--muted); }
.history .current { color: #2e7d32; font-size: 12px; font-weight: 600; }

/* ---------- modal ---------- */
.modal { position: fixed; inset: 0; z-index: 40; background: rgba(30, 15, 5, .45); display: flex; align-items: center; justify-content: center; padding: 16px; }
.modal-card { background: var(--paper); border-top: 5px solid var(--gold); border-radius: 16px; width: 100%; max-width: 520px; max-height: calc(100vh - 32px); overflow: auto; padding: 20px; box-shadow: 0 10px 40px rgba(0,0,0,.25); }
.modal-card h2 { margin: 0 0 4px; }
.modal-card .hint { color: var(--muted); font-size: 14px; margin: 0 0 14px; }
.field { display: flex; flex-direction: column; gap: 4px; margin-bottom: 12px; font-size: 14px; }
.field > span { font-weight: 600; }
.field input, .field select, .field textarea { padding: 9px 10px; border: 1px solid #d9c9b6; border-radius: 9px; background: #fff; width: 100%; }
.field textarea { min-height: 70px; resize: vertical; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.check { display: flex; align-items: center; gap: 8px; font-size: 14px; margin-bottom: 12px; }
.photo-edit { display: flex; align-items: center; gap: 14px; margin-bottom: 12px; }
.photo-edit img { width: 84px; height: 84px; border-radius: 50%; object-fit: cover; box-shadow: var(--shadow); }
.photo-edit .btns { display: flex; flex-direction: column; gap: 6px; }
.error { color: #b3261e; font-size: 14px; min-height: 1em; margin: 4px 0 8px; }
.modal-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 8px; }
.seg { display: flex; border: 1px solid #d9c9b6; border-radius: 9px; overflow: hidden; }
.seg label { flex: 1; text-align: center; padding: 8px 4px; cursor: pointer; font-size: 14px; line-height: 1.2; }
.seg input { display: none; }
.seg label:has(input:checked) { background: var(--saffron); color: #fff; font-weight: 600; }

.toast { position: fixed; left: 50%; bottom: calc(var(--nav) + 14px); transform: translateX(-50%); z-index: 50; background: #2b1d14; color: #fff; padding: 10px 16px; border-radius: 10px; box-shadow: var(--shadow); font-size: 14px; width: max-content; max-width: calc(100vw - 32px); }

/* modal: full-width sheet on phones */
.modal { align-items: flex-end; padding: 0; }
.modal-card { border-radius: 18px 18px 0 0; max-height: 94vh; padding: 18px 16px calc(18px + env(safe-area-inset-bottom)); }
.modal-actions { position: sticky; bottom: -18px; background: var(--paper); padding: 10px 0 4px; }
.modal-actions .btn { flex: 1; }
.grid2 { grid-template-columns: 1fr; }
.field input, .field select, .field textarea { font-size: 16px; } /* stops iOS zoom on focus */

/* ================= tablets & desktop ================= */
@media (min-width: 760px) {
  :root { --nav: 0px; }
  .bottomnav { display: none; }
  .topbar { padding: 6px 14px; min-height: 60px; }
  .brand { flex: 0 1 auto; }
  .brand .h1-gu { display: inline; }
  .brand .sub { max-width: 34vw; }
  .actions { display: flex; }
  .search { display: block; position: relative; top: auto; left: auto; right: auto; flex: 1; max-width: 420px; margin-left: auto; padding: 0; background: none; z-index: auto; }
  .search input { padding: 8px 14px; font-size: 15px; }
  .search-results { left: 0; right: 0; top: 44px; max-height: 60vh; }
  .version-banner span { flex: 1; min-width: 200px; }
  .zoom { left: 14px; right: auto; bottom: 14px; }
  .scopebar { left: 14px; right: 14px; flex-direction: row; align-items: center; flex-wrap: wrap; }
  .g-item .gu { display: inline; }
  .panel, #panel, .panel.families, .panel.history {
    left: auto; right: 0; top: var(--top); bottom: 0; width: 380px; height: auto; max-height: none;
    border-radius: 0; box-shadow: -4px 0 20px rgba(0,0,0,.12); padding-top: 34px; animation: none;
  }
  .panel::before { display: none; }
  .panel .close { top: 26px; }
  .panel .hero img { width: 140px; height: 140px; }
  .modal { align-items: center; padding: 16px; }
  .modal-card { border-radius: 16px; max-height: calc(100vh - 32px); padding: 20px; }
  .modal-actions { position: static; }
  .modal-actions .btn { flex: none; }
  .grid2 { grid-template-columns: 1fr 1fr; }
  .toast { bottom: 24px; }
}
