:root {
  --paper: #faf8f4;
  --paper-2: #f3efe8;
  --card: #ffffff;
  --ink: #2a2622;
  --ink-2: #5b534c;
  --muted: #8e857c;
  --rule: #e3ddd3;
  --rule-2: #d3cbbf;
  --accent: #8a5a3b;
  --accent-soft: #f1e7de;
  --male: #5d7389;
  --female: #9a6474;
  --danger: #a1443a;
  --ok: #4f7a57;
  --shadow: 0 1px 2px rgba(42, 38, 34, .05), 0 8px 24px -12px rgba(42, 38, 34, .18);
  --serif: "Iowan Old Style", "Palatino Linotype", Palatino, "Book Antiqua", Georgia, serif;
  --sans: "Avenir Next", Avenir, "Segoe UI", system-ui, -apple-system, sans-serif;
  --radius: 10px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --paper: #1b1917; --paper-2: #23201d; --card: #262320;
    --ink: #ece6dd; --ink-2: #c3bab0; --muted: #8f867d;
    --rule: #3a3531; --rule-2: #4a443e;
    --accent: #d1a07c; --accent-soft: #3a2e25;
    --male: #9bb3c9; --female: #d1a1ae;
    --danger: #e08a7f; --ok: #8fc29a;
    --shadow: 0 1px 2px rgba(0,0,0,.3), 0 8px 24px -12px rgba(0,0,0,.6);
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font: 16px/1.6 var(--sans);
  -webkit-font-smoothing: antialiased;
}
a { color: inherit; text-decoration-color: var(--rule-2); text-underline-offset: 3px; }
a:hover { color: var(--accent); text-decoration-color: currentColor; }
img { max-width: 100%; }
[hidden] { display: none !important; }

h1, h2, h3, .serif { font-family: var(--serif); font-weight: 400; letter-spacing: .005em; }
h1 { font-size: clamp(2rem, 4.5vw, 3.1rem); line-height: 1.1; margin: 0 0 .4em; }
h2 { font-size: 1.55rem; margin: 2.2em 0 .8em; }
h3 { font-size: 1.15rem; margin: 1.6em 0 .5em; }
.eyebrow {
  font: 600 .72rem/1 var(--sans);
  letter-spacing: .16em; text-transform: uppercase; color: var(--muted);
}
.muted { color: var(--muted); }
.small { font-size: .875rem; }

/* ---------- layout ---------- */
.wrap { max-width: 1120px; margin: 0 auto; padding-inline: 24px; }
.narrow { max-width: 760px; }

.topbar {
  position: sticky; top: env(safe-area-inset-top, 0px); z-index: 20;
  background: color-mix(in srgb, var(--paper) 88%, transparent);
  backdrop-filter: saturate(1.4) blur(10px);
  -webkit-backdrop-filter: saturate(1.4) blur(10px);
  border-bottom: 1px solid var(--rule);
}
.topbar .wrap { display: flex; align-items: center; gap: 24px; min-height: 64px; flex-wrap: wrap; }
.brand { font-family: var(--serif); font-size: 1.3rem; text-decoration: none; white-space: nowrap; }
.brand span { color: var(--muted); font-size: .95rem; margin-left: .5em; }
.nav { display: flex; gap: 4px; margin-left: auto; flex-wrap: wrap; }
.nav a {
  text-decoration: none; padding: 6px 12px; border-radius: 999px; color: var(--ink-2); font-size: .93rem;
}
.nav a:hover { background: var(--paper-2); color: var(--ink); }
.nav a.active { background: var(--ink); color: var(--paper); }

main { padding-block: 40px 80px; }
footer.site { border-top: 1px solid var(--rule); padding-block: 28px; color: var(--muted); font-size: .85rem; }

/* ---------- hero ---------- */
.hero { padding-block: 48px 24px; text-align: center; }
.hero p.lead { font-family: var(--serif); font-size: 1.25rem; color: var(--ink-2); max-width: 640px; margin: 1em auto 0; line-height: 1.55; }
.ornament { display: flex; align-items: center; gap: 14px; justify-content: center; color: var(--rule-2); margin: 28px auto; max-width: 260px; }
.ornament::before, .ornament::after { content: ""; height: 1px; background: currentColor; flex: 1; }
.ornament span { font-family: var(--serif); color: var(--accent); font-size: 1.1rem; }

.stats { display: flex; justify-content: center; gap: 48px; flex-wrap: wrap; margin: 8px 0 24px; }
.stat { text-align: center; }
.stat b { display: block; font: 400 2rem/1.1 var(--serif); }
.stat span { font-size: .8rem; color: var(--muted); letter-spacing: .08em; text-transform: uppercase; }

/* ---------- search ---------- */
.search {
  display: flex; align-items: center; gap: 10px;
  background: var(--card); border: 1px solid var(--rule); border-radius: 999px;
  padding: 10px 18px; max-width: 520px; margin: 0 auto; box-shadow: var(--shadow);
}
.search input { border: 0; outline: 0; background: transparent; flex: 1; font: inherit; color: var(--ink); min-width: 0; -webkit-appearance: none; appearance: none; }
.search input::-webkit-search-decoration { -webkit-appearance: none; }
.search svg { flex: none; color: var(--muted); }

/* ---------- person cards / lists ---------- */
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: 14px; }
.pcard {
  display: block; text-decoration: none; background: var(--card);
  border: 1px solid var(--rule); border-radius: var(--radius); padding: 14px 16px;
  border-left: 3px solid var(--rule-2); transition: transform .15s, box-shadow .15s, border-color .15s;
}
.pcard:hover { transform: translateY(-1px); box-shadow: var(--shadow); color: inherit; }
.pcard.M { border-left-color: var(--male); }
.pcard.F { border-left-color: var(--female); }
.pcard .n { font-family: var(--serif); font-size: 1.08rem; line-height: 1.3; }
.pcard .n b { font-weight: 400; text-transform: uppercase; letter-spacing: .04em; font-size: .92em; }
.pcard .d { color: var(--muted); font-size: .85rem; margin-top: 2px; }

.surname-group { margin-bottom: 36px; }
.surname-group h3 { display: flex; align-items: baseline; gap: 10px; border-bottom: 1px solid var(--rule); padding-bottom: 6px; margin-bottom: 14px; }
.surname-group h3 small { font: .8rem var(--sans); color: var(--muted); }
.letters { display: flex; flex-wrap: wrap; gap: 6px; margin: 0 0 32px; }
.letters a { text-decoration: none; width: 32px; height: 32px; display: grid; place-items: center; border-radius: 50%; font-family: var(--serif); color: var(--ink-2); }
.letters a:hover { background: var(--paper-2); }

/* ---------- person page ---------- */
.person-head { display: grid; grid-template-columns: 1fr auto; gap: 24px; align-items: end; border-bottom: 1px solid var(--rule); padding-bottom: 28px; }
.person-head h1 b { font-weight: 400; text-transform: uppercase; letter-spacing: .04em; font-size: .86em; }
.person-head .life { font-family: var(--serif); font-size: 1.2rem; color: var(--ink-2); }
.facts { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 0; margin: 28px 0; border: 1px solid var(--rule); border-radius: var(--radius); background: var(--card); overflow: hidden; }
.fact { padding: 16px 20px; border-right: 1px solid var(--rule); border-bottom: 1px solid var(--rule); margin: 0 -1px -1px 0; }
.fact .eyebrow { margin-bottom: 8px; display: block; }
.fact .v { font-family: var(--serif); font-size: 1.1rem; }
.fact .p { color: var(--ink-2); font-size: .93rem; }
.cols { display: grid; grid-template-columns: minmax(0, 1.6fr) minmax(0, 1fr); gap: 48px; }
.bio { font-family: var(--serif); font-size: 1.12rem; line-height: 1.75; white-space: pre-line; overflow-wrap: anywhere; }
.rel-list { display: grid; gap: 8px; }
.rel-label { margin: 22px 0 8px; }

.timeline { list-style: none; padding: 0; margin: 0; border-left: 1px solid var(--rule-2); }
.timeline li { position: relative; padding: 0 0 22px 22px; }
.timeline li::before { content: ""; position: absolute; left: -5px; top: 8px; width: 9px; height: 9px; border-radius: 50%; background: var(--paper); border: 1px solid var(--accent); }
.timeline .when { font-size: .82rem; color: var(--muted); letter-spacing: .04em; }
.timeline .what { font-family: var(--serif); font-size: 1.05rem; }
.timeline .src { font-size: .82rem; color: var(--muted); font-style: italic; }

.docs { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 16px; }
.doc { background: var(--card); border: 1px solid var(--rule); border-radius: var(--radius); overflow: hidden; cursor: zoom-in; text-align: left; padding: 0; font: inherit; color: inherit; }
.doc .thumb { aspect-ratio: 4 / 3; background: var(--paper-2) center / cover no-repeat; display: grid; place-items: center; color: var(--muted); font-family: var(--serif); }
.doc .cap { padding: 10px 14px 12px; }
.doc .cap b { font-weight: 500; display: block; font-size: .93rem; }
.doc .cap span { font-size: .8rem; color: var(--muted); }

/* ---------- lightbox ---------- */
.lightbox { position: fixed; inset: 0; z-index: 100; background: rgba(20, 18, 16, .92); display: grid; grid-template-rows: 1fr auto; padding: 24px; }
.lightbox .stage { overflow: auto; display: grid; place-items: center; }
.lightbox img { max-width: none; width: auto; max-height: calc(100vh - 140px); max-height: calc(100dvh - 140px); cursor: zoom-in; background: #fff; display: block; }
.lightbox img.zoom { max-height: none; width: min(180vw, 3000px); cursor: zoom-out; }
.lightbox .ph { position: relative; line-height: 0; }
.lb-pin { position: absolute; transform: translate(-50%, -50%); pointer-events: none; line-height: 1.2; opacity: 0; transition: opacity .25s; }
.lb-pin i { display: block; width: 12px; height: 12px; margin: 0 auto; border-radius: 50%; border: 2px solid #fff; background: var(--accent); box-shadow: 0 0 0 2px rgba(0,0,0,.35); }
.lb-pin span { position: absolute; left: 50%; top: 16px; transform: translateX(-50%); white-space: nowrap; background: rgba(20,18,16,.8); color: #fff; font-size: .8rem; padding: 2px 9px; border-radius: 999px; }
.lightbox .ph:hover .lb-pin, .lightbox.names-on .lb-pin { opacity: 1; }
.lightbox .bar .kw { font-style: normal; font-size: .75rem; border: 1px solid #666; border-radius: 999px; padding: 0 8px; color: #ccc; }
.lightbox button.names.on { background: #eee; color: #222; }
.lightbox iframe { width: min(1000px, 100%); height: 100%; border: 0; background: #fff; }
.lightbox .lb-main { display: grid; grid-template-columns: minmax(0, 1fr); gap: 18px; min-height: 0; }
.lightbox.tx-on .lb-main { grid-template-columns: minmax(0, 1fr) minmax(300px, 40%); }
.lightbox.tx-on img { max-width: 100%; height: auto; }
.lightbox .lb-tx { overflow-y: auto; background: var(--paper, #faf8f4); color: var(--ink, #2b2620); border-radius: 6px; padding: 18px 22px; }
.lightbox .lb-sum { font-style: italic; margin: 0 0 14px; padding-bottom: 12px; border-bottom: 1px solid #d3cbbf; line-height: 1.5; }
.lightbox .lb-text { font-family: var(--serif); font-size: 1.02rem; line-height: 1.65; white-space: pre-wrap; }
.lightbox button.txb.on { background: #eee; color: #222; }
textarea.tx { min-height: 220px; font-family: var(--serif); line-height: 1.55; }
.lightbox .bar { color: #eee; display: flex; gap: 16px; align-items: center; padding-top: 14px; flex-wrap: wrap; }
.lightbox .bar .t { font-family: var(--serif); font-size: 1.1rem; }
.lightbox .bar .s { color: #aaa; font-size: .85rem; flex: 1; }
.lightbox button { background: transparent; border: 1px solid #666; color: #eee; border-radius: 999px; padding: 6px 16px; cursor: pointer; font: inherit; }

/* ---------- tree ---------- */
.tree-head { display: flex; flex-direction: column; gap: 16px; margin-bottom: 24px; }
/* Barre d'outils sur sa propre ligne, au-dessus du nom : les modes à gauche et le PDF à droite ne bougent pas
   d'une vue ou d'une personne à l'autre ; le sélecteur de générations s'insère entre les deux. */
.tree-tools { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.tree-tools .pdf-menu { margin-left: auto; }
.depth { display: inline-flex; align-items: center; gap: 6px; font-size: .85rem; color: var(--ink-2); }
.depth select { font: inherit; font-size: .85rem; padding: 4px 8px; border: 1px solid var(--rule-2); border-radius: 999px; background: var(--card); color: var(--ink); }
.pdf-menu { position: relative; }
.pdf-pop { position: absolute; right: 0; top: calc(100% + 6px); z-index: 20; min-width: 220px; padding: 6px; display: flex; flex-direction: column;
  background: var(--card); border: 1px solid var(--rule-2); border-radius: 10px; box-shadow: 0 8px 24px rgba(0,0,0,.12); }
.pdf-pop[hidden] { display: none; }
.pdf-pop button { border: 0; background: transparent; text-align: left; padding: 8px 10px; border-radius: 6px; font: inherit; font-size: .88rem; color: var(--ink); cursor: pointer; }
.pdf-pop button:hover { background: var(--paper-2); }
.seg { display: inline-flex; border: 1px solid var(--rule-2); border-radius: 999px; overflow: hidden; }
.seg button { border: 0; background: transparent; padding: 6px 14px; font: inherit; font-size: .85rem; color: var(--ink-2); cursor: pointer; }
.seg button.on { background: var(--ink); color: var(--paper); }
.tree-scroll { position: relative; display: flex; min-height: 320px; overflow: auto; border: 1px solid var(--rule); border-radius: 14px; background:
  radial-gradient(circle at 1px 1px, var(--rule) 1px, transparent 0) 0 0 / 22px 22px, var(--card); }
.tree { position: relative; padding: 40px 32px 48px; min-width: max-content; margin: auto; }
.tree-full { position: sticky; top: 12px; left: 12px; z-index: 2; flex: none; align-self: flex-start; margin: 12px 0 0 12px; }
.tree-scroll:fullscreen { width: 100% !important; height: 100% !important; margin: 0 !important; border: 0; border-radius: 0; }
.tree-scroll:-webkit-full-screen { width: 100% !important; height: 100% !important; margin: 0 !important; border: 0; border-radius: 0; }
.tree svg.links { position: absolute; inset: 0; pointer-events: none; overflow: visible; }
.tree svg.links path { fill: none; stroke: var(--rule-2); stroke-width: 1.2; }
.tree svg.links path.union { stroke: var(--accent); stroke-dasharray: 2 3; }
.gen { display: flex; justify-content: center; gap: 18px; margin-bottom: 46px; }
.gen:last-child { margin-bottom: 0; }
.ped { display: grid; gap: 18px 14px; margin-bottom: 46px; }
.slot { display: flex; justify-content: center; align-items: end; }
.node {
  width: 168px; background: var(--card); border: 1px solid var(--rule-2); border-radius: 9px;
  padding: 10px 12px; text-align: center; cursor: pointer; position: relative; font: inherit; color: inherit;
  border-top: 3px solid var(--rule-2); transition: box-shadow .15s, transform .15s;
}
.node:hover { box-shadow: var(--shadow); transform: translateY(-1px); }
.node.M { border-top-color: var(--male); }
.node.F { border-top-color: var(--female); }
.node .g { font-family: var(--serif); font-size: .98rem; line-height: 1.25; }
.node .s { font-size: .74rem; letter-spacing: .08em; text-transform: uppercase; color: var(--ink-2); }
.node .y { font-size: .78rem; color: var(--muted); margin-top: 3px; }
.node.focus { width: 200px; border-color: var(--accent); box-shadow: 0 0 0 4px var(--accent-soft); }
.node.focus .g { font-size: 1.15rem; }
.node.ghost { border-style: dashed; background: transparent; color: var(--muted); cursor: default; box-shadow: none; transform: none; border-top-width: 1px; }
.node.small { width: 140px; padding: 8px 10px; }
.node .badge { position: absolute; top: -9px; right: -9px; background: var(--accent); color: #fff; font-size: .68rem; width: 18px; height: 18px; border-radius: 50%; display: grid; place-items: center; }
.couple { display: flex; align-items: center; gap: 28px; }
.desc { display: flex; justify-content: center; gap: 22px; align-items: start; }
.desc-col { display: flex; flex-direction: column; align-items: center; gap: 36px; }
.desc-col .gen { margin: 0; gap: 10px; }
.legend { display: flex; gap: 18px; color: var(--muted); font-size: .82rem; margin-top: 14px; flex-wrap: wrap; }
.legend i { display: inline-block; width: 14px; height: 3px; vertical-align: middle; margin-right: 6px; }


/* ---------- multi-tree ---------- */
.nav-group { display: contents; }
.nav-group:not(:empty)::before { content: ""; width: 1px; background: var(--rule); margin: 6px 6px; }
.nav-group.user a { color: var(--accent); }
.tag { display: inline-block; font-size: .72rem; padding: 2px 9px; border-radius: 999px; background: var(--paper-2); color: var(--ink-2); letter-spacing: .02em; }
.tag.priv { background: var(--accent-soft); color: var(--accent); }
.tag.ok { background: color-mix(in srgb, var(--ok) 14%, transparent); color: var(--ok); }
.tag.warn { background: color-mix(in srgb, var(--danger) 12%, transparent); color: var(--danger); }
.tree-list { display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); gap: 18px; }
.tree-card { background: var(--card); border: 1px solid var(--rule); border-radius: 14px; padding: 20px 22px; display: flex; flex-direction: column; gap: 6px; }
.tree-card h3 { margin: 6px 0 0; font-size: 1.35rem; }
.tree-card h3 a { text-decoration: none; }
.tree-card p { margin: 6px 0 0; color: var(--ink-2); font-size: .94rem; }
.tc-head { display: flex; gap: 6px; flex-wrap: wrap; }
.tc-foot { margin-top: auto; padding-top: 14px; display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }

/* ---------- forms & buttons (shared with admin) ---------- */
.btn {
  display: inline-flex; align-items: center; gap: 8px; border: 1px solid var(--rule-2); background: var(--card);
  color: var(--ink); padding: 8px 16px; border-radius: 999px; font: 500 .9rem var(--sans); cursor: pointer; text-decoration: none;
}
.btn:hover { border-color: var(--ink-2); color: var(--ink); }
.btn.primary { background: var(--ink); color: var(--paper); border-color: var(--ink); }
.btn.primary:hover { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.ghost { border-color: transparent; background: transparent; }
.btn.danger { color: var(--danger); }
.btn.danger:hover { border-color: var(--danger); }
.btn.sm { padding: 4px 12px; font-size: .82rem; }

.empty { text-align: center; padding: 64px 16px; color: var(--muted); font-family: var(--serif); font-size: 1.15rem; }

@media (max-width: 820px) {
  .cols { grid-template-columns: 1fr; gap: 8px; }
  .person-head { grid-template-columns: 1fr; }
  .topbar .wrap { gap: 8px; padding-block: 10px; }
  .nav { margin-left: 0; }
  .wrap { padding-inline: 16px; }
  main { padding-block: 24px 64px; }
}

.seg a { display: inline-block; padding: 6px 14px; font-size: .85rem; color: var(--ink-2); text-decoration: none; }
.seg a.on { background: var(--ink); color: var(--paper); }
.seg a:hover:not(.on) { background: var(--paper-2); color: var(--ink); }

/* ---------- constellation 3D ---------- */
.t3d { position: relative; height: min(76vh, 760px); min-height: 320px; margin-top: 18px; border: 1px solid var(--rule); border-radius: var(--radius);
  background: radial-gradient(ellipse at 50% 40%, var(--card) 0%, var(--paper) 70%); overflow: hidden; touch-action: none; user-select: none; -webkit-user-select: none; }
.t3d canvas { display: block; width: 100%; height: 100%; cursor: grab; outline: none; }
.t3d canvas:active { cursor: grabbing; }
/* Nuages de points de la v2 : deux calques flous sous la vue (profondeur de champ), sans effet sur la souris. */
.t3d canvas.t3d-haze { position: absolute; inset: 0; pointer-events: none; }
.t3d canvas.t3d-haze.near { filter: blur(1.2px); }
.t3d canvas.t3d-haze.far { filter: blur(3.5px); }
.t3d canvas.t3d-main { position: relative; }
.t3d-tools { position: absolute; top: 12px; left: 12px; right: 12px; display: flex; gap: 8px; flex-wrap: wrap; align-items: center; pointer-events: none; }
.t3d-tools > * { pointer-events: auto; }
.t3d-tools .seg { background: var(--card); }
.t3d-tools input { font: inherit; font-size: .875rem; padding: 6px 12px; border: 1px solid var(--rule); border-radius: 999px; background: var(--card); color: var(--ink); width: min(240px, 100%); }
.t3d-btn { font: inherit; width: 34px; height: 34px; border-radius: 50%; border: 1px solid var(--rule); background: var(--card); color: var(--ink-2); cursor: pointer; }
.t3d-btn svg { display: block; margin: auto; }
.t3d-btn.on { color: var(--accent); border-color: var(--accent); }
.t3d-card { position: absolute; left: 12px; bottom: 12px; max-width: min(360px, calc(100% - 24px)); background: var(--card); border: 1px solid var(--rule); border-radius: var(--radius); padding: 12px 16px; box-shadow: var(--shadow); }
.t3d-name { font-family: var(--serif); font-size: 1.2rem; }
.t3d-actions { display: flex; gap: 8px; margin-top: 10px; flex-wrap: wrap; }
.t3d-hint { position: absolute; right: 14px; bottom: 10px; font-size: .75rem; color: var(--muted); pointer-events: none; text-align: right; max-width: 50%; }
@media (max-width: 640px) { .t3d-hint { display: none; } }
.t3d:fullscreen { width: 100% !important; height: 100% !important; margin: 0 !important; border: 0; border-radius: 0; }
.t3d:-webkit-full-screen { width: 100% !important; height: 100% !important; margin: 0 !important; border: 0; border-radius: 0; }

/* ---------- Intelligence artificielle : assistant, propositions ---------- */
.ai-panel { position: fixed; top: 0; right: 0; bottom: 0; width: min(440px, 100vw); z-index: 60; background: var(--card); color: var(--ink);
  border-left: 1px solid var(--rule); box-shadow: var(--shadow); display: flex; flex-direction: column; padding: 14px 16px; gap: 10px; }
.ai-head { display: flex; justify-content: space-between; align-items: center; font-family: var(--serif); font-size: 1.1rem; }
.ai-bar { display: flex; gap: 8px; } .ai-bar select { flex: 1; min-width: 0; }
.ai-msgs { flex: 1; overflow-y: auto; display: flex; flex-direction: column; gap: 10px; padding: 4px 2px; }
.ai-msg { padding: 10px 12px; border-radius: 12px; line-height: 1.45; font-size: .93rem; max-width: 92%; overflow-wrap: anywhere; }
.ai-msg.user { align-self: flex-end; background: var(--accent-soft); }
.ai-msg.assistant { align-self: flex-start; background: var(--paper-2); }
.ai-msg.error { align-self: stretch; background: color-mix(in srgb, var(--danger) 12%, transparent); color: var(--danger); }
.ai-msg.wait { opacity: .7; font-style: italic; }
.ai-msg p { margin: 0 0 .6em; }
.ai-msg > :last-child { margin-bottom: 0; }
.ai-msg ul, .ai-msg ol { margin: 0 0 .6em; padding-left: 1.3em; }
.ai-msg li { margin: .15em 0; }
.ai-msg code { font-size: .88em; background: color-mix(in srgb, var(--ink) 8%, transparent); padding: 0 .25em; border-radius: 4px; }
.ai-msg hr { border: 0; border-top: 1px solid var(--rule); margin: .6em 0; }
.ai-tools, .ai-props { margin-top: 8px; font-size: .78rem; color: var(--muted); }
.ai-tools span { display: inline-block; background: var(--card); border: 1px solid var(--rule); border-radius: 6px; padding: 1px 6px; margin: 2px 2px 0 0; }
.ai-tools span.bad { color: var(--danger); border-color: currentColor; }
.ai-props { color: var(--ok); font-weight: 600; }
.ai-form { display: flex; flex-direction: column; gap: 6px; } .ai-form textarea { width: 100%; resize: vertical; }
.ai-foot { display: flex; justify-content: space-between; align-items: center; gap: 10px; }
.ai-empty, .ai-warn { font-size: .88rem; padding: 10px 12px; border-radius: 10px; background: var(--paper-2); }
.ai-warn { background: color-mix(in srgb, var(--danger) 10%, transparent); color: var(--danger); }
.ai-toast { position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%); z-index: 80; background: var(--ink); color: var(--paper);
  padding: 10px 16px; border-radius: 10px; box-shadow: var(--shadow); max-width: 90vw; font-size: .9rem; }
.ai-toast.err { background: var(--danger); color: #fff; }
.ai-token { border: 1px solid var(--rule); border-radius: 12px; padding: 14px 16px; margin-bottom: 16px; background: var(--paper-2); }
.ai-copy { display: block; white-space: pre-wrap; overflow-wrap: anywhere; background: var(--card); border: 1px solid var(--rule); border-radius: 8px;
  padding: 8px 10px; cursor: copy; font-size: .82rem; margin: 4px 0 10px; }
.ai-list { display: grid; gap: 14px; }
.ai-card { border: 1px solid var(--rule); border-radius: 12px; padding: 14px 16px; background: var(--card); }
.ai-card header { margin-bottom: 8px; }
.ai-fields { border-collapse: collapse; width: 100%; font-size: .9rem; margin: 6px 0; }
.ai-fields th { text-align: left; font-weight: 600; color: var(--muted); padding: 4px 10px 4px 0; white-space: nowrap; vertical-align: top; width: 1%; }
.ai-fields td { padding: 4px 8px 4px 0; vertical-align: top; } .ai-fields input, .ai-fields textarea { width: 100%; }
.ai-changed { color: var(--danger); }
.ai-note { margin: 6px 0; padding: 8px 12px; border-left: 3px solid var(--accent); background: var(--paper-2); font-size: .92rem; }
.ai-prov { font-size: .88rem; display: grid; gap: 3px; margin: 8px 0; padding-top: 8px; border-top: 1px dashed var(--rule); }
.st { display: inline-block; font: 600 .66rem/1 var(--sans); letter-spacing: .1em; text-transform: uppercase; padding: 4px 8px; border-radius: 999px; border: 1px solid currentColor; }
.st.ok { color: var(--ok); } .st.warn { color: var(--accent); } .st.bad { color: var(--danger); } .st.new { color: var(--muted); }
.seg .count { display: inline-block; min-width: 1.4em; padding: 0 5px; border-radius: 999px; background: var(--accent); color: #fff; font-size: .72rem; text-align: center; }
.ai-doc { display: grid; grid-template-columns: 160px 1fr; gap: 14px; align-items: start; }
.ai-doc img { width: 100%; border-radius: 8px; border: 1px solid var(--rule); }
@media (max-width: 600px) { .ai-doc { grid-template-columns: 1fr; } }

/* Fiche en superposition, dans la vue plein écran de l'arbre */
.fs-overlay { position: fixed; inset: 0; z-index: 90; display: grid; place-items: center; background: rgba(20, 18, 16, .45); }
.fs-panel { position: relative; width: min(88vw, 1200px); height: 86vh; height: 86dvh; background: var(--paper); color: var(--ink); border-radius: var(--radius);
  box-shadow: 0 20px 60px rgba(0, 0, 0, .35); overflow: hidden; display: flex; }
.fs-body { flex: 1; overflow: auto; padding: 32px clamp(16px, 4vw, 48px); }
.fs-close { position: absolute; top: 10px; right: 12px; z-index: 1; width: 38px; height: 38px; border-radius: 50%; border: 1px solid var(--rule);
  background: var(--card); color: var(--ink); font-size: 1.5rem; line-height: 1; cursor: pointer; }
.fs-close:hover { background: var(--rule); }
@media (max-width: 640px) { .fs-panel { width: 96vw; height: 92vh; height: 92dvh; } }
.flip-layer { position: fixed; pointer-events: none; z-index: 50; overflow: hidden; }
.flip-layer svg { pointer-events: none; overflow: visible; }
.flip-layer svg path { fill: none; stroke: var(--rule-2); stroke-width: 1.2; }
.flip-layer svg path.union { stroke: var(--accent); stroke-dasharray: 2 3; }
.node.phantom { border-style: dashed; border-top-style: dashed; background: transparent; color: var(--muted); box-shadow: none; }
.node.phantom .g { font-style: italic; }

/* ---------- plein écran simulé (Safari sur iPhone ne met pas un élément en plein écran) ---------- */
.pseudo-full { position: fixed !important; inset: 0; z-index: 70; width: auto !important; height: auto !important; margin: 0 !important;
  border: 0 !important; border-radius: 0 !important; padding-top: env(safe-area-inset-top, 0px); padding-bottom: env(safe-area-inset-bottom, 0px); }
html.pseudo-full-on, html.pseudo-full-on body { overflow: hidden; }

/* ---------- petits écrans (téléphones) ---------- */
@media (max-width: 640px) {
  /* Barre du site : ne reste plus collée en haut (elle prenait le quart de l'écran) ; le titre tient sur une ligne,
     les liens défilent latéralement sur une seule ligne au lieu de s'empiler. */
  .topbar { position: static; }
  .topbar .wrap { gap: 2px; padding-block: 8px 4px; min-height: 0; flex-wrap: nowrap; flex-direction: column; align-items: stretch; }
  .brand { font-size: 1.12rem; overflow: hidden; text-overflow: ellipsis; }
  .brand span, .admin-badge { display: none; }
  .nav { flex-wrap: nowrap; overflow-x: auto; margin: 0 -16px; padding: 0 12px 4px; scrollbar-width: none; -webkit-overflow-scrolling: touch; }
  .nav::-webkit-scrollbar { display: none; }
  .nav a { white-space: nowrap; flex: none; padding: 6px 10px; }
  .nav-group:not(:empty)::before { margin: 6px 2px; flex: none; }

  /* Sélecteurs à onglets : une seule ligne qui défile plutôt que des boutons coupés ou sur deux lignes. */
  .seg { max-width: 100%; overflow-x: auto; scrollbar-width: none; }
  .seg::-webkit-scrollbar { display: none; }
  .seg button, .seg a { white-space: nowrap; flex: none; padding-inline: 12px; }

  h1 { font-size: 1.85rem; }
  h2 { font-size: 1.35rem; margin-top: 1.8em; }
  main { padding-block: 18px 48px; }
  .hero { padding-block: 24px 8px; }
  .hero p.lead { font-size: 1.1rem; }
  .stats { display: grid; grid-template-columns: 1fr 1fr; gap: 18px 12px; }
  .stat b { font-size: 1.7rem; }
  .person-head { gap: 14px; padding-bottom: 20px; }
  .facts { margin: 20px 0; }
  .fact { padding: 12px 16px; }
  .bio { font-size: 1.05rem; line-height: 1.65; }
  .docs { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
  .doc .cap { padding: 8px 10px 10px; }
  .tree-list { grid-template-columns: 1fr; }
  .tree-card { padding: 16px; }
  .panel { padding: 16px 14px; border-radius: 12px; }

  /* Arbre : boîtes plus étroites pour voir davantage de monde à la fois. */
  .tree { padding: 28px 16px 32px; }
  .node { width: 132px; padding: 8px 8px; }
  .node.focus { width: 156px; }
  .node.small { width: 116px; }
  .node .g { font-size: .9rem; }
  .node.focus .g { font-size: 1rem; }
  .node .s { font-size: .68rem; }
  .gen { gap: 12px; margin-bottom: 36px; }
  .couple { gap: 18px; }
  .desc { gap: 14px; }
  .legend span:last-child { display: none; }
  .t3d-tools input { width: 100%; order: 9; font-size: 16px; }  /* sous 16 px, iOS zoome la page à la saisie */

  /* Lecture des documents */
  .lightbox { padding: 10px 8px calc(10px + env(safe-area-inset-bottom, 0px)); }
  .lightbox { grid-template-rows: minmax(0, 1fr) auto; background: rgb(20, 18, 16); }
  .lightbox img { max-height: 58vh; max-height: 58dvh; }
  .lightbox.tx-on .lb-main { grid-template-columns: minmax(0, 1fr); grid-template-rows: minmax(0, 1fr) minmax(0, 1fr); gap: 8px; }
  .lightbox.tx-on img { max-height: 32vh; }
  .lightbox .lb-tx { padding: 12px 14px; }
  .lightbox .bar { gap: 8px 12px; max-height: 38vh; overflow-y: auto; }
  .lightbox .bar .s { flex-basis: 100%; }
  .fs-panel { width: 100vw; height: 100%; border-radius: 0; }
  .fs-body { padding: 52px 16px 24px; }

  /* Mon espace : la liste des personnes garde le nom, la naissance et le décès. */
  table.list th, table.list td { padding: 9px 6px; }
  table.list.persons th:nth-child(n+4), table.list.persons td:nth-child(n+4) { display: none; }
  table.list td { font-size: .9rem; }
  table.list.persons td .small { display: none; }  /* lieux masqués : les dates suffisent dans la liste */
  .panel-head .btn { padding: 7px 12px; }
  .ai-panel { padding: 10px 12px calc(10px + env(safe-area-inset-bottom, 0px)); }
}

/* Formulaire de suggestion (contributeur en accès complet) */
.lightbox.suggest { place-items: center; grid-template-rows: 1fr; overflow-y: auto; }
.suggest form { max-width: 640px; width: 100%; background: var(--card); color: var(--ink); margin: auto; }
.suggest label { display: grid; gap: 4px; font-size: 13px; color: var(--muted); margin-top: 10px; }
.suggest input, .suggest select, .suggest textarea { font: inherit; font-size: 16px; color: var(--ink); background: var(--paper);
  border: 1px solid var(--rule-2); border-radius: 8px; padding: 8px 10px; width: 100%; box-sizing: border-box; }
.suggest textarea { min-height: 70px; resize: vertical; }
.sg-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 0 12px; }
.sg-actions { display: flex; gap: 8px; justify-content: flex-end; margin-top: 16px; }
.sg-msg { color: var(--accent, #a33); margin: 10px 0 0; }
@media (max-width: 640px) { .lightbox.suggest { padding: 8px; } .sg-grid { grid-template-columns: 1fr; } }
.sg-modes { margin: 4px 0 6px; }
.sg-who { display: flex; gap: 16px; flex-wrap: wrap; margin-top: 12px; }
.suggest .sg-who label, .suggest .sg-check { display: flex; align-items: center; gap: 6px; font-size: 14px; color: var(--ink); }
.suggest .sg-who input, .suggest .sg-check input { width: auto; }
/* Identité partagée entre arbres */
.twins { list-style: none; padding: 0; margin: 0 0 8px; }
.twins li { padding: 4px 0; }
.twin-actions { display: flex; flex-wrap: wrap; gap: 6px; }
.cands { display: grid; gap: 6px; margin-top: 10px; max-height: 40vh; overflow-y: auto; }
.cand { text-align: left; font: inherit; background: var(--paper); color: var(--ink); border: 1px solid var(--rule-2); border-radius: 8px; padding: 8px 10px; cursor: pointer; display: grid; }
.cand:hover { border-color: var(--accent); }
.share-tw { border: 1px solid var(--rule-2); border-radius: 8px; margin: 10px 0 0; padding: 4px 10px 10px; }
.share-tw legend { font-size: 13px; color: var(--muted); padding: 0 4px; }
.suggest .sg-check { align-items: flex-start; }
