/* ─────────────────────────────────────────────────────────────────────
   Родовід Паливода — оформлення
   ───────────────────────────────────────────────────────────────────── */

:root {
  --bg:            #f5f5f7;
  --bg-elevated:   #ffffff;
  --surface:       rgba(255,255,255,.72);
  --surface-solid: #ffffff;
  --stroke:        rgba(0,0,0,.09);
  --stroke-strong: rgba(0,0,0,.16);
  --text:          #1d1d1f;
  --text-2:        #6e6e73;
  --text-3:        #8e8e93;
  --accent:        #0071e3;
  --accent-soft:   rgba(0,113,227,.12);
  --male:          #2f77d6;
  --female:        #c2568f;
  --shadow-s: 0 1px 2px rgba(0,0,0,.06), 0 4px 12px rgba(0,0,0,.05);
  --shadow-m: 0 2px 6px rgba(0,0,0,.07), 0 12px 32px rgba(0,0,0,.10);
  --shadow-l: 0 8px 24px rgba(0,0,0,.10), 0 32px 72px rgba(0,0,0,.16);
  --r-s: 12px; --r-m: 18px; --r-l: 26px; --r-xl: 34px;
  --ease: cubic-bezier(.32,.72,0,1);
  --dur: .42s;
  --topbar-h: 60px;
  color-scheme: light;
}

/* Світла тема — основна. Темна вмикається лише перемикачем, а не системою. */
:root[data-theme="dark"] {
  --bg:            #000000;
  --bg-elevated:   #1c1c1e;
  --surface:       rgba(28,28,30,.72);
  --surface-solid: #1c1c1e;
  --stroke:        rgba(255,255,255,.10);
  --stroke-strong: rgba(255,255,255,.20);
  --text:          #f5f5f7;
  --text-2:        #a1a1a6;
  --text-3:        #8e8e93;
  --accent:        #0a84ff;
  --accent-soft:   rgba(10,132,255,.18);
  --male:          #6aa9f5;
  --female:        #e08ab6;
  --shadow-s: 0 1px 2px rgba(0,0,0,.5);
  --shadow-m: 0 4px 16px rgba(0,0,0,.55);
  --shadow-l: 0 16px 48px rgba(0,0,0,.7);
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Display", "SF Pro Text",
               "Helvetica Neue", "Segoe UI", system-ui, sans-serif;
  font-size: 15px;
  line-height: 1.47;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
  overscroll-behavior: none;
}
button { font: inherit; color: inherit; border: 0; background: none; cursor: pointer; }
input { font: inherit; color: inherit; }
img { max-width: 100%; display: block; }
[hidden] { display: none !important; }

/* ── Заставка ─────────────────────────────────────────────────────── */
.intro {
  position: fixed; inset: 0; z-index: 60;
  display: grid; place-items: center;
  padding: 32px 24px;
  background: var(--bg);
  overflow: hidden;
  transition: opacity .6s var(--ease), transform .7s var(--ease);
}
.intro.leaving { opacity: 0; transform: scale(1.04); pointer-events: none; }
.intro-glow {
  position: absolute; width: min(120vw, 1100px); aspect-ratio: 1;
  background: radial-gradient(circle at 50% 50%,
              rgba(0,113,227,.20), rgba(194,86,143,.14) 38%, transparent 66%);
  filter: blur(40px);
  animation: drift 22s ease-in-out infinite alternate;
}
@keyframes drift {
  from { transform: translate3d(-6%,-4%,0) scale(1); }
  to   { transform: translate3d(6%,5%,0) scale(1.12); }
}
.intro-inner { position: relative; text-align: center; max-width: 680px; }
.intro-eyebrow {
  margin: 0 0 10px; font-size: 13px; font-weight: 600; letter-spacing: .08em;
  text-transform: uppercase; color: var(--text-3);
  animation: rise .8s var(--ease) both;
}
.intro-title {
  margin: 0; font-size: clamp(52px, 13vw, 108px); font-weight: 700;
  letter-spacing: -.045em; line-height: .95;
  animation: rise .9s var(--ease) .06s both;
}
.intro-sub {
  margin: 18px auto 0; max-width: 30ch; font-size: clamp(16px, 2.4vw, 20px);
  color: var(--text-2); animation: rise .9s var(--ease) .14s both;
}
.intro-stats {
  display: flex; flex-wrap: wrap; justify-content: center; gap: 10px 34px;
  margin: 40px 0 36px; animation: rise .9s var(--ease) .22s both;
}
.intro-stat { min-width: 84px; }
.intro-stat b {
  display: block; font-size: clamp(26px, 4.6vw, 38px); font-weight: 700;
  letter-spacing: -.03em; font-variant-numeric: tabular-nums;
}
.intro-stat span { font-size: 12.5px; color: var(--text-3); }
@keyframes rise { from { opacity: 0; transform: translateY(18px); } to { opacity: 1; transform: none; } }

.btn-primary {
  display: inline-flex; align-items: center; gap: 8px;
  padding: 13px 24px; border-radius: 980px;
  background: var(--accent); color: #fff; font-weight: 600; font-size: 16px;
  box-shadow: 0 6px 20px rgba(0,113,227,.32);
  transition: transform .25s var(--ease), box-shadow .25s var(--ease), filter .2s;
  animation: rise .9s var(--ease) .3s both;
}
.btn-primary:hover { transform: translateY(-1px) scale(1.02); filter: brightness(1.06); }
.btn-primary:active { transform: scale(.97); }
.intro-scroll {
  position: absolute; bottom: 26px; left: 50%; width: 1px; height: 46px;
  background: linear-gradient(var(--text-3), transparent);
  opacity: .5; animation: rise 1s var(--ease) .5s both;
}

/* ── Верхня панель ────────────────────────────────────────────────── */
.app { display: flex; flex-direction: column; height: 100dvh; }
.topbar {
  position: sticky; top: 0; z-index: 30;
  display: flex; align-items: center; gap: 16px;
  height: var(--topbar-h); padding: 0 16px;
  background: var(--surface);
  -webkit-backdrop-filter: saturate(180%) blur(22px);
  backdrop-filter: saturate(180%) blur(22px);
  border-bottom: 1px solid var(--stroke);
}
.brand { display: flex; align-items: center; gap: 9px; flex: 0 0 auto; }
.brand-mark {
  width: 22px; height: 22px; border-radius: 7px;
  background: linear-gradient(145deg, var(--accent), var(--female));
  box-shadow: inset 0 0 0 1px rgba(255,255,255,.25);
}
.brand-text { font-weight: 600; letter-spacing: -.015em; white-space: nowrap; }

.segmented {
  position: relative; display: flex; gap: 2px; padding: 3px;
  background: color-mix(in srgb, var(--text) 7%, transparent);
  border-radius: 980px; margin: 0 auto;
}
.seg {
  position: relative; z-index: 1; padding: 6px 15px; border-radius: 980px;
  font-size: 13.5px; font-weight: 500; color: var(--text-2);
  transition: color .25s var(--ease);
  white-space: nowrap;
}
.seg[aria-selected="true"] { color: var(--text); font-weight: 600; }
.seg-thumb {
  position: absolute; top: 3px; bottom: 3px; left: 3px; z-index: 0;
  border-radius: 980px; background: var(--surface-solid);
  box-shadow: var(--shadow-s);
  transition: transform .42s var(--ease), width .42s var(--ease);
}

.topbar-right { display: flex; align-items: center; gap: 10px; flex: 0 0 auto; }
.search { position: relative; display: flex; align-items: center; }
.search svg { position: absolute; left: 11px; color: var(--text-3); pointer-events: none; }
.search input {
  width: 190px; padding: 8px 12px 8px 32px; border-radius: 980px;
  background: color-mix(in srgb, var(--text) 7%, transparent);
  border: 1px solid transparent; outline: none;
  transition: width .38s var(--ease), background .25s, border-color .25s;
}
.search input:focus { width: 250px; background: var(--surface-solid); border-color: var(--accent); }
.search input::-webkit-search-cancel-button { -webkit-appearance: none; }
.search-results {
  position: absolute; top: calc(100% + 8px); right: 0; width: 330px; max-height: 60vh;
  overflow-y: auto; padding: 6px; border-radius: var(--r-m);
  background: var(--surface-solid); border: 1px solid var(--stroke);
  box-shadow: var(--shadow-l); z-index: 40;
}
.sr-item {
  display: flex; align-items: center; gap: 10px; width: 100%;
  padding: 7px 9px; border-radius: 10px; text-align: left;
  transition: background .18s;
}
.sr-item:hover, .sr-item.active { background: var(--accent-soft); }
.sr-item .av { width: 34px; height: 34px; flex: 0 0 auto; }
.sr-name { font-weight: 500; font-size: 14px; }
.sr-meta { font-size: 12px; color: var(--text-3); }
.sr-empty { padding: 14px; text-align: center; color: var(--text-3); font-size: 13.5px; }

.icon-btn {
  display: grid; place-items: center; width: 34px; height: 34px;
  border-radius: 50%; color: var(--text-2);
  transition: background .2s, color .2s, transform .2s var(--ease);
}
.icon-btn:hover { background: color-mix(in srgb, var(--text) 8%, transparent); color: var(--text); }
.icon-btn:active { transform: scale(.92); }

/* ── Загальне для видів ───────────────────────────────────────────── */
.view { flex: 1; min-height: 0; position: relative; }
.view-people, .view-timeline, .view-places { overflow-y: auto; padding: 26px 20px 60px; }

/* ── Дерево ───────────────────────────────────────────────────────── */
.tree-controls {
  position: absolute; top: 14px; left: 14px; z-index: 10;
  display: flex; gap: 8px; flex-wrap: wrap;
}
.pill-group { display: flex; padding: 3px; gap: 2px; border-radius: 980px;
  background: var(--surface); -webkit-backdrop-filter: blur(18px); backdrop-filter: blur(18px);
  border: 1px solid var(--stroke); box-shadow: var(--shadow-s); }
.pill {
  padding: 6px 14px; border-radius: 980px; font-size: 13px; font-weight: 500;
  color: var(--text-2); transition: background .22s, color .22s;
}
.pill.active { background: var(--accent); color: #fff; font-weight: 600; }
.pill-wide {
  display: flex; align-items: center; gap: 7px; max-width: 260px;
  padding: 8px 14px; border-radius: 980px;
  background: var(--surface); -webkit-backdrop-filter: blur(18px); backdrop-filter: blur(18px);
  border: 1px solid var(--stroke); box-shadow: var(--shadow-s);
  font-size: 13px; font-weight: 500;
}
.pill-wide span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.pill-wide:hover { border-color: var(--stroke-strong); }

.stage {
  position: absolute; inset: 0; overflow: hidden;
  cursor: grab; touch-action: none;
  background:
    radial-gradient(circle at 18% 12%, color-mix(in srgb, var(--accent) 7%, transparent), transparent 42%),
    radial-gradient(circle at 82% 84%, color-mix(in srgb, var(--female) 7%, transparent), transparent 45%);
}
.stage.dragging { cursor: grabbing; }
.stage-inner { position: absolute; top: 0; left: 0; transform-origin: 0 0; will-change: transform; }
.links { position: absolute; top: 0; left: 0; overflow: visible; pointer-events: none; }
.link-path { fill: none; stroke: var(--stroke-strong); stroke-width: 1.6px; }
.link-path.hot { stroke: var(--accent); stroke-width: 2.4px; }
.nodes { position: absolute; top: 0; left: 0; }

.stage-hint {
  position: absolute; bottom: 16px; left: 50%; transform: translateX(-50%);
  padding: 7px 15px; border-radius: 980px; font-size: 12.5px; color: var(--text-2);
  background: var(--surface); -webkit-backdrop-filter: blur(18px); backdrop-filter: blur(18px);
  border: 1px solid var(--stroke); pointer-events: none;
  transition: opacity .5s;
}
.stage-hint.gone { opacity: 0; }

.zoom {
  position: absolute; right: 14px; bottom: 14px; z-index: 10;
  display: flex; flex-direction: column; gap: 2px; padding: 4px;
  border-radius: 16px; background: var(--surface);
  -webkit-backdrop-filter: blur(18px); backdrop-filter: blur(18px);
  border: 1px solid var(--stroke); box-shadow: var(--shadow-s);
}
.zoom .icon-btn { width: 32px; height: 32px; font-size: 17px; }

/* Вузол дерева */
.node {
  position: absolute; width: 180px;
  display: flex; align-items: center; gap: 10px;
  padding: 8px 11px 8px 8px; border-radius: var(--r-m);
  background: var(--surface-solid);
  border: 1px solid var(--stroke);
  box-shadow: var(--shadow-s);
  transition: transform .28s var(--ease), box-shadow .28s var(--ease), border-color .2s;
  animation: pop .5s var(--ease) both;
  cursor: pointer;
}
@keyframes pop { from { opacity: 0; transform: translateY(10px) scale(.94); } to { opacity: 1; transform: none; } }
.node:hover { transform: translateY(-2px) scale(1.025); box-shadow: var(--shadow-m); border-color: var(--stroke-strong); z-index: 5; }
.node.is-root { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft), var(--shadow-m); }
.node.is-owner::after {
  content: "це ви"; position: absolute; top: -8px; right: 8px;
  padding: 1px 7px; border-radius: 980px; font-size: 10px; font-weight: 600;
  background: var(--accent); color: #fff;
}
.node-text { min-width: 0; }
.node-name {
  font-size: 13.5px; font-weight: 600; letter-spacing: -.01em;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.node-years { font-size: 11.5px; color: var(--text-3); font-variant-numeric: tabular-nums; }

/* Аватар */
.av {
  position: relative; width: 42px; height: 42px; flex: 0 0 auto;
  border-radius: 50%; overflow: hidden;
  background: color-mix(in srgb, var(--text) 8%, transparent);
  display: grid; place-items: center;
  font-size: 14px; font-weight: 600; color: var(--text-3);
  box-shadow: inset 0 0 0 1px var(--stroke);
}
/* 🔑 Нічого не ріжемо у файлі — кадрує браузер, оригінал завжди цілий.
   Але типове «по центру» на портретах зрізає маківку й показує груди:
   на фотопортреті обличчя майже завжди у верхній третині. */
.av img { width: 100%; height: 100%; object-fit: cover; object-position: 50% 28%; }
.av.m { box-shadow: inset 0 0 0 2px var(--male); }
.av.f { box-shadow: inset 0 0 0 2px var(--female); }

/* Значок «є ще гілка» */
.node-more {
  position: absolute; bottom: -9px; left: 50%; transform: translateX(-50%);
  min-width: 20px; height: 18px; padding: 0 6px; border-radius: 980px;
  display: grid; place-items: center; font-size: 10.5px; font-weight: 700;
  background: var(--accent); color: #fff; box-shadow: var(--shadow-s);
}

/* ── Люди ─────────────────────────────────────────────────────────── */
.filters { display: flex; flex-wrap: wrap; gap: 8px; max-width: 1240px; margin: 0 auto 22px; }
.chip {
  padding: 7px 14px; border-radius: 980px; font-size: 13px; font-weight: 500;
  background: color-mix(in srgb, var(--text) 7%, transparent); color: var(--text-2);
  transition: background .2s, color .2s, transform .2s var(--ease);
}
.chip:hover { transform: translateY(-1px); }
.chip.active { background: var(--accent); color: #fff; font-weight: 600; }

.grid {
  display: grid; gap: 14px; max-width: 1240px; margin: 0 auto;
  grid-template-columns: repeat(auto-fill, minmax(184px, 1fr));
}
.card {
  padding: 18px 14px 16px; border-radius: var(--r-l); text-align: center;
  background: var(--surface-solid); border: 1px solid var(--stroke);
  box-shadow: var(--shadow-s); cursor: pointer;
  transition: transform .3s var(--ease), box-shadow .3s var(--ease);
  animation: pop .5s var(--ease) both;
}
.card:hover { transform: translateY(-4px); box-shadow: var(--shadow-m); }
.card .av { width: 76px; height: 76px; margin: 0 auto 11px; font-size: 24px; }
.card-name { font-size: 14.5px; font-weight: 600; letter-spacing: -.012em; }
.card-years { margin-top: 2px; font-size: 12.5px; color: var(--text-3); font-variant-numeric: tabular-nums; }
.card-rel { margin-top: 7px; font-size: 11.5px; color: var(--text-2);
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.section-title {
  max-width: 1240px; margin: 0 auto 14px; font-size: 26px; font-weight: 700;
  letter-spacing: -.03em;
}
.count-note { max-width: 1240px; margin: 0 auto 18px; color: var(--text-3); font-size: 13.5px; }

/* ── Хроніка ──────────────────────────────────────────────────────── */
.timeline { max-width: 820px; margin: 0 auto; position: relative; padding-left: 22px; }
.timeline::before {
  content: ""; position: absolute; left: 4px; top: 6px; bottom: 6px; width: 2px;
  background: linear-gradient(var(--stroke), var(--stroke-strong), var(--stroke));
  border-radius: 2px;
}
.tl-decade {
  position: relative; margin: 34px 0 14px; font-size: 22px; font-weight: 700;
  letter-spacing: -.02em;
}
.tl-decade::before {
  content: ""; position: absolute; left: -22px; top: 12px;
  width: 10px; height: 10px; border-radius: 50%;
  background: var(--accent); box-shadow: 0 0 0 4px var(--bg);
}
.tl-item {
  position: relative; display: flex; align-items: center; gap: 12px;
  padding: 10px 14px; margin-bottom: 8px; border-radius: var(--r-m);
  background: var(--surface-solid); border: 1px solid var(--stroke);
  box-shadow: var(--shadow-s); cursor: pointer;
  transition: transform .25s var(--ease), box-shadow .25s var(--ease);
}
.tl-item:hover { transform: translateX(3px); box-shadow: var(--shadow-m); }
.tl-item::before {
  content: ""; position: absolute; left: -22px; top: 50%; transform: translateY(-50%);
  width: 6px; height: 6px; border-radius: 50%;
  background: var(--text-3); box-shadow: 0 0 0 3px var(--bg);
}
.tl-year { flex: 0 0 46px; font-weight: 700; font-variant-numeric: tabular-nums; color: var(--text-2); }
.tl-text { min-width: 0; }
.tl-title { font-size: 14px; font-weight: 500; }
.tl-sub { font-size: 12.5px; color: var(--text-3); }
.tl-kind { margin-left: auto; font-size: 11px; padding: 2px 9px; border-radius: 980px;
  background: color-mix(in srgb, var(--text) 7%, transparent); color: var(--text-2); white-space: nowrap; }

/* ── Місця ────────────────────────────────────────────────────────── */
.places { max-width: 1000px; margin: 0 auto; display: grid; gap: 12px; }
.place {
  padding: 16px 18px; border-radius: var(--r-l);
  background: var(--surface-solid); border: 1px solid var(--stroke); box-shadow: var(--shadow-s);
}
.place h4 { margin: 0 0 4px; font-size: 16px; font-weight: 650; letter-spacing: -.015em; }
.place-count { font-size: 12.5px; color: var(--text-3); }
.place-people { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 11px; }
.mini {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 4px 11px 4px 4px; border-radius: 980px; font-size: 12.5px;
  background: color-mix(in srgb, var(--text) 6%, transparent);
  transition: background .2s, transform .2s var(--ease);
}
.mini:hover { background: var(--accent-soft); transform: translateY(-1px); }
.mini .av { width: 22px; height: 22px; font-size: 10px; }

/* ── Картка людини (панель) ───────────────────────────────────────── */
.sheet-backdrop {
  position: fixed; inset: 0; z-index: 45; background: rgba(0,0,0,.32);
  -webkit-backdrop-filter: blur(3px); backdrop-filter: blur(3px);
  animation: fade .3s ease both;
}
@keyframes fade { from { opacity: 0; } to { opacity: 1; } }
.sheet {
  position: fixed; z-index: 50; top: 0; right: 0; bottom: 0; width: min(460px, 100vw);
  overflow-y: auto; overscroll-behavior: contain;
  background: var(--bg-elevated); border-left: 1px solid var(--stroke);
  box-shadow: var(--shadow-l);
  animation: slideIn .5s var(--ease) both;
}
@keyframes slideIn { from { transform: translateX(34px); opacity: 0; } to { transform: none; opacity: 1; } }
.sheet-close {
  position: sticky; top: 12px; float: right; margin: 12px 14px 0 0; z-index: 2;
  display: grid; place-items: center; width: 30px; height: 30px; border-radius: 50%;
  background: color-mix(in srgb, var(--text) 9%, transparent); color: var(--text-2);
  -webkit-backdrop-filter: blur(10px); backdrop-filter: blur(10px);
}
.sheet-close:hover { background: color-mix(in srgb, var(--text) 16%, transparent); }
.sheet-body { padding: 8px 26px 46px; }

.sheet-hero { text-align: center; padding: 14px 0 6px; }
.sheet-hero .av { width: 118px; height: 118px; margin: 0 auto 14px; font-size: 38px; }
.sheet-name { font-size: 27px; font-weight: 700; letter-spacing: -.03em; line-height: 1.15; }
.sheet-years { margin-top: 5px; color: var(--text-2); font-variant-numeric: tabular-nums; }
.sheet-rel {
  display: inline-block; margin-top: 11px; padding: 4px 13px; border-radius: 980px;
  font-size: 12.5px; font-weight: 500; background: var(--accent-soft); color: var(--accent);
}
.sheet-actions { display: flex; gap: 8px; justify-content: center; margin: 18px 0 4px; }
.btn-ghost {
  padding: 8px 16px; border-radius: 980px; font-size: 13.5px; font-weight: 500;
  background: color-mix(in srgb, var(--text) 8%, transparent); color: var(--text);
  transition: background .2s, transform .2s var(--ease);
}
.btn-ghost:hover { background: color-mix(in srgb, var(--text) 14%, transparent); transform: translateY(-1px); }

.sheet h3 {
  margin: 30px 0 10px; font-size: 12px; font-weight: 600; letter-spacing: .07em;
  text-transform: uppercase; color: var(--text-3);
}
.facts { display: grid; gap: 1px; border-radius: var(--r-m); overflow: hidden;
  background: var(--stroke); border: 1px solid var(--stroke); }
.fact { display: flex; gap: 12px; padding: 11px 14px; background: var(--surface-solid); }
.fact-k { flex: 0 0 104px; color: var(--text-3); font-size: 13px; }
.fact-v { min-width: 0; font-size: 13.8px; }
.fact-v small { display: block; color: var(--text-3); font-size: 12.5px; }

.rel-row { display: flex; flex-wrap: wrap; gap: 7px; }
.gallery { display: grid; grid-template-columns: repeat(auto-fill, minmax(92px, 1fr)); gap: 7px; }
.gallery img {
  width: 100%; aspect-ratio: 1; object-fit: cover; object-position: 50% 32%;
  border-radius: 13px;
  cursor: zoom-in; transition: transform .3s var(--ease), box-shadow .3s var(--ease);
}
.gallery img:hover { transform: scale(1.04); box-shadow: var(--shadow-m); }

/* ── Вибір родоначальника ─────────────────────────────────────────── */
.picker-backdrop { position: fixed; inset: 0; z-index: 55; background: rgba(0,0,0,.34);
  -webkit-backdrop-filter: blur(3px); backdrop-filter: blur(3px); animation: fade .25s ease both; }
.picker {
  position: fixed; z-index: 56; top: 50%; left: 50%; transform: translate(-50%,-50%);
  width: min(430px, calc(100vw - 32px)); max-height: 72vh; display: flex; flex-direction: column;
  border-radius: var(--r-xl); background: var(--bg-elevated);
  border: 1px solid var(--stroke); box-shadow: var(--shadow-l);
  animation: popIn .4s var(--ease) both; overflow: hidden;
}
@keyframes popIn { from { opacity: 0; transform: translate(-50%,-48%) scale(.95); } to { opacity: 1; transform: translate(-50%,-50%) scale(1); } }
.picker-head { display: flex; align-items: center; justify-content: space-between;
  padding: 18px 20px 12px; border-bottom: 1px solid var(--stroke); }
.picker-head h3 { margin: 0; font-size: 17px; font-weight: 650; letter-spacing: -.02em; }
.picker-list { overflow-y: auto; padding: 8px; }
.picker-item { display: flex; align-items: center; gap: 11px; width: 100%;
  padding: 9px 11px; border-radius: 13px; text-align: left; transition: background .18s; }
.picker-item:hover { background: var(--accent-soft); }
.picker-item .av { width: 38px; height: 38px; }
.picker-n { font-weight: 550; font-size: 14px; }
.picker-m { font-size: 12px; color: var(--text-3); }

/* ── Фото на весь екран ───────────────────────────────────────────── */
.lightbox {
  position: fixed; inset: 0; z-index: 70; display: grid; place-items: center;
  padding: 40px 20px; background: rgba(0,0,0,.9);
  -webkit-backdrop-filter: blur(8px); backdrop-filter: blur(8px);
  animation: fade .25s ease both;
}
.lightbox img { max-width: 100%; max-height: 82vh; border-radius: 14px; box-shadow: var(--shadow-l); }
.lb-caption { margin-top: 14px; color: rgba(255,255,255,.72); font-size: 13.5px; text-align: center; }
.lb-close { position: absolute; top: 20px; right: 20px; display: grid; place-items: center;
  width: 38px; height: 38px; border-radius: 50%; color: #fff;
  background: rgba(255,255,255,.14); transition: background .2s; }
.lb-close:hover { background: rgba(255,255,255,.26); }

/* ── Вузькі екрани ────────────────────────────────────────────────── */
@media (max-width: 860px) {
  .brand-text { display: none; }
  .segmented { margin: 0; }
  .seg { padding: 6px 11px; font-size: 12.5px; }
  .search input { width: 40px; padding-left: 30px; }
  .search input:focus { width: 168px; }
}
@media (max-width: 620px) {
  .topbar { gap: 8px; padding: 0 12px; }
  .view-people, .view-timeline, .view-places { padding: 20px 14px 50px; }
  .grid { grid-template-columns: repeat(auto-fill, minmax(142px, 1fr)); gap: 10px; }
  .card .av { width: 62px; height: 62px; }
  .sheet { width: 100vw; border-left: 0; border-top-left-radius: var(--r-xl); border-top-right-radius: var(--r-xl);
    top: 7vh; animation: slideUp .5s var(--ease) both; }
  @keyframes slideUp { from { transform: translateY(30px); opacity: 0; } to { transform: none; opacity: 1; } }
  .sheet-body { padding: 8px 18px 40px; }
  .fact-k { flex-basis: 84px; }
  .tree-controls { top: 10px; left: 10px; }
  .stage-hint { display: none; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; transition-duration: .01ms !important; }
}

/* ─────────────────────────────────────────────────────────────────────
   Нові розділи: віяло, мапа, фотостіна, адмінка
   ───────────────────────────────────────────────────────────────────── */

/* ── «Цього дня в роді» ───────────────────────────────────────────── */
.today-strip { margin: -18px 0 30px; animation: rise .9s var(--ease) .26s both; }
.today-pill {
  display: inline-flex; align-items: center; gap: 9px;
  padding: 8px 16px; border-radius: 980px; font-size: 13.5px;
  background: var(--surface-solid); border: 1px solid var(--stroke);
  box-shadow: var(--shadow-s); color: var(--text-2);
  transition: transform .25s var(--ease), box-shadow .25s var(--ease);
}
.today-pill:hover { transform: translateY(-1px); box-shadow: var(--shadow-m); color: var(--text); }
.today-dot {
  width: 7px; height: 7px; border-radius: 50%; background: var(--accent);
  box-shadow: 0 0 0 4px var(--accent-soft);
}
.today-more {
  padding: 1px 7px; border-radius: 980px; font-size: 11px; font-weight: 600;
  background: var(--accent-soft); color: var(--accent);
}

/* ── Віяло предків ────────────────────────────────────────────────── */
.view-fan { display: flex; flex-direction: column; overflow: hidden; }
.fan-head {
  display: flex; align-items: center; gap: 12px;
  padding: 14px 20px 6px; flex: 0 0 auto;
}
.fan-count { font-size: 13px; color: var(--text-3); }
.fan-wrap {
  flex: 1; min-height: 0; display: grid; place-items: center;
  padding: 4px 16px 22px; overflow: auto;
}
#fanSvg { width: min(100%, 78vh); height: auto; max-height: 100%; }

.fan-seg {
  fill: color-mix(in srgb, var(--text) calc(4% + var(--k) * 3%), transparent);
  stroke: var(--bg); stroke-width: 1.5;
  cursor: pointer;
  transition: fill .22s var(--ease), transform .22s var(--ease);
}
.fan-seg.m { fill: color-mix(in srgb, var(--male) calc(11% + var(--k) * 9%), transparent); }
.fan-seg.f { fill: color-mix(in srgb, var(--female) calc(11% + var(--k) * 9%), transparent); }
.fan-seg:hover { fill: var(--accent); }
.fan-label {
  font-size: 12px; font-weight: 550; fill: var(--text);
  pointer-events: none; letter-spacing: -.01em;
}
.fan-sub { font-size: 10px; fill: var(--text-3); pointer-events: none; }
.fan-core { fill: var(--surface-solid); stroke: var(--stroke); stroke-width: 1.5; }
.fan-core-ring { fill: none; stroke: var(--accent); stroke-width: 3; }
.fan-core-name { font-size: 19px; font-weight: 700; fill: var(--text); letter-spacing: -.02em; }
.fan-core-sub { font-size: 12px; fill: var(--text-3); }

/* ── Хроніка: історичне тло ───────────────────────────────────────── */
.tl-era {
  position: relative; margin: 22px 0 12px; padding: 13px 18px;
  border-radius: var(--r-m);
  background: color-mix(in srgb, var(--text) 5%, transparent);
  border-left: 3px solid var(--text-3);
}
.tl-era.hard { border-left-color: #c4433a; background: color-mix(in srgb, #c4433a 9%, transparent); }
.tl-era::before {
  content: ""; position: absolute; left: -25px; top: 50%; transform: translateY(-50%);
  width: 8px; height: 8px; border-radius: 2px; background: var(--text-3);
  box-shadow: 0 0 0 3px var(--bg);
}
.tl-era.hard::before { background: #c4433a; }
.tl-era-name { font-size: 15px; font-weight: 650; letter-spacing: -.015em; }
.tl-era-meta { margin-top: 2px; font-size: 12.5px; color: var(--text-2); }

/* ── Мапа ─────────────────────────────────────────────────────────── */
.view-map { display: flex; flex-direction: column; overflow: hidden; padding: 0; }
.map-head { padding: 12px 20px 8px; font-size: 13px; color: var(--text-3); flex: 0 0 auto; }
.map-canvas { flex: 1; min-height: 0; }
.map-canvas .leaflet-container { width: 100%; height: 100%; background: var(--bg); font: inherit; }
.map-pin-wrap { background: none; border: 0; }
.map-pin {
  display: grid; place-items: center; border-radius: 50%;
  background: var(--accent); color: #fff; font-size: 12px; font-weight: 650;
  border: 2px solid var(--surface-solid); box-shadow: var(--shadow-m);
  transition: transform .2s var(--ease);
}
.map-pin:hover { transform: scale(1.12); }
.map-pop b { font-size: 14px; }
.map-pop-n { color: #6e6e73; font-size: 12px; margin: 2px 0 6px; }
.map-pop-l { font-size: 12.5px; line-height: 1.45; max-width: 240px; }
.map-people {
  flex: 0 0 auto; max-height: 34vh; overflow-y: auto;
  padding: 14px 20px 18px; border-top: 1px solid var(--stroke);
  background: var(--surface-solid);
}
.map-people h4 { margin: 0 0 10px; font-size: 15px; font-weight: 650; letter-spacing: -.015em; }
.leaflet-popup-content-wrapper { border-radius: 14px; }

/* ── Фотостіна ────────────────────────────────────────────────────── */
.photo-wall {
  display: grid; gap: 10px; max-width: 1240px; margin: 0 auto;
  grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
}
.ph {
  margin: 0; border-radius: var(--r-m); overflow: hidden;
  background: var(--surface-solid); border: 1px solid var(--stroke);
  box-shadow: var(--shadow-s); cursor: zoom-in;
  animation: pop .5s var(--ease) both;
  transition: transform .3s var(--ease), box-shadow .3s var(--ease);
  display: flex; flex-direction: column;
}
.ph:hover { transform: translateY(-3px); box-shadow: var(--shadow-m); }
.ph-shot { position: relative; }
.ph img { width: 100%; aspect-ratio: 3/4; object-fit: cover; object-position: 50% 34%;
         display: block; }
/* Підпис завжди на видноті: стіна з самих облич нічого не розповідає. */
.ph figcaption { padding: 9px 11px 11px; text-align: left; }
.ph-name {
  font-size: 13px; font-weight: 600; letter-spacing: -.012em; color: var(--text);
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.ph-sub {
  margin-top: 2px; font-size: 11.5px; color: var(--text-3); line-height: 1.35;
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden;
}
.lb-people { display: flex; flex-wrap: wrap; gap: 7px; justify-content: center; margin-top: 12px; }
.lb-people .mini { background: rgba(255,255,255,.14); color: #fff; }
.lb-people .mini:hover { background: rgba(255,255,255,.26); }

/* ── Вибір людини: пошук ──────────────────────────────────────────── */
.picker-search {
  margin: 10px 14px 4px; padding: 9px 14px; border-radius: 12px;
  background: color-mix(in srgb, var(--text) 6%, transparent);
  border: 1px solid transparent; outline: none;
}
.picker-search:focus { background: var(--surface-solid); border-color: var(--accent); }
.picker-new { color: var(--accent); font-weight: 600; }

/* ── Вхід і адмінка ───────────────────────────────────────────────── */
.auth { max-height: none; }
.auth-body { padding: 26px 24px 24px; display: flex; flex-direction: column; }
.auth-close { position: absolute; top: 12px; right: 12px; }
.auth-body h3 { margin: 0 0 8px; font-size: 20px; font-weight: 700; letter-spacing: -.025em; }
.auth-note { margin: 0 0 16px; font-size: 13.5px; color: var(--text-2); line-height: 1.5; }
.auth-input {
  padding: 11px 14px; border-radius: 12px; outline: none;
  background: color-mix(in srgb, var(--text) 6%, transparent);
  border: 1px solid var(--stroke);
}
.auth-input:focus { border-color: var(--accent); background: var(--surface-solid); }
.auth-err { margin-top: 9px; font-size: 13px; color: #d0453b; }
.auth-go { margin-top: 16px; align-self: flex-start; }
.auth-log {
  margin-top: 6px; max-height: 210px; overflow-y: auto;
  font-size: 12.5px; color: var(--text-2);
  border: 1px solid var(--stroke); border-radius: 12px; padding: 10px 12px;
}
.auth-log-row { padding: 3px 0; border-bottom: 1px solid var(--stroke); }
.auth-log-row:last-child { border-bottom: 0; }

/* рядок знімка: дата ліворуч, «Повернути» праворуч */
.backup-row {
  display: flex; align-items: center; gap: 10px;
  justify-content: space-between; padding: 6px 0;
}
.backup-row > span { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.backup-go { flex: none; padding: 4px 11px; font-size: 12px; }

.export-btn {
  display: block; width: 100%; text-align: left; margin: 8px 0; padding: 11px 14px;
}
.export-btn b { display: block; font-size: 14px; font-weight: 600; }
.export-btn span { display: block; margin-top: 2px; font-size: 12px; color: var(--text-2); }

/* знімок у картці, коли ввімкнено режим редагування */
.gal-cell { position: relative; display: block; }
.gal-cell.is-main img { outline: 2px solid var(--accent); outline-offset: -2px; }
.gal-tools {
  position: absolute; left: 4px; right: 4px; bottom: 4px;
  display: flex; gap: 4px; align-items: center; justify-content: flex-end;
  opacity: 0; transition: opacity .18s var(--ease);
}
.gal-cell:hover .gal-tools, .gal-cell:focus-within .gal-tools { opacity: 1; }
.gal-tools button {
  width: 24px; height: 24px; border: 0; border-radius: 50%; cursor: pointer;
  background: rgba(0,0,0,.62); color: #fff; font-size: 12px; line-height: 1;
  backdrop-filter: saturate(180%) blur(8px);
}
.gal-tools button:hover { background: rgba(0,0,0,.82); }
.gal-main {
  margin-right: auto; padding: 2px 7px; border-radius: 8px; font-size: 10px;
  background: var(--accent); color: #fff; letter-spacing: .02em;
}
/* на тачскріні наводити нічим — показуємо одразу */
@media (hover: none) { .gal-tools { opacity: 1; } }

/* довідка */
.help h3 { margin: 22px 0 8px; font-size: 15px; }
.help h3:first-child { margin-top: 4px; }
.help p, .help li { font-size: 13.5px; line-height: 1.55; color: var(--text-2); }
.help ol, .help ul { margin: 6px 0; padding-left: 20px; }
.help li { margin: 4px 0; }
.help b { color: var(--text); font-weight: 600; }
.help .help-key {
  margin: 10px 0; padding: 10px 12px; border-radius: var(--r-s);
  background: var(--accent-soft); color: var(--text); font-size: 13px; line-height: 1.5;
}

.icon-btn.on { background: var(--accent); color: #fff; }
.add-btn { font-size: 19px; font-weight: 500; }

.admin-bar {
  display: flex; flex-wrap: wrap; gap: 7px; justify-content: center;
  margin: 4px 0 6px; padding: 12px 0 2px; border-top: 1px dashed var(--stroke);
}
.admin-btn {
  padding: 7px 13px; border-radius: 980px; font-size: 12.5px; font-weight: 500;
  background: var(--accent-soft); color: var(--accent);
  transition: background .2s, transform .2s var(--ease);
}
.admin-btn:hover { transform: translateY(-1px); filter: brightness(.96); }
.admin-btn.danger { background: color-mix(in srgb, #d0453b 14%, transparent); color: #d0453b; }

/* ── Форма редагування ────────────────────────────────────────────── */
.edit-head {
  margin: 6px 0 18px; font-size: 20px; font-weight: 700; letter-spacing: -.025em;
}
.fld { display: block; margin-bottom: 13px; }
.fld > span { display: block; margin-bottom: 5px; font-size: 12px; color: var(--text-3); }
.fld input, .fld textarea {
  width: 100%; padding: 10px 13px; border-radius: 11px; outline: none;
  background: color-mix(in srgb, var(--text) 5%, transparent);
  border: 1px solid var(--stroke);
}
.fld input:focus, .fld textarea:focus { border-color: var(--accent); background: var(--surface-solid); }
.fld-row { display: flex; align-items: center; gap: 9px; }
.fld-row input { width: auto; }
.fld-row > span { margin: 0; font-size: 14px; color: var(--text); }

.mini-seg { display: flex; gap: 4px; }
.mini-seg button {
  flex: 1; padding: 8px 10px; border-radius: 10px; font-size: 13px;
  background: color-mix(in srgb, var(--text) 6%, transparent); color: var(--text-2);
  transition: background .2s, color .2s;
}
.mini-seg button.on { background: var(--accent); color: #fff; font-weight: 600; }

.facts-edit { display: grid; gap: 7px; margin-bottom: 10px; }
.fact-edit { display: flex; gap: 6px; }
.fact-edit input {
  flex: 1; min-width: 0; padding: 8px 11px; border-radius: 10px; outline: none;
  background: color-mix(in srgb, var(--text) 5%, transparent); border: 1px solid var(--stroke);
}
.fact-edit input:focus { border-color: var(--accent); }
.fact-del {
  flex: 0 0 32px; border-radius: 10px; color: var(--text-3);
  background: color-mix(in srgb, var(--text) 5%, transparent);
}
.fact-del:hover { color: #d0453b; }
.edit-actions { display: flex; gap: 9px; margin-top: 22px; }

.mini-x {
  margin-left: 2px; padding: 0 2px; font-size: 11px; color: var(--text-3);
  background: none; line-height: 1;
}
.mini-x:hover { color: #d0453b; }
.mini-add { color: var(--accent); font-weight: 600; padding-left: 11px; }

/* ── Спливне повідомлення ─────────────────────────────────────────── */
.toast {
  position: fixed; left: 50%; bottom: 28px; transform: translateX(-50%); z-index: 80;
  padding: 11px 20px; border-radius: 980px; font-size: 13.5px;
  background: var(--text); color: var(--bg);
  box-shadow: var(--shadow-l); animation: rise .35s var(--ease) both;
}

@media (max-width: 860px) {
  .segmented { overflow-x: auto; scrollbar-width: none; max-width: 52vw; }
  .segmented::-webkit-scrollbar { display: none; }
}
@media (max-width: 620px) {
  .photo-wall { grid-template-columns: repeat(auto-fill, minmax(118px, 1fr)); gap: 7px; }
  .fan-wrap { padding: 4px 8px 16px; }
  #fanSvg { width: 100%; }
  .map-people { max-height: 40vh; }
}

/* ── ШІ-режим ─────────────────────────────────────────────────────── */
.ai-btn { font-size: 16px; color: var(--accent); }
.ai-input {
  width: 100%; padding: 13px 15px; border-radius: 14px; resize: vertical;
  font: inherit; line-height: 1.5; outline: none;
  background: color-mix(in srgb, var(--text) 5%, transparent);
  border: 1px solid var(--stroke); color: var(--text);
}
.ai-input:focus { border-color: var(--accent); background: var(--surface-solid); }
.ai-out { margin-top: 18px; }
.ai-summary {
  padding: 12px 15px; border-radius: 13px; font-size: 13.5px; line-height: 1.5;
  background: var(--accent-soft); color: var(--text); margin-bottom: 12px;
}
.ai-op {
  display: grid; grid-template-columns: auto auto 1fr; gap: 4px 9px;
  align-items: start; padding: 10px 12px; margin-bottom: 6px;
  border-radius: 12px; border: 1px solid var(--stroke);
  background: var(--surface-solid); cursor: pointer;
  transition: border-color .2s;
}
.ai-op:hover { border-color: var(--stroke-strong); }
.ai-op input { margin-top: 2px; }
.ai-op-kind {
  padding: 1px 9px; border-radius: 980px; font-size: 11px; font-weight: 600;
  background: color-mix(in srgb, var(--text) 7%, transparent); color: var(--text-2);
  white-space: nowrap;
}
.ai-op-txt { font-size: 13.5px; line-height: 1.45; }
.ai-op-why { grid-column: 3; font-size: 12px; color: var(--text-3); }
.ai-question {
  padding: 9px 13px; margin: 8px 0; border-radius: 11px; font-size: 13px;
  background: color-mix(in srgb, #e8a33d 14%, transparent); color: var(--text);
}
.ai-model { margin-top: 12px; font-size: 11.5px; color: var(--text-3); }
.ai-rekey {
  margin-top: 18px; font-size: 12px; color: var(--text-3); text-decoration: underline;
}

/* ── Дівоче прізвище та історія змін ──────────────────────────────── */
.sheet-maiden { margin-top: 3px; font-size: 13.5px; color: var(--text-3); }
.card-maiden {
  margin-top: 2px; font-size: 11.5px; color: var(--text-3);
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.hist {
  display: grid; gap: 1px; border-radius: var(--r-m); overflow: hidden;
  background: var(--stroke); border: 1px solid var(--stroke);
}
.hist-row {
  display: grid; grid-template-columns: auto 1fr auto; gap: 10px;
  align-items: baseline; padding: 9px 13px; background: var(--surface-solid);
  font-size: 12.5px;
}
.hist-when { color: var(--text-3); font-variant-numeric: tabular-nums; white-space: nowrap; }
.hist-what { color: var(--text); }
.hist-who { color: var(--text-3); white-space: nowrap; }
@media (max-width: 620px) {
  .hist-row { grid-template-columns: 1fr; gap: 2px; }
}

/* Плитки OSM приглушуємо під загальний спокійний вигляд сайту. */
.map-canvas .leaflet-tile-pane { filter: saturate(.42) contrast(.93) brightness(1.04); }
:root[data-theme="dark"] .map-canvas .leaflet-tile-pane {
  filter: invert(1) hue-rotate(180deg) saturate(.3) brightness(.86) contrast(.95);
}
.leaflet-control-attribution { font-size: 10px; opacity: .7; }

/* ── Пошук: підказки, чому знайшлось ──────────────────────────────── */
.sr-item { align-items: center; }
.sr-text { min-width: 0; flex: 1; }
.sr-why {
  flex: 0 0 auto; max-width: 42%; padding: 2px 9px; border-radius: 980px;
  font-size: 11px; color: var(--text-2);
  background: color-mix(in srgb, var(--text) 7%, transparent);
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.sr-why.fuzzy { background: color-mix(in srgb, #e8a33d 18%, transparent); color: var(--text); }
.sr-suggest { justify-content: center; color: var(--accent); font-size: 13px; }
.search-results { width: 380px; }

/* Пошук усередині розділу «Люди» */
.people-search {
  position: relative; display: flex; align-items: center;
  max-width: 1240px; margin: 0 auto 16px;
}
.people-search svg { position: absolute; left: 16px; color: var(--text-3); pointer-events: none; }
.people-search input {
  width: 100%; padding: 12px 16px 12px 42px; border-radius: 14px; outline: none;
  background: var(--surface-solid); border: 1px solid var(--stroke);
  box-shadow: var(--shadow-s);
  transition: border-color .25s, box-shadow .25s;
}
.people-search input:focus { border-color: var(--accent); box-shadow: var(--shadow-m); }
.people-search input::-webkit-search-cancel-button { -webkit-appearance: none; }

@media (max-width: 620px) {
  .search-results { width: min(86vw, 340px); }
  .sr-why { display: none; }
}

.sr-meta { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sr-why { max-width: 46%; }

/* ── Пошук на телефоні ────────────────────────────────────────────────
   Список підказок не мав шансу зʼявитись: у .topbar стояв overflow-x,
   а він обрізає все, що спозиційоване absolute. Тепер панель не ріже,
   а сам список на вузькому екрані — fixed на всю ширину.
   ──────────────────────────────────────────────────────────────────── */
@media (max-width: 620px) {
  .search { flex: 1; min-width: 0; }
  .search input { width: 100%; }
  .search input:focus { width: 100%; }

  /* поки шукаємо — решта панелі відходить, поле займає весь рядок */
  body.searching .brand,
  body.searching .segmented,
  body.searching #themeBtn,
  body.searching #adminBtn,
  body.searching .ai-btn,
  body.searching .add-btn { display: none; }
  body.searching .search-cancel { display: block; }

  .search-results {
    position: fixed; left: 10px; right: 10px; width: auto;
    top: calc(var(--topbar-h) + 6px); max-height: 72vh;
    border-radius: var(--r-l);
  }
  .sr-item { padding: 10px; }
}

.search-cancel {
  display: none; flex: 0 0 auto; padding: 6px 4px;
  font-size: 14px; color: var(--accent); white-space: nowrap;
}

/* ── Щоб сторінка не їхала вбік ───────────────────────────────────────
   Панель — flex-рядок, і поки її діти не мали min-width:0, поле пошуку
   у фокусі розпирало її ширше за екран, і скролився вже весь документ.
   ──────────────────────────────────────────────────────────────────── */
html, body { max-width: 100%; overflow-x: hidden; }
.app { max-width: 100%; overflow-x: clip; }
.topbar { min-width: 0; }
.topbar > * { min-width: 0; }
.brand { overflow: hidden; }
.segmented { flex: 0 1 auto; min-width: 0; }
.topbar-right { min-width: 0; }
.view { max-width: 100%; }
.grid, .photo-wall, .timeline, .filters, .people-search { max-width: min(1240px, 100%); }

/* ── «Хто ви в цьому роді» ────────────────────────────────────────── */
.whoami {
  position: fixed; inset: 0; z-index: 58;
  display: grid; place-items: center; padding: 32px 20px;
  background: var(--bg); overflow: hidden;
  animation: fade .4s ease both;
}
.whoami-glow {
  position: absolute; width: min(110vw, 900px); aspect-ratio: 1;
  background: radial-gradient(circle at 50% 50%,
              rgba(0,113,227,.16), rgba(194,86,143,.10) 40%, transparent 68%);
  filter: blur(40px); animation: drift 22s ease-in-out infinite alternate;
}
.whoami-close { position: absolute; top: 18px; right: 18px; z-index: 2; }
.whoami-inner {
  position: relative; width: min(520px, 100%); text-align: center;
  display: flex; flex-direction: column; max-height: 100%;
}
.whoami-title {
  margin: 0; font-size: clamp(28px, 6vw, 40px); font-weight: 700; letter-spacing: -.035em;
  animation: rise .7s var(--ease) .04s both;
}
.whoami-sub {
  margin: 12px auto 26px; max-width: 34ch; color: var(--text-2);
  font-size: clamp(14.5px, 2vw, 16px); animation: rise .7s var(--ease) .1s both;
}
.whoami-field {
  position: relative; display: flex; align-items: center; flex: 0 0 auto;
  animation: rise .7s var(--ease) .16s both;
}
.whoami-field svg { position: absolute; left: 17px; color: var(--text-3); pointer-events: none; }
.whoami-field input {
  width: 100%; padding: 15px 18px 15px 46px; border-radius: 16px; outline: none;
  font-size: 16px; background: var(--surface-solid);
  border: 1px solid var(--stroke); box-shadow: var(--shadow-m);
  transition: border-color .25s;
}
.whoami-field input:focus { border-color: var(--accent); }
.whoami-field input::-webkit-search-cancel-button { -webkit-appearance: none; }

.whoami-results {
  flex: 1 1 auto; min-height: 0; overflow-y: auto;
  margin-top: 12px; text-align: left;
  animation: rise .7s var(--ease) .22s both;
}
.whoami-hint {
  padding: 6px 4px 8px; font-size: 12px; color: var(--text-3);
  text-transform: uppercase; letter-spacing: .06em;
}
.whoami-item {
  display: flex; align-items: center; gap: 12px; width: 100%;
  padding: 10px 12px; margin-bottom: 5px; border-radius: 14px; text-align: left;
  background: var(--surface-solid); border: 1px solid var(--stroke);
  transition: border-color .2s, transform .2s var(--ease);
}
.whoami-item:hover { border-color: var(--accent); transform: translateX(2px); }
.whoami-item .av { width: 42px; height: 42px; }
.whoami-skip {
  flex: 0 0 auto; margin-top: 18px; padding: 10px; font-size: 13.5px;
  color: var(--text-3); animation: rise .7s var(--ease) .28s both;
}
.whoami-skip:hover { color: var(--text); }

/* фішка з обраною перспективою */
.viewer-chip {
  display: flex; align-items: center; gap: 7px; flex: 0 0 auto;
  padding: 3px 12px 3px 3px; border-radius: 980px;
  background: color-mix(in srgb, var(--text) 7%, transparent);
  font-size: 13px; font-weight: 500; max-width: 160px;
  transition: background .2s, transform .2s var(--ease);
}
.viewer-chip:hover { background: color-mix(in srgb, var(--text) 13%, transparent); transform: translateY(-1px); }
.viewer-chip .av { width: 26px; height: 26px; font-size: 10px; }
.viewer-chip span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

@media (max-width: 860px) { .viewer-chip span { display: none; } .viewer-chip { padding: 3px; } }
@media (max-width: 620px) { body.searching .viewer-chip { display: none; } }

/* ── Через кого звʼязок і ланцюжок спорідненості ──────────────────── */
.sheet-via {
  display: flex; align-items: center; justify-content: center; gap: 8px;
  margin: 10px 0 2px; font-size: 12.5px; color: var(--text-3);
}
.chain {
  display: flex; align-items: center; gap: 4px; flex-wrap: wrap;
  padding: 12px 14px; border-radius: var(--r-m);
  background: color-mix(in srgb, var(--text) 4%, transparent);
  border: 1px solid var(--stroke);
}
.chain-arrow { color: var(--text-3); font-size: 12px; }
.chain-node {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 3px 10px 3px 3px; border-radius: 980px; font-size: 12.5px;
  background: var(--surface-solid); border: 1px solid var(--stroke);
  transition: border-color .2s, transform .2s var(--ease);
}
.chain-node:hover { border-color: var(--accent); transform: translateY(-1px); }
.chain-node .av { width: 22px; height: 22px; font-size: 9px; }
.chain-node.me { border-color: var(--accent); box-shadow: 0 0 0 2px var(--accent-soft); }
.chain-node.target { background: var(--accent-soft); }

/* ─────────────────────────────────────────────────────────────────────
   Рід у цифрах

   Кожен графік — один ряд величин, тому легенди немає: її роль виконує
   заголовок. Довжина смуги несе значення, колір — ні (крім імен, де пара
   кольорів перевірена валідатором і продубльована підписами).
   ───────────────────────────────────────────────────────────────────── */
.view-stats { overflow-y: auto; padding: 26px 20px 70px; }
.stats { max-width: 860px; margin: 0 auto; display: grid; gap: 28px; }

.tiles {
  display: grid; gap: 10px;
  grid-template-columns: repeat(auto-fit, minmax(126px, 1fr));
}
.tile {
  padding: 16px 14px; border-radius: var(--r-l); text-align: center;
  background: var(--surface-solid); border: 1px solid var(--stroke);
  box-shadow: var(--shadow-s);
}
.tile b {
  display: block; font-size: 27px; font-weight: 700; letter-spacing: -.03em;
  font-variant-numeric: tabular-nums;
}
.tile span { font-size: 12px; color: var(--text-3); }

.chart {
  padding: 20px 20px 18px; border-radius: var(--r-l);
  background: var(--surface-solid); border: 1px solid var(--stroke);
  box-shadow: var(--shadow-s);
}
.chart-title {
  margin: 0 0 4px; font-size: 17px; font-weight: 650; letter-spacing: -.02em;
  text-transform: none; color: var(--text);
}
.chart-note { margin: 0 0 16px; font-size: 12.5px; color: var(--text-3); line-height: 1.5; }

.bars { display: grid; gap: 7px; }
.bar-row {
  display: grid; grid-template-columns: minmax(84px, 150px) 1fr auto;
  align-items: center; gap: 12px; padding: 3px 0;
}
.bar-row.clickable { cursor: pointer; border-radius: 8px; }
.bar-row.clickable:hover .bar-label { color: var(--text); }
.bar-row.clickable:hover .bar-fill { filter: brightness(1.08); }
.bar-row.open .bar-label { color: var(--accent); }
.bar-label {
  font-size: 13px; color: var(--text-2);
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.bar-track {
  height: 10px; border-radius: 999px;
  background: color-mix(in srgb, var(--text) 6%, transparent);
  overflow: hidden;
}
/* Кінець смуги заокруглений і притиснутий до нульової лінії. */
.bar-fill {
  display: block; height: 100%; border-radius: 0 4px 4px 0;
  background: var(--accent);
  transition: width .5s var(--ease), filter .2s;
}
.bar-fill.tone-m { background: #2f77d6; }
.bar-fill.tone-f { background: #c2568f; }
:root[data-theme="dark"] .bar-fill.tone-m { background: #4a8fe0; }
:root[data-theme="dark"] .bar-fill.tone-f { background: #c9699c; }

.bar-value {
  font-size: 13px; font-weight: 600; color: var(--text);
  font-variant-numeric: tabular-nums; white-space: nowrap;
}
.bar-sub { grid-column: 1 / -1; margin: -4px 0 4px; font-size: 11.5px; color: var(--text-3); }
.bar-people {
  display: flex; flex-wrap: wrap; gap: 6px;
  padding: 8px 0 12px; animation: fade .3s ease both;
}
.bar-more { align-self: center; font-size: 12px; color: var(--text-3); }

.names-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 22px; }
.names-title {
  margin: 0 0 10px; font-size: 12px; font-weight: 600; letter-spacing: .07em;
  text-transform: uppercase; color: var(--text-3);
}

.month-list { display: grid; gap: 5px; }
.month-row {
  display: flex; align-items: center; gap: 11px; width: 100%;
  padding: 8px 10px; border-radius: 12px; text-align: left;
  transition: background .2s;
}
.month-row:hover { background: color-mix(in srgb, var(--text) 5%, transparent); }
.month-row.today { background: var(--accent-soft); }
.month-day {
  flex: 0 0 26px; text-align: center; font-weight: 700; font-size: 14px;
  color: var(--text-2); font-variant-numeric: tabular-nums;
}
.month-row .av { width: 32px; height: 32px; font-size: 11px; }
.month-name { font-size: 14px; font-weight: 500; }
.month-what { font-size: 12px; color: var(--text-3); }

@media (max-width: 620px) {
  .view-stats { padding: 20px 14px 60px; }
  .stats { gap: 20px; }
  .chart { padding: 16px 14px 14px; }
  .names-grid { grid-template-columns: 1fr; gap: 18px; }
  .bar-row { grid-template-columns: minmax(68px, 110px) 1fr auto; gap: 9px; }
}

/* ── Інструменти віяла ────────────────────────────────────────────── */
.fan-tools { display: flex; gap: 7px; margin-left: auto; }
.fan-tools .pill {
  background: var(--surface); border: 1px solid var(--stroke);
  -webkit-backdrop-filter: blur(18px); backdrop-filter: blur(18px);
  box-shadow: var(--shadow-s); color: var(--text-2);
}
.fan-tools .pill:hover { color: var(--text); border-color: var(--stroke-strong); }
.fan-tools .pill:disabled { opacity: .5; }

/* ── Друк: на папір іде саме віяло, без інтерфейсу ────────────────── */
@media print {
  body.printing-fan .topbar,
  body.printing-fan .fan-head,
  body.printing-fan .zoom,
  body.printing-fan .sheet,
  body.printing-fan .sheet-backdrop,
  body.printing-fan .stage-hint,
  body.printing-fan #intro,
  body.printing-fan #whoami { display: none !important; }
  body.printing-fan .app { height: auto; }
  body.printing-fan .view:not(.view-fan) { display: none !important; }
  body.printing-fan .fan-wrap { padding: 0; overflow: visible; }
  body.printing-fan #fanSvg { width: 100%; max-height: none; }
  body.printing-fan .fan-seg { stroke: #fff; }
  body.printing-fan { background: #fff; }
  @page { size: A3 landscape; margin: 10mm; }
}
@media (max-width: 620px) {
  .fan-head { flex-wrap: wrap; }
  .fan-tools { margin-left: 0; width: 100%; }
  .fan-tools .pill { flex: 1; }
}

/* ── Мобільна панель: вкладки важливіші за поле пошуку ─────────────────
   Раніше .search брав flex:1 і тиснув сегментований перемикач до нуля —
   на 320px вкладки зникали зовсім. Тепер поле згорнуте в іконку, а
   розгортається лише у фокусі (body.searching).
   ──────────────────────────────────────────────────────────────────── */
@media (max-width: 620px) {
  .segmented { flex: 1 1 auto; min-width: 0; max-width: none; }
  .search { flex: 0 0 auto; }
  .search input { width: 38px; padding-left: 30px; }
  .search input:focus { width: 38px; }
  body.searching .search { flex: 1 1 auto; }
  body.searching .search input,
  body.searching .search input:focus { width: 100%; padding-left: 36px; }
}

/* ── Вибір акаунта у вході ────────────────────────────────────────── */
.auth-who { margin-bottom: 14px; }
.auth-who button { padding: 10px 12px; }
.auth-body .auth-input + .auth-input { margin-top: 9px; }
.auth-actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 18px; }
.btn-ghost.danger { color: #d0453b; background: color-mix(in srgb, #d0453b 12%, transparent); }
.btn-ghost.danger:hover { background: color-mix(in srgb, #d0453b 20%, transparent); }

/* Кути звʼязків — прямі, без згладжування. */
.link-path { stroke-linejoin: miter; stroke-linecap: butt; }

/* Ширину картки задає розкладка — у повному вигляді вона вужча. */
.node { width: var(--node-w, 180px); }
.stage.compact .node { padding: 6px 9px 6px 6px; border-radius: 13px; }
.stage.compact .node .av { width: 30px; height: 30px; font-size: 11px; }
.stage.compact .node-name { font-size: 11.5px; }
.stage.compact .node-years { font-size: 10px; }
.stage.compact .node-more { height: 15px; font-size: 9.5px; }

/* Знайдену людину видно одразу: кільце, що двічі пульсує. */
.node.found {
  border-color: var(--accent);
  box-shadow: 0 0 0 4px var(--accent-soft), var(--shadow-m);
  animation: foundPulse 1.1s var(--ease) 2;
  z-index: 6;
}
@keyframes foundPulse {
  0%   { box-shadow: 0 0 0 0 color-mix(in srgb, var(--accent) 55%, transparent), var(--shadow-m); }
  70%  { box-shadow: 0 0 0 16px transparent, var(--shadow-m); }
  100% { box-shadow: 0 0 0 4px var(--accent-soft), var(--shadow-m); }
}

/* ── Кнопка ШІ: помітна, з підписом ──────────────────────────────── */
.ai-btn {
  display: inline-flex; align-items: center; gap: 8px; flex: 0 0 auto;
  padding: 8px 16px 8px 12px; border-radius: 980px;
  font-size: 12.5px; font-weight: 700; letter-spacing: .02em; text-transform: uppercase;
  color: #fff;
  background: linear-gradient(135deg, var(--accent), var(--female));
  box-shadow: 0 4px 14px color-mix(in srgb, var(--accent) 32%, transparent);
  transition: transform .22s var(--ease), box-shadow .22s var(--ease), filter .2s;
}
.ai-btn:hover { transform: translateY(-1px); filter: brightness(1.06);
  box-shadow: 0 6px 20px color-mix(in srgb, var(--accent) 40%, transparent); }
.ai-btn:active { transform: scale(.97); }
.ai-btn svg { flex: 0 0 auto; }

@media (max-width: 1100px) { .ai-btn span { display: none; } .ai-btn { padding: 8px; } }
@media (max-width: 620px) { body.searching .ai-btn { display: none; } }

/* ── Прикріплені фото в ШІ-режимі ─────────────────────────────────── */
.ai-drop {
  margin-top: 10px; padding: 16px 14px; border-radius: 14px; text-align: center;
  font-size: 13px; color: var(--text-3); cursor: pointer;
  border: 1.5px dashed var(--stroke-strong);
  background: color-mix(in srgb, var(--text) 3%, transparent);
  transition: border-color .2s, background .2s, color .2s;
}
.ai-drop b { color: var(--accent); font-weight: 600; }
.ai-drop:hover, .ai-drop.over { border-color: var(--accent); color: var(--text-2);
  background: var(--accent-soft); }
.ai-drop.has { padding: 10px; font-size: 12px; }

.ai-files { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 10px; }
.ai-file {
  position: relative; width: 92px; border-radius: 12px; overflow: hidden;
  background: var(--surface-solid); border: 1px solid var(--stroke);
}
.ai-file img { width: 100%; aspect-ratio: 1; object-fit: cover; display: block; }
.ai-file span {
  display: block; padding: 5px 6px; font-size: 10.5px; color: var(--text-3);
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.ai-file-x {
  position: absolute; top: 4px; right: 4px; width: 20px; height: 20px;
  border-radius: 50%; display: grid; place-items: center; font-size: 10px;
  background: rgba(0,0,0,.55); color: #fff;
}
.ai-file-x:hover { background: rgba(0,0,0,.8); }

/* ── Картка людини не блокує дерево ───────────────────────────────────
   Раніше вона затуляла екран півпрозорим щитом: подивитись когось іншого
   можна було, лише закривши її. Тепер на широкому екрані сцена просто
   стає вужчою, а дерево лишається живим — клік по іншій людині просто
   перемальовує картку.
   ──────────────────────────────────────────────────────────────────── */
:root { --sheet-w: 460px; }

@media (min-width: 861px) {
  .sheet-backdrop { display: none !important; }
  .sheet { box-shadow: -1px 0 0 var(--stroke), var(--shadow-l); }

  body.sheet-open .stage { right: var(--sheet-w); transition: right .35s var(--ease); }
  body.sheet-open .zoom { right: calc(var(--sheet-w) + 14px); transition: right .35s var(--ease); }
  .stage, .zoom { transition: right .35s var(--ease); }

  body.sheet-open .view-people,
  body.sheet-open .view-timeline,
  body.sheet-open .view-photos,
  body.sheet-open .view-stats,
  body.sheet-open .view-fan { padding-right: calc(var(--sheet-w) + 20px); }
  body.sheet-open .view-map .map-canvas,
  body.sheet-open .view-map .map-head,
  body.sheet-open .view-map .map-people { margin-right: var(--sheet-w); }
}

/* ── Редактор подій життя ─────────────────────────────────────────── */
.events-edit { display: grid; gap: 7px; margin-bottom: 10px; }
.event-edit { display: grid; grid-template-columns: 104px 1fr 1fr 1fr 32px; gap: 6px; }
.event-edit select, .event-edit input {
  min-width: 0; padding: 8px 10px; border-radius: 10px; outline: none;
  font: inherit; color: var(--text);
  background: color-mix(in srgb, var(--text) 5%, transparent);
  border: 1px solid var(--stroke);
}
.event-edit select { appearance: none; cursor: pointer; font-size: 12.5px; }
.event-edit input:focus, .event-edit select:focus { border-color: var(--accent); }
@media (max-width: 620px) {
  .event-edit { grid-template-columns: 1fr 1fr 32px; }
  .event-edit select { grid-column: 1 / 3; }
  .event-edit input:nth-of-type(3) { grid-column: 1 / 4; }
}
