@font-face {
  font-family: "Fraunces"; /* the Bengal Fig wordmark */
  src: url("fonts/fraunces-latin-wght-normal.woff2") format("woff2-variations");
  font-weight: 100 900;
  font-display: swap;
}
@font-face {
  font-family: "Figtree";
  src: url("fonts/figtree-latin-ext-wght-normal.woff2") format("woff2-variations");
  font-weight: 300 900;
  font-display: swap;
  unicode-range: U+0100-02BA, U+02BD-02C5, U+02C7-02CC, U+02CE-02D7, U+02DD-02FF, U+0304, U+0308, U+0329, U+1D00-1DBF, U+1E00-1E9F, U+1EF2-1EFF, U+2020, U+20A0-20AB, U+20AD-20C0, U+2113, U+2C60-2C7F, U+A720-A7FF;
}
@font-face {
  font-family: "Figtree";
  src: url("fonts/figtree-latin-wght-normal.woff2") format("woff2-variations");
  font-weight: 300 900;
  font-display: swap;
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}

:root {
  --sans: "Figtree", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --bg: #f6f4ef;
  --surface: #ffffff;
  --surface-2: #f0ede6;
  --text: #1f2328;
  --muted: #5d6168;
  --border: #dcd7cc;
  --field-border: #969083; /* ≥3:1 against the surface so fields are findable */
  --line: #a39d8f;
  --accent: #2f6f5e; /* links, selection, focus rings, tints */
  --accent-text: #ffffff;
  --brand: #193a1e; /* the banyan, the wordmark and main buttons: deep banyan-leaf green */
  --brand-text: #ffffff;
  /* One muted tone per surname, so families read as groups. */
  --tone-0: #77716a;
  --tone-1: #a4553a;
  --tone-2: #5d7343;
  --tone-3: #4a6788;
  --tone-4: #7d4f73;
  --tone-5: #8a6a1f;
  --tone-6: #7a5236;
  --danger: #b3261e;
  --shadow: 0 1px 2px rgba(60, 50, 30, .07), 0 6px 18px rgba(60, 50, 30, .08);
  color-scheme: light;
}

/* Dark colours: when the device prefers dark (unless Light was chosen in ⋯ → Appearance),
   or whenever Dark was chosen. */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #15171a;
    --surface: #1f2226;
    --surface-2: #2a2e33;
    --text: #e8e6e1;
    --muted: #9ca1a8;
    --border: #353a40;
    --field-border: #6a6f76;
    --line: #5f646b;
    --accent: #5fb39b;
    --accent-text: #0f1a17;
    --brand: #5fb39b;
    --brand-text: #0f1a17;
    --tone-0: #6c6862;
    --tone-1: #a65a40;
    --tone-2: #5f7546;
    --tone-3: #4f6c8d;
    --tone-4: #82567a;
    --tone-5: #8c6d24;
    --tone-6: #7f583b;
    --danger: #f2867d;
    --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 6px 18px rgba(0, 0, 0, .35);
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #15171a;
  --surface: #1f2226;
  --surface-2: #2a2e33;
  --text: #e8e6e1;
  --muted: #9ca1a8;
  --border: #353a40;
  --field-border: #6a6f76;
  --line: #5f646b;
  --accent: #5fb39b;
  --accent-text: #0f1a17;
  --brand: #5fb39b;
  --brand-text: #0f1a17;
  --tone-0: #6c6862;
  --tone-1: #a65a40;
  --tone-2: #5f7546;
  --tone-3: #4f6c8d;
  --tone-4: #82567a;
  --tone-5: #8c6d24;
  --tone-6: #7f583b;
  --danger: #f2867d;
  --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 6px 18px rgba(0, 0, 0, .35);
  color-scheme: dark;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font: 14px/1.4 var(--sans);
  -webkit-font-smoothing: antialiased;
  caret-color: var(--accent);
  accent-color: var(--accent);
  scrollbar-color: var(--border) transparent;
}

::selection { background: color-mix(in srgb, var(--accent) 22%, transparent); }

body { display: flex; flex-direction: column; }

button, input, select, textarea { font: inherit; color: inherit; }
input, select, textarea { color: var(--text); }
::placeholder { color: var(--muted); opacity: 1; }

button {
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  border: 1px solid var(--border);
  background: var(--surface);
  border-radius: 8px;
  padding: 6px 12px;
  white-space: nowrap;
}
.icon-svg { width: 16px; height: 16px; flex: none; fill: none; stroke: currentColor; stroke-width: 1.75; stroke-linecap: round; stroke-linejoin: round; }
button:hover:not(:disabled) { background: var(--surface-2); }
button:disabled { opacity: .45; cursor: not-allowed; }
button.primary { background: var(--brand); border-color: var(--brand); color: var(--brand-text); }
button.primary:hover { filter: brightness(1.15); background: var(--brand); }
button.danger { color: var(--danger); }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* ---------- toolbar ---------- */

.toolbar {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 16px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  position: relative;
  z-index: 3;
}
.tree-menu { min-width: 0; }
.menu.tree-menu summary.tree-select {
  display: flex;
  align-items: center;
  gap: 6px;
  max-width: 44vw;
  padding: 3px 8px 3px 6px;
  border-color: transparent;
  font-size: 21px;
  font-weight: 600;
  letter-spacing: -0.01em;
}
.menu.tree-menu summary.tree-select:hover, .tree-menu[open] summary.tree-select { background: var(--surface-2); }
/* Mid-width windows: icon-only Relationship and Share, so the tree's name keeps room. */
@media (max-width: 1000px) {
  #relate-open .label, #share-open .label { display: none; }
  .tree-menu { min-width: 120px; }
}
#tree-title { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tree-select .chevron { width: 14px; height: 14px; color: var(--muted); }
.tree-menu[open] .chevron { transform: rotate(180deg); }
.tree-list { left: 0; right: auto; min-width: 240px; max-height: 60vh; overflow-y: auto; }
.tree-list button { gap: 8px; }
.tree-list button[aria-current="true"] { font-weight: 600; }
.tree-list .icon-svg { color: var(--accent); }
.icon-space { width: 16px; flex: none; }
.status {
  font-size: 12px;
  color: var(--muted);
  background: var(--surface-2);
  border-radius: 999px;
  padding: 2px 10px;
  white-space: nowrap;
}
.status.warn { color: var(--danger); }
.spacer { flex: 1; }
.history { display: flex; gap: 4px; }
.history button { padding: 6px 8px; }
.search input {
  width: clamp(130px, 16vw, 200px);
  padding: 6px 10px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--bg);
}

.menu { position: relative; }
.menu summary {
  list-style: none;
  cursor: pointer;
  display: grid;
  place-items: center;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 6px 9px;
  user-select: none;
}
.menu summary:hover { background: var(--surface-2); }
.menu summary::-webkit-details-marker { display: none; }
.menu-items {
  position: absolute;
  right: 0;
  top: calc(100% + 6px);
  display: flex;
  flex-direction: column;
  min-width: 210px;
  padding: 6px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  box-shadow: var(--shadow);
}
.menu-items button { border: 0; justify-content: flex-start; text-align: left; }
.menu-items .danger { color: var(--danger); }
.menu-items hr { border: 0; border-top: 1px solid var(--border); margin: 6px 4px; }

/* ---------- canvas ---------- */

main { position: relative; flex: 1; min-height: 0; overflow: hidden; }

#tree {
  display: block;
  width: 100%;
  height: 100%;
  touch-action: none;
  cursor: grab;
  user-select: none;
}
#tree.dragging { cursor: grabbing; }

.edge { fill: none; stroke: var(--line); stroke-width: 1.5; }
.edge.coparent { stroke-dasharray: 5 4; }

.card { cursor: pointer; }
.card-bg {
  fill: var(--surface);
  stroke: var(--border);
  stroke-width: 1;
  filter: drop-shadow(0 1px 2px rgba(0, 0, 0, .08));
}
.card:hover .card-bg { stroke: var(--line); }
.card.selected .card-bg { stroke: var(--accent); stroke-width: 2.5; }
.card:focus { outline: none; }
.card:focus-visible .card-bg { stroke: var(--accent); stroke-width: 2.5; }
.avatar { fill: var(--tone-0); }
.tone-1 { --tone: var(--tone-1); } .tone-2 { --tone: var(--tone-2); } .tone-3 { --tone: var(--tone-3); }
.tone-4 { --tone: var(--tone-4); } .tone-5 { --tone: var(--tone-5); } .tone-6 { --tone: var(--tone-6); }
.card .avatar { fill: var(--tone, var(--tone-0)); }
.initials { fill: #fff; font-size: 12.5px; font-weight: 600; letter-spacing: .02em; text-anchor: middle; dominant-baseline: central; }
.name { fill: var(--text); font-size: 15px; font-weight: 600; }
.years { fill: var(--muted); font-size: 12px; font-variant-numeric: tabular-nums; }

.empty {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 4px;
  color: var(--muted);
}
.empty[hidden] { display: none; }

.zoom {
  position: absolute;
  left: 16px;
  bottom: 16px;
  display: flex;
  gap: 4px;
  z-index: 1;
}
.zoom button { box-shadow: var(--shadow); min-width: 36px; min-height: 34px; }

/* ---------- side panel ---------- */

.panel {
  position: absolute;
  top: 12px;
  right: 12px;
  bottom: 12px;
  width: 340px;
  overflow-y: auto;
  padding: 16px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 14px;
  box-shadow: var(--shadow);
  z-index: 2;
}
.panel[hidden] { display: none; }
.panel h2 { font-size: 19px; font-weight: 600; margin: 0; }
.panel h3 { font-size: 13px; font-weight: 600; color: var(--text); margin: 18px 0 6px; }
.panel label { display: block; font-size: 12px; color: var(--muted); margin-top: 10px; }
.panel input, .panel select, .panel textarea {
  display: block;
  width: 100%;
  margin-top: 4px;
  padding: 7px 9px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--bg);
}
.panel textarea { resize: vertical; }
.panel .row { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.panel fieldset.date {
  display: grid;
  grid-template-columns: 64px 1fr 84px;
  gap: 6px;
  margin: 10px 0 0;
  padding: 0;
  border: 0;
  min-width: 0;
}
.panel fieldset.date legend { padding: 0; margin-bottom: 4px; font-size: 13px; color: var(--muted); }
.panel fieldset.date input, .panel fieldset.date select { margin-top: 0; min-width: 0; }
.panel fieldset.date { position: relative; grid-template-columns: 56px 1fr 72px auto; }
.readonly .panel fieldset.date { grid-template-columns: 56px 1fr 72px; }
.panel .date-pick { padding: 6px 8px; border: 1px solid var(--border); background: var(--bg); color: var(--muted); }
.panel .date-pick:hover { color: var(--text); background: var(--surface-2); }
.panel input.date-native { position: absolute; right: 0; bottom: 0; width: 1px; height: 1px; margin: 0; padding: 0; border: 0; opacity: 0; pointer-events: none; }
.legend-hint { font-weight: 400; }
.panel .age { margin-top: 6px; }
.panel .age:empty { display: none; }
.icon { border: 0; padding: 6px; background: transparent; }

.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.spouse-row { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 6px; }
.panel .spouse-row select { width: auto; margin-top: 0; padding: 4px 8px; }
.chips .none { color: var(--muted); font-size: 13px; }
.chip { display: inline-flex; border: 1px solid var(--border); border-radius: 999px; overflow: hidden; }
.chip button { border: 0; border-radius: 0; padding: 3px 10px; background: var(--surface-2); }
.chip button + button { padding: 3px 8px; color: var(--muted); }

.panel details { margin-top: 14px; }
.panel summary { cursor: pointer; color: var(--muted); font-size: 13px; }
.link-row { display: grid; grid-template-columns: auto 1fr; gap: 6px; align-items: end; }
.link-row button { grid-column: 1 / -1; }
.error { color: var(--danger); font-size: 12px; min-height: 1em; margin: 4px 0 0; }
.panel .delete { width: 100%; margin-top: 20px; }
.panel .wide { width: 100%; margin-top: 6px; }

.photo-preview {
  flex: none;
  display: grid;
  place-items: center;
  width: 72px;
  height: 72px;
  padding: 0;
  border: 0;
  border-radius: 50%;
  overflow: hidden;
  background: var(--tone, var(--tone-0));
  color: #fff;
  font-size: 22px;
  font-weight: 600;
}
.photo-preview:hover:not(:disabled) { background: var(--tone, var(--tone-0)); filter: brightness(1.05); }
.photo-preview:disabled { opacity: 1; cursor: default; }
.photo-preview img { display: block; width: 100%; height: 100%; object-fit: cover; }
.photo-actions { display: flex; flex-wrap: wrap; gap: 6px; }

/* ---------- dialogs ---------- */

[hidden] { display: none !important; }

.dialog {
  width: min(440px, calc(100vw - 32px));
  padding: 20px;
  border: 1px solid var(--border);
  border-radius: 14px;
  background: var(--surface);
  color: var(--text);
  box-shadow: var(--shadow);
}
.dialog::backdrop { background: rgba(0, 0, 0, .45); }
.dialog h2 { margin: 0; font-size: 17px; }
.dialog label { display: block; font-size: 12px; color: var(--muted); margin-top: 14px; }
.dialog select {
  display: block;
  width: 100%;
  margin-top: 4px;
  padding: 7px 9px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--bg);
}
.dialog .check { display: flex; gap: 8px; align-items: flex-start; font-size: 13px; color: var(--text); }
.dialog .check input { margin: 2px 0 0; }
.hint { color: var(--muted); font-size: 13px; margin: 6px 0 0; }
.source-row { display: flex; gap: 6px; margin-top: 4px; }
.source-row select { flex: 1; min-width: 0; margin-top: 0; }
.source-row button { flex: none; white-space: nowrap; }
.dialog-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 18px; }

.photo-dialog { padding: 0; border: 0; background: transparent; max-width: 92vw; max-height: 92vh; cursor: zoom-out; }
.photo-dialog::backdrop { background: rgba(0, 0, 0, .75); }
.photo-dialog img { display: block; max-width: 92vw; max-height: 88vh; border-radius: 12px; }

@media (max-width: 720px) {
  .toolbar { flex-wrap: wrap; }
  .spacer { display: none; }
  .tree-menu { flex: 1; }
  .menu.tree-menu summary.tree-select { max-width: none; }
  .search { order: 5; flex-basis: 100%; }
  .status { order: 6; }
  .search input { width: 100%; }
  .panel {
    top: auto;
    left: 0;
    right: 0;
    bottom: 0;
    width: auto;
    max-height: 60%;
    border-radius: 14px 14px 0 0;
  }
}

/* ---------- sign in & view-only ---------- */

.view-only { display: none; }
.readonly .view-only { display: block; }
.readonly .edit-only { display: none !important; }
.panel input:disabled, .panel select:disabled, .panel textarea:disabled { opacity: 1; color: var(--text); cursor: default; }

.login {
  position: fixed;
  inset: 0;
  z-index: 10;
  display: grid;
  place-items: safe center; /* centred, but scrolls from the top on short screens */
  padding: 24px 16px;
  overflow-y: auto;
  background: var(--bg);
}
.login-card {
  width: min(360px, 100%);
  padding: 24px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 14px;
  box-shadow: var(--shadow);
}
.login-stack { display: flex; flex-direction: column; align-items: center; gap: 22px; width: min(360px, 100%); }
.login-stack .login-card { width: 100%; }
.brand { display: flex; flex-direction: column; align-items: center; gap: 2px; color: var(--brand); }
.brand-mark { width: 92px; height: 92px; fill: none; stroke: currentColor; }
.brand-name { font-family: "Fraunces", Georgia, "Times New Roman", serif; font-size: 40px; font-weight: 560; line-height: 1; letter-spacing: -0.01em; font-variation-settings: "SOFT" 50, "WONK" 0; }
.login-card h1 { margin: 0; font-size: 26px; font-weight: 600; letter-spacing: -0.01em; }
.login-mark { width: 64px; height: 64px; margin: -6px 0 6px -4px; color: var(--brand); }
.login-card label { display: block; font-size: 12px; color: var(--muted); margin-top: 14px; }
.login-card input {
  display: block;
  width: 100%;
  margin-top: 4px;
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--bg);
}
.login-card button { width: 100%; margin-top: 8px; padding: 9px 12px; }

.empty p { font-size: 18px; color: var(--muted); margin: 0 0 8px; }
.chip button + button .icon-svg { width: 12px; height: 12px; }

/* Bigger hit areas for fingers. */
@media (pointer: coarse) {
  button, .menu summary, .search input, .tree-select { min-height: 44px; }
  .zoom button { min-width: 44px; }
  .chip button { min-height: 36px; }
}

.steps { margin: 10px 0 0; padding-left: 20px; color: var(--text); font-size: 13px; line-height: 1.6; }
.steps a { color: var(--accent); text-underline-offset: 2px; }
.copy-row { display: flex; align-items: center; gap: 10px; margin-top: 12px; }
.dialog textarea {
  display: block;
  width: 100%;
  margin-top: 4px;
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--bg);
  font: 12.5px/1.45 ui-monospace, SFMono-Regular, Menlo, monospace;
  resize: vertical;
}
.prompt-preview { margin-top: 8px; }
.prompt-preview summary { cursor: pointer; color: var(--muted); font-size: 13px; }
button.link { border: 0; background: none; color: var(--accent); padding: 4px 8px; text-decoration: underline; text-underline-offset: 3px; }
button.link:hover:not(:disabled) { background: none; }

/* ---------- relationship bar ---------- */

.visually-hidden { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
#relate-open[aria-pressed="true"] { background: var(--surface-2); border-color: var(--line); }
.relate {
  position: absolute;
  top: 12px;
  left: 50%;
  transform: translateX(-50%);
  width: min(560px, calc(100% - 32px));
  padding: 12px 14px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 14px;
  box-shadow: var(--shadow);
  z-index: 2;
}
.relate[hidden] { display: none; }
.relate-pickers { display: grid; grid-template-columns: 1fr auto 1fr auto; gap: 6px; align-items: center; }
.relate select { min-width: 0; padding: 7px 9px; border: 1px solid var(--border); border-radius: 8px; background: var(--bg); }
.relate-result { margin: 10px 2px 0; font-size: 18px; font-weight: 600; line-height: 1.3; text-wrap: balance; }
.relate-result:empty { display: none; }
.relate .hint { margin: 4px 2px 0; }
.relating .card { transition: opacity .2s ease-out; }
.relating .card:not(.on-path), .relating .edge { opacity: .3; }
.relating .card.on-path .card-bg { stroke: var(--accent); stroke-width: 2; }
@media (max-width: 720px) {
  .relate { top: 8px; }
  #relate-open { order: 4; }
}

/* ---------- quick-add handles & relationship headings ---------- */

.handle { cursor: pointer; }
.handle rect { fill: var(--surface); stroke: var(--accent); stroke-width: 1.25; filter: drop-shadow(0 1px 2px rgba(0, 0, 0, .12)); }
.handle path { stroke: var(--accent); stroke-width: 1.75; stroke-linecap: round; }
.handle text { fill: var(--accent); font: 600 12px var(--sans); dominant-baseline: central; }
.handle:hover rect, .handle:focus-visible rect { fill: var(--accent); }
.handle:hover path, .handle:focus-visible path { stroke: var(--accent-text); }
.handle:hover text, .handle:focus-visible text { fill: var(--accent-text); }
.handle:focus { outline: none; }

.section-head { display: flex; align-items: center; justify-content: space-between; margin: 18px 0 6px; }
.panel .section-head h3 { margin: 0; }
.panel button.add { border: 0; background: none; color: var(--accent); padding: 4px 6px; font-weight: 600; font-size: 13px; }
.panel button.add:hover:not(:disabled) { background: var(--surface-2); }
.panel .other-parent { margin: 0 0 8px; }

/* ---------- usability pass ---------- */

/* Readable form text; 16px also stops phones zooming in when a field is focused. */
.panel label, .dialog label, .login-card label { font-size: 13px; }
.panel input, .panel select, .panel textarea,
.dialog select, .dialog textarea, .login-card input,
.relate select, .search input { font-size: 16px; border-color: var(--field-border); }
.dialog textarea { font-family: var(--sans); }
.panel h3 { font-size: 14px; }
.panel .add-note { font-size: 13px; color: var(--muted); }
.panel .more { margin-top: 20px; }
.panel .more .wide, .panel .more .delete { margin-top: 10px; }
.panel .link-existing { margin-top: 12px; }

/* "Add person" is the primary action, shown as a menu. */
.menu.add-menu summary {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 12px;
  background: var(--brand);
  border-color: var(--brand);
  color: var(--brand-text);
  white-space: nowrap;
}
.menu.add-menu summary:hover { background: var(--brand); filter: brightness(1.15); }
.add-items { min-width: 250px; }
.menu-note { margin: 4px 8px 6px; font-size: 13px; color: var(--muted); line-height: 1.4; }

/* Phones: tree name gets the first row, controls the second, search the third. */
@media (max-width: 720px) {
  .toolbar { row-gap: 8px; }
  .tree-menu { order: 0; flex: 1 0 100%; }
  .status { order: 1; flex: none; }
  .status.idle { display: none; }
  .history { order: 2; }
  #relate-open { order: 3; }
  #relate-open .label { display: none; }
  #share-open { display: none; } /* in the ⋯ menu instead */
  .add-menu { order: 4; margin-left: auto; }
  #menu { order: 5; }
  .search { order: 6; flex-basis: 100%; }
}

/* ---------- dialogs, toast, tip, key ---------- */

button.danger-solid { background: var(--danger); border-color: var(--danger); color: #fff; }
button.danger-solid:hover:not(:disabled) { background: var(--danger); filter: brightness(1.08); }
.dialog input { display: block; width: 100%; margin-top: 4px; padding: 8px 10px; border: 1px solid var(--field-border); border-radius: 8px; background: var(--bg); font-size: 16px; }
#ask-extra:empty { display: none; }
#ask-extra { margin-top: 8px; }
#ask-extra .link { padding: 4px 0; }

.toast {
  position: absolute;
  left: 50%;
  bottom: 20px;
  transform: translateX(-50%);
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 8px 8px 8px 16px;
  background: var(--text);
  color: var(--bg);
  border-radius: 10px;
  box-shadow: var(--shadow);
  z-index: 5;
  max-width: calc(100% - 32px);
}
.toast[hidden] { display: none; }
.toast button.link { color: var(--bg); font-weight: 600; }

.hint-pill {
  position: absolute;
  top: 14px;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 6px 6px 6px 14px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 999px;
  box-shadow: var(--shadow);
  font-size: 14px;
  white-space: nowrap;
  z-index: 1;
}
.hint-pill[hidden] { display: none; }
.hint-pill .icon { padding: 4px; }

.legend {
  position: absolute;
  left: 16px;
  bottom: 64px;
  width: min(300px, calc(100% - 32px));
  padding: 14px 16px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  box-shadow: var(--shadow);
  z-index: 3;
}
.legend[hidden] { display: none; }
.legend h2 { margin: 0 0 8px; font-size: 15px; }
.legend ul { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; font-size: 13px; }
.legend li { display: flex; align-items: center; gap: 10px; }
.legend svg { width: 44px; height: 16px; flex: none; fill: none; stroke: var(--line); stroke-width: 1.5; }
.legend li.edit-only svg { stroke: var(--accent); }
.swatches { display: flex; gap: 3px; width: 44px; flex: none; }
.swatches i { width: 12px; height: 12px; border-radius: 50%; background: var(--tone); }

/* ---------- compact panel: photo beside name, Family / Details tabs ---------- */

.panel { font-size: 14px; }
.panel .hint, .panel .none, .panel .add-note, .panel summary { font-size: 13px; }
.panel-close { position: absolute; top: 10px; right: 10px; }
.panel-delete { position: absolute; top: 10px; right: 44px; color: var(--danger); }
.panel-delete:hover:not(:disabled) { background: var(--surface-2); }
.panel-head { display: grid; grid-template-columns: 72px 1fr; gap: 14px; align-items: start; padding-right: 64px; }
.panel-head .head-fields label:first-child { margin-top: 0; }
.panel-head .photo-preview { position: relative; width: 72px; height: 72px; margin-top: 2px; overflow: visible; }
.panel-head .photo-preview img { border-radius: 50%; }
.photo-add {
  position: absolute;
  right: -2px;
  bottom: -2px;
  display: grid;
  place-items: center;
  width: 24px;
  height: 24px;
  border-radius: 50%;
  background: var(--accent);
  color: var(--accent-text);
  border: 2px solid var(--surface);
}
.photo-add .icon-svg { width: 13px; height: 13px; stroke-width: 2.25; }
.panel .photo-actions { margin-top: 10px; }

.tabs { display: flex; gap: 4px; margin: 16px 0 2px; border-bottom: 1px solid var(--border); }
.tabs button {
  border: 0;
  border-radius: 0;
  background: none;
  padding: 8px 12px;
  margin-bottom: -1px;
  border-bottom: 2px solid transparent;
  color: var(--muted);
  font-weight: 600;
}
.tabs button:hover:not(:disabled) { background: none; color: var(--text); }
.tabs button[aria-selected="true"] { color: var(--text); border-bottom-color: var(--accent); }
.tab-pane[hidden] { display: none; }
.tab-pane > .section-head:first-child { margin-top: 12px; }
.tab-pane > fieldset.date:first-child { margin-top: 12px; }

/* Notes start small and grow with what's typed. */
.panel textarea { field-sizing: content; min-height: 3.4em; max-height: 16em; }

/* Appearance switch in the ⋯ menu */
.theme-row { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 6px 8px; font-size: 13px; color: var(--muted); }
.segmented { display: flex; gap: 2px; padding: 2px; border: 1px solid var(--border); border-radius: 8px; }
.menu-items .segmented button { padding: 4px 9px; font-size: 13px; border-radius: 6px; background: none; justify-content: center; }
.menu-items .segmented button[aria-pressed="true"] { background: var(--surface-2); color: var(--text); font-weight: 600; }

/* ---------- focus bar ---------- */

.focus-bar {
  position: absolute;
  top: 12px;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  justify-content: center;
  gap: 10px;
  max-width: calc(100% - 32px);
  padding: 8px 10px 8px 14px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  box-shadow: var(--shadow);
  z-index: 2;
  font-size: 14px;
}
.focus-bar[hidden], .focus-bar [hidden] { display: none; }
.focus-bar .segmented button { padding: 4px 10px; font-size: 13px; border: 0; border-radius: 6px; background: none; }
.focus-bar .segmented button[aria-pressed="true"] { background: var(--surface-2); font-weight: 600; }
.panel .focus-btn { margin-top: 12px; justify-content: flex-start; }

/* ---------- history ---------- */

.history-dialog { width: min(520px, calc(100vw - 32px)); }
.history-list { list-style: none; margin: 14px 0 0; padding: 0; max-height: 55vh; overflow-y: auto; }
.history-list li { padding: 10px 0; border-top: 1px solid var(--border); }
.history-list li:first-child { border-top: 0; }
.history-head { display: flex; align-items: center; gap: 8px; }
.history-head .hint { margin: 0; flex: 1; }
.history-list p { margin: 4px 0 0; font-size: 14px; }
.badge { font-size: 12px; font-weight: 600; color: var(--accent); }

/* ---------- print ---------- */

.print-only { display: none; }
@media print {
  @page { size: landscape; margin: 12mm; }
  html, body { height: auto; background: #fff; }
  body { display: block; }
  .toolbar, .panel, .zoom, .legend, .hint-pill, .toast, .relate, .focus-bar, .empty, .login, dialog { display: none !important; }
  main { overflow: visible; }
  .print-only { display: block; }
  #print-header h1 { margin: 0 0 2px; font-size: 20px; font-weight: 650; }
  #print-header p { margin: 0 0 10px; font-size: 11px; color: #555; }
  #tree { width: 100%; height: auto; max-height: 170mm; }
  .card-bg { filter: none; }
}

/* With the person panel open on wide screens, centre the floating bars in the space left of it. */
@media (min-width: 721px) {
  main:has(> .panel:not([hidden])) :is(.focus-bar, .relate, .hint-pill, .toast) { left: calc((100% - 364px) / 2); max-width: calc(100% - 364px - 32px); }
}

/* ---------- accounts, families and sharing ---------- */

.owner-only { display: none; }
.owner .owner-only { display: block; }

.google-button[hidden] { display: none; }
.google-button { display: flex; justify-content: center; min-height: 44px; margin-top: 18px; color-scheme: light; /* stops a white box behind Google's button in dark mode */ }
.google-button iframe { color-scheme: normal; }
.invite-note {
  margin: 12px 0 0;
  padding: 10px 12px;
  border-radius: 8px;
  background: color-mix(in srgb, var(--accent) 12%, transparent);
  font-size: 14px;
}
.invite-note[hidden], .dev-form[hidden], .login-card section[hidden], .login-card label[hidden] { display: none; }
.dev-form { margin-top: 18px; padding-top: 4px; border-top: 1px dashed var(--border); }

.welcome-card { position: relative; }
#welcome .login-stack { width: min(420px, 100%); }
.welcome-card section { margin-top: 20px; padding-top: 16px; border-top: 1px solid var(--border); }
.welcome-card h2 { margin: 0; font-size: 16px; font-weight: 600; }
.welcome-card > .hint { margin-top: 20px; }
.welcome-card button.link { width: auto; margin: 8px auto 0; display: flex; }
.welcome-close { position: absolute; top: 10px; right: 10px; width: auto !important; margin: 0 !important; border: 0; background: none; padding: 6px !important; }

.share-dialog { width: min(520px, calc(100vw - 32px)); }
.share-dialog h3 { margin: 22px 0 6px; font-size: 14px; }
.share-link { display: flex; gap: 12px; align-items: center; justify-content: space-between; padding: 12px 0; border-bottom: 1px solid var(--border); }
.share-link .hint { margin-top: 2px; }
.share-actions { display: flex; gap: 6px; align-items: center; flex: none; }
.share-actions a.button {
  display: inline-flex; align-items: center; padding: 6px 12px; border-radius: 8px;
  border: 1px solid var(--border); background: var(--surface); color: inherit; text-decoration: none;
}
.share-actions a.button:hover { background: var(--surface-2); }
.share-actions .menu-items { right: 0; left: auto; }
.share-links > .hint { margin-top: 10px; }
.members { list-style: none; margin: 0; padding: 0; max-height: 40vh; overflow-y: auto; }
.members li { display: flex; align-items: center; gap: 10px; padding: 8px 0; }
.member-photo {
  width: 32px; height: 32px; border-radius: 50%; flex: none; object-fit: cover;
  display: grid; place-items: center; background: var(--surface-2); color: var(--muted); font-weight: 600;
}
.member-name { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.member-name strong { font-weight: 500; }
.member-name .hint { margin: 0; font-size: 12px; overflow: hidden; text-overflow: ellipsis; }
.member-role { font-size: 13px; color: var(--muted); }
.members select { width: auto; flex: none; margin: 0; padding: 4px 6px; font-size: 14px; border-radius: 6px; border: 1px solid var(--field-border); background: var(--bg); }
.share-dialog .dialog-actions .spacer { display: block; flex: 1; }
@media (max-width: 520px) {
  .share-link { flex-direction: column; align-items: stretch; }
}

/* Birthplace suggestions from Google Maps. */
.place-field { position: relative; }
.place-list {
  position: absolute; z-index: 5; left: 0; right: 0; top: 100%; margin: 4px 0 0; padding: 4px;
  list-style: none; background: var(--surface); border: 1px solid var(--border); border-radius: 8px; box-shadow: var(--shadow);
}
.place-list[hidden] { display: none; }
.place-list li { padding: 7px 8px; border-radius: 6px; cursor: pointer; font-size: 14px; line-height: 1.3; }
.place-list li small { display: block; color: var(--muted); font-size: 12px; }
.place-list li[aria-selected="true"], .place-list li:hover { background: var(--surface-2); }
.place-list .powered { cursor: default; padding: 4px 8px 2px; font-size: 11px; color: var(--muted); text-align: right; }
.place-list .powered:hover { background: none; }
.place-map { display: inline-flex; align-items: center; gap: 4px; margin-top: 4px; font-size: 12px; color: var(--accent); }
.place-map .icon-svg { width: 13px; height: 13px; }
.place-map[hidden] { display: none; }

/* Email and password sign-in. */
.login-or { display: flex; align-items: center; gap: 10px; margin: 16px 0 0; color: var(--muted); font-size: 13px; }
.login-or::before, .login-or::after { content: ""; flex: 1; border-top: 1px solid var(--border); }
.login-or[hidden], .email-form[hidden], .email-form [hidden], .email-sent[hidden] { display: none; }
.email-form { margin-top: 12px; }
.email-form h2 { margin: 4px 0 0; font-size: 15px; font-weight: 600; }
.email-form .primary { margin-top: 16px; }
.email-links { display: flex; flex-wrap: wrap; justify-content: center; gap: 4px 12px; margin: 10px 0 0; }
.login-card .email-links button.link { width: auto; margin: 0; padding: 4px; }
.email-sent { margin: 16px 0 0; padding: 12px; border-radius: 8px; background: color-mix(in srgb, var(--accent) 12%, transparent); font-size: 14px; line-height: 1.5; }
.login-card .email-sent button.link { width: auto; margin: 6px 0 0; padding: 0; display: block; }
.dev-link { display: block; margin-top: 8px; font-size: 13px; color: var(--muted); }
.dev-link a { color: var(--accent); }
.login-card .login-prompt { margin: 0; text-align: center; }
.login-card > .invite-note:first-child { margin-top: 0; }
.invite-note:not([hidden]) + .login-prompt { margin-top: 12px; }
