@font-face {
  font-family: 'Source Serif 4';
  src: url('../fonts/source-serif-4.woff2') format('woff2');
  font-weight: 400 700;
  font-style: normal;
  font-display: swap;
}

:root {
  color-scheme: light;
  --bg: #f4efe6;
  --paper: #fbf8f2;
  --ink: #221e19;
  --ink-2: #4f473d;
  --muted: #7a7064;
  --rule: #ddd3c3;
  --ring: #e6ddcf;
  --ring-strong: #d6cab7;
  --chip: #ece5d8;
  --chip-hover: #e2d9c9;
  --focus: #2a78d6;
  /* the three founders, in the order of the chart legend */
  --darley: #2a78d6;
  --godolphin: #eb6834;
  --byerley: #1baf7a;
  --serif: 'Source Serif 4', Georgia, 'Times New Roman', serif;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --bg: #131a17;
    --paper: #18211d;
    --ink: #efe8da;
    --ink-2: #cfc6b5;
    --muted: #9d9483;
    --rule: #2b3631;
    --ring: #1f2925;
    --ring-strong: #2b3833;
    --chip: #223029;
    --chip-hover: #2b3b33;
    --focus: #6aa6ee;
    --darley: #3987e5;
    --godolphin: #d95926;
    --byerley: #199e70;
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #131a17;
  --paper: #18211d;
  --ink: #efe8da;
  --ink-2: #cfc6b5;
  --muted: #9d9483;
  --rule: #2b3631;
  --ring: #1f2925;
  --ring-strong: #2b3833;
  --chip: #223029;
  --chip-hover: #2b3b33;
  --focus: #6aa6ee;
  --darley: #3987e5;
  --godolphin: #d95926;
  --byerley: #199e70;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--bg);
  color: var(--ink);
  font: 16px/1.45 var(--serif);
  -webkit-text-size-adjust: 100%;
  overflow: hidden;
}
button { font: inherit; color: inherit; }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.noscript { padding: 24px; }

.app {
  height: 100vh;
  height: 100dvh;
  display: grid;
  grid-template-columns: minmax(0, 1fr) 380px;
  grid-template-rows: auto minmax(0, 1fr);
}

/* Header */
.top {
  grid-column: 1 / -1;
  display: flex;
  align-items: center;
  gap: 24px;
  padding: 14px 22px 12px;
  padding-top: max(14px, env(safe-area-inset-top));
  border-bottom: 1px solid var(--rule);
}
.brand { display: flex; align-items: baseline; gap: 18px; min-width: 0; flex: 1; }
h1 {
  margin: 0;
  font-size: 30px;
  line-height: 1;
  font-weight: 700;
  letter-spacing: -0.01em;
  font-variation-settings: 'opsz' 60;
}
.lede { margin: 0; color: var(--ink-2); font-size: 15.5px; max-width: 46em; }

.find { position: relative; width: 300px; flex: none; }
.find input {
  width: 100%;
  height: 40px;
  padding: 0 14px 0 38px;
  border: 1px solid var(--rule);
  border-radius: 20px;
  background: var(--paper) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 20 20'%3E%3Ccircle cx='8.5' cy='8.5' r='5.5' fill='none' stroke='%23857a6c' stroke-width='1.8'/%3E%3Cpath d='M12.6 12.6 17 17' stroke='%23857a6c' stroke-width='1.8' stroke-linecap='round'/%3E%3C/svg%3E") no-repeat 13px 50% / 17px;
  color: var(--ink);
  font: 16px var(--serif);
  outline: none;
}
.find input:focus-visible { border-color: var(--focus); box-shadow: 0 0 0 3px color-mix(in srgb, var(--focus) 25%, transparent); }
.find input::placeholder { color: var(--muted); }
.find input::-webkit-search-cancel-button { display: none; }
#suggest {
  position: absolute;
  z-index: 20;
  top: 46px;
  left: 0;
  right: 0;
  margin: 0;
  padding: 6px;
  list-style: none;
  background: var(--paper);
  border: 1px solid var(--rule);
  border-radius: 14px;
  box-shadow: 0 10px 30px rgb(0 0 0 / 0.14);
}
#suggest li {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 10px;
  border-radius: 9px;
  cursor: pointer;
}
#suggest li[aria-selected="true"], #suggest li:hover { background: var(--chip); }
#suggest .yr { margin-left: auto; color: var(--muted); font-size: 14px; font-variant-numeric: tabular-nums; }
#suggest .none { color: var(--muted); cursor: default; background: none; }

/* Chart */
.stage { position: relative; grid-column: 1; grid-row: 2; min-height: 0; overflow: hidden; }
#chart { position: absolute; inset: 0; width: 100%; height: 100%; touch-action: none; cursor: grab; display: block; }
#chart.dragging { cursor: grabbing; }
#chart.over { cursor: pointer; }

.legend {
  position: absolute;
  top: 12px;
  left: 14px;
  margin: 0;
  padding: 0;
  list-style: none;
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  pointer-events: none;
}
.legend button {
  pointer-events: auto;
  display: flex;
  align-items: center;
  gap: 7px;
  padding: 4px 10px 4px 8px;
  border: 0;
  border-radius: 14px;
  background: color-mix(in srgb, var(--bg) 82%, transparent);
  font-size: 14px;
  cursor: pointer;
}
.legend button:hover { background: var(--chip); }

.sw { display: inline-block; width: 10px; height: 10px; border-radius: 50%; background: var(--c); flex: none; }

.zoom {
  position: absolute;
  right: 14px;
  bottom: 14px;
  display: flex;
  flex-direction: column;
  border: 1px solid var(--rule);
  border-radius: 12px;
  background: var(--paper);
  overflow: hidden;
}
.zoom button {
  width: 40px;
  height: 40px;
  border: 0;
  background: none;
  font-size: 22px;
  line-height: 1;
  cursor: pointer;
  display: grid;
  place-items: center;
}
.zoom button + button { border-top: 1px solid var(--rule); }
.zoom button:hover { background: var(--chip); }
.zoom button:focus-visible { outline-offset: -3px; border-radius: 11px; } /* inside the box, which clips anything outside */
.zoom svg { width: 19px; height: 19px; }

.hint {
  position: absolute;
  left: 14px;
  bottom: 12px;
  margin: 0;
  padding: 4px 10px;
  border-radius: 12px;
  background: color-mix(in srgb, var(--bg) 85%, transparent);
  color: var(--muted);
  font-size: 13.5px;
  pointer-events: none;
  transition: opacity 0.6s;
}
.hint.gone { opacity: 0; }
.hint .touch { display: none; }
@media (pointer: coarse) {
  .hint .touch { display: inline; }
  .hint .mouse { display: none; }
}

/* Panel */
.panel {
  grid-column: 2;
  grid-row: 2;
  min-height: 0;
  overflow-y: auto;
  overscroll-behavior: contain;
  border-left: 1px solid var(--rule);
  background: var(--paper);
  padding: 20px 22px 28px;
  padding-bottom: max(28px, env(safe-area-inset-bottom));
}
.panel h2 {
  margin: 0 0 4px;
  font-size: 28px;
  line-height: 1.12;
  font-weight: 700;
  font-variation-settings: 'opsz' 48;
  text-wrap: balance;
}
.panel h3 {
  margin: 22px 0 8px;
  font-size: 13px;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--muted);
}
.panel p { margin: 0 0 10px; }
.phead { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 6px; min-height: 28px; }
.kicker { display: flex; align-items: center; gap: 7px; margin: 0; font-size: 14px; color: var(--ink-2); }
.x {
  flex: none;
  width: 32px;
  height: 32px;
  margin-right: -6px;
  border: 0;
  border-radius: 50%;
  background: none;
  font-size: 24px;
  line-height: 1;
  color: var(--muted);
  cursor: pointer;
}
.x:hover { background: var(--chip); color: var(--ink); }
.meta { color: var(--muted); font-size: 15px; font-variant-numeric: tabular-nums; }
.note { font-size: 17px; }
.fine { color: var(--muted); font-size: 14.5px; }
.big { font-size: 21px; font-weight: 600; line-height: 1.25; margin-bottom: 8px !important; }

.link {
  padding: 0;
  border: 0;
  background: none;
  color: var(--ink);
  text-decoration: underline;
  text-decoration-color: color-mix(in srgb, var(--ink) 35%, transparent);
  text-underline-offset: 3px;
  text-align: left;
  cursor: pointer;
}
.link:hover { text-decoration-color: currentColor; }

.act {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-height: 40px;
  margin: 6px 8px 0 0;
  padding: 8px 16px;
  border: 1px solid var(--rule);
  border-radius: 20px;
  background: var(--chip);
  font-size: 15.5px;
  cursor: pointer;
}
.act:hover { background: var(--chip-hover); }
.act.primary { background: var(--ink); color: var(--paper); border-color: var(--ink); }
.act.primary:hover { background: var(--ink-2); }

.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip {
  padding: 6px 12px;
  border: 0;
  border-radius: 16px;
  background: var(--chip);
  font-size: 15px;
  cursor: pointer;
  text-align: left;
}
.chip:hover { background: var(--chip-hover); }

.founders { list-style: none; margin: 14px 0 0; padding: 0; display: grid; gap: 4px; }
.founders button {
  width: 100%;
  display: grid;
  grid-template-columns: 12px 1fr;
  column-gap: 10px;
  align-items: baseline;
  padding: 8px 10px;
  border: 0;
  border-radius: 10px;
  background: none;
  text-align: left;
  cursor: pointer;
}
.founders button:hover { background: var(--chip); }
.founders .sw { align-self: center; }
.founders b { font-weight: 600; }
.founders small { grid-column: 2; color: var(--muted); font-size: 14.5px; }

/* The line from founder to horse */
.chain { list-style: none; margin: 0; padding: 0 0 0 4px; }
.chain li {
  position: relative;
  display: flex;
  align-items: baseline;
  gap: 10px;
  padding: 2px 0 2px 18px;
  font-size: 15.5px;
}
.chain li::before {
  content: '';
  position: absolute;
  left: 3px;
  top: 0;
  bottom: 0;
  width: 2px;
  background: var(--c);
  opacity: 0.55;
}
.chain li:first-child::before { top: 50%; }
.chain li:last-child::before { bottom: 50%; }
.chain li::after {
  content: '';
  position: absolute;
  left: 0;
  top: calc(50% - 4px);
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--c);
}
.chain li.here { font-weight: 700; }
.chain li.meet::after { background: var(--paper); box-shadow: inset 0 0 0 2px var(--ink); }
.chain .yr { margin-left: auto; color: var(--muted); font-size: 14px; font-variant-numeric: tabular-nums; white-space: nowrap; }

.pair { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.pair h4 { margin: 0 0 6px; font-size: 15px; font-weight: 600; }

.group { list-style: none; margin: 0; padding: 0; }
.group li button {
  width: 100%;
  display: flex;
  align-items: baseline;
  gap: 10px;
  padding: 7px 8px;
  border: 0;
  border-radius: 8px;
  background: none;
  text-align: left;
  cursor: pointer;
}
.group li button:hover { background: var(--chip); }
.group .yr { margin-left: auto; color: var(--muted); font-size: 14px; font-variant-numeric: tabular-nums; }
.group .sw { align-self: center; }

details { margin-top: 22px; border-top: 1px solid var(--rule); padding-top: 12px; }
summary { cursor: pointer; color: var(--ink-2); font-size: 15px; }
details p { font-size: 15px; color: var(--ink-2); margin-top: 10px !important; }
details a { color: inherit; }

.jd-foot {
  margin-top: 22px;
  color: var(--muted);
  font-size: 14px;
  text-align: center;
}
.jd-foot a { color: var(--ink-2); text-decoration: none; }
.jd-foot a:hover, .jd-foot a:focus-visible { text-decoration: underline; text-underline-offset: 3px; }

:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }

/* Phone and narrow windows: header, chart, then the panel underneath. No page scroll. */
@media (max-width: 899px) {
  .app { grid-template-columns: minmax(0, 1fr); grid-template-rows: auto minmax(0, 1fr) 41%; }
  .top {
    display: grid;
    grid-template-columns: auto minmax(0, 1fr);
    grid-template-areas: "title find" "lede lede";
    align-items: center;
    gap: 6px 14px;
    padding: 10px 16px 9px;
    padding-top: max(10px, env(safe-area-inset-top));
  }
  .brand { display: contents; }
  h1 { grid-area: title; font-size: 25px; }
  .lede { grid-area: lede; font-size: 14.5px; line-height: 1.35; }
  @media (max-width: 599px) { .lede { display: none; } }
  .find { grid-area: find; width: 100%; }
  .find input { height: 38px; }
  .stage { grid-column: 1; grid-row: 2; }
  .panel { grid-column: 1; grid-row: 3; border-left: 0; border-top: 1px solid var(--rule); padding: 14px 16px max(22px, env(safe-area-inset-bottom)); }
  .panel h2 { font-size: 25px; }
  .legend { top: 8px; left: 8px; right: 8px; gap: 2px; }
  .legend button { font-size: 12.5px; padding: 3px 7px 3px 5px; gap: 5px; white-space: nowrap; }
  .legend .sw { width: 9px; height: 9px; }
  .zoom { right: 10px; bottom: 10px; }
  .zoom button { width: 38px; height: 38px; }
  .hint { left: 10px; bottom: 10px; font-size: 13px; }
}
@media (max-width: 380px) {
  .pair { grid-template-columns: 1fr; }
}
@media (prefers-reduced-motion: reduce) {
  .hint { transition: none; }
}
