:root {
  --bg: #f4f2ec;
  --card: #ffffff;
  --ink: #26302a;
  --muted: #85806f;
  --accent: #3c7a4e;
  --accent-dark: #2c5c3a;
  --accent-soft: #e4efe7;
  --danger: #b3462e;
  --line: #e3ded1;
  --radius: 12px;
  --shadow: 0 1px 3px rgba(38, 48, 42, 0.08), 0 4px 16px rgba(38, 48, 42, 0.06);
  --nav-h: 52px;
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  font-family: system-ui, -apple-system, "Segoe UI", sans-serif;
  background: var(--bg);
  color: var(--ink);
}
main { max-width: 1400px; margin: 0 auto; padding: 0.9rem; }
h1 { font-size: 1.4rem; margin: 0.5rem 0; }
h2 { font-size: 1.02rem; margin: 0 0 0.6rem; }
h3 { font-size: 0.78rem; margin: 0.7rem 0 0.2rem; color: var(--muted); text-transform: uppercase; letter-spacing: 0.05em; }
a { color: var(--accent-dark); }
.muted { color: var(--muted); font-size: 0.9em; }
.error { color: var(--danger); }
.spacer { flex: 1; }

/* ── top navigation ──────────────────────────────────────────────────────── */
.topnav {
  position: sticky; top: 0; z-index: 50;
  display: flex; align-items: center; gap: 0.9rem;
  background: rgba(255, 255, 255, 0.92); backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--line);
  padding: 0 0.9rem; height: var(--nav-h);
  overflow-x: auto; white-space: nowrap;
}
.topnav a { text-decoration: none; color: var(--ink); font-size: 0.95rem; padding: 0.3rem 0; }
.topnav a:hover { color: var(--accent-dark); }
.topnav .brand { font-weight: 700; }
.topnav .who { color: var(--muted); font-size: 0.85rem; }

/* ── cards & forms ───────────────────────────────────────────────────────── */
.card {
  background: var(--card); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 1rem; margin: 0.8rem 0;
  box-shadow: var(--shadow);
}
.grid2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); gap: 0.8rem; }

label { display: block; margin: 0.55rem 0; font-size: 0.88rem; color: #4a463c; }
label.inline { display: inline-flex; align-items: center; gap: 0.4rem; margin: 0; }
input, select, textarea, button {
  font: inherit; padding: 0.55rem 0.7rem;
  border: 1px solid var(--line); border-radius: 8px; background: #fff;
  max-width: 100%;
}
label > input, label > select, label > textarea { width: 100%; margin-top: 0.25rem; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent); outline-offset: -1px; border-color: var(--accent); }
textarea { width: 100%; resize: vertical; }
button {
  background: var(--accent); color: #fff; border: none; cursor: pointer;
  font-weight: 600; transition: background 0.15s;
}
button:hover { background: var(--accent-dark); }
button.danger { background: var(--danger); }
button.linkish {
  background: none; color: var(--accent-dark); padding: 0 0.2rem;
  text-decoration: underline; font-size: 0.83em; font-weight: 400;
}
button.linkish:hover { color: var(--danger); background: none; }
button.plink {
  background: none; border: none; color: var(--accent-dark); padding: 0;
  text-decoration: underline; cursor: pointer; font-weight: 600;
}
.row-form { display: flex; flex-wrap: wrap; gap: 0.5rem; align-items: center; }
.row-form label { margin: 0; }
.stack-form .row-form { margin-bottom: 0.5rem; }
.two-col { display: grid; grid-template-columns: 1fr 1fr; gap: 0.5rem; }
.self { font-weight: 600; }

/* ── login ───────────────────────────────────────────────────────────────── */
.login-box { max-width: 22rem; margin: 12vh auto; text-align: center; }
.login-box form { text-align: left; }
.login-box button { width: 100%; margin-top: 0.8rem; padding: 0.7rem; }
.login-box input { width: 100%; }

/* ── workbench: edit panel + chart ──────────────────────────────────────── */
/* mobile (default): panel on top, graph below */
.workbench { display: grid; grid-template-columns: 1fr; gap: 0.8rem; margin-top: 0.4rem; }
.panel-col, .chart-col { min-width: 0; }
.toolbar { display: flex; align-items: center; gap: 1rem; margin: 0 0 0.5rem; flex-wrap: wrap; }
.toolbar select { max-width: 100%; }
.chart {
  width: 100%; height: 58vh; min-height: 380px;
  background: radial-gradient(ellipse at 50% 30%, #2e4128 0%, #1e2c1a 75%);
  border-radius: var(--radius); color: #fff;
  box-shadow: inset 0 0 40px rgba(0, 0, 0, 0.25), var(--shadow);
  touch-action: none;
}
.chart-empty {
  height: 100%; display: flex; align-items: center; justify-content: center;
  text-align: center; color: #cfd8c8; font-size: 1.05rem; line-height: 1.7; padding: 1rem;
}
/* desktop: edit left, graph right, panel scrolls independently */
@media (min-width: 960px) {
  .workbench { grid-template-columns: minmax(340px, 400px) 1fr; align-items: start; }
  .panel-col {
    position: sticky; top: calc(var(--nav-h) + 10px);
    max-height: calc(100vh - var(--nav-h) - 20px); overflow-y: auto;
    padding-right: 2px;
  }
  .chart { height: calc(100vh - var(--nav-h) - 92px); }
}

/* ── edit panel ─────────────────────────────────────────────────────────── */
.panel-inner {
  background: var(--card); border: 1px solid var(--line);
  border-radius: var(--radius); box-shadow: var(--shadow);
  padding: 0.9rem;
}
.panel-head { display: flex; align-items: center; gap: 0.7rem; margin-bottom: 0.4rem; }
.panel-title { display: flex; flex-direction: column; line-height: 1.3; }
.panel-title strong { font-size: 1.05rem; }
.panel-notes {
  white-space: pre-line; background: var(--accent-soft);
  border-radius: 8px; padding: 0.6rem 0.8rem; font-size: 0.9rem; margin: 0.5rem 0;
}
.panel-tip { margin-top: 0.8rem; line-height: 1.5; }
.panel-inner details { border-top: 1px solid var(--line); padding: 0.45rem 0; }
.panel-inner details:last-of-type { border-bottom: 1px solid var(--line); }
.panel-inner summary {
  cursor: pointer; font-weight: 600; font-size: 0.92rem;
  padding: 0.3rem 0; list-style-position: outside; color: var(--ink);
}
.panel-inner summary:hover { color: var(--accent-dark); }
.panel-inner form { margin: 0.3rem 0 0.5rem; }
.panel-inner form button[type="submit"] { margin-top: 0.4rem; }

/* ── people list & person page ──────────────────────────────────────────── */
.person-list { list-style: none; padding: 0; }
.person-list li { border-bottom: 1px solid var(--line); }
.person-item {
  display: flex; align-items: center; gap: 0.8rem;
  padding: 0.6rem 0.2rem; text-decoration: none;
}
.person-item:hover { background: var(--accent-soft); border-radius: 8px; }
.person-item .pname { font-weight: 600; }
.person-head { display: flex; align-items: center; gap: 1rem; margin-top: 0.8rem; flex-wrap: wrap; }

.avatar {
  display: inline-block; border-radius: 50%;
  background: #d8d3c4 center/cover; flex: none;
  border: 1px solid var(--line);
}
.avatar.sm { width: 40px; height: 40px; }
.avatar.md { width: 60px; height: 60px; }
.avatar.lg { width: 92px; height: 92px; }

.notes { white-space: pre-line; }
.rel-list { list-style: none; padding: 0; margin: 0.2rem 0; }
.rel-list li { padding: 0.22rem 0; }

.chips { display: flex; flex-wrap: wrap; gap: 0.7rem; }
.chip {
  display: flex; flex-direction: column; align-items: center; gap: 0.3rem;
  padding: 0.6rem; border: 1px solid var(--line); border-radius: var(--radius);
  font-size: 0.83rem; background: #fff;
}
.badge {
  background: var(--accent); color: #fff; border-radius: 99px;
  font-size: 0.68rem; padding: 0.12rem 0.55rem;
}

/* ── photos ─────────────────────────────────────────────────────────────── */
.photo-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); gap: 0.8rem; }
.photo-tile {
  display: block; position: relative; border-radius: var(--radius); overflow: hidden;
  border: 1px solid var(--line); background: var(--card); text-decoration: none;
  box-shadow: var(--shadow); transition: transform 0.15s;
}
.photo-tile:hover { transform: translateY(-2px); }
.photo-tile img { width: 100%; height: 170px; object-fit: cover; display: block; }
.photo-tile .caption {
  position: absolute; left: 0; right: 0; bottom: 0;
  background: rgba(0, 0, 0, 0.55); color: #fff; font-size: 0.8rem; padding: 0.25rem 0.5rem;
}
.crop-stage img { max-width: 100%; display: block; }
.crop-stage { margin-bottom: 0.6rem; }

/* ── family-chart cards ─────────────────────────────────────────────────── */
.f3 .card-html {
  background: linear-gradient(180deg, #ffffff 0%, #f6f3ea 100%);
  color: var(--ink);
  border-radius: 14px; padding: 8px 14px 8px 8px;
  display: flex; align-items: center; gap: 10px;
  border: 1px solid #b9b29c;
  box-shadow: 0 3px 10px rgba(0, 0, 0, 0.4);
  cursor: pointer; pointer-events: auto; min-width: 150px;
  transition: transform 0.12s, box-shadow 0.12s;
}
.f3 .card-html:hover { transform: translateY(-2px); box-shadow: 0 6px 16px rgba(0, 0, 0, 0.5); }
.f3 .card-html.sel { outline: 3px solid #7fb98f; outline-offset: 1px; }
.f3 .card-html .avatar {
  width: 46px; height: 46px; border: none;
  box-shadow: 0 0 0 2px var(--accent), 0 0 0 4px rgba(255, 255, 255, 0.5);
  background-color: #cfe0d3;
}
.f3 .card-html .ctext { display: flex; flex-direction: column; line-height: 1.25; }
/* explicit colors: family-chart's own css paints card text white */
.f3 .card-html .cname { font-weight: 700; font-size: 0.88rem; white-space: nowrap; color: #26302a; }
.f3 .card-html .cyears { font-size: 0.74rem; color: #85806f; }
/* soften the connecting lines */
.f3 path.link, .f3 .link { stroke: rgba(220, 232, 214, 0.5) !important; }

@media (max-width: 600px) {
  main { padding: 0.6rem; }
  .f3 .card-html { min-width: 128px; padding: 6px 10px 6px 6px; }
  .f3 .card-html .avatar { width: 38px; height: 38px; }
}
