:root {
  --bg: #f6f7f9;
  --surface: #ffffff;
  --surface-2: #f1f3f6;
  --text: #14171c;
  --muted: #5f6673;
  --line: #e3e6eb;
  --accent: #4f46e5;
  --accent-soft: #eceafd;
  --good: #0f8a5f;
  --good-soft: #e3f5ee;
  --warn: #a15c00;
  --warn-soft: #fdf1e1;
  --sim: #6b4fd8;
  --sim-soft: #f0ebfd;
  --source: #0b6bcb;
  --source-soft: #e5f1fc;
  --shadow: 0 1px 2px rgba(20, 23, 28, 0.04), 0 8px 24px rgba(20, 23, 28, 0.06);
  --radius: 16px;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Inter, Roboto, "Helvetica Neue", Arial, sans-serif;
  color-scheme: light dark;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1115;
    --surface: #171a20;
    --surface-2: #1e222a;
    --text: #eceef2;
    --muted: #9aa1ad;
    --line: #2a2f38;
    --accent: #8b85ff;
    --accent-soft: #24223f;
    --good: #4fd1a1;
    --good-soft: #13302a;
    --warn: #f0b45a;
    --warn-soft: #33270f;
    --sim: #b6a2ff;
    --sim-soft: #272040;
    --source: #6cb6ff;
    --source-soft: #132a3f;
    --shadow: 0 1px 2px rgba(0, 0, 0, 0.3), 0 8px 24px rgba(0, 0, 0, 0.3);
  }
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-size: 15px;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
}

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

.topbar {
  position: sticky;
  top: 0;
  z-index: 5;
  display: flex;
  align-items: center;
  gap: 24px;
  padding: 14px max(16px, calc((100vw - 1040px) / 2));
  background: color-mix(in srgb, var(--bg) 85%, transparent);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--line);
}

.brand { display: flex; align-items: center; gap: 10px; color: var(--text); font-weight: 650; font-size: 18px; letter-spacing: -0.01em; }
.brand:hover { text-decoration: none; }
.brand-mark {
  display: grid; place-items: center; width: 30px; height: 30px; border-radius: 9px;
  background: linear-gradient(135deg, var(--accent), var(--sim)); color: #fff; font-weight: 700;
}

.tabs { display: flex; gap: 4px; flex: 1; overflow-x: auto; }
.tabs a { padding: 7px 12px; border-radius: 999px; color: var(--muted); font-weight: 550; white-space: nowrap; }
.tabs a:hover { background: var(--surface-2); text-decoration: none; }
.tabs a.active { background: var(--accent-soft); color: var(--accent); }

main { max-width: 1040px; margin: 0 auto; padding: 28px 16px 48px; }

h1 { font-size: 28px; line-height: 1.2; letter-spacing: -0.02em; margin: 0 0 6px; }
h2 { font-size: 17px; margin: 0 0 12px; letter-spacing: -0.01em; }
h3 { font-size: 15px; margin: 0 0 8px; }
p { margin: 0 0 10px; }
.lede { color: var(--muted); font-size: 16px; max-width: 62ch; }
.muted { color: var(--muted); }
.small { font-size: 13px; color: var(--muted); }

.grid { display: grid; gap: 16px; }
.grid.two { grid-template-columns: minmax(0, 1.4fr) minmax(0, 1fr); }
.grid.cards { grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); }
@media (max-width: 760px) { .grid.two { grid-template-columns: 1fr; } }

.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 20px;
  box-shadow: var(--shadow);
}
.card + .card { margin-top: 16px; }
.grid > .card + .card { margin-top: 0; }

.hero { padding: 28px; display: flex; gap: 20px; align-items: center; }
.hero .avatar { width: 64px; height: 64px; font-size: 24px; }

.avatar {
  flex: none; display: grid; place-items: center; width: 42px; height: 42px; border-radius: 50%;
  font-weight: 650; color: #fff; background: var(--accent);
}
.avatar.org { border-radius: 12px; }
.avatar.place { border-radius: 12px 12px 12px 2px; }
.place-line { margin-top: 4px; }
.place-line .inline { margin-top: 6px; }

.person-card { display: flex; flex-direction: column; gap: 10px; color: var(--text); transition: transform 0.12s ease, border-color 0.12s ease; }
.person-card:hover { transform: translateY(-2px); border-color: color-mix(in srgb, var(--accent) 40%, var(--line)); text-decoration: none; }
.row { display: flex; align-items: center; gap: 12px; }
.row.between { justify-content: space-between; }
.stack { display: flex; flex-direction: column; gap: 4px; min-width: 0; }
.name { font-weight: 620; }

.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip { font-size: 12px; font-weight: 600; padding: 3px 9px; border-radius: 999px; background: var(--surface-2); color: var(--muted); }
.chip.sim { background: var(--sim-soft); color: var(--sim); }
.chip.claimed { background: var(--good-soft); color: var(--good); }
.chip.source { background: var(--source-soft); color: var(--source); }
.chip.warn { background: var(--warn-soft); color: var(--warn); }

.status { display: inline-flex; align-items: center; gap: 8px; font-weight: 600; font-size: 14px; }
.status::before { content: ""; width: 8px; height: 8px; border-radius: 50%; background: var(--muted); }
.status.live::before { background: var(--good); box-shadow: 0 0 0 4px var(--good-soft); }
.status.waiting::before { background: var(--warn); }

.timeline { list-style: none; margin: 0; padding: 0; }
.timeline li { position: relative; padding: 0 0 18px 24px; }
.timeline li::before { content: ""; position: absolute; left: 6px; top: 8px; bottom: -4px; width: 2px; background: var(--line); }
.timeline li:last-child::before { display: none; }
.timeline li::after { content: ""; position: absolute; left: 1px; top: 4px; width: 12px; height: 12px; border-radius: 50%; background: var(--surface); border: 2px solid var(--sim); }
.timeline .when { font-size: 12px; color: var(--muted); }
.timeline .title { font-weight: 600; }
.day { font-size: 12px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.06em; color: var(--muted); margin: 18px 0 10px; }

.section-title { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 12px; }
.section-title h2 { margin: 0; }

.facts { list-style: none; padding: 0; margin: 0; display: grid; gap: 10px; }
.facts li { padding: 12px 14px; border-radius: 12px; background: var(--surface-2); }
.facts .label { font-size: 12px; font-weight: 650; text-transform: capitalize; color: var(--muted); }

.empty { padding: 18px; border-radius: 12px; border: 1px dashed var(--line); color: var(--muted); text-align: center; }

form { display: grid; gap: 14px; }
.field { display: grid; gap: 6px; }
.field > span { font-size: 13px; font-weight: 600; }
.field .hint { font-size: 12px; color: var(--muted); font-weight: 400; }
input, select, textarea {
  font: inherit; color: var(--text); background: var(--surface); border: 1px solid var(--line);
  border-radius: 10px; padding: 10px 12px; width: 100%;
}
input:focus, select:focus, textarea:focus { outline: 2px solid color-mix(in srgb, var(--accent) 45%, transparent); border-color: var(--accent); }
textarea { resize: vertical; min-height: 72px; }
.inline { display: grid; gap: 10px; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); }

button {
  font: inherit; font-weight: 600; cursor: pointer; border: 0; border-radius: 10px; padding: 10px 16px;
  background: var(--accent); color: #fff;
}
button:hover { filter: brightness(1.06); }
button:disabled { opacity: 0.55; cursor: default; }
button.ghost { background: transparent; color: var(--muted); border: 1px solid var(--line); }
button.ghost:hover { color: var(--text); background: var(--surface-2); }
button.link { background: none; color: var(--accent); padding: 0; }
.actions { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; }

.segments { display: flex; flex-wrap: wrap; gap: 8px; }
.segments button { background: var(--surface-2); color: var(--text); border: 1px solid var(--line); font-weight: 550; }
.segments button.on { background: var(--accent-soft); color: var(--accent); border-color: color-mix(in srgb, var(--accent) 35%, var(--line)); }

.steps { display: flex; gap: 8px; margin: 8px 0 22px; }
.steps span { flex: 1; height: 4px; border-radius: 4px; background: var(--line); }
.steps span.done { background: var(--accent); }

.entry { display: grid; gap: 10px; padding: 14px; border-radius: 12px; background: var(--surface-2); }
.entry + .entry { margin-top: 10px; }

.welcome { max-width: 640px; margin: 6vh auto 0; text-align: center; }
.welcome .brand-mark { width: 56px; height: 56px; font-size: 26px; border-radius: 16px; margin: 0 auto 18px; }
.promises { display: grid; gap: 12px; text-align: left; margin: 24px 0; }
.promises div { display: flex; gap: 12px; align-items: flex-start; padding: 14px; border-radius: 12px; background: var(--surface); border: 1px solid var(--line); }
.promises b { display: block; }

.toast { position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%); z-index: 10; padding: 10px 16px; border-radius: 12px; background: var(--text); color: var(--bg); font-weight: 550; box-shadow: var(--shadow); }
.toast.error { background: #b42318; color: #fff; }

.footnote { max-width: 1040px; margin: 0 auto; padding: 0 16px 32px; font-size: 12px; color: var(--muted); }
.badge-status { font-size: 12px; font-weight: 650; padding: 2px 8px; border-radius: 6px; background: var(--surface-2); color: var(--muted); text-transform: capitalize; }
.badge-status.active, .badge-status.satisfied { background: var(--good-soft); color: var(--good); }
.badge-status.blocked, .badge-status.conflicted { background: var(--warn-soft); color: var(--warn); }

.narrow { max-width: 680px; margin: 0 auto; }
.mt { margin-top: 16px; }
.mt-sm { margin-top: 12px; }
.mt-xs { margin-top: 8px; }
.my { margin: 18px 0; }
.mb { margin-bottom: 16px; }
.actions.center { justify-content: center; }

[hidden] { display: none !important; }

.graph { width: 100%; height: auto; max-height: 58vh; display: block; margin: 12px 0; }
.graph-edge { stroke: var(--line); stroke-width: 1.5; }
.graph-you { fill: var(--accent); }
.graph-you-label { fill: #fff; font-weight: 700; font-size: 14px; }
.graph-group { fill: var(--muted); font-size: 12px; font-weight: 700; letter-spacing: 0.06em; text-transform: uppercase; }
.graph-node { cursor: pointer; }
.graph-node:focus { outline: none; }
.graph-node:hover circle, .graph-node:hover rect, .graph-node:focus circle, .graph-node:focus rect { stroke: var(--text); stroke-width: 2; }
.graph-node.on circle, .graph-node.on rect { stroke: var(--accent); stroke-width: 3; }
.graph-node.unnamed circle, .graph-node.unnamed rect { stroke-dasharray: 4 3; stroke: var(--muted); stroke-width: 2; }
.graph-initials { fill: #fff; font-size: 12px; font-weight: 700; pointer-events: none; }
.graph-name { fill: var(--text); font-size: 12px; font-weight: 600; }
.graph-relation { fill: var(--muted); font-size: 11px; }
.segments + .graph, .segments + .card { margin-top: 12px; }
.wide { max-width: 1120px; margin: 0 auto; }
.graph-region { fill: var(--surface-2); stroke: var(--line); stroke-width: 1; }
.graph-region.family { fill: color-mix(in srgb, var(--accent) 7%, var(--surface)); }
.graph-region.friends { fill: color-mix(in srgb, var(--good) 8%, var(--surface)); }
.graph-region.work { fill: color-mix(in srgb, var(--warn) 8%, var(--surface)); }
.people-detail { min-width: 0; }
@media (min-width: 960px) {
  .people-pane { display: grid; grid-template-columns: minmax(0, 3fr) minmax(0, 2fr); gap: 20px; align-items: start; }
  .people-detail { position: sticky; top: 16px; }
}
.wide > div > .actions { position: sticky; bottom: 0; background: var(--surface); padding: 12px 0; border-top: 1px solid var(--line); }
.badge-status.plain { text-transform: none; }
.steps span { position: relative; }
.steps span b { position: absolute; top: 8px; left: 0; font-size: 12px; font-weight: 650; color: var(--muted); }
.steps span.done b { color: var(--accent); }
.steps { margin-bottom: 40px; }
.avatar.big { width: 64px; height: 64px; font-size: 22px; }
a.button { display: inline-block; font-weight: 600; border-radius: 10px; padding: 10px 16px; background: var(--accent); color: #fff; text-decoration: none; }
a.button:hover { filter: brightness(1.06); }
.when .badge-status { margin-left: 8px; }

details.fold > summary { cursor: pointer; font-weight: 650; list-style: none; }
details.fold > summary::-webkit-details-marker { display: none; }
details.fold > summary::after { content: " ▸"; color: var(--muted); }
details.fold[open] > summary::after { content: " ▾"; }
details.fold[open] > summary { margin-bottom: 12px; }
.hero .small { display: block; margin-top: 4px; }
ul.plain { list-style: none; margin: 0; padding: 0; display: grid; gap: 12px; }
ul.plain > li + li { border-top: 1px solid var(--line); padding-top: 12px; }
p.center, .muted.center, .small.center { text-align: center; }
