:root {
  --bg: #0a0f1f; --bg2: #111936;
  --panel: rgba(22, 30, 58, .72); --panel-solid: #161e3a;
  --line: rgba(130, 160, 255, .18); --line-strong: rgba(130, 160, 255, .38);
  --text: #e9edff; --muted: #94a0c8;
  --accent: #5b8cff; --accent2: #22d3ee; --danger: #ff6b8a; --ok: #34d399;
  --male: #4f8bff; --female: #c084fc; --other: #34d399; --unknown: #7d8bb5;
  --edge: rgba(120, 165, 255, .55); --edge-glow: rgba(34, 211, 238, .35);
  --shadow: 0 10px 40px rgba(0, 0, 0, .45);
  --radius: 16px;
  color-scheme: dark;
}
[data-theme="light"] {
  --bg: #eef2ff; --bg2: #dfe7ff;
  --panel: rgba(255, 255, 255, .78); --panel-solid: #ffffff;
  --line: rgba(60, 90, 190, .18); --line-strong: rgba(60, 90, 190, .4);
  --text: #141a36; --muted: #5a668f;
  --edge: rgba(60, 100, 220, .5); --edge-glow: rgba(34, 150, 200, .25);
  --shadow: 0 10px 30px rgba(40, 60, 140, .18);
  color-scheme: light;
}
* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  font: 15px/1.45 ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  color: var(--text); background: var(--bg); overflow: hidden;
  display: flex; flex-direction: column;
}
button, input, select, textarea { font: inherit; color: inherit; }
a { color: var(--accent2); }
code { background: var(--line); padding: 1px 6px; border-radius: 6px; font-size: .9em; }
[hidden] { display: none !important; }

.aurora { position: fixed; inset: 0; z-index: -1; pointer-events: none;
  background:
    radial-gradient(900px 500px at 10% -10%, rgba(91, 140, 255, .28), transparent 60%),
    radial-gradient(800px 500px at 100% 0%, rgba(192, 132, 252, .20), transparent 60%),
    radial-gradient(900px 600px at 50% 120%, rgba(34, 211, 238, .16), transparent 60%),
    var(--bg);
}
.aurora::after { content: ""; position: absolute; inset: 0; opacity: .5;
  background-image: radial-gradient(rgba(160, 190, 255, .25) 1px, transparent 1px);
  background-size: 34px 34px; mask-image: radial-gradient(ellipse at center, #000 30%, transparent 75%); }
[data-theme="light"] .aurora::after { opacity: .25; }

.glass { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius);
  backdrop-filter: blur(16px) saturate(140%); -webkit-backdrop-filter: blur(16px) saturate(140%); box-shadow: var(--shadow); }

/* ---------- top bar ---------- */
.topbar { display: flex; align-items: center; gap: 12px; padding: 10px 16px; padding-top: max(10px, env(safe-area-inset-top));
  border-bottom: 1px solid var(--line); background: var(--panel); backdrop-filter: blur(16px); position: relative; z-index: 30; }
.brand { display: flex; align-items: center; gap: 10px; font-weight: 700; letter-spacing: .3px; font-size: 17px; white-space: nowrap; }
.tabs { display: flex; gap: 4px; background: var(--line); padding: 4px; border-radius: 12px; }
.tabs button { border: 0; background: transparent; padding: 6px 14px; border-radius: 9px; cursor: pointer; color: var(--muted); font-weight: 600; }
.tabs button.active { background: linear-gradient(135deg, var(--accent), #7a6bff); color: #fff; box-shadow: 0 4px 16px rgba(91, 140, 255, .4); }
.search { position: relative; flex: 1; max-width: 340px; margin-left: auto; }
.search input { width: 100%; }
.search-results { position: absolute; top: 110%; left: 0; right: 0; background: var(--panel-solid); border: 1px solid var(--line-strong);
  border-radius: 12px; box-shadow: var(--shadow); max-height: 340px; overflow: auto; z-index: 50; }
.search-results button { display: flex; width: 100%; gap: 10px; align-items: center; padding: 8px 10px; border: 0; background: none; cursor: pointer; text-align: left; }
.search-results button:hover, .search-results button:focus { background: var(--line); outline: 0; }

input, select, textarea { background: rgba(8, 12, 28, .45); border: 1px solid var(--line); border-radius: 10px; padding: 8px 12px; min-width: 0; }
[data-theme="light"] input, [data-theme="light"] select, [data-theme="light"] textarea { background: rgba(255, 255, 255, .85); }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent); outline-offset: 0; border-color: transparent; }
textarea { width: 100%; resize: vertical; min-height: 90px; }
input[type="range"] { padding: 0; accent-color: var(--accent); width: 90px; }
input[type="checkbox"] { accent-color: var(--accent); width: 16px; height: 16px; }

.btn { border: 1px solid var(--line-strong); background: var(--line); border-radius: 11px; padding: 8px 14px; cursor: pointer; font-weight: 600; transition: .15s; }
.btn:hover { border-color: var(--accent); transform: translateY(-1px); }
.btn.primary { background: linear-gradient(135deg, var(--accent), #7a6bff); border-color: transparent; color: #fff; box-shadow: 0 6px 20px rgba(91, 140, 255, .35); }
.btn.danger { color: var(--danger); border-color: rgba(255, 107, 138, .4); }
.btn.small { padding: 4px 10px; font-size: 13px; border-radius: 9px; }
.icon-btn { width: 36px; height: 36px; border-radius: 10px; border: 1px solid var(--line); background: var(--line); cursor: pointer; font-size: 17px; }
.icon-btn:hover { border-color: var(--accent); }
.menu-wrap { position: relative; }
.menu { position: absolute; right: 0; top: 115%; min-width: 220px; background: var(--panel-solid); border: 1px solid var(--line-strong); border-radius: 12px; box-shadow: var(--shadow); padding: 6px; z-index: 60; display: flex; flex-direction: column; }
.menu a, .menu button { padding: 9px 12px; border-radius: 8px; border: 0; background: none; color: var(--text); text-decoration: none; text-align: left; cursor: pointer; }
.menu a:hover, .menu button:hover { background: var(--line); }

main { flex: 1; position: relative; min-height: 0; }
.view { position: absolute; inset: 0; display: none; overflow: auto; }
.view.active { display: block; }
#view-tree { overflow: hidden; }

/* ---------- tree ---------- */
.toolbar { position: absolute; z-index: 5; top: 12px; left: 12px; right: 12px; display: flex; flex-wrap: wrap; gap: 8px 18px; align-items: center; padding: 8px 14px; border-radius: 14px; }
.toolbar label { display: flex; align-items: center; gap: 8px; color: var(--muted); font-size: 13px; font-weight: 600; }
.toolbar label.check { color: var(--text); }
.toolbar select { max-width: 220px; }
.toolbar output { color: var(--text); min-width: 1ch; }
.zoom { margin-left: auto; display: flex; gap: 6px; }
#canvas { width: 100%; height: 100%; display: block; touch-action: none; cursor: grab; user-select: none; }
#canvas.panning { cursor: grabbing; }
#viewport.animate { transition: transform .55s cubic-bezier(.2, .8, .2, 1); }

.edge { fill: none; stroke: var(--edge); stroke-width: 2; stroke-linecap: round; filter: drop-shadow(0 0 4px var(--edge-glow));
  stroke-dasharray: 1; stroke-dashoffset: 1; animation: draw .9s .15s ease forwards; }
.edge.spouse { stroke: #f0abfc; stroke-opacity: .8; stroke-width: 2.5; }
@keyframes draw { to { stroke-dashoffset: 0; } }
.node { cursor: pointer; animation: nodeIn .55s both cubic-bezier(.2, .9, .3, 1.2); animation-delay: var(--d, 0s); transform-box: fill-box; transform-origin: center; }
@keyframes nodeIn { from { opacity: 0; transform: translateY(14px) scale(.9); } to { opacity: 1; transform: none; } }
.node .card { fill: var(--panel-solid); stroke: var(--line-strong); stroke-width: 1.5; transition: .2s; }
.node:focus { outline: none; }
.node:focus-visible .card { stroke: var(--accent2); stroke-width: 3; }
.node:hover .card { stroke: var(--accent2); filter: drop-shadow(0 0 10px var(--edge-glow)); }
.node.M .ring { stroke: var(--male); } .node.F .ring { stroke: var(--female); } .node.O .ring { stroke: var(--other); } .node.U .ring { stroke: var(--unknown); }
.node .ring { fill: none; stroke-width: 3; }
.node .initials { fill: #fff; font-weight: 700; font-size: 19px; text-anchor: middle; dominant-baseline: central; }
.node .avatar-bg.M { fill: url(#gM); } .node .avatar-bg.F { fill: url(#gF); } .node .avatar-bg.O { fill: url(#gO); } .node .avatar-bg.U { fill: url(#gU); }
.node .name1 { fill: var(--muted); font-size: 12.5px; }
.node .name2 { fill: var(--text); font-size: 14.5px; font-weight: 700; }
.node .dates { fill: var(--muted); font-size: 11.5px; }
.node.focus .card { stroke: var(--accent2); stroke-width: 2.5; filter: drop-shadow(0 0 14px var(--edge-glow)); }
.node.selected .card { stroke: #fff; stroke-width: 2.5; }
[data-theme="light"] .node.selected .card { stroke: var(--accent); }
.node .badge { fill: var(--ok); }
.heart { fill: #f0abfc; font-size: 13px; text-anchor: middle; dominant-baseline: central; }

.empty { position: absolute; z-index: 4; top: 50%; left: 50%; transform: translate(-50%, -50%); padding: 32px 40px; text-align: center; max-width: 440px; }
.empty h2 { margin: 0 0 6px; font-size: 24px; }
.row { display: flex; gap: 10px; align-items: center; } .row.wrap { flex-wrap: wrap; }
.empty .row { justify-content: center; margin-top: 18px; }

/* ---------- people grid ---------- */
.people-head { display: flex; align-items: center; justify-content: space-between; padding: 20px 24px 0; gap: 12px; }
.people-head h1, .discover h1 { margin: 0; font-size: 26px; } .people-head small { color: var(--muted); font-weight: 400; font-size: 15px; }
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 16px; padding: 20px 24px 40px; }
.pcard { text-align: left; padding: 0; overflow: hidden; cursor: pointer; border: 1px solid var(--line); background: var(--panel); border-radius: var(--radius); transition: .2s; color: inherit; }
.pcard:hover { transform: translateY(-4px); border-color: var(--accent); box-shadow: 0 14px 36px rgba(91, 140, 255, .25); }
.pcard .ph { aspect-ratio: 4 / 3; background: var(--line); display: grid; place-items: center; overflow: hidden; }
.pcard .ph img { width: 100%; height: 100%; object-fit: cover; object-position: center 20%; }
.pcard .ph .ini { font-size: 44px; font-weight: 800; color: #fff; width: 100%; height: 100%; display: grid; place-items: center; }
.pcard .meta { padding: 10px 14px 14px; }
.pcard .nm { font-weight: 700; } .pcard .dt { color: var(--muted); font-size: 13px; }
.g-M { background: linear-gradient(135deg, #3b6bff, #22d3ee); } .g-F { background: linear-gradient(135deg, #a855f7, #f472b6); }
.g-O { background: linear-gradient(135deg, #10b981, #22d3ee); } .g-U { background: linear-gradient(135deg, #52608f, #7d8bb5); }

/* ---------- discover ---------- */
.discover { max-width: 820px; margin: 0 auto; padding: 24px 20px 60px; }
.lead { color: var(--muted); margin: 6px 0 20px; }
.card { padding: 20px 22px; margin-bottom: 18px; } .card h2 { margin: 0 0 10px; font-size: 18px; }
.card p { color: var(--muted); margin: 6px 0 12px; }
#web-q { flex: 1; min-width: 200px; }
.hint { color: var(--muted); font-size: 13px; margin-top: 8px; }
.results { display: grid; gap: 10px; margin-top: 14px; }
.result { display: flex; gap: 12px; align-items: center; justify-content: space-between; flex-wrap: wrap; padding: 12px 14px; border: 1px solid var(--line); border-radius: 12px; background: rgba(0, 0, 0, .12); }
.result .t { font-weight: 700; } .result .s { color: var(--muted); font-size: 13px; }
.result .ctl { display: flex; gap: 8px; align-items: center; font-size: 12px; color: var(--muted); }
.result .ctl select { padding: 4px 8px; }
.drop { display: grid; place-items: center; height: 110px; border: 2px dashed var(--line-strong); border-radius: 14px; cursor: pointer; color: var(--muted); transition: .2s; }
.drop.over, .drop:hover { border-color: var(--accent2); color: var(--text); background: var(--line); }
.status { padding: 14px 18px; border-radius: 12px; border: 1px solid var(--ok); background: rgba(52, 211, 153, .1); display: flex; gap: 12px; align-items: center; justify-content: space-between; flex-wrap: wrap; }
.status.err { border-color: var(--danger); background: rgba(255, 107, 138, .1); }
.spinner { width: 18px; height: 18px; border: 3px solid var(--line-strong); border-top-color: var(--accent2); border-radius: 50%; animation: spin .8s linear infinite; display: inline-block; vertical-align: middle; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- drawer ---------- */
.drawer { position: fixed; z-index: 40; top: 0; right: 0; bottom: 0; width: min(440px, 100vw); border-radius: 0; border-width: 0 0 0 1px; transform: translateX(105%); transition: transform .35s cubic-bezier(.2, .8, .2, 1); overflow: auto; padding-bottom: 40px; }
.drawer.open { transform: none; }
#backdrop { position: fixed; inset: 0; z-index: 35; background: rgba(0, 0, 0, .35); }
.d-hero { position: relative; height: 230px; background: var(--line); overflow: hidden; cursor: zoom-in; }
.d-hero img { width: 100%; height: 100%; object-fit: cover; object-position: center 25%; }
.d-hero .ini { width: 100%; height: 100%; display: grid; place-items: center; font-size: 80px; font-weight: 800; color: #fff; cursor: default; }
.d-hero::after { content: ""; position: absolute; inset: 0; background: linear-gradient(transparent 45%, var(--panel-solid)); pointer-events: none; }
.d-close { position: absolute; top: 12px; right: 12px; z-index: 2; background: rgba(0, 0, 0, .45); color: #fff; border-color: transparent; }
.d-body { padding: 0 22px; margin-top: -42px; position: relative; z-index: 1; }
.d-body h2 { margin: 0; font-size: 26px; line-height: 1.15; }
.d-sub { color: var(--muted); margin: 4px 0 14px; }
.d-actions { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 18px; }
.sec { margin-top: 22px; } .sec h3 { margin: 0 0 8px; font-size: 12px; letter-spacing: 1.2px; text-transform: uppercase; color: var(--muted); display: flex; align-items: center; justify-content: space-between; }
.facts { display: grid; grid-template-columns: auto 1fr; gap: 6px 14px; margin: 0; } .facts dt { color: var(--muted); } .facts dd { margin: 0; }
.bio { white-space: pre-wrap; }
.rel { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.chip { display: inline-flex; align-items: center; gap: 8px; padding: 4px 6px 4px 4px; border-radius: 999px; border: 1px solid var(--line-strong); background: var(--line); cursor: pointer; font-size: 14px; }
.chip:hover { border-color: var(--accent2); }
.chip .mini { width: 26px; height: 26px; border-radius: 50%; overflow: hidden; display: grid; place-items: center; color: #fff; font-size: 11px; font-weight: 700; flex: none; }
.chip .mini img { width: 100%; height: 100%; object-fit: cover; }
.chip .x { border: 0; background: none; color: var(--muted); cursor: pointer; padding: 0 6px 0 2px; font-size: 15px; }
.chip .x:hover { color: var(--danger); }
.addrow { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; }
.gallery { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.thumb { position: relative; aspect-ratio: 1; border-radius: 10px; overflow: hidden; border: 2px solid transparent; cursor: pointer; background: var(--line); }
.thumb.primary { border-color: var(--accent2); }
.thumb img { width: 100%; height: 100%; object-fit: cover; }
.thumb .tools { position: absolute; inset: auto 0 0 0; display: flex; justify-content: space-between; padding: 4px; background: linear-gradient(transparent, rgba(0, 0, 0, .75)); opacity: 0; transition: .2s; }
.thumb:hover .tools, .thumb:focus-within .tools { opacity: 1; }
.tools button { border: 0; background: rgba(255, 255, 255, .18); color: #fff; border-radius: 6px; cursor: pointer; font-size: 12px; padding: 2px 7px; }
@media (hover: none) { .thumb .tools { opacity: 1; } }

/* ---------- forms / modals ---------- */
.form { display: grid; grid-template-columns: 1fr 1fr; gap: 10px 12px; }
.form .full { grid-column: 1 / -1; } .form label { display: flex; flex-direction: column; gap: 4px; font-size: 12px; color: var(--muted); font-weight: 600; }
.form label.inline { flex-direction: row; align-items: center; gap: 8px; color: var(--text); }
.modal-bg { position: fixed; inset: 0; z-index: 70; background: rgba(3, 6, 18, .6); backdrop-filter: blur(4px); display: grid; place-items: center; padding: 16px; animation: fade .2s; }
@keyframes fade { from { opacity: 0; } }
.modal { width: min(560px, 100%); max-height: 92vh; overflow: auto; padding: 22px; background: var(--panel-solid); }
.modal.wide { width: min(820px, 100%); }
.modal h2 { margin: 0 0 14px; } .modal .foot { display: flex; justify-content: flex-end; gap: 10px; margin-top: 18px; }
.seg { display: inline-flex; background: var(--line); border-radius: 10px; padding: 3px; margin-bottom: 14px; } .seg button { border: 0; background: none; padding: 5px 14px; border-radius: 8px; cursor: pointer; color: var(--muted); font-weight: 600; } .seg button.active { background: var(--accent); color: #fff; }
.photo-results { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 10px; margin-top: 14px; }
.pr { border: 1px solid var(--line); border-radius: 12px; overflow: hidden; background: var(--line); cursor: pointer; padding: 0; text-align: left; color: inherit; }
.pr:hover { border-color: var(--accent2); } .pr img { width: 100%; aspect-ratio: 1; object-fit: cover; display: block; } .pr span { display: block; padding: 6px 8px; font-size: 11px; color: var(--muted); }
.lightbox img { max-width: 92vw; max-height: 88vh; border-radius: 12px; box-shadow: var(--shadow); }

#toasts { position: fixed; z-index: 90; bottom: 18px; left: 50%; transform: translateX(-50%); display: grid; gap: 8px; justify-items: center; pointer-events: none; }
.toast { background: var(--panel-solid); border: 1px solid var(--line-strong); padding: 10px 16px; border-radius: 12px; box-shadow: var(--shadow); animation: nodeIn .3s both; pointer-events: auto; }
.toast.err { border-color: var(--danger); }

.login { position: fixed; inset: 0; z-index: 100; display: grid; place-items: center; background: var(--bg); }
.login form { display: grid; gap: 12px; justify-items: center; width: min(340px, 92vw); } .login input { width: 100%; } .login .btn { width: 100%; }
.error { color: var(--danger); min-height: 1.2em; font-size: 13px; }

@media (max-width: 760px) {
  .hide-sm { display: none; } .brand span { display: none; } .search { max-width: none; }
  .toolbar { gap: 6px 12px; } .toolbar input[type="range"] { width: 70px; } .zoom { margin-left: 0; }
  .form { grid-template-columns: 1fr; }
}
@media (prefers-reduced-motion: reduce) { *, *::before, *::after { animation-duration: .01ms !important; transition-duration: .01ms !important; animation-delay: 0s !important; } .edge { stroke-dashoffset: 0; } }
