:root {
  color-scheme: light dark;
  --bg: #f7f3ec;
  --surface: #fffdf9;
  --surface-2: #f1ebe0;
  --text: #2b2520;
  --text-muted: #6f655b;
  --line: #d9cfbf;
  --accent: #8a4b2a;
  --accent-strong: #6e3818;
  --accent-soft: #f3e3d6;
  --male: #3b6ea5;
  --female: #b05070;
  --neutral: #6b7a6a;
  --danger: #a33a2a;
  --danger-soft: #f6e1dc;
  --radius: 12px;
  --shadow: 0 1px 2px rgba(43, 37, 32, 0.06), 0 6px 20px rgba(43, 37, 32, 0.06);
  --font: ui-sans-serif, system-ui, -apple-system, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
  --serif: 'Iowan Old Style', 'Palatino Linotype', Palatino, Georgia, serif;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #17140f;
    --surface: #221d17;
    --surface-2: #2b251e;
    --text: #efe7da;
    --text-muted: #a89c8c;
    --line: #3b3328;
    --accent: #d99866;
    --accent-strong: #ecb182;
    --accent-soft: #3a2a1f;
    --male: #7fb0e0;
    --female: #e08aa8;
    --neutral: #9db09b;
    --danger: #e07a6a;
    --danger-soft: #42221d;
    --shadow: 0 1px 2px rgba(0, 0, 0, 0.3), 0 6px 20px rgba(0, 0, 0, 0.25);
  }
}

* {
  box-sizing: border-box;
}

html {
  font-family: var(--font);
  font-size: 16px;
  line-height: 1.5;
  -webkit-text-size-adjust: 100%;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

a {
  color: var(--accent);
}
a:hover {
  color: var(--accent-strong);
}

h1,
h2,
h3 {
  font-family: var(--serif);
  font-weight: 600;
  line-height: 1.2;
  margin: 0 0 0.5rem;
}
h1 {
  font-size: 2rem;
}
h2 {
  font-size: 1.25rem;
}
h3 {
  font-size: 1.05rem;
}

p {
  margin: 0 0 0.75rem;
}

.visually-hidden {
  position: absolute !important;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
}

/* ---------- header / layout ---------- */

.site-header {
  background: var(--surface);
  border-bottom: 1px solid var(--line);
  position: sticky;
  top: 0;
  z-index: 10;
}
.site-header__inner {
  max-width: 1100px;
  margin: 0 auto;
  padding: 0.6rem 16px;
  display: flex;
  align-items: center;
  gap: 1rem;
  flex-wrap: wrap;
}
.brand {
  font-family: var(--serif);
  font-size: 1.3rem;
  font-weight: 700;
  text-decoration: none;
  color: var(--text);
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
}
.brand__mark {
  color: var(--accent);
}
.site-nav {
  display: flex;
  align-items: center;
  gap: 1rem;
  margin-left: auto;
}
.site-nav a {
  text-decoration: none;
  font-weight: 500;
}
.site-search {
  flex: 0 1 240px;
}
.site-search input {
  width: 100%;
}
@media (max-width: 720px) {
  .site-nav {
    margin-left: 0;
    width: 100%;
    order: 3;
  }
  .site-search {
    flex: 1 1 100%;
    order: 4;
  }
}

.container {
  width: 100%;
  max-width: 1100px;
  margin: 0 auto;
  padding: 1.5rem 16px 3rem;
  flex: 1;
}
.container--wide {
  max-width: none;
}

.site-footer {
  text-align: center;
  color: var(--text-muted);
  font-size: 0.85rem;
  padding: 1.5rem 16px;
  border-top: 1px solid var(--line);
}

/* ---------- common pieces ---------- */

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

.button {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  padding: 0.5rem 0.9rem;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--text);
  font: inherit;
  font-size: 0.95rem;
  font-weight: 500;
  text-decoration: none;
  cursor: pointer;
  line-height: 1.2;
  white-space: nowrap;
}
.button:hover {
  background: var(--surface-2);
  color: var(--text);
}
.button--primary {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}
.button--primary:hover {
  background: var(--accent-strong);
  color: #fff;
}
.button--ghost {
  background: transparent;
}
.button--danger {
  color: var(--danger);
  border-color: var(--danger);
  background: transparent;
}
.button--danger:hover {
  background: var(--danger-soft);
  color: var(--danger);
}
.button--small {
  padding: 0.3rem 0.7rem;
  font-size: 0.85rem;
}
.button--link {
  border: 0;
  background: none;
  padding: 0;
  color: var(--accent);
  font-weight: 500;
  text-decoration: underline;
  cursor: pointer;
  font: inherit;
}

.count {
  display: inline-block;
  margin-left: 0.5rem;
  font-family: var(--font);
  font-size: 0.75rem;
  font-weight: 600;
  background: var(--surface-2);
  color: var(--text-muted);
  border-radius: 999px;
  padding: 0.05rem 0.5rem;
  vertical-align: middle;
}

.hint,
.empty {
  color: var(--text-muted);
  font-size: 0.9rem;
}
.empty {
  font-style: italic;
}

.alert {
  border-radius: var(--radius);
  padding: 0.75rem 1rem;
  margin-bottom: 1rem;
  border: 1px solid var(--line);
  background: var(--surface-2);
}
.alert p:last-child {
  margin: 0;
}
.alert--error {
  background: var(--danger-soft);
  border-color: var(--danger);
  color: var(--text);
}
.alert--info {
  background: var(--accent-soft);
  border-color: var(--accent);
}

.breadcrumb {
  font-size: 0.9rem;
  color: var(--text-muted);
  margin-bottom: 0.75rem;
}
.breadcrumb a {
  text-decoration: none;
}

.tag {
  display: inline-block;
  font-size: 0.72rem;
  font-weight: 600;
  letter-spacing: 0.02em;
  text-transform: uppercase;
  padding: 0.1rem 0.45rem;
  border-radius: 4px;
  background: var(--surface-2);
  color: var(--text-muted);
  vertical-align: middle;
}
.tag--accent {
  background: var(--accent-soft);
  color: var(--accent-strong);
}
.tag--muted {
  opacity: 0.8;
}

/* ---------- person chips ---------- */

.chip-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  gap: 0.6rem;
}
.chip {
  display: flex;
  gap: 0.7rem;
  align-items: flex-start;
  padding: 0.6rem 0.75rem;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 10px;
  border-left-width: 4px;
  border-left-color: var(--neutral);
}
.chip--male {
  border-left-color: var(--male);
}
.chip--female {
  border-left-color: var(--female);
}
.chip--deceased .chip__avatar {
  filter: grayscale(1);
  opacity: 0.7;
}
.chip__avatar {
  flex: 0 0 36px;
  width: 36px;
  height: 36px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  font-size: 0.8rem;
  font-weight: 700;
  color: #fff;
  background: var(--neutral);
}
.chip--male .chip__avatar {
  background: var(--male);
}
.chip--female .chip__avatar {
  background: var(--female);
}
.chip__body {
  min-width: 0;
  flex: 1;
}
.chip__body .person-link {
  font-weight: 600;
  text-decoration: none;
  color: var(--text);
}
.chip__body .person-link:hover {
  color: var(--accent);
  text-decoration: underline;
}
.chip__meta {
  display: flex;
  flex-wrap: wrap;
  gap: 0.25rem 0.6rem;
  font-size: 0.82rem;
  color: var(--text-muted);
}
.chip__note {
  color: var(--accent-strong);
  font-weight: 500;
}
.chip__detail {
  font-size: 0.82rem;
  color: var(--text-muted);
  margin-top: 0.15rem;
}
.chip__actions {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
  font-size: 0.8rem;
  align-items: flex-end;
}
.chip__actions a {
  text-decoration: none;
}

/* ---------- profile ---------- */

.profile-header {
  display: flex;
  gap: 1.25rem;
  align-items: flex-start;
  flex-wrap: wrap;
  margin-bottom: 1.5rem;
}
.profile-header__avatar {
  flex: 0 0 72px;
  width: 72px;
  height: 72px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  font-size: 1.5rem;
  font-weight: 700;
  color: #fff;
  background: var(--neutral);
}
.profile-header__avatar--male {
  background: var(--male);
}
.profile-header__avatar--female {
  background: var(--female);
}
.profile-header__body {
  flex: 1 1 300px;
}
.profile-header__body h1 {
  margin-bottom: 0.15rem;
}
.profile-header__sub {
  color: var(--text-muted);
  margin: 0;
}
.profile-header__actions {
  display: flex;
  gap: 0.5rem;
  flex-wrap: wrap;
  align-items: center;
}
.facts {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 0.75rem 1.5rem;
  margin: 0 0 1.5rem;
  padding: 1rem 1.25rem;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
}
.facts div {
  margin: 0;
}
.facts dt {
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--text-muted);
}
.facts dd {
  margin: 0;
  font-weight: 500;
}
.notes {
  white-space: pre-wrap;
  margin-bottom: 1.5rem;
}

.relation-section {
  margin-bottom: 1.75rem;
}
.relation-section__header {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 1rem;
  margin-bottom: 0.6rem;
  border-bottom: 1px solid var(--line);
  padding-bottom: 0.35rem;
}
.relation-section__header h2 {
  margin: 0;
}

.relation-group {
  margin: 1rem 0 2rem;
}
.relation-group > h2 {
  font-size: 1rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-muted);
  font-family: var(--font);
  margin-bottom: 0.75rem;
}

.danger-zone {
  margin-top: 2rem;
  border: 1px dashed var(--danger);
  border-radius: var(--radius);
  padding: 0.75rem 1rem;
}
.danger-zone summary {
  cursor: pointer;
  color: var(--danger);
  font-weight: 600;
}
.danger-zone form {
  margin-top: 0.75rem;
}

/* ---------- forms ---------- */

form.stack {
  display: grid;
  gap: 1rem;
}
fieldset {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 1rem 1.25rem;
  margin: 0;
  min-width: 0;
}
legend {
  padding: 0 0.4rem;
  font-weight: 600;
  color: var(--text-muted);
  font-size: 0.9rem;
}
.field {
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
  min-width: 0;
}
.field label {
  font-size: 0.85rem;
  font-weight: 600;
}
.field__hint {
  font-size: 0.78rem;
  color: var(--text-muted);
  margin: 0;
}
.field__error {
  font-size: 0.8rem;
  color: var(--danger);
  margin: 0;
  font-weight: 500;
}
.field--invalid input,
.field--invalid select,
.field--invalid textarea {
  border-color: var(--danger);
}
.field-row {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(170px, 1fr));
  gap: 0.75rem 1rem;
}
.person-fields {
  display: grid;
  gap: 0.9rem;
}

input,
select,
textarea {
  font: inherit;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0.5rem 0.65rem;
  width: 100%;
  min-width: 0;
}
input[type='checkbox'],
input[type='radio'] {
  width: auto;
  accent-color: var(--accent);
}
input:focus,
select:focus,
textarea:focus {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
  border-color: var(--accent);
}
textarea {
  resize: vertical;
}

.submit-bar {
  display: flex;
  gap: 0.75rem;
  align-items: center;
  flex-wrap: wrap;
}

.segmented {
  display: inline-flex;
  border: 1px solid var(--line);
  border-radius: 999px;
  overflow: hidden;
  margin-bottom: 1rem;
  background: var(--surface);
}
.segmented label {
  position: relative;
}
.segmented input {
  position: absolute;
  opacity: 0;
  inset: 0;
  margin: 0;
  cursor: pointer;
}
.segmented span {
  display: block;
  padding: 0.45rem 1rem;
  font-weight: 500;
  font-size: 0.95rem;
  cursor: pointer;
}
.segmented input:checked + span {
  background: var(--accent);
  color: #fff;
}
.segmented input:disabled + span {
  opacity: 0.4;
  cursor: not-allowed;
}
.segmented input:focus-visible + span {
  outline: 2px solid var(--accent-strong);
  outline-offset: -2px;
}

/* Toggle the "new" vs "existing" panels purely with CSS. */
.person-choice__panel--existing {
  display: none;
}
.person-choice:has(input[name='mode'][value='existing']:checked) .person-choice__panel--new {
  display: none;
}
.person-choice:has(input[name='mode'][value='existing']:checked) .person-choice__panel--existing {
  display: block;
}

.checkbox-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  gap: 0.4rem;
}
.checkbox-list label {
  display: flex;
  gap: 0.5rem;
  align-items: center;
  font-weight: 500;
}

/* ---------- home ---------- */

.hero {
  display: grid;
  gap: 1.5rem;
  grid-template-columns: 1.2fr 1fr;
  align-items: stretch;
  margin-bottom: 2rem;
}
@media (max-width: 800px) {
  .hero {
    grid-template-columns: 1fr;
  }
}
.hero h1 {
  font-size: 2.2rem;
}
.stats {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(120px, 1fr));
  gap: 0.75rem;
  margin: 1rem 0 0;
  padding: 0;
  list-style: none;
}
.stats li {
  background: var(--surface-2);
  border-radius: 10px;
  padding: 0.6rem 0.8rem;
}
.stats strong {
  display: block;
  font-size: 1.5rem;
  font-family: var(--serif);
}
.stats span {
  font-size: 0.8rem;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}
.welcome {
  max-width: 760px;
  margin: 2rem auto;
}
.welcome .lede {
  font-size: 1.1rem;
  color: var(--text-muted);
}

/* ---------- people index ---------- */

.toolbar {
  display: flex;
  gap: 1rem;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  margin-bottom: 1rem;
}
.toolbar form {
  display: flex;
  gap: 0.5rem;
  flex: 1 1 320px;
}

/* ---------- tree ---------- */

.tree-page h1 {
  margin-bottom: 0.25rem;
}
.tree-toolbar {
  display: flex;
  gap: 0.75rem;
  flex-wrap: wrap;
  align-items: center;
  margin-bottom: 1.25rem;
}
.tree-section {
  margin-bottom: 2rem;
}
.tree-section > h2 {
  font-family: var(--font);
  font-size: 0.85rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-muted);
  margin-bottom: 0.75rem;
}
.gen-row {
  display: flex;
  flex-wrap: wrap;
  gap: 0.6rem;
  justify-content: center;
  margin-bottom: 0.75rem;
  position: relative;
}
.gen-row + .gen-row::before {
  content: '';
  display: block;
  width: 100%;
  height: 0;
}
.gen-label {
  text-align: center;
  font-size: 0.75rem;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  margin: 0.25rem 0;
}

.tnode {
  display: inline-flex;
  flex-direction: column;
  align-items: center;
  gap: 0.15rem;
  min-width: 140px;
  max-width: 200px;
  padding: 0.5rem 0.7rem;
  background: var(--surface);
  border: 1px solid var(--line);
  border-top: 3px solid var(--neutral);
  border-radius: 10px;
  box-shadow: var(--shadow);
  text-align: center;
  font-size: 0.9rem;
}
.tnode--male {
  border-top-color: var(--male);
}
.tnode--female {
  border-top-color: var(--female);
}
.tnode--focus {
  outline: 3px solid var(--accent);
  outline-offset: 2px;
}
.tnode--deceased {
  background: var(--surface-2);
}
.tnode a {
  font-weight: 600;
  text-decoration: none;
  color: var(--text);
}
.tnode a:hover {
  color: var(--accent);
}
.tnode small {
  color: var(--text-muted);
  font-size: 0.78rem;
}
.tnode .tag {
  margin-top: 0.2rem;
}

.tfamily {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  flex-wrap: wrap;
  justify-content: center;
}
.tfamily__join {
  color: var(--text-muted);
  font-size: 1.1rem;
  line-height: 1;
}
.tfamily__join--ended {
  text-decoration: line-through;
  opacity: 0.7;
}

.tree-scroll {
  overflow-x: auto;
  padding: 0.5rem 0 1rem;
}
.tree ul {
  padding-top: 24px;
  position: relative;
  display: flex;
  justify-content: center;
  margin: 0;
  padding-left: 0;
}
.tree li {
  list-style: none;
  text-align: center;
  position: relative;
  padding: 24px 8px 0;
}
.tree li::before,
.tree li::after {
  content: '';
  position: absolute;
  top: 0;
  right: 50%;
  border-top: 2px solid var(--line);
  width: 50%;
  height: 24px;
}
.tree li::after {
  right: auto;
  left: 50%;
  border-left: 2px solid var(--line);
}
.tree li:only-child::after,
.tree li:only-child::before {
  display: none;
}
.tree li:only-child {
  padding-top: 0;
}
.tree li:first-child::before,
.tree li:last-child::after {
  border: 0 none;
}
.tree li:last-child::before {
  border-right: 2px solid var(--line);
  border-radius: 0 8px 0 0;
}
.tree li:first-child::after {
  border-radius: 8px 0 0 0;
}
.tree ul ul::before {
  content: '';
  position: absolute;
  top: 0;
  left: 50%;
  border-left: 2px solid var(--line);
  width: 0;
  height: 24px;
}
.tree > ul {
  padding-top: 0;
}
.tree > ul > li {
  padding-top: 0;
}

.legend {
  display: flex;
  gap: 1rem;
  flex-wrap: wrap;
  font-size: 0.8rem;
  color: var(--text-muted);
}
.legend span::before {
  content: '';
  display: inline-block;
  width: 10px;
  height: 10px;
  border-radius: 2px;
  margin-right: 0.35rem;
  vertical-align: middle;
  background: var(--neutral);
}
.legend .l-male::before {
  background: var(--male);
}
.legend .l-female::before {
  background: var(--female);
}

/* ---------- auth & accounts ---------- */

.user-menu {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.9rem;
}
.user-menu a {
  text-decoration: none;
  font-weight: 600;
}
.banner {
  background: var(--accent-soft);
  color: var(--accent-strong);
  border-bottom: 1px solid var(--line);
  padding: 0.6rem 16px;
  text-align: center;
  font-size: 0.9rem;
}
.auth-card {
  max-width: 440px;
  margin: 3rem auto;
}
.auth-card h1 {
  margin-bottom: 0.25rem;
}
.code-input {
  font-size: 1.6rem;
  letter-spacing: 0.4em;
  text-align: center;
  font-variant-numeric: tabular-nums;
}
.invite-link {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 0.85rem;
  word-break: break-all;
  background: var(--surface-2);
  padding: 0.4rem 0.6rem;
  border-radius: 6px;
}
table.data {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.92rem;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  overflow: hidden;
}
table.data th,
table.data td {
  text-align: left;
  padding: 0.55rem 0.75rem;
  border-bottom: 1px solid var(--line);
  vertical-align: top;
}
table.data th {
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--text-muted);
  background: var(--surface-2);
}
table.data tr:last-child td {
  border-bottom: 0;
}
.inline-actions {
  display: flex;
  gap: 0.4rem;
  flex-wrap: wrap;
}
.inline-actions form {
  display: inline;
}
.step {
  color: var(--text-muted);
  font-size: 0.85rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
}
.place-choice__panel--claim {
  display: none;
}
.place-choice:has(input[name='mode'][value='claim']:checked) .place-choice__panel--claim {
  display: block;
}
.place-choice:has(input[name='mode'][value='claim']:checked) .place-choice__panel--create {
  display: none;
}
