/* Tree: Popsicle (light) + Popsicle Dark (house-design §15). All color through tokens.
   Contrast, measured by scripts/contrast-test.mjs on every deploy (CLAUDE.global §4):
     light: ink #241f33 on bg #f6f5fa = 14.6; muted #6f6885 on surface = 5.0; white on --accent-fill #c94d0c = 4.62;
            --accent-text #b7460b on surface = 5.39; --accent #e2570e carries no text (3.75 with white, which fails).
     dark:  ink #f2eef9 on bg #191625 = 15.4; muted #a69dba on surface #241f33 = 6.6; #2a1206 on accent #ff8a3d = 8.9 */
:root {
  --bg: #f6f5fa; --surface: #ffffff; --surface2: #efedf8; --line: #e2def0;
  --ink: #241f33; --muted: #6f6885; --accent: #e2570e; --accent-ink: #ffffff;
  --accent-fill: #c94d0c; --accent-text: #b7460b;
  --teal: #0a9d90; --teal-text: #066c64; --grape: #6b4de6; --danger: #c43b3b; --danger-ink: #ffffff; --gold: #e0a400;
  --male: #dff0fb; --female: #fbe4ef; --nosex: #efedf8;
  --glass: rgba(255,255,255,.86); --shadow: 0 6px 20px rgba(36,31,51,.10); --radius: 15px;
}
:root[data-theme="dark"] {
  --bg: #191625; --surface: #241f33; --surface2: #2e2840; --line: #3b3352;
  --ink: #f2eef9; --muted: #a69dba; --accent: #ff8a3d; --accent-ink: #2a1206;
  --accent-fill: #ff8a3d; --accent-text: #ff8a3d;
  --teal: #2fd4c4; --teal-text: #2fd4c4; --grape: #ab8dff; --danger: #ff6b78; --danger-ink: #2a0a0e; --gold: #e0b24d;
  --male: #1f3346; --female: #3d2234; --nosex: #2e2840;
  --glass: rgba(25,22,37,.86); --shadow: 0 10px 26px rgba(0,0,0,.42);
}
* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  background: var(--bg); color: var(--ink);
  font-family: ui-rounded, "SF Pro Rounded", "Segoe UI Variable Text", "Nunito", system-ui, sans-serif;
  font-size: 16px; line-height: 1.4; overflow: hidden; overscroll-behavior: none; -webkit-text-size-adjust: 100%;
}
button, input, textarea, select { font: inherit; color: inherit; }
h1, h2, h3 { margin: 0; font-weight: 700; }
h2 { font-size: 22px; display: flex; align-items: center; gap: 8px; }
h3 { font-size: 17px; }
a { color: var(--accent-text); }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.row { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.actions { display: flex; gap: 6px; flex-wrap: wrap; justify-content: flex-end; }
[hidden] { display: none !important; }
.h-ico { width: 26px; height: 26px; }

/* ---- version badge (§26): top right, no header control lives there */
.vbadge { position: fixed; z-index: 200; top: calc(env(safe-area-inset-top, 0px) + 3px); right: calc(env(safe-area-inset-right, 0px) + 6px);
  font-size: 9px; line-height: 1; padding: 2px 5px; border-radius: 6px; background: var(--glass); color: var(--muted); pointer-events: none; font-variant-numeric: tabular-nums; }

/* ---- PIN gate */
.gate { position: fixed; inset: 0; z-index: 90; display: grid; place-items: center; background: var(--bg);
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left); }
.gate-inner { display: flex; flex-direction: column; align-items: center; gap: clamp(6px, 1.5vh, 12px); text-align: center; padding: 12px; }
.gate-logo { width: clamp(48px, 9vh, 72px); height: clamp(48px, 9vh, 72px); }
.gate-title { font-size: clamp(22px, 4vh, 30px); }
.gate-sub { margin: 0; font-size: 15px; color: var(--muted); max-width: 32ch; }
.pin-gate { display: flex; flex-direction: column; align-items: center; gap: clamp(10px, 2.2vh, 20px); margin-top: 6px;
  touch-action: manipulation; -webkit-user-select: none; user-select: none; -webkit-touch-callout: none; }
.pin-dots { display: flex; gap: 10px; }
.pin-dots span { width: 14px; height: 14px; border-radius: 50%; border: 2px solid var(--ink); }
.pin-dots span.on { background: var(--ink); }
.pin-gate.busy .pin-dots span.on { animation: pinpulse .9s ease-in-out infinite; }
@keyframes pinpulse { 50% { opacity: .35; } }
.pin-gate.bad .pin-dots { animation: pinshake .35s; }
@keyframes pinshake { 20%,60% { transform: translateX(-8px); } 40%,80% { transform: translateX(8px); } }
.pin-msg { min-height: 1.3em; font-size: 16px; color: var(--muted); }
.pin-pad { display: grid; grid-template-columns: repeat(3, clamp(64px, 22vw, 84px)); gap: clamp(8px, 1.8vh, 16px); }
.pin-pad button { height: clamp(60px, 9vh, 84px); border-radius: 50%; border: 1px solid var(--line); background: var(--surface); color: var(--ink);
  font-weight: 600; font-size: clamp(26px, 4vh, 32px); line-height: 1; touch-action: manipulation; -webkit-tap-highlight-color: transparent; cursor: pointer; box-shadow: var(--shadow); }
.pin-pad button:active { background: var(--accent-fill); color: var(--accent-ink); }
.pin-pad button:disabled { opacity: .5; }
.pin-pad .pin-del { border: none; background: transparent; font-size: 24px; box-shadow: none; }

/* ---- app frame: fixed chrome, only the middle region scrolls (§3 fallback 3 for long lists) */
.app { position: fixed; inset: 0; display: grid; grid-template-rows: 1fr auto; grid-template-columns: minmax(0, 1fr); }
.views { min-height: 0; position: relative; }
.view { position: absolute; inset: 0; display: grid; grid-template-rows: auto 1fr; grid-template-columns: minmax(0, 1fr); overflow: hidden; }
#view-ask { grid-template-rows: auto 1fr auto; }
.view-head { padding: max(calc(env(safe-area-inset-top, 0px) + 10px), 20px) max(16px, env(safe-area-inset-right)) 10px max(16px, env(safe-area-inset-left)); display: flex; flex-direction: column; gap: 10px; }
.view-head.row { flex-direction: row; flex-wrap: wrap; }
.title-row { display: flex; align-items: center; justify-content: space-between; gap: 10px; flex-wrap: wrap; }
.view-body { min-height: 0; overflow-y: auto; -webkit-overflow-scrolling: touch; overscroll-behavior: contain;
  padding: 2px max(16px, env(safe-area-inset-right)) 18px max(16px, env(safe-area-inset-left)); }
.tabbar { display: flex; justify-content: space-around; background: var(--glass); backdrop-filter: blur(14px); -webkit-backdrop-filter: blur(14px);
  border-top: 1px solid var(--line); padding: 6px max(8px, env(safe-area-inset-right)) calc(env(safe-area-inset-bottom, 0px) + 6px) max(8px, env(safe-area-inset-left)); }
.tabbar button { flex: 1; max-width: 140px; display: flex; flex-direction: column; align-items: center; gap: 2px; border: 0; background: none; color: var(--muted);
  font-size: 12px; font-weight: 600; padding: 4px 0; border-radius: 10px; cursor: pointer; -webkit-tap-highlight-color: transparent; }
.tabbar button .ico { font-size: 21px; line-height: 1; }
.tabbar button.on { color: var(--accent-text); }

/* ---- controls */
.btn { border: 1px solid var(--line); background: var(--surface); color: var(--ink); border-radius: 12px; padding: 9px 14px; font-weight: 600; cursor: pointer;
  touch-action: manipulation; -webkit-tap-highlight-color: transparent; white-space: nowrap; }
.btn.small { padding: 6px 11px; font-size: 14px; border-radius: 10px; }
.btn.accent { background: var(--accent-fill); border-color: var(--accent-fill); color: var(--accent-ink); }
.btn.ghost { background: transparent; }
.btn:disabled { opacity: .55; cursor: default; }
.btn.danger { color: var(--danger); }
.icon-btn { border: 0; background: var(--surface2); color: var(--ink); width: 40px; height: 40px; border-radius: 50%; font-size: 18px; cursor: pointer; flex: none; }
.seg { display: inline-flex; background: var(--surface2); border-radius: 11px; padding: 3px; gap: 2px; }
.seg button { border: 0; background: none; padding: 6px 12px; border-radius: 9px; font-weight: 600; font-size: 14px; color: var(--muted); cursor: pointer; }
.seg button.on { background: var(--surface); color: var(--ink); box-shadow: var(--shadow); }
.search { width: 100%; font-size: 17px; padding: 12px 14px 12px 40px; border-radius: 14px; border: 1px solid var(--line); background: var(--surface) no-repeat 13px 50% / 18px;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%236f6885' stroke-width='2.4' stroke-linecap='round'%3E%3Ccircle cx='11' cy='11' r='7'/%3E%3Cpath d='m20 20-3.5-3.5'/%3E%3C/svg%3E"); }
.search:focus, textarea:focus, input:focus { outline: 2px solid var(--accent); outline-offset: 1px; }
.chips { display: flex; gap: 6px; overflow-x: auto; scrollbar-width: none; padding-bottom: 2px; }
.chips::-webkit-scrollbar { display: none; }
.chip { flex: none; border: 1px solid var(--line); background: var(--surface); border-radius: 999px; padding: 6px 12px; font-size: 14px; font-weight: 600; cursor: pointer; color: var(--ink); white-space: nowrap; }
.chip.on { background: var(--ink); color: var(--bg); border-color: var(--ink); }
.chip .n { font-variant-numeric: tabular-nums; opacity: .8; margin-left: 4px; }
.tag { display: inline-block; font-size: 12px; font-weight: 700; padding: 2px 8px; border-radius: 999px; background: var(--surface2); color: var(--ink); }
.tag.rel { background: color-mix(in srgb, var(--teal) 16%, var(--surface)); color: var(--teal-text); }
.tag.anc { background: color-mix(in srgb, var(--grape) 16%, var(--surface)); color: var(--ink); }

/* ---- cards and lists */
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px; box-shadow: var(--shadow); }
.card + .card, .card + .section-h, .section-h + .card { margin-top: 12px; }
.section-h { font-size: 13px; font-weight: 800; letter-spacing: .04em; text-transform: uppercase; color: var(--muted); margin: 16px 2px 8px; }
.list { display: grid; gap: 8px; grid-template-columns: repeat(auto-fill, minmax(min(100%, 300px), 1fr)); }
.prow { display: flex; gap: 12px; align-items: center; padding: 10px 12px; background: var(--surface); border: 1px solid var(--line); border-radius: 13px; cursor: pointer; text-align: left; width: 100%; color: var(--ink); }
.prow:active { transform: scale(.99); }
.avatar { flex: none; width: 40px; height: 40px; border-radius: 50%; display: grid; place-items: center; font-weight: 800; font-size: 15px; background: var(--nosex); color: var(--ink); }
.avatar.M { background: var(--male); } .avatar.F { background: var(--female); }
.prow .who { min-width: 0; flex: 1; }
.prow .nm { display: block; font-weight: 700; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.prow .meta { display: block; font-size: 13px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.divider { margin: 16px 2px 8px; font-size: 13px; font-weight: 800; color: var(--muted); display: flex; align-items: center; gap: 8px; }
.divider::after { content: ""; flex: 1; height: 1px; background: var(--line); }
.empty { text-align: center; padding: 30px 12px; color: var(--muted); }
.empty .big { font-size: 46px; }
.empty h3 { color: var(--ink); margin: 8px 0 6px; }
.surnames { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 8px; }
.surname { border: 1px solid var(--line); background: var(--surface); border-radius: 12px; padding: 8px 12px; cursor: pointer; text-align: left; color: var(--ink); }
.surname b { display: block; }
.surname span { font-size: 12px; color: var(--muted); }

/* ---- pedigree: columns of 1, 2, 4, 8 (16) boxes that always fit the screen */
.ped-wrap { min-height: 0; overflow: hidden; padding: 0 max(10px, env(safe-area-inset-right)) 10px max(10px, env(safe-area-inset-left)); display: flex; flex-direction: column; gap: 8px; }
.ped { flex: 1; min-height: 0; display: grid; grid-auto-flow: column; grid-auto-columns: minmax(0, 1fr); gap: clamp(6px, 1.4vw, 14px); }
.ped-col { display: flex; flex-direction: column; justify-content: space-around; gap: 3px; min-height: 0; }
.pbox { position: relative; display: flex; flex-direction: column; justify-content: center; min-height: 0; flex: 1 1 0; max-height: 92px; border-radius: 11px; padding: 4px 8px;
  background: var(--surface); border: 1px solid var(--line); border-left: 5px solid var(--nosex); cursor: pointer; text-align: left; color: var(--ink); overflow: hidden; }
.pbox.M { border-left-color: #5aa9e6; } .pbox.F { border-left-color: #e66fa5; }
.pbox.root { border-color: var(--accent); box-shadow: 0 0 0 2px var(--accent); }
.pbox .pn { font-weight: 700; font-size: clamp(11px, 1.6vh, 15px); line-height: 1.15; overflow: hidden; display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; overflow-wrap: anywhere; }
.pbox .py { font-size: clamp(10px, 1.4vh, 13px); color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.pbox.unknown { border-style: dashed; color: var(--muted); cursor: default; background: transparent; }
.pbox.unknown .pn { font-weight: 600; color: var(--muted); }
.ped-kids { display: flex; gap: 6px; overflow-x: auto; align-items: center; min-height: 34px; scrollbar-width: none; }
.ped-kids .label { font-size: 13px; color: var(--muted); flex: none; }

/* ---- person sheet */
.sheet { position: fixed; inset: 0; z-index: 60; background: var(--bg); display: grid; grid-template-rows: auto 1fr; grid-template-columns: minmax(0, 1fr); animation: sheetin .18s ease-out; }
@keyframes sheetin { from { transform: translateY(14px); opacity: .4; } }
.sheet-head { display: flex; align-items: center; gap: 10px; padding: max(calc(env(safe-area-inset-top, 0px) + 8px), 14px) max(12px, env(safe-area-inset-right)) 10px max(12px, env(safe-area-inset-left));
  border-bottom: 1px solid var(--line); background: var(--glass); backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px); }
.sheet-title { flex: 1; min-width: 0; }
.sheet-name { font-size: 20px; font-weight: 800; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sheet-sub { font-size: 14px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sheet-body { min-height: 0; overflow-y: auto; -webkit-overflow-scrolling: touch; overscroll-behavior: contain; padding: 14px max(16px, env(safe-area-inset-right)) calc(env(safe-area-inset-bottom, 0px) + 24px) max(16px, env(safe-area-inset-left)); }
.sheet-grid { display: grid; gap: 14px; grid-template-columns: repeat(auto-fit, minmax(min(100%, 380px), 1fr)); align-items: start; max-width: 1400px; margin: 0 auto; }
.hero { display: flex; gap: 14px; align-items: center; flex-wrap: wrap; }
.hero .avatar { width: 64px; height: 64px; font-size: 24px; }
.hero-tags { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 6px; }
.hero-actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 12px; }
.brief { margin-top: 12px; padding: 12px 14px; border-radius: 12px; background: var(--surface2); white-space: pre-wrap; }
.brief.thinking { color: var(--muted); }
.fact { display: grid; grid-template-columns: 74px 1fr; gap: 2px 12px; padding: 10px 0; border-top: 1px solid var(--line); }
.fact:first-child { border-top: 0; }
.fact .yr { font-weight: 800; font-variant-numeric: tabular-nums; color: var(--accent-text); }
.fact .what { font-weight: 700; }
.fact .where, .fact .date { color: var(--muted); font-size: 14px; }
.fact details { grid-column: 2; font-size: 14px; }
.fact summary, .card summary { cursor: pointer; color: var(--teal-text); font-weight: 600; font-size: 14px; }
.cite { margin: 6px 0 0; padding: 8px 10px; border-radius: 10px; background: var(--surface2); overflow-wrap: anywhere; }
.cite .st { font-weight: 700; }
.fam-group + .fam-group { margin-top: 12px; }
.fam-group .lbl { font-size: 13px; font-weight: 800; color: var(--muted); margin-bottom: 6px; }
.fam-group .list { grid-template-columns: repeat(auto-fill, minmax(min(100%, 240px), 1fr)); }
.copy { border: 0; background: none; cursor: pointer; padding: 2px 4px; font-size: 14px; color: var(--muted); vertical-align: middle; }
.photos { display: grid; grid-template-columns: repeat(auto-fill, minmax(110px, 1fr)); gap: 8px; }
.photos figure { margin: 0; }
.photos img { width: 100%; aspect-ratio: 1; object-fit: cover; border-radius: 10px; display: block; background: var(--surface2); }
.photos a.doc { display: grid; place-items: center; aspect-ratio: 1; border-radius: 10px; background: var(--surface2); font-size: 32px; text-decoration: none; }
.photos figcaption { font-size: 12px; color: var(--muted); margin-top: 3px; }
.note-row { display: flex; gap: 10px; align-items: flex-start; padding: 8px 0; border-top: 1px solid var(--line); }
.note-row:first-child { border-top: 0; }
.note-row .txt { flex: 1; white-space: pre-wrap; overflow-wrap: anywhere; }
.note-row.done .txt { text-decoration: line-through; color: var(--muted); }
.note-row input[type=checkbox] { width: 22px; height: 22px; margin-top: 1px; accent-color: var(--teal); }
textarea.note-in { width: 100%; min-height: 70px; font-size: 16px; padding: 10px; border-radius: 12px; border: 1px solid var(--line); background: var(--surface); resize: vertical; }

/* ---- issues */
.issue { padding: 12px; background: var(--surface); border: 1px solid var(--line); border-radius: 13px; border-left: 5px solid var(--line); }
.issue.s3 { border-left-color: var(--danger); } .issue.s2 { border-left-color: var(--gold); } .issue.s1 { border-left-color: var(--teal); }
.issue .d { margin-bottom: 8px; }
.issue .ppl { display: flex; gap: 6px; flex-wrap: wrap; align-items: center; }
.issue-help { margin: 2px 2px 12px; color: var(--muted); font-size: 14px; }
.issues { display: grid; gap: 8px; grid-template-columns: repeat(auto-fill, minmax(min(100%, 420px), 1fr)); }

/* ---- chat */
.chat-body { display: flex; flex-direction: column; gap: 12px; }
.msg { max-width: min(760px, 92%); padding: 10px 14px; border-radius: 16px; overflow-wrap: anywhere; }
.msg.user { align-self: flex-end; background: var(--accent-fill); color: var(--accent-ink); border-bottom-right-radius: 6px; white-space: pre-wrap; }
.msg.assistant { align-self: flex-start; background: var(--surface); border: 1px solid var(--line); border-bottom-left-radius: 6px; }
.msg.assistant p { margin: 0 0 8px; } .msg.assistant p:last-child { margin-bottom: 0; }
.msg.assistant ul, .msg.assistant ol { margin: 4px 0 8px; padding-left: 22px; }
.msg.assistant a.plink { font-weight: 700; color: var(--teal-text); text-decoration: none; border-bottom: 1px dotted currentColor; }
.msg.thinking { color: var(--muted); }
.steps { font-size: 13px; color: var(--muted); margin-top: 8px; }
.steps summary { cursor: pointer; }
.suggest { display: flex; flex-wrap: wrap; gap: 8px; justify-content: center; margin-top: 10px; }
.ask-form { padding: 8px max(12px, env(safe-area-inset-right)) 8px max(12px, env(safe-area-inset-left)); border-top: 1px solid var(--line); background: var(--glass); }
.ask-row { display: flex; gap: 8px; align-items: flex-end; max-width: 980px; margin: 0 auto; }
.ask-row textarea { flex: 1; resize: none; font-size: 16px; padding: 10px 12px; border-radius: 14px; border: 1px solid var(--line); background: var(--surface); max-height: 140px; }
.ask-focus { max-width: 980px; margin: 0 auto 6px; font-size: 13px; color: var(--muted); display: flex; gap: 8px; align-items: center; }

/* ---- drawer, drop veil, toast */
.drawer { position: fixed; inset: 0; z-index: 70; background: rgba(0,0,0,.35); display: grid; place-items: center; padding: 16px; }
.drawer-card { width: min(520px, 100%); max-height: min(80vh, 640px); display: grid; grid-template-rows: auto 1fr; gap: 10px; background: var(--bg); border-radius: 18px; padding: 16px; box-shadow: var(--shadow); }
.drawer-body { overflow-y: auto; display: grid; gap: 6px; align-content: start; }
.drop-veil { position: fixed; inset: 0; z-index: 150; display: grid; place-items: center; text-align: center; font-size: 22px; font-weight: 800;
  background: color-mix(in srgb, var(--bg) 85%, transparent); border: 4px dashed var(--accent); pointer-events: none; }
.drop { border: 2px dashed var(--line); border-radius: 14px; padding: 18px; text-align: center; color: var(--muted); margin-top: 10px; }
.drop.over { border-color: var(--accent); color: var(--ink); }
.toast { position: fixed; z-index: 160; left: 50%; transform: translateX(-50%); bottom: calc(env(safe-area-inset-bottom, 0px) + 76px); max-width: min(92vw, 520px);
  background: var(--ink); color: var(--bg); padding: 11px 16px; border-radius: 14px; font-weight: 600; box-shadow: var(--shadow); text-align: center; }
.toast.bad { background: var(--danger); color: var(--danger-ink); }
.progress { margin-top: 10px; color: var(--muted); }
.bar { height: 8px; border-radius: 99px; background: var(--surface2); overflow: hidden; margin-top: 6px; }
.bar > i { display: block; height: 100%; width: 40%; background: var(--accent); border-radius: 99px; animation: barslide 1.3s ease-in-out infinite; }
@keyframes barslide { 0% { transform: translateX(-100%); } 100% { transform: translateX(260%); } }
table.kv { width: 100%; border-collapse: collapse; font-size: 14px; }
table.kv td, table.kv th { text-align: left; padding: 6px 4px; border-top: 1px solid var(--line); vertical-align: top; }
table.kv th { color: var(--muted); font-weight: 700; }
.table-scroll { overflow-x: auto; }
details.group { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px 14px; }
details.group + details.group { margin-top: 10px; }
details.group > summary { font-weight: 800; cursor: pointer; list-style: none; display: flex; justify-content: space-between; color: var(--ink); font-size: 16px; }
details.group > summary::after { content: "▸"; color: var(--muted); }
details.group[open] > summary::after { content: "▾"; }
details.group > summary::-webkit-details-marker { display: none; }
details.group > .inner { margin-top: 10px; }

@media (min-width: 900px) {
  .tabbar { justify-content: center; gap: 12px; }
}
