/* ---------- Tree view ---------- */
.view--tree {
  position: relative;
  height: calc(100dvh - var(--header-h));
  overflow: hidden;
  background:
    radial-gradient(1200px 600px at 20% -10%, color-mix(in oklch, var(--gold-soft) 60%, transparent), transparent 60%),
    radial-gradient(900px 500px at 100% 110%, color-mix(in oklch, var(--lagoon-soft) 50%, transparent), transparent 60%),
    var(--paper);
}
.tree-canvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  touch-action: none;
  cursor: grab;
  user-select: none;
  -webkit-user-select: none;
}
.tree-canvas:active {
  cursor: grabbing;
}
.tree-viewport {
  transform-origin: 0 0;
  will-change: transform;
}

/* nodes */
.tnode {
  cursor: pointer;
  outline: none;
}
.tnode:focus-visible .tcard__bg {
  stroke: var(--focus);
  stroke-width: 2.5;
}
.tcard__bg {
  fill: var(--paper-raise);
  stroke: var(--rule-strong);
  stroke-width: 1;
  filter: drop-shadow(0 2px 4px oklch(20% 0.03 60 / 0.08));
  transition: stroke var(--duration-fast), fill var(--duration-fast);
}
.tnode:hover .tcard__bg {
  stroke: var(--ink);
}
.tcard__bar {
  fill: var(--rule-strong);
}
.tnode--royal .tcard__bar {
  fill: var(--royal);
}
.tnode--maternal .tcard__bar {
  fill: var(--lagoon);
}
.tnode--both .tcard__bar {
  fill: url(#bar-both);
}
.tnode--root .tcard__bg {
  stroke: var(--gold-ink);
  stroke-width: 1.6;
}
.tcard__name {
  font-family: var(--font-body);
  font-size: 13px;
  font-weight: 600;
  fill: var(--ink);
}
.tcard__sub {
  font-family: var(--font-body);
  font-size: 11px;
  fill: var(--muted);
}
.tnode--deceased .tcard__name {
  fill: var(--ink-2);
}
.tnode--placeholder .tcard__bg {
  stroke-dasharray: 4 3;
  fill: var(--paper-2);
}
.tnode--placeholder .tcard__name {
  font-weight: 500;
  font-style: italic;
  fill: var(--muted);
}
.tcard__star {
  fill: var(--gold);
  stroke: var(--gold-ink);
  stroke-width: 0.8;
}
.tcard__deceased {
  fill: none;
  stroke: var(--muted);
  stroke-width: 1.2;
}

/* spouse chips */
.tchip__bg {
  fill: color-mix(in oklch, var(--paper-raise) 70%, var(--paper-2));
  stroke: var(--rule);
  stroke-width: 1;
}
.tchip:hover .tchip__bg {
  stroke: var(--ink);
}
.tchip__name {
  font-family: var(--font-body);
  font-size: 12px;
  font-weight: 500;
  fill: var(--ink-2);
}
.tchip__sub {
  font-family: var(--font-body);
  font-size: 10.5px;
  fill: var(--muted);
}
.tchip--unknown .tchip__bg {
  stroke-dasharray: 3 3;
  fill: transparent;
}
.tchip--unknown .tchip__name {
  font-style: italic;
  fill: var(--muted);
}
.tchip__tie {
  stroke: var(--rule-strong);
  stroke-width: 1.4;
}
.tchip__ring {
  fill: var(--paper);
  stroke: var(--rule-strong);
  stroke-width: 1.4;
}
.tbadge__bg {
  fill: var(--ink);
}
.tbadge__text {
  font-family: var(--font-body);
  font-size: 9px;
  font-weight: 700;
  fill: var(--paper);
  text-anchor: middle;
}

/* links */
.tlink {
  fill: none;
  stroke: var(--rule-strong);
  stroke-width: 1.4;
  transition: stroke var(--duration-fast), opacity var(--duration);
}
.tlink--loose {
  stroke-dasharray: 5 5;
}
.tlink.is-path {
  stroke: var(--gold-ink);
  stroke-width: 2.4;
}
.tnode.is-dim,
.tlink.is-dim {
  opacity: 0.32;
}
.tnode.is-path .tcard__bg {
  stroke: var(--gold-ink);
  stroke-width: 1.8;
}
.tnode.is-selected .tcard__bg {
  stroke: var(--ink);
  stroke-width: 2.4;
  fill: var(--gold-soft);
}
.tnode,
.tlink {
  transition: opacity var(--duration);
}

/* generation labels */
.tgen {
  font-family: var(--font-display);
  font-size: 13px;
  font-style: italic;
  fill: var(--muted);
  text-anchor: end;
}
.tgen--rule {
  stroke: var(--rule);
  stroke-dasharray: 2 6;
  stroke-width: 1;
}

/* ---------- controls ---------- */
.tree-panel {
  position: absolute;
  z-index: 5;
  top: var(--space-4);
  left: var(--space-4);
  width: 300px;
  max-height: calc(100% - var(--space-4) * 2);
  overflow: auto;
  background: color-mix(in oklch, var(--paper-raise) 88%, transparent);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border: 1px solid var(--rule);
  border-radius: var(--radius-l);
  box-shadow: var(--shadow-2);
  padding: var(--space-4);
  display: grid;
  gap: var(--space-4);
}
.tree-panel__label {
  font-size: var(--text-xs);
  font-weight: 600;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--muted);
  margin-bottom: var(--space-2);
}
.tree-panel__title {
  font-family: var(--font-display);
  font-size: 1.15rem;
  line-height: 1.2;
  margin: 0;
}
.tree-panel__quick {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-1);
  margin-top: var(--space-2);
}
.tree-panel__quick button {
  border: 1px solid var(--rule);
  background: transparent;
  border-radius: var(--radius-pill);
  padding: 0.25rem 0.6rem;
  font-size: var(--text-xs);
  cursor: pointer;
  color: var(--ink-2);
}
.tree-panel__quick button:hover,
.tree-panel__quick button[aria-pressed='true'] {
  background: var(--paper-3);
  color: var(--ink);
  border-color: var(--rule-strong);
}
.legend {
  display: grid;
  gap: 0.35rem;
  font-size: var(--text-xs);
  color: var(--ink-2);
}
.legend li {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}
.legend__swatch {
  width: 22px;
  height: 10px;
  border-radius: 3px;
  flex: none;
  border: 1px solid var(--rule-strong);
}
.legend__swatch--royal {
  background: var(--royal);
  border-color: transparent;
}
.legend__swatch--maternal {
  background: var(--lagoon);
  border-color: transparent;
}
.legend__swatch--both {
  background: linear-gradient(90deg, var(--royal) 50%, var(--lagoon) 50%);
  border-color: transparent;
}
.legend__swatch--loose {
  background: repeating-linear-gradient(90deg, var(--rule-strong) 0 4px, transparent 4px 8px);
  height: 2px;
  border: 0;
  border-radius: 0;
}
.legend__swatch--placeholder {
  border-style: dashed;
  background: transparent;
}
.tree-panel__toggle {
  display: none;
}
.tree-zoom {
  position: absolute;
  z-index: 5;
  right: var(--space-4);
  bottom: var(--space-4);
  display: grid;
  gap: var(--space-1);
}
.tree-hint {
  position: absolute;
  z-index: 4;
  left: 50%;
  bottom: var(--space-4);
  transform: translateX(-50%);
  font-size: var(--text-xs);
  color: var(--muted);
  background: color-mix(in oklch, var(--paper-raise) 80%, transparent);
  padding: 0.3rem 0.7rem;
  border-radius: var(--radius-pill);
  pointer-events: none;
  white-space: nowrap;
}

/* ---------- drawer ---------- */
.tree-drawer {
  position: absolute;
  z-index: 6;
  top: var(--space-4);
  right: var(--space-4);
  bottom: var(--space-4);
  width: min(380px, calc(100% - var(--space-4) * 2));
  background: color-mix(in oklch, var(--paper-raise) 94%, transparent);
  backdrop-filter: blur(18px);
  -webkit-backdrop-filter: blur(18px);
  border: 1px solid var(--rule);
  border-radius: var(--radius-l);
  box-shadow: var(--shadow-2);
  padding: var(--space-5);
  overflow: auto;
  transform: translateX(calc(100% + var(--space-4) * 2));
  transition: transform var(--duration-slow) var(--ease-out), opacity var(--duration);
  opacity: 0;
}
.tree-drawer.is-open {
  transform: none;
  opacity: 1;
}
.tree-drawer__close {
  position: absolute;
  top: var(--space-3);
  right: var(--space-3);
}
.tree-drawer h2 {
  font-size: 1.5rem;
  margin: var(--space-4) 0 var(--space-1);
  padding-right: var(--space-7);
}
.tree-drawer__aka {
  color: var(--muted);
  margin-bottom: var(--space-3);
}
.tree-drawer__section {
  margin-top: var(--space-4);
  padding-top: var(--space-4);
  border-top: 1px solid var(--rule);
}
.tree-drawer__section h3 {
  font-family: var(--font-body);
  font-size: var(--text-xs);
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--muted);
  font-weight: 600;
  margin-bottom: var(--space-2);
}
.tree-drawer .titles li {
  font-size: var(--text-sm);
  color: var(--ink-2);
  padding-left: 1rem;
  position: relative;
}
.tree-drawer .titles li::before {
  content: '◆';
  position: absolute;
  left: 0;
  font-size: 0.55rem;
  top: 0.45rem;
  color: var(--gold-ink);
}
.tree-drawer__bio {
  font-size: var(--text-sm);
  color: var(--ink-2);
}

@media (max-width: 900px) {
  .tree-panel {
    top: var(--space-3);
    left: var(--space-3);
    right: var(--space-3);
    width: auto;
    max-height: 48vh;
    padding: var(--space-3);
    gap: var(--space-3);
  }
  .tree-panel.is-collapsed > :not(.tree-panel__head) {
    display: none;
  }
  .tree-panel__toggle {
    display: inline-grid;
  }
  .tree-panel__head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: var(--space-2);
  }
  .tree-drawer {
    top: auto;
    left: var(--space-3);
    right: var(--space-3);
    bottom: var(--space-3);
    width: auto;
    max-height: 60vh;
    transform: translateY(calc(100% + var(--space-4) * 2));
  }
  .tree-hint {
    display: none;
  }
  .tree-zoom {
    grid-auto-flow: column;
    right: auto;
    left: var(--space-3);
    bottom: var(--space-3);
  }
  .tree-drawer.is-open ~ .tree-zoom {
    display: none;
  }
  .tree-drawer {
    max-height: 50vh;
  }
}
