:root {
  --paper: #f4ecdc;
  --paper-2: #efe4cf;
  --card: #fffaf0;
  --ink: #2b2219;
  --ink-2: #5b4c3d;
  --muted: #8a7a66;
  --line: #d8c8ab;
  --accent: #8c3b2f;
  --accent-2: #a8613f;
  --doc: #4f7a4c;
  --doc-bg: #eef3e4;
  --family: #3f6694;
  --family-bg: #e9eef6;
  --hyp: #9a8b74;
  --hyp-bg: #f3eee4;
  --shadow: 0 1px 2px rgba(60, 40, 20, .08), 0 6px 20px rgba(60, 40, 20, .10);
  --serif: "PT Serif", Georgia, "Times New Roman", serif;
  --display: "Cormorant Garamond", "PT Serif", Georgia, serif;
  --sans: "PT Sans", "Segoe UI", Roboto, Arial, sans-serif;
}
* { box-sizing: border-box; }
html, body { margin: 0; overflow-x: hidden; max-width: 100%; }
body {
  font-family: var(--serif); color: var(--ink); background: var(--paper);
  background-image:
    radial-gradient(ellipse at 20% 0%, rgba(255,255,255,.55), transparent 55%),
    radial-gradient(ellipse at 100% 100%, rgba(140,90,40,.08), transparent 60%);
  line-height: 1.5; -webkit-font-smoothing: antialiased;
}
a { color: var(--accent); }
h1, h2, h3 { font-family: var(--display); font-weight: 700; line-height: 1.15; color: var(--ink); }
h1 { font-size: clamp(30px, 5vw, 46px); margin: 0 0 8px; }
h3 { font-size: 22px; margin: 18px 0 8px; }
.small { font-size: 13px; } .muted { color: var(--muted); }
.nowrap { white-space: nowrap; }

/* шапка */
.topbar {
  position: sticky; top: 0; z-index: 30; display: flex; align-items: center; justify-content: space-between;
  gap: 12px; padding: 10px 20px; background: rgba(244, 236, 220, .92); backdrop-filter: blur(6px);
  border-bottom: 1px solid var(--line); font-family: var(--sans);
}
.brand { display: flex; align-items: center; gap: 10px; text-decoration: none; color: var(--ink); font-family: var(--display); font-size: 22px; font-weight: 700; }
.brand-mark { width: 34px; height: 34px; border-radius: 50%; display: grid; place-items: center; background: var(--accent); color: #fff6e8; font-size: 20px; }
.topbar nav { display: flex; align-items: center; gap: 16px; flex-wrap: wrap; justify-content: flex-end; }
.topbar nav a { color: var(--ink-2); text-decoration: none; font-size: 15px; }
.topbar nav a:hover { color: var(--accent); }
.inline { display: inline; margin: 0; }
.linklike { background: none; border: 0; padding: 0; color: var(--accent); cursor: pointer; font: inherit; text-decoration: underline; text-underline-offset: 2px; }
.linklike.danger, .danger { color: #a23b2c; }
.btn, .btn-small, .topbar nav a.btn-small {
  display: inline-block; background: var(--accent); color: #fff8ec !important; border: 0; border-radius: 999px;
  padding: 10px 20px; font-family: var(--sans); font-size: 15px; font-weight: 700; cursor: pointer; text-decoration: none;
  box-shadow: 0 2px 6px rgba(140, 59, 47, .25);
}
.btn-small, .topbar nav a.btn-small { padding: 6px 14px; font-size: 14px; }
.btn:hover, .btn-small:hover { background: #7a3127; }

.flashes { max-width: 900px; margin: 12px auto 0; padding: 0 16px; }
.flash { padding: 10px 14px; border-radius: 8px; margin-bottom: 8px; font-family: var(--sans); background: #f2ead6; border: 1px solid var(--line); }
.flash.error { background: #f7e1da; border-color: #e0b3a6; }
.flash.ok { background: #e7efdc; border-color: #bcd0a6; }

/* главная */
.tree-page { overflow: hidden; height: var(--app-h, 100dvh); display: flex; flex-direction: column; }
.hero { display: flex; justify-content: space-between; align-items: flex-end; gap: 16px 30px; padding: 14px 24px 10px; flex-wrap: wrap; }
.hero-text { max-width: 760px; }
.hero h1 { margin: 0; font-size: clamp(30px, 4.5vw, 44px); }
.hero p { margin: 2px 0 0; color: var(--ink-2); font-size: 15px; }
.legend { display: flex; gap: 14px; flex-wrap: wrap; font-family: var(--sans); font-size: 13px; color: var(--ink-2); }
.legend span { display: inline-flex; align-items: center; gap: 6px; }
.sw { width: 16px; height: 12px; border-radius: 3px; display: inline-block; border: 2px solid; }
.sw.doc { border-color: var(--doc); background: var(--doc-bg); }
.sw.family { border-color: var(--family); background: var(--family-bg); }
.sw.hyp { border-color: var(--hyp); background: var(--hyp-bg); border-style: dashed; }

.tree-wrap { position: relative; flex: 1; min-height: 0; border-top: 1px solid var(--line); background:
  linear-gradient(rgba(255,255,255,.25), rgba(255,255,255,0)),
  repeating-linear-gradient(0deg, transparent 0 39px, rgba(140,110,70,.05) 39px 40px); touch-action: none; }
#tree { width: 100%; height: 100%; display: block; cursor: grab; user-select: none; -webkit-user-select: none; }
#tree.dragging { cursor: grabbing; }
#tree.dragging #viewport { will-change: transform; }
.tree-controls { position: absolute; right: 16px; bottom: 16px; display: flex; flex-direction: column; gap: 6px; }
.tree-controls button {
  width: 42px; height: 42px; border-radius: 50%; border: 1px solid var(--line); background: var(--card); color: var(--ink);
  font-size: 22px; line-height: 1; cursor: pointer; box-shadow: var(--shadow);
}
.tree-controls button:hover { background: #fff; color: var(--accent); }
.tree-hint { position: absolute; left: 16px; bottom: 14px; font-family: var(--sans); font-size: 12.5px; color: var(--muted); background: rgba(255,250,240,.8); padding: 4px 10px; border-radius: 999px; pointer-events: none; }

/* узлы дерева (SVG) */
.node { cursor: pointer; }
.node .box { fill: var(--card); stroke-width: 1.6; }
.node.doc .box { stroke: var(--doc); }
.node.family .box { stroke: var(--family); }
.node.hyp .box { stroke: var(--hyp); stroke-dasharray: 6 4; }
.node .band { opacity: .9; }
.node.doc .band { fill: var(--doc); } .node.family .band { fill: var(--family); } .node.hyp .band { fill: var(--hyp); }
.node:hover .box, .node.active .box { stroke-width: 3; }
.node.line .box { fill: #fffdf6; }
.node.me .box { stroke: var(--accent); stroke-width: 2.6; }
.node .nm { font-family: var(--serif); font-weight: 700; font-size: 13.5px; fill: var(--ink); }
.node .yr { font-family: var(--sans); font-size: 12.5px; fill: var(--accent); font-weight: 700; }
.node .rl { font-family: var(--sans); font-size: 11.5px; fill: var(--muted); }
.node .ava-bg { fill: #eadbc0; stroke: #fffaf0; stroke-width: 2; }
.node.f .ava-bg { fill: #ecd6c9; }
.node .ini { font-family: var(--display); font-weight: 700; font-size: 22px; fill: #8a6a48; }
.node.placeholder .box { fill: transparent; stroke-dasharray: 3 4; }
.edge { fill: none; stroke-width: 1.8; }
.edge.doc { stroke: #7c9a73; } .edge.family { stroke: #7c98bd; } .edge.hyp { stroke: #b3a58e; stroke-dasharray: 6 5; }
.spouse-line { stroke: #b49b78; stroke-width: 1.6; }
.spouse-ring { fill: var(--paper); stroke: #b49b78; stroke-width: 1.4; }
.gen-label { font-family: var(--display); font-size: 26px; font-weight: 700; fill: rgba(140, 59, 47, .35); }
.gen-sub { font-family: var(--sans); font-size: 12px; fill: rgba(91, 76, 61, .55); }

/* карточка человека */
.card {
  position: fixed; z-index: 40; width: min(440px, calc(100vw - 24px)); max-height: min(78vh, 760px); overflow: auto;
  background: var(--card); border: 1px solid var(--line); border-radius: 14px; box-shadow: 0 10px 40px rgba(60, 40, 20, .25);
  padding: 18px 18px 14px; font-size: 15px;
}
.card.pinned { border-color: var(--accent-2); }
.card-close { position: absolute; top: 8px; right: 10px; border: 0; background: none; font-size: 26px; color: var(--muted); cursor: pointer; line-height: 1; }
.card-head { display: flex; gap: 14px; align-items: center; margin-bottom: 10px; padding-right: 20px; }
.card-ava { width: 72px; height: 72px; border-radius: 50%; object-fit: cover; flex: 0 0 72px; background: #eadbc0; display: grid; place-items: center; font-family: var(--display); font-size: 30px; color: #8a6a48; border: 3px solid #fff; box-shadow: 0 1px 4px rgba(0,0,0,.15); cursor: zoom-in; }
.card h2 { margin: 0; font-size: 26px; }
.card .role { color: var(--ink-2); font-family: var(--sans); font-size: 14px; }
.card .years { color: var(--accent); font-family: var(--sans); font-weight: 700; font-size: 14px; }
.badge { display: inline-block; font-family: var(--sans); font-size: 12px; padding: 1px 9px; border-radius: 999px; color: #fff; vertical-align: middle; }
.badge.gen { background: #fff; color: var(--accent); border: 1px solid #d9b7a3; }
.badge.doc { background: var(--doc); } .badge.family { background: var(--family); } .badge.hyp { background: var(--hyp); }
.card section { margin-top: 12px; }
.card h4 { margin: 0 0 6px; font-family: var(--sans); font-size: 12px; letter-spacing: .08em; text-transform: uppercase; color: var(--muted); }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip { font-family: var(--sans); font-size: 13px; padding: 3px 10px; border-radius: 999px; background: var(--paper-2); border: 1px solid var(--line); color: var(--ink); cursor: pointer; }
.chip:hover { border-color: var(--accent-2); }
.chip .k { color: var(--muted); margin-right: 3px; }
.facts { list-style: none; margin: 0; padding: 0; }
.facts li { position: relative; padding: 0 0 10px 16px; border-left: 2px solid var(--line); margin-left: 4px; }
.facts li::before { content: ""; position: absolute; left: -6px; top: 6px; width: 10px; height: 10px; border-radius: 50%; background: var(--accent-2); border: 2px solid var(--card); }
.facts .src { display: block; margin-top: 2px; font-family: var(--sans); font-size: 12.5px; color: var(--muted); }
.srcbtn { font: inherit; border: 0; background: none; padding: 0; color: var(--doc); cursor: pointer; text-decoration: underline; text-underline-offset: 2px; }
.oral { color: var(--family); }
.docs { display: grid; grid-template-columns: repeat(auto-fill, minmax(120px, 1fr)); gap: 8px; }
.dtile { border: 1px solid var(--line); border-radius: 8px; overflow: hidden; background: #fff; cursor: zoom-in; display: flex; flex-direction: column; padding: 0; font: inherit; text-align: left; color: inherit; }
.dtile img { width: 100%; height: 86px; object-fit: cover; object-position: top; display: block; background: #eee; }
.dtile .noimg { display: grid; place-items: center; width: 100%; align-self: stretch; height: 86px; display: grid; place-items: center; font-family: var(--sans); font-size: 12px; color: var(--muted); background: var(--paper-2); }
.dtile .cap { display: block; width: 100%; padding: 5px 7px; font-family: var(--sans); font-size: 11.5px; line-height: 1.3; color: var(--ink-2); }
.dtile .cap b { display: block; color: var(--ink); font-size: 12px; }
.dtile .cap a { color: var(--accent); }
.gallery { display: flex; gap: 8px; flex-wrap: wrap; }
.gallery img { width: 78px; height: 78px; object-fit: cover; border-radius: 8px; cursor: zoom-in; border: 1px solid var(--line); }
.req-list { margin: 0; padding-left: 18px; font-size: 14px; color: var(--ink-2); }
.card-foot { margin-top: 14px; padding-top: 10px; border-top: 1px dashed var(--line); display: flex; gap: 12px; flex-wrap: wrap; font-family: var(--sans); font-size: 14px; }
.living-note { background: var(--family-bg); border-radius: 8px; padding: 8px 10px; font-size: 14px; }

/* лайтбокс: сцена на весь экран, pinch-zoom через transform */
.lightbox { position: fixed; inset: 0; z-index: 60; background: #1d160f; display: flex; flex-direction: column; }
.lightbox[hidden] { display: none; }
.lb-stage { flex: 1; min-height: 0; display: flex; align-items: center; justify-content: center; overflow: hidden; touch-action: none; padding: 8px; }
.lb-frame { position: relative; flex: 0 0 auto; max-width: 100%; max-height: 100%; transform-origin: 50% 50%; --zk: 1; }
.lb-frame.gesture { will-change: transform; }
.lb-frame img { display: block; width: 100%; height: 100%; background: #fff; user-select: none; -webkit-user-drag: none; }
.lb-cap { flex: 0 0 auto; max-height: 30vh; overflow: auto; color: #f1e6d2; font-family: var(--sans); font-size: 15px; line-height: 1.45; padding: 10px 16px calc(12px + env(safe-area-inset-bottom)); background: #251c13; }
.lb-cap a { color: #f6c8a0; }
.lb-links { display: flex; flex-wrap: wrap; gap: 6px 16px; margin-top: 6px; }
.lb-links a { display: inline-flex; align-items: center; min-height: 44px; }
.lb-close { position: absolute; top: calc(6px + env(safe-area-inset-top)); right: 8px; width: 48px; height: 48px; font-size: 34px; line-height: 1; color: #fff; background: rgba(0,0,0,.35); border: 0; border-radius: 50%; cursor: pointer; z-index: 61; }
body.lb-open, body.sheet-open { overflow: hidden; }

/* обычные страницы */
.page { max-width: 1180px; margin: 0 auto; padding: 24px 20px 60px; }
.page.narrow { max-width: 760px; }
.page.center { text-align: center; }
.lead { font-size: 18px; color: var(--ink-2); }
.form { display: flex; flex-direction: column; gap: 14px; margin-top: 14px; }
.form label { display: flex; flex-direction: column; gap: 5px; font-family: var(--sans); font-size: 14px; color: var(--ink-2); }
.form label.radio { flex-direction: row; align-items: center; gap: 8px; flex-wrap: wrap; }
.form input:not([type=radio]):not([type=checkbox]), .form select, .form textarea, .inline input {
  font: 16px var(--serif); padding: 10px 12px; border: 1px solid var(--line); border-radius: 8px; background: #fffdf8; color: var(--ink);
}
.inline input { padding: 4px 8px; font-size: 14px; }
.form textarea { resize: vertical; }
.form input:focus, .form select:focus, .form textarea:focus { outline: 2px solid rgba(168, 97, 63, .4); border-color: var(--accent-2); }
.form .btn, .form .btn-small { align-self: flex-start; }
.row2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.req { color: var(--accent); }
.srcset { border: 1px solid var(--line); border-radius: 8px; padding: 8px 12px; display: flex; flex-direction: column; gap: 6px; }
.srcset legend { font-family: var(--sans); font-size: 13px; color: var(--muted); }
.srcset select, .srcset input { flex: 1; min-width: 160px; }
.login { max-width: 420px; }

.src-list { display: flex; flex-direction: column; gap: 14px; margin-top: 18px; }
.srcitem { display: grid; grid-template-columns: 160px 1fr; gap: 16px; background: var(--card); border: 1px solid var(--line); border-radius: 10px; padding: 12px; }
.srcitem img { width: 160px; height: 120px; object-fit: cover; object-position: top; border-radius: 6px; }
.srcitem .noimg { width: 160px; height: 120px; display: grid; place-items: center; background: var(--paper-2); border-radius: 6px; color: var(--muted); font-family: var(--sans); font-size: 13px; }
.srcitem h3 { margin: 0 0 4px; font-size: 20px; }
.srcitem p { margin: 4px 0; font-size: 15px; }
.meta { font-family: var(--sans); font-size: 13px; color: var(--muted); }

/* админка */
.admin-nav { display: flex; gap: 6px; flex-wrap: wrap; align-items: center; margin-bottom: 18px; font-family: var(--sans); }
.admin-nav a { padding: 6px 14px; border-radius: 999px; text-decoration: none; color: var(--ink-2); border: 1px solid var(--line); background: var(--card); }
.admin-nav a.on { background: var(--accent); color: #fff; border-color: var(--accent); }
.admin-nav .who { margin-left: auto; color: var(--muted); font-size: 13px; }
.tabs { display: flex; gap: 10px; flex-wrap: wrap; margin: 6px 0 14px; font-family: var(--sans); font-size: 14px; }
.tabs a { color: var(--ink-2); text-decoration: none; padding-bottom: 2px; }
.tabs a.on { color: var(--accent); border-bottom: 2px solid var(--accent); }
.tbl { width: 100%; border-collapse: collapse; background: var(--card); border: 1px solid var(--line); border-radius: 10px; overflow: hidden; font-size: 14.5px; }
.tbl th, .tbl td { text-align: left; padding: 8px 10px; border-bottom: 1px solid #eadfc9; vertical-align: top; }
.tbl th { font-family: var(--sans); font-size: 12.5px; color: var(--muted); font-weight: 700; background: #f8f0e0; }
.tbl tr.click { cursor: pointer; } .tbl tr.click:hover td { background: #fbf4e6; }
.pill { display: inline-block; font-family: var(--sans); font-size: 12px; padding: 1px 9px; border-radius: 999px; background: var(--paper-2); border: 1px solid var(--line); white-space: nowrap; }
.st-new { background: #f7e1da; border-color: #e0b3a6; } .st-review { background: #f6ecc9; border-color: #e2cf8f; }
.st-accepted { background: #e2eed8; border-color: #b7cf9f; } .st-rejected { background: #e8e3dc; color: #7d7468; }
.s-doc { background: var(--doc-bg); border-color: #b8cba9; } .s-family { background: var(--family-bg); border-color: #b5c4dc; } .s-hyp { background: var(--hyp-bg); }
.grid-2 { display: grid; grid-template-columns: 1.15fr 1fr; gap: 18px; align-items: start; }
.panel { background: var(--card); border: 1px solid var(--line); border-radius: 12px; padding: 16px 18px; }
.panel h3:first-child { margin-top: 0; }
.kv { display: grid; grid-template-columns: 120px 1fr; gap: 4px 12px; margin: 0 0 12px; font-size: 15px; }
.kv dt { color: var(--muted); font-family: var(--sans); font-size: 13px; padding-top: 2px; }
.kv dd { margin: 0; }
.subtext { white-space: pre-wrap; background: #fffdf8; border: 1px solid #eadfc9; border-radius: 8px; padding: 12px 14px; font-size: 16px; }
.files-grid, .photos-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(130px, 1fr)); gap: 10px; }
.filebox { display: flex; flex-direction: column; gap: 4px; padding: 6px; border: 1px solid var(--line); border-radius: 8px; text-decoration: none; color: var(--ink); background: #fff; font-size: 12.5px; font-family: var(--sans); word-break: break-word; }
.filebox img { width: 100%; height: 100px; object-fit: cover; border-radius: 4px; }
.filebox .ext { height: 100px; display: grid; place-items: center; background: var(--paper-2); font-weight: 700; color: var(--accent); border-radius: 4px; }
.comment { border-left: 3px solid var(--accent-2); padding: 4px 10px; margin-bottom: 10px; white-space: pre-wrap; }
.inline-form { flex-direction: row; align-items: flex-end; gap: 10px; margin-top: 0; }
.fact { border-bottom: 1px dashed #e3d5bb; padding: 8px 0; }
.fact.req { background: #fbf3e3; padding: 8px; border-radius: 6px; }
.fact .src { font-family: var(--sans); font-size: 12.5px; color: var(--muted); margin-top: 2px; }
.ph { margin: 0; border: 1px solid var(--line); border-radius: 8px; padding: 6px; background: #fff; font-size: 12.5px; font-family: var(--sans); }
.ph.avatar { border-color: var(--accent-2); }
.ph img { width: 100%; height: 120px; object-fit: cover; border-radius: 4px; }
.ph-actions { margin-top: 4px; display: flex; gap: 8px; flex-wrap: wrap; }
.doclist { padding-left: 18px; font-size: 14px; }
.note { background: var(--family-bg); border-radius: 8px; padding: 8px 12px; font-family: var(--sans); font-size: 14px; }

@media (max-width: 760px) {
  .topbar { padding: 8px 12px; }
  .brand span:last-child { display: none; }
  .topbar nav { gap: 10px; flex-wrap: nowrap; }
  .topbar nav a { font-size: 14px; white-space: nowrap; }
  .topbar nav a.btn-small { padding: 5px 11px; font-size: 13px; }
  .hero h1 { font-size: 28px; }
  .legend { gap: 8px; font-size: 12px; }
  .hero { padding: 10px 14px 8px; }
  .hero p { display: none; }
  .tree-hint { display: none; }
  .row2, .grid-2 { grid-template-columns: 1fr; }
  .srcitem { grid-template-columns: 1fr; }
  .srcitem img, .srcitem .noimg { width: 100%; height: 160px; }
  .tbl { font-size: 13px; } .tbl th:nth-child(5), .tbl td:nth-child(5) { display: none; }
}

/* переключатель вида */
.view-switch { display: inline-flex; background: var(--paper-2); border: 1px solid var(--line); border-radius: 999px; padding: 3px; font-family: var(--sans); }
.view-switch button { border: 0; background: none; padding: 7px 16px; border-radius: 999px; font: 700 14px var(--sans); color: var(--ink-2); cursor: pointer; min-height: 36px; }
.view-switch button[aria-selected="true"] { background: var(--accent); color: #fff8ec; }
.tree-page.view-list { height: auto; overflow: visible; display: block; }
.tree-wrap[hidden], .ladder[hidden] { display: none; }

/* список-«лестница» */
.ladder { max-width: 720px; margin: 0 auto; padding: 4px 14px calc(40px + env(safe-area-inset-bottom)); font-family: var(--sans); }
.ladder-intro { color: var(--ink-2); font: 17px/1.5 var(--serif); margin: 4px 2px 14px; }
.ladder-loading { padding: 30px; text-align: center; color: var(--muted); }
.steps { display: flex; flex-direction: column; }
.step { background: var(--card); border: 1px solid var(--line); border-radius: 16px; padding: 10px 10px 8px; }
.step.me { border-color: var(--accent); }
.step-link { width: 2px; height: 18px; background: #b49b78; margin: 0 auto; }
.gen-chip { font: 700 13px var(--sans); letter-spacing: .08em; text-transform: uppercase; color: var(--accent-2); margin: 2px 4px 6px; }
.lr { -webkit-tap-highlight-color: rgba(140,59,47,.12); touch-action: manipulation; display: flex; align-items: center; gap: 12px; width: 100%; min-height: 64px; padding: 6px 6px; border: 0; background: none; text-align: left; font: inherit; color: var(--ink); border-radius: 12px; cursor: pointer; }
.lr:active { background: var(--paper-2); }
.lr-ava { flex: 0 0 56px; width: 56px; height: 56px; border-radius: 50%; object-fit: cover; display: grid; place-items: center; background: #eadbc0; color: #8a6a48; font: 700 22px var(--display); border: 2px solid #fff; box-shadow: 0 0 0 2px var(--doc); }
.lr.family .lr-ava { box-shadow: 0 0 0 2px var(--family); }
.lr.hyp .lr-ava { box-shadow: 0 0 0 2px var(--hyp); }
.lr-ava.f { background: #ecd6c9; }
.lr-txt { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 1px; }
.lr-name { font: 700 20px/1.25 var(--serif); }
.lr-years { font: 700 16px var(--sans); color: var(--accent); }
.lr-role { font-size: 15px; color: var(--muted); }
.lr-go { font-size: 28px; color: #c2ae8d; padding: 0 4px; }
.lr.small { min-height: 56px; }
.lr.small .lr-ava { flex-basis: 44px; width: 44px; height: 44px; font-size: 17px; }
.lr.small .lr-name { font-size: 18px; }
.lg-label { font: 700 12px var(--sans); color: var(--muted); text-transform: uppercase; letter-spacing: .06em; margin: 6px 6px 0; }
.lg { border-top: 1px dashed #e3d5bb; margin-top: 4px; }
.lg summary { list-style: none; cursor: pointer; min-height: 48px; display: flex; align-items: center; gap: 8px; padding: 4px 6px; font: 700 16px var(--sans); color: var(--ink-2); }
.lg summary::-webkit-details-marker { display: none; }
.lg summary::before { content: "▸"; color: var(--accent-2); transition: transform .15s; }
.lg[open] summary::before { transform: rotate(90deg); }
.lg-body { padding: 0 0 4px 10px; }

.sheet-backdrop { position: fixed; inset: 0; background: rgba(30, 20, 10, .45); z-index: 39; }
.sheet-backdrop[hidden] { display: none; }
.sheet-grip { display: none; }

@media (max-width: 820px), (hover: none) and (pointer: coarse) {
  body { font-size: 17px; }
  /* дерево на телефоне: на весь экран под шапкой, страница не прокручивается */
  .tree-page.view-tree { height: var(--app-h, 100dvh); overflow: hidden; display: flex; flex-direction: column; overscroll-behavior: none; }
  .tree-page.view-tree .hero { flex-wrap: nowrap; padding: 6px 12px; gap: 10px; }
  .tree-page.view-tree .hero h1 { font-size: 22px; white-space: nowrap; }
  .tree-page.view-tree .hero-text p { display: none; }
  .tree-wrap { touch-action: none; }
  #tree { touch-action: none; }
  .hero { padding: 10px 14px 10px; align-items: center; }
  .hero-text p { display: none; }
  .legend { order: 3; width: 100%; gap: 6px 12px; font-size: 12.5px; }
  .tree-page.view-tree .legend { display: none; }
  .view-switch { margin-left: auto; }
  .view-switch button { min-height: 40px; padding: 8px 16px; font-size: 15px; }
  .tree-hint { display: none; }
  .tree-controls button { width: 46px; height: 46px; }

  /* карточка — полноэкранный bottom-sheet */
  .card {
    left: 0 !important; right: 0; top: auto !important; bottom: 0; width: 100%; max-width: 100%;
    height: calc(100dvh - 40px); max-height: none; border-radius: 18px 18px 0 0; border: 0;
    padding: 6px 18px calc(24px + env(safe-area-inset-bottom)); font-size: 17px; overscroll-behavior: contain;
    box-shadow: 0 -6px 30px rgba(40, 25, 10, .3);
  }
  .sheet-grip { display: block; width: 44px; height: 5px; border-radius: 3px; background: #d6c5a6; margin: 4px auto 8px; }
  .card-close { position: sticky; top: 0; float: right; width: 44px; height: 44px; margin: -2px -8px 0 0; background: var(--card); border-radius: 50%; font-size: 32px; z-index: 2; }
  .card h2 { font-size: 28px; }
  .card .role, .card .years { font-size: 16px; }
  .card h4 { font-size: 13px; }
  .card-ava { width: 84px; height: 84px; flex-basis: 84px; }
  .places { font-size: 16px; color: var(--muted); }
  .chips { gap: 8px; }
  .chip { min-height: 44px; font-size: 15.5px; padding: 6px 14px; text-align: left; }
  .facts li { font-size: 17px; padding-bottom: 14px; }
  .facts .src { font-size: 14px; }
  .srcbtn { min-height: 36px; text-align: left; }
  .docs { grid-template-columns: repeat(2, 1fr); gap: 10px; }
  .dtile img, .dtile .noimg { height: 120px; }
  .dtile .cap { font-size: 13px; padding: 6px 8px; }
  .gallery img { width: 96px; height: 96px; }
  .req-list { font-size: 16px; }
  .card-foot { font-size: 16px; }
  .card-foot a { min-height: 44px; display: inline-flex; align-items: center; }
  .living-note { font-size: 16px; }
}

/* пометки «куда смотреть» поверх скана (координаты — доли исходного файла) */
.marks { position: absolute; inset: 0; pointer-events: none; }
.mk { position: absolute; border: calc(2px / var(--zk, 1)) solid rgba(160, 40, 30, .75); background: rgba(160, 40, 30, .06); border-radius: calc(3px / var(--zk, 1)); box-sizing: border-box; }
.mk-label {
  position: absolute; max-width: 62%; margin: calc(10px / var(--zk, 1)) 0; padding: calc(3px / var(--zk, 1)) calc(7px / var(--zk, 1));
  background: rgba(160, 40, 30, .88); color: #fff; font: 600 calc(12px / var(--zk, 1))/1.3 var(--sans); border-radius: calc(4px / var(--zk, 1));
  box-shadow: 0 1px 3px rgba(0,0,0,.25);
}
.mk-label::after { content: ""; position: absolute; border: calc(6px / var(--zk, 1)) solid transparent; }
.mk-label.up::after { top: 100%; border-top-color: rgba(160, 40, 30, .88); }
.mk-label.down::after { bottom: 100%; border-bottom-color: rgba(160, 40, 30, .88); }
.mk-label.l::after { left: calc(10px / var(--zk, 1)); }
.mk-label.r::after { right: calc(10px / var(--zk, 1)); }
body.marks-off .marks { display: none; }
.marks-toggle { font: 600 14px var(--sans); color: var(--accent); background: none; border: 1px solid #d9b7a3; border-radius: 999px; padding: 6px 14px; min-height: 36px; cursor: pointer; }
.lb-links .marks-toggle { color: #f6c8a0; border-color: rgba(246, 200, 160, .5); min-height: 44px; }
.marks-bar { margin: 6px 0 10px; }
.docbig-list { display: flex; flex-direction: column; gap: 10px; }
.docbig { margin: 0; border: 1px solid var(--line); border-radius: 10px; overflow: hidden; background: #fff; cursor: zoom-in; }
.docbig-frame { position: relative; }
.docbig-frame img { display: block; width: 100%; height: auto; }
.docbig figcaption { font: 13px/1.35 var(--sans); color: var(--ink-2); padding: 6px 9px; }
.docbig .mk-label { font-size: 11px; }
.mark-editor { position: relative; display: inline-block; max-width: 100%; touch-action: none; cursor: crosshair; border: 1px solid var(--line); margin: 6px 0 12px; }
.mark-editor img { display: block; max-width: 100%; height: auto; user-select: none; }
.mk.draft { border-style: dashed; }

/* ===== карточка человека на телефоне — отдельная страница ===== */
.badge.archive { background: #f1ebe0; color: #5b4c3d; border: 1px solid #d6c7ad; white-space: normal; }
@media (max-width: 820px), (hover: none) and (pointer: coarse) {
  .card.page { top: 0 !important; height: var(--app-h, 100dvh); max-height: none; border-radius: 0; padding: 0 0 calc(28px + env(safe-area-inset-bottom));
    font: 17px/1.5 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "PT Sans", sans-serif; color: var(--ink); background: #fffaf2; }
  .card.page .sheet-grip, .card.page .card-close { display: none; }
  .pg-bar { position: sticky; top: 0; z-index: 3; display: flex; align-items: center; gap: 10px; padding: calc(6px + env(safe-area-inset-top)) 8px 6px;
    background: rgba(255, 250, 242, .97); border-bottom: 1px solid var(--line); }
  .pg-back { border: 0; background: none; color: var(--accent); font-weight: 600; font-size: 17px; font-family: inherit; min-height: 44px; padding: 0 10px; }
  .pg-bar-name { font-weight: 600; font-size: 16px; color: var(--ink-2); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
  .pg-head { padding: 18px 16px 6px; text-align: left; }
  .pg-ava { width: 88px; height: 88px; border-radius: 50%; object-fit: cover; display: grid; place-items: center; background: #eadbc0; color: #8a6a48;
    font: 700 34px var(--display); border: 3px solid #fff; box-shadow: 0 1px 4px rgba(0,0,0,.15); margin-bottom: 10px; }
  .pg-ava.f { background: #ecd6c9; }
  .pg-head h2 { font: 700 26px/1.2 var(--serif); margin: 0 0 6px; }
  .pg-meta { font-weight: 700; font-size: 17px; color: var(--accent); }
  .pg-role { font-size: 16px; color: var(--ink-2); margin-top: 2px; }
  .pg-badges { margin-top: 10px; }
  .pg-badges .badge { font-size: 15px; padding: 4px 12px; font-family: inherit; }
  .pg-sec { padding: 6px 16px 10px; border-top: 1px solid #efe3cc; margin-top: 10px; }
  .pg-sec h3 { font-weight: 700; font-size: 15px; font-family: inherit; letter-spacing: .05em; text-transform: uppercase; color: var(--accent-2); margin: 12px 0 8px; }
  .pg-text { font-size: 18px; line-height: 1.5; margin: 0; }
  .pg-place { font-size: 16px; color: var(--ink-2); margin: 8px 0 0; }
  .pg-rels { display: flex; flex-direction: column; }
  .pg-rel { display: flex; align-items: center; gap: 12px; min-height: 52px; border: 0; border-bottom: 1px solid #f0e6d3; background: none; padding: 8px 2px; text-align: left; color: var(--ink); font-family: inherit; }
  .pg-rel-k { flex: 0 0 72px; font-size: 15px; color: var(--muted); }
  .pg-rel-n { flex: 1; font-size: 17px; font-weight: 600; display: flex; flex-direction: column; }
  .pg-rel-n small { font-size: 15px; font-weight: 400; color: var(--accent); }
  .pg-go { font-size: 24px; color: #c2ae8d; }
  .pg-sub { font-weight: 700; font-size: 15px; color: var(--ink-2); margin: 14px 0 2px; }
  .pg-docs { display: flex; flex-direction: column; gap: 14px; }
  .pg-doc { margin: 0; border: 1px solid var(--line); border-radius: 12px; overflow: hidden; background: #fff; }
  .pg-doc figcaption { padding: 10px 12px; display: flex; flex-direction: column; gap: 2px; font-size: 16px; }
  .pg-doc figcaption span { font-size: 15px; color: var(--ink-2); }
  .pg-doc .mk-label { font-size: 13px; }
  .pg-doc-ns { padding: 10px 0; border-bottom: 1px solid #f0e6d3; font-size: 16px; display: flex; flex-direction: column; gap: 2px; }
  .pg-doc-ns span { font-size: 15px; color: var(--ink-2); }
  .pg-facts li { font-size: 17px; line-height: 1.5; }
  .pg-facts .src { font-size: 15px; }
  .pg-req { padding-left: 20px; font-size: 16px; margin: 0; }
  .pg-req li { margin-bottom: 8px; }
  .pg-foot { padding: 16px; display: flex; gap: 16px; align-items: center; flex-wrap: wrap; font-size: 16px; }
  .card.page .marks-toggle { font-size: 15px; min-height: 44px; }
}

/* критерий приёмки: на телефоне весь текст ≥ 16px — без зума пальцами */
@media (max-width: 820px), (hover: none) and (pointer: coarse) {
  .topbar nav a, .topbar nav a.btn-small, .view-switch button, .gen-chip, .lr-role, .lg-label, .lg summary,
  .badge, .pg-badges .badge, .pg-sec h3,
  .pg-rel-k, .pg-rel-n small, .pg-sub, .marks-toggle, .lb-cap, .lb-cap *, .lb-links a, .srcbtn, .facts .src,
  .btn, .btn-small, .form label, .form .small, .small, .muted, .meta, .srcitem p, .srcitem a, .srcitem .noimg,
  .req, .pg-doc figcaption span, .pg-doc-ns span, .pg-place, .pg-role, .pg-bar-name, .dtile .cap, .chip, .flash,
  .ladder-loading, .nv-none, .living-note, .oral, .lead { font-size: 16px !important; }
  .srcitem h3 { font-size: 20px; }
  .hero .legend { display: none; }
  .pg-doc .marks .mk-label { display: none; }
  .pg-mk { font-size: 16px; color: #8c2d22; }
  body.marks-off .pg-mk { display: none; }
  .lb-frame .mk-label { font-size: calc(16px / var(--zk, 1)); max-width: 80%; }
}

/* телефон: крупнее меню, текст карточки 18px; в узлах дерева на телефоне подпись роли скрыта (она в карточке) */
@media (max-width: 820px), (hover: none) and (pointer: coarse) {
  .topbar { padding: 8px 12px; }
  .topbar nav { gap: 6px; }
  .topbar nav a, .topbar nav a.btn-small { font-size: 18px !important; min-height: 44px; display: inline-flex; align-items: center; padding: 0 10px; }
  .topbar nav a.btn-small { padding: 0 16px; }
  .brand-mark { width: 40px; height: 40px; font-size: 22px; }
  .view-switch button { font-size: 18px !important; min-height: 44px; }
  .tree-page.view-tree .hero h1 { font-size: 24px; }
  .card.page { font-size: 18px; }
  .pg-text, .pg-facts li, .pg-rel-n, .lr-name { font-size: 18px; }
  .pg-head h2 { font-size: 26px; }
  .node .rl { display: none; }
}
@media (hover: none) and (pointer: coarse) {
  .brand span:last-child { display: none; }
  .topbar nav { flex-wrap: nowrap; }
}

/* мобильная шапка: всегда три пункта — Дерево · Источники · Дополнить */
.btn-back { display: inline-flex; align-items: center; min-height: 44px; padding: 0 16px; border: 1px solid #d9b7a3; border-radius: 999px;
  color: var(--accent); text-decoration: none; font: 700 16px var(--sans); background: var(--card); }
.back-tree { margin: 0 0 8px; }
.topbar nav a[aria-current="page"]:not(.btn-small) { color: var(--accent); font-weight: 700; }
@media (max-width: 820px), (hover: none) and (pointer: coarse) {
  .topbar { padding: 6px 8px; gap: 6px; }
  .brand-mark { width: 40px; height: 40px; flex: 0 0 40px; }
  .topbar nav { gap: 2px; flex-wrap: nowrap; }
  .topbar nav a.nav-item { font-size: 17px !important; min-height: 44px; padding: 0 9px; white-space: nowrap; display: inline-flex; align-items: center; }
  .topbar nav a.nav-item.btn-small { padding: 0 13px; margin-left: 2px; }
  .topbar nav a[aria-current="page"]:not(.btn-small) { box-shadow: inset 0 -3px 0 var(--accent); }
  .topbar .nav-admin { display: none; }
  .btn-back { font-size: 17px; }
}
@media (max-width: 360px) { .topbar nav a.nav-item { font-size: 16px !important; padding: 0 6px; } }
