:root{
  --bg:#f6f2e9; --panel:#fffdf8; --ink:#25231f; --muted:#6f6a61; --line:#b9b2a6;
  --gold:#a67831; --gold2:#d4bd8b; --green:#66816d; --blue:#66798d; --red:#a15b55;
  --shadow:0 10px 30px rgba(50,40,25,.10); --radius:16px;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}
*{box-sizing:border-box}
html,body{height:100%; margin:0; background:var(--bg); color:var(--ink); overflow:hidden}
button,input,select{font:inherit}
.app{height:100%; display:grid; grid-template-rows:74px 1fr}
header{display:flex;align-items:center;gap:18px;padding:11px 18px;background:rgba(255,253,248,.96);border-bottom:1px solid #ddd5c8;z-index:20;box-shadow:0 2px 12px rgba(50,40,25,.05)}
.brand{min-width:280px;display:flex;align-items:center;gap:12px}
.crest{width:44px;height:44px;border-radius:50%;display:grid;place-items:center;background:#efe3ca;border:1px solid #d2b780;color:#825f26;font-family:Georgia,serif;font-weight:800;font-size:20px}
.brand h1{font-family:Georgia,serif;font-size:20px;margin:0;line-height:1.05}.brand small{color:var(--muted)}
.controls{display:flex;align-items:center;gap:8px;flex:1;min-width:0}
.segment{display:flex;background:#eee8dc;border:1px solid #ddd4c4;border-radius:12px;padding:3px;white-space:nowrap}
.segment button{border:0;background:transparent;padding:8px 11px;border-radius:9px;color:#665f54;cursor:pointer}.segment button.active{background:#fff;box-shadow:0 1px 5px rgba(0,0,0,.08);color:#2c2822;font-weight:650}
.search{position:relative;flex:1;max-width:420px;min-width:180px}.search input{width:100%;padding:10px 36px 10px 13px;border:1px solid #d8d0c2;border-radius:11px;background:#fff}.search .x{position:absolute;right:7px;top:6px;border:0;background:transparent;font-size:20px;color:#928a7e;cursor:pointer}
.iconbtn{border:1px solid #d8d0c2;background:#fff;border-radius:11px;padding:9px 11px;cursor:pointer;color:#544d43}.iconbtn:hover{background:#faf7f0}
.main{display:grid;grid-template-columns:270px minmax(0,1fr) 330px;min-height:0}
.sidebar,.details{background:var(--panel);overflow:auto;z-index:10}.sidebar{border-right:1px solid #ded6c9;padding:16px}.details{border-left:1px solid #ded6c9;padding:0}
.sidebar h3,.details h3{font-family:Georgia,serif;margin:4px 0 10px}.muted{color:var(--muted)}
.card{background:#fff;border:1px solid #e0d8cb;border-radius:14px;padding:12px;margin-bottom:11px;box-shadow:0 3px 10px rgba(50,40,25,.03)}
.legend{display:grid;grid-template-columns:12px 1fr;gap:8px 9px;font-size:12px;align-items:center}.dot{width:10px;height:10px;border-radius:50%}.dot.primary{background:#b3843e}.dot.documented{background:#66816d}.dot.probable{background:#778b9b}.dot.uncertain{background:#c49c49}.dot.reconstructed{background:#9c6e68}
.toggleline{display:flex;justify-content:space-between;gap:10px;align-items:center;font-size:13px;margin:8px 0}.toggleline input{accent-color:#8b6a35}
.stats{display:grid;grid-template-columns:1fr 1fr;gap:7px}.stat{background:#f5efe4;border-radius:10px;padding:8px}.stat b{display:block;font-size:17px}.stat span{font-size:11px;color:var(--muted)}
.canvasWrap{position:relative;overflow:hidden;background:
 radial-gradient(circle at 1px 1px,rgba(126,111,88,.14) 1px,transparent 1.2px) 0 0/24px 24px,#f8f5ee;cursor:grab}.canvasWrap.dragging{cursor:grabbing}
#viewport{position:absolute;left:0;top:0;transform-origin:0 0;will-change:transform}
#edges{position:absolute;left:0;top:0;overflow:visible;pointer-events:none}.edge{fill:none;stroke:#b8b0a3;stroke-width:2}.edge.direct{stroke:#a67831;stroke-width:3.5}.edge.searchpath{stroke:#657e69;stroke-width:3}.edge.faint{opacity:.17}
.node{position:absolute;width:220px;min-height:104px;border-radius:15px;border:1px solid #d8d0c2;background:#fffdf9;box-shadow:0 6px 16px rgba(40,32,22,.09);padding:11px 12px 10px;cursor:pointer;user-select:none;transition:box-shadow .15s,border-color .15s,opacity .15s,transform .15s}.node:hover{box-shadow:0 10px 24px rgba(40,32,22,.15);border-color:#b6a37c}.node.selected{outline:3px solid rgba(166,120,49,.25);border-color:#a67831}.node.group{background:#f3f1eb;border-style:dashed}.node.direct{background:#fffaf0;border-color:#c39a56}.node.searchhit{box-shadow:0 0 0 4px rgba(102,129,109,.23),0 10px 26px rgba(40,32,22,.15);border-color:#66816d}.node.dim{opacity:.22}
.node .top{display:flex;gap:9px;align-items:flex-start}.avatar{width:38px;height:38px;flex:0 0 38px;border-radius:50%;background:#ede6d9;display:grid;place-items:center;font-family:Georgia,serif;font-weight:700;color:#725d3c;overflow:hidden;border:1px solid #d8cbb6}.avatar img{width:100%;height:100%;object-fit:cover}.node h4{font-size:13.3px;line-height:1.15;margin:1px 0 3px}.life{font-size:11px;color:#7c7469}.partner{font-size:10.5px;color:#696257;margin-top:5px;white-space:nowrap;overflow:hidden;text-overflow:ellipsis}.badges{display:flex;gap:4px;flex-wrap:wrap;margin-top:8px}.badge{font-size:9.5px;border-radius:20px;padding:3px 6px;background:#f0ece4;color:#6b6256}.badge.live{background:#e7f1e9;color:#46604c}.badge.warn{background:#fff0d4;color:#8a682c}.badge.you{background:#efe2c7;color:#76551f;font-weight:700}.badge.rel{background:#e9eef4;color:#526579}
.collapse{position:absolute;left:50%;bottom:-13px;transform:translateX(-50%);width:25px;height:25px;border-radius:50%;border:1px solid #d6cdbf;background:#fff;display:grid;place-items:center;font-size:15px;color:#6a6155;box-shadow:0 2px 7px rgba(0,0,0,.08);z-index:2}.collapse:hover{background:#f7f1e7}
.empty{padding:24px;color:var(--muted);text-align:center}
.detailsHero{min-height:155px;background:linear-gradient(135deg,#e7dac1,#f5efe4);position:relative;overflow:hidden}.detailsHero img{width:100%;height:185px;object-fit:cover;filter:sepia(.12)}.detailsHero .placeholder{height:155px;display:grid;place-items:center;font-family:Georgia,serif;font-size:54px;color:#8a7048}.detailsBody{padding:17px}.detailsBody h2{font-family:Georgia,serif;font-size:23px;line-height:1.12;margin:0 0 4px}.kicker{text-transform:uppercase;letter-spacing:.09em;font-size:10px;color:#8a7659;font-weight:700}.detailsLife{color:#71695e;margin:2px 0 12px}.detailRow{border-top:1px solid #eee7dc;padding:9px 0}.detailRow b{font-size:11px;text-transform:uppercase;letter-spacing:.06em;color:#867c6e;display:block;margin-bottom:3px}.detailRow p{margin:0;font-size:13px;line-height:1.45}.sources a{display:block;font-size:12px;color:#5b6f80;text-decoration:none;margin:5px 0}.sources a:hover{text-decoration:underline}
.galleryGrid{display:grid;grid-template-columns:1fr 1fr;gap:8px}.galleryItem{border-radius:10px;overflow:hidden;border:1px solid #ddd4c6;background:#fff;cursor:pointer}.galleryItem img{width:100%;height:95px;object-fit:cover;display:block}.galleryItem span{display:block;padding:6px;font-size:10px;line-height:1.2}
.searchResults{position:absolute;left:0;right:0;top:46px;background:#fff;border:1px solid #d8d0c2;border-radius:12px;box-shadow:var(--shadow);max-height:330px;overflow:auto;z-index:50;display:none}.searchResults.show{display:block}.result{padding:9px 11px;border-bottom:1px solid #eee8de;cursor:pointer}.result:last-child{border:0}.result:hover{background:#f7f2ea}.result b{display:block;font-size:12px}.result small{color:#7d756a}
.aboutModal,.photoModal{position:fixed;inset:0;background:rgba(30,26,22,.48);z-index:100;display:none;align-items:center;justify-content:center;padding:24px}.aboutModal.show,.photoModal.show{display:flex}.modalBox{background:#fffdf8;max-width:900px;max-height:88vh;overflow:auto;border-radius:18px;box-shadow:0 25px 70px rgba(0,0,0,.25);padding:22px;position:relative}.modalBox h2{font-family:Georgia,serif;margin:0 40px 10px 0}.closeModal{position:absolute;right:13px;top:10px;border:0;background:transparent;font-size:27px;cursor:pointer;color:#6c6459}.sourceTable{width:100%;border-collapse:collapse;font-size:12px}.sourceTable td{padding:8px;border-top:1px solid #ebe3d8;vertical-align:top}.sourceTable td:first-child{font-weight:700;width:50px}.sourceTable a{color:#566f80}.photoBox{max-width:min(94vw,1100px);padding:10px}.photoBox img{max-width:90vw;max-height:78vh;display:block;border-radius:11px}.photoCap{padding:10px 5px 3px;color:#f9f5ed;text-align:center;max-width:900px}.photoModal .closeModal{color:white;position:fixed;right:25px;top:14px;font-size:35px}
.help{font-size:12px;line-height:1.45}.kbd{display:inline-block;border:1px solid #d7cfc3;border-bottom-width:2px;background:#fff;border-radius:5px;padding:1px 5px;font-size:10px}
#miniMap{height:100px;border:1px solid #ddd4c6;border-radius:10px;background:#f6f2ea;position:relative;overflow:hidden}.miniRect{position:absolute;border:1px solid #96743e;background:rgba(166,120,49,.10)}
.statusbar{position:absolute;left:12px;bottom:10px;background:rgba(255,253,248,.92);border:1px solid #ddd3c4;border-radius:10px;padding:6px 9px;font-size:11px;color:#6d655a;z-index:5;pointer-events:none}
@media(max-width:1050px){.main{grid-template-columns:220px minmax(0,1fr) 300px}.brand{min-width:220px}.brand small{display:none}}
@media(max-width:820px){.app{grid-template-rows:auto 1fr}header{flex-wrap:wrap}.brand{min-width:auto}.controls{width:100%;order:2}.main{grid-template-columns:1fr}.sidebar{display:none}.details{position:absolute;right:0;top:0;bottom:0;width:min(88vw,350px);transform:translateX(100%);transition:transform .2s;box-shadow:-8px 0 30px rgba(0,0,0,.15)}.details.mobileShow{transform:none}.canvasWrap{grid-column:1}.segment button{padding:7px 8px;font-size:12px}}

/* --------------------------------------------------------------------------
   Responsive / touch-first layer
   -------------------------------------------------------------------------- */
:root{
  --header-h:74px;
  --safe-top:env(safe-area-inset-top,0px);
  --safe-right:env(safe-area-inset-right,0px);
  --safe-bottom:env(safe-area-inset-bottom,0px);
  --safe-left:env(safe-area-inset-left,0px);
}
body{overscroll-behavior:none}
header{padding-left:max(18px,var(--safe-left));padding-right:max(18px,var(--safe-right));padding-top:max(11px,var(--safe-top))}
.canvasWrap{touch-action:none;-webkit-user-select:none;user-select:none}
.node{touch-action:manipulation}
.mobileMenuBtn{display:none;border:1px solid #d8d0c2;background:#fff;border-radius:11px;padding:9px 11px;color:#544d43;cursor:pointer;white-space:nowrap}
.drawerBackdrop{display:none;position:fixed;inset:0;background:rgba(29,25,21,.42);z-index:69;backdrop-filter:blur(2px)}
.detailsClose{display:none;position:sticky;top:8px;float:right;z-index:5;width:38px;height:38px;border-radius:50%;border:1px solid #ddd4c7;background:rgba(255,253,248,.96);font-size:24px;line-height:1;cursor:pointer;color:#655c50;box-shadow:0 4px 14px rgba(0,0,0,.12)}
.search input{min-height:42px}
.segment{overflow-x:auto;scrollbar-width:none}.segment::-webkit-scrollbar{display:none}.segment button{min-height:38px}
.iconbtn,.mobileMenuBtn{min-height:42px}
.collapse{width:30px;height:30px;bottom:-16px}
.statusbar{max-width:calc(100% - 24px);white-space:nowrap;overflow:hidden;text-overflow:ellipsis}

@media (max-width:1279px){
  .main{grid-template-columns:235px minmax(0,1fr) 300px}
  .brand{min-width:225px}
  .sidebar{padding:12px}
  .detailsBody{padding:14px}
  .galleryGrid{grid-template-columns:1fr}
}

/* Tablet: the tree gets the full canvas. Filters and details become drawers. */
@media (max-width:1023px){
  html,body{overflow:hidden}
  .app{grid-template-rows:auto minmax(0,1fr)}
  header{display:grid;grid-template-columns:1fr auto;gap:10px 12px;align-items:center;padding-bottom:10px}
  .brand{min-width:0}
  .brand small{display:block}
  .mobileMenuBtn{display:inline-flex;align-items:center;gap:6px;justify-self:end}
  .controls{grid-column:1/-1;width:100%;display:grid;grid-template-columns:minmax(0,1fr) auto auto auto;grid-template-areas:"modes modes modes modes" "search fit reset sources";gap:8px}
  #modeButtons{grid-area:modes;width:100%;justify-content:flex-start}
  .search{grid-area:search;max-width:none;min-width:0}
  #fitBtn{grid-area:fit} #resetBtn{grid-area:reset} #aboutBtn{grid-area:sources}
  .main{grid-template-columns:minmax(0,1fr);position:relative;min-height:0}
  .canvasWrap{grid-column:1;min-width:0}
  .sidebar{display:block;position:fixed;left:0;top:0;bottom:0;width:min(86vw,340px);padding:calc(16px + var(--safe-top)) 14px calc(18px + var(--safe-bottom)) max(14px,var(--safe-left));transform:translateX(-105%);transition:transform .24s ease;z-index:80;box-shadow:16px 0 48px rgba(0,0,0,.18)}
  .sidebar.drawerOpen{transform:translateX(0)}
  .drawerBackdrop.show{display:block}
  .details{display:block;position:fixed;right:0;top:0;bottom:0;width:min(88vw,380px);padding-top:var(--safe-top);transform:translateX(105%);transition:transform .24s ease;z-index:85;box-shadow:-16px 0 48px rgba(0,0,0,.20);border-left:1px solid #ded6c9}
  .details.mobileShow{transform:translateX(0)}
  .detailsClose{display:grid;place-items:center;margin:8px 10px -46px auto}
  .searchResults{top:48px;max-height:min(46vh,360px)}
  #miniMap{height:110px}
}

/* Phone: details becomes a bottom sheet and controls are compact. */
@media (max-width:767px){
  header{gap:8px;padding:calc(8px + var(--safe-top)) max(10px,var(--safe-right)) 8px max(10px,var(--safe-left))}
  .crest{width:38px;height:38px;font-size:17px}
  .brand{gap:9px}.brand h1{font-size:18px}.brand small{font-size:10px}
  .mobileMenuBtn span{display:none}.mobileMenuBtn{padding:7px 10px;min-height:38px;font-size:16px}
  .controls{grid-template-columns:minmax(0,1fr) 42px 48px 48px;gap:6px}
  .segment{border-radius:10px;padding:2px}.segment button{padding:7px 10px;font-size:12px;flex:0 0 auto}
  .search input{min-height:40px;padding:8px 34px 8px 11px;font-size:16px}
  .iconbtn{padding:7px 6px;min-height:40px;font-size:11px}
  #fitBtn{font-size:0} #fitBtn::after{content:"Fit";font-size:11px}
  #resetBtn{font-size:0} #resetBtn::after{content:"1:1";font-size:11px}
  #aboutBtn{font-size:0} #aboutBtn::after{content:"ⓘ";font-size:17px}
  .details{left:0;right:0;top:auto;bottom:0;width:100%;height:min(78dvh,720px);max-height:78dvh;border-left:0;border-top:1px solid #d7cec0;border-radius:20px 20px 0 0;padding:0 0 var(--safe-bottom);transform:translateY(105%);box-shadow:0 -18px 50px rgba(0,0,0,.23)}
  .details.mobileShow{transform:translateY(0)}
  .details::before{content:"";display:block;width:44px;height:4px;border-radius:3px;background:#c9c0b3;margin:8px auto 0;position:sticky;top:6px;z-index:4}
  .detailsClose{position:sticky;top:10px;margin:2px 10px -42px auto}
  .detailsHero{min-height:120px}.detailsHero img{height:155px}.detailsHero .placeholder{height:125px;font-size:44px}
  .detailsBody h2{font-size:21px}
  .statusbar{left:8px;bottom:calc(8px + var(--safe-bottom));font-size:10px;padding:6px 8px}
  .node{border-radius:13px;padding:9px 10px;box-shadow:0 4px 12px rgba(40,32,22,.09)}
  .node h4{font-size:12.5px}.partner{font-size:10px}.avatar{width:34px;height:34px;flex-basis:34px}
  .badge{font-size:9px;padding:2px 5px}
  .modalBox{max-height:92dvh;border-radius:16px;padding:17px;margin-top:var(--safe-top);margin-bottom:var(--safe-bottom)}
  .aboutModal,.photoModal{padding:10px}
  .photoBox img{max-width:95vw;max-height:72dvh}
}

@media (max-width:430px){
  .brand small{display:none}
  .brand h1{font-size:17px}
  .controls{grid-template-columns:minmax(0,1fr) 40px 44px 44px}
  .segment button{font-size:11px;padding:7px 8px}
  .sidebar{width:min(92vw,330px)}
  .card{padding:10px;margin-bottom:8px}
  .galleryGrid{grid-template-columns:1fr 1fr}
  .galleryItem img{height:82px}
}

@media (max-height:620px) and (orientation:landscape){
  .brand small{display:none}
  header{grid-template-columns:auto 1fr auto;padding-top:max(6px,var(--safe-top));padding-bottom:6px}
  .controls{grid-column:auto;grid-template-columns:minmax(280px,1fr) minmax(170px,.7fr) auto auto auto;grid-template-areas:"modes search fit reset sources"}
  .details{top:0;bottom:0;left:auto;width:min(58vw,390px);height:100%;max-height:none;border-radius:0;transform:translateX(105%)}
  .details.mobileShow{transform:translateX(0)}
}

@media (prefers-reduced-motion:reduce){*{scroll-behavior:auto!important;transition:none!important;animation:none!important}}

