:root {
  --bg:      #F7F3EE;
  --card:    #FFFFFF;
  --primary: #6B4226;
  --prim-dk: #4E2F1A;
  --accent:  #D4894A;
  --male:    #3D6B9E;
  --female:  #9E3D6B;
  --text:    #1A1008;
  --muted:   #8A7060;
  --border:  #E2D8CE;
  --danger:  #B92B27;
  --r:       16px;
  --rs:      10px;
  --sh:      0 2px 14px rgba(0,0,0,.10);
  --tap:     50px;
}

/* ── Dark mode ───────────────────────────────────────────────── */
.dark {
  --bg:      #111318;
  --card:    #1C2028;
  --primary: #8B5A3C;
  --prim-dk: #6B4226;
  --accent:  #C87D3E;
  --male:    #2A4F7A;
  --female:  #7A2A50;
  --text:    #EDE8E2;
  --muted:   #9A8E84;
  --border:  #2E3340;
  --bg-inp:  #242830;
}
.dark .inp,
.dark #search  { background: var(--bg-inp); color: var(--text); border-color: var(--border); }
.dark .inp:focus,
.dark #search:focus { border-color: var(--accent); background: #2a303c; }
.dark .gbtn    { background: var(--bg-inp); color: var(--muted); border-color: var(--border); }
.dark .list-item:active,
.dark .spouse-card:active { background: #242830; }
.dark .tree-ctrl { background: var(--card); border-color: var(--border); color: var(--text); }
.dark #tree-svg rect[fill="#fff"] { fill: var(--card) !important; }

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html, body {
  height: 100%; overflow: hidden;
  font-family: -apple-system, 'Segoe UI', system-ui, sans-serif;
  background: var(--bg); color: var(--text);
  -webkit-font-smoothing: antialiased;
}

/* ── Firebase banner ─────────────────── */
#firebase-banner {
  position: fixed; top: 0; left: 0; right: 0; z-index: 40;
  background: #fff3cd; color: #856404;
  font-size: .78rem; padding: 6px 14px;
  text-align: center; border-bottom: 1px solid #ffc107;
}
#firebase-banner a { color: #856404; font-weight: 700; }
#firebase-banner ~ header { top: 30px; }
#firebase-banner ~ .view   { top: 86px; }

/* ── Header ─────────────────────────── */
header {
  position: fixed; top: 0; left: 0; right: 0; z-index: 30;
  height: 56px;
  background: var(--primary);
  color: #fff;
  display: flex; align-items: center;
  padding: 0 10px;
  box-shadow: 0 2px 8px rgba(0,0,0,.2);
}
header h1 { flex: 1; text-align: center; font-size: 1.05rem; font-weight: 700; letter-spacing: .01em; }
.hdr-btn {
  width: 36px; height: 36px;
  border: none; background: transparent; color: rgba(255,255,255,.9);
  border-radius: 50%; cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0;
  -webkit-tap-highlight-color: transparent;
  transition: background .12s;
}
.hdr-btn:active { background: rgba(255,255,255,.22); }
.hdr-btn svg { width: 19px; height: 19px; stroke: currentColor; fill: none; }
.hdr-btn.hidden { visibility: hidden; pointer-events: none; }
.tree-ctrl svg { width: 17px; height: 17px; stroke: var(--text); fill: none; }
.fab svg { width: 22px; height: 22px; stroke: #fff; stroke-width: 2.5; fill: none; }
.aitem .ai svg { stroke: var(--primary); }
.aitem.danger .ai svg { stroke: var(--danger); }
.focus-acts svg { width: 14px; height: 14px; fill: none; stroke: currentColor; display: inline-block; vertical-align: middle; margin-right: 3px; position: relative; top: -1px; }

/* ── Views ──────────────────────────── */
.view {
  position: fixed; top: 56px; left: 0; right: 0; bottom: 0;
  overflow-y: auto; -webkit-overflow-scrolling: touch;
  padding: 16px 14px 80px;
}
.hidden { display: none !important; }

/* ── Splash ─────────────────────────── */
#view-empty { display: flex; align-items: center; justify-content: center; }
.splash { text-align: center; max-width: 300px; padding: 20px; }
.splash-icon { font-size: 72px; margin-bottom: 16px; }
.splash h2 { font-size: 1.4rem; margin-bottom: 10px; }
.splash p { color: var(--muted); line-height: 1.5; margin-bottom: 28px; }

/* ── Buttons ─────────────────────────── */
.btn-primary, .btn-secondary, .btn-danger {
  display: flex; align-items: center; justify-content: center;
  width: 100%; height: var(--tap);
  border: none; border-radius: var(--rs);
  font-size: 1rem; font-weight: 700; cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  font-family: inherit;
}
.btn-primary  { background: var(--primary); color: #fff; }
.btn-primary:active  { background: var(--prim-dk); }
.btn-secondary { background: var(--border); color: var(--text); }
.btn-secondary:active { filter: brightness(.94); }
.btn-danger   { background: #fde8e8; color: var(--danger); }
.btn-danger:active { filter: brightness(.94); }

/* ── Navigator zones ─────────────────── */
.zone { margin-bottom: 14px; }
.zone-lbl {
  font-size: 0.72rem; font-weight: 800;
  text-transform: uppercase; letter-spacing: .08em;
  color: var(--muted); margin-bottom: 8px;
}
.two-slots { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }

/* ── Focus card ─────────────────────── */
.focus-card {
  background: var(--card);
  border-radius: var(--r);
  padding: 22px 18px 16px;
  box-shadow: var(--sh);
  display: flex; flex-direction: column; align-items: center; gap: 8px;
  margin-bottom: 14px;
}
.focus-av {
  width: 88px; height: 88px; border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-size: 40px; flex-shrink: 0;
}
.focus-av img { width: 88px; height: 88px; border-radius: 50%; object-fit: cover; }
.av-m { background: #D7E6F5; }
.av-f { background: #F5D7E6; }
.focus-name { font-size: 1.3rem; font-weight: 800; text-align: center; }
.focus-dates { font-size: .85rem; color: var(--muted); }
.focus-flags { font-size: 1.4rem; letter-spacing: 2px; }
.focus-loc   { font-size: .82rem; color: var(--muted); }
.focus-note { font-size: .83rem; color: var(--muted); text-align: center; line-height: 1.5; }
.lang-btn { font-size: .7rem; font-weight: 800; letter-spacing: .06em; }
.focus-acts { display: flex; gap: 8px; width: 100%; margin-top: 6px; }
.focus-acts button {
  flex: 1; height: 42px;
  border: 1.5px solid var(--border); border-radius: var(--rs);
  background: #fff; font-size: .88rem; cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  font-family: inherit;
}
.focus-acts button:active { background: var(--bg); }

/* ── Person pill (parent / child / sibling) ── */
.pill {
  background: var(--card);
  border-radius: var(--rs);
  padding: 10px 8px;
  display: flex; flex-direction: column; align-items: center; gap: 5px;
  box-shadow: var(--sh); cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  border: 2px solid transparent;
  min-height: var(--tap); transition: border-color .15s;
  user-select: none;
}
.pill:active, .pill.pressed { border-color: var(--accent); }

.pill-av {
  width: 46px; height: 46px; border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-size: 22px;
}
.pill-av img { width: 46px; height: 46px; border-radius: 50%; object-fit: cover; }
.pill-name { font-size: .78rem; font-weight: 700; text-align: center; line-height: 1.2; }
.pill-yr   { font-size: .68rem; color: var(--muted); }

/* ── Add slot ────────────────────────── */
.add-slot {
  background: var(--card);
  border: 2px dashed var(--border);
  border-radius: var(--rs);
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 4px; cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  min-height: 90px; color: var(--muted); font-size: .8rem; font-weight: 600;
  font-family: inherit; width: 100%;
}
.add-slot .plus { font-size: 1.5rem; line-height: 1; }
.add-slot:active { background: var(--border); }

/* ── Spouse card ─────────────────────── */
.spouse-card, .spouse-add {
  background: var(--card);
  border-radius: var(--r);
  padding: 16px;
  display: flex; align-items: center; gap: 14px;
  box-shadow: var(--sh); cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
}
.spouse-card:active { background: #f5f0eb; }
.spouse-add {
  border: 2px dashed var(--border); background: var(--card);
  color: var(--muted); font-size: .9rem; font-weight: 700;
}
.spouse-add:active { background: var(--border); }
.spouse-av {
  width: 58px; height: 58px; border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-size: 28px; flex-shrink: 0;
}
.spouse-av img { width: 58px; height: 58px; border-radius: 50%; object-fit: cover; }
.spouse-info { flex: 1; min-width: 0; }
.spouse-name { font-size: 1rem; font-weight: 700; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.spouse-meta { font-size: .8rem; color: var(--muted); margin-top: 2px; }
.chevron { font-size: 1.4rem; color: var(--muted); flex-shrink: 0; }

/* ── Children / siblings row ─────────── */
.hscroll {
  display: flex; gap: 10px;
  overflow-x: auto; -webkit-overflow-scrolling: touch;
  padding-bottom: 6px; scrollbar-width: none;
}
.hscroll::-webkit-scrollbar { display: none; }
.hcard { flex-shrink: 0; width: 88px; }
.add-child-btn {
  flex-shrink: 0; width: 88px;
  background: var(--card); border: 2px dashed var(--border);
  border-radius: var(--rs); min-height: 90px;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 4px; cursor: pointer; color: var(--muted); font-size: .78rem; font-weight: 700;
  -webkit-tap-highlight-color: transparent; font-family: inherit;
}
.add-child-btn .plus { font-size: 1.4rem; }
.add-child-btn:active { background: var(--border); }

/* ── List view ───────────────────────── */
.list-toolbar {
  display: flex; gap: 8px; align-items: center; margin-bottom: 12px; flex-wrap: wrap;
}
.search-wrap {
  flex: 1; min-width: 0; position: relative; display: flex; align-items: center;
}
.search-icon {
  position: absolute; left: 12px;
  width: 16px; height: 16px;
  stroke: var(--muted); fill: none; stroke-width: 2;
  pointer-events: none;
}
#search {
  width: 100%; height: var(--tap);
  border: 1.5px solid var(--border); border-radius: var(--rs);
  padding: 0 14px 0 36px; font-size: 16px; background: var(--card); outline: none;
  font-family: inherit; color: var(--text);
}
#search:focus { border-color: var(--primary); }
#search:focus + .search-icon, .search-wrap:focus-within .search-icon { stroke: var(--primary); }
.pill-btn {
  height: 40px; padding: 0 14px;
  background: var(--card); border: 1.5px solid var(--border);
  border-radius: var(--rs); font-size: .82rem; font-weight: 700;
  cursor: pointer; white-space: nowrap;
  -webkit-tap-highlight-color: transparent; font-family: inherit;
  display: inline-flex; align-items: center; justify-content: center;
  color: var(--text);
}
.pill-btn:active { background: var(--border); }

.list-item {
  background: var(--card);
  border-radius: var(--r);
  padding: 14px; margin-bottom: 9px;
  display: flex; align-items: center; gap: 14px;
  box-shadow: var(--sh); cursor: pointer;
  -webkit-tap-highlight-color: transparent; user-select: none;
}
.list-item:active { background: #f5f0eb; }
.list-av {
  width: 50px; height: 50px; border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-size: 24px; flex-shrink: 0;
}
.list-av img { width: 50px; height: 50px; border-radius: 50%; object-fit: cover; }
.list-name { font-weight: 700; font-size: 1rem; }
.list-meta { font-size: .8rem; color: var(--muted); margin-top: 3px; }

.fab {
  position: fixed; right: 20px; bottom: 28px;
  width: 58px; height: 58px; border-radius: 50%;
  background: var(--primary); color: #fff;
  font-size: 1.8rem; border: none;
  box-shadow: 0 4px 18px rgba(0,0,0,.25);
  cursor: pointer; display: flex; align-items: center; justify-content: center;
  -webkit-tap-highlight-color: transparent; z-index: 10;
}
.fab:active { background: var(--prim-dk); }

/* ── Tree view ───────────────────────── */
#view-tree { padding: 0; overflow: hidden; }

#tree-svg {
  width: 100%; height: 100%;
  cursor: grab; user-select: none;
  touch-action: none;
}
#tree-svg:active { cursor: grabbing; }

#tree-controls {
  position: absolute;
  bottom: 24px; right: 16px;
  display: flex; flex-direction: column; gap: 8px;
}
.tree-ctrl {
  width: 44px; height: 44px;
  background: var(--card); border: 1.5px solid var(--border);
  border-radius: 50%; font-size: 1.1rem;
  box-shadow: var(--sh); cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  -webkit-tap-highlight-color: transparent;
}
.tree-ctrl:active { background: var(--bg); }

#tree-tip {
  position: absolute; bottom: 18px; left: 50%; transform: translateX(-50%);
  background: rgba(0,0,0,.55); color: #fff;
  font-size: .72rem; padding: 5px 12px; border-radius: 20px;
  white-space: nowrap; pointer-events: none;
  animation: fadeOut 4s forwards 2s;
}
@keyframes fadeOut { to { opacity: 0; } }

/* ── Overlay & Sheet ─────────────────── */
.overlay {
  position: fixed; inset: 0;
  background: rgba(0,0,0,.5);
  z-index: 60; display: flex; align-items: flex-end;
}
.sheet {
  background: var(--card);
  border-radius: var(--r) var(--r) 0 0;
  padding: 0 18px 44px;
  width: 100%; max-height: 92vh;
  overflow-y: auto; -webkit-overflow-scrolling: touch;
  animation: up .22s ease;
}
@keyframes up { from { transform: translateY(100%); } to { transform: translateY(0); } }
.handle {
  width: 38px; height: 4px; background: var(--border);
  border-radius: 2px; margin: 12px auto 18px;
}
.sheet h2 { font-size: 1.15rem; color: var(--primary); margin-bottom: 16px; }

/* ── Form ────────────────────────────── */
.lbl { display: block; font-size: .8rem; font-weight: 800; color: var(--muted); margin: 14px 0 5px; }
.inp {
  width: 100%; height: var(--tap);
  border: 1.5px solid var(--border); border-radius: var(--rs);
  padding: 0 14px; font-size: 16px; background: var(--bg);
  color: var(--text); outline: none; font-family: inherit;
}
.inp:focus { border-color: var(--primary); background: #fff; }
textarea.inp { height: auto; padding: 12px 14px; resize: none; }
.row2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.gender-row { display: flex; gap: 8px; }
.gbtn {
  flex: 1; height: var(--tap);
  border: 2px solid var(--border); border-radius: var(--rs);
  background: #fff; font-size: .9rem; font-weight: 700;
  cursor: pointer; color: var(--muted);
  -webkit-tap-highlight-color: transparent; font-family: inherit;
}
.gbtn.active { border-color: var(--primary); background: var(--primary); color: #fff; }
.photo-preview {
  width: 64px; height: 64px; border-radius: 50%;
  object-fit: cover; margin: 8px auto 0; display: block;
  border: 2px solid var(--border);
}
.form-btns { display: flex; flex-direction: column; gap: 10px; margin-top: 22px; }

/* ── Action sheet ────────────────────── */
.action-title { font-size: .9rem; font-weight: 800; color: var(--muted); margin-bottom: 6px; }
.aitem {
  display: flex; align-items: center; gap: 14px;
  width: 100%; background: none; border: none;
  padding: 16px 0; font-size: .98rem; cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  border-bottom: 1px solid var(--border); color: var(--text);
  font-family: inherit; text-align: left;
}
.aitem:last-of-type { border-bottom: none; }
.aitem:active { background: var(--bg); }
.aitem.danger { color: var(--danger); }
.aitem .ai { width: 32px; display: flex; align-items: center; justify-content: center; flex-shrink: 0; }
.aitem .ai svg { width: 18px; height: 18px; stroke: currentColor; stroke-width: 2; fill: none; }
.aitem.danger .ai svg { stroke: var(--danger); }
.focus-acts svg { width: 15px; height: 15px; stroke: currentColor; stroke-width: 2; fill: none; vertical-align: middle; margin-right: 4px; }
.aitem-sub { font-size: .78rem; color: var(--muted); margin-top: 2px; }
