:root {
  --bg: #fbf7f2;
  --surface: #ffffff;
  --fg: #2b2622;
  --muted: #6f645b;
  --accent: #b84a33;
  --on-accent: #ffffff;
  --accent-soft: #f6e1d9;
  --line: #d6c4b2;
  --shadow: 0 1px 2px rgba(60, 40, 20, .08), 0 4px 14px rgba(60, 40, 20, .06);
  --radius: 14px;
  --gap: 28px;
  --serif: "Iowan Old Style", "Palatino Linotype", Palatino, Georgia, serif;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #1c1815;
    --surface: #272220;
    --fg: #f3ece4;
    --muted: #b3a699;
    --accent: #e8836b;
    --on-accent: #1c1815;
    --accent-soft: #3b2a24;
    --line: #5a4d44;
    --shadow: 0 1px 2px rgba(0, 0, 0, .4), 0 4px 14px rgba(0, 0, 0, .3);
  }
}

* { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  background: var(--bg);
  color: var(--fg);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  line-height: 1.5;
}

main { flex: 1; }

/* ---------- Header ---------- */
.site-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  max-width: 1100px;
  margin: 0 auto;
  padding: 14px 16px;
}

.brand {
  font-family: var(--serif);
  font-size: 1.15rem;
  font-style: italic;
  color: var(--fg);
  text-decoration: none;
}

.lang {
  display: inline-flex;
  border: 1px solid var(--line);
  border-radius: 999px;
  overflow: hidden;
  background: var(--surface);
}

.lang button {
  appearance: none;
  border: 0;
  background: transparent;
  color: var(--fg);
  font: inherit;
  font-size: .85rem;
  font-weight: 600;
  letter-spacing: .04em;
  padding: 6px 14px;
  min-height: 36px;
  cursor: pointer;
}

.lang button[aria-pressed="true"] {
  background: var(--accent);
  color: var(--on-accent);
}

.lang button:focus-visible,
.person:focus-visible,
.dlg-close:focus-visible,
.brand:focus-visible,
.tree-wrap:focus-visible {
  outline: 3px solid var(--accent);
  outline-offset: 2px;
}

/* ---------- Hero ---------- */
.hero {
  max-width: 40rem;
  margin: 0 auto;
  padding: 28px 16px 8px;
  text-align: center;
}

.eyebrow {
  margin: 0 0 8px;
  color: var(--accent);
  font-size: .8rem;
  font-weight: 700;
  letter-spacing: .1em;
  text-transform: uppercase;
}

h1 {
  margin: 0 0 12px;
  font-family: var(--serif);
  font-size: clamp(2rem, 6vw, 3.2rem);
  line-height: 1.1;
  font-weight: 600;
}

.lead {
  margin: 0;
  color: var(--muted);
  font-size: 1.1rem;
}

/* ---------- Tree section ---------- */
.tree-section {
  max-width: 1100px;
  margin: 0 auto;
  padding: 8px 16px 32px;
}

.hint {
  margin: 12px 0 20px;
  text-align: center;
  color: var(--muted);
  font-size: .95rem;
}

.status {
  text-align: center;
  color: var(--muted);
}

.tree-wrap {
  overflow-x: auto;
  padding: 8px 4px 16px;
}

.tree,
.tree ul {
  list-style: none;
  margin: 0;
  padding: 0;
}

.tree { width: max-content; margin-inline: auto; }

.tree li { position: relative; }

/* ---------- Person card ---------- */
.unit {
  display: flex;
  align-items: center;
}

.join {
  color: var(--accent);
  padding: 0 8px;
  font-size: 1rem;
}

.person {
  appearance: none;
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 190px;
  max-width: 250px;
  padding: 10px 16px 10px 10px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  color: inherit;
  font: inherit;
  text-align: left;
  cursor: pointer;
  box-shadow: var(--shadow);
  transition: transform .12s ease, border-color .12s ease;
}

.person:hover {
  transform: translateY(-2px);
  border-color: var(--accent);
}

.avatar {
  flex: none;
  display: grid;
  place-items: center;
  width: 44px;
  height: 44px;
  border-radius: 50%;
  background: var(--accent-soft);
  color: var(--accent);
  font-weight: 700;
  letter-spacing: .02em;
}

.avatar svg { width: 24px; height: 24px; }

.avatar.big {
  width: 88px;
  height: 88px;
  margin: 0 auto 12px;
  font-size: 1.8rem;
}

.avatar.big svg { width: 46px; height: 46px; }

.pname { display: block; font-weight: 650; line-height: 1.2; overflow-wrap: anywhere; }
.pname.tbd { color: var(--muted); font-style: italic; font-weight: 500; }
.psub { display: block; margin-top: 2px; color: var(--muted); font-size: .85rem; }

/* ---------- Desktop: connected tree ---------- */
@media (min-width: 861px) {
  .tree ul {
    display: flex;
    justify-content: center;
    position: relative;
    padding-top: var(--gap);
  }

  .tree li {
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: var(--gap) 10px 0;
  }

  .tree > li { padding-top: 0; }

  /* vertical drop from a family unit to its children's bar */
  .tree li > ul::before {
    content: "";
    position: absolute;
    top: 0;
    left: 50%;
    height: var(--gap);
    border-left: 2px solid var(--line);
  }

  /* horizontal bar pieces above each child */
  .tree ul > li::before,
  .tree ul > li::after {
    content: "";
    position: absolute;
    top: 0;
    right: 50%;
    width: 50%;
    height: var(--gap);
    border-top: 2px solid var(--line);
  }

  .tree ul > li::after {
    right: auto;
    left: 50%;
    border-left: 2px solid var(--line);
  }

  .tree ul > li:only-child { padding-top: 0; }
  .tree ul > li:only-child::before,
  .tree ul > li:only-child::after { display: none; }

  .tree ul > li:first-child::before,
  .tree ul > li:last-child::after { border-top: 0; }

  .tree ul > li:last-child::before {
    border-right: 2px solid var(--line);
    border-radius: 0 8px 0 0;
  }

  .tree ul > li:first-child::after { border-radius: 8px 0 0 0; }
}

/* ---------- Mobile: indented list ---------- */
@media (max-width: 860px) {
  .tree { width: auto; }

  .tree ul {
    margin-left: 18px;
    padding-left: 26px;
  }

  .tree li { padding-top: 12px; }

  .unit { flex-direction: column; align-items: flex-start; }
  .join { padding: 2px 0 2px 14px; }
  .person { min-width: 0; width: 100%; max-width: 360px; }

  /* vertical rail + elbow tick for every child */
  .tree ul > li::before {
    content: "";
    position: absolute;
    left: -26px;
    top: 0;
    height: 100%;
    border-left: 2px solid var(--line);
  }

  .tree ul > li:last-child::before { height: 46px; }

  .tree ul > li::after {
    content: "";
    position: absolute;
    left: -26px;
    top: 46px;
    width: 26px;
    border-top: 2px solid var(--line);
  }
}

/* ---------- Dialog ---------- */
dialog {
  width: min(92vw, 440px);
  padding: 0;
  border: 0;
  border-radius: 20px;
  background: var(--surface);
  color: var(--fg);
  box-shadow: 0 20px 60px rgba(0, 0, 0, .35);
}

dialog::backdrop { background: rgba(20, 12, 8, .55); }

.dlg-inner {
  position: relative;
  padding: 32px 24px 28px;
  text-align: center;
}

.dlg-close {
  appearance: none;
  position: absolute;
  top: 10px;
  right: 10px;
  width: 40px;
  height: 40px;
  border: 0;
  border-radius: 50%;
  background: transparent;
  color: var(--muted);
  font-size: 1.6rem;
  line-height: 1;
  cursor: pointer;
}

.dlg-close:hover { background: var(--accent-soft); color: var(--accent); }

#dlg-name {
  margin: 0;
  font-family: var(--serif);
  font-size: 1.6rem;
  font-weight: 600;
  line-height: 1.2;
  overflow-wrap: anywhere;
}

#dlg-name.tbd { color: var(--muted); font-style: italic; font-weight: 500; }
.dlg-role { margin: 4px 0 0; color: var(--accent); font-weight: 600; }
.dlg-years { margin: 2px 0 0; color: var(--muted); }
.dlg-bio { margin: 18px 0 0; text-align: left; white-space: pre-line; }
.dlg-bio.empty { color: var(--muted); font-style: italic; text-align: center; }
.dlg-role:empty, .dlg-years:empty { display: none; }

/* ---------- App chrome: buttons, forms, panels ---------- */
[hidden] { display: none !important; }

:root { --danger: #b3261e; --ok: #2e7d32; }
@media (prefers-color-scheme: dark) { :root { --danger: #f2a29b; --ok: #81c995; } }

.header-actions {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  flex-wrap: wrap;
  gap: 8px;
}

.who {
  max-width: 200px;
  overflow: hidden;
  color: var(--muted);
  font-size: .8rem;
  text-overflow: ellipsis;
  white-space: nowrap;
}

@media (max-width: 640px) { .who { display: none; } }

.btn {
  appearance: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-height: 44px;
  padding: 8px 18px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--surface);
  color: var(--fg);
  font: inherit;
  font-weight: 600;
  cursor: pointer;
}

.btn:hover { border-color: var(--accent); }
.btn:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--on-accent); }
.btn.ghost { background: transparent; }
.btn.danger { color: var(--danger); border-color: var(--danger); background: transparent; }
.btn.small { min-height: 36px; padding: 4px 14px; font-size: .88rem; }
.btn.wide { width: 100%; }
.btn[disabled] { opacity: .6; cursor: default; }

.badge {
  display: inline-grid;
  place-items: center;
  min-width: 20px;
  height: 20px;
  padding: 0 6px;
  border-radius: 999px;
  background: var(--accent);
  color: var(--on-accent);
  font-size: .75rem;
}

.panel { max-width: 28rem; margin: 8px auto 40px; padding: 0 16px; }

.card {
  padding: 24px 20px;
  border: 1px solid var(--line);
  border-radius: 20px;
  background: var(--surface);
  box-shadow: var(--shadow);
}

.card h2 { margin: 0 0 4px; font-family: var(--serif); font-size: 1.4rem; font-weight: 600; }
.card .muted { margin: 0 0 16px; }
.card p { margin: 0 0 14px; }
.card .btn + .btn { margin-top: 8px; }
.muted { color: var(--muted); }
.center { text-align: center; }

.or {
  display: flex;
  align-items: center;
  gap: 12px;
  margin: 18px 0;
  color: var(--muted);
  font-size: .85rem;
}

.or::before, .or::after { content: ""; flex: 1; border-top: 1px solid var(--line); }

.field { display: block; margin: 0 0 12px; font-size: .9rem; font-weight: 600; }

input[type="text"], input[type="email"], textarea {
  display: block;
  width: 100%;
  margin-top: 4px;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--bg);
  color: var(--fg);
  font: inherit;
  font-weight: 400;
}

input:focus-visible, textarea:focus-visible { outline: 3px solid var(--accent); outline-offset: 1px; }
textarea { resize: vertical; }

.msg { min-height: 1.4em; margin: 10px 0 0; color: var(--muted); font-size: .9rem; }
.msg[data-kind="error"] { color: var(--danger); }
.msg[data-kind="ok"] { color: var(--ok); }
.card .msg { margin-bottom: 8px; }

.toolbar {
  display: flex;
  align-items: center;
  justify-content: center;
  flex-wrap: wrap;
  gap: 12px;
  margin: 12px 0 20px;
}

.toolbar .hint { margin: 0; }
.empty { max-width: 30rem; margin: 24px auto; text-align: center; color: var(--muted); }
.forest { display: flex; flex-direction: column; gap: 40px; }

.dlg-actions { display: flex; flex-wrap: wrap; justify-content: center; gap: 8px; margin-top: 22px; }
.form { text-align: left; }
.form h2 { margin: 0 0 4px; text-align: center; font-family: var(--serif); font-size: 1.4rem; font-weight: 600; }
.form .row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.form-actions { display: flex; align-items: center; flex-wrap: wrap; gap: 8px; margin-top: 8px; }
.spacer { flex: 1; }
.dlg-inner.left { text-align: left; }
.dlg-inner h3 { margin: 18px 0 6px; font-size: 1rem; }
#mem-title { margin: 0; font-family: var(--serif); font-size: 1.4rem; font-weight: 600; padding-right: 32px; }

.rows { margin: 0 0 8px; padding: 0; list-style: none; }

.rows li {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 8px 0;
  border-bottom: 1px solid var(--line);
}

.rows .info { min-width: 0; overflow-wrap: anywhere; }
.rows .info small { display: block; color: var(--muted); }
.rows .btns { display: flex; flex: none; gap: 6px; }
.inline-form { display: flex; gap: 8px; }
.inline-form input { margin-top: 0; }

dialog { max-height: 92vh; overflow-y: auto; }

/* ---------- Footer ---------- */
.site-footer {
  padding: 24px 16px 32px;
  text-align: center;
  color: var(--muted);
  font-size: .9rem;
}

.site-footer p { margin: 0; }

@media (prefers-reduced-motion: reduce) {
  .person { transition: none; }
  .person:hover { transform: none; }
}
