/* FamilyTree styles – phone first, desktop at ≥ 760px */
@import url('brief-message.css');
@import url('contextual-help.css');

:root {
  --brief-msg-bg: rgba(42, 39, 36, 0.95);
  --brief-msg-color: #fff;
  --brief-msg-border: none;
  --brief-msg-radius: 999px;
  --brief-msg-padding: 0.4rem 0.8rem;
  --brief-msg-font-size: 0.85rem;
  --brief-msg-font-weight: 600;
  --bg: #f4efe6;
  --panel: #ffffff;
  --panel-2: #faf7f1;
  --ink: #2a2724;
  --muted: #736d63;
  --line: #e4ddd0;
  --accent: #4f7a45;
  --accent-ink: #ffffff;
  --accent-soft: #e4eedf;
  --warm: #b8623a;
  --warm-soft: #f6e4da;
  --male: #dbe7f3;
  --male-ink: #2f5a86;
  --female: #f5dfe4;
  --female-ink: #8a3a52;
  --unknown: #ebe7df;
  --unknown-ink: #5d574d;
  --danger: #b4402f;
  --radius: 14px;
  --radius-sm: 9px;
  --shadow: 0 1px 2px rgba(40, 30, 10, 0.06), 0 6px 20px rgba(40, 30, 10, 0.06);
  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", sans-serif;
  --header-h: 56px;
  --tabbar-h: 62px;
  --safe-b: env(safe-area-inset-bottom, 0px);
}

*, *::before, *::after { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font);
  font-size: 16px;
  line-height: 1.45;
  -webkit-text-size-adjust: 100%;
  min-height: 100vh;
}
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
button { font: inherit; }
h1, h2, h3 { margin: 0; line-height: 1.2; }
h1 { font-size: 1.5rem; }
h2 { font-size: 1.1rem; }
h3 { font-size: .95rem; color: var(--muted); font-weight: 600; text-transform: uppercase; letter-spacing: .04em; }
p { margin: 0 0 .6rem; }
.muted { color: var(--muted); }
.small { font-size: .85rem; }
.hidden { display: none !important; }

/* ---------- shell ---------- */
.app-header {
  position: sticky; top: 0; z-index: 30;
  height: var(--header-h);
  display: flex; align-items: center; gap: .6rem;
  padding: 0 .9rem;
  background: rgba(244, 239, 230, .92);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--line);
}
.app-header__title { font-weight: 700; font-size: 1.05rem; flex: 1; min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.app-header__title small { display: block; font-weight: 500; font-size: .72rem; color: var(--muted); }
.app-header__btn {
  width: 40px; height: 40px; border-radius: 50%; border: none; background: transparent;
  display: grid; place-items: center; cursor: pointer; color: var(--ink); font-size: 1.15rem;
}
.app-header__btn:hover { background: rgba(0,0,0,.05); }
.me-chip {
  display: inline-flex; align-items: center; gap: .4rem;
  padding: .25rem .6rem .25rem .3rem; border-radius: 999px;
  background: var(--panel); border: 1px solid var(--line); font-size: .8rem; font-weight: 600;
  cursor: pointer; font-family: inherit; color: inherit;
}
.me-chip--guest { padding: .35rem .8rem; color: var(--accent); }
.me-chip .avatar { width: 24px; height: 24px; font-size: .6rem; }

.app-main {
  padding: 1rem .9rem calc(var(--tabbar-h) + var(--safe-b) + 1rem);
  max-width: 1100px; margin: 0 auto; width: 100%; min-width: 0;
}
html, body { overflow-x: hidden; }
.app-main--flush { padding: 0; max-width: none; }

.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 30;
  height: calc(var(--tabbar-h) + var(--safe-b));
  padding-bottom: var(--safe-b);
  display: grid; grid-template-columns: repeat(5, 1fr);
  background: var(--panel); border-top: 1px solid var(--line);
}
.tabbar a {
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
  color: var(--muted); font-size: .68rem; font-weight: 600; text-decoration: none;
}
.tabbar a .ico { font-size: 1.25rem; line-height: 1; }
.tabbar a.is-active { color: var(--accent); }
.sidenav { display: none; }

@media (min-width: 760px) {
  body { display: grid; grid-template-columns: 232px minmax(0, 1fr); grid-template-rows: var(--header-h) 1fr; min-height: 100vh; }
  .app-main { min-width: 0; }
  .app-header { grid-column: 1 / -1; }
  .sidenav {
    display: flex; flex-direction: column; gap: .2rem;
    padding: 1rem .7rem; border-right: 1px solid var(--line);
    position: sticky; top: var(--header-h); height: calc(100vh - var(--header-h));
  }
  .sidenav a {
    display: flex; align-items: center; gap: .7rem;
    padding: .6rem .8rem; border-radius: var(--radius-sm);
    color: var(--ink); font-weight: 600; text-decoration: none;
  }
  .sidenav a .ico { width: 1.4rem; text-align: center; }
  .sidenav a:hover { background: rgba(0,0,0,.04); }
  .sidenav a.is-active { background: var(--accent-soft); color: var(--accent); }
  .sidenav__foot { margin-top: auto; font-size: .75rem; color: var(--muted); padding: .6rem .8rem; }
  .tabbar { display: none; }
  .app-main { padding: 1.4rem 1.6rem 2rem; }
  .app-main--flush { padding: 0; }
}

/* ---------- primitives ---------- */
.card {
  background: var(--panel); border-radius: var(--radius); box-shadow: var(--shadow);
  padding: .9rem 1rem; margin-bottom: .9rem;
}
.card__head { display: flex; align-items: center; justify-content: space-between; gap: .5rem; margin-bottom: .6rem; }
.card__head h2, .card__head h3 { margin: 0; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: .4rem;
  min-height: 40px; padding: .5rem .95rem; border-radius: 999px;
  border: 1px solid var(--line); background: var(--panel); color: var(--ink);
  font-weight: 600; font-size: .9rem; cursor: pointer; text-decoration: none; white-space: nowrap;
}
.btn:hover { background: var(--panel-2); text-decoration: none; }
.btn--primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn--primary:hover { background: #456b3c; }
.btn--warm { background: var(--warm); border-color: var(--warm); color: #fff; }
.btn--ghost { background: transparent; border-color: transparent; color: var(--accent); }
.btn--danger { color: var(--danger); border-color: #e8c4bd; }
.btn--sm { min-height: 32px; padding: .25rem .7rem; font-size: .8rem; }
.btn--icon { width: 40px; padding: 0; border-radius: 50%; }
.btn--block { width: 100%; }
.btn-row { display: flex; flex-wrap: wrap; gap: .5rem; }
.btn-row--end { justify-content: flex-end; }

.chip {
  display: inline-flex; align-items: center; gap: .3rem;
  padding: .2rem .6rem; border-radius: 999px; font-size: .75rem; font-weight: 600;
  background: var(--unknown); color: var(--unknown-ink); border: 1px solid transparent;
}
.chip--living { background: var(--accent-soft); color: var(--accent); }
.chip--deceased { background: var(--unknown); color: var(--muted); }
.chip--warm { background: var(--warm-soft); color: var(--warm); }
.chip--male { background: var(--male); color: var(--male-ink); }
.chip--female { background: var(--female); color: var(--female-ink); }
.chip-row { display: flex; gap: .4rem; flex-wrap: nowrap; overflow-x: auto; padding-bottom: .3rem; scrollbar-width: none; }
.chip-row::-webkit-scrollbar { display: none; }
.chip-row .chip { cursor: pointer; background: var(--panel); border-color: var(--line); color: var(--ink); flex: 0 0 auto; min-height: 32px; padding: .3rem .8rem; }
.chip-row .chip.is-active { background: var(--ink); color: #fff; border-color: var(--ink); }

.avatar {
  width: 44px; height: 44px; border-radius: 50%; flex: 0 0 auto;
  display: inline-grid; place-items: center;
  font-weight: 700; font-size: .95rem; letter-spacing: .02em;
  background: var(--unknown); color: var(--unknown-ink);
  position: relative; overflow: hidden;
}
.avatar--M { background: var(--male); color: var(--male-ink); }
.avatar--F { background: var(--female); color: var(--female-ink); }
.avatar--lg { width: 84px; height: 84px; font-size: 1.6rem; }
.avatar--xl { width: 112px; height: 112px; font-size: 2.1rem; }
.avatar--sm { width: 32px; height: 32px; font-size: .7rem; }
.avatar--photo { background: linear-gradient(145deg, hsl(var(--h, 200) 45% 72%), hsl(var(--h, 200) 40% 48%)); color: rgba(255,255,255,.92); text-shadow: 0 1px 2px rgba(0,0,0,.25); }
.avatar--photo::after { content: ""; position: absolute; inset: 0; background: radial-gradient(circle at 50% 38%, rgba(255,255,255,.18), transparent 40%); }
.avatar--img { background-size: cover; background-position: center; background-repeat: no-repeat; color: transparent; }
.avatar--img::after { display: none; }

.search {
  display: flex; align-items: center; gap: .5rem;
  background: var(--panel); border: 1px solid var(--line); border-radius: 999px;
  padding: .3rem .4rem .3rem .9rem; box-shadow: var(--shadow);
}
.search input { flex: 1; min-width: 0; border: none; outline: none; background: transparent; font: inherit; font-size: 1rem; padding: .4rem 0; }
.search .ico { color: var(--muted); }

.person-row {
  display: flex; align-items: center; gap: .75rem;
  padding: .6rem .2rem; border-bottom: 1px solid var(--line);
  color: inherit; text-decoration: none;
}
.person-row:last-child { border-bottom: none; }
.person-row:hover { text-decoration: none; background: var(--panel-2); border-radius: var(--radius-sm); }
.person-row__body { flex: 1; min-width: 0; display: block; }
.person-row__name { display: block; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.person-row__meta { display: block; font-size: .8rem; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.person-row__tag { font-size: .72rem; color: var(--muted); flex: 0 0 auto; text-align: right; }
.person-row__chev { color: #c2bbae; flex: 0 0 auto; }

.list-head { display: flex; justify-content: space-between; align-items: baseline; margin: .9rem 0 .3rem; }
.list-head h3 { margin: 0; }

.stat-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: .6rem; }
.stat { background: var(--panel); border-radius: var(--radius); box-shadow: var(--shadow); padding: .8rem .9rem; }
.stat__n { font-size: 1.6rem; font-weight: 800; line-height: 1; }
.stat__l { font-size: .78rem; color: var(--muted); margin-top: .2rem; }
@media (min-width: 760px) { .stat-grid { grid-template-columns: repeat(4, 1fr); } }

.two-col { display: grid; gap: .9rem; }
@media (min-width: 900px) { .two-col { grid-template-columns: 1.3fr 1fr; align-items: start; } }

.empty { color: var(--muted); font-size: .9rem; padding: .4rem 0; }

/* ---------- forms ---------- */
.field { display: flex; flex-direction: column; gap: .3rem; margin-bottom: .8rem; }
.field label { font-size: .8rem; font-weight: 600; color: var(--muted); }
.field input[type="text"], .field input[type="search"], .field input[type="password"], .field select, .field textarea {
  font: inherit; font-size: 1rem; padding: .6rem .75rem; border-radius: var(--radius-sm);
  border: 1px solid var(--line); background: var(--panel); color: var(--ink); width: 100%;
}
.field input:focus, .field textarea:focus, .field select:focus { outline: 2px solid var(--accent-soft); border-color: var(--accent); }
.field .hint { font-size: .75rem; color: var(--muted); }
.field-row { display: grid; grid-template-columns: 1fr 1fr; gap: .6rem; }
.seg { display: inline-flex; border: 1px solid var(--line); border-radius: 999px; overflow: hidden; background: var(--panel); }
.seg button { border: none; background: transparent; padding: .45rem .9rem; font-weight: 600; cursor: pointer; color: var(--muted); min-height: 38px; }
.seg button[aria-pressed="true"] { background: var(--ink); color: #fff; }
.seg--block { display: flex; } .seg--block button { flex: 1; }
.toggle { display: flex; align-items: center; justify-content: space-between; gap: .8rem; padding: .5rem 0; }
.switch { width: 46px; height: 28px; border-radius: 999px; background: #d9d2c5; position: relative; border: none; cursor: pointer; flex: 0 0 auto; }
.switch::after { content: ""; position: absolute; top: 3px; left: 3px; width: 22px; height: 22px; border-radius: 50%; background: #fff; transition: left .15s; box-shadow: 0 1px 2px rgba(0,0,0,.2); }
.switch[aria-checked="true"] { background: var(--accent); }
.switch[aria-checked="true"]::after { left: 21px; }

/* ---------- sheet / dialog ---------- */
.sheet-backdrop { position: fixed; inset: 0; background: rgba(30, 25, 15, .45); z-index: 80; display: flex; align-items: flex-end; justify-content: center; animation: fade .15s ease-out; }
.sheet {
  background: var(--panel); width: 100%; max-height: 92vh; overflow: auto;
  border-radius: 20px 20px 0 0; padding: .6rem 1rem calc(1rem + var(--safe-b));
  animation: up .2s ease-out;
}
.sheet__grab { width: 40px; height: 4px; border-radius: 2px; background: #d9d2c5; margin: .2rem auto .8rem; }
.sheet__head { display: flex; align-items: center; justify-content: space-between; gap: .5rem; margin-bottom: .8rem; }
.sheet__head h2 { font-size: 1.15rem; }
.sheet__foot { display: flex; gap: .5rem; justify-content: flex-end; margin-top: .6rem; position: sticky; bottom: 0; background: var(--panel); padding-top: .5rem; flex-wrap: wrap; }
@media (min-width: 760px) {
  .sheet-backdrop { align-items: center; }
  .sheet { width: min(560px, 92vw); border-radius: var(--radius); padding: 1.2rem 1.4rem; max-height: 86vh; }
  .sheet__grab { display: none; }
}
@keyframes up { from { transform: translateY(30px); opacity: .6; } to { transform: none; opacity: 1; } }
@keyframes fade { from { opacity: 0; } to { opacity: 1; } }

.brief {
  position: fixed; z-index: 90; transform: translate(-50%, -100%);
  background: rgba(42, 39, 36, .95); color: #fff; padding: .4rem .8rem; border-radius: 999px;
  font-size: .85rem; font-weight: 600; pointer-events: none; white-space: nowrap;
  animation: fade .12s ease-out;
}
.brief--fading { opacity: 0; transition: opacity .25s; }

/* ---------- FAB ---------- */
.fab {
  position: fixed; right: 1rem; bottom: calc(var(--tabbar-h) + var(--safe-b) + 1rem); z-index: 25;
  width: 56px; height: 56px; border-radius: 50%; border: none; background: var(--accent); color: #fff;
  font-size: 1.8rem; line-height: 1; box-shadow: 0 6px 18px rgba(79, 122, 69, .4); cursor: pointer;
}
@media (min-width: 760px) { .fab { bottom: 1.5rem; right: 1.5rem; } }

/* ---------- home ---------- */
.hero-me { display: flex; align-items: center; gap: .9rem; }
.hero-me__body { flex: 1; min-width: 0; }
.hero-me__name { font-weight: 700; font-size: 1.05rem; }
.quick-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: .5rem; margin-top: .8rem; }
.quick {
  display: flex; flex-direction: column; align-items: center; gap: .3rem; padding: .7rem .3rem;
  border-radius: var(--radius-sm); background: var(--panel-2); color: var(--ink); text-decoration: none;
  font-size: .72rem; font-weight: 600; text-align: center; border: 1px solid var(--line);
}
.quick:hover { text-decoration: none; background: var(--accent-soft); }
.quick .ico { font-size: 1.4rem; }
.search-results { position: absolute; left: 0; right: 0; top: calc(100% + .4rem); background: var(--panel); border-radius: var(--radius); box-shadow: var(--shadow); padding: .3rem .6rem; z-index: 20; max-height: 60vh; overflow: auto; }
.search-results .person-row { padding-left: .2rem; padding-right: .2rem; }
.search-wrap { position: relative; margin-bottom: 1rem; }

.change { display: flex; gap: .7rem; padding: .55rem 0; border-bottom: 1px solid var(--line); align-items: flex-start; }
.change:last-child { border-bottom: none; }
.change__who { width: 32px; height: 32px; border-radius: 50%; display: grid; place-items: center; font-size: .75rem; font-weight: 700; background: var(--accent-soft); color: var(--accent); flex: 0 0 auto; }
.change__body { flex: 1; min-width: 0; font-size: .9rem; }
.change__meta { font-size: .75rem; color: var(--muted); }

.onday { display: flex; gap: .7rem; align-items: center; padding: .5rem 0; border-bottom: 1px solid var(--line); }
.onday:last-child { border-bottom: none; }
.onday__year { font-weight: 800; color: var(--warm); min-width: 3rem; }

/* ---------- people list ---------- */
.people-toolbar { display: flex; flex-direction: column; gap: .6rem; margin-bottom: .6rem; position: sticky; top: var(--header-h); background: var(--bg); padding: .4rem 0 .5rem; z-index: 10; }
.people-layout { display: grid; grid-template-columns: 1fr; gap: 0; }
.alpha-index { display: none; }
@media (min-width: 760px) {
  .people-layout { grid-template-columns: 1fr 2rem; }
  .alpha-index { display: flex; flex-direction: column; align-items: center; position: sticky; top: calc(var(--header-h) + 7rem); height: fit-content; gap: 0; font-size: .7rem; font-weight: 700; }
  .alpha-index a { color: var(--muted); padding: .05rem .3rem; }
  .alpha-index a:hover { color: var(--accent); text-decoration: none; }
}
.letter-head { font-weight: 800; color: var(--accent); margin: 1rem 0 .2rem; font-size: 1rem; }
.sort-row { display: flex; justify-content: space-between; align-items: center; font-size: .8rem; color: var(--muted); }

/* ---------- person profile ---------- */
.profile-hero { display: flex; gap: 1rem; align-items: flex-start; }
.profile-hero__body { flex: 1; min-width: 0; }
.profile-hero h1 { font-size: 1.45rem; }
.profile-hero__life { color: var(--muted); font-size: .92rem; margin: .25rem 0 .5rem; }
.profile-actions { display: flex; gap: .5rem; overflow-x: auto; padding: .2rem 0 .4rem; scrollbar-width: none; margin-top: .6rem; }
.profile-actions::-webkit-scrollbar { display: none; }
.profile-actions .btn { flex: 0 0 auto; }
.tabs { display: flex; border-bottom: 1px solid var(--line); margin: .4rem 0 .9rem; position: sticky; top: var(--header-h); background: var(--bg); z-index: 9; }
.tabs button { flex: 1; border: none; background: transparent; padding: .7rem .3rem; font-weight: 600; color: var(--muted); border-bottom: 3px solid transparent; cursor: pointer; }
.tabs button[aria-selected="true"] { color: var(--accent); border-bottom-color: var(--accent); }
.profile-grid > section { display: none; }
.profile-grid > section.is-active { display: block; }
@media (min-width: 900px) {
  .tabs { display: none; }
  .profile-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 0 1rem; align-items: start; }
  .profile-grid > section { display: block; }
  .profile-grid > section[data-tab="family"] { grid-column: 1; grid-row: 1 / span 2; }
  .profile-grid > section[data-tab="timeline"] { grid-column: 2; }
  .profile-grid > section[data-tab="photos"] { grid-column: 2; }
  .profile-grid > section[data-tab="notes"] { grid-column: 1; }
}
.fam-group { margin-bottom: .9rem; }
.fam-group__title { display: flex; justify-content: space-between; align-items: center; margin-bottom: .2rem; }
.fam-group__title h3 { margin: 0; }
.fam-union { font-size: .85rem; color: var(--muted); margin: .2rem 0 .3rem; display: flex; gap: .4rem; align-items: center; }
.add-link { display: inline-flex; align-items: center; gap: .3rem; font-size: .82rem; font-weight: 600; color: var(--accent); background: none; border: 1px dashed #bcd2b4; border-radius: 999px; padding: .3rem .7rem; cursor: pointer; }
.add-link:hover { background: var(--accent-soft); }
.fam-parent { border-bottom: 1px solid var(--line); }
.fam-parent .person-row { border-bottom: none; padding-bottom: .25rem; }
.fam-parent__acts {
  display: flex; flex-wrap: wrap; gap: .4rem;
  padding: 0 0 .55rem .2rem; margin-left: calc(44px + .75rem);
}
.fam-parent__acts .add-link { min-height: 44px; box-sizing: border-box; }
.add-link--danger { color: var(--danger); border-color: #e8c4bc; }
.add-link--danger:hover { background: var(--warm-soft); }

.timeline { list-style: none; margin: 0; padding: 0; position: relative; }
.timeline::before { content: ""; position: absolute; left: 3.4rem; top: .4rem; bottom: .4rem; width: 2px; background: var(--line); }
.tl { display: grid; grid-template-columns: 3rem 1.1rem 1fr; gap: .4rem; padding: .45rem 0; align-items: start; cursor: pointer; }
.tl__year { font-weight: 800; font-size: .85rem; text-align: right; color: var(--warm); padding-top: .1rem; }
.tl__dot { width: 12px; height: 12px; border-radius: 50%; background: var(--panel); border: 3px solid var(--accent); margin-top: .35rem; justify-self: center; position: relative; z-index: 1; }
.tl--media { grid-template-columns: 3rem 1.1rem 1fr 44px; align-items: center; }
.tl--media .tl__dot { border-color: var(--warm); }
.tl__thumb { width: 44px; height: 44px; object-fit: cover; border-radius: 8px; background: #1c1915; }
.tl__title { font-weight: 600; font-size: .92rem; }
.tl__meta { font-size: .8rem; color: var(--muted); }
.otd { display: flex; justify-content: space-between; gap: .7rem; align-items: baseline; padding: .5rem 0; border-bottom: 1px solid var(--line); color: inherit; text-decoration: none; }
.otd--stack { flex-direction: column; align-items: flex-start; gap: .1rem; }
.otd:last-child { border-bottom: none; }
a.otd:hover { color: var(--accent); }
.otd__year { font-weight: 800; color: var(--warm); min-width: 3.2rem; }
.surname-index h3 { margin: .85rem 0 .15rem; font-size: .78rem; letter-spacing: .08em; color: var(--muted); }
.surname-index__row {
  display: flex; justify-content: space-between; align-items: center; width: 100%;
  min-height: 44px; background: none; border: none; border-bottom: 1px solid var(--line);
  font: inherit; color: inherit; cursor: pointer; text-align: left; padding: .15rem 0;
}
@media (min-width: 760px) {
  .surname-index { columns: 2; column-gap: 2rem; }
  .surname-index h3, .surname-index__row { break-inside: avoid; }
}

.media-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: .4rem; }
@media (min-width: 560px) { .media-grid { grid-template-columns: repeat(4, 1fr); } }
@media (min-width: 900px) { .media-grid { grid-template-columns: repeat(5, 1fr); gap: .6rem; } }
.media-grid--wide { grid-template-columns: repeat(2, 1fr); }
@media (min-width: 560px) { .media-grid--wide { grid-template-columns: repeat(3, 1fr); } }
@media (min-width: 900px) { .media-grid--wide { grid-template-columns: repeat(4, 1fr); } }
.tile {
  aspect-ratio: 1; border-radius: var(--radius-sm); overflow: hidden; position: relative; cursor: pointer; border: none; padding: 0;
  background: linear-gradient(160deg, hsl(var(--h, 200) 40% 78%), hsl(var(--h, 200) 35% 50%));
  color: #fff; display: flex; flex-direction: column; justify-content: flex-end; text-align: left;
}
.tile--doc { background: linear-gradient(160deg, #f1e7d0, #c9b995); color: #3c3225; }
.tile__ico { position: absolute; top: 50%; left: 50%; transform: translate(-50%, -60%); font-size: 2rem; opacity: .85; }
.tile__cap { padding: .35rem .45rem; font-size: .7rem; font-weight: 600; background: linear-gradient(transparent, rgba(0,0,0,.45)); line-height: 1.2; }
.tile--doc .tile__cap { background: linear-gradient(transparent, rgba(60,50,37,.35)); color: #fff; }
.tile__kind { position: absolute; top: .35rem; left: .35rem; font-size: .62rem; font-weight: 700; padding: .1rem .4rem; border-radius: 999px; background: rgba(255,255,255,.85); color: var(--ink); z-index: 1; }
.tile__img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; }
.tile--photo { background: #1c1915; }
.tile--photo .tile__ico { display: none; }
.tile__when { opacity: .8; font-weight: 500; }
button.person-row { width: 100%; background: none; border: none; border-bottom: 1px solid var(--line); font: inherit; color: inherit; text-align: left; cursor: pointer; }

.note { padding: .6rem .7rem; border-radius: var(--radius-sm); background: var(--panel-2); margin-bottom: .5rem; border-left: 3px solid var(--line); }
.note--research { border-left-color: var(--male-ink); }
.note--todo { border-left-color: var(--warm); }
.note__meta { font-size: .75rem; color: var(--muted); margin-top: .3rem; }
.note__kind { font-size: .68rem; font-weight: 700; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); }

.rel-result { text-align: center; padding: .6rem 0 .2rem; }
.rel-result__term { font-size: 1.3rem; font-weight: 800; color: var(--accent); }
.rel-chart { overflow-x: auto; margin: .5rem 0 .8rem; }
.rel-chart svg { display: block; }
.rel-path { display: flex; flex-direction: column; gap: .2rem; margin-top: .8rem; }
.rel-path__step { display: flex; align-items: center; gap: .6rem; font-size: .9rem; }
.rel-path__arrow { color: var(--muted); font-size: .75rem; padding-left: 1rem; }

/* ---------- tree page ---------- */
.tree-page {
  display: flex; flex-direction: column;
  height: calc(100vh - var(--header-h) - var(--tabbar-h) - var(--safe-b));
  height: calc(100dvh - var(--header-h) - var(--tabbar-h) - var(--safe-b));
}
@media (min-width: 760px) {
  .tree-page {
    height: calc(100vh - var(--header-h));
    height: calc(100dvh - var(--header-h));
  }
}
.tree-toolbar { display: flex; flex-wrap: wrap; gap: .5rem; align-items: center; padding: .6rem .9rem; border-bottom: 1px solid var(--line); background: var(--bg); }
.tree-toolbar .seg button { padding: .4rem .7rem; font-size: .85rem; }
.tree-focus { display: inline-flex; align-items: center; gap: .4rem; background: var(--panel); border: 1px solid var(--line); border-radius: 999px; padding: .2rem .7rem .2rem .25rem; font-weight: 600; font-size: .85rem; cursor: pointer; }
.tree-focus .avatar { width: 28px; height: 28px; font-size: .65rem; }
.stepper { display: inline-flex; align-items: center; border: 1px solid var(--line); border-radius: 999px; background: var(--panel); overflow: hidden; }
.stepper button { border: none; background: transparent; width: 34px; height: 36px; cursor: pointer; font-size: 1.1rem; color: var(--ink); }
.stepper span { font-size: .8rem; font-weight: 600; min-width: 4.4rem; text-align: center; }
.chart-wrap { flex: 1; min-height: 0; position: relative; overflow: hidden; background: radial-gradient(circle at 1px 1px, #e3dccf 1px, transparent 1px) 0 0 / 22px 22px; }
.chart-wrap svg { width: 100%; height: 100%; display: block; touch-action: none; cursor: grab; user-select: none; -webkit-user-select: none; }
.chart-wrap svg:active { cursor: grabbing; }
.chart-controls { position: absolute; right: .7rem; top: .7rem; display: flex; flex-direction: column; gap: .4rem; }
.chart-controls .btn { width: 40px; height: 40px; padding: 0; border-radius: 50%; }
.chart-info {
  position: fixed; left: .7rem; right: .7rem;
  bottom: calc(var(--tabbar-h) + var(--safe-b) + .7rem);
  z-index: 25;
  background: var(--panel); border-radius: var(--radius); box-shadow: var(--shadow);
  padding: .6rem .8rem; display: flex; align-items: center; gap: .7rem; flex-wrap: wrap;
  animation: up .15s ease-out;
}
.chart-info .btn-row { margin-left: auto; }
@media (min-width: 760px) {
  .chart-info {
    position: absolute; left: auto; right: .7rem; bottom: .7rem; width: 380px; z-index: 5;
  }
}
.chart-soon {
  position: absolute; left: 50%; top: 40%; transform: translate(-50%, -50%);
  z-index: 6; background: var(--panel); color: var(--ink);
  border-radius: var(--radius); box-shadow: var(--shadow);
  padding: .85rem 1.1rem; font-weight: 600; text-align: center; max-width: 16rem;
}
.chart-info__body { flex: 1; min-width: 0; }
.chart-info__name { font-weight: 700; }
.legend { position: absolute; left: .7rem; top: .7rem; display: flex; gap: .6rem; font-size: .72rem; color: var(--muted); }
.legend span::before { content: ""; display: inline-block; width: 10px; height: 10px; border-radius: 3px; margin-right: .3rem; vertical-align: -1px; }
.legend .pat::before { background: var(--male); border: 1px solid var(--male-ink); }
.legend .mat::before { background: var(--female); border: 1px solid var(--female-ink); }

/* SVG node styles */
.node { cursor: pointer; }
.node rect { fill: #fff; stroke: #cfc7b8; stroke-width: 1.2; rx: 10; }
.node--M rect { fill: var(--male); stroke: #9fb9d4; }
.node--F rect { fill: var(--female); stroke: #d7a9b6; }
.node--focus rect { stroke: var(--accent); stroke-width: 2.5; }
.node--selected rect { stroke: var(--ink); stroke-width: 2.5; }
.node text { font-family: var(--font); fill: var(--ink); pointer-events: none; }
.node .n-name { font-size: 12.5px; font-weight: 700; }
.node .n-years { font-size: 10.5px; fill: var(--muted); }
.n-rel { font-family: var(--font); font-size: 10.5px; fill: var(--muted); pointer-events: none; }
.node--ph rect { fill: transparent; stroke: #bfb7a8; stroke-dasharray: 4 3; }
.node--ph text { fill: var(--accent); font-size: 11px; font-weight: 600; }
.edge { fill: none; stroke: #b9b0a0; stroke-width: 1.5; }
.fan-sector { stroke: #fff; stroke-width: 1.5; cursor: pointer; }
.fan-sector:hover { filter: brightness(.95); }
.fan-text { font-family: var(--font); font-size: 11px; fill: var(--ink); pointer-events: none; }
.fan-text--sm { font-size: 9.5px; fill: var(--muted); }
.fan-text--xs { font-size: 8px; }
.fan-centre { fill: #fff; stroke: var(--accent); stroke-width: 2.5; }
.edge--union { stroke: var(--warm); }
.node-toggle { cursor: pointer; }
.node-toggle__hit { fill: transparent; }
.node-toggle__face { fill: #fff; stroke: var(--accent); stroke-width: 1.6; }
.node-toggle .n-toggle { font-size: 11px; font-weight: 800; fill: var(--accent); }

/* ---------- gallery ---------- */
.gallery-toolbar { display: flex; flex-direction: column; gap: .6rem; margin-bottom: .8rem; }
.lightbox { position: fixed; inset: 0; z-index: 70; background: rgba(20, 17, 12, .96); color: #fff; display: flex; flex-direction: column; animation: fade .15s ease-out; }
.lightbox__top { display: flex; justify-content: space-between; align-items: center; padding: .6rem .8rem; gap: .5rem; }
.lightbox__top .btn { background: rgba(255,255,255,.1); border-color: transparent; color: #fff; }
.lightbox__stage {
  flex: 1; position: relative; min-height: 0; overflow: hidden;
  touch-action: none; user-select: none;
}
.lightbox__track { display: flex; height: 100%; will-change: transform; }
.lightbox__slide {
  flex: 0 0 100%; height: 100%; box-sizing: border-box;
  display: grid; place-items: center; overflow: hidden; padding: .35rem .6rem;
}
.lightbox__frame {
  position: relative; display: inline-block; line-height: 0;
  max-width: 100%; max-height: 100%;
}
.lightbox__zoom { transform-origin: center center; will-change: transform; }
.lightbox__frame.is-tagging { cursor: crosshair; }
.lightbox__frame.is-tagging .lightbox__photo { outline: 2px dashed rgba(255,255,255,.55); outline-offset: 3px; }
.lightbox__photo {
  display: block; width: auto; height: auto;
  max-width: min(92vw, 900px); max-height: min(58vh, 100%);
  border-radius: var(--radius); box-shadow: 0 20px 60px rgba(0,0,0,.5); background: #111;
  pointer-events: auto;
}
.lightbox__ph { font-size: 3rem; opacity: .5; }
.lightbox__nav {
  position: absolute; top: 50%; transform: translateY(-50%); z-index: 2;
  width: 48px; height: 48px; border-radius: 50%; border: none;
  background: rgba(255,255,255,.12); color: #fff; font-size: 1.4rem; cursor: pointer; display: none;
}
.lightbox__nav--l { left: .8rem; } .lightbox__nav--r { right: .8rem; }
.lightbox__zoom-btns {
  position: absolute; right: .7rem; bottom: .7rem; z-index: 2;
  display: flex; flex-direction: column; gap: .4rem;
}
.lightbox__zoom-btns .btn {
  width: 40px; height: 40px; padding: 0; border-radius: 50%;
  background: rgba(255,255,255,.12); border: none; color: #fff;
}
@media (min-width: 760px) { .lightbox__nav { display: block; } }
.lightbox__info { padding: .8rem 1rem calc(1rem + var(--safe-b)); max-width: 760px; margin: 0 auto; width: 100%; overflow: auto; max-height: 38vh; }
.lightbox__title { font-weight: 700; font-size: 1.05rem; }
.lightbox__meta { color: rgba(255,255,255,.7); font-size: .85rem; margin: .2rem 0 .4rem; }
.lightbox__caption { margin: 0 0 .6rem; color: rgba(255,255,255,.88); }
.lightbox__label { font-size: .72rem; font-weight: 700; letter-spacing: .04em; text-transform: uppercase; color: rgba(255,255,255,.55); margin-bottom: .35rem; }
.lightbox__people { display: flex; flex-wrap: wrap; gap: .4rem; align-items: center; }
.lightbox__person { display: inline-flex; flex-wrap: wrap; gap: .25rem; align-items: center; }
.lightbox__people a, .lightbox__pill { background: rgba(255,255,255,.12); color: #fff; padding: .25rem .7rem; border-radius: 999px; font-size: .8rem; font-weight: 600; border: none; }
.lightbox__pill { cursor: pointer; font: inherit; }
.lightbox__none { opacity: .65; }
.lightbox__actions { margin-top: .8rem; }
.face-tag { position: absolute; border: 2px solid #fff; box-shadow: 0 0 0 1px rgba(0,0,0,.5); border-radius: 4px; background: transparent; padding: 0; cursor: pointer; }
.face-tag span { position: absolute; left: 0; top: 100%; margin-top: 2px; background: rgba(0,0,0,.75); color: #fff; font-size: .72rem; font-weight: 600; line-height: 1.3; padding: .05rem .35rem; border-radius: 4px; white-space: nowrap; }
body.lightbox-open { overflow: hidden; }
.upload-drop { border: 2px dashed var(--line); border-radius: var(--radius); padding: 1.2rem; text-align: center; color: var(--muted); background: var(--panel-2); cursor: pointer; }
.upload-preview { aspect-ratio: 4/3; border-radius: var(--radius-sm); margin: .8rem 0; display: grid; place-items: center; overflow: hidden; background: #1c1915; }
.upload-preview[hidden], .checkline[hidden], #upForm[hidden] { display: none; }
.upload-preview img { width: 100%; height: 100%; object-fit: contain; }
.file-btn input { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }
.checkline { display: flex; align-items: center; gap: .5rem; margin: .2rem 0 .4rem; font-size: .92rem; }
.people-pick { display: flex; flex-wrap: wrap; gap: .4rem; }
.people-pick .chip { cursor: pointer; background: var(--panel); border-color: var(--line); color: var(--ink); min-height: 32px; }
.people-pick .chip.is-active { background: var(--accent); color: #fff; border-color: var(--accent); }

/* ---------- admin ---------- */
.kv { display: grid; grid-template-columns: 1fr auto; gap: .5rem .8rem; align-items: center; padding: .5rem 0; border-bottom: 1px solid var(--line); }
.kv:last-child { border-bottom: none; }
.kv__k { font-weight: 600; font-size: .92rem; }
.kv__v { font-size: .85rem; color: var(--muted); }
.code { font-family: ui-monospace, Menlo, Consolas, monospace; font-weight: 700; letter-spacing: .12em; background: var(--panel-2); padding: .2rem .5rem; border-radius: 6px; border: 1px solid var(--line); }
.bar { height: 10px; border-radius: 5px; background: var(--line); overflow: hidden; margin: .4rem 0; }
.bar > span { display: block; height: 100%; background: var(--accent); }
.contrib { display: flex; align-items: center; gap: .7rem; padding: .5rem 0; border-bottom: 1px solid var(--line); }
.contrib:last-child { border-bottom: none; }
.contrib__body { flex: 1; min-width: 0; }
.diff { font-family: ui-monospace, Menlo, Consolas, monospace; font-size: .78rem; background: var(--panel-2); border-radius: var(--radius-sm); padding: .5rem .7rem; margin-top: .4rem; }
.diff .del { color: var(--danger); text-decoration: line-through; }
.diff .ins { color: var(--accent); }

.banner { background: var(--warm-soft); color: var(--warm); border-radius: var(--radius-sm); padding: .5rem .8rem; font-size: .82rem; font-weight: 600; margin-bottom: .9rem; display: flex; justify-content: space-between; align-items: center; gap: .6rem; }
.banner button { background: none; border: none; color: inherit; font-weight: 700; cursor: pointer; text-decoration: underline; }

/* ---------- landing (no share code) ---------- */
body.page-landing {
  display: block;
  grid-template-columns: none;
}
body.page-landing .sidenav,
body.page-landing .tabbar,
body.page-landing .fab { display: none !important; }
body.page-landing .app-header { justify-content: flex-start; }
body.page-landing .app-main {
  padding: 2rem 1.1rem 3rem;
  max-width: 28rem;
  margin: 0 auto;
}
.landing { text-align: center; }
.landing .tree-mark { font-size: 3rem; line-height: 1; margin-bottom: .4rem; }
.landing h1 { color: var(--accent); font-size: clamp(1.8rem, 5vw, 2.4rem); margin-bottom: .5rem; }
.landing .card { text-align: left; }
.codes-once { text-align: left; }
.codes-once .kv { grid-template-columns: 7rem 1fr auto; }
.phase-note { font-size: .85rem; color: var(--muted); margin-top: .8rem; }
