/* The Hancock Family Archive — stylesheet.
   Warm paper + serif aesthetic carried from the canonical tree, plus a search sidebar,
   an About overlay, and a mobile-first responsive layout. */
:root {
  --paper: #eef1ec;
  --card: #fbfcfa;
  --ink: #1d2420;
  --muted: #5b655f;
  --line: #a9b4ac;
  --rule: #d3d9d2;
  --qld: #2f6b4f;
  --qld-soft: #e1ede5;
  --eng: #3a5378;
  --eng-soft: #e1e8f2;
  --mark: #8a5a12;
  --panel-bg: #fbfcfa;
  --f-display: "Gloock", "Georgia", "Times New Roman", serif;
  --f-body: "Source Serif 4", "Georgia", "Times New Roman", serif;
  --f-data: "IBM Plex Mono", ui-monospace, "SFMono-Regular", Menlo, monospace;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --paper: #121614; --card: #1b201d; --ink: #e6ebe7; --muted: #9ba59f; --line: #4a554e; --rule: #2e3631;
    --qld: #7cc4a0; --qld-soft: #1d2c24; --eng: #9db6dd; --eng-soft: #1d2431; --mark: #e0b268; --panel-bg: #1b201d;
  }
}
html, body { height: 100%; }
* { box-sizing: border-box; }
body {
  margin: 0; background: var(--paper); color: var(--ink); font-family: var(--f-body);
  display: flex; flex-direction: column; overflow: hidden; -webkit-text-size-adjust: 100%;
}

/* ---- Header ---- */
header {
  padding-left: max(16px, env(safe-area-inset-left, 0px));
  padding-right: max(16px, env(safe-area-inset-right, 0px));
  padding-block: 11px 10px;
  display: flex; flex-wrap: wrap; align-items: baseline; gap: 4px 16px;
  border-bottom: 1px solid var(--rule); background: var(--paper); z-index: 5;
}
h1 { font-family: var(--f-display); font-weight: 400; font-size: clamp(20px, 3.4vw, 32px); margin: 0; line-height: 1.1; }
.sub { font-size: 13.5px; color: var(--muted); }
.key { display: flex; flex-wrap: wrap; gap: 6px 14px; font-family: var(--f-data); font-size: 11.5px; color: var(--muted); margin-left: auto; align-items: center; }
.key i { display: inline-block; width: 18px; height: 0; border-top: 3px solid; vertical-align: middle; margin-right: 6px; }
.key .q i { border-color: var(--qld); } .key .e i { border-color: var(--eng); } .key .l i { border-top-style: dashed; border-color: var(--mark); }
.hdr-btns { display: flex; gap: 8px; margin-left: auto; align-items: center; }
.hdr-btn {
  font: 500 13px/1 var(--f-data); padding: 7px 12px; border-radius: 7px;
  border: 1px solid var(--rule); background: var(--card); color: var(--ink); cursor: pointer;
}
.hdr-btn:hover { border-color: var(--ink); }
.hdr-btn:focus-visible { outline: 2px solid var(--ink); outline-offset: 2px; }

/* ---- Main layout: sidebar + stage ---- */
#main { flex: 1; display: flex; min-height: 0; position: relative; }

#sidebar {
  width: 340px; flex: 0 0 340px; background: var(--card); border-right: 1px solid var(--rule);
  display: flex; flex-direction: column; min-height: 0; z-index: 4;
  transition: transform .22s ease;
}
#sidebar .search-wrap { padding: 12px 14px 8px; border-bottom: 1px solid var(--rule); }
#search {
  width: 100%; font-family: var(--f-body); font-size: 16px; padding: 10px 12px;
  border: 1px solid var(--line); border-radius: 8px; background: var(--paper); color: var(--ink);
}
#search:focus-visible { outline: 2px solid var(--eng); outline-offset: 0; border-color: var(--eng); }
.search-note { font-family: var(--f-data); font-size: 11px; color: var(--muted); margin-top: 6px; }
#results { flex: 1; overflow-y: auto; -webkit-overflow-scrolling: touch; padding: 6px 8px 16px; }
.result {
  display: block; width: 100%; text-align: left; background: none; border: 0; cursor: pointer;
  padding: 9px 10px; border-radius: 8px; border-left: 3px solid transparent; color: inherit;
  font-family: var(--f-body);
}
.result:hover, .result:focus-visible { background: var(--paper); outline: none; }
.result.q { border-left-color: var(--qld); } .result.e { border-left-color: var(--eng); } .result.r { border-left-color: var(--ink); }
.result .rn { font-size: 15px; font-weight: 600; line-height: 1.25; }
.result .rd { font-family: var(--f-data); font-size: 11px; color: var(--muted); margin-top: 2px; }
.result mark { background: #f4e2b8; color: inherit; border-radius: 2px; padding: 0 1px; }
@media (prefers-color-scheme: dark) { .result mark { background: #5a4a1e; } }
.result .rpct { font-family: var(--f-data); font-size: 11px; color: var(--muted); float: right; }
.no-results { padding: 16px 12px; color: var(--muted); font-size: 14px; }
/* Contact line sits directly under the search panel, same side column */
.contact-wrap { flex: 0 0 auto; border-top: 1px solid var(--rule); background: var(--qld-soft); padding: 13px 15px calc(13px + env(safe-area-inset-bottom, 0px)); }
.contact-wrap p { margin: 0; font-size: 13.5px; line-height: 1.5; color: var(--ink); }
.contact-wrap a { color: var(--eng); font-weight: 600; word-break: break-word; }

/* ---- Stage ---- */
#stage { position: relative; flex: 1; overflow: hidden; touch-action: none; cursor: grab; background: var(--paper); }
#stage.dragging { cursor: grabbing; }
svg#svg { width: 100%; height: 100%; display: block; user-select: none; -webkit-user-select: none; }

.link { fill: none; stroke: var(--line); stroke-width: 1.6; }
.node rect.box { fill: var(--card); stroke: var(--rule); stroke-width: 1; }
.node rect.band { stroke: none; }
.node.qld rect.band { fill: var(--qld); } .node.eng rect.band { fill: var(--eng); } .node.root rect.band { fill: var(--ink); }
.node.likely rect.box { stroke: var(--mark); stroke-dasharray: 5 4; stroke-width: 1.4; }
.node.unknown rect.box { fill: none; stroke-dasharray: 4 4; }
.node text.n { font-family: var(--f-body); font-weight: 600; font-size: 15px; fill: var(--ink); }
.node.unknown text.n { font-weight: 400; font-style: italic; fill: var(--muted); }
.node text.d { font-family: var(--f-data); font-size: 11px; fill: var(--muted); }
.node { cursor: pointer; }
.node:hover rect.box, .node.sel rect.box { stroke: var(--ink); stroke-width: 1.6; }
.node.hit rect.box { stroke: var(--eng); stroke-width: 2.6; }
.node:focus-visible { outline: none; } .node:focus-visible rect.box { stroke: var(--ink); stroke-width: 2.4; }
.node .pct { font-family: var(--f-data); font-size: 11px; fill: var(--muted); }
.gapwire { stroke-dasharray: 2 7; stroke-linecap: round; stroke-width: 2.2; }
.gapwire.open { stroke: var(--mark); }
.deepwire { stroke-dasharray: 1 6; stroke-linecap: round; stroke-width: 1.6; }
.node.grpnode rect.box { fill: var(--qld-soft); }
.node.eng.grpnode rect.box { fill: var(--eng-soft); }
.node.deepnode rect.box { fill: var(--paper); stroke: var(--muted); stroke-width: 1.4; }
.node.gapnode rect.box { fill: none; stroke: var(--mark); stroke-dasharray: 6 5; stroke-width: 1.4; }
.node.gapnode text.n { font-style: italic; }
.node.collat rect.box { fill: #eef4f1; stroke: #5a8f74; stroke-dasharray: 3 3; stroke-width: 1.3; }
.node.collat rect.band { fill: #5a8f74; }
.node.collat text.n { font-size: 14px; }
@media (prefers-color-scheme: dark) { .node.collat rect.box { fill: #1a2622; } }
.cbar-title { font-family: var(--f-display); font-size: 30px; fill: var(--ink); }
.cbar-grid { stroke: var(--rule); stroke-width: 1; }
.cbar-grid.t70 { stroke: var(--mark); stroke-dasharray: 6 6; }
.cbar-axis, .cbar-lab { font-family: var(--f-data); font-size: 13px; fill: var(--muted); }
.cbar-line { fill: none; stroke: var(--ink); stroke-width: 3; stroke-dasharray: 2 9; stroke-linecap: round; }
.cbar-dot { fill: var(--card); stroke: var(--ink); stroke-width: 2.5; }
.cbar-val { font-family: var(--f-data); font-size: 15px; font-weight: 500; fill: var(--ink); }
.side-title { font-family: var(--f-display); font-size: 34px; }
.side-title.qld { fill: var(--qld); } .side-title.eng { fill: var(--eng); }
.gen-tag { font-family: var(--f-data); font-size: 11px; letter-spacing: .1em; fill: var(--muted); text-transform: uppercase; }
.marr-t { font-family: var(--f-data); font-size: 10.5px; fill: var(--muted); }

/* ---- Controls ---- */
.controls { position: absolute; right: max(12px, env(safe-area-inset-right, 0px)); bottom: calc(12px + env(safe-area-inset-bottom, 0px)); display: flex; gap: 6px; z-index: 3; }
.controls button { font: 500 18px/1 var(--f-data); width: 44px; height: 44px; border-radius: 22px; border: 1px solid var(--rule); background: var(--card); color: var(--ink); cursor: pointer; }
.controls button.wide { width: auto; padding: 0 14px; font-size: 13px; }
.controls button:focus-visible { outline: 2px solid var(--ink); outline-offset: 2px; }
.hint { position: absolute; left: max(12px, env(safe-area-inset-left, 0px)); bottom: calc(14px + env(safe-area-inset-bottom, 0px)); font-family: var(--f-data); font-size: 11.5px; color: var(--muted); background: var(--paper); padding: 4px 8px; border-radius: 4px; z-index: 3; }

/* ---- Detail panel ---- */
#panel {
  position: absolute; top: 12px; right: max(12px, env(safe-area-inset-right, 0px)); width: min(380px, calc(100% - 24px));
  max-height: calc(100% - 80px); overflow: auto; background: var(--panel-bg); border: 1px solid var(--rule); border-radius: 8px;
  padding: 16px 18px; display: grid; gap: 8px; box-shadow: 0 10px 30px rgba(0,0,0,.18); z-index: 6;
}
#panel[hidden] { display: none; }
#panel .side { font-family: var(--f-data); font-size: 11px; letter-spacing: .1em; text-transform: uppercase; }
#panel .side.qld { color: var(--qld); } #panel .side.eng { color: var(--eng); } #panel .side.root { color: var(--muted); }
#panel h2 { font-family: var(--f-display); font-weight: 400; font-size: 26px; margin: 0; line-height: 1.15; text-wrap: balance; padding-right: 30px; }
#panel dl { margin: 0; display: grid; grid-template-columns: auto 1fr; gap: 4px 12px; font-size: 15px; }
#panel dt { font-family: var(--f-data); font-size: 12px; color: var(--muted); padding-top: 2px; }
#panel dd { margin: 0; }
#panel p { margin: 0; font-size: 15px; line-height: 1.5; }
#panel .src { font-family: var(--f-data); font-size: 11.5px; color: var(--muted); line-height: 1.5; border-top: 1px dashed var(--rule); padding-top: 8px; }
#panel .flag { font-family: var(--f-data); font-size: 11px; color: var(--mark); text-transform: uppercase; letter-spacing: .06em; }
#panel figure.ph { margin: 0; display: grid; gap: 6px; }
#panel figure.ph img { width: 100%; max-width: 100%; border-radius: 4px; border: 1px solid var(--rule); background: var(--paper); min-height: 40px; }
#panel .conf { font-family: var(--f-data); font-size: 12px; color: var(--muted); margin: 2px 0 6px; }
#panel .ab { display:flex; gap:16px; flex-wrap: wrap; font-family: var(--f-data); font-size:12px; color:var(--muted); margin:2px 0 7px; }
#panel .ab b { color:var(--ink); font-weight:600; }
#panel .toconfirm { background: #fbf3e4; border-left: 3px solid #c79a4e; padding: 7px 10px; border-radius: 4px; font-size: 13.5px; color: #3a2e12; }
@media (prefers-color-scheme: dark) { #panel .toconfirm { background: #2c2512; color: #e8d9b4; } }
#panel figure.ph figcaption { font-family: var(--f-data); font-size: 11.5px; color: var(--muted); line-height: 1.5; }
#panel button.close { position: absolute; top: 8px; right: 8px; width: 40px; height: 40px; border: 0; background: none; color: var(--muted); font-size: 24px; line-height: 1; cursor: pointer; border-radius: 20px; }
#panel button.close:hover { background: var(--paper); color: var(--ink); }
#panel button.close:focus-visible { outline: 2px solid var(--ink); outline-offset: 1px; }

/* ---- About overlay ---- */
#about {
  position: fixed; inset: 0; z-index: 20; background: rgba(0,0,0,.45);
  display: flex; align-items: flex-start; justify-content: center; padding: 24px 16px; overflow-y: auto;
}
#about[hidden] { display: none; }
#about .about-card {
  background: var(--panel-bg); color: var(--ink); max-width: 680px; width: 100%;
  border-radius: 12px; padding: 28px 30px 32px; box-shadow: 0 20px 60px rgba(0,0,0,.35); position: relative;
  margin: auto;
}
#about h2 { font-family: var(--f-display); font-weight: 400; font-size: 30px; margin: 0 0 4px; }
#about h3 { font-family: var(--f-display); font-weight: 400; font-size: 20px; margin: 22px 0 6px; }
#about p { font-size: 15.5px; line-height: 1.6; margin: 0 0 12px; }
#about ul { font-size: 15px; line-height: 1.55; padding-left: 20px; margin: 0 0 12px; }
#about li { margin-bottom: 8px; }
#about .swatch { display: inline-block; width: 12px; height: 12px; border-radius: 3px; vertical-align: middle; margin-right: 6px; }
#about .dashed-demo { display:inline-block; width: 26px; height: 15px; border: 1.4px dashed #5a8f74; border-radius: 3px; vertical-align: middle; margin-right: 6px; }
#about .contact { background: var(--qld-soft); border-radius: 8px; padding: 14px 16px; font-size: 15px; line-height: 1.55; margin-top: 18px; }
#about .contact a { color: var(--eng); font-weight: 600; }
#about button.close {
  position: absolute; top: 14px; right: 14px; width: 40px; height: 40px; border: 0; background: none;
  color: var(--muted); font-size: 26px; cursor: pointer; border-radius: 20px; line-height: 1;
}
#about button.close:hover { background: var(--paper); color: var(--ink); }
#about button.close:focus-visible { outline: 2px solid var(--ink); }
.about-footer { margin-top: 20px; font-family: var(--f-data); font-size: 12px; color: var(--muted); }

/* ---- Sidebar toggle (mobile) ---- */
#sidebar-toggle { display: none; }
#scrim { display: none; }

/* ---- Loading screen: the growing oak ---- */
#loader {
  position: fixed; inset: 0; z-index: 50; background: radial-gradient(ellipse at 50% 42%, #f4f6f1 0%, var(--paper) 62%, #e4e8e0 100%);
  display: flex; align-items: center; justify-content: center;
  transition: opacity 1.1s ease; opacity: 1;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) #loader { background: radial-gradient(ellipse at 50% 42%, #1a211d 0%, var(--paper) 60%, #0d110f 100%); }
}
#loader.fade-out { opacity: 0; pointer-events: none; }
#loader.gone { display: none; }
.loader-inner { display: flex; flex-direction: column; align-items: center; gap: 2px; width: min(380px, 80vw); }
#loader-tree { width: 100%; height: auto; display: block; }
.oak-ground { stroke: var(--line); stroke-width: 1.2; opacity: 0; animation: oak-ground-in 1.2s ease 0.1s forwards; }
@keyframes oak-ground-in { to { opacity: .55; } }
/* Each path draws itself via dash offset. Roots grow downward, branches upward — staggered. */
.oak-branches path, .oak-roots path {
  stroke: var(--mark);
  stroke-dasharray: 160; stroke-dashoffset: 160;
}
.oak-branches path { stroke-width: 3.2; animation: oak-grow 2.2s cubic-bezier(.33,.7,.3,1) forwards; }
.oak-roots path { stroke-width: 2.5; stroke: #7a5a2a; opacity: .9; animation: oak-grow 2.4s cubic-bezier(.33,.7,.3,1) forwards; }
@keyframes oak-grow { to { stroke-dashoffset: 0; } }
/* lush canopy glow + leaves blooming after the branches grow */
.oak-canopy { fill: #4e7a46; opacity: 0; filter: blur(17px); animation: oak-canopy-in 2.4s ease .8s forwards; }
@keyframes oak-canopy-in { to { opacity: .3; } }
.oak-leaves circle { opacity: 0; fill: #5c8a4e; animation: leaf-in 1.4s ease forwards; }
.oak-leaves circle:nth-child(3n+1) { fill: #6f9a56; animation-delay: 1.35s; }
.oak-leaves circle:nth-child(3n+2) { fill: #4f7a44; animation-delay: 1.55s; }
.oak-leaves circle:nth-child(3n) { fill: #80ae5e; animation-delay: 1.72s; }
@keyframes leaf-in { from { opacity: 0; } to { opacity: .92; } }
/* Stagger: trunk first, then limbs, then twigs; roots alongside */
.oak-branches .trunk { animation-delay: .15s; }
.oak-branches path:nth-child(2) { animation-delay: .55s; }
.oak-branches path:nth-child(3) { animation-delay: .7s; }
.oak-branches path:nth-child(4) { animation-delay: .62s; }
.oak-branches path:nth-child(5) { animation-delay: .78s; }
.oak-branches path:nth-child(6) { animation-delay: .9s; }
.oak-branches path:nth-child(7) { animation-delay: 1.02s; }
.oak-branches path:nth-child(n+8) { animation-delay: 1.15s; }
.oak-branches path:nth-child(n+12) { animation-delay: 1.35s; }
.oak-roots path:nth-child(1) { animation-delay: .4s; }
.oak-roots path:nth-child(2) { animation-delay: .72s; }
.oak-roots path:nth-child(3) { animation-delay: .5s; }
.oak-roots path:nth-child(4) { animation-delay: .82s; }
.oak-roots path:nth-child(5) { animation-delay: .35s; }
.oak-roots path:nth-child(6) { animation-delay: .68s; }
.oak-roots path:nth-child(n+7) { animation-delay: .95s; }
.loader-title { font-family: var(--f-display); font-size: clamp(18px, 4.5vw, 24px); color: var(--ink); margin-top: 10px; opacity: 0; animation: oak-fade-in 1s ease 1.1s forwards; text-align: center; }
.loader-sub { font-family: var(--f-data); font-size: 12px; color: var(--muted); letter-spacing: .04em; opacity: 0; animation: oak-fade-in 1s ease 1.5s forwards; }
@keyframes oak-fade-in { to { opacity: 1; } }
@media (prefers-reduced-motion: reduce) {
  .oak-branches path, .oak-roots path { animation: none; stroke-dashoffset: 0; }
  .loader-title, .loader-sub, .oak-ground { animation: none; opacity: 1; }
  .oak-leaves circle { animation: none; opacity: .92; }
  .oak-canopy { animation: none; opacity: .3; }
  #loader { transition: opacity .3s ease; }
}

/* ---- Tablet / iPad (portrait & landscape, ~760–1100px) ---- */
@media (min-width: 761px) and (max-width: 1100px) {
  #sidebar { width: 300px; flex-basis: 300px; }
  .sub { display: none; }           /* free up header room on tablet */
  #panel { width: min(360px, 44%); }
  /* larger, finger-friendly controls for touch tablets */
  .controls button { width: 48px; height: 48px; border-radius: 24px; }
  .controls button.wide { width: auto; }
  .result { padding: 11px 10px; }   /* taller tap targets */
  .hdr-btn { padding: 9px 13px; }
}

/* ---- Mobile ---- */
@media (max-width: 760px) {
  header { gap: 2px 10px; padding-block: 9px 8px; }
  .sub { display: none; }
  .key { display: none; }
  .hdr-btns { width: 100%; margin-left: 0; margin-top: 4px; }
  #sidebar-toggle { display: inline-block; }

  #sidebar {
    position: absolute; top: 0; left: 0; bottom: 0; width: min(85vw, 340px); flex-basis: auto;
    transform: translateX(-100%); box-shadow: 4px 0 24px rgba(0,0,0,.25);
  }
  body.sidebar-open #sidebar { transform: translateX(0); }
  body.sidebar-open #scrim { display: block; position: absolute; inset: 0; z-index: 3; background: rgba(0,0,0,.3); }

  #panel { width: calc(100% - 20px); left: 10px; right: 10px; top: 10px; max-height: calc(100% - 40px); }
  #panel h2 { font-size: 23px; }
  #about .about-card { padding: 22px 18px 26px; }
  #about h2 { font-size: 25px; }
}
