:root {
  /* the reading face, the same system sans the Bible companion reads in */
  --read-sans: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --paper: #f7f1e3;
  --ink: #241d12;
  --ink-soft: #5c5240;
  --ink-faint: #8d8064;
  --oxblood: #8b2a1d;
  --gold: #a97d1c;
  --gold-soft: #e9d9ae;
  --hairline: rgba(36, 29, 18, 0.18);
}

* { box-sizing: border-box; margin: 0; padding: 0; }

body {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  background: var(--paper);
  background-image:
    radial-gradient(ellipse 120% 80% at 50% -20%, rgba(255, 252, 242, 0.9), transparent 60%),
    radial-gradient(ellipse 100% 100% at 100% 120%, rgba(169, 125, 28, 0.08), transparent 55%);
  color: var(--ink);
  font-family: var(--read-sans);
  font-size: 17px;
}

/* ---------- masthead ---------- */

.masthead {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 1.5rem 2rem;
  padding: 1.1rem 1.6rem 0.9rem;
  border-bottom: 1px solid var(--ink);
  flex-wrap: wrap;
}

.wordmark {
  font-family: var(--sans);
  font-weight: 600;
  font-size: 1.9rem;
  letter-spacing: -0.01em;
  line-height: 1;
}

.wordmark em { font-style: italic; font-weight: 400; color: var(--oxblood); }

.tagline {
  margin-top: 0.3rem;
  font-style: italic;
  color: var(--ink-soft);
  font-size: 0.95rem;
}

.views { display: flex; gap: 0.5rem; flex-wrap: wrap; }

.views button {
  padding: 0.45rem 0.9rem;
  font-family: var(--sans);
  font-size: 0.85rem;
  letter-spacing: 0.04em;
  color: var(--ink);
  background: transparent;
  border: 1px solid var(--ink);
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
}

.views button:hover { background: var(--oxblood); border-color: var(--oxblood); color: var(--paper); }
.views button.active { background: var(--ink); color: var(--paper); }

/* ---------- legend ---------- */

.legend-bar {
  display: flex;
  align-items: center;
  gap: 0.4rem 1.3rem;
  flex-wrap: wrap;
  padding: 0.5rem 1.6rem;
  border-bottom: 1px solid var(--hairline);
  font-size: 0.82rem;
  font-style: italic;
  color: var(--ink-soft);
}

.legend-bar[hidden] { display: none; }
.legend-item { display: flex; align-items: center; gap: 0.45rem; }
.legend-hint { margin-left: auto; color: var(--ink-faint); }

.swatch { width: 14px; height: 10px; display: inline-block; }
.swatch-rail { width: 4px; height: 15px; background: var(--oxblood); }
.swatch-round { width: 12px; height: 12px; border-radius: 50%; }
.swatch-band {
  width: 15px; height: 15px; border-radius: 50%;
  border: 1.6px solid var(--ink-soft);
  background: rgba(255, 255, 255, 0.9);
}
.swatch-cluster {
  width: 18px; height: 12px;
  border: 1.3px dashed var(--ink-faint);
  background: rgba(255, 255, 255, 0.7);
  border-radius: 2px;
}
.swatch-elided {
  width: 18px; height: 12px;
  border: 1.6px dotted var(--oxblood);
  background: rgba(255, 255, 255, 0.7);
  border-radius: 2px;
}
.swatch-legal {
  width: 4px; height: 15px;
  background: repeating-linear-gradient(to bottom, var(--oxblood) 0 4px, transparent 4px 7px);
}

/* ---------- chart ---------- */

.chart-wrap {
  position: relative;
  padding: 0.8rem 1.2rem 0;
  max-width: 1340px;
  margin: 0 auto;
  width: 100%;
}

.chart-wrap[hidden] { display: none; }
#chart, #lives { width: 100%; height: auto; display: block; }

/* generation gutter + toledot rules */

.gen-rule { stroke: var(--hairline); stroke-width: 1; }

.gen-num {
  font-family: var(--read-sans);
  font-size: 10.5px;
  fill: var(--ink-faint);
  text-anchor: end;
  letter-spacing: 0.08em;
}

.tol-rule { stroke: rgba(169, 125, 28, 0.5); stroke-width: 1; stroke-dasharray: 2 3; }

.tol-text {
  font-family: var(--read-sans);
  font-style: italic;
  font-size: 11.5px;
  fill: var(--gold);
}

.tol-ref {
  font-family: var(--sans);
  font-size: 9.5px;
  letter-spacing: 0.1em;
  fill: var(--ink-faint);
}

.band-label {
  font-family: var(--sans);
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  fill: var(--ink-faint);
}

/* edges */

.edge {
  fill: none;
  stroke: var(--ink-soft);
  stroke-width: 1.4;
  opacity: 0.5;
  transition: opacity 0.25s, stroke-width 0.25s;
}
.edge.rail { stroke: var(--oxblood); stroke-width: 3.4; opacity: 0.85; }
/* Joseph to Jesus: the one rung joined by law rather than blood */
.edge.rail.legal { stroke-dasharray: 7 6; }
.edge.married-in { stroke: var(--gold); stroke-dasharray: 5 4; opacity: 0.75; }
.edge.union { stroke-width: 1.2; opacity: 0.42; }
.edge.cain { stroke: var(--ink-faint); stroke-dasharray: 3 3; opacity: 0.4; }
.edge.hot { opacity: 1; stroke-width: 2.6; }
.edge.dim { opacity: 0.08; }

/* nodes */

.node { cursor: pointer; outline: none; }
.node .hit { fill: transparent; }
.node .ring { fill: none; stroke: none; }
.node.selected .ring, .node:focus-visible .ring { stroke: var(--gold); stroke-width: 2.4; }
.node .body { stroke-width: 1.4; transition: opacity 0.25s; }
.node.dim { opacity: 0.2; }
.node.cluster .body { stroke-dasharray: 4 3; }
/* dashed already means "a group not drawn out"; someone who died early
   is faded instead, so the two never read as the same thing */
.node.gone .body { stroke-opacity: 0.4; }
/* and a king on the rail whom Matthew's list passes over is dotted — a
   third mark, so it reads as neither a cluster nor an early death */
.node.elided .body { stroke-dasharray: 1.5 3.5; stroke-width: 1.8; }
.node.elided .node-name { font-weight: 500; font-style: italic; }
/* the last rung */
.node.terminus .body { stroke-width: 2.4; }
.node.terminus .ring { stroke: var(--gold); stroke-width: 1.1; }
.node.terminus .node-name { font-size: 16px; }

.node-name {
  font-family: var(--sans);
  font-weight: 600;
  font-size: 13px;
  fill: var(--ink);
  text-anchor: middle;
  pointer-events: none;
}

.node.small .node-name { font-size: 11.5px; font-weight: 500; }
.node.band .node-name { font-family: var(--read-sans); font-style: italic; font-weight: 400; font-size: 12px; }
.node.cluster .node-name { font-family: var(--read-sans); font-style: italic; font-weight: 400; font-size: 12px; }

.node-years {
  font-family: var(--read-sans);
  font-style: italic;
  font-size: 10.5px;
  fill: var(--ink-soft);
  text-anchor: middle;
  pointer-events: none;
}

/* the small life-bar drawn inside each node in the tree view */
.node-life { pointer-events: none; }
.node-life .track { fill: rgba(36, 29, 18, 0.1); }
.node-life .fill { fill: var(--oxblood); opacity: 0.45; }

/* ---------- lifespan view ---------- */

.life-axis line { stroke: var(--hairline); stroke-width: 1; }

.life-tick {
  font-family: var(--read-sans);
  font-size: 11px;
  fill: var(--ink-faint);
  text-anchor: middle;
}

.life-grid { stroke: var(--hairline); stroke-width: 1; stroke-dasharray: 2 4; }

.life-event line { stroke: var(--oxblood); stroke-width: 1.2; opacity: 0.5; }
.life-event.flood line { stroke-width: 2; opacity: 0.75; }

.life-event text {
  font-family: var(--sans);
  font-size: 10.5px;
  letter-spacing: 0.08em;
  fill: var(--oxblood);
  text-anchor: end;
}

.life-row { cursor: pointer; outline: none; }
.life-row .hit { fill: transparent; }
.life-row .bar { transition: opacity 0.2s; }
.life-row.dim { opacity: 0.18; }
.life-row.hot .bar { stroke: var(--ink); stroke-width: 1.4; }

.life-name {
  font-family: var(--sans);
  font-size: 12px;
  fill: var(--ink);
  text-anchor: end;
  pointer-events: none;
}

.life-len {
  font-family: var(--read-sans);
  font-style: italic;
  font-size: 11px;
  fill: var(--ink-soft);
  pointer-events: none;
}

.life-taken { fill: none; stroke: var(--gold); stroke-width: 1.6; }

/* ---------- tooltip ---------- */

/* fixed, not absolute: the tooltip lives outside the chart panes, and the
   page scrolls a long way — viewport coordinates keep it under the cursor */
.tooltip {
  position: fixed;
  max-width: 320px;
  padding: 0.6rem 0.8rem;
  background: var(--ink);
  color: var(--paper);
  font-size: 0.85rem;
  line-height: 1.45;
  pointer-events: none;
  z-index: 10;
}

.tooltip .tip-ref {
  font-family: var(--sans);
  font-size: 0.8rem;
  letter-spacing: 0.06em;
  color: var(--gold-soft);
  display: block;
  margin-bottom: 0.2rem;
}

/* ---------- detail card ---------- */

.detail {
  max-width: 860px;
  margin: 0 auto;
  padding: 1.4rem 1.6rem 1.8rem;
  width: 100%;
}

.detail-hint {
  font-style: italic;
  color: var(--ink-faint);
  text-align: center;
  padding: 1rem 0;
}

.detail-kicker {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  font-size: 0.74rem;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--ink-soft);
  margin-bottom: 0.4rem;
}

.detail-kicker .swatch-round { width: 11px; height: 11px; }

.detail-name {
  font-family: var(--sans);
  font-weight: 600;
  font-size: 2rem;
  line-height: 1.05;
  margin-bottom: 0.2rem;
}

.detail-name .alt {
  font-weight: 400;
  font-style: italic;
  font-size: 1.2rem;
  color: var(--ink-soft);
}

.detail-dates {
  font-style: italic;
  color: var(--ink-soft);
  margin-bottom: 0.7rem;
}

.detail-dates b { font-weight: 600; font-style: normal; color: var(--ink); }

.detail-note {
  font-size: 1.2rem;
  line-height: 1.55;
  max-width: 62ch;
  margin-bottom: 1rem;
}

.detail-note em { color: var(--ink-soft); }

.lineage {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.4rem;
  margin-bottom: 0.7rem;
}

.lineage-cap {
  font-size: 0.74rem;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--ink-faint);
  margin-right: 0.3rem;
  flex: none;
}

.chip {
  font-family: var(--read-sans);
  font-size: 0.92rem;
  color: var(--ink);
  background: rgba(255, 255, 255, 0.75);
  border: 1px solid var(--hairline);
  padding: 0.22rem 0.6rem;
  cursor: pointer;
  transition: background 0.12s, border-color 0.12s;
}

.chip span { font-style: italic; color: var(--ink-faint); font-size: 0.85em; }
.chip:hover { background: var(--gold-soft); border-color: var(--gold); }
.chip.here { background: var(--gold-soft); border-color: var(--gold); }
.chip.flat { cursor: default; }
.chip.flat:hover { background: rgba(255, 255, 255, 0.75); border-color: var(--hairline); }

.detail-refs { display: flex; flex-wrap: wrap; gap: 0.45rem; }

.detail-refs a {
  font-family: var(--read-sans);
  font-size: 0.95rem;
  color: var(--ink);
  background: rgba(255, 255, 255, 0.75);
  border: 1px solid var(--hairline);
  padding: 0.25rem 0.65rem;
  text-decoration: none;
  transition: background 0.12s, border-color 0.12s;
}

.detail-refs a:hover { background: var(--gold-soft); border-color: var(--gold); }
.detail-refs a::after { content: " ↗"; color: var(--ink-faint); font-size: 0.8em; }

/* ---------- colophon ---------- */

.colophon {
  margin-top: auto;
  padding: 0.9rem 1.6rem;
  border-top: 1px solid var(--ink);
  font-size: 0.8rem;
  font-style: italic;
  line-height: 1.6;
  color: var(--ink-soft);
  text-align: center;
}

.colophon a { color: var(--oxblood); }
.colophon p + p { margin-top: 0.5rem; }

/* ---------- changelog ---------- */

.changelog {
  padding: 0.7rem 1.6rem 1.3rem;
  border-top: 1px solid var(--hairline);
  font-size: 0.8rem;
  line-height: 1.6;
  color: var(--ink-soft);
  text-align: center;
}

.changelog h2 {
  font-family: var(--sans);
  font-size: 0.68rem;
  font-weight: 600;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--ink-faint);
  margin-bottom: 0.35rem;
}

.changelog ul { list-style: none; max-width: 62rem; margin: 0 auto; }
.changelog li + li { margin-top: 0.3rem; }

.changelog time {
  font-family: var(--sans);
  font-size: 0.72rem;
  font-variant-numeric: tabular-nums;
  letter-spacing: 0.04em;
  color: var(--ink-faint);
  margin-right: 0.55rem;
  white-space: nowrap;
}

@media (max-width: 720px) {
  body { font-size: 16px; }
  .masthead { padding: 0.9rem 1rem 0.8rem; }
  .wordmark { font-size: 1.5rem; }
  .legend-bar { padding: 0.5rem 1rem; font-size: 0.78rem; gap: 0.35rem 0.9rem; }
  .legend-hint { margin-left: 0; }
  .chart-wrap { padding: 0.6rem 0.6rem 0; overflow-x: auto; }
  #chart, #lives { min-width: 900px; }
  .detail { padding: 1.1rem 1rem 1.4rem; }
  .changelog { padding: 0.7rem 1rem 1.2rem; }
  .detail-name { font-size: 1.6rem; }
  .detail-note { font-size: 1.08rem; }
}

@media (prefers-reduced-motion: reduce) {
  .edge, .node .body, .life-row .bar { transition: none; }
}
