:root {
  color-scheme: light dark;
  --bg: #f7f4ef;
  --surface: #ffffff;
  --surface-2: #f0ebe4;
  --line: #e4ddd3;
  --text: #2b2622;
  --muted: #6f655d;
  --accent: #b84d33;
  --accent-ink: #ffffff;
  --accent-soft: #f6e2db;
  --ok: #2f7a4f;
  --danger: #b3261e;
  --danger-soft: #fbe4e2;
  --shadow: 0 1px 2px rgb(60 40 20 / 0.06), 0 4px 16px rgb(60 40 20 / 0.06);
  --tree-accent: #c9b8a6;
  --radius: 14px;
  --nav-h: 64px;
  --font: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  accent-color: var(--accent);
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #181614;
    --surface: #24211e;
    --surface-2: #2e2a26;
    --line: #3a352f;
    --text: #f1ece6;
    --muted: #b0a59b;
    --accent: #ec8f72;
    --accent-ink: #2a120a;
    --accent-soft: #43271e;
    --ok: #7fcf9f;
    --danger: #ff8a80;
    --danger-soft: #4a2220;
    --shadow: 0 1px 2px rgb(0 0 0 / 0.3), 0 4px 16px rgb(0 0 0 / 0.25);
    --tree-accent: #6f6357;
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.45 var(--font);
  min-height: 100dvh;
  overflow-wrap: break-word; /* long emails / links must not widen the page on phones */
}
a { color: var(--accent); }
h1, h2, h3 { line-height: 1.2; margin: 0 0 0.5rem; }
h1 { font-size: 1.5rem; }
h2 { font-size: 1.2rem; }
h3 { font-size: 1rem; }
p { margin: 0 0 0.75rem; }
.muted { color: var(--muted); }
.small { font-size: 0.875rem; }
.visually-hidden:where(:not(:focus-within, :active)) {
  position: absolute !important; clip-path: inset(50%) !important; overflow: hidden !important;
  width: 1px !important; height: 1px !important; margin: -1px !important; padding: 0 !important; border: 0 !important; white-space: nowrap !important;
}

/* ---- layout ------------------------------------------------------------------------ */
.app { display: grid; grid-template-rows: auto 1fr; min-height: 100dvh; }
.topbar {
  position: sticky; top: 0; z-index: 10;
  display: flex; align-items: center; gap: 0.5rem;
  padding: 0.6rem 1rem; padding-top: max(0.6rem, env(safe-area-inset-top));
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--line);
}
.brand { font-weight: 700; display: flex; align-items: center; gap: 0.4rem; color: var(--text); text-decoration: none; white-space: nowrap; }
.brand img { width: 28px; height: 28px; }
.family-switch { flex: 1; min-width: 0; display: flex; justify-content: center; }
@media (max-width: 520px) { .brand-text { display: none; } }
@media (min-width: 900px) { .family-switch { justify-content: flex-start; margin-left: 2.5rem; } .family-switch select { width: auto; min-width: 220px; } }
.family-switch select { max-width: 100%; font-weight: 600; border: 0; background: var(--surface-2); padding: 0.4rem 0.8rem; border-radius: 999px; }
.main { display: grid; grid-template-columns: 1fr; }
.content { padding: 1rem; padding-bottom: calc(var(--nav-h) + 1.5rem + env(safe-area-inset-bottom)); max-width: 860px; width: 100%; margin: 0 auto; }
.content.wide { max-width: none; padding: 0; padding-bottom: calc(var(--nav-h) + env(safe-area-inset-bottom)); }

.nav {
  position: fixed; bottom: 0; left: 0; right: 0; z-index: 10;
  display: flex; justify-content: space-around;
  background: var(--surface); border-top: 1px solid var(--line);
  padding-bottom: env(safe-area-inset-bottom);
  height: calc(var(--nav-h) + env(safe-area-inset-bottom));
}
.nav a {
  flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
  color: var(--muted); text-decoration: none; font-size: 0.72rem; font-weight: 600;
}
.nav a svg { width: 24px; height: 24px; }
.nav a[aria-current="page"] { color: var(--accent); }

@media (min-width: 900px) {
  .main { grid-template-columns: 220px 1fr; }
  .nav {
    position: sticky; top: 57px; height: calc(100dvh - 57px); flex-direction: column; justify-content: flex-start;
    border-top: 0; border-right: 1px solid var(--line); background: transparent; padding: 1rem 0.75rem; gap: 0.25rem;
  }
  .nav a { flex: 0; flex-direction: row; justify-content: flex-start; gap: 0.75rem; padding: 0.6rem 0.9rem; border-radius: 10px; font-size: 0.95rem; }
  .nav a[aria-current="page"] { background: var(--accent-soft); }
  .content { padding: 1.5rem 2rem 3rem; }
  .content.wide { padding: 0; }
  .fab { bottom: 2rem !important; right: 2rem !important; }
}

/* ---- components -------------------------------------------------------------------- */
.card { background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow); padding: 1rem; margin-bottom: 1rem; }
.card > h2:first-child, .card > h3:first-child { margin-bottom: 0.75rem; }
.row { display: flex; gap: 0.5rem; align-items: center; flex-wrap: wrap; }
.row.between { justify-content: space-between; }
.stack > * + * { margin-top: 0.75rem; }
.grow { flex: 1; min-width: 0; }
.page-head { display: flex; align-items: center; justify-content: space-between; gap: 0.75rem; margin-bottom: 1rem; flex-wrap: wrap; }
.page-head h1 { margin: 0; }

button, .btn {
  font: inherit; font-weight: 600; cursor: pointer;
  border: 1px solid var(--line); background: var(--surface); color: var(--text);
  padding: 0.6rem 1rem; border-radius: 10px; min-height: 44px;
  display: inline-flex; align-items: center; justify-content: center; gap: 0.4rem; text-decoration: none;
}
button:hover, .btn:hover { border-color: var(--muted); }
button.primary, .btn.primary { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
button.danger { color: var(--danger); border-color: color-mix(in srgb, var(--danger) 40%, transparent); }
button.ghost, .btn.ghost { background: transparent; border-color: transparent; }
button.small, .btn.small { min-height: 34px; padding: 0.3rem 0.7rem; font-size: 0.875rem; }
button.icon { padding: 0.5rem; min-width: 44px; }
button:disabled { opacity: 0.55; cursor: default; }
:focus-visible { outline: 3px solid color-mix(in srgb, var(--accent) 60%, transparent); outline-offset: 2px; }

.fab {
  position: fixed; right: 1rem; bottom: calc(var(--nav-h) + 1rem + env(safe-area-inset-bottom)); z-index: 9;
  width: 58px; height: 58px; border-radius: 50%; font-size: 1.8rem; line-height: 1;
  background: var(--accent); color: var(--accent-ink); border: 0; box-shadow: 0 6px 20px rgb(0 0 0 / 0.2);
}

label { display: block; font-weight: 600; font-size: 0.9rem; margin-bottom: 0.3rem; }
.field { margin-bottom: 0.9rem; }
.field .hint { font-weight: 400; color: var(--muted); font-size: 0.82rem; display: block; margin-bottom: 0.3rem; overflow-wrap: anywhere; }
input, select, textarea {
  font: inherit; color: inherit; width: 100%; min-width: 0;
  background: var(--surface); border: 1px solid var(--line); border-radius: 10px;
  padding: 0.6rem 0.75rem; min-height: 44px;
}
textarea { min-height: 80px; resize: vertical; }
input[type="checkbox"], input[type="radio"] { width: 20px; min-height: 20px; height: 20px; margin: 0; flex: none; }
input[type="color"] { padding: 4px; width: 60px; }
input:user-invalid, select:user-invalid, textarea:user-invalid { border-color: var(--danger); background: var(--danger-soft); }
.check { display: flex; gap: 0.6rem; align-items: center; font-weight: 500; margin: 0; cursor: pointer; }
.grid-2 { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 0 0.75rem; }
@media (max-width: 480px) { .grid-2.collapse { grid-template-columns: 1fr; } }
.form-error { color: var(--danger); background: var(--danger-soft); border-radius: 10px; padding: 0.6rem 0.8rem; margin-bottom: 0.9rem; }
.form-error:empty { display: none; }
.segmented { display: flex; flex-wrap: wrap; gap: 0.4rem; }
.segmented label { margin: 0; }
.segmented input { position: absolute; opacity: 0; pointer-events: none; }
.segmented span { display: inline-block; padding: 0.45rem 0.9rem; border: 1px solid var(--line); border-radius: 999px; font-weight: 600; font-size: 0.9rem; cursor: pointer; }
.segmented input:checked + span { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
.segmented input:focus-visible + span { outline: 3px solid color-mix(in srgb, var(--accent) 60%, transparent); }

.chips { display: flex; flex-wrap: wrap; gap: 0.35rem; }
.chip { display: inline-flex; align-items: center; gap: 0.35rem; background: var(--surface-2); border-radius: 999px; padding: 0.2rem 0.6rem 0.2rem 0.25rem; font-size: 0.85rem; text-decoration: none; color: var(--text); }
.chip .avatar { width: 22px; height: 22px; font-size: 0.65rem; }
.avatar {
  width: 42px; height: 42px; border-radius: 50%; flex: none;
  display: inline-grid; place-items: center; font-weight: 700; font-size: 0.95rem; color: #fff;
  background: var(--tree-accent);
}
.avatar.lg { width: 72px; height: 72px; font-size: 1.6rem; }

.list { list-style: none; margin: 0; padding: 0; }
.list > li + li { border-top: 1px solid var(--line); }
.list-item { display: flex; align-items: center; gap: 0.8rem; padding: 0.75rem 0.25rem; color: inherit; text-decoration: none; width: 100%; background: none; border: 0; border-radius: 0; text-align: left; font-weight: inherit; min-height: 0; }
button.list-item:hover { border: 0; background: var(--surface-2); }
.list-item .title { font-weight: 600; overflow-wrap: anywhere; }
.list-item .sub { color: var(--muted); font-size: 0.875rem; overflow-wrap: anywhere; }

.empty { text-align: center; padding: 2.5rem 1rem; color: var(--muted); }
.empty .big { font-size: 2.5rem; }

/* upcoming */
.group-title { font-size: 0.8rem; text-transform: uppercase; letter-spacing: 0.06em; color: var(--muted); margin: 1.25rem 0 0.4rem; font-weight: 700; }
.occ { display: flex; gap: 0.85rem; align-items: center; padding: 0.7rem 0.8rem; }
.date-badge { width: 52px; flex: none; text-align: center; border-radius: 12px; background: var(--surface-2); padding: 0.3rem 0; }
.date-badge .d { font-size: 1.35rem; font-weight: 700; line-height: 1.1; }
.date-badge .w { font-size: 0.7rem; text-transform: uppercase; color: var(--muted); font-weight: 700; }
.date-badge.today { background: var(--accent); color: var(--accent-ink); }
.date-badge.today .w { color: inherit; }
.occ .emoji { font-size: 1.3rem; }
.when { font-size: 0.8rem; font-weight: 700; color: var(--accent); white-space: nowrap; }
.occ-list { background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow); overflow: hidden; }
.occ-list > li + li { border-top: 1px solid var(--line); }
.occ-list button.list-item { padding: 0; }

/* month calendar */
.cal-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 0.75rem; }
.cal { display: grid; grid-template-columns: repeat(7, 1fr); gap: 2px; background: var(--line); border-radius: var(--radius); overflow: hidden; box-shadow: var(--shadow); }
.cal .dow { background: var(--surface-2); text-align: center; font-size: 0.72rem; font-weight: 700; padding: 0.35rem 0; color: var(--muted); }
.cal .day { background: var(--surface); min-height: 64px; padding: 0.3rem; border: 0; border-radius: 0; display: block; text-align: left; font-weight: 400; cursor: pointer; }
.cal .day.out { opacity: 0.45; }
.cal .day .n { font-size: 0.8rem; font-weight: 700; }
.cal .day.today .n { background: var(--accent); color: var(--accent-ink); border-radius: 999px; padding: 0 0.4rem; }
.cal .day.sel { outline: 2px solid var(--accent); outline-offset: -2px; }
.cal .dots { display: flex; flex-wrap: wrap; gap: 2px; margin-top: 2px; }
.cal .ev { display: block; font-size: 0.7rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; background: var(--accent-soft); border-radius: 4px; padding: 0 3px; margin-top: 2px; }
@media (max-width: 600px) {
  .cal .ev { display: none; }
  .cal .day { min-height: 48px; }
  .cal .dots::after { content: attr(data-count); font-size: 0.68rem; color: var(--accent); font-weight: 700; }
}
@media (min-width: 601px) { .cal .dots { display: block; } }

/* person page */
.person-head { display: flex; gap: 1rem; align-items: center; }
.kv { display: grid; grid-template-columns: minmax(110px, 35%) 1fr; gap: 0.4rem 1rem; margin: 0; }
.kv dt { color: var(--muted); font-size: 0.9rem; }
.kv dd { margin: 0; white-space: pre-wrap; overflow-wrap: anywhere; }
.field-row { display: grid; grid-template-columns: 1fr 1.4fr auto; gap: 0.5rem; margin-bottom: 0.5rem; }
.person-pick { max-height: 220px; overflow: auto; border: 1px solid var(--line); border-radius: 10px; padding: 0.4rem; }
.person-pick .check { padding: 0.35rem 0.3rem; }

/* tree */
.tree-wrap { position: relative; height: calc(100dvh - 57px - var(--nav-h) - env(safe-area-inset-bottom)); background: var(--bg); }
@media (min-width: 900px) { .tree-wrap { height: calc(100dvh - 57px); } }
.tree-host { position: absolute; inset: 0; }
.tree-svg { width: 100%; height: 100%; display: block; touch-action: none; cursor: grab; user-select: none; -webkit-user-select: none; }
.tree-svg:active { cursor: grabbing; }
.tree-lines path, .tree-lines line { fill: none; stroke: var(--muted); stroke-width: 1.6; opacity: 0.7; }
.tree-lines line.partner { stroke: var(--accent); stroke-width: 2.4; opacity: 0.8; }
.tree-lines line.partner.ended { stroke-dasharray: 5 5; }
.tree-svg .card { cursor: pointer; }
.tree-svg .card-bg { fill: var(--surface); stroke: var(--line); stroke-width: 1.2; filter: drop-shadow(0 1px 2px rgb(0 0 0 / 0.08)); }
.tree-svg .card.me .card-bg { stroke: var(--accent); stroke-width: 2; }
.tree-svg .card.focus .card-bg { stroke: var(--accent); stroke-width: 3; }
.tree-svg .card.deceased .card-bg { fill: var(--surface-2); }
.tree-svg .card:focus { outline: none; }
.tree-svg .card:focus-visible .card-bg { stroke: var(--accent); stroke-width: 3; }
.tree-svg .card-name { font: 600 14px var(--font); fill: var(--text); }
.tree-svg .card-sub { font: 12px var(--font); fill: var(--muted); }
.tree-tools { position: absolute; top: 0.75rem; left: 0.75rem; right: 0.75rem; display: flex; gap: 0.5rem; flex-wrap: wrap; pointer-events: none; }
.tree-tools > * { pointer-events: auto; }
.tree-tools select { width: auto; max-width: 60vw; box-shadow: var(--shadow); }
.tree-tools .zoom { position: fixed; right: 0.75rem; bottom: calc(var(--nav-h) + 0.75rem + env(safe-area-inset-bottom)); display: flex; gap: 0.35rem; }
@media (min-width: 900px) { .tree-tools .zoom { bottom: 1.25rem; right: 1.25rem; } }
.tree-tools button { box-shadow: var(--shadow); }

/* dialogs */
dialog {
  border: 0; padding: 0; border-radius: 18px; background: var(--surface); color: var(--text);
  width: min(560px, calc(100vw - 1.5rem)); max-height: calc(100dvh - 2rem);
  box-shadow: 0 20px 60px rgb(0 0 0 / 0.3);
}
dialog:modal { overscroll-behavior: contain; }
dialog::backdrop { background: rgb(20 12 6 / 0.45); overflow: hidden; overscroll-behavior: contain; }
@media (max-width: 600px) {
  dialog:modal { margin: auto 0 0; width: 100vw; max-width: 100vw; border-radius: 18px 18px 0 0; max-height: 92dvh; padding-bottom: env(safe-area-inset-bottom); }
}
.dlg-head { display: flex; align-items: center; justify-content: space-between; padding: 1rem 1rem 0.25rem 1.25rem; position: sticky; top: 0; background: var(--surface); z-index: 1; }
.dlg-head h2 { margin: 0; }
.dlg-body { padding: 0.75rem 1.25rem 0.5rem; }
.dlg-foot { display: flex; gap: 0.5rem; justify-content: flex-end; padding: 0.75rem 1.25rem 1.25rem; flex-wrap: wrap; position: sticky; bottom: 0; background: var(--surface); }
.dlg-foot .left { margin-right: auto; }

/* login */
.login { min-height: 100dvh; display: grid; place-items: center; padding: 1.5rem; }
.login .card { width: min(420px, 100%); padding: 1.75rem; }
.login .logo { width: 64px; height: 64px; display: block; margin-bottom: 0.75rem; }
.code-input { font-size: 1.6rem; letter-spacing: 0.4em; text-align: center; font-variant-numeric: tabular-nums; }

/* toast */
.toast {
  position: fixed; left: 50%; transform: translateX(-50%); bottom: calc(var(--nav-h) + 1.25rem + env(safe-area-inset-bottom)); z-index: 100;
  background: var(--text); color: var(--bg); padding: 0.7rem 1.1rem; border-radius: 12px; font-weight: 600; box-shadow: var(--shadow);
  max-width: calc(100vw - 2rem);
}
.toast:empty { display: none; }
.copy-field { display: flex; gap: 0.4rem; }
.copy-field input { font-family: ui-monospace, monospace; font-size: 0.8rem; }
.badge { display: inline-block; font-size: 0.72rem; font-weight: 700; padding: 0.1rem 0.5rem; border-radius: 999px; background: var(--surface-2); color: var(--muted); text-transform: uppercase; letter-spacing: 0.04em; }
.spinner { display: grid; place-items: center; padding: 3rem; color: var(--muted); }

/* public calendar page */
.public-view .content { padding-bottom: calc(2rem + env(safe-area-inset-bottom)); }
.public-view .toast { bottom: calc(1.25rem + env(safe-area-inset-bottom)); }
.public-view .brand span { overflow: hidden; text-overflow: ellipsis; }
.public-view .brand { min-width: 0; }

/* personal dates editor */
.date-row { border: 1px solid var(--line); border-radius: 12px; padding: 0.6rem; display: grid; gap: 0.5rem; }
.date-row .row > .grow { min-width: 8rem; }
