/* ============================================
   Delingpole family — interactive genealogical map
   Shares the palette of the main site / memoir reader
   ============================================ */

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --color-bg: #faf8f4;
  --color-bg-alt: #f4f1ea;
  --color-text: #16150f;
  --color-muted: #6c685c;
  --color-faint: #9b978a;
  --color-border: #e4dfd3;
  --color-border-strong: #d6d0c1;
  --color-surface: #ffffff;

  --accent: #0f6b54;
  --accent-soft: #1c8a6e;
  --accent-wash: #e7f2ee;
  --accent-rgb: 15, 107, 84;

  --strong: #9a5b1e;          /* maternal (Strong) line accent */
  --strong-wash: #f4ebdf;
  --line: #cbc4b4;

  --font-serif: 'Georgia', 'Times New Roman', serif;
  --transition: 0.25s cubic-bezier(.4,0,.2,1);
}

html[data-theme="dark"] {
  --color-bg: #14130f;
  --color-bg-alt: #1c1a15;
  --color-text: #f3f0e8;
  --color-muted: #a8a496;
  --color-faint: #76736a;
  --color-border: #2c2a23;
  --color-border-strong: #3a382f;
  --color-surface: #1f1d17;

  --accent: #4cc7a4;
  --accent-soft: #6fe0bf;
  --accent-wash: #15302a;
  --accent-rgb: 76, 199, 164;

  --strong: #d6a86a;
  --strong-wash: #2e2618;
  --line: #423f35;
}

html { scroll-behavior: smooth; }
body.family-body {
  background: var(--color-bg);
  color: var(--color-text);
  font-family: var(--font-serif);
  line-height: 1.7;
  -webkit-font-smoothing: antialiased;
  overflow-x: hidden;
  transition: background-color var(--transition), color var(--transition);
}
a { color: var(--accent); text-underline-offset: 3px; }
::selection { background: var(--accent); color: #fff; }

/* ---------- top bar (shared look with reader) ---------- */
.reader-bar {
  position: sticky; top: 0; z-index: 60;
  display: flex; align-items: center; gap: 0.75rem;
  height: 56px; padding: 0 clamp(0.75rem, 3vw, 1.75rem);
  background: color-mix(in srgb, var(--color-bg) 88%, transparent);
  backdrop-filter: saturate(1.2) blur(10px);
  -webkit-backdrop-filter: saturate(1.2) blur(10px);
  border-bottom: 1px solid var(--color-border);
}
.bar-home { font-size: 0.82rem; letter-spacing: 0.04em; text-transform: uppercase; text-decoration: none; color: var(--color-muted); white-space: nowrap; }
.bar-home:hover { color: var(--accent); }
.bar-title { flex: 1; text-align: center; font-size: 0.86rem; color: var(--color-faint); font-style: italic; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.bar-tools { display: flex; align-items: center; gap: 0.35rem; }
.bar-btn {
  display: inline-flex; align-items: center; justify-content: center;
  font-family: var(--font-serif); font-size: 0.85rem; color: var(--color-text);
  background: transparent; border: 1px solid transparent; border-radius: 8px;
  padding: 0.4rem 0.7rem; cursor: pointer; text-decoration: none;
  transition: background var(--transition), border-color var(--transition), color var(--transition);
}
.bar-btn:hover { background: var(--color-bg-alt); border-color: var(--color-border); }
.bar-btn.icon { min-width: 38px; font-weight: 600; }
.theme-icon { font-size: 1rem; line-height: 1; }
html[data-theme="dark"] .theme-icon.moon { display: none; }
html:not([data-theme="dark"]) .theme-icon.sun { display: none; }

/* ---------- intro ---------- */
.family-intro { max-width: 760px; margin: 0 auto; padding: clamp(2rem, 6vw, 3.5rem) 1.5rem 1.5rem; text-align: center; }
.fi-eyebrow { font-size: 0.78rem; letter-spacing: 0.24em; text-transform: uppercase; color: var(--accent); margin-bottom: 0.8rem; }
.family-intro h1 { font-size: clamp(2.1rem, 7vw, 3.4rem); font-weight: 400; line-height: 1.05; letter-spacing: -0.01em; }
.fi-lead { margin: 1rem auto 0; color: var(--color-muted); max-width: 38rem; }

.legend { display: flex; flex-wrap: wrap; gap: 0.5rem 1rem; justify-content: center; margin-top: 1.4rem; font-size: 0.78rem; color: var(--color-muted); }
.lg { display: inline-flex; align-items: center; gap: 0.4rem; }
.lg::before { content: ""; width: 12px; height: 12px; border-radius: 3px; border: 1px solid var(--line); }
.lg-self::before { background: var(--accent); border-color: var(--accent); }
.lg-delingpole::before { background: var(--accent-wash); border-color: var(--accent); }
.lg-strong::before { background: var(--strong-wash); border-color: var(--strong); }
.lg-spouse::before { background: var(--color-surface); }
.lg-step::before { background: var(--color-surface); border-style: dashed; }

/* ---------- tree viewport ---------- */
.tree-viewport {
  position: relative;
  height: min(74vh, 760px);
  margin: 0.5rem clamp(0.5rem, 3vw, 2rem) 2rem;
  border: 1px solid var(--color-border);
  border-radius: 14px;
  background:
    radial-gradient(circle at 1px 1px, var(--color-border) 1px, transparent 0) 0 0 / 26px 26px,
    var(--color-bg-alt);
  overflow: hidden;
  cursor: grab;
  touch-action: none;
}
.tree-viewport.grabbing { cursor: grabbing; }

.tree-stage { position: absolute; top: 0; left: 0; transform-origin: 0 0; will-change: transform; }
.tree-links { position: absolute; top: 0; left: 0; overflow: visible; pointer-events: none; }

.tree-nodes { position: absolute; top: 0; left: 0; }

/* person card */
.person {
  position: absolute;
  width: 168px;
  transform: translate(-50%, -50%);
  background: var(--color-surface);
  border: 1px solid var(--color-border-strong);
  border-left: 4px solid var(--line);
  border-radius: 10px;
  padding: 0.55rem 0.7rem;
  cursor: pointer;
  box-shadow: 0 4px 14px rgba(0,0,0,0.06);
  transition: transform .15s ease, box-shadow .15s ease, border-color .15s ease;
  text-align: left;
}
.person:hover { box-shadow: 0 10px 26px rgba(0,0,0,0.14); border-color: var(--accent); z-index: 5; }
.person .p-name { font-size: 0.92rem; line-height: 1.2; }
.person .p-sub { font-size: 0.72rem; color: var(--color-muted); margin-top: 0.15rem; line-height: 1.25; }
.person .p-life { font-size: 0.7rem; color: var(--color-faint); font-style: italic; margin-top: 0.1rem; }

.person.side-delingpole { border-left-color: var(--accent); background: color-mix(in srgb, var(--accent-wash) 55%, var(--color-surface)); }
.person.side-strong { border-left-color: var(--strong); background: color-mix(in srgb, var(--strong-wash) 55%, var(--color-surface)); }
.person.side-spouse { border-left-color: var(--color-border-strong); }
.person.side-step { border-left-style: dashed; border-left-color: var(--color-faint); }
.person.side-self {
  border-color: var(--accent); border-left-color: var(--accent);
  background: var(--accent); color: #fff; width: 184px;
  box-shadow: 0 8px 24px rgba(var(--accent-rgb), 0.4);
}
.person.side-self .p-sub, .person.side-self .p-life { color: rgba(255,255,255,0.85); }
.person.dim { opacity: 0.32; }
.person.active { outline: 2px solid var(--accent); outline-offset: 2px; }

/* controls + hint */
.tree-controls { position: absolute; top: 12px; right: 12px; z-index: 10; display: flex; flex-direction: column; gap: 6px; }
.tree-controls button {
  width: 38px; height: 38px; border-radius: 9px;
  background: var(--color-surface); border: 1px solid var(--color-border-strong);
  color: var(--color-text); font-size: 1.1rem; cursor: pointer; font-family: var(--font-serif);
  box-shadow: 0 2px 8px rgba(0,0,0,0.08);
  transition: background var(--transition), border-color var(--transition);
}
.tree-controls button:hover { background: var(--color-bg-alt); border-color: var(--accent); color: var(--accent); }
.tree-hint { position: absolute; left: 12px; bottom: 10px; z-index: 10; font-size: 0.72rem; color: var(--color-faint); background: color-mix(in srgb, var(--color-bg) 80%, transparent); padding: 0.2rem 0.5rem; border-radius: 6px; pointer-events: none; }

/* ---------- biography drawer ---------- */
.bio {
  position: fixed; top: 0; right: 0; bottom: 0;
  width: min(440px, 92vw); z-index: 90;
  background: var(--color-surface); border-left: 1px solid var(--color-border);
  transform: translateX(104%); transition: transform var(--transition);
  overflow-y: auto; box-shadow: -8px 0 40px rgba(0,0,0,0.16);
}
.bio.open { transform: translateX(0); }
.bio-close { position: absolute; top: 0.8rem; right: 1rem; background: none; border: none; font-size: 1.8rem; line-height: 1; color: var(--color-muted); cursor: pointer; z-index: 2; }
.bio-close:hover { color: var(--color-text); }
.bio-inner { padding: 2.4rem 1.8rem 3rem; }

.bio-tag { display: inline-block; font-size: 0.72rem; letter-spacing: 0.14em; text-transform: uppercase; color: var(--accent); margin-bottom: 0.6rem; }
.bio-name { font-size: 1.7rem; font-weight: 400; line-height: 1.1; letter-spacing: -0.01em; }
.bio-life { color: var(--color-faint); font-style: italic; margin-top: 0.3rem; }
.bio-rule { width: 48px; height: 2px; background: var(--accent); margin: 1.3rem 0; }
.bio-body p { margin: 0 0 1rem; }
.bio-rel { margin-top: 1.6rem; padding-top: 1.2rem; border-top: 1px solid var(--color-border); font-size: 0.9rem; }
.bio-rel h4 { font-size: 0.72rem; letter-spacing: 0.14em; text-transform: uppercase; color: var(--color-faint); font-weight: 400; margin-bottom: 0.5rem; }
.bio-rel .rel-row { margin-bottom: 0.35rem; }
.bio-rel .rel-row span { color: var(--color-muted); }
.bio-rel a { cursor: pointer; text-decoration: underline; text-decoration-color: var(--color-border-strong); }
.bio-rel a:hover { text-decoration-color: var(--accent); }

.bio-scrim { position: fixed; inset: 0; z-index: 80; background: rgba(0,0,0,0.3); opacity: 0; transition: opacity var(--transition); }
.bio-scrim.show { opacity: 1; }

@media (max-width: 560px) {
  .person { width: 150px; }
  .person.side-self { width: 160px; }
}
