/* Family Tree on the web (server/web/pages/tree.js and its tree-*.js siblings;
   the phone's is components/pages/TreePage.tsx and components/tree/*).
   Every colour is a theme variable, so all the themes, light and dark, come
   for free; the photo viewer alone is black whatever the theme, as Photos' is.

   The tree is the page: on the Tree tab it fills everything under the tabs
   and nothing scrolls — the canvas pans. Everywhere else is one column that
   scrolls, read at 320px as often as at 1440. Every control is at least 40px
   tall, and nothing is said in colour alone. */

.tree-root { flex: 1; min-height: 0; display: flex; flex-direction: column; position: relative; color: var(--ink); }
.tree-root [hidden], .tree-sheet [hidden], .tree-lightbox [hidden] { display: none !important; }
.tree-root svg, .tree-sheet svg, .tree-lightbox svg, .tree-ask svg { stroke: currentColor; fill: none; stroke-width: 36; }
.tree-frame { flex: 1; min-height: 0; display: flex; flex-direction: column; }
.tree-body { flex: 1; min-height: 0; display: flex; flex-direction: column; position: relative; }
.tree-scroll { flex: 1; min-height: 0; overflow-y: auto; -webkit-overflow-scrolling: touch; }
.tree-page, .tree-list-page {
  display: flex; flex-direction: column; gap: 16px; min-width: 0; box-sizing: border-box;
  max-width: 720px; margin: 0 auto; padding: 14px 16px 40px;
}
.tree-list-page.narrow { max-width: 600px; }
/* Clear of the floating rail when the page has no head of its own above it. */
.tree-over > .tree-page, .tree-root[data-at='start'] .tree-page, .tree-root > .tree-page { padding-top: calc(54px + env(safe-area-inset-top)); }
.tree-over > .tree-page { max-width: 1000px; }

/* ---- the head: the tree's name (and the trees you are in), what it holds, the three dots ---- */
.tree-head { flex: none; display: flex; align-items: flex-start; gap: 8px; padding: calc(52px + env(safe-area-inset-top)) 8px 2px 16px; }
.tree-head-main { flex: 1; min-width: 0; }
.tree-title-wrap { margin: 0; font-size: inherit; font-weight: inherit; display: flex; min-width: 0; }
.tree-title-wrap > .tree-more { min-width: 0; max-width: 100%; }
.tree-title {
  display: inline-flex; align-items: flex-end; gap: 6px; max-width: 100%; min-height: 40px; padding: 0; border: none; background: none; cursor: pointer;
  color: var(--ink); font: inherit; font-size: 26px; font-weight: 800; letter-spacing: -0.5px; font-family: var(--font-display, inherit); text-align: left; border-radius: 8px;
}
.tree-title-text { min-width: 0; white-space: normal; overflow-wrap: break-word; }
.tree-title svg { flex: none; width: 18px; height: 18px; stroke-width: 52; color: var(--ink-muted); margin-bottom: 8px; } /* after the last line of a wrapped name, not halfway up */
.tree-stats { font-size: 13px; color: var(--ink-muted); white-space: normal; overflow-wrap: break-word; }

/* ---- the tabs ---- */
.tree-tabs { flex: none; display: flex; gap: 4px; padding: 4px 12px 0; border-bottom: 1px solid var(--border); }
.tree-tab {
  flex: 0 1 auto; min-width: 0; min-height: 44px; padding: 0 14px; border: none; background: none; cursor: pointer;
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  font: inherit; font-size: 14.5px; font-weight: 600; color: var(--ink-muted); border-bottom: 2.5px solid transparent; margin-bottom: -1px;
}
.tree-tab.on { color: var(--ink); font-weight: 800; border-bottom-color: var(--accent); }
.tree-tab-count {
  flex: none; min-width: 20px; height: 20px; padding: 0 6px; border-radius: 10px; background: var(--accent); color: var(--on-accent, var(--bg));
  font-size: 11.5px; font-weight: 800; line-height: 20px; text-align: center; font-variant-numeric: tabular-nums;
}

/* ---- words ---- */
.tree-quiet { font-size: 13.5px; line-height: 1.45; color: var(--ink-muted); overflow-wrap: anywhere; }
.tree-err { display: flex; align-items: center; flex-wrap: wrap; gap: 4px 10px; color: var(--ink); padding: 9px 12px; border-radius: 10px; border: 1px solid color-mix(in srgb, var(--danger) 45%, var(--border)); background: color-mix(in srgb, var(--danger) 8%, var(--surface)); }
.tree-empty-line { font-size: 14px; line-height: 1.5; color: var(--ink-muted); padding: 4px 0; }
.tree-warns { display: flex; flex-direction: column; gap: 6px; }
.tree-warn { font-size: 13.5px; line-height: 1.45; color: var(--ink); padding: 8px 12px; border-radius: 10px; background: color-mix(in srgb, var(--accent-2, var(--accent)) 12%, var(--surface)); border: 1px solid color-mix(in srgb, var(--accent-2, var(--accent)) 35%, var(--border)); }
.tree-section { display: flex; flex-direction: column; gap: 10px; min-width: 0; }
.tree-section > .tree-btn { align-self: flex-start; }
.tree-h { margin: 0; font-size: 18px; font-weight: 800; letter-spacing: -0.2px; color: var(--ink); font-family: var(--font-display, inherit); }
.tree-h3 { margin: 0; font-size: 12.5px; font-weight: 800; letter-spacing: 0.3px; text-transform: uppercase; color: var(--ink-muted); }
.tree-tag {
  flex: none; display: inline-flex; align-items: center; height: 20px; margin-left: 6px; padding: 0 7px; border-radius: 6px; vertical-align: 1px;
  background: var(--accent-soft); color: var(--accent); font-size: 11.5px; font-weight: 700; white-space: nowrap; letter-spacing: 0;
}
.tree-tag:empty { display: none; }
.tree-tag.low { background: var(--surface); color: var(--ink-muted); box-shadow: inset 0 0 0 1px var(--border); }
.tree-tag.medium { background: color-mix(in srgb, var(--accent-2, var(--accent)) 16%, var(--surface)); color: var(--ink); }
.tree-spring { flex: 1; }

/* ---- buttons ---- */
.tree-btn {
  flex: none; display: inline-flex; align-items: center; justify-content: center; gap: 6px; min-height: 40px; padding: 0 16px; max-width: 100%;
  border: 1px solid var(--border); border-radius: 12px; background: var(--surface); color: var(--ink); cursor: pointer;
  font: inherit; font-size: 14px; font-weight: 700; line-height: 1.2; text-decoration: none; white-space: nowrap;
}
.tree-btn:hover { border-color: var(--ink-faint); }
.tree-btn.solid { background: var(--accent); border-color: var(--accent); color: var(--on-accent, var(--bg)); }
.tree-btn.soft { background: var(--accent-soft); border-color: transparent; color: var(--accent); }
.tree-btn.plain { border-color: transparent; background: none; padding: 0 8px; color: var(--accent); }
.tree-btn.plain:hover { background: var(--accent-soft); }
.tree-btn.danger { background: var(--danger); border-color: var(--danger); color: var(--bg); }
.tree-btn.plain.danger { background: none; border-color: transparent; color: var(--danger); }
.tree-btn:disabled { opacity: 0.45; cursor: default; }
.tree-btn svg { width: 16px; height: 16px; stroke-width: 48; }
.tree-back { margin-left: -8px; color: var(--ink); }
.tree-backrow { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.tree-backrow > .tree-more { margin-right: -8px; }
.tree-icon-btn {
  flex: none; display: inline-grid; place-items: center; width: 40px; height: 40px; border: none; border-radius: 20px; background: none; color: var(--ink-muted); cursor: pointer;
}
.tree-icon-btn:hover { color: var(--ink); background: var(--accent-soft); }
.tree-icon-btn svg { width: 20px; height: 20px; stroke-width: 44; }
.tree-more > .tree-icon-btn svg { width: 22px; height: 22px; stroke-width: 64; }
.tree-add {
  align-self: flex-start; display: inline-flex; align-items: center; gap: 6px; min-height: 40px; padding: 0 10px 0 6px; margin-left: -6px; border: none; border-radius: 10px;
  background: none; color: var(--accent); cursor: pointer; font: inherit; font-size: 14px; font-weight: 700; text-align: left;
}
.tree-add:hover { background: var(--accent-soft); }
.tree-add svg { flex: none; width: 18px; height: 18px; stroke-width: 48; }
.tree-root :is(button, a, input, select, textarea):focus-visible, .tree-sheet :is(button, a, input, select, textarea):focus-visible,
.tree-ask :is(button, a):focus-visible, .tree-lightbox :is(button, a):focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* The three dots (and the tree's name): a short list under the button. */
.tree-more { position: relative; flex: none; display: inline-flex; }
.tree-menu {
  position: absolute; top: calc(100% + 4px); right: 0; z-index: 12; min-width: 220px; max-width: min(320px, 86vw); max-height: min(70vh, 480px); overflow-y: auto; padding: 6px;
  border: 1px solid var(--border); border-radius: 14px; background: var(--surface-solid, var(--surface));
  box-shadow: 0 12px 32px color-mix(in srgb, var(--ink) 16%, transparent); display: flex; flex-direction: column;
}
.tree-menu.left { right: auto; left: 0; }
.tree-menu-head { padding: 8px 10px 4px; font-size: 12px; font-weight: 800; letter-spacing: 0.3px; text-transform: uppercase; color: var(--ink-muted); }
.tree-menu-sep { height: 1px; margin: 6px 4px; background: var(--border); }
.tree-menu-row {
  display: flex; flex-direction: column; justify-content: center; min-height: 44px; padding: 5px 10px; border: none; border-radius: 9px; background: none; cursor: pointer;
  font: inherit; text-align: left; color: var(--ink);
}
.tree-menu-row:hover { background: var(--accent-soft); }
.tree-menu-row.on { background: var(--accent-soft); }
.tree-menu-row.danger .tree-menu-label { color: var(--danger); }
.tree-menu-label { font-size: 14.5px; font-weight: 600; white-space: normal; overflow-wrap: break-word; }
.tree-menu-sub { font-size: 12.5px; color: var(--ink-muted); white-space: normal; overflow-wrap: break-word; }

/* ---- chips and choices ---- */
/* They wrap rather than slide: four filters are few enough that none should be out of sight. */
.tree-chips { display: flex; flex-wrap: wrap; gap: 8px; }
.tree-chip.pick {
  flex: none; min-height: 40px; padding: 0 14px; border-radius: 20px; border: 1px solid var(--border); background: var(--surface); color: var(--ink);
  font: inherit; font-size: 14px; font-weight: 600; cursor: pointer; white-space: nowrap;
}
.tree-chip.pick.on { background: var(--accent); border-color: var(--accent); color: var(--on-accent, var(--bg)); font-weight: 700; }
.tree-choice, .tree-rel-row { display: flex; flex-wrap: wrap; gap: 6px; }
.tree-rel-grid { display: flex; flex-direction: column; gap: 6px; }
.tree-choice > .tree-chip.pick, .tree-rel-row > .tree-chip.pick { padding: 0 12px; }
.tree-field.tall .tree-choice { flex-direction: column; }
.tree-field.tall .tree-chip.pick { justify-content: flex-start; text-align: left; border-radius: 12px; min-height: 48px; white-space: normal; }

/* ---- a face: a picture, or initials on a quiet tint ---- */
.tree-face { flex: none; display: inline-grid; place-items: center; width: 40px; height: 40px; border-radius: 50%; object-fit: cover; background: var(--accent-soft); overflow: hidden; }
.tree-face-none { color: var(--accent); font-weight: 800; letter-spacing: 0.2px; line-height: 1; user-select: none; }
.tree-face-none svg { width: 46%; height: 46%; }

/* ---- a person in a row ---- */
.tree-rows { display: flex; flex-direction: column; min-width: 0; }
.tree-rows > * + * { border-top: 1px solid var(--border); }
.tree-row { display: flex; align-items: center; gap: 6px 10px; padding: 6px 0; min-width: 0; }
.tree-row.cannot { opacity: 0.4; }
.tree-row-acts { flex: none; display: flex; align-items: center; gap: 4px; margin-left: auto; }
.tree-who {
  flex: 1 1 0; min-width: 0; min-height: 44px; display: flex; align-items: center; gap: 10px; padding: 0; border: none; background: none; color: inherit;
  font: inherit; text-align: left; cursor: pointer; border-radius: 10px;
}
.tree-who.still { cursor: default; }
.tree-who-text { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.tree-who-name { font-size: 15px; font-weight: 700; color: var(--ink); line-height: 1.3; white-space: normal; overflow-wrap: break-word; }
button.tree-who:hover .tree-who-name { text-decoration: underline; text-underline-offset: 3px; }
.tree-who-sub { font-size: 13px; line-height: 1.35; color: var(--ink-muted); white-space: normal; overflow-wrap: break-word; }
.tree-who-sub:empty { display: none; }

/* ============================ the Tree tab ============================ */
.tree-stage { flex: 1; min-height: 0; position: relative; overflow: hidden; }
.tree-canvas { position: absolute; inset: 0; overflow: hidden; touch-action: none; cursor: grab; user-select: none; -webkit-user-select: none; outline: none; }
.tree-canvas.dragging { cursor: grabbing; }
.tree-canvas:focus-visible { box-shadow: inset 0 0 0 2px var(--accent); }
.tree-view {
  position: absolute; inset: 0; overflow: hidden;
  -webkit-mask-image: linear-gradient(to bottom, transparent 0, transparent 40px, black 60px);
  mask-image: linear-gradient(to bottom, transparent 0, transparent 40px, black 60px);
}
.tree-layer { position: absolute; left: 0; top: 0; width: 0; height: 0; transform-origin: 0 0; will-change: transform; }
.tree-layer.glide { transition: transform 240ms cubic-bezier(.2, .8, .2, 1); }
.tree-links { position: absolute; left: 0; top: 0; overflow: visible; pointer-events: none; }
.tree-root svg.tree-links { stroke: none; }
.tree-link { fill: none; stroke: color-mix(in srgb, var(--ink) 38%, transparent); stroke-width: 1.6; stroke-linecap: round; stroke-linejoin: round; }
.tree-link.other { stroke-dasharray: 6 5; }
.tree-link.union { stroke: color-mix(in srgb, var(--accent) 70%, transparent); stroke-width: 2; }
.tree-link.union.ended { stroke-dasharray: 2 5; }
.tree-link.ghost { stroke: var(--ink-faint); stroke-dasharray: 3 5; }

.tree-card {
  position: absolute; box-sizing: border-box; display: flex; align-items: center; gap: 9px; padding: 0 10px 0 9px; margin: 0;
  border: 1px solid var(--border); border-radius: 16px; background: var(--surface-solid, var(--surface)); color: var(--ink); cursor: pointer;
  font: inherit; text-align: left; box-shadow: 0 1px 3px color-mix(in srgb, var(--ink) 10%, transparent);
}
.tree-card:hover { border-color: var(--ink-faint); }
.tree-card.focus { border: 2px solid var(--accent); padding: 0 9px 0 8px; }
.tree-card.sel { box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 38%, transparent), 0 1px 3px color-mix(in srgb, var(--ink) 10%, transparent); border-color: var(--accent); }
.tree-card.ref { border-style: dashed; border-color: var(--ink-faint); background: color-mix(in srgb, var(--surface-solid, var(--surface)) 55%, transparent); box-shadow: none; }
.tree-card.ref .tree-card-name, .tree-card.ref .tree-card-life { color: var(--ink-muted); }
.tree-card.ghost { border: 1.5px dashed color-mix(in srgb, var(--accent) 60%, var(--border)); background: color-mix(in srgb, var(--accent-soft) 55%, transparent); box-shadow: none; }
.tree-card.ghost .tree-card-name { color: var(--accent); }
.tree-card-face { width: 40px; height: 40px; font-size: 15px; pointer-events: none; }
.tree-card-text { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 1px; pointer-events: none; }
.tree-card-name {
  /* --name-size: a long name drawn smaller to keep to two lines (tree-canvas.js cardNameSize). */
  font-size: var(--name-size, 13.5px); font-weight: 700; line-height: 1.22; color: var(--ink); overflow-wrap: anywhere;
  display: block;
}
.tree-card-life { font-size: 12px; line-height: 1.25; color: var(--ink-muted); white-space: normal; font-variant-numeric: tabular-nums; overflow-wrap: break-word; }
.tree-card-dot { position: absolute; top: -4px; right: -4px; width: 12px; height: 12px; border-radius: 50%; background: var(--accent-2, var(--accent)); border: 2px solid var(--surface-solid, var(--surface)); }
/* Far out, a card says less and says it larger. */
.tree-canvas.far .tree-card-life { display: none; }
.tree-canvas.far .tree-card-name { font-size: 17px; }
.tree-canvas.tiny .tree-card-text { display: none; }
.tree-canvas.tiny .tree-card { justify-content: center; }
.tree-canvas.tiny .tree-card-face { width: 52px; height: 52px; font-size: 20px; }

.tree-more-pill {
  position: absolute; transform: translate(-50%, -50%); z-index: 2; min-width: 36px; height: 26px; padding: 0 8px; border-radius: 13px; cursor: pointer;
  border: 1px solid var(--border); background: var(--surface-solid, var(--surface)); color: var(--ink-muted); font: inherit; font-size: 12px; font-weight: 800; line-height: 24px;
  font-variant-numeric: tabular-nums; box-shadow: 0 1px 3px color-mix(in srgb, var(--ink) 10%, transparent);
}
/* The pill stays the size the gap allows; what a finger can hit is a thumb high. */
.tree-more-pill::after { content: ''; position: absolute; left: 50%; top: 50%; width: max(100%, 44px); height: 44px; transform: translate(-50%, -50%); }
.tree-more-pill:hover { color: var(--accent); border-color: var(--accent); }

.tree-controls { position: absolute; top: 8px; left: 10px; right: 10px; z-index: 5; display: flex; flex-wrap: wrap; align-items: flex-start; justify-content: space-between; gap: 8px; pointer-events: none; }
.tree-controls > * { pointer-events: auto; }
.tree-switch, .tree-pill {
  display: flex; align-items: center; padding: 3px; border: 1px solid var(--border); border-radius: 24px; background: var(--surface-solid, var(--surface));
  box-shadow: 0 4px 14px color-mix(in srgb, var(--ink) 10%, transparent);
}
.tree-seg { min-height: 38px; padding: 0 14px; border: none; border-radius: 20px; background: none; color: var(--ink-muted); font: inherit; font-size: 13.5px; font-weight: 700; cursor: pointer; white-space: nowrap; }
.tree-seg.on { background: var(--accent); color: var(--on-accent, var(--bg)); }
.tree-pill-btn { display: grid; place-items: center; width: 40px; height: 38px; border: none; border-radius: 20px; background: none; color: var(--ink); cursor: pointer; }
.tree-pill-btn:hover { background: var(--accent-soft); color: var(--accent); }
.tree-pill-btn svg { width: 19px; height: 19px; stroke-width: 46; }
/* A narrow phone: the switch and the pill still share the row, each a little tighter. */
@media (max-width: 400px) {
  .tree-controls { left: 8px; right: 8px; gap: 6px; }
  .tree-seg { padding: 0 11px; }
  .tree-pill-btn { width: 36px; }
}
@media (max-width: 350px) {
  .tree-seg { padding: 0 8px; font-size: 12.5px; }
  .tree-pill-btn { width: 32px; }
  .tree-pill-btn svg { width: 17px; height: 17px; }
}

/* The fan of ancestors. */
.tree-fan-slot { pointer-events: auto; stroke-width: 1; }
.tree-fan-slot.full { fill: var(--surface-solid, var(--surface)); stroke: var(--border); cursor: pointer; }
.tree-fan-slot.full:hover { fill: var(--accent-soft); }
.tree-fan-slot.focus { fill: var(--accent-soft); stroke: var(--accent); stroke-width: 2; }
.tree-fan-slot.empty { fill: color-mix(in srgb, var(--surface) 35%, transparent); stroke: var(--border); stroke-dasharray: 3 4; pointer-events: none; }
.tree-fan-slot.add { pointer-events: auto; cursor: pointer; stroke: color-mix(in srgb, var(--accent) 55%, var(--border)); }
.tree-fan-slot.add:hover { fill: var(--accent-soft); }
.tree-fan-slot.repeat { stroke-dasharray: 5 4; fill: color-mix(in srgb, var(--surface-solid, var(--surface)) 55%, transparent); }
.tree-fan-slot.sel { stroke: var(--accent); stroke-width: 2.5; }
.tree-fan-text { pointer-events: none; fill: var(--ink); stroke: none; font-weight: 600; }
.tree-fan-text .name { font-weight: 800; }
.tree-fan-text .life { fill: var(--ink-muted); font-weight: 500; font-size: 0.9em; }
.tree-fan-text.add { fill: color-mix(in srgb, var(--accent) 60%, transparent); font-weight: 700; font-size: 15px; }

/* The peek: who was pressed. A sheet at the foot on a phone, a panel beside the tree on a wide window; the tree stays. */
.tree-peek {
  position: absolute; left: 8px; right: 8px; bottom: 10px; z-index: 6; box-sizing: border-box;
  display: flex; flex-direction: column; gap: 10px; padding: 14px; max-width: 520px; margin: 0 auto;
  border: 1px solid var(--border); border-radius: 18px; background: var(--surface-solid, var(--surface));
  box-shadow: 0 10px 32px color-mix(in srgb, var(--ink) 18%, transparent); animation: tree-peek-up 200ms cubic-bezier(.2, .8, .2, 1);
}
.tree-peek.beside { top: 64px; right: 12px; left: auto; bottom: auto; width: 320px; margin: 0; animation-name: tree-peek-in; }
@keyframes tree-peek-up { from { transform: translateY(14px); opacity: 0; } }
@keyframes tree-peek-in { from { transform: translateX(14px); opacity: 0; } }
.tree-peek-head { display: flex; align-items: flex-start; gap: 12px; min-width: 0; }
.tree-peek-head > .tree-icon-btn { margin: -6px -6px 0 0; }
.tree-peek-text { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 2px; }
.tree-peek-name { font-size: 18px; font-weight: 800; letter-spacing: -0.2px; line-height: 1.25; overflow-wrap: anywhere; font-family: var(--font-display, inherit); display: block; }
.tree-peek-life { font-size: 13.5px; color: var(--ink-muted); font-variant-numeric: tabular-nums; }
.tree-peek-rel { font-size: 13.5px; font-weight: 600; color: var(--accent); }
.tree-chip.pick.tree-peek-hints { align-self: flex-start; background: var(--accent-soft); border-color: transparent; color: var(--accent); font-weight: 700; }
.tree-peek-acts { display: flex; flex-wrap: wrap; gap: 8px; }
.tree-peek-acts > .tree-btn { flex: 1 1 auto; }

/* ============================ one person ============================ */
.tree-person { display: flex; flex-direction: column; gap: 18px; min-width: 0; position: relative; }
.tree-person-head { display: flex; align-items: center; gap: 16px; min-width: 0; }
.tree-person-face { width: 88px; height: 88px; font-size: 32px; }
.tree-person-text { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 2px; }
.tree-person-name { margin: 0; font-size: 28px; line-height: 1.15; font-weight: 800; letter-spacing: -0.6px; color: var(--ink); font-family: var(--font-display, inherit); overflow-wrap: anywhere; }
.tree-person-aka { font-size: 13.5px; color: var(--ink-muted); overflow-wrap: anywhere; }
.tree-person-life { font-size: 15px; color: var(--ink-muted); font-variant-numeric: tabular-nums; }
.tree-person-rel { font-size: 14.5px; font-weight: 700; color: var(--accent); }
.tree-person-acts { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }
.tree-cols { display: flex; flex-direction: column; gap: 26px; min-width: 0; }
.tree-main, .tree-side { display: flex; flex-direction: column; gap: 26px; min-width: 0; }

/* Facts: a label over what it says over where — the way a record is read. */
.tree-facts { display: flex; flex-direction: column; border: 1px solid var(--border); border-radius: 14px; background: var(--surface); overflow: hidden; }
.tree-fact { display: flex; flex-direction: column; gap: 1px; padding: 10px 14px; min-width: 0; border: none; background: none; color: inherit; font: inherit; text-align: left; }
.tree-fact + .tree-fact { border-top: 1px solid var(--border); }
button.tree-fact { cursor: pointer; }
button.tree-fact:hover { background: var(--accent-soft); }
.tree-fact-text { display: flex; flex-direction: column; gap: 1px; min-width: 0; }
.tree-fact-label { font-size: 12px; font-weight: 800; letter-spacing: 0.3px; text-transform: uppercase; color: var(--ink-muted); }
.tree-fact-main { font-size: 15.5px; font-weight: 600; color: var(--ink); overflow-wrap: anywhere; }
.tree-fact-sub { font-size: 14px; color: var(--ink-muted); overflow-wrap: anywhere; }
.tree-fact-note { font-size: 14px; line-height: 1.45; color: var(--ink); white-space: pre-wrap; overflow-wrap: anywhere; margin-top: 2px; }
.tree-family-group { display: flex; flex-direction: column; gap: 4px; min-width: 0; }
.tree-family-group + .tree-family-group { margin-top: 8px; }
.tree-source { display: flex; align-items: flex-start; gap: 8px; padding: 10px 0; min-width: 0; }
.tree-source-text { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 3px; }
.tree-source-title { font-size: 15px; font-weight: 700; overflow-wrap: anywhere; }
.tree-source-detail { font-size: 14px; line-height: 1.45; color: var(--ink-muted); white-space: pre-wrap; overflow-wrap: anywhere; display: -webkit-box; -webkit-box-orient: vertical; -webkit-line-clamp: 4; line-clamp: 4; overflow: hidden; /* preview: a long free-text preview a tap opens in full — the one sanctioned cut */ }
.tree-link-out { align-self: flex-start; display: inline-flex; align-items: center; gap: 6px; min-height: 40px; max-width: 100%; color: var(--accent); font-size: 14px; font-weight: 600; text-decoration: underline; text-underline-offset: 3px; overflow-wrap: anywhere; border-radius: 6px; }
.tree-link-out svg { flex: none; width: 16px; height: 16px; stroke-width: 40; }
.tree-story { font-size: 15.5px; line-height: 1.6; color: var(--ink); white-space: pre-wrap; overflow-wrap: anywhere; }
.tree-kin { display: flex; flex-wrap: wrap; align-items: center; gap: 4px; }
.tree-kin-arrow { display: inline-grid; place-items: center; color: var(--ink-faint); }
.tree-kin-arrow svg { width: 14px; height: 14px; stroke-width: 56; }
.tree-kin-step { display: inline-flex; align-items: center; gap: 7px; min-height: 40px; padding: 0 12px 0 6px; border: 1px solid var(--border); border-radius: 20px; background: var(--surface); color: var(--ink); font: inherit; font-size: 13.5px; font-weight: 600; cursor: pointer; max-width: 100%; }
.tree-kin-step:hover { border-color: var(--accent); }

/* Photos and documents. */
.tree-thumbs { display: grid; grid-template-columns: repeat(auto-fill, minmax(92px, 1fr)); gap: 6px; }
.tree-thumb-btn { padding: 0; border: none; background: none; cursor: pointer; border-radius: 12px; min-width: 0; }
.tree-thumb { display: block; position: relative; aspect-ratio: 1; width: 100%; border-radius: 12px; overflow: hidden; background: var(--surface); border: 1px solid var(--border); box-sizing: border-box; }
.tree-thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }
.tree-thumb-doc { position: absolute; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 6px; padding: 8px; color: var(--ink-muted); }
.tree-thumb-doc svg { width: 28px; height: 28px; stroke-width: 30; }
.tree-thumb-name { max-width: 100%; font-size: 11.5px; line-height: 1.25; text-align: center; overflow-wrap: anywhere; display: block; }
button.tree-thumb.add { display: grid; place-items: center; border: 1.5px dashed color-mix(in srgb, var(--accent) 55%, var(--border)); background: color-mix(in srgb, var(--accent-soft) 55%, transparent); color: var(--accent); cursor: pointer; padding: 0; font: inherit; }
button.tree-thumb.add svg { width: 26px; height: 26px; stroke-width: 44; }
.tree-thumbs-foot { display: flex; flex-direction: column; align-items: flex-start; }
.tree-transcript { font-size: 14.5px; line-height: 1.55; white-space: pre-wrap; overflow-wrap: anywhere; padding: 12px 14px; border-radius: 12px; border: 1px solid var(--border); background: var(--surface); color: var(--ink); max-height: 46vh; overflow-y: auto; }
/* Files held over a person's page. */
.tree-drop { position: absolute; inset: -6px; z-index: 8; display: grid; place-items: center; border-radius: 18px; border: 2px dashed var(--accent); background: color-mix(in srgb, var(--accent-soft) 88%, transparent); pointer-events: none; }
.tree-drop-in { display: flex; flex-direction: column; align-items: center; gap: 10px; color: var(--accent); font-size: 17px; font-weight: 800; position: sticky; top: 40%; }
.tree-drop-in svg { width: 40px; height: 40px; stroke-width: 34; }

/* A hint: what was found, where, and each thing it would add, ticked or not. */
.tree-hints { display: flex; flex-direction: column; gap: 12px; }
.tree-hintcard { display: flex; flex-direction: column; gap: 8px; padding: 14px; border: 1px solid var(--border); border-radius: 16px; background: var(--surface); min-width: 0; }
.tree-hint-who { align-self: flex-start; display: inline-flex; align-items: center; gap: 7px; min-height: 40px; padding: 0 10px 0 4px; margin: -4px 0 -2px -4px; border: none; border-radius: 20px; background: none; color: var(--accent); font: inherit; font-size: 13.5px; font-weight: 700; cursor: pointer; }
.tree-hint-who:hover { background: var(--accent-soft); }
.tree-hint-title { font-size: 16px; font-weight: 800; line-height: 1.3; overflow-wrap: anywhere; }
.tree-hint-from { display: flex; flex-wrap: wrap; align-items: center; gap: 4px 8px; font-size: 13.5px; color: var(--ink-muted); overflow-wrap: anywhere; }
.tree-hint-from > .tree-tag { margin-left: 0; }
.tree-hint-summary { margin: 0; font-size: 14.5px; line-height: 1.5; color: var(--ink); overflow-wrap: anywhere; }
.tree-hint-facts { display: flex; flex-direction: column; border: 1px solid var(--border); border-radius: 12px; overflow: hidden; background: var(--surface-solid, var(--surface)); }
.tree-hint-fact { display: flex; align-items: flex-start; gap: 12px; padding: 10px 12px; min-width: 0; }
.tree-hint-fact + .tree-hint-fact { border-top: 1px solid var(--border); }
.tree-hint-fact > .tree-check { margin-top: 3px; }
.tree-hint-acts { display: flex; justify-content: flex-end; flex-wrap: wrap; gap: 8px; margin-top: 2px; }

/* ============================ the lists ============================ */
.tree-toolbar { display: flex; flex-wrap: wrap; gap: 8px; }
.tree-search { flex: 1 1 220px; display: flex; align-items: center; min-height: 46px; min-width: 0; border: 1px solid var(--border); border-radius: 23px; background: var(--surface); }
.tree-search:focus-within { border-color: var(--accent); }
.tree-search-glass { flex: none; display: grid; place-items: center; width: 44px; color: var(--ink-muted); }
.tree-search-glass svg { width: 18px; height: 18px; stroke-width: 40; }
.tree-search-in { flex: 1; min-width: 0; height: 44px; padding: 0 14px 0 0; border: none; background: none; color: var(--ink); font: inherit; font-size: 16px; outline: none; appearance: none; }
.tree-search-in::-webkit-search-cancel-button { display: none; }
.tree-root .tree-search-in:focus-visible { outline: none; }
.tree-people { display: flex; flex-direction: column; min-width: 0; }
.tree-letter { margin: 14px 0 2px; font-size: 13px; font-weight: 800; color: var(--accent); }
.tree-people > .tree-btn { align-self: flex-start; margin-top: 10px; }

/* ============================ sheets ============================ */
.tree-sheet-back { align-items: flex-end; padding: 0; }
.tree-sheet {
  display: flex; flex-direction: column; width: 100%; max-width: 500px; max-height: min(92vh, 92dvh); min-height: 0; box-sizing: border-box;
  border: 1px solid var(--border); border-bottom: none; border-radius: 20px 20px 0 0; background: var(--surface-solid, var(--bg)); color: var(--ink); overflow: hidden;
  animation: tree-peek-up 220ms cubic-bezier(.2, .8, .2, 1);
}
.tree-sheet.wide { max-width: 680px; }
.tree-sheet-head { flex: none; display: flex; align-items: center; gap: 10px; padding: 10px 10px 10px 18px; border-bottom: 1px solid var(--border); }
.tree-sheet-title { flex: 1; min-width: 0; margin: 0; font-size: 17px; line-height: 1.3; font-weight: 800; color: var(--ink); font-family: var(--font-display, inherit); overflow-wrap: anywhere; }
.tree-sheet-body { flex: 1; min-height: 0; overflow-y: auto; display: flex; flex-direction: column; gap: 14px; padding: 16px 18px; }
.tree-sheet-text { margin: 0; font-size: 14.5px; line-height: 1.5; color: var(--ink-muted); }
.tree-sheet-err { flex: none; padding: 0 18px; }
.tree-sheet-err > .tree-err { margin-bottom: 10px; }
.tree-sheet-foot { flex: none; display: flex; align-items: center; justify-content: flex-end; flex-wrap: wrap; gap: 8px; padding: 12px 18px calc(12px + env(safe-area-inset-bottom)); border-top: 1px solid var(--border); }
.tree-sheet-foot:empty { display: none; }
@media (min-width: 600px) {
  .tree-sheet-back { align-items: center; padding: 18px; }
  .tree-sheet { max-height: min(88vh, 88dvh); border-bottom: 1px solid var(--border); border-radius: 20px; }
}
.modal.tree-ask { max-width: 400px; border-radius: 18px; }
.tree-ask-title { margin: 0 0 6px; font-size: 17px; line-height: 1.3; font-weight: 800; color: var(--ink); overflow-wrap: anywhere; }
.tree-ask-body { margin: 0; font-size: 14.5px; line-height: 1.5; color: var(--ink-muted); overflow-wrap: anywhere; }
.tree-ask-acts { display: flex; justify-content: flex-end; flex-wrap: wrap; gap: 8px; margin-top: 18px; }

/* ---- fields ---- */
.tree-form { display: flex; flex-direction: column; gap: 14px; min-width: 0; }
.tree-form-part { display: flex; flex-direction: column; gap: 14px; }
.tree-field { display: flex; flex-direction: column; gap: 5px; min-width: 0; }
.tree-label { font-size: 13px; font-weight: 700; color: var(--ink); }
.tree-hint { margin: 0; font-size: 13px; line-height: 1.4; color: var(--ink-muted); }
.tree-hint.unread { color: var(--ink); }
.tree-input {
  display: block; width: 100%; min-width: 0; min-height: 46px; box-sizing: border-box; padding: 10px 13px; border: 1px solid var(--border); border-radius: 12px;
  background: var(--surface); color: var(--ink); font: inherit; font-size: 16px; line-height: 1.4; outline: none;
}
.tree-input::placeholder, .tree-search-in::placeholder { color: var(--ink-faint); }
.tree-input:focus { border-color: var(--accent); }
textarea.tree-input { resize: vertical; }
.tree-select { appearance: auto; }
.tree-pair { display: grid; grid-template-columns: minmax(0, 3fr) minmax(0, 2fr); gap: 10px; }
.tree-checkrow { display: flex; align-items: center; gap: 12px; min-height: 44px; font-size: 14.5px; color: var(--ink); cursor: pointer; min-width: 0; }
.tree-checkrow > .tree-who { pointer-events: none; }
.tree-check { flex: none; width: 22px; height: 22px; margin: 0; cursor: pointer; appearance: none; -webkit-appearance: none; border: 1.5px solid var(--ink-muted); border-radius: 6px; background: transparent; }
.tree-check:checked { border-color: var(--accent); background: var(--accent); box-shadow: inset 0 0 0 3px var(--surface-solid, var(--surface)); }
.tree-pick-list { max-height: 52vh; overflow-y: auto; }
.tree-invite { display: flex; flex-direction: column; gap: 12px; padding-top: 14px; border-top: 1px solid var(--border); }
.tree-invite .tree-field > .tree-btn { align-self: flex-start; }
.tree-invite-acts { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }
.tree-linkbox { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }
.tree-linkbox > .tree-input { flex: 1 1 200px; width: auto; font-size: 14px; }
.tree-linkbox > .tree-hint { flex: 1 1 100%; }
.tree-leave { padding-top: 10px; border-top: 1px solid var(--border); }
.tree-dropbox { display: flex; flex-direction: column; align-items: center; gap: 10px; padding: 22px 16px; border: 1.5px dashed var(--border); border-radius: 16px; color: var(--ink-muted); }
.tree-dropbox.over { border-color: var(--accent); background: var(--accent-soft); }
.tree-dropbox > svg { width: 30px; height: 30px; stroke-width: 34; }
.tree-found { display: flex; flex-direction: column; gap: 2px; padding: 12px 14px; border-radius: 12px; background: var(--accent-soft); font-size: 14.5px; overflow-wrap: anywhere; }
.tree-run { display: flex; flex-wrap: wrap; align-items: center; gap: 6px 10px; font-size: 15px; }
.tree-run > .tree-quiet { flex: 1 1 100%; }
.tree-log { display: flex; flex-direction: column; }
.tree-log-row { display: flex; flex-direction: column; justify-content: center; gap: 1px; min-height: 44px; padding: 9px 0; border: none; background: none; color: inherit; font: inherit; text-align: left; min-width: 0; }
.tree-log-top { display: flex; align-items: baseline; justify-content: space-between; gap: 10px; min-width: 0; }
.tree-log-by { min-width: 0; font-size: 13.5px; white-space: normal; overflow-wrap: break-word; }
.tree-log-row + .tree-log-row { border-top: 1px solid var(--border); }
button.tree-log-row { cursor: pointer; }
button.tree-log-row:hover .tree-log-text { text-decoration: underline; text-underline-offset: 3px; }
.tree-log-text { min-width: 0; font-size: 14.5px; line-height: 1.45; color: var(--ink); overflow-wrap: anywhere; }
.tree-log-when { flex: none; font-size: 12.5px; color: var(--ink-muted); white-space: nowrap; font-variant-numeric: tabular-nums; }

/* ============================ no tree yet, and an invitation ============================ */
.tree-start { display: flex; flex-direction: column; align-items: center; text-align: center; gap: 10px; padding: 36px 8px 12px; }
.tree-start-ico { width: 72px; height: 72px; border-radius: 24px; background: var(--accent-soft); color: var(--accent); display: grid; place-items: center; margin-bottom: 6px; }
.tree-start-ico svg { width: 36px; height: 36px; stroke-width: 30; }
.tree-start-title { margin: 0; font-size: 24px; font-weight: 800; letter-spacing: -0.4px; line-height: 1.2; font-family: var(--font-display, inherit); }
.tree-start-body { margin: 0; max-width: 420px; font-size: 15px; line-height: 1.5; color: var(--ink-muted); }
.tree-start-acts { display: flex; flex-wrap: wrap; justify-content: center; gap: 8px; margin-top: 8px; }
.tree-start > .tree-hint { max-width: 380px; }
.tree-start-form { max-width: 440px; width: 100%; margin: 0 auto; }
.tree-start-form .tree-start-acts { justify-content: flex-end; }
.tree-invites { display: flex; flex-direction: column; gap: 8px; }
.tree-invite-row { display: flex; align-items: center; flex-wrap: wrap; gap: 8px 12px; padding: 12px 14px; border: 1px solid var(--border); border-radius: 16px; background: var(--surface); }
.tree-invite-text { flex: 1 1 180px; min-width: 0; font-size: 15px; font-weight: 600; overflow-wrap: anywhere; }

/* ============================ the photo viewer: black, whatever the theme ============================ */
.tree-lightbox { position: fixed; inset: 0; z-index: var(--z-modal, 44); display: flex; flex-direction: column; background: black; color: white; }
.tree-lb-top { flex: none; display: flex; align-items: flex-start; gap: 10px; padding: calc(10px + env(safe-area-inset-top)) 10px 6px 16px; }
.tree-lb-caption { flex: 1; min-width: 0; }
.tree-lb-title { font-size: 16px; font-weight: 700; white-space: normal; overflow-wrap: break-word; }
.tree-lb-sub { font-size: 13px; color: color-mix(in srgb, white 70%, transparent); white-space: normal; overflow-wrap: break-word; }
.tree-lb-note { margin-top: 4px; font-size: 13px; line-height: 1.4; color: color-mix(in srgb, white 86%, transparent); display: block; overflow-wrap: break-word; }
.tree-lightbox .tree-icon-btn { color: white; }
.tree-lightbox .tree-icon-btn:hover { background: color-mix(in srgb, white 16%, transparent); color: white; }
.tree-lb-mid { flex: 1; min-height: 0; display: flex; align-items: center; gap: 4px; padding: 0 4px; }
/* One cell exactly the stage's size, so the picture's 100% is the stage and a tall document is fitted, not cut. */
.tree-lb-stage { flex: 1; min-width: 0; min-height: 0; height: 100%; display: grid; grid-template: minmax(0, 1fr) / minmax(0, 1fr); place-items: center; overflow: hidden; }
.tree-lb-img { width: auto; height: auto; max-width: 100%; max-height: 100%; min-width: 0; min-height: 0; object-fit: contain; border-radius: 6px; }
.tree-lb-doc { display: flex; flex-direction: column; align-items: center; gap: 12px; padding: 24px; font-size: 15px; text-align: center; overflow-wrap: anywhere; color: color-mix(in srgb, white 80%, transparent); }
.tree-lb-doc svg { width: 64px; height: 64px; stroke-width: 22; }
.tree-lb-nav { width: 44px; height: 44px; }
.tree-lb-acts { flex: none; display: flex; flex-wrap: wrap; justify-content: center; gap: 8px; padding: 10px 12px calc(14px + env(safe-area-inset-bottom)); max-height: 42vh; overflow-y: auto; }
.tree-btn.light { background: color-mix(in srgb, white 12%, transparent); border-color: color-mix(in srgb, white 26%, transparent); color: white; }
.tree-btn.light:hover { background: color-mix(in srgb, white 22%, transparent); }
.tree-btn.light.danger { background: color-mix(in srgb, white 12%, transparent); border-color: color-mix(in srgb, white 26%, transparent); color: white; }
.tree-lb-text { flex: 1 1 100%; max-width: 720px; display: flex; flex-direction: column; gap: 6px; }
.tree-lb-text .tree-label { color: white; }
.tree-lb-text .tree-transcript { max-height: 22vh; }

/* ============================ a wide screen ============================ */
@media (min-width: 561px) {
  body[data-page='tree'] .app-shell { max-width: 1360px; }
}
@media (min-width: 900px) {
  .tree-head { padding-left: 24px; padding-right: 16px; }
  .tree-tabs { padding-left: 20px; }
  .tree-controls { top: 12px; left: 16px; right: 16px; }
  .tree-cols { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 40px; align-items: start; }
  .tree-list-page { max-width: 760px; }
  .tree-people .tree-rows { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); column-gap: 32px; }
  .tree-people .tree-rows > * { border-top: none; border-bottom: 1px solid var(--border); }
}
@media (max-width: 380px) {
  .tree-person-face { width: 68px; height: 68px; font-size: 25px; }
  .tree-person-name { font-size: 24px; }
  .tree-title { font-size: 23px; }
  .tree-tab { padding: 0 10px; }
}
@media (prefers-reduced-motion: reduce) {
  .tree-layer.glide { transition: none; }
  .tree-peek, .tree-sheet { animation: none; }
}
