:root {
  --ink: #142033;
  --blue: #0038a8;
  --sun: #fcd116;
  --red: #ce1126;
  --paper: #eef3f9;
  --card: #ffffff;
  --line: #d3deec;
  --field: #c5d3e4;
  --muted: #5a6b82;
  --soft: #e7eef8;
  --sans: "Segoe UI", system-ui, sans-serif;
  color: var(--ink);
  background: var(--paper);
  font-family: var(--sans);
  font-size: 15px;
  line-height: 1.4;
}
html:has(body.viewer) { background: #f4f1ea; }
body.viewer {
  --ink: #241c14;
  --paper: #f4f1ea;
  --card: #fffcf7;
  --line: #e3dacb;
  --field: #d4cbbd;
  --muted: #6e655b;
  --soft: #f6f0e6;
  --gold: #c8960a;
  background: #f4f1ea;
  color: var(--ink);
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body { display: flex; flex-direction: column; }
button, input, select { font: inherit; color: inherit; }
button { cursor: pointer; }
.vh {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.topbar {
  display: flex;
  align-items: center;
  gap: 18px;
  padding: 12px 18px;
  border-bottom: 3px solid var(--sun);
  background: var(--blue);
  color: #fff;
}
.wordmark {
  display: flex;
  align-items: center;
  gap: 10px;
  color: #fff;
  text-decoration: none;
  font-size: 20px;
  font-weight: 650;
  letter-spacing: -0.01em;
  white-space: nowrap;
}
.mark {
  display: block;
  flex: none;
  border-radius: 50%;
  background: #fff;
  box-shadow: 0 0 0 2px var(--sun);
}
.filemeta { margin: 0; color: rgba(255, 255, 255, 0.84); font-size: 13px; }
.editlink { margin-left: auto; color: #fff; font-size: 14px; font-weight: 600; text-decoration: none; }
.editlink:hover { color: var(--sun); }
body.viewer .topbar {
  gap: 14px;
  padding: 10px 18px;
  border-bottom: 2px solid var(--sun);
  background: var(--paper);
  color: var(--ink);
}
body.viewer .wordmark { color: var(--ink); font-size: 18px; }
body.viewer .filemeta { color: var(--muted); white-space: nowrap; }
body.viewer .editlink { margin-left: 14px; color: var(--blue); }
body.viewer .editlink:hover { color: var(--red); }
body.viewer .headnav { display: flex; gap: 2px; margin-left: auto; }
body.viewer .headnav button {
  border: 0;
  background: transparent;
  color: var(--muted);
  padding: 6px 10px;
  border-radius: 999px;
  font-weight: 650;
}
body.viewer .headnav button[aria-current="page"] { color: var(--blue); background: rgba(0, 56, 168, 0.08); }
body.viewer .finder { position: relative; width: min(440px, 42vw); }
body.viewer .finder .search input { border-radius: 999px; background: var(--card); }
body.viewer .finder-panel {
  position: absolute;
  z-index: 20;
  top: calc(100% + 6px);
  left: 0;
  right: 0;
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 12px;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 14px;
  box-shadow: 0 16px 40px rgba(36, 28, 20, 0.12);
}
body.viewer .finder-panel[hidden] { display: none; }
body.viewer .finder-panel .list { flex: none; height: min(320px, 46vh); }

.workspace { flex: 1; display: flex; min-height: 0; }
.aside {
  width: 320px;
  flex: none;
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 12px;
  border-right: 1px solid var(--line);
  background: var(--card);
  min-height: 0;
}
.search input, select, .yrrow input {
  width: 100%;
  padding: 8px 10px;
  border: 1px solid var(--field);
  border-radius: 6px;
  background: var(--card);
}
.extra-filters { display: flex; flex-direction: column; gap: 8px; }
.yrrow { display: flex; gap: 8px; }
.yrrow label { flex: 1; }
.countrow { display: flex; align-items: center; justify-content: space-between; min-height: 24px; }
.count { margin: 0; color: var(--muted); font-size: 13px; }
.textbtn {
  border: 0;
  background: transparent;
  color: var(--blue);
  padding: 0;
  font-weight: 600;
}
.list { position: relative; flex: 1; overflow: auto; min-height: 0; }
#spacer { position: relative; }
.empty { margin: 12px 4px; color: var(--muted); }
.prow {
  position: absolute;
  left: 0;
  right: 0;
  height: 52px;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: flex-start;
  padding: 0 10px;
  border: 0;
  border-left: 3px solid transparent;
  background: transparent;
  text-align: left;
}
.prow:hover { background: var(--soft); }
.prow.sel { background: #e4eefb; border-left-color: var(--sun); }
.nm, .ls { max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.nm { font-size: 16px; font-weight: 600; }
.ls { color: var(--muted); font-size: 12px; }

.stage { flex: 1; min-height: 0; overflow: auto; padding: 28px 32px 48px; }
.stage.charting {
  display: flex;
  flex-direction: column;
  overflow: hidden;
  padding: 12px 16px 16px;
}
.chart-frame { position: relative; flex: 1; min-height: 0; display: flex; flex-direction: column; }
.page-title { margin: 0 0 8px; font-size: 32px; font-weight: 650; letter-spacing: -0.03em; }
.banner {
  margin: 12px 16px 0;
  padding: 10px 12px;
  background: #fff8d4;
  border: 1px solid #e4c84a;
  border-radius: 8px;
  max-height: 150px;
  overflow: auto;
}
.banner ul { margin: 6px 0; padding-left: 18px; }
.banner li { margin: 2px 0; }
.banner p { margin: 0; }
.loading { color: var(--muted); }
.life {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 300px;
  gap: 36px;
  align-items: start;
  max-width: 1040px;
}
.story h1 {
  margin: 0;
  font-size: 42px;
  font-weight: 650;
  letter-spacing: -0.03em;
  line-height: 1.05;
}
.lifeline { margin: 8px 0 0; color: var(--muted); font-size: 17px; }
.akas { margin: 6px 0 0; color: var(--muted); }
.rail { list-style: none; margin: 28px 0 0; padding: 0; }
.rail li { display: grid; grid-template-columns: 132px 18px minmax(0, 1fr); column-gap: 12px; }
.rail-date { text-align: right; color: var(--muted); padding-top: 1px; }
.rail-age { display: block; font-size: 12px; }
.rail-spine { position: relative; }
.rail-spine::before {
  content: "";
  position: absolute;
  left: 50%;
  top: 0;
  bottom: 0;
  width: 1px;
  background: var(--line);
}
.rail li:first-child .rail-spine::before { top: 8px; }
.rail li:last-child .rail-spine::before { height: 10px; bottom: auto; }
.rail-spine::after {
  content: "";
  position: absolute;
  left: 50%;
  top: 5px;
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: var(--blue);
  box-shadow: 0 0 0 2px var(--sun);
  transform: translateX(-50%);
}
.rail-what { padding-bottom: 18px; }
.rail-label { font-weight: 650; }
.rail-place { color: var(--muted); }
.notes { margin-top: 8px; max-width: 62ch; }
.notes h2 {
  margin: 0 0 6px;
  font-size: 12px;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--blue);
}
.notes p { white-space: pre-wrap; margin: 0 0 10px; }
.kin {
  position: sticky;
  top: 0;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 8px 14px 14px;
}
.kin h2, .union h3 {
  margin: 14px 0 8px;
  font-size: 12px;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--blue);
  font-weight: 650;
}
.kinempty { margin: 8px 0; color: var(--muted); }
.kincard {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  width: 100%;
  margin: 0 0 6px;
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--paper);
  text-align: left;
}
.kincard:hover { border-color: #b9c3ea; }
.kinrole { font-size: 11px; letter-spacing: 0.04em; text-transform: uppercase; color: var(--muted); }
.kinnm { font-weight: 650; }
.kinyears { font-size: 12px; color: var(--muted); }
.kin-actions { display: flex; flex-direction: column; gap: 8px; margin-top: 16px; }
.kin-actions button {
  border: 1px solid var(--line);
  background: var(--card);
  border-radius: 10px;
  padding: 8px 12px;
  font-weight: 650;
  color: var(--blue);
}
.kin-actions button.primary { background: var(--blue); color: #fff; border-color: var(--blue); }
.life-sheet {
  position: absolute;
  top: 0;
  right: 0;
  bottom: 0;
  z-index: 2;
  width: min(380px, 100%);
  overflow: auto;
  padding: 12px 16px 28px;
  background: var(--card);
  border-left: 1px solid var(--line);
  box-shadow: -16px 0 36px rgba(36, 28, 20, 0.1);
  animation: sheet-in 180ms ease;
}
.life-sheet .story h1 { font-size: 28px; }
.life-sheet .kin { position: static; margin-top: 18px; padding: 0; border: 0; background: transparent; }
@keyframes sheet-in {
  from { transform: translateX(18px); opacity: 0; }
  to { transform: none; opacity: 1; }
}
.sheet-bar { display: flex; justify-content: flex-end; }
.sheet-close {
  border: 0;
  background: transparent;
  color: var(--blue);
  font-weight: 650;
  padding: 0;
}

.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 16px 18px;
  margin-bottom: 14px;
}
.card h2 { font-size: 26px; font-weight: 650; letter-spacing: -0.02em; margin: 0; }
.psub { margin: 4px 0 0; color: var(--muted); }
.chips { display: flex; gap: 6px; margin-top: 10px; }
.chip {
  font-size: 12px;
  padding: 2px 8px;
  border-radius: 999px;
  background: var(--soft);
  color: var(--ink);
}
.group { margin-top: 16px; }
.group h3 {
  margin: 0 0 6px;
  font-size: 12px;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--blue);
  font-weight: 600;
}
.event, .relrow { display: grid; grid-template-columns: 140px 1fr; gap: 8px; padding: 4px 0; }
.evdate { color: var(--muted); }
.note { white-space: pre-wrap; margin: 6px 0; }
.people { display: flex; flex-wrap: wrap; gap: 6px; }
.pill, .linkish {
  border: 0;
  background: var(--soft);
  border-radius: 999px;
  padding: 4px 10px;
}
.linkish { padding: 0; background: none; color: var(--blue); text-decoration: underline; text-underline-offset: 2px; }

.chart-controls { display: flex; flex-wrap: wrap; gap: 12px; align-items: center; margin-bottom: 8px; }
.seg { display: flex; border: 1px solid var(--line); border-radius: 8px; overflow: hidden; }
.seg button { border: 0; background: transparent; padding: 6px 12px; }
.seg button[aria-pressed="true"] { background: var(--blue); color: #fff; }
.genctl, .zoomctl { display: flex; align-items: center; gap: 8px; color: var(--muted); font-size: 13px; }
.zoomctl button, .relbtn {
  border: 1px solid var(--line);
  background: var(--card);
  border-radius: 6px;
  padding: 6px 10px;
}
.hint { margin: 0 0 8px; color: var(--muted); font-size: 13px; }
.viewport {
  flex: 1;
  min-height: 0;
  overflow: hidden;
  position: relative;
  background:
    linear-gradient(var(--paper), var(--paper)),
    var(--paper);
  border: 1px solid var(--line);
  border-radius: 10px;
  cursor: grab;
  touch-action: none;
  user-select: none;
}
.viewport.dragging { cursor: grabbing; }
.chart-stage { position: absolute; top: 0; left: 0; transform-origin: 0 0; }
.chart-stage text { fill: var(--ink); }
.chart-stage .years, .chart-stage .spouse { font-size: 11px; fill: var(--muted); }
.chart-stage .empty-label { font-size: 12px; fill: var(--muted); }
.chart-stage .colhead { font-size: 11px; fill: var(--blue); letter-spacing: 0.04em; font-weight: 650; }
.chart-stage rect.person, .chart-stage circle.person { fill: var(--card); stroke: var(--blue); stroke-width: 1.25; }
.chart-stage rect.person.on, .chart-stage circle.person.on { stroke: var(--gold, #c8960a); stroke-width: 2.75; }
.chart-stage rect.person.path, .chart-stage circle.person.path { stroke: var(--red); stroke-width: 2.5; }
.chart-stage rect.missing { fill: transparent; stroke: #b7c6da; stroke-dasharray: 3 3; }
.chart-stage path.link { fill: none; stroke: #7d93b8; stroke-width: 1.25; }
.chart-stage path.link.path { stroke: var(--red); stroke-width: 2.25; }
.chart-stage path.wedge { stroke: #fff; stroke-width: 1; cursor: pointer; }
.chart-stage path.wedge.on { stroke: var(--gold, #c8960a); stroke-width: 2.75; }
.chart-stage path.wedge.path { stroke: var(--red); stroke-width: 2.5; }
.chart-stage path.wedge.missing { fill: #e4ebf5; cursor: default; }
.chart-stage [data-id] { cursor: pointer; }

.relpickers { display: flex; flex-wrap: wrap; gap: 12px; align-items: end; }
.relpickers label { display: flex; flex-direction: column; gap: 4px; font-size: 13px; color: var(--muted); position: relative; }
.relpickers input { width: 240px; padding: 8px 10px; border: 1px solid var(--field); border-radius: 6px; background: white; }
.suggest {
  position: absolute;
  z-index: 2;
  top: 100%;
  left: 0;
  right: 0;
  margin: 2px 0 0;
  padding: 4px;
  list-style: none;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 8px;
  max-height: 220px;
  overflow: auto;
}
.suggest button { display: block; width: 100%; text-align: left; border: 0; background: transparent; padding: 6px 8px; border-radius: 6px; }
.suggest button:hover { background: var(--soft); }
.verdict { font-size: 24px; font-weight: 650; letter-spacing: -0.02em; margin: 16px 0 8px; }
.blood-kicker {
  margin: 18px 0 8px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 650;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}
.blood-sentence { margin: 0; max-width: 440px; }
.blood-name {
  display: block;
  width: 100%;
  border: 0;
  background: none;
  padding: 0;
  color: var(--blue);
  font-size: 26px;
  font-weight: 750;
  letter-spacing: -0.02em;
  line-height: 1.15;
  text-align: left;
}
.blood-name:hover { text-decoration: underline; }
.blood-is { display: block; margin: 3px 0; font-size: 18px; }
.blood-rule {
  width: min(100%, 420px);
  height: 0;
  margin: 12px 0 16px;
  border: 0;
  border-top: 3px solid var(--blue);
}
.tracing .ladder-arrow,
.tracing .ladder-via { color: var(--red); }
.tracing .blood-rule { border-top-color: var(--red); }
.tracing .rbox { border-color: var(--red); }
.path-jump { margin-top: 14px; }
.ladder {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  column-gap: 22px;
  justify-content: start;
  width: min(100%, 322px);
}
.ladder.single { grid-template-columns: minmax(0, 1fr); width: min(100%, 150px); }
.ladder-ancestor { grid-column: 1 / -1; display: flex; justify-content: center; }
.ladder-ancestor .rbox { width: calc((100% - 22px) / 2); }
.ladder.single .ladder-ancestor .rbox,
.ladder.single > .ladder-col .rbox { width: 100%; }
.ladder-row { display: contents; }
.ladder-col { display: flex; flex-direction: column; align-items: stretch; min-width: 0; }
.ladder-blank { display: block; }
.ladder-arrow {
  height: 18px;
  color: #5d6e8c;
  font-size: 15px;
  line-height: 18px;
  text-align: center;
}
.ladder-via {
  margin: 5px 0;
  color: var(--blue);
  font-size: 11px;
  font-weight: 650;
  letter-spacing: 0.06em;
  text-align: center;
  text-transform: uppercase;
}
.rbox {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  min-height: 52px;
  margin: 0;
  padding: 8px 10px;
  border: 1px solid #c5cdec;
  border-radius: 10px;
  background: #e4e9fb;
  color: #1e3a8a;
  font-size: 14px;
  font-weight: 650;
  line-height: 1.2;
  text-align: center;
}
.rbox.f { background: #f8c9c6; border-color: #e7aaa6; color: #7a2430; }
.rbox:hover { filter: brightness(0.97); }

.tl { list-style: none; margin: 0; padding: 0; }
.tl li { display: grid; grid-template-columns: 92px 16px 1fr; gap: 8px; }
.tlyear { text-align: right; color: var(--muted); padding-top: 2px; }
.tlage { display: block; font-size: 12px; }
.tldot {
  width: 9px;
  height: 9px;
  margin-top: 6px;
  border-radius: 50%;
  background: var(--blue);
  box-shadow: 0 0 0 2px var(--sun);
  justify-self: center;
}
.tlplace { color: var(--muted); }

.placerow, .snrow { padding: 8px 0; border-bottom: 1px solid var(--line); }
.placename, .snname { font-size: 18px; font-weight: 650; }
.snname { border: 0; background: none; padding: 0; text-align: left; }
.snname.on { color: var(--blue); }
.placecount, .sncount { color: var(--muted); font-size: 13px; }
.snbar { height: 8px; background: #dce6f3; border-radius: 99px; margin: 6px 0; }
.snfill { height: 100%; background: var(--blue); border-radius: 99px; }
.placepeople { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 6px; }

@media (max-width: 640px) {
  .blood-name { font-size: 22px; }
  .ladder { column-gap: 12px; width: min(100%, 280px); }
  .ladder-ancestor .rbox { width: calc((100% - 12px) / 2); }
  .wordmark { min-width: 0; }
  body.viewer .story h1 { font-size: 32px; }
  body.viewer .topbar { flex-wrap: wrap; }
  body.viewer .editlink { grid-column: auto; }
}
@media (max-width: 800px) {
  .workspace { flex-direction: column; }
  .aside {
    width: auto;
    height: min(55vh, 440px);
    border-right: 0;
    border-bottom: 1px solid var(--line);
  }
  body.viewer .topbar { flex-wrap: wrap; }
  body.viewer .wordmark { order: 1; }
  body.viewer .headnav { order: 2; margin-left: auto; }
  body.viewer .filemeta { order: 3; flex-basis: auto; }
  body.viewer .editlink { order: 4; margin-left: auto; }
  body.viewer .finder { order: 5; width: 100%; }
  body.viewer .life { grid-template-columns: 1fr; }
  body.viewer .kin { position: static; }
  body.viewer .finder.finding {
    position: fixed;
    left: 0;
    right: 0;
    top: 0;
    z-index: 40;
    width: auto;
    height: 100dvh;
    display: flex;
    flex-direction: column;
    gap: 8px;
    padding: max(12px, env(safe-area-inset-top)) 12px 12px;
    background: var(--card);
  }
  body.viewer .finder.finding .finder-panel {
    position: static;
    flex: 1;
    width: auto;
    min-height: 0;
    border: 0;
    box-shadow: none;
    padding: 0;
  }
  body.viewer .finder.finding .finder-panel .list { height: auto; max-height: none; flex: 1; }
  body.viewer .finder.finding .search-done { display: inline; }
  .search-done { display: none; }
  .event, .relrow { grid-template-columns: 1fr; gap: 0; }
  .relpickers input { width: min(240px, 70vw); }
  .card h2 { font-size: 24px; }
  .life-sheet { width: 100%; }
}
