* { box-sizing: border-box; }

html, body {
  margin: 0; height: 100%;
  background: var(--paper); color: var(--ink);
  font-family: var(--sans);
  -webkit-font-smoothing: antialiased;
  overscroll-behavior: none;
}
button { font: inherit; color: inherit; cursor: pointer; }
:focus-visible { outline: 2px solid var(--ochre); outline-offset: 2px; }

/* ------------------------------------------------------------------ шапка */
.head {
  position: fixed; inset: 0 0 auto 0; z-index: 30;
  height: var(--header-h);
  display: flex; align-items: center; gap: 16px;
  padding: 0 16px;
  background: color-mix(in srgb, var(--paper) 88%, transparent);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--rule);
}
.head__zeg { position: fixed; top: var(--header-h); left: 0; right: 0; z-index: 29; }

.brand { display: flex; align-items: baseline; gap: 10px; min-width: 0; }
.brand__name {
  font-family: var(--serif); font-size: 20px; letter-spacing: .04em;
  text-transform: uppercase; white-space: nowrap;
}
.brand__meta {
  font-size: 12px; color: var(--muted); white-space: nowrap;
  overflow: hidden; text-overflow: ellipsis;
}
.head__spacer { flex: 1; }

.btn {
  display: inline-flex; align-items: center; gap: 6px;
  height: 32px; padding: 0 11px;
  background: transparent; border: 1px solid var(--rule);
  border-radius: var(--r-md); font-size: 13px; white-space: nowrap;
  transition: background .12s, border-color .12s;
}
.btn:hover { background: var(--paper-sunk); border-color: var(--muted); }
a.btn { text-decoration: none; }
.btn[aria-pressed="true"] {
  background: var(--ochre); border-color: var(--ochre); color: #fff;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .btn[aria-pressed="true"] { color: #16130F; }
}
:root[data-theme="dark"] .btn[aria-pressed="true"] { color: #16130F; }
:root[data-theme="light"] .btn[aria-pressed="true"] { color: #fff; }
.btn--ghost { border-color: transparent; }
.btn--primary {
  background: var(--indigo); border-color: var(--indigo); color: var(--paper-raised);
}
.btn--primary:hover { filter: brightness(1.12); background: var(--indigo); }
.btn kbd {
  font-family: var(--mono); font-size: 10px; color: var(--muted);
  border: 1px solid var(--rule); border-radius: var(--r-sm); padding: 1px 4px;
}

.seg { display: flex; border: 1px solid var(--rule); border-radius: var(--r-md); overflow: hidden; }
.seg .btn { border: 0; border-radius: 0; height: 30px; }
.seg .btn + .btn { border-left: 1px solid var(--rule); }

/* ------------------------------------------------------------------ холст */
.stage {
  position: fixed; inset: calc(var(--header-h) + 10px) 0 0 0;
  overflow: hidden; touch-action: none; cursor: grab;
}
.stage[hidden] { display: none; }
.stage.is-panning { cursor: grabbing; }
.stage svg { display: block; width: 100%; height: 100%; }

/* Узлы. Всё оформление карточек живёт здесь, а не в рендере: так
   тему можно менять, не трогая генерацию SVG. */
.node__box {
  fill: var(--paper-raised); stroke: var(--indigo-soft); stroke-width: 1;
  transition: stroke .12s, fill .12s;
}
.node__name {
  font-family: var(--serif); font-size: 14px; fill: var(--ink);
  dominant-baseline: middle;
}
.node__name--gone { fill: var(--ink-soft); }
.node__alt { font-family: var(--serif); font-size: 11px; fill: var(--ochre); }
.node__years {
  font-family: var(--mono); font-size: 10.5px; fill: var(--muted);
  font-variant-numeric: tabular-nums; text-anchor: end; dominant-baseline: middle;
}
.node__rule { stroke: var(--rule); stroke-width: 1; }
.node__diamond { fill: var(--ochre); }
.node__flag { fill: var(--ochre); }
.node__echo {
  font-family: var(--sans); font-size: 9px; letter-spacing: .04em;
  fill: var(--ochre); opacity: .9;
}
.node__marriage {
  font-family: var(--sans); font-size: 9.5px; letter-spacing: .06em;
  fill: var(--ochre); text-anchor: middle; text-transform: uppercase;
}

.node { cursor: pointer; }
.node:hover .node__box { stroke: var(--ochre); }
.node.is-selected .node__box { stroke: var(--ochre); stroke-width: 2; }
.node.is-selected .node__tick { stroke: var(--ochre); stroke-width: 2; fill: none; }
.node.is-lineage .node__box { stroke: var(--ochre); }

.link { fill: none; stroke: var(--indigo); stroke-width: 1.25; opacity: .45; }
.link.is-lineage { opacity: 1; stroke-width: 2; stroke: var(--ochre); }

/* Приглушение всего, что вне выбранной линии. */
.stage.is-focused .node:not(.is-lineage):not(.is-selected) { opacity: .22; }
.stage.is-focused .link:not(.is-lineage) { opacity: .1; }
.stage.is-dimmed .node:not(.is-match) { opacity: .18; }

/* ---------------------------------------------------------- зум-управление */
.zoombar {
  position: fixed; left: 16px; bottom: 16px; z-index: 20;
  display: flex; flex-direction: column; gap: 1px;
  background: var(--rule); border: 1px solid var(--rule);
  border-radius: var(--r-md); overflow: hidden; box-shadow: var(--shadow);
}
.zoombar[hidden] { display: none; }
.zoombar .btn {
  border: 0; border-radius: 0; background: var(--paper-raised);
  width: 34px; height: 32px; justify-content: center; padding: 0;
}
.zoombar .btn--wide { width: auto; padding: 0 10px; font-size: 12px; }

.hint {
  position: fixed; right: 16px; bottom: 16px; z-index: 20;
  font-size: 11px; color: var(--muted); text-align: right; line-height: 1.6;
  pointer-events: none;
}

/* ------------------------------------------------------- панель человека */
.panel {
  position: fixed; top: var(--header-h); right: 0; bottom: 0; z-index: 25;
  width: var(--panel-w); max-width: 100vw;
  background: var(--paper-raised); border-left: 1px solid var(--rule);
  box-shadow: var(--shadow);
  transform: translateX(100%); transition: transform .22s cubic-bezier(.4, 0, .2, 1);
  display: flex; flex-direction: column;
}
.panel.is-open { transform: none; }
.panel__head { padding: 20px 20px 0; }
.panel__close {
  position: absolute; top: 12px; right: 12px;
  width: 30px; height: 30px; border: 0; background: transparent;
  border-radius: var(--r-md); font-size: 18px; line-height: 1; color: var(--muted);
}
.panel__close:hover { background: var(--paper-sunk); color: var(--ink); }
.panel__name { font-family: var(--serif); font-size: 26px; margin: 0 28px 2px 0; line-height: 1.15; }
.panel__alt { font-family: var(--serif); color: var(--ochre); font-size: 16px; }
.panel__years {
  font-family: var(--mono); font-size: 13px; color: var(--muted);
  font-variant-numeric: tabular-nums; margin-top: 6px;
}
.panel__body { padding: 0 20px 24px; overflow-y: auto; flex: 1; }
.panel__section { margin-top: 18px; }
.panel__label {
  font-size: 10.5px; letter-spacing: .12em; text-transform: uppercase;
  color: var(--muted); margin-bottom: 7px;
}
.panel__actions { display: flex; flex-wrap: wrap; gap: 6px; padding: 14px 20px; border-top: 1px solid var(--rule); }

.rel { display: flex; flex-direction: column; gap: 1px; }
.relitem {
  display: flex; align-items: baseline; gap: 8px; width: 100%;
  padding: 6px 8px; margin-left: -8px;
  background: transparent; border: 0; border-radius: var(--r-md);
  text-align: left; font-size: 14px;
}
.relitem:hover { background: var(--paper-sunk); }
.relitem__name { font-family: var(--serif); }
.relitem__years {
  margin-left: auto; font-family: var(--mono); font-size: 11px;
  color: var(--muted); font-variant-numeric: tabular-nums;
}
.relitem__tag { font-size: 11px; color: var(--muted); }

.bio {
  font-size: 13.5px; line-height: 1.65; color: var(--ink-soft);
  border-left: 2px solid var(--ochre); padding: 4px 0 4px 14px;
  font-family: var(--serif);
}
.note {
  font-size: 12.5px; line-height: 1.55; color: var(--muted);
  background: var(--paper-sunk); border-radius: var(--r-md); padding: 9px 11px;
}
.flag {
  display: inline-flex; align-items: center; gap: 5px;
  font-size: 11.5px; color: var(--ochre);
  background: color-mix(in srgb, var(--ochre) 12%, transparent);
  border-radius: 999px; padding: 3px 9px;
}

/* ------------------------------------------------------------------ поиск */
.scrim {
  position: fixed; inset: 0; z-index: 40;
  background: rgba(20, 17, 14, .35); backdrop-filter: blur(2px);
  display: flex; justify-content: center; align-items: flex-start;
  padding: 12vh 0 0;
  /* dvh вместо vh: мобильный Safari считает vh по экрану БЕЗ своих
     панелей, из-за чего низ листа с кнопками уезжал под адресную
     строку. dvh учитывает панели, а vh выше остаётся запасным
     значением для браузеров постарше. */
  padding: 12dvh 0 0;
}
.scrim[hidden] { display: none; }
.palette {
  width: min(560px, 92vw); max-height: 66vh; max-height: 66dvh;
  display: flex; flex-direction: column;
  background: var(--paper-raised); border: 1px solid var(--rule);
  border-radius: var(--r-lg); box-shadow: var(--shadow); overflow: hidden;
}
.palette input {
  border: 0; border-bottom: 1px solid var(--rule); background: transparent;
  padding: 15px 18px; font-size: 16px; font-family: var(--serif); color: var(--ink);
}
.palette input:focus { outline: none; }
.palette__list { overflow-y: auto; padding: 6px; }
.palette__item {
  display: flex; align-items: baseline; gap: 10px; width: 100%;
  padding: 9px 12px; border: 0; background: transparent;
  border-radius: var(--r-md); text-align: left;
}
.palette__item[aria-selected="true"] { background: var(--paper-sunk); }
.palette__item em { font-style: normal; color: var(--ochre); }
.palette__name { font-family: var(--serif); font-size: 15px; }
.palette__ctx { font-size: 12px; color: var(--muted); }
.palette__years {
  margin-left: auto; font-family: var(--mono); font-size: 11px;
  color: var(--muted); font-variant-numeric: tabular-nums;
}
.palette__empty { padding: 22px; text-align: center; color: var(--muted); font-size: 13px; }

/* ------------------------------------------------------------ форма правки */
.sheet {
  width: min(560px, 92vw); max-height: 82vh; max-height: 82dvh;
  display: flex; flex-direction: column;
  background: var(--paper-raised); border: 1px solid var(--rule);
  border-radius: var(--r-lg); box-shadow: var(--shadow); overflow: hidden;
}
.sheet__head { padding: 18px 20px 14px; border-bottom: 1px solid var(--rule); position: relative; }
.sheet__title { font-family: var(--serif); font-size: 20px; margin: 0; }
.sheet__sub { font-size: 12.5px; color: var(--muted); margin-top: 3px; }
.sheet__body { padding: 18px 20px; overflow-y: auto; }
.sheet__foot {
  display: flex; gap: 8px; justify-content: flex-end;
  padding: 14px 20px; border-top: 1px solid var(--rule); background: var(--paper-sunk);
  /* Вырез и полоса-индикатор снизу у айфонов: без этого кнопка
     прижимается вплотную к краю и по ней трудно попасть. */
  padding-bottom: calc(14px + env(safe-area-inset-bottom, 0px));
  flex: none;
}
.field { margin-bottom: 13px; }
.field > label {
  display: block; font-size: 11px; letter-spacing: .08em; text-transform: uppercase;
  color: var(--muted); margin-bottom: 5px;
}
.field input, .field select, .field textarea {
  width: 100%; padding: 9px 11px; font: inherit; font-size: 14px;
  color: var(--ink); background: var(--paper);
  border: 1px solid var(--rule); border-radius: var(--r-md);
}
.field input:focus, .field select:focus, .field textarea:focus {
  outline: none; border-color: var(--ochre);
}
.field__hint { font-size: 11.5px; color: var(--muted); margin-top: 4px; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 0 12px; }

.diff { font-family: var(--mono); font-size: 12px; line-height: 1.7; }
.diff__row { display: flex; gap: 8px; padding: 2px 8px; border-radius: var(--r-sm); }
.diff__row--add { background: color-mix(in srgb, #2E7D32 14%, transparent); }
.diff__row--del { background: color-mix(in srgb, #C62828 12%, transparent); }
.diff__key { color: var(--muted); min-width: 116px; }

/* ------------------------------------------------------------ лента (моб.) */
.feed {
  position: fixed; inset: calc(var(--header-h) + 10px) 0 0 0;
  overflow-y: auto; padding: 12px 14px 80px;
}
.feed[hidden] { display: none; }
.feed__node { border-left: 1px solid var(--rule); margin-left: 9px; padding-left: 14px; }
.feed__node:first-child { border-left: 0; margin-left: 0; padding-left: 0; }
.feed__card {
  display: flex; align-items: center; gap: 10px; width: 100%;
  padding: 9px 11px; margin: 3px 0 3px -1px;
  background: var(--paper-raised); border: 1px solid var(--rule);
  border-radius: var(--r-md); text-align: left; position: relative;
}
.feed__card.is-selected { border-color: var(--ochre); }
.feed__twist {
  width: 22px; height: 22px; flex: none; border: 0; border-radius: var(--r-sm);
  background: var(--paper-sunk); color: var(--muted); font-size: 10px; line-height: 1;
}
.feed__names { min-width: 0; flex: 1; }
.feed__pair {
  display: block; font-family: var(--serif); font-size: 15px; line-height: 1.35;
  overflow-wrap: anywhere;
}
.feed__pair span { color: var(--ink-soft); }
.feed__years {
  display: block; font-family: var(--mono); font-size: 11px; color: var(--muted);
  font-variant-numeric: tabular-nums;
}
.feed__count {
  font-size: 11px; color: var(--muted); background: var(--paper-sunk);
  border-radius: 999px; padding: 2px 8px; flex: none;
}

/* ------------------------------------------------------------------ сверка */
.audit { max-width: 860px; margin: 0 auto; padding: calc(var(--header-h) + 32px) 20px 80px; }
.audit h2 { font-family: var(--serif); font-size: 17px; margin: 28px 0 8px; }
.audit table { width: 100%; border-collapse: collapse; font-size: 13.5px; }
.audit td { padding: 5px 8px; border-bottom: 1px solid var(--rule); vertical-align: top; }
.audit td:first-child { font-family: var(--mono); font-size: 11px; color: var(--muted); width: 34px; }
.audit .yr { font-family: var(--mono); font-size: 11.5px; color: var(--muted); white-space: nowrap; }
.audit .q { color: var(--ochre); }

/* ------------------------------------------------------------------ мобилка */
.btn__short { display: none; }

@media (max-width: 720px) {
  :root { --panel-w: 100vw; }

  /* Диалог во весь экран: сверху остаётся полоска фона, чтобы было
     понятно, что это окно поверх схемы, а кнопки внизу — под большой
     палец, а не под адресную строку браузера. */
  .scrim { padding: 6vh 0 0; padding: 6dvh 0 0; align-items: flex-end; }
  .sheet, .sheet--wide, .palette {
    width: 100%; max-height: 94dvh;
    border-radius: var(--r-lg) var(--r-lg) 0 0;
    border-bottom: 0;
  }
  .sheet__foot { position: sticky; bottom: 0; }
  /* Сверка со сканом — настольная задача: на телефоне кнопка только
     выталкивает переключатель видов за край экрана. */
  .brand__meta, .hint, #export, #gedcom, #theme, #filter-unclear, .btn kbd { display: none; }
  .brand { overflow: hidden; }
  .brand__name { font-size: 16px; letter-spacing: .02em; }
  .head { gap: 6px; padding: 0 10px; }
  .head .btn { padding: 0 9px; }
  .btn__long { display: none; }
  .btn__short { display: inline; }
  .zoombar { left: 10px; bottom: 10px; }
}

@media print {
  .head, .head__zeg, .zoombar, .hint, .panel, .scrim { display: none !important; }
  .stage { position: static; inset: auto; height: 100vh; }
}

/* --------------------------------------------------- семантический зум
   Издалека схема должна читаться как структура рода, а не как стена
   мелкого текста: годы и вторые имена появляются при приближении. */
.stage[data-zoom="far"] .node__years,
.stage[data-zoom="far"] .node__alt,
.stage[data-zoom="far"] .node__flag { display: none; }
.stage[data-zoom="far"] .node__name { font-size: 15px; }
.stage[data-zoom="mid"] .node__alt { opacity: .8; }

.node.is-match .node__box { stroke: var(--ochre); stroke-width: 1.75; }

/* ------------------------------------------------------------ подсказка */
.flash {
  position: fixed; left: 50%; bottom: 22px; transform: translateX(-50%);
  z-index: 35; max-width: min(460px, 92vw);
  padding: 9px 15px; font-size: 13px;
  background: var(--indigo); color: var(--paper-raised);
  border-radius: 999px; box-shadow: var(--shadow);
}
.flash[hidden] { display: none; }

.feed__pair.is-gone { color: var(--ink-soft); }

.col__label {
  font-size: 10px; letter-spacing: .16em; text-transform: uppercase;
  fill: var(--muted); font-family: var(--sans);
}
.stage[data-zoom="far"] .col__label { font-size: 22px; letter-spacing: .1em; }

.node__flag {
  font-family: var(--sans); font-size: 9px; font-weight: 600;
  fill: var(--ochre); text-anchor: end; opacity: .85;
}

.btn[hidden] { display: none; }

.panel__rel {
  display: flex; align-items: baseline; gap: 8px; width: 100%;
  margin-top: 8px; padding: 6px 10px;
  background: color-mix(in srgb, var(--ochre) 13%, transparent);
  border: 0; border-radius: var(--r-md);
  font-family: var(--serif); font-size: 13.5px; color: var(--ink); text-align: left;
}
.panel__rel span { margin-left: auto; font-family: var(--sans); font-size: 11px; color: var(--muted); }
.panel__rel:hover span { color: var(--ochre); }

.feed__marriage {
  display: flex; align-items: center; gap: 8px;
  margin: 6px 0 2px;
  font-size: 9.5px; letter-spacing: .08em; text-transform: uppercase;
  color: var(--ochre);
}
.feed__marriage::before, .feed__marriage::after {
  content: ""; flex: 1; height: 1px; background: var(--rule);
}
.feed__echo { margin-left: 8px; color: var(--ochre); font-family: var(--sans); }

/* ------------------------------------------------------ конструктор ветки */
.sheet--wide { width: min(680px, 94vw); }
.branch__node {
  border-left: 2px solid var(--ochre-soft);
  padding-left: 10px; margin: 8px 0;
}
.branch__kids { margin-left: 16px; }
.branch__row { display: flex; gap: 6px; margin: 5px 0; align-items: center; }
.branch__row input, .branch__row select {
  min-width: 0; padding: 7px 9px; font: inherit; font-size: 13.5px;
  color: var(--ink); background: var(--paper);
  border: 1px solid var(--rule); border-radius: var(--r-md);
}
.branch__row input:focus, .branch__row select:focus {
  outline: none; border-color: var(--ochre);
}
.branch__person { margin: 6px 0 10px; }
.branch__person--spouse {
  margin-left: 14px; padding-left: 10px;
  border-left: 2px dotted var(--ochre-soft);
}
.branch__tie {
  font-size: 11px; letter-spacing: .06em; text-transform: uppercase;
  color: var(--ochre); margin: 2px 0 3px;
}
.branch__acts { display: flex; gap: 12px; margin-top: 3px; }
.branch__act {
  border: 0; background: none; padding: 2px 0;
  font-size: 12.5px; color: var(--indigo); cursor: pointer;
  border-bottom: 1px dashed var(--indigo-soft);
}
.branch__act:hover { color: var(--ochre); border-color: var(--ochre); }
.branch__act--del { color: var(--muted); }
.branch__preview .diff { max-height: 180px; overflow-y: auto; }

@media (max-width: 720px) {
  .branch__row { flex-wrap: wrap; }
  .branch__row input[data-f="given"], .branch__row input[data-f="s-given"] {
    flex: 1 1 100%;
  }
}

/* ------------------------------------------------------- фото и истории */
.panel__portrait {
  float: right; width: 72px; height: 72px; object-fit: cover;
  border-radius: var(--r-md); border: 1px solid var(--rule);
  margin: 0 0 8px 12px; cursor: zoom-in;
}
.gallery { display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; }
.gallery__cell {
  padding: 0; border: 1px solid var(--rule); border-radius: var(--r-sm);
  overflow: hidden; background: none; cursor: zoom-in; aspect-ratio: 1;
}
.gallery__cell img { width: 100%; height: 100%; object-fit: cover; display: block; }

.story { margin-bottom: 14px; }
.story__title { font-family: var(--serif); font-size: 15px; margin-bottom: 4px; }
.story__text {
  font-family: var(--serif); font-size: 13.5px; line-height: 1.65;
  color: var(--ink-soft); white-space: pre-wrap;
  border-left: 2px solid var(--indigo-soft); padding-left: 12px;
}
.story__by { font-size: 12px; color: var(--muted); margin-top: 5px; text-align: right; }

.photo__pick span {
  display: block; padding: 22px; text-align: center;
  border: 2px dashed var(--rule); border-radius: var(--r-md);
  color: var(--indigo); cursor: pointer; font-size: 14px;
}
.photo__pick span:hover { border-color: var(--ochre); color: var(--ochre); }
.photo__preview { margin-top: 12px; text-align: center; }
.photo__preview img {
  max-width: 100%; max-height: 260px;
  border-radius: var(--r-md); border: 1px solid var(--rule);
}

.lightbox {
  position: fixed; inset: 0; z-index: 60; cursor: zoom-out;
  background: rgba(20, 17, 14, .88);
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  padding: 24px; gap: 12px;
}
.lightbox img {
  max-width: 100%; max-height: 85vh; max-height: 80dvh;
  border-radius: var(--r-sm); box-shadow: var(--shadow);
}
.lightbox__caption { color: #EDE6DA; font-size: 13.5px; text-align: center; }

/* Метка «есть фотографии» — тонкая рамка со снимком, охрой. */
.node__cam rect, .node__cam path {
  fill: none; stroke: var(--ochre); stroke-width: 1;
  stroke-linecap: round; stroke-linejoin: round; opacity: .8;
}
.stage[data-zoom="far"] .node__cam { display: none; }
.feed__cam {
  width: 11px; height: 10px; margin-left: 6px; vertical-align: baseline;
}
.feed__cam rect, .feed__cam path {
  fill: none; stroke: var(--ochre); stroke-width: 1;
  stroke-linecap: round; stroke-linejoin: round; opacity: .8;
}

/* Отметка людей на фото. */
.who__hints { display: flex; flex-direction: column; gap: 2px; margin-top: 4px; }
.who__hint {
  text-align: left; padding: 7px 10px; font-size: 13.5px;
  border: 0; background: var(--paper-sunk); border-radius: var(--r-md);
  cursor: pointer; font-family: var(--serif);
}
.who__hint:hover { background: color-mix(in srgb, var(--ochre) 15%, var(--paper-sunk)); }
.who__chips { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; }
.who__chip {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 4px 10px; font-size: 13px; font-family: var(--serif);
  background: color-mix(in srgb, var(--ochre) 12%, transparent);
  border: 1px solid var(--ochre-soft); border-radius: 999px; cursor: pointer;
}
.who__chip span { color: var(--muted); }
.who__chip:hover span { color: var(--ochre); }
