/* ===== Fonts (self-hosted so exports keep Arabic glyphs) ===== */
@font-face { font-family: "Plex Arabic"; font-weight: 400; font-display: swap; src: url(fonts/ibm-plex-sans-arabic-arabic-400-normal.woff2) format("woff2"); unicode-range: U+0600-06FF, U+0750-077F, U+08A0-08FF, U+FB50-FDFF, U+FE70-FEFF, U+200C-200E; }
@font-face { font-family: "Plex Arabic"; font-weight: 600; font-display: swap; src: url(fonts/ibm-plex-sans-arabic-arabic-600-normal.woff2) format("woff2"); unicode-range: U+0600-06FF, U+0750-077F, U+08A0-08FF, U+FB50-FDFF, U+FE70-FEFF, U+200C-200E; }
@font-face { font-family: "Plex Arabic"; font-weight: 400; font-display: swap; src: url(fonts/ibm-plex-sans-arabic-latin-400-normal.woff2) format("woff2"); unicode-range: U+0000-00FF, U+2000-206F; }
@font-face { font-family: "Plex Arabic"; font-weight: 600; font-display: swap; src: url(fonts/ibm-plex-sans-arabic-latin-600-normal.woff2) format("woff2"); unicode-range: U+0000-00FF, U+2000-206F; }
@font-face { font-family: "Amiri"; font-weight: 400; font-display: swap; src: url(fonts/amiri-arabic-400-normal.woff2) format("woff2"); }
@font-face { font-family: "Amiri"; font-weight: 700; font-display: swap; src: url(fonts/amiri-arabic-700-normal.woff2) format("woff2"); }

/* ===== Tokens ===== */
:root {
  --bg: #f6f2ea;
  --bg-2: #efe8db;
  --surface: #fffdf8;
  --surface-2: #f8f3ea;
  --glass: rgba(255, 252, 245, .78);
  --ink: #1d2a26;
  --ink-2: #4b5a55;
  --muted: #7c8681;
  --line: #e3dacb;
  --line-2: #d4c8b4;
  --brand: #0f5c4d;
  --brand-2: #157a66;
  --brand-ink: #ffffff;
  --gold: #b0852f;
  --gold-soft: #f1e3c2;
  --male: #1f6b8f;
  --male-soft: #e2eff5;
  --female: #a24a6b;
  --female-soft: #f7e6ec;
  --danger: #b3261e;
  --danger-soft: #fbe9e7;
  --ok: #1e7a46;
  --shadow-sm: 0 1px 2px rgba(40, 32, 18, .06), 0 1px 1px rgba(40, 32, 18, .04);
  --shadow: 0 10px 30px -12px rgba(40, 32, 18, .22), 0 2px 6px rgba(40, 32, 18, .06);
  --shadow-lg: 0 30px 60px -20px rgba(20, 30, 25, .35);
  --radius: 18px;
  --radius-sm: 12px;
  --ease: cubic-bezier(.2, .8, .2, 1);
  --font: "Plex Arabic", "Segoe UI", Tahoma, system-ui, sans-serif;
  --display: "Amiri", "Plex Arabic", serif;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0d1513; --bg-2: #111c19; --surface: #15211e; --surface-2: #1a2824; --glass: rgba(16, 26, 23, .78);
    --ink: #ece6da; --ink-2: #b9b4a8; --muted: #8b918c; --line: #25352f; --line-2: #33463f;
    --brand: #3fb495; --brand-2: #5cc7a9; --brand-ink: #06231c; --gold: #d8b26a; --gold-soft: #3a3020;
    --male: #6fb3d6; --male-soft: #16303b; --female: #e08aac; --female-soft: #3a1f2b;
    --danger: #ff8a80; --danger-soft: #3b1c1a; --ok: #6fd39c;
    --shadow-sm: 0 1px 2px rgba(0, 0, 0, .4); --shadow: 0 12px 30px -12px rgba(0, 0, 0, .6); --shadow-lg: 0 30px 60px -20px rgba(0, 0, 0, .7);
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #0d1513; --bg-2: #111c19; --surface: #15211e; --surface-2: #1a2824; --glass: rgba(16, 26, 23, .78);
  --ink: #ece6da; --ink-2: #b9b4a8; --muted: #8b918c; --line: #25352f; --line-2: #33463f;
  --brand: #3fb495; --brand-2: #5cc7a9; --brand-ink: #06231c; --gold: #d8b26a; --gold-soft: #3a3020;
  --male: #6fb3d6; --male-soft: #16303b; --female: #e08aac; --female-soft: #3a1f2b;
  --danger: #ff8a80; --danger-soft: #3b1c1a; --ok: #6fd39c;
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, .4); --shadow: 0 12px 30px -12px rgba(0, 0, 0, .6); --shadow-lg: 0 30px 60px -20px rgba(0, 0, 0, .7);
  color-scheme: dark;
}

/* ===== Base ===== */
*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; scroll-behavior: smooth; }
body {
  margin: 0; font-family: var(--font); color: var(--ink); background: var(--bg);
  font-size: 16px; line-height: 1.6; min-height: 100dvh; overflow-x: hidden;
  transition: background-color .4s var(--ease), color .4s var(--ease);
}
body::before { /* subtle heritage pattern */
  content: ""; position: fixed; inset: 0; z-index: -1; pointer-events: none; opacity: .5;
  background:
    radial-gradient(1200px 600px at 100% -10%, color-mix(in srgb, var(--gold) 14%, transparent), transparent 60%),
    radial-gradient(900px 500px at -10% 110%, color-mix(in srgb, var(--brand) 12%, transparent), transparent 60%);
}
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
a { color: var(--brand); text-decoration: none; }
:focus-visible { outline: 2px solid var(--gold); outline-offset: 2px; border-radius: 8px; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
[hidden] { display: none !important; }
.ico { width: 20px; height: 20px; flex: none; stroke: currentColor; fill: none; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }

/* ===== Buttons & chips ===== */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px; min-height: 42px; padding: 0 16px;
  border-radius: 999px; border: 1px solid var(--line); background: var(--surface); color: var(--ink);
  box-shadow: var(--shadow-sm); transition: transform .2s var(--ease), background .2s, border-color .2s, box-shadow .2s; white-space: nowrap;
}
.btn:hover { border-color: var(--line-2); box-shadow: var(--shadow); }
.btn:active { transform: scale(.97); }
.btn.primary { background: var(--brand); border-color: var(--brand); color: var(--brand-ink); }
.btn.primary:hover { background: var(--brand-2); }
.btn.danger { background: var(--danger); border-color: var(--danger); color: #fff; }
.btn.ghost { background: transparent; box-shadow: none; border-color: transparent; }
.btn.ghost:hover { background: var(--surface-2); }
.btn.icon { width: 42px; padding: 0; }
.btn.sm { min-height: 34px; padding: 0 12px; font-size: 14px; }
.btn.sm.icon { width: 34px; }
.btn[disabled] { opacity: .45; pointer-events: none; }
.chip {
  display: inline-flex; align-items: center; gap: 6px; padding: 4px 12px; border-radius: 999px; font-size: 14px;
  background: var(--surface-2); border: 1px solid var(--line); color: var(--ink-2); transition: all .2s var(--ease);
}
button.chip:hover, a.chip:hover { border-color: var(--brand); color: var(--brand); }
.chip.on { background: var(--brand); color: var(--brand-ink); border-color: var(--brand); }
.badge { display: inline-flex; align-items: center; padding: 1px 8px; border-radius: 999px; font-size: 12px; background: var(--gold-soft); color: var(--gold); font-weight: 600; }
.badge.warn { background: var(--danger-soft); color: var(--danger); }

/* ===== Welcome ===== */
.welcome {
  min-height: 100dvh; display: grid; place-items: center; padding: 32px 16px; position: relative; overflow: hidden;
}
.welcome-card {
  position: relative; width: min(760px, 100%); text-align: center; padding: clamp(28px, 6vw, 64px) clamp(20px, 5vw, 56px);
  background: var(--glass); backdrop-filter: blur(14px); -webkit-backdrop-filter: blur(14px);
  border: 1px solid var(--line); border-radius: 28px; box-shadow: var(--shadow-lg);
  animation: rise 1s var(--ease) both;
}
.welcome-card::before, .welcome-card::after {
  content: ""; position: absolute; inset: 10px; border: 1px solid color-mix(in srgb, var(--gold) 45%, transparent); border-radius: 20px; pointer-events: none;
}
.welcome-card::after { inset: 14px; opacity: .45; }
.crest { width: 84px; height: 84px; margin: 0 auto 8px; color: var(--gold); animation: grow 1.4s var(--ease) both .2s; }
.basmala { font-family: var(--display); font-size: clamp(26px, 5vw, 38px); color: var(--gold); margin: 0 0 6px; font-weight: 700; }
.welcome h1 { font-family: var(--display); font-weight: 700; font-size: clamp(34px, 7vw, 56px); line-height: 1.25; margin: 4px 0 18px; color: var(--brand); }
.welcome .text p { margin: 0 0 14px; color: var(--ink-2); font-size: clamp(15px, 2.2vw, 17px); line-height: 2; text-align: justify; text-align-last: center; }
.welcome .text p:nth-child(1) { animation: fade .8s var(--ease) both .45s; }
.welcome .text p:nth-child(2) { animation: fade .8s var(--ease) both .6s; }
.welcome .text p:nth-child(3) { animation: fade .8s var(--ease) both .75s; }
.welcome .sign { font-family: var(--display); font-size: 20px; color: var(--ink); margin: 18px 0 26px !important; text-align: center !important; }
.enter-btn {
  font-size: 18px; min-height: 54px; padding: 0 34px; gap: 12px; animation: fade .8s var(--ease) both 1s;
  background: linear-gradient(135deg, var(--brand), var(--brand-2)); color: var(--brand-ink); border: 0; box-shadow: 0 14px 30px -12px color-mix(in srgb, var(--brand) 70%, transparent);
}
.enter-btn:hover { transform: translateY(-2px); }
.enter-btn .ico { transition: transform .3s var(--ease); }
.enter-btn:hover .ico { transform: translateX(-4px); }
.welcome-stats { display: flex; justify-content: center; flex-wrap: wrap; gap: 10px 22px; margin-top: 24px; color: var(--muted); font-size: 14px; animation: fade .8s var(--ease) both 1.2s; }
.welcome-stats b { color: var(--ink); font-size: 18px; margin-inline-end: 4px; }
.welcome .theme-float { position: absolute; top: 16px; inset-inline-start: 16px; }

/* ===== App shell ===== */
.topbar {
  position: sticky; top: 0; z-index: 40; display: flex; align-items: center; gap: 10px; padding: 10px 16px;
  background: var(--glass); backdrop-filter: blur(16px) saturate(1.2); -webkit-backdrop-filter: blur(16px) saturate(1.2);
  border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: center; gap: 10px; color: var(--ink); font-family: var(--display); font-size: 22px; font-weight: 700; white-space: nowrap; }
.brand svg { width: 30px; height: 30px; color: var(--gold); }
.brand span { display: none; }
@media (min-width: 720px) { .brand span { display: inline; } }
.search { position: relative; flex: 1; max-width: 520px; margin-inline-start: auto; }
.search input {
  width: 100%; height: 42px; border-radius: 999px; border: 1px solid var(--line); background: var(--surface); padding: 0 42px 0 14px;
  box-shadow: var(--shadow-sm); transition: border-color .2s, box-shadow .2s; outline: none;
}
.search input:focus { border-color: var(--brand); box-shadow: 0 0 0 4px color-mix(in srgb, var(--brand) 15%, transparent); }
.search > .ico { position: absolute; top: 11px; right: 14px; color: var(--muted); }
.results {
  position: absolute; top: calc(100% + 8px); inset-inline: 0; max-height: min(60vh, 460px); overflow: auto; z-index: 60;
  background: var(--surface); border: 1px solid var(--line); border-radius: 16px; box-shadow: var(--shadow-lg); padding: 6px;
  animation: pop .18s var(--ease) both;
}
.results button { display: flex; align-items: center; gap: 10px; width: 100%; text-align: start; border: 0; background: none; padding: 8px 10px; border-radius: 10px; }
.results button.active, .results button:hover { background: var(--surface-2); }
.results .r-name { font-weight: 600; }
.results .r-sub { display: block; font-size: 13px; color: var(--muted); }
.results .empty { padding: 14px; color: var(--muted); text-align: center; }
mark { background: var(--gold-soft); color: inherit; border-radius: 4px; padding: 0 2px; }

.tabs {
  position: sticky; top: 62px; z-index: 30; display: flex; gap: 6px; padding: 8px 16px; overflow-x: auto; scrollbar-width: none;
  background: color-mix(in srgb, var(--bg) 85%, transparent); backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--line);
}
.tabs::-webkit-scrollbar { display: none; }
.tab { display: inline-flex; align-items: center; gap: 6px; padding: 7px 14px; border-radius: 999px; color: var(--ink-2); white-space: nowrap; border: 1px solid transparent; transition: all .25s var(--ease); font-size: 15px; }
.tab:hover { background: var(--surface); color: var(--ink); }
.tab.on { background: var(--ink); color: var(--bg); }
.tab .ico { width: 18px; height: 18px; }

main { padding: 18px 16px 80px; max-width: 1200px; margin: 0 auto; }
.view { animation: viewIn .45s var(--ease) both; }
.view-head { display: flex; flex-wrap: wrap; align-items: center; gap: 10px; margin-bottom: 16px; }
.view-head h2 { font-family: var(--display); font-size: 28px; margin: 0; margin-inline-end: auto; }
.toolbar { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }

/* ===== Person page ===== */
.crumbs { display: flex; flex-wrap: wrap; align-items: center; gap: 4px; margin: 4px 0 16px; font-size: 14px; }
.crumbs a { color: var(--ink-2); padding: 3px 9px; border-radius: 999px; background: var(--surface); border: 1px solid var(--line); transition: all .2s; }
.crumbs a:hover { color: var(--brand); border-color: var(--brand); }
.crumbs .sep { color: var(--muted); font-size: 12px; }
.crumbs .here { font-weight: 600; color: var(--ink); padding: 3px 9px; }
.hero {
  position: relative; overflow: hidden; border-radius: 26px; padding: clamp(22px, 5vw, 40px); margin-bottom: 18px;
  background: linear-gradient(140deg, var(--surface), var(--surface-2)); border: 1px solid var(--line); box-shadow: var(--shadow);
}
.hero::after { content: ""; position: absolute; inset-inline-end: -60px; top: -60px; width: 240px; height: 240px; border-radius: 50%; background: radial-gradient(circle, color-mix(in srgb, var(--gold) 20%, transparent), transparent 70%); }
.hero-top { display: flex; align-items: center; gap: 14px; flex-wrap: wrap; }
.avatar { width: 64px; height: 64px; border-radius: 50%; display: grid; place-items: center; font-family: var(--display); font-weight: 700; font-size: 30px; flex: none; }
.avatar.m { background: var(--male-soft); color: var(--male); }
.avatar.f { background: var(--female-soft); color: var(--female); }
.avatar.sm { width: 40px; height: 40px; font-size: 19px; }
.avatar.xs { width: 32px; height: 32px; font-size: 16px; }
.hero h1 { font-family: var(--display); font-size: clamp(34px, 8vw, 56px); line-height: 1.2; margin: 0; }
.hero .lineage { margin: 10px 0 0; color: var(--ink-2); font-size: 16px; line-height: 1.9; position: relative; z-index: 1; }
.hero .meta { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 14px; position: relative; z-index: 1; }
.back-row { display: flex; gap: 8px; align-items: center; margin-bottom: 8px; }
.grid2 { display: grid; gap: 16px; }
@media (min-width: 900px) { .grid2 { grid-template-columns: 1fr 340px; align-items: start; } }
.section { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 18px; box-shadow: var(--shadow-sm); margin-bottom: 16px; }
.section h3 { margin: 0 0 12px; font-size: 17px; display: flex; align-items: center; gap: 8px; color: var(--ink-2); font-weight: 600; }
.section h3 .count { margin-inline-start: auto; }
.spouses { display: flex; flex-direction: column; gap: 8px; }
.spouse { display: flex; align-items: center; gap: 10px; padding: 10px 12px; border-radius: 14px; background: var(--surface-2); border: 1px solid var(--line); }
a.spouse:hover { border-color: var(--brand); }
.spouse .s-name { font-weight: 600; color: var(--ink); }
.spouse .s-note { font-size: 13px; color: var(--muted); }
.kids { display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 10px; }
.kid {
  position: relative; display: flex; flex-direction: column; align-items: center; gap: 6px; padding: 16px 10px 12px; text-align: center;
  border-radius: 16px; background: var(--surface-2); border: 1px solid var(--line); color: var(--ink); transition: transform .25s var(--ease), box-shadow .25s, border-color .25s;
  animation: cardIn .5s var(--ease) both; animation-delay: calc(var(--i, 0) * 35ms);
}
.kid:hover { transform: translateY(-3px); box-shadow: var(--shadow); border-color: var(--line-2); }
.kid .k-name { font-weight: 600; font-size: 17px; }
.kid .k-sub { font-size: 12px; color: var(--muted); }
.kid .k-n { position: absolute; top: 8px; inset-inline-start: 8px; }
.kv { display: grid; grid-template-columns: auto 1fr; gap: 8px 14px; font-size: 15px; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; }
.mini-list { display: flex; flex-wrap: wrap; gap: 6px; }
.note { padding: 12px 14px; border-radius: 12px; background: var(--gold-soft); color: var(--ink); font-size: 14px; }
.empty-note { color: var(--muted); font-size: 15px; }

/* ===== Cards view ===== */
.filters { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 14px; }
.gen-head { position: sticky; top: 118px; z-index: 5; display: flex; align-items: center; gap: 10px; margin: 22px 0 10px; padding: 6px 0; background: color-mix(in srgb, var(--bg) 92%, transparent); backdrop-filter: blur(6px); }
.gen-head h3 { margin: 0; font-family: var(--display); font-size: 22px; }
.gen-head::after { content: ""; flex: 1; height: 1px; background: linear-gradient(to left, var(--line-2), transparent); }
.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(min(100%, 230px), 1fr)); gap: 12px; }
.card {
  display: flex; gap: 12px; align-items: center; text-align: start; padding: 12px 14px; border-radius: 16px; background: var(--surface);
  border: 1px solid var(--line); box-shadow: var(--shadow-sm); transition: transform .25s var(--ease), box-shadow .25s, border-color .25s; width: 100%;
  content-visibility: auto; contain-intrinsic-size: 74px;
}
.card:hover { transform: translateY(-2px); box-shadow: var(--shadow); border-color: var(--line-2); }
.card .c-body { min-width: 0; flex: 1; }
.card .c-name { font-weight: 600; font-size: 16px; }
.card .c-sub { font-size: 13px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.card .c-n { font-size: 12px; color: var(--ink-2); }

/* ===== Outline (list) ===== */
.outline { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 10px 6px; box-shadow: var(--shadow-sm); overflow-x: auto; }
.outline ul { list-style: none; margin: 0; padding: 0; }
.outline ul ul { margin-inline-start: 22px; padding-inline-start: 10px; border-inline-start: 1.5px solid var(--line); }
.o-row { display: flex; align-items: center; gap: 6px; padding: 3px 4px; border-radius: 10px; min-height: 38px; }
.o-row:hover { background: var(--surface-2); }
.o-tg { width: 28px; height: 28px; border-radius: 8px; border: 0; background: none; display: grid; place-items: center; color: var(--muted); flex: none; transition: transform .25s var(--ease); }
.o-tg.open { transform: rotate(-90deg); }
.o-tg.leaf { visibility: hidden; }
.o-name { border: 0; background: none; padding: 2px 6px; border-radius: 8px; font-weight: 600; white-space: nowrap; }
.o-name:hover { color: var(--brand); }
.o-dot { width: 8px; height: 8px; border-radius: 50%; flex: none; }
.o-dot.m { background: var(--male); } .o-dot.f { background: var(--female); }
.o-sp { font-size: 13px; color: var(--muted); white-space: nowrap; }
.o-kids { overflow: hidden; }
.o-kids.anim { animation: slideDown .3s var(--ease) both; }
.flash { animation: flash 1.6s var(--ease); }

/* ===== Tree diagram ===== */
.tree-wrap {
  position: relative; height: calc(100dvh - 190px); min-height: 420px; border-radius: 22px; overflow: hidden; border: 1px solid var(--line);
  background: radial-gradient(circle at 50% 0%, var(--surface), var(--bg-2)); box-shadow: var(--shadow); touch-action: none;
}
.tree-wrap svg { width: 100%; height: 100%; display: block; cursor: grab; user-select: none; -webkit-user-select: none; }
.tree-wrap svg:active { cursor: grabbing; }
.tree-ctrl { position: absolute; bottom: 14px; inset-inline-end: 14px; display: flex; flex-direction: column; gap: 6px; z-index: 2; }
.tree-ctrl .btn { background: var(--glass); backdrop-filter: blur(8px); }
.tree-hint { position: absolute; bottom: 14px; inset-inline-start: 14px; font-size: 12px; color: var(--muted); background: var(--glass); padding: 4px 10px; border-radius: 999px; }
.node rect.box { fill: var(--surface); stroke: var(--line-2); stroke-width: 1; transition: stroke .2s, fill .2s; }
.node.m rect.box { fill: var(--male-soft); stroke: color-mix(in srgb, var(--male) 40%, transparent); }
.node.f rect.box { fill: var(--female-soft); stroke: color-mix(in srgb, var(--female) 40%, transparent); }
.node.root rect.box { fill: var(--brand); stroke: var(--gold); stroke-width: 2; }
.node.root text.nm { fill: var(--brand-ink); font-size: 17px; }
.node.root text.sub { fill: var(--brand-ink); opacity: .85; font-size: 12px; }
.node.sel rect.box { stroke: var(--gold); stroke-width: 3; }
.node.hit rect.box { stroke: var(--gold); stroke-width: 3; filter: drop-shadow(0 0 8px var(--gold)); }
.node text.nm { fill: var(--ink); font-family: var(--font); font-weight: 600; font-size: 15px; }
.node text.sub { fill: var(--muted); font-family: var(--font); font-size: 10.5px; }
.node .tg circle { fill: var(--surface); stroke: var(--line-2); }
.node .tg text { fill: var(--ink-2); font-size: 11px; font-family: var(--font); font-weight: 600; }
.node .tg:hover circle { stroke: var(--brand); }
.node { cursor: pointer; }
.node text.nm, .node text.sub, .node .tg text { pointer-events: none; }
.link { fill: none; stroke: var(--line-2); stroke-width: 1.6; }
.link.hl { stroke: var(--gold); stroke-width: 2.6; }

/* ===== Side panel ===== */
.scrim { position: fixed; inset: 0; z-index: 70; background: rgba(10, 15, 13, .35); backdrop-filter: blur(2px); animation: fade .25s both; }
.panel {
  position: fixed; z-index: 80; background: var(--surface); box-shadow: var(--shadow-lg); border: 1px solid var(--line); overflow: auto; overscroll-behavior: contain;
  inset-inline: 0; bottom: 0; max-height: 86dvh; border-radius: 24px 24px 0 0; padding: 8px 18px 26px; animation: sheetUp .4s var(--ease) both;
}
.panel .grab { width: 44px; height: 5px; border-radius: 3px; background: var(--line-2); margin: 4px auto 10px; }
@media (min-width: 820px) {
  .panel { inset-inline: auto 0; inset-inline-start: auto; top: 0; bottom: 0; right: auto; left: 0; width: 420px; max-height: none; border-radius: 0 24px 24px 0; padding: 20px 22px; animation: sheetSide .4s var(--ease) both; }
  .panel .grab { display: none; }
}
.panel-head { display: flex; align-items: center; gap: 12px; margin-bottom: 10px; }
.panel-head h2 { font-family: var(--display); font-size: 30px; margin: 0; flex: 1; line-height: 1.2; }
.panel h4 { margin: 16px 0 8px; font-size: 14px; color: var(--muted); font-weight: 600; }
.panel .lineage { color: var(--ink-2); font-size: 15px; line-height: 1.9; margin: 0; }
.panel-actions { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 18px; position: sticky; bottom: -26px; padding: 12px 0; background: var(--surface); }

/* ===== Stats ===== */
.tiles { display: grid; grid-template-columns: repeat(auto-fill, minmax(min(100%, 160px), 1fr)); gap: 12px; margin-bottom: 18px; }
.tile { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; box-shadow: var(--shadow-sm); animation: cardIn .5s var(--ease) both; animation-delay: calc(var(--i, 0) * 60ms); }
.tile .t-num { font-size: 34px; font-weight: 600; line-height: 1.1; font-variant-numeric: tabular-nums; }
.tile .t-lbl { color: var(--muted); font-size: 14px; }
.bars { display: flex; flex-direction: column; gap: 8px; }
.bar-row { display: grid; grid-template-columns: minmax(70px, 120px) 1fr auto; gap: 10px; align-items: center; font-size: 14px; position: relative; }
.bar-row .b-lbl { color: var(--ink-2); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.bar-row .b-track { height: 14px; display: flex; }
.bar-row .b-fill { height: 100%; background: var(--brand); border-radius: 0 4px 4px 0; transform-origin: right; animation: barIn .9s var(--ease) both; animation-delay: calc(var(--i, 0) * 60ms); min-width: 2px; }
[dir="rtl"] .bar-row .b-fill { border-radius: 4px 0 0 4px; }
.bar-row .b-val { font-variant-numeric: tabular-nums; color: var(--ink); font-weight: 600; min-width: 2.5em; text-align: end; }
.bar-row:hover .b-fill { background: var(--brand-2); }
.tip { position: fixed; z-index: 90; pointer-events: none; background: var(--ink); color: var(--bg); padding: 6px 10px; border-radius: 8px; font-size: 13px; box-shadow: var(--shadow); white-space: nowrap; }
.stats-grid { display: grid; gap: 16px; }
@media (min-width: 900px) { .stats-grid { grid-template-columns: 1fr 1fr; } }

/* ===== Relationship ===== */
.rel-form { display: grid; gap: 10px; }
@media (min-width: 720px) { .rel-form { grid-template-columns: 1fr 1fr auto; align-items: end; } }
.picker { position: relative; }
.picker label { display: block; font-size: 14px; color: var(--muted); margin-bottom: 4px; }
.picker input { width: 100%; height: 44px; border-radius: 12px; border: 1px solid var(--line); background: var(--surface); padding: 0 12px; outline: none; }
.picker input:focus { border-color: var(--brand); }
.rel-result { margin-top: 18px; }
.rel-title { font-family: var(--display); font-size: 26px; margin: 0 0 10px; color: var(--brand); }
.path { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; }

/* ===== Toast & dialog ===== */
.toasts { position: fixed; bottom: 18px; left: 50%; transform: translateX(-50%); z-index: 120; display: flex; flex-direction: column; gap: 8px; align-items: center; pointer-events: none; width: min(92vw, 460px); }
.toast { pointer-events: auto; background: var(--ink); color: var(--bg); padding: 10px 16px; border-radius: 14px; box-shadow: var(--shadow-lg); animation: pop .3s var(--ease) both; display: flex; gap: 10px; align-items: center; font-size: 15px; }
.toast.err { background: var(--danger); color: #fff; }
.toast.ok { background: var(--ok); color: #fff; }
.toast button { background: none; border: 0; color: inherit; font-weight: 600; text-decoration: underline; }
dialog.modal {
  border: 1px solid var(--line); border-radius: 22px; padding: 0; width: min(520px, calc(100vw - 32px)); background: var(--surface); color: var(--ink); box-shadow: var(--shadow-lg);
}
dialog.modal[open] { animation: pop .3s var(--ease) both; }
dialog.modal::backdrop { background: rgba(10, 15, 13, .45); backdrop-filter: blur(3px); }
.modal-body { padding: 22px; }
.modal-body h3 { margin: 0 0 10px; font-size: 20px; }
.modal-actions { display: flex; gap: 8px; justify-content: flex-end; flex-wrap: wrap; padding: 0 22px 20px; }

.loading { display: grid; place-items: center; min-height: 50vh; color: var(--muted); gap: 12px; }
.spinner { width: 34px; height: 34px; border-radius: 50%; border: 3px solid var(--line); border-top-color: var(--brand); animation: spin 1s linear infinite; }

/* ===== Animations ===== */
@keyframes rise { from { opacity: 0; transform: translateY(24px) scale(.98); } to { opacity: 1; transform: none; } }
@keyframes fade { from { opacity: 0; } to { opacity: 1; } }
@keyframes grow { from { opacity: 0; transform: scale(.6) rotate(-8deg); } to { opacity: 1; transform: none; } }
@keyframes pop { from { opacity: 0; transform: translateY(6px) scale(.98); } to { opacity: 1; transform: none; } }
@keyframes viewIn { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: none; } }
@keyframes cardIn { from { opacity: 0; transform: translateY(12px); } to { opacity: 1; transform: none; } }
@keyframes sheetUp { from { transform: translateY(100%); } to { transform: none; } }
@keyframes sheetSide { from { transform: translateX(-100%); } to { transform: none; } }
@keyframes slideDown { from { opacity: 0; transform: translateY(-6px); } to { opacity: 1; transform: none; } }
@keyframes barIn { from { transform: scaleX(0); } to { transform: none; } }
@keyframes spin { to { transform: rotate(360deg); } }
@keyframes flash { 0%, 100% { background: transparent; } 20%, 60% { background: var(--gold-soft); } }
@media (prefers-reduced-motion: reduce) { *, *::before, *::after { animation-duration: .01ms !important; transition-duration: .01ms !important; } }

/* ===== Print ===== */
.print-only { display: none; }
@media print {
  @page { margin: 12mm; }
  body { background: #fff; color: #000; }
  body::before, .topbar, .tabs, .toolbar, .back-row, .tree-ctrl, .tree-hint, .panel, .scrim, .toasts, .no-print, .filters { display: none !important; }
  main { padding: 0; max-width: none; }
  .section, .hero, .card, .kid, .tile, .outline { box-shadow: none !important; break-inside: avoid; }
  .gen-head { position: static; }
  .view { animation: none; }
  .print-only { display: block; }
  .print-only img { width: 100%; height: auto; }
  body.printing-tree .tree-wrap { display: none; }
  .o-kids[hidden] { display: block !important; }
}

/* while rendering an image export: show everything, no entry animations */
.exporting .card { content-visibility: visible; }
.exporting .view, .exporting .kid, .exporting .tile, .exporting .b-fill, .exporting .o-kids { animation: none !important; }
