/* Components — «Световой стол семьи». Tokens live in tokens.css. */

/* ---------- base ---------- */
*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; scroll-padding-top: calc(var(--masthead-h) + 16px); }
body {
  margin: 0;
  min-height: 100vh;
  background: var(--mount);
  color: var(--text);
  font: 400 var(--fs-ui)/1.5 var(--font-sans);
  overflow-x: hidden;
  font-kerning: normal;
  text-rendering: optimizeLegibility;
}
body.has-dialog { overflow: hidden; }
img { max-width: 100%; display: block; }
a { color: var(--ink); text-underline-offset: .18em; text-decoration-thickness: 1px; }
a:hover { text-decoration-thickness: 2px; }
h1, h2, h3, h4 { margin: 0; font-weight: 500; }
p { margin: 0; }
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
[hidden] { display: none !important; }
:focus-visible { outline: 3px solid var(--ink); outline-offset: 2px; border-radius: 2px; }
.visually-hidden { position: absolute !important; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); clip-path: inset(50%); white-space: nowrap; }
.skip-link { position: fixed; left: 12px; top: -60px; z-index: 100; background: var(--paper); color: var(--ink); padding: 12px 16px; border-radius: var(--r-control); box-shadow: var(--shadow-lift); }
.skip-link:focus { top: 12px; }
.unknown { color: var(--text-faint); font-style: italic; }
.uncertain { color: var(--ochre); font-size: var(--fs-small); }
.empty-note { color: var(--text-soft); padding: var(--s5); background: var(--mount-light); border: 1px dashed var(--rule-strong); border-radius: var(--r-panel); }

/* ---------- buttons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: var(--s2);
  min-height: 44px; padding: 0 18px;
  border: 1px solid transparent; border-radius: var(--r-control);
  font: 600 var(--fs-ui)/1.2 var(--font-sans);
  text-decoration: none; white-space: nowrap;
  transition: background var(--t-fast), border-color var(--t-fast), color var(--t-fast), transform var(--t-fast);
}
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: .55; cursor: progress; }
.btn-lg { min-height: 50px; padding: 0 24px; font-size: 1rem; }
.btn-ink { background: var(--ink); color: var(--paper); }
.btn-ink:hover { background: color-mix(in srgb, var(--ink) 86%, black); text-decoration: none; }
.btn-quiet { background: transparent; color: var(--graphite); border-color: var(--rule-strong); }
.btn-quiet:hover { border-color: var(--graphite); background: var(--paper); text-decoration: none; }
.btn-link { background: none; color: var(--ink); text-decoration: underline; padding: 0 6px; }
.btn-paper { background: transparent; color: var(--on-dark); border-color: color-mix(in srgb, var(--on-dark) 45%, transparent); }
.btn-paper:hover { border-color: var(--on-dark); }
.btn-paper:focus-visible { outline-color: var(--on-dark); }
.btn-danger { background: transparent; color: var(--graphite); border: 1px dashed var(--ochre); }
.icon-btn { width: 44px; height: 44px; display: inline-grid; place-items: center; border: 0; background: transparent; font-size: 26px; line-height: 1; border-radius: var(--r-control); color: inherit; }
.icon-btn:hover { background: color-mix(in srgb, var(--graphite) 8%, transparent); }

/* ---------- stamps ---------- */
.stamp {
  display: inline-block;
  padding: 3px 9px 2px;
  border: 1.5px solid var(--stamp);
  border-radius: var(--r-print);
  color: var(--stamp);
  font: 600 var(--fs-stamp)/1.35 var(--font-sans);
  letter-spacing: .03em;
  transform: rotate(-1.2deg);
  background: color-mix(in srgb, var(--paper) 70%, transparent);
}
.stamp-memory { border-style: dotted; border-width: 2px; }
.stamp-hypothesis, .stamp-research { color: var(--ochre); border-color: var(--ochre); border-style: dashed; }
.stamp-confirmed { color: var(--ink); border-color: var(--ink); }
.date-stamp { color: var(--stamp); font-weight: 600; font-variant-numeric: tabular-nums lining-nums; letter-spacing: .01em; }
.date-stamp.is-exact { border-bottom: 1.5px solid color-mix(in srgb, var(--stamp) 35%, transparent); }

/* ---------- masthead ---------- */
.masthead {
  position: sticky; top: 0; z-index: 30;
  height: var(--masthead-h);
  display: flex; align-items: center; gap: var(--s5);
  padding: 0 clamp(16px, 3vw, 40px);
  background: var(--graphite);
  color: var(--on-dark);
}
.brand { display: flex; align-items: center; gap: var(--s3); color: var(--on-dark); text-decoration: none; min-height: 44px; }
.brand-mark { width: 34px; height: 34px; fill: none; stroke: var(--on-dark); stroke-width: 1.6; }
.brand-mark circle { fill: var(--graphite); }
.brand-text { display: grid; line-height: 1.05; }
.brand-text span { font-size: var(--fs-small); color: var(--on-dark-soft); }
.brand-text strong { font: 600 1.25rem/1.1 var(--font-serif); font-optical-sizing: auto; }
.primary-nav { display: flex; gap: 2px; margin-left: var(--s4); }
.primary-nav a {
  display: inline-flex; align-items: center; min-height: 44px; padding: 0 14px;
  color: var(--on-dark-soft); text-decoration: none; font-weight: 500; position: relative;
}
.primary-nav a:hover { color: var(--on-dark); }
.primary-nav a.is-active { color: var(--on-dark); }
.primary-nav a.is-active::after { content: ""; position: absolute; left: 14px; right: 14px; bottom: 6px; height: 2px; background: var(--on-dark); }
.primary-nav a:focus-visible, .brand:focus-visible, .viewer-chip:focus-visible { outline-color: var(--on-dark); }
.masthead-tools { margin-left: auto; display: flex; align-items: center; gap: var(--s3); }
.search { position: relative; display: flex; align-items: center; }
.search svg { position: absolute; left: 12px; width: 18px; height: 18px; fill: none; stroke: var(--on-dark-soft); stroke-width: 1.8; pointer-events: none; }
.search input {
  width: clamp(180px, 20vw, 280px); height: 42px; padding: 0 12px 0 38px;
  border: 1px solid color-mix(in srgb, var(--on-dark) 26%, transparent); border-radius: var(--r-control);
  background: color-mix(in srgb, var(--on-dark) 8%, transparent); color: var(--on-dark);
}
.search input::placeholder { color: var(--on-dark-soft); }
.search input:focus-visible { outline-color: var(--on-dark); }
.viewer-chip {
  display: inline-flex; align-items: center; gap: 8px; min-height: 42px; padding: 0 14px;
  border: 1px solid color-mix(in srgb, var(--on-dark) 26%, transparent); border-radius: var(--r-control);
  background: transparent; color: var(--on-dark); font-weight: 500; max-width: 200px;
}
.viewer-chip span:last-child { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.viewer-chip-dot { width: 9px; height: 9px; border: 2px solid var(--on-dark); border-radius: 50%; flex: none; }

/* suggestions listbox */
.suggest {
  position: absolute; top: calc(100% + 6px); left: 0; right: 0; z-index: 40;
  margin: 0; padding: 6px; list-style: none; min-width: 300px;
  background: var(--paper); color: var(--graphite);
  border-radius: var(--r-panel); box-shadow: var(--shadow-lift); max-height: 360px; overflow: auto;
}
.search .suggest { left: auto; right: 0; width: 360px; }
.suggest li { display: grid; gap: 1px; padding: 9px 12px; border-radius: var(--r-control); cursor: pointer; min-height: 44px; }
.suggest li:hover, .suggest li[aria-selected="true"] { background: var(--ink-soft); }
.sg-name { font-weight: 600; }
.sg-meta { font-size: var(--fs-small); color: var(--text-soft); }

/* ---------- views ---------- */
main { display: block; outline: none; }
.view { max-width: var(--page-max); margin: 0 auto; padding: clamp(20px, 3vw, 40px) clamp(16px, 3vw, 40px) 120px; }
.view-head { display: flex; flex-wrap: wrap; align-items: flex-end; justify-content: space-between; gap: var(--s4) var(--s6); margin-bottom: var(--s5); }
.view-head h1 { font: 500 var(--fs-title)/var(--lh-tight) var(--font-serif); font-optical-sizing: auto; letter-spacing: -.01em; }
.view-sub { margin-top: 6px; color: var(--text-soft); max-width: 68ch; }
.view-actions { display: flex; flex-wrap: wrap; gap: var(--s3); }

/* segmented control */
.segmented { display: inline-flex; flex-wrap: wrap; gap: 0; border: 1px solid var(--rule-strong); border-radius: var(--r-control); padding: 3px; margin: 0; min-width: 0; background: var(--paper); }
.segmented label, .segmented > button { position: relative; }
.segmented input { position: absolute; opacity: 0; inset: 0; margin: 0; cursor: pointer; }
.segmented span, .segmented > button {
  display: inline-flex; align-items: center; min-height: 38px; padding: 0 14px; border-radius: 4px; border: 0; background: none;
  font-weight: 500; color: var(--text-soft);
}
.segmented input:checked + span, .segmented > button[aria-selected="true"] { background: var(--graphite); color: var(--paper); }
.segmented input:focus-visible + span { outline: 3px solid var(--ink); outline-offset: 1px; }

/* ---------- photo / print ---------- */
.photo { display: block; position: relative; overflow: hidden; background: var(--mount-deep); flex: none; }
.photo img { width: 100%; height: 100%; object-fit: cover; object-position: 50% 22%; }
.photo.is-unknown {
  display: grid; place-items: center; align-content: center; gap: 4px;
  background:
    repeating-linear-gradient(135deg, transparent 0 9px, color-mix(in srgb, var(--graphite) 5%, transparent) 9px 10px),
    var(--mount-deep);
  color: color-mix(in srgb, var(--graphite) 55%, var(--mount));
}
.photo-initials { font: 500 1.05rem/1 var(--font-serif); letter-spacing: .04em; }
.photo-unknown-note { display: none; font-size: var(--fs-small); }
.photo-xs { width: 44px; height: 52px; }
.photo-sm { width: 58px; height: 70px; }
.photo-lg { width: 100%; aspect-ratio: 4 / 5; }
.photo-lg .photo-initials { font-size: 3.4rem; font-weight: 400; }
.photo-lg .photo-unknown-note { display: block; }

.print {
  position: relative; z-index: 1;
  display: grid; grid-template-columns: auto 1fr; align-items: center; gap: 12px;
  width: 100%; min-height: 86px; padding: 7px 14px 7px 7px;
  background: var(--paper); border: 0; border-radius: var(--r-print);
  box-shadow: var(--shadow-print); text-align: left; color: var(--graphite);
  transition: transform var(--t-fast) var(--ease), box-shadow var(--t-fast);
}
button.print:hover { transform: translateY(-2px); box-shadow: var(--shadow-lift); }
.print-text { display: grid; gap: 2px; min-width: 0; }
.print-label { justify-self: start; font: 600 var(--fs-stamp)/1.3 var(--font-sans); color: var(--stamp); letter-spacing: .02em; }
.print-name { font: 500 1rem/1.22 var(--font-serif); overflow-wrap: anywhere; }
.print-name .nm-given, .print-name .nm-surname { display: block; }
.print-name .nm-surname { font-size: .875rem; color: var(--text-soft); font-style: italic; }
.nm-maiden { font-style: italic; }
.print-years { font-size: var(--fs-small); color: var(--text-soft); font-variant-numeric: tabular-nums; }
.print-md { min-height: 96px; }
.print-md .photo-sm { width: 66px; height: 80px; }
.print-xs { min-height: 66px; gap: 10px; padding: 6px 10px 6px 6px; }
.print-xs .print-name .nm-surname { display: inline; }
.print-xs .print-name { font-size: .95rem; }
.print.is-missing { box-shadow: none; background: transparent; border: 1.5px dashed var(--rule-strong); color: var(--text-faint); }
.print.is-missing .print-label { color: var(--text-faint); }

/* ---------- 1. light table ---------- */
.view-card { padding-top: clamp(24px, 4vw, 56px); }
.desk {
  position: relative;
  display: grid;
  grid-template-columns: minmax(170px, 1fr) minmax(0, 3.6fr) minmax(170px, 1fr);
  grid-template-areas:
    ".        parents  ."
    "siblings focus    spouses"
    ".        children .";
  column-gap: clamp(40px, 5vw, 80px);
  row-gap: 64px;
  align-items: start;
}
.desk-lines { position: absolute; inset: 0; width: 100%; height: 100%; pointer-events: none; z-index: 0; overflow: visible; }
.desk-lines .dl { fill: none; stroke: var(--ink); stroke-width: 1.6; stroke-linecap: round; stroke-linejoin: round; }
.desk-lines .dl.is-dashed { stroke-dasharray: 6 5; }
.desk-lines .dl-marriage { stroke-width: 1.2; }
.desk-lines .dl-dot { fill: var(--ink); }
.slot { position: relative; z-index: 1; min-width: 0; }
.desk:not(.has-siblings):not(.has-spouses) { grid-template-columns: minmax(0, .6fr) minmax(0, 3.6fr) minmax(0, .6fr); }
.slot-parents { grid-area: parents; }
.slot-siblings { grid-area: siblings; padding-top: 24px; }
.slot-spouses { grid-area: spouses; padding-top: 24px; }
.slot-children { grid-area: children; }
.parents-pair { display: grid; grid-template-columns: repeat(2, minmax(0, 260px)); justify-content: center; gap: clamp(24px, 4vw, 64px); }
.slot-title { font: 600 var(--fs-small)/1.3 var(--font-sans); color: var(--text-soft); margin: 0 0 10px; }
.slot-prints { display: grid; gap: 14px; }
.slot-children .slot-title { text-align: center; position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); }
.slot-note { margin-top: 8px; font-size: var(--fs-small); color: var(--text-soft); font-style: italic; }
.slot-children .slot-prints { grid-template-columns: repeat(auto-fit, minmax(190px, 240px)); justify-content: center; gap: 16px 22px; padding-top: 0; }
.slot-more { margin-top: 10px; min-height: 44px; border: 1px dashed var(--rule-strong); background: transparent; border-radius: var(--r-control); width: 100%; color: var(--ink); font-weight: 600; }
.slot-children .slot-more { width: auto; display: block; margin: 12px auto 0; padding: 0 18px; }
.slot-empty { text-align: center; color: var(--text-faint); font-style: italic; padding: 10px; border: 1.5px dashed var(--rule-strong); border-radius: var(--r-print); max-width: 420px; margin: 0 auto; }

.focus {
  grid-area: focus; position: relative; z-index: 2;
  display: grid; grid-template-columns: minmax(180px, 260px) minmax(0, 1fr); gap: clamp(24px, 3vw, 44px);
  padding: clamp(20px, 2.4vw, 32px);
  background: var(--paper);
  border-radius: var(--r-print);
  box-shadow: var(--shadow-lift);
}
.focus-side { display: grid; gap: 28px; align-content: start; }
.focus-print { margin: -44px 0 0 -8px; transform: rotate(-1.4deg); align-self: start; }
.focus-print .photo { border: var(--border-print); border-bottom-width: 52px; box-shadow: var(--shadow-lift); }
.focus-print figcaption { margin-top: -48px; position: relative; padding: 0 12px; min-height: 44px; font: italic 400 .8125rem/1.3 var(--font-serif); color: var(--text-soft); }
.focus-back { display: grid; align-content: start; gap: 16px; min-width: 0; }
.focus-evidence { display: flex; flex-wrap: wrap; align-items: center; gap: 6px 12px; font-size: var(--fs-small); color: var(--text-soft); }
.focus-name { font: 500 clamp(2.1rem, 1.3rem + 2vw, 3.25rem)/1.04 var(--font-serif); font-optical-sizing: auto; letter-spacing: -.02em; overflow-wrap: break-word; hyphens: manual; }
.focus-name.is-long { font-size: clamp(1.8rem, 1.1rem + 1.6vw, 2.6rem); }
.focus-name .nm-given { display: block; }
.focus-name .nm-surname { display: block; margin-top: 6px; font-size: .5em; font-style: italic; font-weight: 400; color: var(--text-soft); letter-spacing: 0; }
.focus-dates { display: flex; flex-wrap: wrap; gap: 8px 28px; margin: 0; padding: 12px 0; border-top: 1px solid var(--rule); border-bottom: 1px solid var(--rule); }
.focus-dates div, .focus-meta div { display: grid; gap: 2px; }
.focus-dates dt, .focus-meta dt { font-size: var(--fs-small); color: var(--text-soft); }
.focus-dates dd { margin: 0; font-size: 1.125rem; }
.focus-dates dd small { display: block; font-size: var(--fs-small); color: var(--text-faint); }
.focus-span dd { color: var(--graphite); }
.focus-meta { display: grid; grid-template-columns: 1fr 1fr; gap: 14px 24px; margin: 0; }
.focus-meta dd { margin: 0; overflow-wrap: anywhere; }
.focus-bio { font: 400 var(--fs-lead)/var(--lh-text) var(--font-serif); max-width: 62ch; }
.focus-fact { padding: 12px 16px; background: var(--stamp-soft); border-left: 3px solid var(--stamp); }
.focus-fact h2 { font: 600 var(--fs-small)/1.3 var(--font-sans); color: var(--stamp); margin-bottom: 4px; }
.focus-fact p { font-family: var(--font-serif); }
.focus-counts { list-style: none; margin: 0; padding: 0; display: grid; border-top: 1px solid var(--rule); }
.focus-counts li { border-bottom: 1px solid var(--rule); }
.focus-counts li > a, .focus-counts li:not(:has(a)) { display: grid; grid-template-columns: 44px 1fr; align-items: baseline; gap: 8px; padding: 8px 2px; min-height: 44px; color: var(--graphite); text-decoration: none; }
.focus-counts b { font: 500 1.375rem/1.1 var(--font-serif); text-align: right; font-variant-numeric: tabular-nums; }
.focus-counts span { font-size: var(--fs-small); color: var(--text-soft); }
.focus-counts li.is-empty b { color: var(--text-faint); }
.focus-counts a:hover b { color: var(--ink); }
.focus-actions { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; }

.line-legend, .tree-legend { list-style: none; display: flex; flex-wrap: wrap; gap: 8px 22px; padding: 0; margin: 40px 0 0; font-size: var(--fs-small); color: var(--text-soft); justify-content: center; }
.line-legend li, .tree-legend li { display: inline-flex; align-items: center; gap: 8px; }
.line-legend svg, .tree-legend svg { width: 40px; height: 8px; fill: none; stroke: var(--ink); stroke-width: 1.6; }
.line-legend .is-dashed, .tree-legend .is-dashed { stroke-dasharray: 6 5; }
.near { display: none; }

/* dealing motion when the table recomposes */
.desk.is-dealing .print { animation: deal var(--t-deal) var(--ease) both; animation-delay: calc(var(--i, 0) * 40ms + 80ms); }
.desk.is-dealing .focus { animation: settle 320ms var(--ease) both; }
.desk.is-dealing .desk-lines { animation: fade 300ms ease 380ms both; }
@keyframes deal { from { opacity: 0; transform: translateY(10px) scale(.97); } }
@keyframes settle { from { opacity: .2; transform: scale(.985); } }
@keyframes fade { from { opacity: 0; } }

/* ---------- 2. tree ---------- */
.view-tree { max-width: none; padding-bottom: 24px; }
.tree-bar { display: flex; flex-wrap: wrap; justify-content: space-between; align-items: center; gap: 12px; margin-bottom: 12px; }
.tree-zoom { display: flex; align-items: center; gap: 6px; }
.tree-zoom button { min-width: 44px; min-height: 44px; padding: 0 12px; border: 1px solid var(--rule-strong); background: var(--paper); border-radius: var(--r-control); font-weight: 600; }
.tree-zoom button:hover { border-color: var(--graphite); }
.tree-zoom output { min-width: 52px; text-align: center; font-variant-numeric: tabular-nums; color: var(--text-soft); }
.tree-search { display: flex; gap: 6px; }
.tree-search input { height: 44px; width: min(300px, 60vw); padding: 0 12px; border: 1px solid var(--rule-strong); border-radius: var(--r-control); background: var(--paper); }
.tree-search button { min-height: 44px; padding: 0 16px; border: 0; border-radius: var(--r-control); background: var(--graphite); color: var(--paper); font-weight: 600; }
.tree-frame { position: relative; border-radius: var(--r-panel); overflow: hidden; border: 1px solid var(--rule); background: var(--mount-light); }
.tree-viewport { position: relative; height: calc(100vh - var(--masthead-h) - 210px); min-height: 480px; overflow: hidden; cursor: grab; touch-action: none; user-select: none; }
.tree-viewport.is-dragging { cursor: grabbing; }
.tree-viewport:focus-visible { outline-offset: -3px; }
.tree-world { position: absolute; left: 0; top: 0; transform-origin: 0 0; will-change: transform; }
.tree-edges { position: absolute; inset: 0; overflow: visible; }
.tree-edges .e { fill: none; stroke: color-mix(in srgb, var(--graphite) 58%, var(--mount-light)); stroke-width: 1.4; vector-effect: non-scaling-stroke; }
.tree-edges .e.is-dashed { stroke-dasharray: 6 4; }
.tree-edges .e-marriage { stroke-width: 1.1; }
.tree-edges .e-marriage.is-far { stroke-dasharray: 2 4; }
.tree-edges .e-other { stroke-dasharray: 1 4; stroke-linecap: round; }
.tree-edges .e.is-focus { stroke: var(--ink); stroke-width: 2.6; }
.tree-nodes { position: absolute; inset: 0; }
.tnode {
  position: absolute; width: 188px; height: 84px;
  display: grid; grid-template-columns: 48px 1fr; gap: 10px; align-items: center;
  padding: 6px 10px 6px 6px; text-align: left;
  background: var(--paper); border: 1px solid var(--rule-strong); border-radius: var(--r-print);
  box-shadow: 0 1px 0 rgb(0 0 0 / .05); color: var(--graphite);
}
.tnode:hover { border-color: var(--ink); }
.tnode.is-hypothesis { border: 1.5px dashed var(--ochre); }
.tnode.is-direct { border: 1.5px solid var(--ink); }
.tnode.is-center { border: 3px solid var(--ink); box-shadow: 0 0 0 6px color-mix(in srgb, var(--ink) 16%, transparent), var(--shadow-lift); z-index: 2; }
.tnode.is-center::after { content: "в центре"; position: absolute; top: -12px; left: 10px; padding: 1px 7px; background: var(--paper); border: 1.5px solid var(--stamp); color: var(--stamp); font: 600 11px/1.3 var(--font-sans); transform: rotate(-2deg); }
.tnode-photo { width: 48px; height: 60px; display: grid; place-items: center; background: var(--mount-deep); font: 500 .95rem var(--font-serif); color: var(--text-soft); overflow: hidden; }
.tnode-photo img { width: 100%; height: 100%; object-fit: cover; }
.tnode-text { display: grid; min-width: 0; line-height: 1.2; }
.tnode-given { font: 500 .95rem/1.18 var(--font-serif); overflow: hidden; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; }
.tnode-surname { font: italic .8rem/1.2 var(--font-serif); color: var(--text-soft); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.tnode-years { font-size: .75rem; color: var(--text-soft); font-variant-numeric: tabular-nums; }
.lod-mid .tnode { grid-template-columns: 1fr; padding: 8px 12px; }
.lod-mid .tnode-photo, .lod-mid .tnode-years { display: none; }
.lod-mid .tnode-given { font-size: 1.35rem; -webkit-line-clamp: 2; }
.lod-mid .tnode-surname { font-size: 1.05rem; }
.lod-far .tnode { background: color-mix(in srgb, var(--graphite) 34%, var(--mount-light)); border-color: transparent; }
.lod-far .tnode.is-hypothesis { background: color-mix(in srgb, var(--ochre) 40%, var(--mount-light)); }
.lod-far .tnode.is-direct { background: color-mix(in srgb, var(--ink) 55%, var(--mount-light)); }
.lod-far .tnode.is-center { background: var(--ink); }
.lod-far .tnode.is-center::after { font-size: 64px; top: -96px; padding: 4px 18px; border-width: 5px; }
.lod-far .tnode-text { visibility: hidden; }
.lod-far .tnode-photo { visibility: hidden; }
.tree-divider { position: absolute; left: 80px; right: 80px; margin: 0; padding-top: 12px; border-top: 1.5px dashed var(--rule-strong); font: italic 1.25rem var(--font-serif); color: var(--text-soft); }
.tree-minimap { position: absolute; right: 14px; top: 14px; width: 220px; height: 140px; border: 1px solid var(--rule-strong); border-radius: var(--r-control); background: var(--paper); box-shadow: var(--shadow-print); cursor: crosshair; touch-action: none; }
.tree-legend { position: absolute; left: 14px; bottom: 14px; margin: 0; justify-content: flex-start; max-width: calc(100% - 270px); padding: 8px 12px; background: color-mix(in srgb, var(--paper) 92%, transparent); border-radius: var(--r-control); border: 1px solid var(--rule); }
.legend-print { width: 22px; height: 14px; border: 1px solid var(--rule-strong); background: var(--paper); }
.legend-print.is-focus { border: 2.5px solid var(--ink); }
.legend-print.is-hypothesis { border: 1.5px dashed var(--ochre); }

/* ---------- 3. lineage ---------- */
.pedigree { list-style: none; margin: 0; padding: 0; display: grid; gap: 28px; }
.pedigree-gen h2 { font: 600 var(--fs-small)/1.3 var(--font-sans); color: var(--text-soft); margin-bottom: 10px; padding-bottom: 6px; border-bottom: 1px solid var(--rule); }
.pedigree-row { display: grid; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); gap: 14px; }
.pedigree-cell { display: grid; gap: 6px; }
.pedigree-cell small { font-size: var(--fs-small); color: var(--text-faint); padding-left: 4px; }
.pedigree-cell.is-missing { align-content: start; }
.pedigree-cell.is-missing > span { display: grid; place-items: center; min-height: 66px; border: 1.5px dashed var(--rule-strong); border-radius: var(--r-print); color: var(--text-faint); font-style: italic; }

/* ---------- 4. map ---------- */
.map-filters { display: flex; flex-wrap: wrap; align-items: flex-end; gap: 12px 16px; margin-bottom: 16px; padding: 14px 16px; background: var(--paper); border-radius: var(--r-panel); border: 1px solid var(--rule); }
.map-filters label, .archive-filters label { display: grid; gap: 4px; font-size: var(--fs-small); color: var(--text-soft); }
.map-filters select, .map-filters input[type="number"], .archive-filters select { min-height: 44px; padding: 0 10px; border: 1px solid var(--rule-strong); border-radius: var(--r-control); background: var(--paper); color: var(--graphite); font-size: var(--fs-ui); max-width: 260px; }
.map-filters input[type="number"] { width: 100px; }
.map-status { border: 0; padding: 0; margin: 0; display: flex; flex-wrap: wrap; gap: 4px 14px; align-items: center; }
.map-status legend { font-size: var(--fs-small); color: var(--text-soft); padding: 0; margin-bottom: 4px; float: left; width: 100%; }
.map-status label { display: inline-flex; align-items: center; gap: 6px; min-height: 44px; color: var(--graphite); font-size: var(--fs-ui); }
.map-status input { width: 18px; height: 18px; accent-color: var(--ink); }
.map-filters button[type="reset"], .archive-filters button[type="reset"] { min-height: 44px; padding: 0 14px; border: 1px solid var(--rule-strong); background: transparent; border-radius: var(--r-control); margin-left: auto; }
.map-layout { display: grid; grid-template-columns: minmax(0, 1fr) 380px; gap: 18px; }
.map-canvas { height: min(620px, 70vh); min-height: 420px; border-radius: var(--r-panel); overflow: hidden; border: 1px solid var(--rule); background: var(--mount-deep); }
.map-panel { display: grid; align-content: start; gap: 10px; padding: 22px; background: var(--paper); border-radius: var(--r-panel); box-shadow: var(--shadow-print); max-height: min(620px, 70vh); overflow: auto; }
.map-panel h2 { font: 500 var(--fs-name)/1.1 var(--font-serif); }
.map-panel h3 { font: 600 var(--fs-small)/1.3 var(--font-sans); color: var(--text-soft); margin-top: 8px; }
.map-panel .stamp { justify-self: start; }
.map-panel-sub { color: var(--text-soft); }
.map-panel-note { font-family: var(--font-serif); }
.map-uncertain { padding: 8px 12px; border-left: 3px dashed var(--ochre); background: var(--ochre-soft); font-size: var(--fs-small); }
.map-people { list-style: none; margin: 0; padding: 0; display: grid; gap: 2px; }
.map-people li { display: flex; align-items: center; gap: 8px; border-bottom: 1px solid var(--rule); }
.map-people a:first-child { flex: 1; display: grid; padding: 8px 0; min-height: 44px; color: var(--graphite); text-decoration: none; }
.map-people a:first-child:hover strong { color: var(--ink); text-decoration: underline; }
.map-people span { font-size: var(--fs-small); color: var(--text-soft); }
.map-tree-link { font-size: var(--fs-small); min-height: 44px; display: inline-flex; align-items: center; }
.map-list { margin-top: 28px; }
.map-list h2 { font: 500 1.375rem/1.2 var(--font-serif); margin-bottom: 12px; }
.map-list ol { list-style: none; padding: 0; margin: 0; display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: 10px; }
.map-list ol button { width: 100%; display: grid; gap: 2px; text-align: left; padding: 12px 14px; min-height: 44px; background: var(--paper); border: 1px solid var(--rule); border-radius: var(--r-control); }
.map-list ol button[aria-pressed="true"] { border: 2px solid var(--ink); padding: 11px 13px; }
.map-list-name { font: 500 1.05rem var(--font-serif); }
.map-list-sub, .map-list-people { font-size: var(--fs-small); color: var(--text-soft); }
.map-unplaced { margin-top: 18px; }
.map-unplaced summary { min-height: 44px; display: inline-flex; align-items: center; cursor: pointer; color: var(--ink); font-weight: 600; }
.map-unplaced ul { list-style: none; padding: 0; display: flex; flex-wrap: wrap; gap: 8px; }
.map-unplaced li { padding: 4px 10px; border: 1px dashed var(--rule-strong); border-radius: var(--r-print); background: var(--paper); font-size: var(--fs-small); }
.map-unplaced li span { color: var(--text-soft); margin-left: 4px; }
.pin-wrap { background: none; border: 0; }
.pin { position: relative; display: grid; place-items: center; width: 36px; height: 36px; background: var(--paper); border: 2.5px solid var(--ink); border-radius: var(--r-print); color: var(--ink); font: 700 14px var(--font-sans); box-shadow: var(--shadow-print); transform: rotate(-3deg); }
.pin::after { content: ""; position: absolute; left: 50%; bottom: -10px; width: 2px; height: 9px; background: currentColor; transform: translateX(-50%); }
.pin.is-hypothesis { border-style: dashed; border-color: var(--ochre); color: var(--ochre); }
.pin.is-research { border-style: dotted; border-color: var(--stamp); color: var(--stamp); }
.is-selected .pin { background: var(--ink); color: var(--paper); border-color: var(--ink); }
.is-selected .pin.is-hypothesis { background: var(--ochre); color: var(--paper); }
.pin-cluster { width: 60px; height: 60px; border-radius: 50%; transform: none; gap: 0; align-content: center; line-height: 1.05; }
.pin-cluster::after { display: none; }
.pin-cluster small { font: 500 10px var(--font-sans); }
.leaflet-container { font-family: var(--font-sans); isolation: isolate; z-index: 0; }
.leaflet-container a { color: var(--ink); }

/* ---------- 5. archive ---------- */
.archive-filters { display: flex; flex-wrap: wrap; align-items: flex-end; gap: 12px 16px; padding: 14px 16px; background: var(--paper); border: 1px solid var(--rule); border-radius: var(--r-panel); }
.archive-count { margin: 16px 0 8px; color: var(--text-soft); }
.archive-albums { display: grid; gap: 44px; }
.album header { display: flex; align-items: baseline; gap: 14px; padding-bottom: 10px; margin-bottom: 18px; border-bottom: 1px solid var(--rule-strong); }
.album h2 { font: 500 1.625rem/1.15 var(--font-serif); }
.album header span { color: var(--text-soft); font-size: var(--fs-small); }
.album-more { margin-top: 16px; }
.contact-sheet { display: grid; grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); gap: 26px 20px; }
.sheet-item { margin: 0; display: grid; gap: 10px; align-content: start; }
.sheet-item button { padding: 0; border: var(--border-print); border-bottom-width: 18px; background: var(--paper); box-shadow: var(--shadow-print); border-radius: var(--r-print); transition: transform var(--t-fast) var(--ease), box-shadow var(--t-fast); }
.sheet-item button:hover { transform: translateY(-3px) rotate(-.6deg); box-shadow: var(--shadow-lift); }
.sheet-item img { width: 100%; aspect-ratio: 1; object-fit: cover; background: var(--mount-deep); }
.sheet-item.is-document img { object-fit: contain; aspect-ratio: 3 / 4; background: var(--paper); }
.sheet-item figcaption { display: grid; gap: 3px; padding: 0 2px; }
.sheet-item figcaption strong { font-size: .875rem; font-weight: 600; line-height: 1.3; }
.sheet-caption { font: italic .875rem/1.4 var(--font-serif); color: var(--text-soft); }
.sheet-people { font-size: var(--fs-small); color: var(--ink); }
.sheet-meta { font-size: var(--fs-small); color: var(--stamp); font-weight: 600; }
.archive-inbox { margin-top: 56px; padding: 24px; border: 1.5px dashed var(--rule-strong); border-radius: var(--r-panel); }
.archive-inbox h2 { font: 500 1.5rem var(--font-serif); }
.archive-inbox > p { color: var(--text-soft); margin: 6px 0 18px; max-width: 70ch; }
.sheet-item.is-inbox img { filter: saturate(.7); }

/* ---------- mobile relatives strip + tabbar ---------- */
.relstrip, .tabbar { display: none; }

/* ---------- Oleg ---------- */
.oleg { position: fixed; right: 24px; bottom: 24px; z-index: 25; display: grid; justify-items: end; gap: 12px; }
.oleg-launch { display: flex; align-items: center; gap: 12px; min-height: 56px; padding: 8px 18px 8px 8px; border: 0; background: var(--graphite); color: var(--on-dark); border-radius: var(--r-panel); box-shadow: var(--shadow-lift); text-align: left; }
.oleg-launch strong { display: block; font-weight: 600; }
.oleg-launch small { display: block; color: var(--on-dark-soft); font-size: var(--fs-small); }
.oleg-launch:focus-visible { outline-color: var(--ink); outline-offset: 3px; }
.oleg-mark { width: 40px; height: 40px; flex: none; display: grid; place-items: center; background: var(--paper); color: var(--ink); font: 600 1.2rem var(--font-serif); border-radius: 50%; }
.oleg-panel { order: -1; width: min(400px, calc(100vw - 32px)); max-height: min(600px, calc(100vh - var(--masthead-h) - 120px)); display: grid; grid-template-rows: auto 1fr auto auto; background: var(--paper); border-radius: var(--r-panel); box-shadow: var(--shadow-dialog); overflow: hidden; }
.oleg-panel header { display: flex; align-items: center; gap: 12px; padding: 12px 8px 12px 16px; border-bottom: 1px solid var(--rule); }
.oleg-panel header .oleg-mark { background: var(--ink); color: var(--paper); }
.oleg-panel h2 { font: 600 1.05rem var(--font-serif); }
.oleg-panel header p { font-size: var(--fs-small); color: var(--text-soft); }
.oleg-panel header .icon-btn { margin-left: auto; }
.oleg-log { overflow: auto; padding: 14px 16px; display: grid; gap: 10px; align-content: start; min-height: 120px; }
.oleg-msg { max-width: 88%; padding: 10px 12px; border-radius: var(--r-control); line-height: 1.45; }
.oleg-msg.is-oleg { background: var(--mount-light); justify-self: start; }
.oleg-msg.is-user { background: var(--ink); color: var(--paper); justify-self: end; }
.oleg-msg a, .oleg-msg button { display: inline-flex; margin-top: 6px; min-height: 36px; align-items: center; font-weight: 600; }
.oleg-starters { display: flex; flex-wrap: wrap; gap: 6px; padding: 10px 16px 0; }
.oleg-starters button { min-height: 36px; padding: 4px 10px; border: 1px solid var(--rule-strong); background: transparent; border-radius: var(--r-control); font-size: var(--fs-small); text-align: left; }
.oleg-starters button:hover { border-color: var(--ink); color: var(--ink); }
.oleg-form { display: flex; gap: 8px; padding: 12px 16px 16px; }
.oleg-form input { flex: 1; min-width: 0; min-height: 44px; padding: 0 12px; border: 1px solid var(--rule-strong); border-radius: var(--r-control); background: var(--paper); }
body.oleg-open .oleg-launch { display: none; }

/* ---------- dialogs ---------- */
dialog { border: 0; padding: 0; color: var(--graphite); background: var(--paper); max-width: none; max-height: none; }
dialog::backdrop { background: rgb(20 24 28 / .62); }

/* gate */
.gate { width: min(980px, 94vw); border-radius: var(--r-panel); box-shadow: var(--shadow-dialog); overflow: visible; }
.gate::backdrop { background: var(--mount); }
.gate-form { display: grid; grid-template-columns: minmax(0, .9fr) minmax(0, 1.1fr); min-height: 520px; }
.gate-print { position: relative; display: grid; align-content: space-between; padding: 28px; background: var(--graphite); color: var(--on-dark); border-radius: var(--r-panel) 0 0 var(--r-panel); overflow: hidden; }
.gate-print .stamp { justify-self: start; color: #C9B9EE; border-color: #C9B9EE; background: transparent; }
.gate-print-caption { font: italic 400 1.5rem/1.35 var(--font-serif); max-width: 18ch; }
.gate-photo { margin: 22px 0; transform: rotate(-2deg); justify-self: center; width: min(78%, 300px); }
.gate-photo img { border: var(--border-print); border-bottom-width: 30px; box-shadow: 0 24px 40px -18px rgb(0 0 0 / .8); width: 100%; height: auto; max-height: 52vh; object-fit: contain; background: var(--paper); }
.gate-photo figcaption { margin-top: -26px; position: relative; padding: 0 10px; color: var(--graphite); font: italic .8125rem/1.3 var(--font-serif); }
.gate-body { padding: clamp(28px, 4vw, 52px); display: grid; align-content: center; gap: 18px; }
.gate-body h1 { font: 500 var(--fs-title)/1.1 var(--font-serif); font-optical-sizing: auto; }
.gate-lead { font: 400 1.0625rem/1.55 var(--font-serif); color: var(--text-soft); }
.gate-field { position: relative; display: grid; gap: 6px; }
.gate-field label { font-weight: 600; }
.gate-field input { min-height: 56px; padding: 0 16px; border: 1.5px solid var(--graphite); border-radius: var(--r-control); font: 500 1.125rem var(--font-serif); background: var(--paper); }
.gate-field input:focus-visible { outline-offset: 1px; }
.gate-error { padding: 12px 14px; border-left: 3px solid var(--ochre); background: var(--ochre-soft); }
.gate-options { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 10px; }
.gate-options small { font-weight: 400; color: var(--text-soft); margin-left: 4px; }
.gate-actions { display: flex; flex-wrap: wrap; align-items: center; gap: 12px; }
.gate-note { font-size: var(--fs-small); color: var(--text-soft); max-width: 58ch; padding-top: 14px; border-top: 1px solid var(--rule); }

/* opening sequence */
.opening { width: 100vw; height: 100dvh; background: var(--graphite-deep); color: var(--on-dark); }
.opening::backdrop { background: var(--graphite-deep); }
.opening[open] { display: grid; grid-template-rows: 1fr auto; }
.opening-film { display: grid; place-items: center; padding: 6vh 6vw; }
.scene { display: grid; justify-items: center; text-align: center; gap: 18px; max-width: 900px; animation: scene-in 700ms var(--ease) both; }
.scene.has-photo { grid-template-columns: auto 1fr; text-align: left; justify-items: start; align-items: center; column-gap: 48px; }
.scene.has-photo .scene-photo { grid-row: 1 / span 3; width: min(260px, 32vw); aspect-ratio: 4 / 5; object-fit: cover; border: 10px solid var(--paper); border-bottom-width: 36px; transform: rotate(-2.5deg); box-shadow: 0 30px 60px -20px #000; }
.scene-kicker { color: #C9B9EE; font: 600 var(--fs-small)/1.3 var(--font-sans); letter-spacing: .04em; }
.scene-title { font: 400 clamp(2rem, 1.4rem + 3vw, 4rem)/1.08 var(--font-serif); font-optical-sizing: auto; letter-spacing: -.02em; }
.scene-line { color: var(--on-dark-soft); font: italic 1.125rem/1.5 var(--font-serif); max-width: 60ch; }
@keyframes scene-in { from { opacity: 0; transform: translateY(14px); } }
.opening-foot { display: flex; align-items: center; gap: 20px; padding: 18px 6vw calc(22px + env(safe-area-inset-bottom)); }
.opening-progress { flex: 1; height: 2px; background: color-mix(in srgb, var(--on-dark) 18%, transparent); }
.opening-progress span { display: block; height: 100%; width: 0; background: var(--on-dark); }

/* story */
.story { width: 100vw; height: 100dvh; background: var(--mount); }
.story[open] { animation: story-in 280ms var(--ease) both; }
@keyframes story-in { from { opacity: 0; transform: translateY(18px) scale(.99); } }
.story-scroll { height: 100%; overflow: auto; overscroll-behavior: contain; }
.story-bar { position: sticky; top: 0; z-index: 5; display: flex; align-items: center; gap: 18px; padding: 10px clamp(16px, 3vw, 40px); background: color-mix(in srgb, var(--mount) 94%, transparent); border-bottom: 1px solid var(--rule); backdrop-filter: blur(6px); }
.story-bar nav { display: flex; gap: 2px; overflow-x: auto; scrollbar-width: none; }
.story-bar nav a { display: inline-flex; align-items: center; min-height: 44px; padding: 0 12px; white-space: nowrap; color: var(--graphite); text-decoration: none; font-weight: 500; }
.story-bar nav a:hover { color: var(--ink); text-decoration: underline; }
.story-open { max-width: 1180px; margin: 0 auto; padding: clamp(32px, 6vw, 80px) clamp(16px, 4vw, 48px) 40px; display: grid; grid-template-columns: minmax(240px, 420px) minmax(0, 1fr); gap: clamp(28px, 5vw, 72px); align-items: center; }
.story-open-print { margin: 0; transform: rotate(-1.8deg); }
.story-open-print img { width: 100%; max-height: 72vh; object-fit: cover; border: 12px solid var(--paper); border-bottom-width: 54px; box-shadow: var(--shadow-lift); background: var(--paper); }
.story-open-print figcaption { margin-top: -46px; position: relative; padding: 0 16px; min-height: 40px; font: italic .875rem/1.35 var(--font-serif); color: var(--text-soft); }
.story-open-print.is-unknown > span { display: grid; place-items: center; aspect-ratio: 4 / 5; border: 12px solid var(--paper); border-bottom-width: 54px; background: repeating-linear-gradient(135deg, transparent 0 11px, color-mix(in srgb, var(--graphite) 5%, transparent) 11px 12px), var(--mount-deep); font: 400 4.5rem var(--font-serif); color: color-mix(in srgb, var(--graphite) 45%, var(--mount)); box-shadow: var(--shadow-lift); }
.story-title { display: grid; gap: 18px; }
.story-title h2 { font: 500 clamp(2.4rem, 1.6rem + 3vw, 4.25rem)/1 var(--font-serif); font-optical-sizing: auto; letter-spacing: -.025em; overflow-wrap: anywhere; }
.story-title h2 .nm-given, .story-title h2 .nm-surname { display: block; }
.story-title h2 .nm-surname { font-size: .45em; font-style: italic; font-weight: 400; color: var(--text-soft); margin-top: 8px; letter-spacing: 0; }
.story-dates { font-size: 1.25rem; }
.story-dates small { display: block; font-size: var(--fs-small); color: var(--text-soft); margin-top: 4px; }
.story-lead { font: 400 var(--fs-lead)/1.55 var(--font-serif); max-width: 52ch; }
.story-actions { display: flex; flex-wrap: wrap; gap: 10px; }
.story-sec { max-width: 920px; margin: 0 auto; padding: 44px clamp(16px, 4vw, 48px); border-top: 1px solid var(--rule); scroll-margin-top: 70px; }
.story-sec h3 { font: 500 1.75rem/1.15 var(--font-serif); margin-bottom: 18px; }
.story-sec h3 .count { font: 500 1rem var(--font-sans); color: var(--text-soft); margin-left: 6px; }
.story-sec h4 { font: 600 var(--fs-small)/1.3 var(--font-sans); color: var(--stamp); margin: 22px 0 8px; }
.story-text { font: 400 1.1875rem/1.7 var(--font-serif); max-width: 64ch; }
.facts { margin: 0; padding-left: 20px; display: grid; gap: 8px; font-family: var(--font-serif); font-size: 1.0625rem; }
.story-occupation { margin-top: 16px; }
.timeline { list-style: none; margin: 0; padding: 0 0 0 22px; border-left: 2px solid var(--ink); display: grid; gap: 18px; }
.timeline li { position: relative; display: grid; gap: 2px; }
.timeline li::before { content: ""; position: absolute; left: -29px; top: 5px; width: 12px; height: 12px; border-radius: 50%; background: var(--paper); border: 2px solid var(--ink); }
.timeline .tl-death::before { background: var(--graphite); border-color: var(--graphite); }
.timeline p { font-family: var(--font-serif); font-size: 1.0625rem; }
.story-map { height: 320px; border-radius: var(--r-panel); overflow: hidden; border: 1px solid var(--rule); margin-bottom: 14px; }
.story-places { list-style: none; padding: 0; margin: 0; display: grid; gap: 6px; }
.story-places span { color: var(--text-soft); font-size: var(--fs-small); }
.story-unplaced { margin-top: 12px; color: var(--text-soft); }
.doc-shelf { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 16px; }
.doc { display: grid; grid-template-rows: 200px auto; text-align: left; padding: 0; border: 1px solid var(--rule); background: var(--paper); border-radius: var(--r-print); overflow: hidden; box-shadow: var(--shadow-print); }
.doc img { width: 100%; height: 200px; object-fit: cover; object-position: top; }
.doc span { display: grid; gap: 2px; padding: 10px 12px; }
.doc small { color: var(--text-soft); }
.story-audio { margin-top: 22px; color: var(--text-soft); }
.story-relations { display: grid; gap: 6px; font: 400 1.0625rem/1.55 var(--font-serif); margin-bottom: 18px; }
.near-prints { display: grid; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); gap: 12px; }
.story-note { color: var(--text-soft); margin-bottom: 18px; }
.ev-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 16px; }
.ev-col { padding: 16px; background: var(--paper); border-radius: var(--r-panel); border: 1px solid var(--rule); }
.ev-col.ev-hypothesis { border: 1.5px dashed color-mix(in srgb, var(--ochre) 60%, transparent); }
.ev-col h3 { margin-bottom: 12px; font-size: 1rem; }
.ev-col ul { list-style: none; padding: 0; margin: 0; display: grid; gap: 12px; }
.ev-col li { display: grid; gap: 3px; font-size: .875rem; }
.ev-col li span { color: var(--text-soft); }

/* lightbox */
.lightbox { width: 100vw; height: 100dvh; background: rgb(14 17 20 / .96); color: var(--on-dark); }
.lightbox::backdrop { background: rgb(14 17 20 / .9); }
.lightbox[open] { display: grid; grid-template-columns: 64px 1fr 64px; align-items: center; }
.lightbox figure { margin: 0; display: grid; justify-items: center; gap: 14px; padding: 24px 0; min-width: 0; }
.lightbox img { max-height: 76vh; max-width: 100%; object-fit: contain; border: 8px solid var(--paper); background: var(--paper); }
.lightbox figcaption { display: grid; gap: 4px; text-align: center; max-width: 70ch; }
.lightbox figcaption strong { font: 500 1.25rem var(--font-serif); }
.lightbox figcaption span { color: var(--on-dark); }
.lightbox figcaption small { color: var(--on-dark-soft); }
.lightbox-people a { color: #C9D8F2; }
.lightbox-close { position: absolute; top: 12px; right: 12px; color: var(--on-dark); }
.lightbox-close:focus-visible, .lightbox-nav:focus-visible { outline-color: var(--on-dark); }
.lightbox-nav { width: 56px; height: 72px; border: 0; background: transparent; color: var(--on-dark); font-size: 44px; border-radius: var(--r-control); }
.lightbox-nav:hover { background: rgb(255 255 255 / .08); }

/* sheet dialogs: upload, keeper */
.sheet-dialog { width: min(900px, 96vw); max-height: 92dvh; border-radius: var(--r-panel); box-shadow: var(--shadow-dialog); overflow: auto; }
.sheet-dialog > form, .sheet-dialog > section, .sheet-dialog > .sheet-head { padding-left: clamp(18px, 3vw, 32px); padding-right: clamp(18px, 3vw, 32px); }
.upload-form { display: grid; gap: 18px; padding-bottom: 24px; }
.sheet-head { display: flex; justify-content: space-between; gap: 16px; padding-top: 22px; padding-bottom: 6px; }
.upload-form .sheet-head { padding-left: 0; padding-right: 0; }
.sheet-head h2 { font: 500 1.75rem/1.15 var(--font-serif); }
.sheet-head p { color: var(--text-soft); margin-top: 6px; max-width: 62ch; }
.dropzone { position: relative; display: grid; place-items: center; gap: 4px; min-height: 130px; padding: 18px; border: 2px dashed var(--rule-strong); border-radius: var(--r-panel); text-align: center; background: var(--mount-light); cursor: pointer; }
.dropzone.is-over { border-color: var(--ink); background: var(--ink-soft); }
.dropzone input { position: absolute; inset: 0; opacity: 0; cursor: pointer; }
.dropzone strong { font: 500 1.25rem var(--font-serif); color: var(--ink); }
.dropzone small { color: var(--text-soft); }
.dropzone:focus-within { outline: 3px solid var(--ink); outline-offset: 2px; }
.upload-preview { display: flex; flex-wrap: wrap; gap: 10px; }
.upload-preview figure { margin: 0; width: 96px; }
.upload-preview img { width: 96px; height: 96px; object-fit: cover; border: 4px solid var(--paper); box-shadow: var(--shadow-print); }
.upload-preview figcaption { font-size: 11px; color: var(--text-soft); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 14px 18px; }
.form-grid .span-2 { grid-column: 1 / -1; }
.form-grid label, .field { display: grid; gap: 5px; }
.form-grid label > span, .field-label, .field legend { font-size: var(--fs-small); font-weight: 600; color: var(--text-soft); }
.form-grid input, .form-grid textarea, .papa-login input { width: 100%; min-height: 44px; padding: 8px 12px; border: 1px solid var(--rule-strong); border-radius: var(--r-control); background: var(--paper); }
.form-grid textarea { resize: vertical; min-height: 88px; }
.precision { border: 0; padding: 0; margin: 0; }
.precision label { display: inline-flex; align-items: center; gap: 6px; min-height: 44px; margin-right: 14px; font-size: var(--fs-ui); color: var(--graphite); font-weight: 400; }
.precision input { width: 18px; height: 18px; min-height: 0; accent-color: var(--ink); }
.check { display: flex; gap: 10px; align-items: flex-start; }
.check input { width: 20px; height: 20px; margin-top: 2px; accent-color: var(--ink); flex: none; }
.form-status { min-height: 1.4em; color: var(--text-soft); }
.form-status.is-error { color: #7A2E1A; }
.form-status.is-success { color: var(--ink); font-weight: 600; }
.sheet-foot { display: flex; justify-content: flex-end; gap: 10px; flex-wrap: wrap; }

/* person picker */
.person-picker { display: grid; gap: 8px; }
.pp-chips { display: flex; flex-wrap: wrap; gap: 6px; min-height: 32px; align-items: center; }
.pp-chip { display: inline-flex; align-items: center; gap: 6px; min-height: 36px; padding: 0 10px; border: 1px solid var(--ink); border-radius: var(--r-print); background: var(--ink-soft); color: var(--ink); font-weight: 500; }
.pp-none { color: var(--text-faint); font-size: var(--fs-small); }
.pp-box { position: relative; }
.pp-options { position: absolute; z-index: 5; top: calc(100% + 4px); left: 0; right: 0; max-height: 260px; overflow: auto; background: var(--paper); border-radius: var(--r-control); box-shadow: var(--shadow-lift); padding: 4px; }
.pp-options button { width: 100%; display: grid; grid-template-columns: 1fr auto auto; gap: 10px; align-items: center; min-height: 44px; padding: 6px 10px; border: 0; background: none; text-align: left; border-radius: 4px; }
.pp-options button:hover, .pp-options button[aria-selected="true"] { background: var(--ink-soft); }
.pp-years { font-size: var(--fs-small); color: var(--text-soft); }
.pp-mark { color: var(--ink); font-weight: 700; }
.pp-empty { padding: 10px; color: var(--text-soft); }

/* keeper desk */
.papa-login { display: grid; gap: 12px; max-width: 420px; padding-bottom: 28px; padding-top: 10px; }
.papa-login label { display: grid; gap: 5px; font-weight: 600; }
.papa-desk { display: grid; gap: 14px; padding-bottom: 28px; }
.papa-top { display: flex; flex-wrap: wrap; justify-content: space-between; gap: 10px; }
.papa-merge summary { min-height: 44px; display: inline-flex; align-items: center; cursor: pointer; color: var(--ink); font-weight: 600; }
.merge-form { display: flex; flex-wrap: wrap; gap: 10px; align-items: flex-end; padding: 12px; background: var(--mount-light); border-radius: var(--r-control); }
.merge-form label { display: grid; gap: 4px; font-size: var(--fs-small); }
.merge-form input, .merge-form select { min-height: 44px; padding: 0 10px; border: 1px solid var(--rule-strong); border-radius: var(--r-control); background: var(--paper); }
.papa-list { display: grid; gap: 18px; }
.review { display: grid; grid-template-columns: 220px minmax(0, 1fr); gap: 18px; padding: 16px; border: 1px solid var(--rule); border-radius: var(--r-panel); background: var(--paper); }
.review-photo { display: grid; gap: 8px; align-content: start; }
.review-photo img { width: 100%; aspect-ratio: 1; object-fit: cover; border: 6px solid var(--paper); box-shadow: var(--shadow-print); }
.review-photo .stamp { justify-self: start; }
.review-from { font-size: var(--fs-small); color: var(--text-soft); }
.review-actions { display: flex; flex-wrap: wrap; gap: 8px; }

/* toast */
.toast { position: fixed; left: 50%; bottom: 28px; z-index: 60; transform: translate(-50%, 20px); opacity: 0; pointer-events: none; padding: 12px 18px; background: var(--graphite); color: var(--on-dark); border-radius: var(--r-control); box-shadow: var(--shadow-lift); transition: opacity var(--t-med), transform var(--t-med); max-width: calc(100vw - 32px); }
.toast.is-shown { opacity: 1; transform: translate(-50%, 0); }

/* boot state */
body.is-booting main::before { content: "Раскладываем семейный архив…"; display: block; text-align: center; padding: 18vh 20px; font: italic 1.25rem var(--font-serif); color: var(--text-soft); }

/* ---------- tablet ---------- */
@media (max-width: 1180px) {
  .primary-nav a { padding: 0 10px; }
  .search input { width: 170px; }
  .brand-text span { display: none; }
}
@media (max-width: 1099px) {
  .desk, .desk:not(.has-siblings):not(.has-spouses) { grid-template-columns: minmax(150px, 1fr) minmax(0, 2fr) minmax(150px, 1fr); column-gap: 36px; }
  .focus { grid-template-columns: 1fr; }
  .focus-print { margin: -40px auto 0; width: min(260px, 70%); }
  .focus-meta { grid-template-columns: 1fr; }
  .print { grid-template-columns: 1fr; padding: 6px 6px 10px; }
  .print .photo-sm, .print-md .photo-sm { width: 100%; height: auto; aspect-ratio: 5 / 4; }
  .print-xs { grid-template-columns: auto 1fr; }
  .print-xs .photo-xs { width: 44px; height: 52px; aspect-ratio: auto; }
  .print-text { padding: 0 4px; }
  .map-layout { grid-template-columns: 1fr; }
  .map-panel { max-height: none; }
  .ev-grid { grid-template-columns: 1fr; }
  .tree-legend { display: none; }
}
@media (max-width: 1020px) {
  .primary-nav { display: none; }
  .relstrip, .tabbar { display: block; }
  .oleg { display: none; }
  body.oleg-open .oleg { display: grid; }
  .tabbar {
    position: fixed; left: 0; right: 0; bottom: 0; z-index: 30;
    display: grid; grid-template-columns: repeat(6, 1fr);
    height: calc(var(--tabbar-h) + env(safe-area-inset-bottom)); padding-bottom: env(safe-area-inset-bottom);
    background: var(--graphite); color: var(--on-dark-soft);
  }
  .tabbar a, .tabbar button { display: grid; justify-items: center; align-content: center; gap: 3px; min-height: 44px; border: 0; background: none; color: inherit; text-decoration: none; font-size: 11px; font-weight: 500; }
  .tabbar svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 1.6; }
  .tabbar a.is-active, .tabbar button[aria-expanded="true"] { color: var(--on-dark); }
  .tabbar a.is-active svg { stroke-width: 2.2; }
  .tabbar .oleg-mark { width: 24px; height: 24px; font-size: .8rem; }
  .tabbar a:focus-visible, .tabbar button:focus-visible { outline-color: var(--on-dark); outline-offset: -4px; }
  .view { padding-bottom: calc(var(--tabbar-h) + 48px); }
  body[data-view="card"] .view-card { padding-bottom: calc(var(--tabbar-h) + var(--strip-h) + 40px); }
  .relstrip { display: none; }
  body[data-view="card"] .relstrip {
    display: block; position: fixed; left: 0; right: 0; bottom: calc(var(--tabbar-h) + env(safe-area-inset-bottom)); z-index: 29;
    height: var(--strip-h); background: var(--paper); border-top: 1px solid var(--rule-strong); box-shadow: 0 -8px 20px -14px rgb(0 0 0 / .4);
  }
  .relstrip ul { display: flex; gap: 4px; height: 100%; margin: 0; padding: 6px 10px; list-style: none; overflow-x: auto; scrollbar-width: none; scroll-snap-type: x proximity; }
  .relstrip li { flex: none; scroll-snap-align: start; }
  .relstrip a { display: grid; justify-items: center; gap: 1px; width: 74px; height: 100%; padding-top: 2px; color: var(--graphite); text-decoration: none; }
  .strip-face { width: 40px; height: 40px; border-radius: 50%; display: grid; place-items: center; background: var(--mount-deep); font: 500 .85rem var(--font-serif); overflow: hidden; }
  .strip-face img { width: 100%; height: 100%; object-fit: cover; }
  .strip-label { font-size: 10.5px; font-weight: 600; color: var(--stamp); line-height: 1.1; }
  .strip-name { font-size: 12px; line-height: 1.1; max-width: 70px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .relstrip p { padding: 28px 16px; color: var(--text-faint); font-style: italic; }
  .oleg { right: 12px; left: 12px; bottom: calc(var(--tabbar-h) + env(safe-area-inset-bottom) + 10px); z-index: 31; }
  .oleg-launch { display: none; }
  .oleg-panel { width: 100%; max-height: calc(100dvh - var(--masthead-h) - var(--tabbar-h) - 40px); }
  .toast { bottom: calc(var(--tabbar-h) + var(--strip-h) + 16px); }
  .tree-viewport { height: calc(100dvh - var(--masthead-h) - var(--tabbar-h) - 220px); min-height: 380px; }
}

/* ---------- phone ---------- */
@media (max-width: 759px) {
  :root { --masthead-h: 112px; }
  .masthead { flex-wrap: wrap; height: auto; min-height: var(--masthead-h); padding: 8px 14px 10px; gap: 8px 10px; }
  .masthead-tools { display: contents; }
  .viewer-chip { margin-left: auto; max-width: 46vw; }
  .search { order: 3; flex: 1 1 100%; }
  .search input { width: 100%; }
  .search .suggest { left: 0; right: 0; width: auto; min-width: 0; }
  .brand-mark { width: 30px; height: 30px; }
  .view { padding-left: 14px; padding-right: 14px; }
  .view-card { padding-top: 34px; }
  .desk { display: block; }
  .desk-lines, .slot, .line-legend { display: none; }
  .focus { display: grid; grid-template-columns: 1fr; padding: 16px; gap: 18px; }
  .focus-side { display: contents; }
  .focus-print { order: 0; width: min(190px, 56%); margin: -30px auto 0; }
  .focus-print figcaption { font-size: .78rem; }
  .focus-back { order: 1; }
  .focus-name { font-size: clamp(2rem, 9vw, 2.5rem); }
  .focus-counts { order: 2; grid-template-columns: repeat(2, minmax(0, 1fr)); column-gap: 14px; }
  .focus-actions .btn { flex: 1 1 auto; }
  .focus-actions .btn-lg { flex-basis: 100%; }
  .near { display: grid; gap: 10px; margin-top: 28px; }
  .near h2 { font: 500 1.5rem var(--font-serif); }
  .near h3 { font: 600 var(--fs-small)/1.3 var(--font-sans); color: var(--text-soft); margin-top: 10px; }
  .near-prints { grid-template-columns: 1fr; gap: 8px; }
  .view-head h1 { font-size: 1.75rem; }
  .segmented { display: flex; width: 100%; min-width: 0; max-width: 100%; overflow-x: auto; flex-wrap: nowrap; }
  .segmented span { white-space: nowrap; padding: 0 12px; }
  .tree-search { width: 100%; }
  .tree-search input { flex: 1; width: auto; }
  .tree-zoom { flex-wrap: wrap; }
  .tree-minimap { width: 120px; height: 76px; right: 8px; top: auto; bottom: 8px; opacity: .92; }
  .map-filters, .archive-filters { padding: 12px; }
  .map-filters label, .archive-filters label { flex: 1 1 140px; }
  .map-filters select, .archive-filters select { max-width: none; width: 100%; }
  .map-canvas { height: 56vh; min-height: 320px; }
  .contact-sheet { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 18px 12px; }
  .gate { width: 100vw; height: 100dvh; max-height: none; border-radius: 0; overflow: auto; }
  .gate-form { grid-template-columns: 1fr; min-height: 100%; }
  .gate-print { border-radius: 0; padding: 18px; grid-template-columns: auto 1fr; align-items: center; gap: 14px; }
  .gate-photo { margin: 0; width: 96px; grid-row: 1 / span 2; }
  .gate-photo figcaption { display: none; }
  .gate-photo img { border-width: 5px; border-bottom-width: 14px; }
  .gate-print-caption { font-size: 1.05rem; }
  .gate-body { padding: 22px 18px 28px; align-content: start; }
  .gate-actions .btn-lg { width: 100%; }
  .scene.has-photo { grid-template-columns: 1fr; justify-items: center; text-align: center; }
  .scene.has-photo .scene-photo { grid-row: auto; width: min(200px, 56vw); }
  .story-open { grid-template-columns: 1fr; padding-top: 24px; }
  .story-open-print { width: min(300px, 80%); justify-self: center; }
  .story-bar { gap: 6px; padding: 6px 10px; }
  .story-back { padding: 0 10px; }
  .lightbox[open] { grid-template-columns: 1fr; }
  .lightbox-nav { position: absolute; bottom: 12px; }
  .lightbox-nav.is-prev { left: 12px; }
  .lightbox-nav.is-next { right: 12px; }
  .form-grid { grid-template-columns: 1fr; }
  .review { grid-template-columns: 1fr; }
  .sheet-dialog { width: 100vw; max-height: 100dvh; height: 100dvh; border-radius: 0; }
}
@media (max-width: 380px) {
  .tabbar a span, .tabbar button span:last-child { font-size: 10px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 1ms !important; animation-delay: 0ms !important; transition-duration: 1ms !important; scroll-behavior: auto !important; }
}
@media (forced-colors: active) {
  .desk-lines .dl, .tree-edges .e { stroke: CanvasText; }
  .print, .tnode { border: 1px solid CanvasText; }
}
