:root {
  --bg: #f4efe7;
  --surface: #fffdf9;
  --surface-2: #f8f4ec;
  --line: #e7dfd1;
  --text: #2f2a22;
  --muted: #8a7f6f;
  --accent: #5d6d48;
  --accent-dark: #4b5a39;
  --accent-2: #e9ede0;
  --danger: #b4483c;
  --danger-bg: #fbecea;
  --male: #e4e9df;
  --male-ring: #9fae88;
  --female: #f3e6e2;
  --female-ring: #c9a39a;
  --link: #6d7a58;
  --shadow: 0 1px 2px rgba(70, 55, 30, .06), 0 8px 24px rgba(70, 55, 30, .09);
  --radius: 14px;
  --font: 'Lora', Georgia, 'Times New Roman', serif;
}
* { box-sizing: border-box; }
html, body, #app { margin: 0; height: 100%; }
body { font-family: var(--font); background: var(--bg); color: var(--text); font-size: 15px; }
h1, h2, h3 { font-weight: 500; margin: 0; }
.hidden:not(svg *) { display: none !important; }
body.role-viewer .editor-only, body:not(.role-admin) .admin-only { display: none !important; }
.muted { color: var(--muted); }
input, select, textarea, button { font: inherit; color: inherit; }
input, select, textarea {
  width: 100%; padding: 9px 12px; border: 1px solid var(--line); border-radius: 8px;
  background: var(--surface); outline: none; transition: border .15s, box-shadow .15s;
}
input:focus, select:focus, textarea:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-2); }
textarea { min-height: 80px; resize: vertical; }
label { display: flex; flex-direction: column; gap: 5px; font-size: 13px; color: var(--muted); }
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }

.btn {
  border: 1px solid var(--line); border-radius: 10px; padding: 9px 18px; cursor: pointer;
  background: var(--surface-2); transition: background .15s, transform .05s; white-space: nowrap;
  display: inline-flex; align-items: center; gap: 8px; text-decoration: none; justify-content: center;
}
.btn:active { transform: translateY(1px); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.primary:hover { background: var(--accent-dark); }
.btn.ghost { background: var(--surface); }
.btn.ghost:hover { background: var(--surface-2); }
.btn.danger { color: var(--danger); border-color: #efd3ce; background: var(--danger-bg); }
.btn.danger:hover { background: #f7dfdb; }
.btn.small { padding: 6px 12px; font-size: 13px; }
.btn.wide { width: 100%; padding: 12px; }
.btn.pill { border-radius: 30px; box-shadow: var(--shadow); }

/* Login */
.login { min-height: 100%; display: grid; place-items: center; padding: 16px;
  background: url('/tree-bg.svg') center / cover no-repeat, var(--bg); }
.login-card { width: 100%; max-width: 380px; background: var(--surface); padding: 32px 28px; border-radius: 20px; box-shadow: var(--shadow); display: flex; flex-direction: column; gap: 14px; text-align: center; }
.login-card h1 { font-size: 26px; }
.login-card label { text-align: left; }
.login-logo { font-size: 52px; }
.form-error { color: var(--danger); font-size: 14px; min-height: 1em; }
.link-btn { border: 0; background: none; color: var(--accent); cursor: pointer; font-size: 14px; padding: 4px; text-decoration: underline; text-underline-offset: 3px; }
.alt-form { display: flex; flex-direction: column; gap: 14px; }
.alt-form h1, #auth-alt h1 { font-size: 24px; }
#auth-alt p { margin: 0; line-height: 1.5; }
#auth-alt { gap: 14px; }

/* invitations */
.access-line { font-size: 13px; padding: 9px 12px; border-radius: 10px; background: var(--surface-2); border: 1px solid var(--line); color: var(--muted); }
.access-line.ok { background: var(--accent-2); color: var(--accent-dark); border-color: #d5dcc6; }
.access-btns { display: flex; gap: 8px; margin-top: 8px; }
.access-btns .btn { flex: 1; }
.inv-who { display: flex; gap: 12px; align-items: center; }
.inv-who .fc-photo { width: 52px; height: 52px; font-size: 16px; }
.sub-h { font-size: 17px; margin: 18px 0 10px; }

/* Topbar */
.topbar { height: 64px; display: flex; align-items: center; gap: 16px; padding: 0 20px; background: var(--surface); border-bottom: 1px solid var(--line); position: relative; z-index: 20; }
.brand { display: flex; align-items: center; gap: 10px; font-size: 19px; font-weight: 500; min-width: 0; }
.brand-icon { font-size: 26px; }
.tabs { display: flex; gap: 6px; flex: 1; justify-content: center; overflow-x: auto; height: 100%; }
.tabs button { border: 0; background: none; padding: 0 16px; cursor: pointer; color: var(--muted); height: 100%; border-bottom: 3px solid transparent; display: flex; align-items: center; gap: 7px; white-space: nowrap; }
.tabs button:hover { color: var(--text); }
.tabs button.active { color: var(--text); border-bottom-color: var(--accent); }
.tabs .ti { color: var(--accent); font-size: 17px; }
.user-menu { position: relative; }
.user-menu .btn { border: 0; background: none; }
.avatar-sm { width: 32px; height: 32px; border-radius: 50%; background: var(--accent-2); color: var(--accent); border: 1px solid var(--line); display: grid; place-items: center; font-size: 14px; font-weight: 600; flex: none; }
.dropdown { position: absolute; right: 0; top: 50px; background: var(--surface); border: 1px solid var(--line); border-radius: 12px; box-shadow: var(--shadow); min-width: 280px; padding: 6px; display: flex; flex-direction: column; }
.dropdown-head { padding: 10px 12px; display: flex; flex-direction: column; gap: 2px; border-bottom: 1px solid var(--line); margin-bottom: 4px; }
.dropdown button, .dropdown a { text-align: left; border: 0; background: none; padding: 10px 12px; border-radius: 8px; cursor: pointer; text-decoration: none; color: var(--text); font-size: 14px; }
.dropdown button:hover, .dropdown a:hover { background: var(--surface-2); }

main { height: calc(100% - 64px); position: relative; }
.view { height: 100%; position: relative; }
.page { max-width: 1100px; margin: 0 auto; padding: 28px 16px 60px; height: 100%; overflow-y: auto; }
.page-head { display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap; margin-bottom: 18px; }
.page-head h2 { font-size: 24px; }
.page-head input { width: 300px; }
.count { color: var(--muted); font-size: 18px; }

/* Tree */
#chart.f3 {
  --background-color: transparent; --text-color: var(--text);
  width: 100%; height: 100%; font-family: var(--font);
  background: url('/tree-bg.svg') center / cover no-repeat, var(--bg);
}
.f3 path.link { stroke: var(--link) !important; stroke-width: 1.4px; }
.f3 div.card-inner, .f3 div.card-female .card-inner, .f3 div.card-male .card-inner { background: none !important; box-shadow: none !important; outline: none !important; }
.fc-card {
  width: 230px; min-height: 92px; display: flex; gap: 12px; align-items: center; padding: 12px 14px;
  background: var(--surface); border-radius: 12px; border: 1px solid var(--line);
  box-shadow: var(--shadow); text-align: left; transition: box-shadow .2s, border-color .2s;
}
.card:hover .fc-card { box-shadow: 0 10px 28px rgba(70, 55, 30, .18); }
.card-main .fc-card { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-2), var(--shadow); }
.fc-photo { width: 64px; height: 64px; border-radius: 50%; flex: none; object-fit: cover; display: grid; place-items: center; font-size: 20px; color: var(--accent); background: var(--male); border: 2px solid var(--male-ring); }
.fc-card.F .fc-photo { background: var(--female); color: #9a6a60; border-color: var(--female-ring); }
.fc-text { min-width: 0; line-height: 1.3; }
.fc-name { font-weight: 500; font-size: 14.5px; }
.fc-last { font-size: 14px; color: #5a5245; }
.fc-maiden { font-size: 12px; color: var(--muted); font-style: italic; }
.fc-years { font-size: 13px; color: var(--muted); margin-top: 2px; }
.fc-card.deceased .fc-photo { filter: grayscale(.6) sepia(.25); }
/* participant of the Great Patriotic War: small red star in the top-left corner */
.fc-card { position: relative; }
.ww2-star { width: 1em; height: 1em; fill: #c62828; stroke: #8e1b1b; stroke-width: .8; stroke-linejoin: round; vertical-align: -.12em; }
.fc-ww2 { position: absolute; top: 6px; left: 8px; font-size: 14px; line-height: 0; filter: drop-shadow(0 1px 1px rgba(120, 20, 20, .25)); }
.ww2-fact .ww2-star, .ww2-inline .ww2-star { font-size: 14px; }
.install-help h4 { margin: 14px 0 4px; }
.install-help ol { margin: 0; padding-left: 22px; line-height: 1.6; }

.tree-toolbar { position: absolute; top: 16px; left: 16px; right: 16px; display: flex; gap: 10px; justify-content: space-between; pointer-events: none; z-index: 5; }
.tree-toolbar > * { pointer-events: auto; }
.search-box { position: relative; width: 320px; max-width: 100%; margin-right: auto; }
.nav-btns { display: flex; gap: 8px; }
.mode-seg { box-shadow: var(--shadow); background: var(--surface); align-self: flex-start; }
.mode-seg button { padding: 8px 14px; }

/* Full tree */
#full-tree { position: absolute; inset: 0; overflow: hidden; cursor: grab; background: url('/tree-bg.svg') center / cover no-repeat, var(--bg); }
#full-tree:active { cursor: grabbing; }
#full-inner { position: absolute; left: 0; top: 0; transform-origin: 0 0; }
#full-inner svg { position: absolute; left: 0; top: 0; overflow: visible; pointer-events: none; }
#full-inner .ft-edge { fill: none; stroke: var(--link); stroke-width: 1.4px; }
#full-inner .ft-union { fill: var(--accent); }
#full-inner .ft-node { position: absolute; cursor: pointer; }
#full-inner .ft-node .fc-card { width: 230px; }
#full-inner .ft-node:hover .fc-card { box-shadow: 0 10px 28px rgba(70, 55, 30, .18); }
#full-inner .ft-node.home .fc-card { border-color: var(--accent); }
#full-inner .ft-node.home .fc-card::after { content: '⌂'; position: absolute; top: 6px; right: 10px; color: var(--accent); }
#full-inner .ft-node.sel .fc-card { border-color: var(--accent); box-shadow: 0 0 0 4px var(--accent-2), var(--shadow); }
#full-inner .fc-card { position: relative; }
.nav-btns .btn { padding: 9px 16px; }
.nav-btns .btn:disabled { opacity: .45; cursor: default; }
.search-box input { box-shadow: var(--shadow); border-color: var(--line); border-radius: 30px; padding: 10px 18px; }
.suggest { position: absolute; top: 46px; left: 0; right: 0; background: var(--surface); border: 1px solid var(--line); border-radius: 12px; box-shadow: var(--shadow); max-height: 320px; overflow-y: auto; padding: 4px; z-index: 10; }
.suggest div { padding: 9px 12px; border-radius: 8px; cursor: pointer; display: flex; justify-content: space-between; gap: 8px; }
.suggest div:hover, .suggest div.active { background: var(--surface-2); }
.suggest small { color: var(--muted); }
.zoom-ctrl { position: absolute; left: 16px; top: 50%; transform: translateY(-50%); display: flex; flex-direction: column; background: var(--surface); border: 1px solid var(--line); border-radius: 12px; box-shadow: var(--shadow); overflow: hidden; z-index: 5; }
.zoom-ctrl button { width: 42px; height: 42px; border: 0; background: none; cursor: pointer; font-size: 20px; color: #5a5245; }
.zoom-ctrl button + button { border-top: 1px solid var(--line); }
.zoom-ctrl button:hover { background: var(--surface-2); }
.stats-box { position: absolute; right: 16px; top: 72px; background: var(--surface); border: 1px solid var(--line); border-radius: 12px; box-shadow: var(--shadow); padding: 14px 18px; display: flex; flex-direction: column; gap: 12px; z-index: 4; font-size: 13px; }
.stat { display: flex; gap: 12px; align-items: center; }
.stat b { font-size: 20px; font-weight: 500; }
.stat-icon { color: var(--accent); font-size: 20px; width: 24px; text-align: center; }
.tree-hint { position: absolute; bottom: 14px; left: 50%; transform: translateX(-50%); font-size: 12px; background: rgba(255,253,249,.8); padding: 5px 14px; border-radius: 20px; white-space: nowrap; }
.empty-state { position: absolute; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; text-align: center; gap: 10px; padding: 16px; }
.empty-icon { font-size: 56px; }

/* Person panel */
.panel { position: absolute; top: 0; right: 0; bottom: 0; width: 410px; max-width: 100%; background: var(--surface); border-left: 1px solid var(--line); box-shadow: -8px 0 30px rgba(70,55,30,.1); overflow-y: auto; z-index: 10; animation: slide .2s ease-out; }
@keyframes slide { from { transform: translateX(30px); opacity: 0; } }
.panel-title { padding: 18px 22px 0; font-size: 18px; display: flex; justify-content: space-between; align-items: center; }
.panel-head { padding: 18px 22px; display: flex; gap: 18px; align-items: center; }
.panel-photo { width: 110px; height: 110px; border-radius: 50%; flex: none; display: grid; place-items: center; font-size: 34px; background: var(--male); color: var(--accent); border: 3px solid var(--male-ring); position: relative; overflow: hidden; }
.panel-photo.F { background: var(--female); color: #9a6a60; border-color: var(--female-ring); }
.panel-photo img { width: 100%; height: 100%; object-fit: cover; }
.panel-photo .photo-edit { position: absolute; inset: auto 0 0 0; background: rgba(40,30,20,.55); color: #fff; font-size: 11px; text-align: center; padding: 5px 0 8px; cursor: pointer; opacity: 0; transition: opacity .15s; display: block; }
.panel-photo:hover .photo-edit { opacity: 1; }
.panel-head h2 { font-size: 21px; line-height: 1.25; }
.panel-head .sub { font-size: 14px; color: var(--muted); margin-top: 4px; }
.panel-close { border: 0; background: none; font-size: 20px; cursor: pointer; color: var(--muted); width: 36px; height: 36px; border-radius: 50%; }
.panel-close:hover { background: var(--surface-2); }
.panel-actions { padding: 0 22px 18px; display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.panel-actions .full { grid-column: 1 / -1; }
.panel-section { padding: 16px 22px; border-top: 1px solid var(--line); }
.panel-section h4 { margin: 0 0 10px; font-size: 16px; font-weight: 500; }
.panel-section .sublabel { margin: 12px 0 6px; font-size: 13px; color: var(--muted); }
.panel-section .sublabel:first-of-type { margin-top: 0; }
.facts { display: grid; grid-template-columns: 110px 1fr; gap: 8px 12px; font-size: 14px; margin: 0; }
.facts dt { color: var(--muted); }
.facts dd { margin: 0; }
.bio { white-space: pre-wrap; font-size: 14px; line-height: 1.6; }
.rel-list { display: flex; flex-wrap: wrap; gap: 10px; }
.rel { display: flex; flex-direction: column; align-items: center; gap: 4px; width: 78px; cursor: pointer; text-align: center; font-size: 12px; line-height: 1.25; position: relative; }
.rel .fc-photo { width: 56px; height: 56px; font-size: 17px; transition: transform .15s; }
.rel:hover .fc-photo { transform: scale(1.06); }
.rel.F .fc-photo { background: var(--female); color: #9a6a60; border-color: var(--female-ring); }
.rel .x { position: absolute; top: -4px; right: 6px; width: 20px; height: 20px; border-radius: 50%; background: var(--surface); border: 1px solid var(--line); color: var(--muted); font-size: 11px; display: grid; place-items: center; }
.rel .x:hover { color: var(--danger); border-color: var(--danger); }
.add-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.add-grid button { border: 1px dashed #d6ccb9; background: var(--surface-2); border-radius: 10px; padding: 10px 4px; cursor: pointer; font-size: 13px; }
.add-grid button:hover:not(:disabled) { border-color: var(--accent); color: var(--accent); background: var(--accent-2); }
.add-grid button:disabled { opacity: .45; cursor: not-allowed; }

/* People */
.people-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 14px; }
.people-grid .fc-card { width: auto; cursor: pointer; }
.people-grid .fc-card:hover { border-color: var(--accent); }

/* History */
.hist-filters select { width: auto; min-width: 200px; }
@media (max-width: 860px) { .hist-filters, .hist-filters > * { width: 100% !important; } }
.history { display: flex; flex-direction: column; gap: 8px; }
.h-item { background: var(--surface); border: 1px solid var(--line); border-radius: 12px; padding: 12px 14px; display: flex; gap: 12px; align-items: flex-start; }
.h-icon { width: 34px; height: 34px; border-radius: 50%; display: grid; place-items: center; flex: none; background: var(--accent-2); }
.h-body { flex: 1; min-width: 0; }
.h-meta { font-size: 12px; color: var(--muted); margin-top: 2px; }
.h-diff { font-size: 13px; margin-top: 6px; color: var(--muted); }
.h-diff b { color: var(--text); font-weight: 500; }
.h-item.reverted { opacity: .55; }
.h-item.reverted .h-summary { text-decoration: line-through; }

/* Users */
.roles-info { display: flex; gap: 8px 24px; flex-wrap: wrap; font-size: 14px; color: var(--muted); margin-bottom: 16px; }
.card-box { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 20px; }
.user-form { display: flex; flex-direction: column; gap: 12px; margin-bottom: 20px; }
.user-form h3 { font-size: 18px; }
.grid-4 { display: grid; grid-template-columns: repeat(4, 1fr); gap: 10px; }
.u-item { background: var(--surface); border: 1px solid var(--line); border-radius: 12px; padding: 12px 14px; display: flex; align-items: center; gap: 12px; margin-bottom: 8px; flex-wrap: wrap; }
.u-item .grow { flex: 1; min-width: 160px; }
.u-item select { width: auto; }
.badge { font-size: 11px; padding: 2px 8px; border-radius: 10px; background: var(--accent-2); color: var(--accent); margin-left: 6px; }
.keybox { font-family: ui-monospace, monospace; background: var(--surface-2); border: 1px solid var(--line); padding: 12px; border-radius: 8px; word-break: break-all; font-size: 13px; }

/* System */
.sys-stats { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 10px; margin-bottom: 14px; }
.sys-stats > div { background: var(--surface); border: 1px solid var(--line); border-radius: 12px; padding: 12px 14px; }
.sys-stats b { display: block; font-size: 20px; font-weight: 500; }
.sys-stats .bad { color: var(--danger); }
.bk-list { background: var(--surface); border: 1px solid var(--line); border-radius: 12px; overflow: hidden; }
.bk-row { display: flex; gap: 12px; align-items: center; padding: 10px 14px; border-top: 1px solid var(--line); flex-wrap: wrap; font-size: 14px; }
.bk-row:first-child { border-top: 0; }
.bk-row .grow { flex: 1; min-width: 180px; }

/* Modal */
.modal-bg { position: fixed; inset: 0; background: rgba(47, 42, 34, .45); display: grid; place-items: center; z-index: 100; padding: 16px; animation: fade .15s; }
@keyframes fade { from { opacity: 0; } }
.modal { background: var(--surface); border-radius: 18px; width: 100%; max-width: 660px; max-height: calc(100vh - 32px); overflow-y: auto; box-shadow: 0 20px 60px rgba(0,0,0,.25); }
.modal.small { max-width: 450px; }
.del-confirm .del-who { padding: 10px 14px; border-radius: 10px; background: var(--danger-bg); color: var(--danger); font-weight: 600; font-size: 17px; }
.del-confirm .del-label { margin: 14px 0 4px; font-size: 13px; color: var(--muted); }
.del-confirm ul { margin: 0 0 10px; padding-left: 20px; line-height: 1.5; }
.del-confirm .muted { margin: 0 0 14px; font-size: 13px; }
.del-check { flex-direction: row; align-items: center; gap: 8px; font-size: 14px; color: inherit; cursor: pointer; }
.del-check input { width: 18px; height: 18px; accent-color: var(--danger); }
#dl-yes:disabled { opacity: .45; cursor: not-allowed; }
.del-note { width: 100%; margin: 4px 0 0; font-size: 12px; }
.modal-head { padding: 22px 24px 8px; }
.modal-head h2 { font-size: 21px; }
.modal-body { padding: 8px 24px; display: flex; flex-direction: column; gap: 14px; }
.modal-foot { padding: 16px 24px 20px; display: flex; gap: 10px; justify-content: flex-end; flex-wrap: wrap; position: sticky; bottom: 0; background: var(--surface); border-top: 1px solid var(--line); }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.fieldset-title { font-size: 15px; color: var(--text); margin-top: 6px; border-bottom: 1px solid var(--line); padding-bottom: 6px; }
.seg { display: inline-flex; background: var(--surface-2); border: 1px solid var(--line); border-radius: 10px; padding: 3px; }
.seg button { border: 0; background: none; padding: 7px 18px; border-radius: 8px; cursor: pointer; }
.seg button.on { background: var(--accent); color: #fff; }
.check { flex-direction: row; align-items: center; gap: 8px; color: var(--text); font-size: 14px; cursor: pointer; }
.check input { width: auto; accent-color: var(--accent); }
.hint { font-size: 12px; color: var(--muted); font-style: italic; }
.combo { position: relative; }
.combo .suggest { top: 42px; }
.combo-clear { position: absolute; right: 8px; top: 8px; border: 0; background: none; cursor: pointer; color: var(--muted); font-size: 15px; }

.toast { position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%); background: var(--text); color: #fff; padding: 12px 20px; border-radius: 12px; z-index: 200; box-shadow: var(--shadow); max-width: calc(100% - 32px); }
.toast.err { background: var(--danger); }

@media (max-width: 860px) {
  .brand-text, .hide-sm, .tree-hint, .stats-box { display: none; }
  .topbar { gap: 6px; padding: 0 10px; }
  .tabs { justify-content: flex-start; }
  .tabs button { padding: 0 10px; }
  .tabs .ti { display: none; }
  .panel { top: auto; height: 78%; width: 100%; border-left: 0; border-top: 1px solid var(--line); border-radius: 20px 20px 0 0; }
  .tree-toolbar { flex-direction: column; }
  .tree-toolbar .btn { align-self: flex-start; }
  .zoom-ctrl { top: auto; bottom: 16px; transform: none; }
  .grid-2, .grid-4 { grid-template-columns: 1fr; }
  .page-head input { width: 100%; }
  .facts { grid-template-columns: 95px 1fr; }
}

/* ---------- touch screens: no hover, bigger targets ---------- */
@media (hover: none) {
  .panel-photo .photo-edit { opacity: 1; }
  .rel .x { width: 28px; height: 28px; top: -8px; right: 2px; font-size: 13px; }
  .add-grid button { padding: 12px 4px; }
}

/* ---------- phones ---------- */
@media (max-width: 640px) {
  :root { --nav-h: calc(58px + env(safe-area-inset-bottom)); }
  #app { height: 100dvh; }
  body { -webkit-tap-highlight-color: transparent; }
  /* no zoom-in on focus in iOS Safari */
  input, select, textarea { font-size: 16px; }

  /* top bar: logo + user only; tabs become a bottom navigation */
  .topbar { height: 52px; padding: 0 12px; padding-top: env(safe-area-inset-top); height: calc(52px + env(safe-area-inset-top)); justify-content: space-between; }
  .brand-text { display: inline; font-size: 17px; }
  main { height: calc(100% - 52px - env(safe-area-inset-top) - var(--nav-h)); }
  .tabs {
    position: fixed; left: 0; right: 0; bottom: 0; height: var(--nav-h); padding-bottom: env(safe-area-inset-bottom);
    background: var(--surface); border-top: 1px solid var(--line); box-shadow: 0 -4px 16px rgba(70,55,30,.06);
    gap: 0; justify-content: space-around; overflow: visible; z-index: 40;
  }
  .tabs button { flex: 1; flex-direction: column; justify-content: center; gap: 1px; padding: 0; font-size: 12px; border-bottom: 0; border-top: 3px solid transparent; }
  .tabs button.active { border-top-color: var(--accent); color: var(--accent); }
  .tabs .ti { display: block; font-size: 21px; line-height: 1.1; }
  .user-menu .btn { padding: 6px; }
  .dropdown { position: fixed; top: calc(52px + env(safe-area-inset-top)); right: 8px; left: 8px; min-width: 0; }
  .dropdown button, .dropdown a { padding: 13px 12px; font-size: 15px; }

  /* tree toolbar: [←][⌂][Ветка|Всё древо] / [search]; add = floating button */
  .tree-toolbar { top: 10px; left: 10px; right: 10px; flex-direction: row; flex-wrap: wrap; gap: 8px; justify-content: flex-start; }
  .tree-toolbar .lbl { display: none; }
  .nav-btns { gap: 6px; }
  .nav-btns .btn { width: 42px; height: 42px; padding: 0; font-size: 18px; }
  .nav-btns .btn:disabled { opacity: 1; color: #cfc6b6; }
  .mode-seg { margin-left: auto; }
  .mode-seg button { padding: 9px 12px; }
  .search-box { flex: 1 1 100%; width: 100%; margin: 0; }
  .search-box input { padding: 10px 16px; }
  #btn-add-person {
    position: fixed; right: 16px; bottom: calc(var(--nav-h) + 16px); width: 56px; height: 56px; padding: 0; border-radius: 50%;
    font-size: 30px; line-height: 1; box-shadow: 0 6px 18px rgba(75,90,57,.4); z-index: 6;
  }
  .zoom-ctrl { left: 10px; bottom: 16px; }
  .zoom-ctrl button { width: 44px; height: 44px; }

  /* person panel = bottom sheet */
  .panel { height: 85%; z-index: 30; box-shadow: 0 -8px 30px rgba(70,55,30,.18); }
  .panel::before { content: ''; display: block; width: 40px; height: 4px; border-radius: 2px; background: var(--line); margin: 8px auto 0; }
  .panel-title { padding: 6px 14px 0 18px; }
  .panel-head { padding: 12px 18px; gap: 14px; }
  .panel-photo { width: 84px; height: 84px; font-size: 28px; }
  .panel-head h2 { font-size: 19px; }
  .panel-actions { padding: 0 18px 14px; }
  .panel-actions .btn { padding: 11px 10px; }
  .panel-section { padding: 14px 18px; }
  .panel .rel-list { gap: 8px 4px; }
  .rel { width: 74px; }

  /* pages */
  .page { padding: 18px 12px 32px; }
  .page-head h2 { font-size: 21px; }
  .page-head .row { width: 100%; flex-wrap: nowrap; }
  .people-grid { grid-template-columns: 1fr; gap: 10px; }
  .people-grid .fc-card { min-height: 80px; padding: 10px 12px; }
  .people-grid .fc-photo { width: 54px; height: 54px; }
  .hist-filters .combo { width: 100% !important; }
  .card-box { padding: 16px; }
  .u-item .btn { flex: 1 1 auto; }

  /* dialogs slide up from the bottom */
  .modal-bg { padding: 0; place-items: end stretch; }
  .modal, .modal.small { max-width: none; max-height: 92dvh; border-radius: 18px 18px 0 0; animation: sheet .2s ease-out; }
  @keyframes sheet { from { transform: translateY(40px); opacity: 0; } }
  .modal-head { padding: 18px 18px 6px; }
  .modal-body { padding: 8px 18px; }
  .modal-foot { padding: 12px 18px calc(14px + env(safe-area-inset-bottom)); flex-wrap: nowrap; }
  .modal-foot .btn { flex: 1; padding: 12px 10px; white-space: normal; }

  .toast { bottom: calc(var(--nav-h) + 14px); }
}

/* ---------- help, welcome, tour (help.js) ---------- */
.user-menu { display: flex; align-items: center; gap: 4px; }
.user-menu .help-btn { width: 36px; height: 36px; padding: 0; border-radius: 50%; border: 1px solid var(--line); background: var(--accent-2); color: var(--accent-dark); font-weight: 700; font-size: 17px; }
.user-menu .help-btn:hover { background: var(--accent); color: #fff; }
.help { font-size: 15px; line-height: 1.55; }
.help p { margin: 0; }
.help h3 { font-size: 18px; margin-top: 10px; padding-top: 14px; border-top: 1px solid var(--line); }
.help-lead { font-size: 17px; }
.help-author { display: flex; gap: 14px; align-items: center; padding: 14px 16px; border-radius: 12px; background: var(--accent-2); border: 1px solid #d5dcc6; }
.help-author-icon { font-size: 30px; flex: none; }
.help-rules { display: flex; flex-direction: column; gap: 10px; }
.help-rule { display: flex; gap: 12px; align-items: flex-start; padding: 10px 12px; border-radius: 12px; background: var(--surface-2); border: 1px solid var(--line); }
.help-rule-icon { font-size: 20px; width: 28px; text-align: center; flex: none; }
.help-rule b { display: block; margin-bottom: 2px; }
.help-faq { display: flex; flex-direction: column; gap: 8px; }
.help-faq details { border: 1px solid var(--line); border-radius: 12px; background: var(--surface); }
.help-faq summary { cursor: pointer; padding: 12px 14px; list-style: none; display: flex; justify-content: space-between; gap: 10px; }
.help-faq summary::-webkit-details-marker { display: none; }
.help-faq summary::after { content: '+'; color: var(--accent); font-size: 20px; line-height: 1; }
.help-faq details[open] summary::after { content: '−'; }
.help-faq details[open] summary { color: var(--accent-dark); }
.help-faq details p { padding: 0 14px 14px; }
.help-tour-cta { display: flex; align-items: center; gap: 14px; width: 100%; text-align: left; font: inherit; color: inherit; cursor: pointer; padding: 14px 16px; border-radius: 14px; border: 1px solid var(--accent); background: var(--accent-2); }
.help-tour-cta > span:first-child { font-size: 26px; }
.help-tour-cta > div { flex: 1; }
.help-tour-cta:hover { background: #dfe6d3; }
a.help-tour-cta { text-decoration: none; }
.welcome-dots { display: flex; gap: 6px; margin-bottom: 12px; }
.welcome-dots span { width: 8px; height: 8px; border-radius: 4px; background: var(--line); transition: width .2s; }
.welcome-dots span.on { width: 24px; background: var(--accent); }

.tour { position: fixed; inset: 0; z-index: 150; }
.tour-block { position: absolute; inset: 0; } /* catches clicks so the page is not changed mid-tour */
.tour-hole { position: absolute; border-radius: 12px; box-shadow: 0 0 0 3px var(--accent), 0 0 0 9999px rgba(47, 42, 34, .55); transition: all .25s ease; pointer-events: none; }
.tour-tip { position: absolute; background: var(--surface); border-radius: 16px; padding: 16px 18px; box-shadow: 0 20px 60px rgba(0,0,0,.3); transition: top .25s ease, left .25s ease; }
.tour-tip h3 { font-size: 18px; margin: 2px 0 6px; }
.tour-tip p { margin: 0 0 14px; line-height: 1.5; }
.tour-count { font-size: 12px; color: var(--muted); }
.tour-btns { display: flex; justify-content: space-between; align-items: center; gap: 8px; }
.tour-btns span { display: flex; gap: 8px; }
@media (max-width: 640px) {
  .user-menu .help-btn { width: 34px; height: 34px; }
  .help-author { align-items: flex-start; }
}

/* ---------- login captcha ---------- */
.captcha { display: flex; flex-direction: column; gap: 10px; padding: 12px; border-radius: 12px; background: var(--surface-2); border: 1px solid var(--line); text-align: left; font-size: 14px; line-height: 1.45; }
.captcha-row { display: flex; gap: 8px; align-items: stretch; }
.captcha-row img { flex: 1; min-width: 0; width: 100%; height: auto; aspect-ratio: 200 / 70; border-radius: 8px; border: 1px solid var(--line); background: #fffdf9; }
.captcha-row .btn { padding: 0 14px; font-size: 20px; }
.captcha input { font-size: 22px; letter-spacing: 8px; text-align: center; }
.captcha input::placeholder { letter-spacing: normal; font-size: 16px; }

/* ---------- print / save dialog (print.js) ---------- */
.pr-row { display: flex; flex-wrap: wrap; align-items: center; gap: 10px; }
.pr-lbl { min-width: 120px; font-weight: 500; }
.pr-seg { display: inline-flex; }
.pr-opt { display: grid; grid-template-columns: auto 1fr auto; gap: 14px; align-items: center; padding: 14px 16px; border: 1px solid var(--line); border-radius: 14px; background: var(--surface); }
.pr-opt .muted { font-size: 14px; margin-top: 2px; }
.pr-opt .pr-row { margin-top: 10px; }
.pr-icon { font-size: 28px; }
.pr-count { margin-top: 8px; font-size: 14px; color: var(--accent-dark); }
@media (max-width: 640px) {
  .pr-opt { grid-template-columns: auto 1fr; }
  .pr-opt > .btn { grid-column: 1 / -1; }
}

/* ---------- what is printed: only #print-root while body.printing ---------- */
#print-root { display: none; }
@media print {
  html, body { height: auto !important; overflow: visible !important; background: #fff !important; }
  body.printing > *:not(#print-root) { display: none !important; }
  body.printing #print-root { display: block; }
  #print-root { font-family: var(--font); color: #2f2a22; -webkit-print-color-adjust: exact; print-color-adjust: exact; }
  .pr-sheet, .pr-tile { break-after: page; overflow: hidden; }
  .pr-sheet:last-child, .pr-tile:last-child { break-after: auto; }
  .pr-sheet svg { display: block; }
  .pr-foot { font-size: 8pt; color: #8a7f6f; text-align: right; padding-top: 1mm; }

  /* family book */
  .pb { font-size: 10.5pt; line-height: 1.45; }
  .pb-cover { height: 250mm; display: flex; flex-direction: column; justify-content: center; align-items: center; text-align: center; gap: 6mm; break-after: page; }
  .pb-cover h1 { font-size: 34pt; font-weight: 500; }
  .pb-tree-icon { font-size: 60pt; }
  .pb-lead { font-size: 16pt; }
  .pb-note { max-width: 120mm; color: #8a7f6f; font-size: 10pt; margin-top: 10mm; }
  .pb-tree { height: 255mm; break-after: page; display: flex; align-items: center; }
  .pb-tree svg { width: 100%; height: 100%; }
  .pb-person { display: grid; grid-template-columns: 26mm 1fr; gap: 6mm; padding: 5mm 0; border-bottom: 0.3mm solid #e7dfd1; break-inside: avoid; }
  .pb-photo { width: 24mm; height: 24mm; border-radius: 50%; overflow: hidden; display: grid; place-items: center; font-size: 16pt; background: #e4e9df; color: #5d6d48; border: 0.6mm solid #9fae88; }
  .pb-photo.F { background: #f3e6e2; color: #9a6a60; border-color: #c9a39a; }
  .pb-photo img { width: 100%; height: 100%; object-fit: cover; }
  .pb-main h3 { font-size: 14pt; font-weight: 600; margin: 0 0 1mm; }
  .pb-num { color: #5d6d48; font-weight: 400; font-size: 11pt; margin-right: 2mm; }
  .pb-sub { color: #8a7f6f; margin-bottom: 1mm; }
  .pb dl { display: grid; grid-template-columns: 26mm 1fr; gap: 1mm 4mm; margin: 2mm 0 0; }
  .pb dt { color: #8a7f6f; }
  .pb dd { margin: 0; }
  .pb-ref { color: #5d6d48; white-space: nowrap; }
  .pb-label { color: #8a7f6f; margin-top: 3mm; }
  .pb-text { white-space: pre-wrap; }
  .pb-src { font-size: 9.5pt; }
}
.pw-row { display: flex; gap: 6px; align-items: stretch; }
.pw-row input { flex: 1; min-width: 0; font-family: ui-monospace, Consolas, monospace; }
