:root {
  --paper: #e6eae2;
  --paper-deep: #d8ded4;
  --ink: #1a2326;
  --ink-soft: #4d5b5f;
  --thread: #9e2a20;
  --rule: #a7b4b4;
  --link: #1f4f6e;
  --display: "IM Fell English", "Iowan Old Style", Georgia, serif;
  --text: "Public Sans", "Atkinson Hyperlegible", system-ui, sans-serif;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --paper: #1b2422;
    --paper-deep: #232e2b;
    --ink: #dfe5dc;
    --ink-soft: #a3b0ab;
    --thread: #d9614f;
    --rule: #4a5a57;
    --link: #8fc0de;
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --paper: #1b2422;
  --paper-deep: #232e2b;
  --ink: #dfe5dc;
  --ink-soft: #a3b0ab;
  --thread: #d9614f;
  --rule: #4a5a57;
  --link: #8fc0de;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; scroll-padding-top: 5.5rem; }
body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font: 400 1.125rem/1.6 var(--text);
}
a { color: var(--link); text-underline-offset: 0.18em; text-decoration-thickness: 1px; }
a:hover { text-decoration-thickness: 2px; }
:focus-visible { outline: 3px solid var(--thread); outline-offset: 3px; border-radius: 2px; }
h1, h2, h3 { font-family: var(--display); font-weight: 400; line-height: 1.1; margin: 0; }
p { margin: 0 0 1em; }
.skip { position: absolute; left: -999px; }
.skip:focus { left: 16px; top: 16px; background: var(--paper); padding: 8px 12px; z-index: 2; }

/* Site navigation */
.topbar {
  display: flex; justify-content: space-between; align-items: baseline; gap: 16px;
  position: sticky; top: 0; z-index: 4;
  padding: 14px max(24px, calc((100% - 68rem) / 2 + 24px));
  background: var(--paper); border-bottom: 1px solid var(--rule);
  font-size: 0.95rem;
}
.topbar .home { font-family: var(--display); font-size: 1.3rem; color: var(--ink); text-decoration: none; }
.topbar nav { display: flex; gap: 20px; flex-wrap: wrap; }
.topbar nav a { color: var(--ink-soft); text-decoration: none; }
.topbar nav a:hover, .topbar nav a[aria-current] { color: var(--ink); text-decoration: underline; }

/* Hero */
.hero {
  max-width: 68rem; margin: 0 auto; padding: 9vh 24px 0;
  display: grid; grid-template-columns: 12rem 3rem minmax(0, 40rem); column-gap: 0;
}
.hero > * { grid-column: 3; }
.gaelic { font-family: var(--display); font-style: italic; font-size: 1.6rem; color: var(--ink-soft); margin: 0; }
.hero h1 {
  font-size: clamp(4.2rem, 15vw, 10.5rem);
  letter-spacing: -0.02em;
  line-height: 0.88;
  margin: 0.08em 0 0.22em -0.05em;
}
.meaning { font-family: var(--display); font-size: 1.6rem; line-height: 1.3; margin: 0 0 1.4rem; max-width: 30ch; }
.intro { color: var(--ink-soft); max-width: 36rem; }
.key {
  display: flex; flex-wrap: wrap; gap: 8px 24px; margin: 1.6rem 0 0; padding: 0; list-style: none;
  font-size: 0.95rem; color: var(--ink-soft);
}
.key li { display: flex; align-items: center; gap: 10px; }
.key i { display: inline-block; width: 0; height: 26px; border-left: 3px solid var(--thread); }
.key .likely { border-left-style: dashed; }
.key .guess { border-left-style: dotted; }

/* The line of descent */
.line { max-width: 68rem; margin: 0 auto; padding: 56px 24px 24px; }
.gen {
  display: grid; grid-template-columns: 12rem 3rem minmax(0, 40rem);
  position: relative;
}
.gen .where {
  grid-column: 1; text-align: right; padding: 0.35rem 0 2.5rem; color: var(--ink-soft); font-size: 0.95rem; line-height: 1.4;
}
.gen .where strong { display: block; color: var(--ink); font-weight: 700; margin-bottom: 4px; font-size: 0.9rem; }
.gen .thread { grid-column: 2; position: relative; }
.gen .thread::before {
  content: ""; position: absolute; left: calc(50% - 1.5px); top: 0; bottom: 0;
  border-left: 3px solid var(--thread);
}
.gen[data-link="likely"] .thread::before { border-left-style: dashed; }
.gen[data-link="guess"] .thread::before { border-left-style: dotted; }
.gen:last-child .thread::before { bottom: auto; height: 1.1rem; }
.gen .thread::after {
  content: ""; position: absolute; left: calc(50% - 7px); top: 0.7rem;
  width: 14px; height: 14px; border-radius: 50%;
  background: var(--paper); border: 3px solid var(--thread);
}
.gen.lore .thread::after { background: var(--paper); border-style: dotted; }
.gen.us .thread::after { background: var(--thread); }
.gen .who { grid-column: 3; padding: 0 0 3.2rem 0.5rem; min-width: 0; }
.gen h2 { font-size: clamp(1.8rem, 4vw, 2.5rem); margin-bottom: 0.25rem; }
.gen h2 .and { font-style: italic; color: var(--ink-soft); font-size: 0.8em; }
.dates { color: var(--ink-soft); font-size: 0.95rem; margin: 0 0 0.9rem; }
.who p { max-width: 38rem; }
.status { font-style: italic; color: var(--ink); }

.portrait { float: right; margin: 0.3rem 0 1rem 1.4rem; width: 9.5rem; }
.portrait img {
  display: block; width: 100%; height: auto;
  border: 6px solid var(--paper-deep); outline: 1px solid var(--rule);
}
.portrait figcaption { font-size: 0.82rem; color: var(--ink-soft); margin-top: 6px; line-height: 1.35; }

.kids { list-style: none; margin: 0 0 1.1rem; padding: 0; }
.kids li { padding: 2px 0; }
.kids .gone { color: var(--ink-soft); }

details { margin: 0.4rem 0 0; border-top: 1px solid var(--rule); clear: both; }
summary {
  cursor: pointer; padding: 10px 0; color: var(--link); list-style: none; font-size: 0.98rem;
  display: flex; align-items: center; gap: 10px;
}
summary::-webkit-details-marker { display: none; }
summary::before {
  content: ""; width: 7px; height: 7px; border-right: 2px solid currentColor; border-bottom: 2px solid currentColor;
  transform: rotate(-45deg); transition: transform 0.15s ease;
}
details[open] summary::before { transform: rotate(45deg); }
.record { font-size: 0.98rem; padding: 0 0 12px; }
.record dl { display: grid; grid-template-columns: 8.5rem minmax(0, 1fr); gap: 8px 16px; margin: 0; }
.record dt { color: var(--ink-soft); }
.record dd { margin: 0; overflow-wrap: anywhere; }

/* Sections after the line */
.chapter { max-width: 68rem; margin: 0 auto; padding: 64px 24px 0; display: grid; grid-template-columns: 15rem minmax(0, 40rem); column-gap: 0.5rem; }
.chapter > h2 { grid-column: 1 / -1; font-size: clamp(2.2rem, 5vw, 3.2rem); margin-bottom: 0.4rem; grid-column-start: 2; }
.chapter > .lede { grid-column: 2; color: var(--ink-soft); }
.chapter > .body { grid-column: 2; }
.family { padding: 1.4rem 0; border-top: 1px solid var(--rule); display: flow-root; }
.family h3 { font-size: 1.7rem; margin-bottom: 0.3rem; }
.family .joined { color: var(--ink-soft); font-size: 0.95rem; margin-bottom: 0.6rem; }
.family .portrait { width: 8rem; }

.service { list-style: none; margin: 0; padding: 0; }
.service li { display: grid; grid-template-columns: 9rem minmax(0, 1fr); gap: 4px 16px; padding: 14px 0; border-top: 1px solid var(--rule); }
.service .war { font-family: var(--display); font-size: 1.25rem; line-height: 1.25; }
.service b { font-weight: 700; }

.closing {
  max-width: 68rem; margin: 0 auto; padding: 96px 24px 40px;
  display: grid; grid-template-columns: 15rem minmax(0, 46rem); column-gap: 0.5rem;
}
.closing blockquote { grid-column: 2; margin: 0; }
.closing blockquote p { font-family: var(--display); font-size: clamp(2rem, 5.5vw, 3.6rem); line-height: 1.12; margin: 0 0 0.6rem; }
.closing cite { font-style: normal; color: var(--ink-soft); font-size: 0.95rem; }

footer { max-width: 68rem; margin: 0 auto; padding: 24px 24px 48px; color: var(--ink-soft); font-size: 0.9rem; }
footer p { margin-left: 15.5rem; max-width: 40rem; }
.page + footer p { margin-left: 0; }

/* Research page */
.page { max-width: 68rem; margin: 0 auto; padding: 0 24px; }
.page-head { padding: 9vh 0 1rem; max-width: 44rem; }
.page-head h1 { font-size: clamp(3rem, 9vw, 5.5rem); line-height: 0.95; margin-bottom: 1rem; }
.page-head p { color: var(--ink-soft); }
.toc { list-style: none; padding: 0; margin: 1.5rem 0 0; display: flex; flex-wrap: wrap; gap: 6px 22px; font-size: 0.98rem; }
.rsec { padding: 56px 0 0; }
.rsec > h2 { font-size: clamp(2rem, 4.5vw, 2.8rem); margin-bottom: 0.5rem; }
.rsec > p, .rsec > .note { max-width: 44rem; }
.note { color: var(--ink-soft); }
.bottom-line { border-left: 3px solid var(--thread); padding: 4px 0 4px 18px; margin: 1.2rem 0; max-width: 44rem; }
.tablewrap { overflow-x: auto; margin: 1rem 0; border-top: 2px solid var(--ink); }
table { border-collapse: collapse; width: 100%; font-size: 0.95rem; line-height: 1.5; }
th { text-align: left; font-weight: 700; padding: 10px 14px 10px 0; border-bottom: 1px solid var(--ink); vertical-align: bottom; }
td { padding: 12px 14px 12px 0; border-bottom: 1px solid var(--rule); vertical-align: top; }
td:first-child { font-weight: 700; min-width: 11rem; }
td.st { white-space: nowrap; font-style: italic; }
.todo { list-style: none; padding: 0; margin: 1rem 0; max-width: 46rem; }
.todo li { padding: 14px 0 14px 34px; border-top: 1px solid var(--rule); position: relative; }
.todo li::before { content: ""; position: absolute; left: 4px; top: 19px; width: 14px; height: 14px; border: 2px solid var(--ink-soft); border-radius: 2px; }
.todo li.done::before { background: var(--thread); border-color: var(--thread); }
.todo li.done b { text-decoration: line-through; text-decoration-color: var(--ink-soft); }
.todo b { display: block; }
.sources { columns: 2 22rem; column-gap: 40px; padding: 0; list-style: none; font-size: 0.95rem; }
.sources li { break-inside: avoid; padding: 8px 0; }
.sources span { display: block; color: var(--ink-soft); font-size: 0.88rem; }
.route { list-style: none; padding: 0; margin: 1.2rem 0; max-width: 44rem; border-left: 3px dotted var(--thread); }
.route li { padding: 0 0 1rem 20px; }
.route b { display: block; }

@media (max-width: 860px) {
  .hero, .gen { grid-template-columns: 2rem minmax(0, 1fr); }
  .hero > * { grid-column: 2; }
  .hero { padding-top: 6vh; }
  .gen .thread { grid-column: 1; grid-row: 1 / span 2; }
  .gen .where { grid-column: 2; text-align: left; padding: 0.3rem 0 0.6rem 0.5rem; }
  .gen .where strong { display: inline; margin-right: 8px; }
  .gen .who { grid-column: 2; padding-bottom: 2.6rem; }
  .chapter, .closing { grid-template-columns: minmax(0, 1fr); }
  .chapter > h2, .chapter > .lede, .chapter > .body, .closing blockquote { grid-column: 1; }
  footer p { margin-left: 0; }
  .line { padding-top: 40px; }
}
@media (max-width: 520px) {
  body { font-size: 1.0625rem; }
  .topbar, .hero, .line, .chapter, .closing, footer, .page { padding-left: 16px; padding-right: 16px; }
  .portrait { width: 7.5rem; margin-left: 1rem; }
  .record dl { grid-template-columns: minmax(0, 1fr); gap: 2px; }
  .record dd { margin-bottom: 8px; }
  .service li { grid-template-columns: minmax(0, 1fr); }
  .topbar { flex-direction: column; gap: 4px; padding-top: 10px; padding-bottom: 10px; }
}
@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; }
}
@media print {
  .topbar nav, .skip { display: none; }
  details { display: block; }
}

/* Tree page */
.tree-head { max-width: 68rem; margin: 0 auto; padding: 7vh 24px 8px; }
.tree-head h1 { font-size: clamp(3rem, 9vw, 5.5rem); line-height: 0.95; margin-bottom: 1rem; }
.tree-head p { color: var(--ink-soft); max-width: 42rem; }
.tree-tools { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 12px 24px; margin-top: 1.2rem; }
.tree-tools .key { margin: 0; }
.zoom, .panel-close {
  font: inherit; font-size: 0.95rem; color: var(--ink); background: transparent; cursor: pointer;
  border: 1px solid var(--ink-soft); border-radius: 3px; padding: 6px 14px;
}
.zoom:hover, .panel-close:hover { background: var(--paper-deep); }
.tree-scroll {
  overflow-x: auto; margin: 16px 0 0; padding-bottom: 12rem;
  border-top: 1px solid var(--rule); cursor: grab;
}
.tree-scroll.dragging { cursor: grabbing; user-select: none; }
.tree-scroll svg { display: block; margin: 0 auto; }
.tree-scroll svg.fit { width: 100%; height: auto; min-width: 640px; }
.tree-fallback { max-width: 68rem; margin: 0 auto; padding: 24px; }

.lines .link { fill: none; stroke: var(--ink-soft); stroke-width: 1.6; }
.lines .link.likely { stroke-dasharray: 6 5; }
.lines .link.guess { stroke-dasharray: 2 4; }
.lines .link.trunk { stroke: var(--thread); stroke-width: 4; }
.lines .link.trunk.likely { stroke-dasharray: 10 6; }
.lines .link.trunk.guess { stroke-dasharray: 3 6; }
.lines .marriage { stroke: var(--ink-soft); stroke-width: 1.6; }

.node { cursor: pointer; }
.node rect { fill: var(--paper-deep); stroke: var(--rule); stroke-width: 1.2; }
.node.mcelroy rect { fill: var(--paper); stroke: var(--thread); stroke-width: 2.4; }
.node.placeholder rect { fill: transparent; stroke: var(--ink-soft); stroke-dasharray: 3 4; }
.node .nm { font-family: var(--display); font-size: 16px; fill: var(--ink); }
.node .dt { font-family: var(--text); font-size: 12px; fill: var(--ink-soft); }
.node.placeholder .nm { font-style: italic; fill: var(--ink-soft); }
.node:hover rect { stroke: var(--ink); }
.node:focus { outline: none; }
.node:focus-visible rect { stroke: var(--thread); stroke-width: 3.5; }

svg.focused .node:not(.on), svg.focused .lines > :not(.on) { opacity: 0.32; }
svg.focused .node.on rect { stroke: var(--thread); stroke-width: 3; }
svg.focused .lines .on { stroke: var(--thread); stroke-width: 3.5; }
.node, .lines > * { transition: opacity 0.2s ease; }

.tree-panel {
  position: fixed; left: 24px; bottom: 24px; z-index: 3;
  width: min(24rem, calc(100vw - 32px));
  background: var(--paper); border: 1px solid var(--ink-soft); border-top: 4px solid var(--thread);
  padding: 16px 20px; font-size: 1rem;
  box-shadow: 0 10px 30px rgba(20, 30, 30, 0.18);
}
.tree-panel h2 { font-size: 1.9rem; margin-bottom: 0.2rem; }
.tree-panel p { margin: 0 0 0.6rem; }
.panel-rel { font-family: var(--display); font-style: italic; font-size: 1.2rem; }
.panel-meta { color: var(--ink-soft); font-size: 0.93rem; }
.panel-hint { color: var(--ink-soft); margin: 0 !important; }
.panel-close { display: block; margin-top: 12px; }

@media (max-width: 520px) {
  .tree-head { padding-left: 16px; padding-right: 16px; }
  .tree-panel { left: 16px; bottom: 16px; padding: 14px 16px; }
  .tree-panel:not(.open) { padding: 10px 16px; }
  .tree-panel h2 { font-size: 1.6rem; }
}
@media print {
  .tree-panel, .tree-tools button { display: none; }
  .tree-scroll { overflow: visible; }
  .tree-scroll svg { width: 100%; height: auto; }
}
