:root {
  --bg: #f5f2ec; --surface: #fff; --ink: #1f2a26; --muted: #6c7a74; --line: #e2dcd0;
  --primary: #2f5d50; --primary-dark: #244a40; --accent: #b8862f; --danger: #b3261e;
  --m: #3f7fc0; --m-bg: #e8f1fa; --f: #c9567f; --f-bg: #fbe9ef; --u: #8a8f8c; --u-bg: #eeeeea;
  --radius: 12px; --shadow: 0 1px 2px rgba(31, 42, 38, .06), 0 4px 16px rgba(31, 42, 38, .06);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; color: var(--ink);
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body { background: var(--bg); font-size: 15px; line-height: 1.5; display: flex; flex-direction: column; }
h1, h2, h3 { font-family: Georgia, "Times New Roman", serif; font-weight: 600; line-height: 1.25; margin: 0 0 .6em; }
h1 { font-size: 1.7rem; } h2 { font-size: 1.15rem; } h3 { font-size: .95rem; margin-top: 1.2em; color: var(--primary-dark); }
h1 small, h3 small { font-family: system-ui, sans-serif; font-weight: 400; font-size: .7em; }
a { color: var(--primary); text-decoration: none; } a:hover { text-decoration: underline; }
[hidden] { display: none !important; }
.muted { color: var(--muted); } .small { font-size: .85rem; } .nowrap { white-space: nowrap; }

/* top bar */
.top { display: flex; align-items: center; gap: 18px; padding: 0 20px; height: 56px; background: var(--primary);
  color: #fff; flex: none; }
.top a { color: #fff; }
.brand { display: flex; align-items: center; gap: 10px; font-family: Georgia, serif; font-size: 1.1rem; font-weight: 600;
  white-space: nowrap; }
.brand:hover { text-decoration: none; }
.main-nav { display: flex; gap: 2px; height: 100%; }
.main-nav a { display: flex; align-items: center; padding: 0 13px; opacity: .82; border-bottom: 3px solid transparent;
  border-top: 3px solid transparent; }
.main-nav a:hover { opacity: 1; text-decoration: none; }
.main-nav a.on { opacity: 1; border-bottom-color: #e3b860; }
.search { margin-left: auto; }
.search input { width: 200px; padding: 7px 12px; border-radius: 999px; border: 0; background: rgba(255, 255, 255, .16);
  color: #fff; font: inherit; }
.search input::placeholder { color: rgba(255, 255, 255, .7); }
.search input:focus { outline: 2px solid #e3b860; background: rgba(255, 255, 255, .24); }
.user { display: flex; align-items: center; gap: 12px; white-space: nowrap; font-size: .9rem; }
.user form { margin: 0; } .user .link { color: #fff; opacity: .8; }
.sub-nav { display: flex; gap: 4px; padding: 0 20px; background: #fff; border-bottom: 1px solid var(--line); flex: none;
  overflow-x: auto; }
.sub-nav a { padding: 11px 12px; color: var(--muted); border-bottom: 2px solid transparent; white-space: nowrap; }
.sub-nav a.on { color: var(--primary); border-bottom-color: var(--primary); font-weight: 600; }

.page { width: 100%; max-width: 1180px; margin: 0 auto; padding: 26px 20px 60px; }
.center { flex: 1; display: grid; place-items: center; padding: 24px; }
.page-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; }

.flashes { max-width: 1180px; width: 100%; margin: 14px auto 0; padding: 0 20px; }
.flash { padding: 10px 14px; border-radius: 10px; background: #e7f2ec; border: 1px solid #b9d8c8; margin-bottom: 8px; }
.flash.error { background: #fbeaea; border-color: #eab8b5; color: #7a1b16; }
.notice { padding: 12px 16px; border-radius: 10px; background: #fff7e0; border: 1px solid #ecd9a0; margin: 0 0 18px; }
.notice.warn { background: #fbeaea; border-color: #eab8b5; }

/* cards, buttons, forms */
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow);
  padding: 20px 22px; margin: 0 0 18px; }
main .card.narrow { max-width: 560px; }
.card.highlight { border-color: var(--accent); background: #fffaf0; }
.auth { width: 100%; max-width: 400px; text-align: center; padding: 32px 30px; }
.auth .field { text-align: left; }
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; padding: 8px 16px; border-radius: 9px;
  border: 1px solid var(--line); background: #fff; color: var(--ink); font: inherit; font-weight: 600; cursor: pointer;
  white-space: nowrap; }
.btn:hover { border-color: var(--primary); text-decoration: none; }
.btn.primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn.primary:hover { background: var(--primary-dark); }
.btn.danger { color: var(--danger); border-color: #eab8b5; }
.btn.danger:hover { background: #fbeaea; }
.btn.small { padding: 5px 12px; font-size: .88rem; }
.btn.wide { width: 100%; padding: 11px; margin: 6px 0 12px; }
button.link { background: none; border: 0; padding: 0; font: inherit; color: var(--primary); cursor: pointer; }
button.link:hover { text-decoration: underline; }
.danger { color: var(--danger) !important; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

.field { display: flex; flex-direction: column; gap: 4px; margin-bottom: 12px; }
.field > span { font-size: .85rem; font-weight: 600; color: #3d4a45; }
.field small { color: var(--muted); font-size: .8rem; }
input, select, textarea { font: inherit; color: inherit; padding: 8px 11px; border: 1px solid #cfc8ba; border-radius: 9px;
  background: #fff; width: 100%; }
input[type=checkbox] { width: 17px; height: 17px; flex: none; margin: 3px 0 0; accent-color: var(--primary); }
input[type=file] { padding: 6px; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--primary); outline-offset: -1px; border-color: var(--primary); }
textarea { resize: vertical; }
.check { display: flex; gap: 9px; align-items: flex-start; margin: 6px 0 12px; }
fieldset.card { min-width: 0; } legend { font-family: Georgia, serif; font-weight: 600; font-size: 1.1rem; padding: 0 8px; }
.grid-form { display: grid; grid-template-columns: repeat(auto-fit, minmax(230px, 1fr)); gap: 0 18px; }
.grid-form .full { grid-column: 1 / -1; }
.edit-form { max-width: 860px; }
.form-actions { display: flex; gap: 10px; position: sticky; bottom: 0; padding: 14px 0; background: linear-gradient(transparent, var(--bg) 30%); }
.inline-form { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; margin: 0; }
.inline-form input, .inline-form select { width: auto; flex: 1 1 160px; }
.copy-row { display: flex; gap: 8px; } .copy-row input { font-family: ui-monospace, Consolas, monospace; font-size: .85rem; }

/* avatars and chips */
.avatar { display: inline-grid; place-items: center; width: 40px; height: 40px; border-radius: 50%; overflow: hidden;
  flex: none; font-weight: 700; font-size: .85rem; color: #fff; background: var(--u); text-transform: uppercase; }
.avatar img { width: 100%; height: 100%; object-fit: cover; }
.avatar.small { width: 32px; height: 32px; font-size: .72rem; }
.avatar.big { width: 104px; height: 104px; font-size: 2rem; border: 4px solid #fff; box-shadow: var(--shadow); }
.avatar.sex-M { background: var(--m); } .avatar.sex-F { background: var(--f); }
.chips { display: flex; flex-direction: column; gap: 6px; }
.chip-row { display: flex; align-items: center; gap: 10px; } .chip-row.child { margin-left: 22px; }
.chip-row form { margin: 0; font-size: .8rem; opacity: 0; } .chip-row:hover form, .chip-row form:focus-within { opacity: 1; }
.chip { display: flex; align-items: center; gap: 10px; padding: 6px 12px 6px 6px; border-radius: 999px; color: var(--ink);
  flex: 1; min-width: 0; }
.chip:hover { background: var(--bg); text-decoration: none; }
.chip-text { display: flex; flex-direction: column; line-height: 1.25; min-width: 0; }
.chip-text small { color: var(--muted); }
.add-link, .small-link { font-size: .85rem; } .add-link { margin: 2px 0 0 22px; }
.small-link { font-family: system-ui, sans-serif; font-weight: 400; margin-left: 8px; }

/* profile */
.profile-head { display: flex; gap: 24px; align-items: center; padding: 26px 28px; border-radius: var(--radius);
  background: linear-gradient(120deg, #fff 55%, var(--u-bg)); border: 1px solid var(--line); box-shadow: var(--shadow);
  margin-bottom: 18px; border-left: 6px solid var(--u); }
.profile-head.sex-M { background: linear-gradient(120deg, #fff 55%, var(--m-bg)); border-left-color: var(--m); }
.profile-head.sex-F { background: linear-gradient(120deg, #fff 55%, var(--f-bg)); border-left-color: var(--f); }
.profile-title h1 { margin: 0; font-size: 2rem; } .profile-title .sub { margin: 4px 0 14px; color: var(--muted); }
.actions { display: flex; gap: 8px; flex-wrap: wrap; }
.menu { position: relative; } .menu summary { list-style: none; } .menu summary::-webkit-details-marker { display: none; }
.menu-list { position: absolute; z-index: 5; top: calc(100% + 6px); left: 0; min-width: 210px; background: #fff;
  border: 1px solid var(--line); border-radius: 10px; box-shadow: var(--shadow); padding: 6px; }
.menu-list a { display: block; padding: 7px 12px; border-radius: 7px; color: var(--ink); }
.menu-list a:hover { background: var(--bg); text-decoration: none; }
.profile-grid { display: grid; grid-template-columns: minmax(0, 3fr) minmax(0, 2fr); gap: 18px; align-items: start; }
.facts { display: grid; grid-template-columns: max-content 1fr; gap: 7px 18px; margin: 0; }
.facts dt { color: var(--muted); } .facts dd { margin: 0; overflow-wrap: anywhere; }
.prose { white-space: pre-wrap; overflow-wrap: anywhere; }
.timeline { list-style: none; margin: 0 0 10px; padding: 0; border-left: 2px solid var(--line); }
.timeline li { position: relative; display: grid; grid-template-columns: 150px 1fr auto; gap: 10px; padding: 7px 0 7px 18px; }
.timeline li::before { content: ""; position: absolute; left: -6px; top: 14px; width: 10px; height: 10px; border-radius: 50%;
  background: var(--accent); border: 2px solid #fff; }
.timeline time { color: var(--muted); } .timeline p { margin: 2px 0 0; color: var(--muted); } .timeline form { margin: 0; }
details.add summary { cursor: pointer; color: var(--primary); font-weight: 600; margin-bottom: 10px; }
.gallery { display: grid; grid-template-columns: repeat(auto-fill, minmax(130px, 1fr)); gap: 12px; margin-bottom: 14px; }
.gallery figure { margin: 0; } .gallery img { width: 100%; aspect-ratio: 1; object-fit: cover; border-radius: 10px; display: block; }
.gallery figcaption { font-size: .8rem; color: var(--muted); padding-top: 4px; }
.fig-actions { display: flex; gap: 8px; flex-wrap: wrap; } .fig-actions form { margin: 0; }
.badge { display: inline-block; padding: 2px 10px; border-radius: 999px; font-size: .8rem; font-weight: 600;
  background: var(--u-bg); color: #50564f; }
.badge.consent-granted { background: #dff0e6; color: #1d5a3a; } .badge.consent-refused, .badge.consent-withdrawn { background: #fbe3e1; color: #8a1f18; }
.checks { list-style: none; padding: 0; margin: 8px 0; }
.checks li::before { content: "✗ "; color: var(--danger); } .checks li.yes::before { content: "✓ "; color: #1d7a4a; }
.checks li.no { color: var(--muted); }

/* lists */
.filters { display: flex; gap: 10px; flex-wrap: wrap; padding: 14px; } .filters input { flex: 2 1 240px; }
.filters select { flex: 1 1 150px; width: auto; }
.letters, .pager { display: flex; flex-wrap: wrap; gap: 4px; margin: 0 0 14px; }
.letters a, .pager a { padding: 3px 10px; border-radius: 7px; background: #fff; border: 1px solid var(--line); color: var(--ink); }
.letters a.on, .pager a.on { background: var(--primary); border-color: var(--primary); color: #fff; }
.table-wrap { padding: 0; overflow-x: auto; }
table.people { width: 100%; border-collapse: collapse; }
table.people th { text-align: left; font-size: .8rem; text-transform: uppercase; letter-spacing: .04em; color: var(--muted);
  padding: 11px 14px; border-bottom: 1px solid var(--line); background: #faf8f4; }
table.people td { padding: 8px 14px; border-bottom: 1px solid #f0ebe1; vertical-align: middle; }
table.people tr:last-child td { border-bottom: 0; } table.people tbody tr:hover { background: #fbf9f5; }
table.people td.av { width: 46px; padding-right: 0; } table.people tr.off { opacity: .55; }
.row-actions { display: flex; gap: 12px; justify-content: flex-end; white-space: nowrap; } .row-actions form { margin: 0; }

/* calendar & stats */
.months { display: grid; grid-template-columns: repeat(auto-fill, minmax(320px, 1fr)); gap: 18px; }
.month { margin: 0; } .cal { list-style: none; margin: 0; padding: 0; }
.cal li { display: flex; gap: 12px; padding: 6px 0; border-top: 1px solid #f0ebe1; align-items: baseline; }
.cal .day { flex: none; width: 30px; height: 30px; border-radius: 50%; display: grid; place-items: center; font-weight: 700;
  background: var(--m-bg); color: #24507f; font-size: .85rem; }
.cal .death .day { background: var(--u-bg); color: #50564f; } .cal .wedding .day { background: #fdf0d2; color: #7a5510; }
.cal .today .day { background: var(--primary); color: #fff; } .cal small { display: block; }
.tiles { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 14px; margin-bottom: 18px; }
.tile { background: #fff; border: 1px solid var(--line); border-radius: var(--radius); padding: 16px 18px; box-shadow: var(--shadow); }
.tile b { display: block; font-family: Georgia, serif; font-size: 1.7rem; color: var(--primary); } .tile span { color: var(--muted); font-size: .88rem; }
.stats-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); gap: 18px; }
.stats-grid .card { margin: 0; } .stats-grid .wide { grid-column: 1 / -1; }
.bars, .rank { list-style: none; margin: 0; padding: 0; }
.bars li { display: grid; grid-template-columns: 130px 1fr 34px; gap: 10px; align-items: center; padding: 3px 0; }
.bar-label { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; } .bar-n { text-align: right; color: var(--muted); }
.bar { height: 10px; background: #f0ebe1; border-radius: 5px; overflow: hidden; } .bar i { display: block; height: 100%; background: var(--primary); border-radius: 5px; }
.rank li { display: flex; justify-content: space-between; gap: 10px; padding: 5px 0; border-top: 1px solid #f0ebe1; }
.rank li:first-child { border-top: 0; } .rank span { color: var(--muted); white-space: nowrap; }
.columns { display: flex; align-items: flex-end; gap: 6px; height: 190px; overflow-x: auto; padding-top: 18px; }
.column { flex: 1 0 34px; height: 100%; display: flex; flex-direction: column; justify-content: flex-end; align-items: center; gap: 3px; }
.column i { display: block; width: 100%; min-height: 2px; background: var(--primary); border-radius: 5px 5px 0 0; }
.column span { font-size: .75rem; color: var(--muted); } .column small { font-size: .72rem; color: var(--muted); }

/* tree page */
.tree-page { overflow: hidden; }
.tree-main { flex: 1; min-height: 0; display: flex; flex-direction: column; }
#tree-app { flex: 1; min-height: 0; display: flex; flex-direction: column; }
.tree-bar { display: flex; align-items: center; gap: 14px; padding: 8px 16px; background: #fff; border-bottom: 1px solid var(--line);
  flex-wrap: wrap; }
.tabs { display: flex; background: var(--bg); border-radius: 10px; padding: 3px; }
.tabs button { border: 0; background: none; font: inherit; font-weight: 600; padding: 6px 14px; border-radius: 8px; cursor: pointer;
  color: var(--muted); }
.tabs button.on { background: #fff; color: var(--primary); box-shadow: 0 1px 3px rgba(0, 0, 0, .12); }
.gen { display: flex; align-items: center; gap: 6px; font-size: .85rem; color: var(--muted); white-space: nowrap; }
.gen select { width: auto; padding: 4px 8px; }
.spacer { flex: 1; }
.finder { position: relative; } .finder input { width: 210px; padding: 6px 12px; border-radius: 999px; }
#find-results { position: absolute; z-index: 20; right: 0; top: calc(100% + 6px); width: 290px; max-height: 60vh; overflow: auto;
  list-style: none; margin: 0; padding: 6px; background: #fff; border: 1px solid var(--line); border-radius: 10px; box-shadow: var(--shadow); }
#find-results button, .panel-list button { display: block; width: 100%; text-align: left; border: 0; background: none; font: inherit;
  padding: 6px 10px; border-radius: 7px; cursor: pointer; border-left: 3px solid var(--u); margin-bottom: 2px; }
#find-results button:hover, .panel-list button:hover { background: var(--bg); }
#find-results small, .panel-list small { display: block; color: var(--muted); font-size: .8rem; }
button.sex-M { border-left-color: var(--m) !important; } button.sex-F { border-left-color: var(--f) !important; }
.tree-body { flex: 1; min-height: 0; display: flex; }
.panel { width: 270px; flex: none; background: #fff; border-right: 1px solid var(--line); overflow-y: auto; padding: 18px 16px; }
.panel-head { display: flex; flex-direction: column; align-items: center; text-align: center; gap: 8px; }
.panel-head strong { display: block; font-family: Georgia, serif; font-size: 1.15rem; } .panel-head small { display: block; color: var(--muted); }
.panel-actions { display: flex; gap: 8px; justify-content: center; margin: 14px 0 6px; }
.panel h3 { font-size: .78rem; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); font-family: system-ui, sans-serif; margin: 18px 0 6px; }
.panel-list { list-style: none; margin: 0; padding: 0; }
.canvas-wrap { position: relative; flex: 1; min-width: 0; background:
  radial-gradient(circle, #d9d2c4 1px, transparent 1.2px) 0 0 / 22px 22px, var(--bg); }
#canvas { width: 100%; height: 100%; display: block; cursor: grab; touch-action: none; user-select: none; }
#canvas.dragging { cursor: grabbing; }
.loading { position: absolute; inset: 0; display: grid; place-items: center; margin: 0; pointer-events: none; }
.zoom { position: absolute; right: 16px; bottom: 16px; display: flex; flex-direction: column; gap: 6px; }
.zoom button { width: 38px; height: 38px; border-radius: 10px; border: 1px solid var(--line); background: #fff; font-size: 1.2rem;
  cursor: pointer; box-shadow: var(--shadow); }
.zoom button:hover { border-color: var(--primary); }

svg .link { fill: none; stroke: #a79f8f; stroke-width: 1.6; }
svg .link.couple { stroke: var(--accent); stroke-width: 2.2; } svg .link.ex { stroke-dasharray: 4 4; } svg .link.dots { stroke-dasharray: 2 4; }
svg .card { cursor: pointer; } svg .card:focus { outline: none; }
svg .card-bg { fill: #fff; stroke: #d5cdbd; stroke-width: 1; filter: drop-shadow(0 1px 2px rgba(31, 42, 38, .12)); }
svg .card.sex-M .card-bg { fill: var(--m-bg); stroke: #b9d2ea; } svg .card.sex-F .card-bg { fill: var(--f-bg); stroke: #efc4d3; }
svg .card.sex-U .card-bg { fill: var(--u-bg); }
svg .card-stripe, svg .card-avatar { fill: var(--u); } svg .sex-M .card-stripe, svg .sex-M .card-avatar { fill: var(--m); }
svg .sex-F .card-stripe, svg .sex-F .card-avatar { fill: var(--f); }
svg .card:hover .card-bg, svg .card:focus-visible .card-bg { stroke: var(--primary); stroke-width: 2; }
svg .card.focus .card-bg { stroke: var(--primary); stroke-width: 3; }
svg .card.me .card-years { font-weight: 700; }
svg .card.dead .card-avatar, svg .card.dead image { opacity: .72; }
svg text { font-family: system-ui, -apple-system, "Segoe UI", sans-serif; fill: var(--ink); pointer-events: none; }
svg .card-initials { fill: #fff; font-weight: 700; font-size: 14px; }
svg .card-first { font-size: 13px; } svg .card-last { font-size: 13.5px; font-weight: 700; } svg .card-years { font-size: 11.5px; fill: var(--muted); }
svg .more { fill: none; stroke: var(--accent); stroke-width: 2.2; stroke-linecap: round; stroke-linejoin: round; }
svg .fan-empty { fill: rgba(255, 255, 255, .45); stroke: #e0d9cb; stroke-dasharray: 3 4; }
svg .fan .card-bg { filter: none; stroke: #fff; stroke-width: 2; }
svg .fan-name { font-size: 12px; } svg .fan-last { font-size: 12.5px; font-weight: 700; } svg .fan-years { font-size: 10.5px; fill: var(--muted); }

.outline { position: absolute; inset: 0; overflow: auto; padding: 22px 28px 60px; background: var(--bg); }
.o-tree, .o-tree ul { list-style: none; margin: 0; padding-left: 26px; } .o-tree { padding-left: 0; }
.o-tree ul { border-left: 2px solid var(--line); margin-left: 12px; }
.o-row { display: flex; align-items: center; gap: 8px; padding: 3px 0; } .o-partner { padding-left: 34px; }
.o-gen { width: 24px; height: 24px; flex: none; border-radius: 50%; background: var(--primary); color: #fff; font-size: .75rem;
  font-weight: 700; display: grid; place-items: center; }
.o-ring { color: var(--accent); } .o-person { color: var(--ink); font-weight: 600; padding: 2px 10px; border-radius: 7px;
  border-left: 3px solid var(--u); background: #fff; }
.o-person.sex-M { border-left-color: var(--m); } .o-person.sex-F { border-left-color: var(--f); }
.o-person.partner { font-weight: 400; } .o-person small { color: var(--muted); font-weight: 400; }

@media (max-width: 900px) {
  .top { flex-wrap: wrap; height: auto; padding: 8px 14px; gap: 6px 14px; }
  .main-nav { order: 3; width: 100%; overflow-x: auto; } .main-nav a { padding: 8px 10px; }
  .search input { width: 140px; } .brand span { display: none; }
  .profile-grid { grid-template-columns: 1fr; } .profile-head { flex-direction: column; text-align: center; }
  .actions { justify-content: center; } .timeline li { grid-template-columns: 1fr auto; } .timeline time { grid-column: 1 / -1; }
  .panel { display: none; } .gen { display: none; } .finder input { width: 150px; } .chip-row form { opacity: 1; }
}
@media print {
  .top, .sub-nav, .tree-bar, .panel, .zoom, .actions, .form-actions { display: none !important; }
  body { background: #fff; } .card { box-shadow: none; }
}
