:root {
  --bg: #f5efe3;
  --bg-raised: #fffaf0;
  --bg-sunk: #ece3d1;
  --ink: #1d2620;
  --ink-soft: #4f5a52;
  --line: #d6c9ae;
  --green: #1f4d3a;
  --green-soft: #dfe9df;
  --gold: #a87622;
  --gold-soft: #f3e4c4;
  --danger: #a33a2c;
  --focus: #c98a1b;
  --shadow: 0 1px 2px rgb(40 30 10 / 0.06), 0 6px 20px rgb(40 30 10 / 0.08);
  --radius: 10px;
  --serif: "Fraunces", Georgia, "Times New Roman", serif;
  --sans: "Source Sans 3", system-ui, -apple-system, "Segoe UI", sans-serif;
  --urdu: "Noto Nastaliq Urdu", "Jameel Noori Nastaleeq", serif;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #141a16;
    --bg-raised: #1c241f;
    --bg-sunk: #101511;
    --ink: #ece6d8;
    --ink-soft: #a9b1a8;
    --line: #34413a;
    --green: #8fc4a6;
    --green-soft: #20352a;
    --gold: #e0b45e;
    --gold-soft: #3a3020;
    --danger: #f08a7a;
    --focus: #e0b45e;
    --shadow: 0 1px 2px rgb(0 0 0 / 0.3), 0 6px 20px rgb(0 0 0 / 0.35);
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #141a16;
  --bg-raised: #1c241f;
  --bg-sunk: #101511;
  --ink: #ece6d8;
  --ink-soft: #a9b1a8;
  --line: #34413a;
  --green: #8fc4a6;
  --green-soft: #20352a;
  --gold: #e0b45e;
  --gold-soft: #3a3020;
  --danger: #f08a7a;
  --focus: #e0b45e;
  --shadow: 0 1px 2px rgb(0 0 0 / 0.3), 0 6px 20px rgb(0 0 0 / 0.35);
  color-scheme: dark;
}

*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; scroll-behavior: smooth; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 17px/1.6 var(--sans);
}
h1, h2, h3 { font-family: var(--serif); font-weight: 600; line-height: 1.15; margin: 0; }
a { color: var(--green); text-underline-offset: 3px; }
:focus-visible { outline: 3px solid var(--focus); outline-offset: 2px; border-radius: 4px; }
[hidden] { display: none !important; }
.ur { font-family: var(--urdu); line-height: 2; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

.wrap { width: min(1120px, 100% - 32px); margin-inline: auto; }

/* ---------- header / hero ---------- */
.site-header {
  border-bottom: 1px solid var(--line);
  background: var(--bg);
  position: sticky; top: 0; z-index: 1000;
}
.site-header .wrap { display: flex; align-items: center; justify-content: space-between; gap: 16px; min-height: 60px; }
.brand { font-family: var(--serif); font-size: 1.15rem; font-weight: 600; color: var(--ink); text-decoration: none; }
.site-nav { display: flex; gap: 20px; font-size: 0.95rem; }
.site-nav a { color: var(--ink-soft); text-decoration: none; }
.site-nav a:hover { color: var(--ink); }

.hero { padding: 72px 0 56px; border-bottom: 1px solid var(--line); }
.eyebrow {
  font-size: 0.8rem; letter-spacing: 0.14em; text-transform: uppercase;
  color: var(--gold); font-weight: 600; margin: 0 0 18px;
}
.hero h1 { font-size: clamp(2.6rem, 7vw, 4.6rem); letter-spacing: -0.02em; }
.hero .ur-title { font-size: clamp(1.4rem, 3.4vw, 2rem); color: var(--ink-soft); margin: 8px 0 0; }
.lede { max-width: 66ch; }
.hero .lede { font-size: 1.15rem; color: var(--ink-soft); margin: 24px 0 0; }
.facts { display: flex; flex-wrap: wrap; gap: 12px 40px; margin: 36px 0 0; padding: 0; list-style: none; }
.facts li { display: flex; flex-direction: column; }
.facts strong { font-family: var(--serif); font-size: 2rem; font-weight: 600; color: var(--green); line-height: 1.1; }
.facts span { font-size: 0.85rem; color: var(--ink-soft); }

section.block { padding: 64px 0; border-bottom: 1px solid var(--line); }
.block-head { display: flex; flex-wrap: wrap; align-items: end; justify-content: space-between; gap: 16px; margin-bottom: 28px; }
.block-head h2 { font-size: clamp(1.8rem, 4vw, 2.4rem); }
.block-head p { margin: 6px 0 0; color: var(--ink-soft); max-width: 60ch; }

/* ---------- buttons & inputs ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  font: 600 0.92rem/1 var(--sans);
  padding: 10px 14px; min-height: 40px;
  border-radius: 8px; border: 1px solid var(--line);
  background: var(--bg-raised); color: var(--ink);
  cursor: pointer; text-decoration: none;
}
.btn:hover { border-color: var(--ink-soft); }
.btn.primary { background: var(--green); border-color: var(--green); color: var(--bg); }
.btn.primary:hover { filter: brightness(1.08); }
.btn.danger { color: var(--danger); }
.btn.small { min-height: 32px; padding: 6px 10px; font-size: 0.85rem; }
.btn:disabled { opacity: 0.55; cursor: not-allowed; }

input, select, textarea {
  font: inherit; color: var(--ink);
  background: var(--bg-raised);
  border: 1px solid var(--line); border-radius: 8px;
  padding: 9px 12px; width: 100%;
}
textarea { resize: vertical; min-height: 90px; }
label { font-weight: 600; font-size: 0.9rem; display: block; margin-bottom: 6px; }

/* ---------- tree toolbar ---------- */
.toolbar { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.toolbar input[type="search"] { width: 220px; max-width: 100%; }

/* ---------- family tree (desktop: top-down chart) ---------- */
.tree-scroll {
  overflow-x: auto;
  background: var(--bg-sunk);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 28px 16px 36px;
}
.tree ul { list-style: none; margin: 0; padding: 0; }
.tree > ul { width: max-content; min-width: 100%; }

.node { display: inline-flex; flex-direction: column; align-items: center; gap: 6px; }
.card {
  display: block; text-align: center;
  min-width: 128px; max-width: 200px;
  padding: 10px 14px;
  background: var(--bg-raised);
  border: 1px solid var(--line);
  border-top: 4px solid var(--green);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  font: inherit; color: inherit; cursor: pointer;
}
.card[data-gender="F"] { border-top-color: var(--gold); }
.card:hover { border-color: var(--ink-soft); border-top-color: inherit; }
.card[data-gender="M"]:hover { border-top-color: var(--green); }
.card[data-gender="F"]:hover { border-top-color: var(--gold); }
.card .name { display: block; font-family: var(--serif); font-weight: 600; font-size: 1.05rem; line-height: 1.25; }
.card .ur { display: block; font-size: 0.95rem; color: var(--ink-soft); }
.card .meta { display: block; font-size: 0.82rem; color: var(--ink-soft); margin-top: 2px; }
.card .spouse { display: block; font-size: 0.82rem; color: var(--ink-soft); margin-top: 4px; font-style: italic; }
.card.match { outline: 3px solid var(--focus); outline-offset: 3px; }

.toggle {
  font: 600 0.75rem/1 var(--sans); color: var(--ink-soft);
  background: var(--bg); border: 1px solid var(--line); border-radius: 999px;
  padding: 5px 10px; cursor: pointer;
}
.toggle:hover { color: var(--ink); border-color: var(--ink-soft); }
.toggle .chev { display: inline-block; transition: transform 0.15s; }
.toggle[aria-expanded="false"] .chev { transform: rotate(-90deg); }

@media (min-width: 761px) {
  .tree ul ul { display: flex; justify-content: center; padding-top: 22px; position: relative; }
  .tree > ul { display: flex; justify-content: center; }
  .tree li { position: relative; display: flex; flex-direction: column; align-items: center; padding: 22px 6px 0; }
  .tree > ul > li { padding-top: 0; }
  /* vertical stub from parent down to the sibling bar */
  .tree ul ul::before {
    content: ""; position: absolute; top: 0; left: 50%;
    border-left: 2px solid var(--line); height: 22px;
  }
  /* horizontal sibling bar, drawn as two halves on each child */
  .tree ul ul > li::before, .tree ul ul > li::after {
    content: ""; position: absolute; top: 0; width: 50%; height: 22px;
    border-top: 2px solid var(--line);
  }
  .tree ul ul > li::before { right: 50%; }
  .tree ul ul > li::after { left: 50%; border-left: 2px solid var(--line); }
  .tree ul ul > li:first-child::before, .tree ul ul > li:last-child::after { border-top: 0; }
  .tree ul ul > li:last-child::before { border-right: 2px solid var(--line); border-top-right-radius: 8px; right: 50%; width: 50%; }
  .tree ul ul > li:last-child::after { border-left: 0; }
  .tree ul ul > li:first-child::after { border-top-left-radius: 8px; }
  .tree ul ul > li:only-child::before { display: none; }
  .tree ul ul > li:only-child::after { border-top: 0; border-radius: 0; }
}

/* ---------- family tree (mobile: indented outline) ---------- */
@media (max-width: 760px) {
  .tree-scroll { padding: 16px 12px; }
  .tree > ul { width: auto; }
  .tree ul ul { margin-left: 14px; padding-left: 14px; border-left: 2px solid var(--line); }
  .tree li { padding-top: 12px; position: relative; }
  .tree ul ul > li::before {
    content: ""; position: absolute; left: -14px; top: 34px; width: 12px;
    border-top: 2px solid var(--line);
  }
  .node { flex-direction: row; align-items: center; gap: 8px; }
  .card { text-align: left; min-width: 0; max-width: none; flex: 1; border-top: 1px solid var(--line); border-left: 4px solid var(--green); }
  .card[data-gender="F"] { border-left-color: var(--gold); }
  .card[data-gender="M"]:hover, .card[data-gender="F"]:hover { border-top-color: var(--ink-soft); }
  .toggle { flex: none; }
}

.legend { display: flex; gap: 18px; margin-top: 12px; font-size: 0.85rem; color: var(--ink-soft); }
.legend span::before { content: ""; display: inline-block; width: 12px; height: 4px; margin-right: 6px; vertical-align: middle; border-radius: 2px; }
.legend .m::before { background: var(--green); }
.legend .f::before { background: var(--gold); }

/* ---------- person dialog ---------- */
dialog.person {
  border: 1px solid var(--line); border-radius: 14px;
  background: var(--bg-raised); color: var(--ink);
  width: min(460px, 100% - 32px); padding: 28px;
  box-shadow: var(--shadow);
}
dialog.person::backdrop { background: rgb(20 20 15 / 0.45); }
dialog.person h3 { font-size: 1.6rem; }
dialog.person dl { display: grid; grid-template-columns: auto 1fr; gap: 6px 16px; margin: 18px 0 0; }
dialog.person dt { color: var(--ink-soft); font-size: 0.9rem; }
dialog.person dd { margin: 0; }
dialog.person .notes { white-space: pre-wrap; margin: 16px 0 0; padding-top: 16px; border-top: 1px solid var(--line); }
dialog.person .close { margin-top: 22px; }

/* ---------- map ---------- */
.place { display: grid; grid-template-columns: minmax(0, 1fr) 320px; gap: 24px; align-items: stretch; }
.map {
  min-height: 440px; border-radius: var(--radius); border: 1px solid var(--line);
  background: var(--bg-sunk); z-index: 0;
}
.place-card {
  background: var(--bg-raised); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 22px; display: flex; flex-direction: column; gap: 14px;
}
.place-card address { font-style: normal; }
.place-card .ur { font-size: 1.15rem; }
.coords { font: 0.9rem/1.5 ui-monospace, "SF Mono", Menlo, monospace; color: var(--ink-soft); }
.place-card .actions { display: flex; flex-direction: column; gap: 8px; margin-top: auto; }
@media (max-width: 860px) {
  .place { grid-template-columns: 1fr; }
  .map { min-height: 340px; }
}
.pin {
  width: 34px; height: 34px; border-radius: 50% 50% 50% 0; transform: rotate(-45deg);
  background: var(--green); border: 3px solid var(--bg-raised);
  box-shadow: 0 3px 10px rgb(0 0 0 / 0.35);
}
.leaflet-container { font: 0.9rem/1.4 var(--sans); }

footer.site-footer { padding: 32px 0 48px; color: var(--ink-soft); font-size: 0.9rem; }
footer.site-footer .wrap { display: flex; flex-wrap: wrap; justify-content: space-between; gap: 12px; }

.status { min-height: 1.5em; font-size: 0.92rem; }
.status.error { color: var(--danger); }
.status.ok { color: var(--green); }

/* ---------- admin ---------- */
.admin-main { padding: 40px 0 64px; }
.panel {
  background: var(--bg-raised); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 24px; box-shadow: var(--shadow);
}
.panel h2 { font-size: 1.5rem; margin-bottom: 16px; }
.login-panel { max-width: 400px; margin: 48px auto; }
.login-panel form { display: grid; gap: 14px; }
.admin-grid { display: grid; grid-template-columns: minmax(0, 1.3fr) minmax(0, 1fr); gap: 24px; align-items: start; }
@media (max-width: 900px) { .admin-grid { grid-template-columns: 1fr; } }
.member-list { list-style: none; margin: 0; padding: 0; }
.member-list li {
  display: flex; align-items: center; gap: 10px; justify-content: space-between;
  padding: 10px 0; border-bottom: 1px solid var(--line);
}
.member-list li:last-child { border-bottom: 0; }
.member-list .who { min-width: 0; padding-left: calc(var(--depth, 0) * 18px); border-left: 0; }
.member-list .who strong { font-weight: 600; }
.member-list .who small { display: block; color: var(--ink-soft); font-size: 0.82rem; }
.member-list .who .dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; background: var(--green); margin-right: 8px; }
.member-list .who .dot.f { background: var(--gold); }
.member-list .row-actions { display: flex; gap: 6px; flex: none; }
.member-list li.editing { background: var(--green-soft); margin-inline: -12px; padding-inline: 12px; border-radius: 8px; }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.form-grid .full { grid-column: 1 / -1; }
@media (max-width: 520px) { .form-grid { grid-template-columns: 1fr; } }
.radio-row { display: flex; gap: 18px; padding-top: 6px; }
.radio-row label { font-weight: 400; display: inline-flex; align-items: center; gap: 6px; margin: 0; }
.radio-row input { width: auto; }
.form-actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 18px; }
.admin-map { height: 320px; border-radius: var(--radius); border: 1px solid var(--line); margin-bottom: 14px; z-index: 0; }
.hint { color: var(--ink-soft); font-size: 0.88rem; margin: 0 0 14px; }
.location-panel { margin-top: 24px; }
.sticky { position: sticky; top: 84px; }
@media (max-width: 900px) { .sticky { position: static; } }
fieldset.plain { border: 0; padding: 0; margin: 0; min-width: 0; }
.legend-label { font-weight: 600; font-size: 0.9rem; padding: 0; }
@media (max-width: 600px) {
  .site-nav a { display: none; }
  .toolbar { width: 100%; }
  .toolbar input[type="search"] { flex: 1 1 100%; width: auto; }
  .toolbar .btn { flex: 1; }
}
