:root {
  --green: #4a6b52;
  --green-dark: #3a5541;
  --bg: #f5f3ee;
  --card: #ffffff;
  --ink: #2b2b2b;
  --muted: #7a7a7a;
  --line: #e3e0d8;
  --pink: #b5657d;
  --blue: #4f7a99;
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; padding: 0; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: var(--bg); color: var(--ink);
  font-size: 18px; line-height: 1.4;
}
#app { max-width: 640px; margin: 0 auto; padding: 0 16px calc(40px + env(safe-area-inset-bottom)); }
.loading { text-align: center; padding: 60px 0; color: var(--muted); }

/* Header */
.topbar {
  position: sticky; top: 0; z-index: 5;
  background: var(--bg); padding: 14px 0 10px;
  display: flex; align-items: center; gap: 12px;
}
.topbar h1 { font-size: 20px; margin: 0; flex: 1; }
.topbar .back { font-size: 26px; background: none; border: none; color: var(--green); cursor: pointer; padding: 4px 6px; }
.linkbtn { background: none; border: none; color: var(--green); font-size: 15px; cursor: pointer; text-decoration: underline; }

/* Buttons */
button { font-family: inherit; }
.btn {
  display: block; width: 100%; padding: 15px 18px; margin: 10px 0;
  font-size: 18px; font-weight: 600; border-radius: 14px; border: none;
  background: var(--green); color: #fff; cursor: pointer; text-align: center;
}
.btn:active { background: var(--green-dark); }
.btn.secondary { background: #fff; color: var(--green); border: 2px solid var(--green); }
.btn.ghost { background: #efece4; color: var(--ink); }
.btn-row { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.btn-row .btn { margin: 0; }

/* Inputs */
label { display: block; font-size: 14px; color: var(--muted); margin: 14px 0 4px; }
input, select {
  width: 100%; padding: 14px; font-size: 18px; border: 2px solid var(--line);
  border-radius: 12px; background: #fff; color: var(--ink);
}
input:focus, select:focus { outline: none; border-color: var(--green); }

/* Search */
.search { position: relative; margin: 6px 0 14px; }
.search input { padding-left: 44px; }
.search::before { content: "🔍"; position: absolute; left: 14px; top: 13px; font-size: 18px; }

/* Person cards / rows */
.person-row {
  display: flex; align-items: center; gap: 14px; width: 100%;
  background: var(--card); border: 1px solid var(--line); border-radius: 14px;
  padding: 12px 14px; margin: 8px 0; cursor: pointer; text-align: left;
}
.person-row:active { background: #faf8f3; }
.avatar {
  width: 46px; height: 46px; border-radius: 50%; flex: 0 0 46px;
  display: flex; align-items: center; justify-content: center;
  font-weight: 700; color: #fff; font-size: 18px; background: var(--muted);
}
.avatar.f { background: var(--pink); }
.avatar.m { background: var(--blue); }
.avatar.has-photo { background-size: cover; background-position: center; }
.person-row .meta { flex: 1; min-width: 0; }
.person-row .name { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.person-row .sub { font-size: 14px; color: var(--muted); }
.chev { color: var(--muted); font-size: 22px; }

/* Person detail header */
.hero { text-align: center; padding: 18px 0 8px; }
.hero .avatar { width: 88px; height: 88px; flex-basis: 88px; font-size: 34px; margin: 0 auto 10px; }
.hero h2 { margin: 0; font-size: 24px; }
.hero .nameline { display: inline-flex; align-items: center; gap: 6px; }
.hero .realname { color: var(--muted); margin-top: 2px; font-size: 15px; }
.hero .years { display: inline-flex; align-items: center; gap: 6px; color: var(--muted); margin-top: 4px; }
.pencil { background: none; border: none; cursor: pointer; font-size: 15px; line-height: 1; padding: 4px; opacity: .55; }
.pencil:active { opacity: 1; }

/* Sections */
.section { margin-top: 22px; }
.section h3 { font-size: 14px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); margin: 0 0 8px; }
.rel-group { margin-bottom: 6px; }
.rel-label { font-size: 13px; color: var(--muted); margin: 10px 0 2px; }
.empty { color: var(--muted); font-style: italic; padding: 6px 0; }

/* Family graph (2 generations) */
.graph-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; margin: 2px -16px 0; padding: 8px 16px; }
.graph { position: relative; margin: 0 auto; }
.graph-lines { position: absolute; top: 0; left: 0; pointer-events: none; }
.gline { stroke: var(--line); stroke-width: 2; }
.gline.marriage { stroke: var(--line); stroke-width: 3; }
.gchip { display: flex; flex-direction: column; align-items: center; gap: 5px; width: 66px; background: none; border: none; padding: 0; cursor: pointer; z-index: 1; }
.gchip .gav {
  width: 50px; height: 50px; border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  color: #fff; font-weight: 700; font-size: 17px; background-color: var(--muted);
  background-size: cover; background-position: center;
}
.gchip.f .gav { background-color: var(--pink); }
.gchip.m .gav { background-color: var(--blue); }
.gchip.me .gav { box-shadow: 0 0 0 3px var(--green); }
.gchip .gname { font-size: 12px; line-height: 1.2; text-align: center; max-width: 66px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.gchip.me .gname { font-weight: 700; }
/* Inline "add relative" nodes */
.gchip.gadd .gav { background-color: transparent; border: 2px dashed var(--line); color: var(--muted); font-weight: 400; }
.gchip.gadd .gname { color: var(--muted); }
.gchip.gadd:active .gav { border-color: var(--green); color: var(--green); }

/* Modal */
.modal-back {
  position: fixed; inset: 0; background: rgba(0,0,0,.4);
  display: flex; align-items: flex-end; justify-content: center; z-index: 20;
}
.modal {
  background: var(--bg); width: 100%; max-width: 640px;
  border-radius: 20px 20px 0 0; padding: 20px 18px calc(24px + env(safe-area-inset-bottom));
  max-height: 92vh; overflow-y: auto;
}
.modal h3 { margin: 0 0 4px; font-size: 20px; }
.modal .hint { color: var(--muted); font-size: 14px; margin-bottom: 6px; }
.seg { display: flex; gap: 8px; margin-top: 6px; }
.seg button {
  flex: 1; padding: 13px; border-radius: 12px; border: 2px solid var(--line);
  background: #fff; font-size: 16px; cursor: pointer; color: var(--ink);
}
.seg button.on { border-color: var(--green); background: #eef3ee; font-weight: 700; }

/* Toast */
.toast {
  position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%);
  background: #2b2b2b; color: #fff; padding: 12px 18px; border-radius: 24px;
  font-size: 15px; z-index: 50; max-width: 90%; text-align: center;
}

.msg { padding: 10px 14px; border-radius: 12px; margin: 10px 0; font-size: 15px; }
.msg.err { background: #fbe6e6; color: #9a2a2a; }
.center { text-align: center; }
.spacer { height: 8px; }
.applogo { font-size: 40px; text-align: center; margin: 30px 0 6px; }
