:root{
  --paper:#f6f2eb;
  --paper-2:#eee8de;
  --ink:#2f2a25;
  --muted:#7a7167;
  --line:rgba(47,42,37,.12);
  --green:#21322e;
  --green-2:#36524a;
  --accent:#a87842;
  --card:#fffdf9;
  --shadow:0 18px 55px rgba(39,31,24,.16);
}
*{box-sizing:border-box}
html,body{margin:0;width:100%;height:100%;font-family:-apple-system,BlinkMacSystemFont,"Segoe UI","Noto Sans Arabic",Tahoma,sans-serif;background:var(--paper);color:var(--ink)}
body{overflow:hidden}
button,input{font:inherit}
button{cursor:pointer}
.app-shell{position:fixed;inset:0;display:grid;grid-template-rows:auto auto 1fr;background:var(--paper)}
.topbar{
  position:relative;z-index:20;display:grid;grid-template-columns:auto minmax(300px,760px) auto;
  align-items:center;gap:18px;padding:14px 18px;background:rgba(250,247,241,.94);
  border-bottom:1px solid var(--line);backdrop-filter:blur(16px);-webkit-backdrop-filter:blur(16px)
}
.brand{display:flex;align-items:center;gap:10px;text-decoration:none;color:inherit;min-width:max-content}
.brand-mark{width:42px;height:42px;border-radius:14px;background:var(--green);color:#fff;display:grid;place-items:center;font-size:1.25rem;font-weight:900}
.brand strong,.brand small{display:block}.brand strong{font-size:.95rem}.brand small{margin-top:2px;color:var(--muted);font-size:.72rem}
.search-wrap{position:relative}
.search-box{display:flex;align-items:center;gap:8px;height:50px;border:1px solid rgba(47,42,37,.16);border-radius:18px;background:#fff;padding:0 8px 0 10px;box-shadow:0 8px 26px rgba(50,40,31,.07)}
.search-icon{width:34px;height:34px;display:grid;place-items:center;border-radius:12px;background:var(--paper-2);font-size:1.2rem}
.search-box input{min-width:0;flex:1;border:0;outline:0;background:transparent;color:var(--ink);font-size:.98rem;padding:0 4px}
.search-box input::placeholder{color:#91877c}
.icon-button{border:0;background:transparent;width:38px;height:38px;border-radius:12px;color:#6a6259;font-size:1.25rem;display:grid;place-items:center}
.icon-button:hover{background:var(--paper-2)}
.header-actions{display:flex;gap:8px;justify-content:flex-end}
.soft-button{border:1px solid var(--line);background:#fff;color:var(--ink);border-radius:13px;min-height:42px;padding:0 14px;font-weight:750}
.soft-button:hover{background:var(--paper-2)}
.search-results{display:none;position:absolute;top:58px;right:0;left:0;z-index:50;max-height:min(56vh,520px);overflow:auto;background:#fffdf9;border:1px solid var(--line);border-radius:18px;box-shadow:var(--shadow)}
.search-results.open{display:block}
.search-result{width:100%;border:0;border-bottom:1px solid rgba(47,42,37,.07);background:transparent;padding:12px 14px;display:flex;gap:14px;align-items:center;text-align:right;color:var(--ink)}
.search-result:last-child{border-bottom:0}.search-result:hover,.search-result:focus{background:#f5efe6;outline:0}
.result-copy{min-width:0;flex:1}.result-name{display:block;font-weight:900}.result-lineage{display:block;color:var(--muted);font-size:.76rem;margin-top:3px;white-space:nowrap;overflow:hidden;text-overflow:ellipsis}
.result-badge{font-size:.68rem;border-radius:999px;background:var(--paper-2);padding:5px 8px;color:#6e655b;white-space:nowrap}
.search-empty{padding:16px;color:var(--muted);font-size:.85rem;line-height:1.7}
.statusbar{z-index:10;display:flex;justify-content:space-between;align-items:center;gap:20px;padding:10px 18px;background:#fbf8f2;border-bottom:1px solid var(--line)}
.eyebrow{display:block;color:var(--accent);font-size:.66rem;font-weight:850;letter-spacing:.02em}.statusbar strong{font-size:.9rem}
.stats{display:flex;gap:8px;flex-wrap:wrap;justify-content:flex-end}
.stat-pill{border:1px solid var(--line);background:#fff;border-radius:999px;padding:6px 10px;font-size:.72rem;color:#675f56}
.graph-stage{position:relative;min-height:0;overflow:hidden;background:
  radial-gradient(circle at 1px 1px, rgba(47,42,37,.055) 1px, transparent 1.2px);
  background-size:24px 24px;
  touch-action:none;user-select:none
}
.tree-svg{display:block;width:100%;height:100%;overflow:visible}
.empty-state{position:absolute;inset:0;display:grid;place-content:center;justify-items:center;text-align:center;padding:24px;pointer-events:none}
.empty-state.hidden{display:none}
.empty-mark{width:74px;height:74px;border-radius:24px;background:var(--green);color:#fff;display:grid;place-items:center;font-size:2rem;font-weight:900;box-shadow:0 15px 40px rgba(33,50,46,.2)}
.empty-state h1{font-size:1.55rem;margin:16px 0 7px}.empty-state p{max-width:530px;margin:0;color:var(--muted);line-height:1.8;font-size:.9rem}
.examples{margin-top:16px;display:flex;gap:8px;pointer-events:auto}
.examples button{border:1px solid var(--line);background:#fff;border-radius:999px;padding:8px 13px;color:var(--ink);font-weight:800}
.zoom-controls{position:absolute;left:16px;bottom:18px;display:flex;flex-direction:column;gap:6px;background:rgba(255,253,249,.94);border:1px solid var(--line);border-radius:16px;padding:6px;box-shadow:0 10px 28px rgba(39,31,24,.1)}
.zoom-controls button{width:40px;height:40px;border:0;border-radius:11px;background:transparent;color:var(--ink);font-size:1.15rem;font-weight:800}
.zoom-controls button:hover{background:var(--paper-2)}
.legend{position:absolute;right:16px;bottom:18px;display:flex;gap:12px;align-items:center;padding:9px 12px;border:1px solid var(--line);background:rgba(255,253,249,.92);border-radius:14px;font-size:.68rem;color:#6f665d;backdrop-filter:blur(12px)}
.legend span{display:flex;gap:5px;align-items:center}.legend-dot{width:9px;height:9px;border-radius:50%;display:inline-block}.selected-dot{background:var(--accent)}.ancestor-dot{background:var(--green)}.normal-dot{background:#c8beb0}
.person-sheet{position:absolute;z-index:30;left:18px;top:96px;width:min(390px,calc(100vw - 36px));max-height:calc(100vh - 122px);overflow:auto;background:rgba(255,253,249,.97);border:1px solid rgba(47,42,37,.13);border-radius:24px;padding:14px 16px 16px;box-shadow:var(--shadow);transform:translateX(calc(-100% - 36px));transition:transform .24s ease;backdrop-filter:blur(18px)}
.person-sheet.open{transform:translateX(0)}
.sheet-handle{display:none;width:42px;height:5px;border-radius:999px;background:#d2c8bb;margin:0 auto 10px}
.sheet-head{display:flex;align-items:flex-start;justify-content:space-between;gap:12px}.sheet-head h2{margin:2px 0 0;font-size:1.45rem}.sheet-close{flex:0 0 auto}
.full-lineage{margin:13px 0;background:#f4eee5;border:1px solid var(--line);border-radius:15px;padding:12px 13px;font-weight:850;line-height:1.9}
.person-meta{display:grid;grid-template-columns:1fr 1fr 1fr;gap:8px;margin:0}.person-meta div{background:#fff;border:1px solid var(--line);border-radius:14px;padding:10px}.person-meta dt{font-size:.66rem;color:var(--muted);margin-bottom:3px}.person-meta dd{margin:0;font-weight:850;font-size:.83rem}
.sheet-actions{display:grid;grid-template-columns:1fr 1fr;gap:8px;margin-top:12px}.sheet-actions button{border:1px solid var(--line);background:#fff;border-radius:13px;min-height:43px;color:var(--ink);font-weight:800}.sheet-actions button:first-child{background:var(--green);color:#fff;border-color:var(--green)}
.toast{position:absolute;z-index:80;left:50%;bottom:24px;transform:translate(-50%,14px);opacity:0;pointer-events:none;background:var(--green);color:#fff;border-radius:999px;padding:10px 16px;font-size:.8rem;box-shadow:0 12px 35px rgba(0,0,0,.18);transition:.2s}
.toast.show{opacity:1;transform:translate(-50%,0)}

.node-group{cursor:pointer}
.node-card{fill:#fffdf9;stroke:rgba(47,42,37,.18);stroke-width:1.2}
.node-group:hover .node-card{stroke:#8e765b;stroke-width:1.8}
.node-name{font-size:17px;font-weight:800;fill:#2f2a25;text-anchor:middle;dominant-baseline:middle}
.node-meta{font-size:10px;fill:#8a8176;text-anchor:middle}
.node-group.ancestor .node-card{fill:#eff3f1;stroke:#47665e;stroke-width:1.8}
.node-group.ancestor .node-name{fill:#21322e}
.node-group.selected .node-card{fill:#fff5e8;stroke:#a87842;stroke-width:3}
.node-group.selected .node-name{fill:#704b24}
.node-group.dimmed{opacity:.42}
.edge{fill:none;stroke:#c8beb0;stroke-width:2.2;stroke-linecap:round}
.edge.ancestry{stroke:#36524a;stroke-width:4}
.expand-badge{fill:#21322e}.expand-text{fill:#fff;font-size:10px;font-weight:900;text-anchor:middle;dominant-baseline:middle}
.unlinked-badge{fill:#efe7dc;stroke:#d9ccbd;stroke-width:1}.unlinked-text{fill:#766b5f;font-size:9px;text-anchor:middle}
@media(max-width:820px){
  .topbar{grid-template-columns:1fr auto;gap:9px;padding:10px 10px calc(10px + env(safe-area-inset-top))}
  .brand{grid-column:1/2}.brand strong{font-size:.86rem}.brand small{display:none}.brand-mark{width:38px;height:38px;border-radius:12px}
  .search-wrap{grid-row:2;grid-column:1/-1}.header-actions{grid-column:2;grid-row:1}.header-actions .soft-button:first-child{display:none}.soft-button{min-height:38px;padding:0 11px;font-size:.76rem}
  .statusbar{padding:8px 10px}.statusbar>div:first-child{display:none}.stats{justify-content:flex-start;overflow:auto;flex-wrap:nowrap}.stat-pill{white-space:nowrap}
  .legend{display:none}.zoom-controls{left:10px;bottom:calc(18px + env(safe-area-inset-bottom))}
  .person-sheet{position:absolute;left:8px;right:8px;top:auto;bottom:calc(8px + env(safe-area-inset-bottom));width:auto;max-height:58vh;border-radius:24px;transform:translateY(calc(100% + 30px))}
  .person-sheet.open{transform:translateY(0)}.sheet-handle{display:block}
  .person-meta{grid-template-columns:1fr 1fr}.person-meta div:last-child{grid-column:1/-1}
  .empty-state h1{font-size:1.25rem}.empty-state p{font-size:.82rem;max-width:340px}.examples{flex-wrap:wrap;justify-content:center}
}
