/* ===== 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: "Messiri"; font-weight: 500; font-display: swap; src: url(fonts/el-messiri-arabic-500-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: "Messiri"; font-weight: 700; font-display: swap; src: url(fonts/el-messiri-arabic-700-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: "Amiri"; font-weight: 700; font-display: swap; src: url(fonts/amiri-arabic-700-normal.woff2) format("woff2"); }

/* ===== Tokens — "ليل ونحاس": midnight indigo with copper accents ===== */
:root {
  --bg: #eef0f6;
  --bg-2: #e3e6f0;
  --surface: #ffffff;
  --surface-2: #f5f6fb;
  --glass: rgba(255, 255, 255, .8);
  --ink: #161b33;
  --ink-2: #454c6b;
  --muted: #767c98;
  --line: #dfe2ee;
  --line-2: #c8cde1;
  --brand: #2a3570;
  --brand-2: #3b4a96;
  --brand-ink: #ffffff;
  --gold: #b5652a;
  --gold-2: #d98b4c;
  --gold-soft: #f7e9dc;
  --night: #121838;
  --night-2: #222b5e;
  --on-night: #f4f1ea;
  --male: #2c62b0;
  --male-soft: #e6eefb;
  --female: #b2427a;
  --female-soft: #fae8f1;
  --rip: #6b6f86;
  --rip-soft: #ecedf3;
  --danger: #b3261e;
  --danger-soft: #fbe9e7;
  --ok: #1e7a46;
  --shadow-sm: 0 1px 2px rgba(18, 24, 56, .06), 0 1px 1px rgba(18, 24, 56, .04);
  --shadow: 0 12px 32px -14px rgba(18, 24, 56, .28), 0 2px 6px rgba(18, 24, 56, .06);
  --shadow-lg: 0 34px 70px -24px rgba(12, 16, 40, .45);
  --radius: 20px;
  --radius-sm: 12px;
  --ease: cubic-bezier(.2, .8, .2, 1);
  --font: "Plex Arabic", "Segoe UI", Tahoma, system-ui, sans-serif;
  --display: "Messiri", "Amiri", "Plex Arabic", serif;
  /* eight-pointed star lattice, coloured through mask so it follows the theme */
  --pattern: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='80' height='80' viewBox='0 0 80 80'%3E%3Cg fill='none' stroke='%23000' stroke-width='1.2'%3E%3Cpath d='M40 14l7.6 18.4L66 40l-18.4 7.6L40 66l-7.6-18.4L14 40l18.4-7.6z'/%3E%3Cpath d='M21.6 21.6h36.8v36.8H21.6z' transform='rotate(45 40 40)'/%3E%3Ccircle cx='40' cy='40' r='6'/%3E%3Cpath d='M0 0l14 14M80 0L66 14M0 80l14-14M80 80L66 66'/%3E%3C/g%3E%3C/svg%3E");
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0a0e20; --bg-2: #0f1530; --surface: #141b38; --surface-2: #1a2246; --glass: rgba(16, 22, 48, .8);
    --ink: #eceef8; --ink-2: #b6bad2; --muted: #8a8fac; --line: #242d55; --line-2: #343f70;
    --brand: #9eacff; --brand-2: #b9c3ff; --brand-ink: #0d1230; --gold: #e6a56c; --gold-2: #f2bd8a; --gold-soft: #3a2a20;
    --night: #070a18; --night-2: #141c44;
    --male: #8fb6f2; --male-soft: #18264a; --female: #f0a0c6; --female-soft: #3b1c33; --rip: #a3a7c0; --rip-soft: #222842;
    --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, .65); --shadow-lg: 0 30px 60px -20px rgba(0, 0, 0, .75);
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #0a0e20; --bg-2: #0f1530; --surface: #141b38; --surface-2: #1a2246; --glass: rgba(16, 22, 48, .8);
  --ink: #eceef8; --ink-2: #b6bad2; --muted: #8a8fac; --line: #242d55; --line-2: #343f70;
  --brand: #9eacff; --brand-2: #b9c3ff; --brand-ink: #0d1230; --gold: #e6a56c; --gold-2: #f2bd8a; --gold-soft: #3a2a20;
  --night: #070a18; --night-2: #141c44;
  --male: #8fb6f2; --male-soft: #18264a; --female: #f0a0c6; --female-soft: #3b1c33; --rip: #a3a7c0; --rip-soft: #222842;
  --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, .65); --shadow-lg: 0 30px 60px -20px rgba(0, 0, 0, .75);
  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 { /* faint geometric lattice */
  content: ""; position: fixed; inset: 0; z-index: -1; pointer-events: none; opacity: .055;
  background: var(--brand); -webkit-mask: var(--pattern) 0 0 / 80px 80px repeat; mask: var(--pattern) 0 0 / 80px 80px repeat;
}
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: 12px; 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, color .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.copper { background: linear-gradient(135deg, var(--gold), var(--gold-2)); border-color: transparent; color: #fff; }
.btn.copper:hover { filter: brightness(1.06); }
.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; border-radius: 10px; }
.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(--gold); color: var(--gold); }
.chip.on { background: var(--brand); color: var(--brand-ink); border-color: var(--brand); }
.badge { display: inline-flex; align-items: center; gap: 4px; padding: 1px 9px; 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); }
.badge.rip { background: var(--rip-soft); color: var(--rip); }

/* ===== Welcome: an arched doorway on a night sky ===== */
.welcome {
  min-height: 100dvh; display: grid; place-items: center; padding: 40px 16px; position: relative; overflow: hidden;
  background: radial-gradient(120% 80% at 50% 0%, var(--night-2), var(--night) 70%); color: var(--on-night);
}
.welcome::before {
  content: ""; position: absolute; inset: 0; opacity: .12; background: var(--gold-2);
  -webkit-mask: var(--pattern) 0 0 / 96px 96px repeat; mask: var(--pattern) 0 0 / 96px 96px repeat;
  animation: drift 90s linear infinite;
}
.welcome::after { /* soft lantern glow */
  content: ""; position: absolute; width: 70vmax; height: 70vmax; top: -35vmax; left: 50%; transform: translateX(-50%); border-radius: 50%;
  background: radial-gradient(circle, color-mix(in srgb, var(--gold-2) 22%, transparent), transparent 60%); pointer-events: none;
}
.welcome-card {
  position: relative; z-index: 1; width: min(760px, 100%); text-align: center;
  padding: clamp(70px, 12vw, 120px) clamp(20px, 5vw, 60px) clamp(28px, 5vw, 48px);
  background: var(--surface); color: var(--ink);
  border-radius: min(380px, 50vw) min(380px, 50vw) 28px 28px / min(260px, 40vw) min(260px, 40vw) 28px 28px;
  box-shadow: 0 0 0 1px color-mix(in srgb, var(--gold) 40%, transparent), 0 0 0 10px color-mix(in srgb, var(--surface) 10%, transparent), var(--shadow-lg);
  animation: rise 1s var(--ease) both;
}
.welcome-card::before { /* inner copper arch line */
  content: ""; position: absolute; inset: 12px; pointer-events: none; border: 1.5px solid color-mix(in srgb, var(--gold) 55%, transparent);
  border-radius: inherit;
}
.crest { width: 88px; height: 88px; margin: 0 auto 6px; color: var(--gold); animation: grow 1.4s var(--ease) both .2s; }
.basmala { font-family: "Amiri", var(--display); font-size: clamp(24px, 4.6vw, 34px); color: var(--gold); margin: 0 0 4px; font-weight: 700; }
.welcome h1 { font-family: var(--display); font-weight: 700; font-size: clamp(36px, 7.5vw, 60px); line-height: 1.25; margin: 2px 0 4px; color: var(--brand); }
.welcome .subtitle { margin: 0 0 22px; color: var(--muted); font-size: 15px; }
.welcome .divider { display: flex; align-items: center; gap: 12px; justify-content: center; color: var(--gold); margin: 0 auto 20px; max-width: 320px; }
.welcome .divider::before, .welcome .divider::after { content: ""; flex: 1; height: 1px; background: linear-gradient(to var(--dir, left), transparent, currentColor); }
.welcome .divider::after { --dir: right; }
.welcome .text { text-align: start; }
.welcome .text p { margin: 0 0 12px; color: var(--ink-2); font-size: clamp(15px, 2.2vw, 17px); line-height: 2; animation: fade .8s var(--ease) both; }
.welcome .text p:nth-child(n+2) { animation-delay: .4s; }
.welcome .text ul { list-style: none; margin: 0 0 14px; padding: 0; display: grid; gap: 6px; }
.welcome .text li { padding: 8px 14px; border-radius: 12px; background: var(--surface-2); border: 1px solid var(--line); color: var(--ink); font-size: 15px; display: flex; gap: 10px; align-items: center; }
.welcome .text li::before { content: ""; width: 8px; height: 8px; flex: none; background: var(--gold); transform: rotate(45deg); border-radius: 2px; }
.welcome .sign { font-family: var(--display); font-size: 19px; color: var(--ink); margin: 20px 0 6px !important; text-align: center; line-height: 1.9; }
.welcome .note-small { font-size: 13px; color: var(--muted); text-align: center; margin: 0 0 22px !important; }
.enter-btn {
  font-size: 18px; min-height: 56px; padding: 0 36px; gap: 12px; animation: fade .8s var(--ease) both .9s; border-radius: 999px;
  background: linear-gradient(135deg, var(--gold), var(--gold-2)); color: #fff; border: 0; box-shadow: 0 16px 34px -14px color-mix(in srgb, var(--gold) 80%, 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: grid; grid-template-columns: repeat(auto-fit, minmax(90px, 1fr)); gap: 10px; margin-top: 26px; animation: fade .8s var(--ease) both 1.1s; }
.welcome-stats span { display: flex; flex-direction: column; padding: 10px; border-radius: 14px; background: var(--surface-2); border: 1px solid var(--line); color: var(--muted); font-size: 13px; }
.welcome-stats b { color: var(--brand); font-size: 24px; font-family: var(--display); line-height: 1.3; }
.welcome .theme-float { position: absolute; top: 16px; inset-inline-start: 16px; z-index: 2; background: rgba(255, 255, 255, .08); color: var(--on-night); border-color: rgba(255, 255, 255, .18); }

/* ===== App shell ===== */
.topbar {
  position: sticky; top: 0; z-index: 40; display: flex; align-items: center; gap: 10px; padding: 10px 16px; min-height: 62px;
  background: linear-gradient(90deg, var(--night), var(--night-2)); color: var(--on-night);
  box-shadow: 0 1px 0 color-mix(in srgb, var(--gold) 35%, transparent);
}
.topbar .btn { background: rgba(255, 255, 255, .08); border-color: rgba(255, 255, 255, .16); color: var(--on-night); box-shadow: none; }
.topbar .btn:hover { background: rgba(255, 255, 255, .16); }
.topbar .btn.primary { background: linear-gradient(135deg, var(--gold), var(--gold-2)); border-color: transparent; color: #fff; }
.brand { display: flex; align-items: center; gap: 10px; color: var(--on-night); font-family: var(--display); font-size: 22px; font-weight: 700; white-space: nowrap; }
.brand svg { width: 32px; height: 32px; color: var(--gold-2); }
.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: 12px; 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, background .2s; outline: none;
}
.topbar .search input { background: rgba(255, 255, 255, .1); border-color: rgba(255, 255, 255, .18); color: var(--on-night); box-shadow: none; }
.topbar .search input::placeholder { color: rgba(244, 241, 234, .6); }
.topbar .search input:focus { background: var(--surface); color: var(--ink); border-color: var(--gold); }
.topbar .search > .ico { color: rgba(244, 241, 234, .7); }
.search input:focus { border-color: var(--gold); box-shadow: 0 0 0 4px color-mix(in srgb, var(--gold) 18%, 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; color: var(--ink);
  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: 2px; padding: 0 12px; overflow-x: auto; scrollbar-width: none;
  background: color-mix(in srgb, var(--surface) 92%, transparent); backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--line); justify-content: safe center;
}
.tabs::-webkit-scrollbar { display: none; }
.tab { position: relative; display: inline-flex; align-items: center; gap: 7px; padding: 13px 14px; color: var(--muted); white-space: nowrap; transition: color .25s var(--ease); font-size: 15px; }
.tab::after { content: ""; position: absolute; inset-inline: 10px; bottom: -1px; height: 3px; border-radius: 3px 3px 0 0; background: var(--gold); transform: scaleX(0); transition: transform .3s var(--ease); }
.tab:hover { color: var(--ink); }
.tab.on { color: var(--brand); font-weight: 600; }
.tab.on::after { transform: none; }
.tab .ico { width: 18px; height: 18px; }

main { padding: 20px 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: 30px; margin: 0; margin-inline-end: auto; color: var(--brand); }
.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 10px; border-radius: 8px; background: var(--surface); border: 1px solid var(--line); transition: all .2s; }
.crumbs a:hover { color: var(--gold); border-color: var(--gold); }
.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: 28px; padding: clamp(24px, 5vw, 44px); margin-bottom: 18px;
  background: linear-gradient(135deg, var(--night), var(--night-2)); color: var(--on-night); box-shadow: var(--shadow-lg);
}
.hero::before { content: ""; position: absolute; inset: 0; opacity: .14; background: var(--gold-2); -webkit-mask: var(--pattern) 0 0 / 72px 72px repeat; mask: var(--pattern) 0 0 / 72px 72px repeat; }
.hero::after { content: ""; position: absolute; inset-inline-end: -80px; top: -80px; width: 300px; height: 300px; border-radius: 50%; background: radial-gradient(circle, color-mix(in srgb, var(--gold-2) 30%, transparent), transparent 70%); }
.hero > * { position: relative; z-index: 1; }
.hero-top { display: flex; align-items: center; gap: 16px; flex-wrap: wrap; }
.hero h1 { font-family: var(--display); font-size: clamp(36px, 8vw, 58px); line-height: 1.2; margin: 0; color: #fff; }
.hero .lineage { margin: 12px 0 0; color: rgba(244, 241, 234, .82); font-size: 16px; line-height: 1.9; }
.hero .meta { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 16px; }
.hero .chip { background: rgba(255, 255, 255, .1); border-color: rgba(255, 255, 255, .2); color: var(--on-night); }
.hero .badge { background: rgba(255, 255, 255, .14); color: #fff; }
.hero .badge.rip { background: color-mix(in srgb, var(--gold-2) 25%, transparent); color: #fff; }
.hero .avatar { box-shadow: 0 0 0 3px var(--night), 0 0 0 5px var(--gold-2); }
.hero.dead h1::after { content: attr(data-rip); display: inline-block; margin-inline-start: 12px; font-size: .38em; vertical-align: middle; color: var(--gold-2); font-family: "Amiri", var(--display); }
.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: 42px; height: 42px; font-size: 19px; }
.avatar.xs { width: 32px; height: 32px; font-size: 16px; }
.avatar.photo { overflow: hidden; background: var(--surface-2); box-shadow: 0 0 0 2px var(--surface), 0 0 0 3px var(--line); }
.avatar.photo img { width: 100%; height: 100%; object-fit: cover; display: block; }
.avatar.lg.photo { width: 108px; height: 108px; }
.avatar.dead { position: relative; box-shadow: 0 0 0 2px var(--surface), 0 0 0 3.5px var(--rip); }
.avatar.dead.photo img { filter: grayscale(.55); }
.back-row { display: flex; gap: 8px; align-items: center; margin-bottom: 8px; flex-wrap: wrap; }
.grid2 { display: grid; gap: 16px; }
@media (min-width: 900px) { .grid2 { grid-template-columns: 1fr 340px; align-items: start; } }
.section { position: relative; 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 14px; font-size: 17px; display: flex; align-items: center; gap: 8px; color: var(--brand); font-weight: 600; font-family: var(--display); font-size: 20px; }
.section h3 .ico { color: var(--gold); }
.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); color: var(--ink); }
a.spouse:hover { border-color: var(--gold); }
.spouse .s-name { font-weight: 600; color: var(--ink); }
.spouse .s-note { font-size: 13px; color: var(--muted); white-space: pre-line; }
.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: 18px 10px 12px; text-align: center; overflow: hidden;
  border-radius: 70px 70px 16px 16px / 50px 50px 16px 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::before { content: ""; position: absolute; top: 0; inset-inline: 30%; height: 3px; border-radius: 0 0 3px 3px; background: var(--gold); opacity: .7; }
.kid:hover { transform: translateY(-3px); box-shadow: var(--shadow); border-color: var(--gold); }
.kid .k-name { font-weight: 600; font-size: 17px; }
.kid .k-sub { font-size: 12px; color: var(--muted); }
.kid .k-n { position: absolute; top: 10px; inset-inline-start: 10px; }
.kid.dead { background: var(--rip-soft); }
.kid.dead::before { background: var(--rip); }
.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; }
.notes-text { white-space: pre-line; line-height: 2; color: var(--ink-2); margin: 0; }
.empty-note { color: var(--muted); font-size: 15px; }

/* ===== Grave location ===== */
.grave { border-color: color-mix(in srgb, var(--gold) 35%, var(--line)); }
.grave .g-place { font-weight: 600; font-size: 17px; margin: 0 0 4px; }
.grave .g-sub { color: var(--muted); font-size: 14px; margin: 0 0 12px; }
.grave .g-map { position: relative; width: 100%; aspect-ratio: 16 / 10; border-radius: 16px; overflow: hidden; border: 1px solid var(--line); background: var(--surface-2); margin-bottom: 12px; }
.grave .g-map iframe { position: absolute; inset: 0; width: 100%; height: 100%; border: 0; }
.grave .g-actions { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 8px; }
.grave .g-actions .btn { width: 100%; }
.g-coords { font-family: ui-monospace, Consolas, monospace; direction: ltr; unicode-bidi: isolate; font-size: 13px; color: var(--muted); }

/* ===== Cards view ===== */
.filters { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 14px; }
.gen-head { position: sticky; top: 112px; 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; color: var(--brand); }
.gen-head::before { content: ""; width: 10px; height: 10px; background: var(--gold); transform: rotate(45deg); border-radius: 2px; }
.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 {
  position: relative; 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; overflow: hidden;
}
.card::after { content: ""; position: absolute; inset-block: 12px; inset-inline-start: 0; width: 3px; border-radius: 0 3px 3px 0; background: var(--line-2); }
.card.m::after { background: var(--male); } .card.f::after { background: var(--female); } .card.dead::after { background: var(--rip); }
.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 dashed var(--line-2); }
.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); color: var(--gold); }
.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(--gold); }
.o-dot { width: 9px; height: 9px; border-radius: 2px; transform: rotate(45deg); flex: none; }
.o-dot.m { background: var(--male); } .o-dot.f { background: var(--female); }
.o-rip { font-size: 12px; color: var(--rip); white-space: nowrap; }
.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: 24px; overflow: hidden; border: 1px solid var(--line);
  background: var(--surface); box-shadow: var(--shadow); touch-action: none;
}
.tree-wrap::before { content: ""; position: absolute; inset: 0; opacity: .05; background: var(--brand); -webkit-mask: var(--pattern) 0 0 / 64px 64px repeat; mask: var(--pattern) 0 0 / 64px 64px repeat; pointer-events: none; }
.tree-wrap svg { position: relative; 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; max-width: calc(100% - 90px); }
.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) 45%, transparent); }
.node.f rect.box { fill: var(--female-soft); stroke: color-mix(in srgb, var(--female) 45%, transparent); }
.node.dead rect.box { fill: var(--rip-soft); stroke: var(--rip); stroke-dasharray: 5 3; }
.node.dead text.nm { fill: var(--ink-2); }
.node.root rect.box { fill: var(--night); stroke: var(--gold-2); stroke-width: 2; stroke-dasharray: none; }
.node.root text.nm { fill: #fff; font-size: 18px; font-family: var(--display); }
.node.root text.sub { fill: var(--gold-2); opacity: 1; font-size: 12px; }
.node.sel rect.box { stroke: var(--gold); stroke-width: 3; stroke-dasharray: none; }
.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(--gold); }
.node .tg text { fill: var(--gold); font-size: 11px; font-family: var(--font); font-weight: 600; }
.node .tg:hover circle { fill: var(--gold-soft); }
.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.8; }

/* ===== Side panel ===== */
.scrim { position: fixed; inset: 0; z-index: 70; background: rgba(8, 10, 26, .45); backdrop-filter: blur(3px); 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: 26px 26px 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 26px 26px 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; color: var(--brand); }
.panel h4 { margin: 16px 0 8px; font-size: 14px; color: var(--gold); 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 { position: relative; overflow: hidden; 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::after { content: ""; position: absolute; inset-inline-end: -18px; top: -18px; width: 60px; height: 60px; background: var(--gold); opacity: .08; transform: rotate(45deg); border-radius: 12px; }
.tile .t-num { font-size: 34px; font-weight: 700; line-height: 1.1; font-variant-numeric: tabular-nums; color: var(--brand); font-family: var(--display); }
.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: linear-gradient(to left, var(--brand), var(--brand-2)); 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(--gold); }
.tip { position: fixed; z-index: 90; pointer-events: none; background: var(--night); color: var(--on-night); 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(--gold); }
.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(--night); color: var(--on-night); 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; border: 1px solid color-mix(in srgb, var(--gold) 40%, transparent); }
.toast.err { background: var(--danger); color: #fff; border-color: transparent; }
.toast.ok { background: var(--ok); color: #fff; border-color: transparent; }
.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(8, 10, 26, .5); backdrop-filter: blur(3px); }
.modal-body { padding: 22px; }
.modal-body h3 { margin: 0 0 10px; font-size: 21px; font-family: var(--display); color: var(--brand); }
.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(--gold); 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 drift { to { -webkit-mask-position: 96px 96px; mask-position: 96px 96px; } }
@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, .g-map, .g-actions { display: none !important; }
  main { padding: 0; max-width: none; }
  .section, .hero, .card, .kid, .tile, .outline { box-shadow: none !important; break-inside: avoid; }
  .hero { background: #fff; color: #000; border: 1px solid #ccc; } .hero h1, .hero .lineage { color: #000; } .hero::before, .hero::after { display: none; }
  .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; }
.exporting .g-map { display: none; }
