:root {
  --bg: #f6f2ea;
  --paper: #fffdf8;
  --ink: #23201b;
  --muted: #6d665a;
  --line: #d9d1c3;
  --band: #efe8db;
  --band2: #e9e1d2;
  --accent: #8a5a12;
  --up: #c27c0e;
  --down: #0f7c7a;
  --edge: #7f776a;
  --shadow: 0 1px 3px rgba(40, 30, 10, .15);
  --serif: "EB Garamond", Georgia, "Times New Roman", serif;
  --sans: Inter, system-ui, -apple-system, "Segoe UI", sans-serif;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #17150f; --paper: #211e17; --ink: #ece6da; --muted: #a39b8c;
    --line: #3b362c; --band: #1d1a14; --band2: #24211a; --accent: #e0a64a;
    --up: #f0a83a; --down: #3cc0bd; --edge: #8d8576; --shadow: 0 1px 3px rgba(0,0,0,.5);
  }
}
:root[data-theme="dark"] {
  --bg: #17150f; --paper: #211e17; --ink: #ece6da; --muted: #a39b8c;
  --line: #3b362c; --band: #1d1a14; --band2: #24211a; --accent: #e0a64a;
  --up: #f0a83a; --down: #3cc0bd; --edge: #8d8576; --shadow: 0 1px 3px rgba(0,0,0,.5);
}
* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--ink); font-family: var(--sans); font-size: 15px; }
h1, h2, h3 { font-family: var(--serif); font-weight: 600; }
.top { position: sticky; top: 0; z-index: 20; background: var(--bg); border-bottom: 1px solid var(--line);
  padding: 10px 16px 8px; display: grid; gap: 6px; }
.brand { display: flex; align-items: baseline; gap: 14px; flex-wrap: wrap; }
.brand h1 { margin: 0; font-size: 26px; letter-spacing: .01em; }
.sub { margin: 0; color: var(--muted); font-size: 13px; }
.tabs { display: flex; gap: 4px; flex-wrap: wrap; }
.tabs button, .seg button, .maptools button { font: 500 13px var(--sans); color: var(--ink); background: transparent;
  border: 1px solid var(--line); border-radius: 999px; padding: 5px 12px; cursor: pointer; }
.tabs button[aria-selected="true"], .seg button.on { background: var(--ink); color: var(--bg); border-color: var(--ink); }
.controls { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
#search { font: 14px var(--sans); padding: 5px 10px; border: 1px solid var(--line); border-radius: 8px;
  background: var(--paper); color: var(--ink); width: 180px; }
.chips { display: flex; gap: 4px; flex-wrap: wrap; }
.chip { font: 12px var(--sans); border: 1px solid var(--line); background: var(--paper); color: var(--ink);
  border-radius: 999px; padding: 3px 9px 3px 7px; cursor: pointer; display: inline-flex; align-items: center; gap: 5px; }
.chip i { width: 9px; height: 9px; border-radius: 50%; display: inline-block; }
.chip.on { border-color: var(--ink); box-shadow: inset 0 0 0 1px var(--ink); }
.banner { background: #b3261e; color: #fff; padding: 8px 16px; font-weight: 600; }
main { padding: 0 16px 90px; }
.view { display: none; }
.view.active { display: block; }
.legend { display: flex; gap: 16px; flex-wrap: wrap; font-size: 12px; color: var(--muted); padding: 8px 0; align-items: center; }
.legend span { display: inline-flex; align-items: center; gap: 6px; }
#river-scroll { overflow-x: auto; }
svg text { fill: var(--ink); }
.eraband { fill: var(--band); }
.eraband.alt { fill: var(--band2); }
.eralabel { font: 600 13px var(--serif); fill: var(--muted); }
.tick text { font: 11px var(--sans); fill: var(--muted); }
.tick line { stroke: var(--line); }
.axisnote { font: 11px var(--sans); fill: var(--muted); }
.edge { fill: none; stroke: var(--edge); stroke-width: 1.4; opacity: .55; }
.e-taught { stroke: var(--edge); stroke-width: 2; }
.e-read_responded { stroke: var(--edge); stroke-dasharray: 6 4; stroke-width: 1.6; }
.e-attributed { stroke: var(--edge); stroke-dasharray: 1.5 4; stroke-width: 1.8; stroke-linecap: round; }
.edge.up { stroke: var(--up); opacity: 1; stroke-width: 2.4; }
.edge.down { stroke: var(--down); opacity: 1; stroke-width: 2.4; }
.edge.faded, .node.faded { opacity: .12; }
.node { cursor: pointer; }
.node .ring { fill: var(--paper); stroke: var(--ink); stroke-width: 1.6; }
.node .ring.life { stroke-width: 2.4; }
.node .ring.copy { stroke-dasharray: 5 3; }
.node .ring.posthumous { stroke-dasharray: 1.5 3; stroke-linecap: round; stroke-width: 2.2; }
.node .ring.uncertain { stroke: var(--muted); stroke-dasharray: 8 2 2 2; }
.node .ring.none { stroke: var(--muted); }
.node .initial { font: 600 22px var(--serif); fill: var(--muted); text-anchor: middle; dominant-baseline: central; }
.node .nm { font: 600 12.5px var(--sans); text-anchor: middle; paint-order: stroke; stroke: var(--bg); stroke-width: 4px; }
.node .nn { font: italic 12px var(--serif); text-anchor: middle; fill: var(--muted); paint-order: stroke; stroke: var(--bg); stroke-width: 4px; }
.node .yrs { font: 10.5px var(--sans); text-anchor: middle; fill: var(--muted); paint-order: stroke; stroke: var(--bg); stroke-width: 4px; }
.node.sel .ring { stroke: var(--accent); stroke-width: 3.5; }
.node.up .ring { stroke: var(--up); stroke-width: 3; }
.node.down .ring { stroke: var(--down); stroke-width: 3; }
.node:focus { outline: none; }
.node:focus-visible .ring { stroke: var(--accent); stroke-width: 3.5; }
.maptools { display: flex; align-items: center; gap: 10px; padding: 10px 0; flex-wrap: wrap; }
#year { width: min(520px, 60vw); }
#yearout { font: 600 20px var(--serif); min-width: 90px; }
.seg { display: inline-flex; gap: 4px; }
#map { width: 100%; height: auto; background: var(--paper); border: 1px solid var(--line); border-radius: 10px; }
.land { fill: var(--band2); stroke: var(--line); stroke-width: .6; }
.grat { fill: none; stroke: var(--line); stroke-width: .4; opacity: .6; }
.trail { stroke: var(--accent); stroke-width: 1.5; fill: none; opacity: .8; }
.pdot { stroke: var(--accent); stroke-width: 1.5; cursor: pointer; }
.pdot.born { fill: var(--paper); }
.pdot.died { fill: var(--accent); }
.plabel { font: 600 12px var(--sans); paint-order: stroke; stroke: var(--paper); stroke-width: 4px; pointer-events: none; }
.alive { font-size: 13px; padding: 8px 0; line-height: 1.7; }
.alive a, .linkish { color: var(--ink); text-decoration: underline; text-decoration-color: var(--line); cursor: pointer; }
.fine { font-size: 12px; color: var(--muted); max-width: 70ch; }
.matrix { border-collapse: collapse; font-size: 12px; }
.matrix th { font: 600 12px var(--sans); color: var(--muted); padding: 6px; text-align: left; vertical-align: bottom; }
.matrix th.row { cursor: pointer; white-space: nowrap; }
.matrix th.row i { width: 9px; height: 9px; border-radius: 50%; display: inline-block; margin-right: 6px; }
.matrix td { border: 1px solid var(--line); padding: 4px; vertical-align: top; min-width: 70px; background: var(--paper); }
.matrix .face { display: inline-block; width: 30px; height: 30px; border-radius: 50%; margin: 2px; overflow: hidden;
  border: 1.5px solid var(--ink); background: var(--band); cursor: pointer; text-align: center; line-height: 27px;
  font: 600 14px var(--serif); color: var(--muted); }
.matrix .face img { width: 100%; height: 100%; object-fit: cover; object-position: 50% 20%; }
.panel { position: fixed; right: 0; top: 0; bottom: 0; width: min(440px, 100vw); background: var(--paper);
  border-left: 1px solid var(--line); box-shadow: -4px 0 16px rgba(0,0,0,.12); overflow-y: auto; z-index: 40; padding: 18px 20px 40px; }
.panel .close { position: absolute; right: 10px; top: 8px; font-size: 26px; background: none; border: 0; color: var(--ink); cursor: pointer; }
.pv-head { display: flex; gap: 14px; align-items: flex-start; }
.pv-img { width: 120px; flex: none; }
.pv-img img { width: 120px; border-radius: 6px; display: block; }
.pv-ph { width: 120px; height: 140px; border-radius: 6px; background: var(--band); display: grid; place-items: center;
  font: 600 54px var(--serif); color: var(--muted); }
.pv-names h2 { margin: 0; font-size: 26px; line-height: 1.1; }
.pv-names .native { font: italic 20px var(--serif); color: var(--muted); }
.pv-names .latin { font: 14px var(--serif); color: var(--muted); }
.pv-dates { font-size: 14px; margin-top: 6px; }
.badge { display: inline-block; font-size: 11px; border: 1px solid var(--line); border-radius: 4px; padding: 2px 6px; margin-top: 6px; color: var(--muted); }
.panel h3 { font-size: 17px; margin: 18px 0 6px; border-bottom: 1px solid var(--line); padding-bottom: 3px; }
.panel p, .panel li { line-height: 1.5; }
.panel ul { padding-left: 18px; margin: 6px 0; }
sup.src a { font-size: 10px; color: var(--accent); text-decoration: none; margin-left: 1px; }
.q-orig { font: italic 18px var(--serif); margin: 4px 0 2px; }
.q-tr { color: var(--muted); font-size: 13px; }
.edge-ev { font-size: 12.5px; color: var(--muted); margin: 2px 0 8px; }
.tagrow { display: flex; gap: 6px; flex-wrap: wrap; }
.tag { font-size: 12px; border-radius: 999px; padding: 2px 8px; border: 1px solid var(--line); display: inline-flex; gap: 5px; align-items: center; }
.tag i { width: 8px; height: 8px; border-radius: 50%; display: inline-block; }
.srclist { font-size: 12px; word-break: break-all; color: var(--muted); }
.srclist a, .panel .fine a { color: var(--muted); }
.prose { max-width: 72ch; line-height: 1.6; }
.prose h2 { font-size: 28px; }
.keylist { list-style: none; padding: 0; }
.keylist li { display: flex; gap: 10px; align-items: center; margin: 6px 0; }
.keylist svg line { fill: none; }
.keylist svg circle { fill: var(--paper); }
@media (max-width: 640px) {
  .brand h1 { font-size: 22px; }
  .sub { display: none; }
  #search { width: 140px; }
}
.fb-open { position: fixed; left: 16px; bottom: 16px; z-index: 30; font: 600 13px var(--sans); background: var(--ink);
  color: var(--bg); border: 0; border-radius: 999px; padding: 10px 16px; cursor: pointer; box-shadow: var(--shadow); }
.fb { position: fixed; inset: 0; z-index: 60; background: rgba(0,0,0,.45); display: grid; place-items: center; padding: 16px; }
.fb[hidden] { display: none; }
.fb-card { background: var(--paper); color: var(--ink); border-radius: 12px; padding: 18px 20px; width: min(480px, 100%);
  display: grid; gap: 8px; box-shadow: 0 8px 30px rgba(0,0,0,.3); }
.fb-card h2 { margin: 0; font-size: 22px; }
.fb-card label { font: 600 13px var(--sans); }
.fb-card select, .fb-card textarea { font: 16px var(--sans); color: var(--ink); background: var(--bg); border: 1px solid var(--line);
  border-radius: 8px; padding: 8px; width: 100%; }
.fb-actions { display: flex; gap: 8px; flex-wrap: wrap; }
.fb-actions button { font: 600 14px var(--sans); border-radius: 8px; padding: 10px 16px; min-height: 44px; cursor: pointer;
  border: 1px solid var(--line); background: var(--paper); color: var(--ink); }
.fb-actions button[type="submit"] { background: var(--ink); color: var(--bg); border-color: var(--ink); }
.fb-status { font-size: 13px; min-height: 1.2em; margin: 0; }
.fb-report { font-size: 12.5px; margin-top: 18px; }
.stepper { display: inline-flex; align-items: center; gap: 4px; }
.stepper button { min-width: 44px; min-height: 40px; font-size: 14px; }
.stepper button.on { background: var(--ink); color: var(--bg); border-color: var(--ink); }
.stepper #yearout { padding: 0 8px; text-align: center; }
.event { min-height: 64px; padding: 6px 0 10px; display: grid; gap: 8px; }
.ev-card { background: var(--paper); border: 1px solid var(--line); border-left: 3px solid var(--accent); border-radius: 8px; padding: 10px 14px; max-width: 760px; }
.ev-head { font: 600 16px var(--sans); }
.ev-year { font: 600 18px var(--serif); color: var(--accent); margin-right: 4px; }
.ev-native { font: italic 15px var(--serif); color: var(--muted); font-weight: 400; }
.ev-sum { margin: 6px 0; line-height: 1.5; }
.ev-none { color: var(--muted); font-size: 13px; }
.pdot.hot { stroke-width: 3; }
.hp { position: absolute; left: -9999px; width: 1px; height: 1px; opacity: 0; }
