/* Палитра — единственный источник правды: canvas читает те же переменные
   через getComputedStyle, поэтому лента и карта не расходятся с интерфейсом.
   Значения выгружены из design/tokens.py скриптом design/export_tokens.py —
   править нужно там, иначе дизайн и приложение разойдутся. */
:root {
  --bg: #f5f2ea;
  --panel: #efeade;
  --panel2: #e6e0d1;
  --line: #d9d1bf;
  --line2: #c3b9a2;
  --fg: #1d2026;
  --muted: #575e68;
  --dim: #8a8f97;
  --accent: #3a6698;
  --accent2: #8a5a1c;
  --ok: #41755a;
  --warn: #9c5420;
  --bad: #a8463a;
  --cv-grid: rgba(29,32,38,.07);
  --cv-band-a: rgba(29,32,38,.035);
  --cv-band-b: rgba(29,32,38,.016);
  --cv-label: #2b333d;
  --cv-label-sel: #000000;
  --cv-tick: #a3adb9;
  --cv-pill: rgba(245,242,234,.9);
  --cv-era: rgba(138,90,28,.45);
  --cv-cursor: rgba(29,32,38,.45);
  --map-bg: #e7e3d7;
  --map-graticule: rgba(29,32,38,.07);
  --map-pill: rgba(231,227,215,.82);
  --map-pin-ring: rgba(29,32,38,.6);
  --map-name: #4a4335;
  --map-unnamed: #ddd8ca;
  --tr-africa: #b0801f;
  --tr-europe: #3a6698;
  --tr-russia: #a8463a;
  --tr-asia: #41755a;
  --tr-namerica: #6f4d88;
  --tr-samerica: #a56331;
  --tr-oceania: #2b7280;
  --tr-world: #6b7078;
  --dm-war: #9e3a30;
  --dm-politics: #31598c;
  --dm-science: #2c6447;
  --dm-culture: #65437e;
  --dm-religion: #84631a;
  --dm-disaster: #9c5420;
  --dm-exploration: #1d6675;
  --dm-economy: #556d26;
  --dm-other: #6b7078;

  --font: "IBM Plex Sans", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: "IBM Plex Mono", ui-monospace, SFMono-Regular, Menlo, monospace;
  --serif: "IBM Plex Serif", Georgia, "Times New Roman", serif;
  --track-h: 26px;
}

:root[data-theme="dark"] {
  --bg: #15171b;
  --panel: #1b1e23;
  --panel2: #23262d;
  --line: #2c3037;
  --line2: #3c414a;
  --fg: #e7e4dc;
  --muted: #9aa0a8;
  --dim: #6a7079;
  --accent: #7ba0cd;
  --accent2: #cf9a4a;
  --ok: #71a888;
  --warn: #cf8a4a;
  --bad: #d1786a;
  --cv-grid: rgba(231,228,220,.055);
  --cv-band-a: rgba(231,228,220,.032);
  --cv-band-b: rgba(231,228,220,.015);
  --cv-label: #c9c5ba;
  --cv-label-sel: #ffffff;
  --cv-tick: #4a505a;
  --cv-pill: rgba(21,23,27,.86);
  --cv-era: rgba(207,154,74,.42);
  --cv-cursor: rgba(231,228,220,.5);
  --map-bg: #101317;
  --map-graticule: rgba(231,228,220,.05);
  --map-pill: rgba(16,19,23,.78);
  --map-pin-ring: rgba(231,228,220,.85);
  --map-name: #cdc6b4;
  --map-unnamed: #2a2c30;
  --tr-africa: #d4a244;
  --tr-europe: #7ba0cd;
  --tr-russia: #d1786a;
  --tr-asia: #71a888;
  --tr-namerica: #a385bd;
  --tr-samerica: #cf9256;
  --tr-oceania: #5aa3ae;
  --tr-world: #8c9199;
  --dm-war: #cf7a70;
  --dm-politics: #7398c4;
  --dm-science: #6fa585;
  --dm-culture: #a184bb;
  --dm-religion: #c6a04a;
  --dm-disaster: #cd8749;
  --dm-exploration: #569fac;
  --dm-economy: #96a95a;
  --dm-other: #8c9199;
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; overflow: hidden; }
body {
  background: var(--bg); color: var(--fg);
  font: 14px/1.45 var(--font);
  -webkit-font-smoothing: antialiased;
}
button, input, select { font: inherit; color: inherit; }
body { font-feature-settings: "tnum" 1; }
button { cursor: pointer; }

/* ── каркас ───────────────────────────────────────────────────────── */
#app { display: grid; grid-template-rows: auto 1fr; height: 100%; }
#main { display: grid; grid-template-columns: 232px 1fr 0px; min-height: 0; transition: grid-template-columns .18s ease; }
#main.with-aside { grid-template-columns: 232px 1fr 340px; }
#main.no-side { grid-template-columns: 0px 1fr 0px; }
#main.no-side.with-aside { grid-template-columns: 0px 1fr 340px; }

/* ── шапка ────────────────────────────────────────────────────────── */
header {
  display: flex; align-items: center; gap: 14px;
  padding: 8px 14px; background: var(--panel);
  border-bottom: 1px solid var(--line); flex-wrap: wrap;
}
.brand { font-weight: 600; letter-spacing: .2px; white-space: nowrap; font-size: 13.5px; }
.brand span { color: var(--accent2); }
.hgroup { display: flex; align-items: center; gap: 8px; }
.hgroup > label {
  color: var(--dim); font-size: 10.5px; letter-spacing: .5px;
  text-transform: uppercase; white-space: nowrap;
}
.sep { width: 1px; height: 22px; background: var(--line2); }
.spacer { flex: 1; }

.btn {
  background: none; border: 1px solid var(--line2); color: var(--muted);
  padding: 5px 11px; border-radius: 3px; font-size: 12.5px; font-weight: 500;
  white-space: nowrap;
}
.btn:hover { background: var(--panel2); color: var(--fg); border-color: var(--dim); }
.btn.on { background: var(--fg); border-color: var(--fg); color: var(--bg); }
.btn.sm { padding: 3px 8px; font-size: 12px; }

input[type=search], input[type=text] {
  background: var(--bg); border: 1px solid var(--line2);
  border-radius: 3px; padding: 5px 10px; width: 210px; font-size: 12.5px;
}
input::placeholder { color: var(--dim); }
input[type=search]:focus, input[type=text]:focus { outline: none; border-color: var(--accent); }
input[type=range] { width: 120px; accent-color: var(--fg); }
.val { font: 12px var(--mono); color: var(--muted); min-width: 26px; text-align: right; }

/* ── боковая панель ───────────────────────────────────────────────── */
aside.left {
  background: var(--panel); border-right: 1px solid var(--line);
  overflow-y: auto; padding: 12px 10px 40px;
}
#main.no-side aside.left { display: none; }
.sect { margin-bottom: 18px; }
.sect h3 {
  margin: 0 0 8px; font-size: 10px; text-transform: uppercase;
  letter-spacing: .9px; color: var(--dim); font-weight: 600;
}
.tgl {
  display: flex; align-items: center; gap: 8px; width: 100%;
  padding: 5px 7px; border-radius: 3px; background: none; border: none;
  text-align: left; font-size: 13px; color: var(--muted);
}
.tgl:hover { background: var(--panel2); }
.tgl.on { color: var(--fg); }
.tgl .sw { width: 10px; height: 10px; border-radius: 1px; background: var(--dim);
             flex: none; border: 1px solid var(--line2); }
.tgl.on .sw { background: var(--c); border-color: var(--c); }
.tgl .n { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tgl .ct { font: 11px var(--mono); color: var(--dim); }

/* ── лента ────────────────────────────────────────────────────────── */
#stage { position: relative; overflow: hidden; background: var(--bg); }
#stage canvas { position: absolute; inset: 0; width: 100%; height: 100%; display: block; }
#overlay { pointer-events: none; }
#stage.grabbing { cursor: grabbing; }
#stage { cursor: crosshair; }

.hint {
  position: absolute; left: 50%; bottom: 14px; transform: translateX(-50%);
  background: var(--panel); border: 1px solid var(--line2);
  padding: 6px 12px; border-radius: 20px; font-size: 12px; color: var(--muted);
  pointer-events: none; transition: opacity .4s; white-space: nowrap;
}
#tooltip {
  position: absolute; pointer-events: none; z-index: 5; max-width: 300px;
  background: var(--panel); border: 1px solid var(--line2);
  border-radius: 3px; padding: 7px 10px; font-size: 12.5px;
  box-shadow: 0 8px 24px rgba(0,0,0,.28); display: none;
}
#tooltip b { display: block; margin-bottom: 2px; }
#tooltip .m { color: var(--muted); font-size: 11.5px; }

/* ── правая панель ────────────────────────────────────────────────── */
aside.right {
  background: var(--panel); border-left: 1px solid var(--line);
  overflow-y: auto; display: none; padding: 0 0 40px;
}
#main.with-aside aside.right { display: block; }
.rhead {
  position: sticky; top: 0; background: var(--panel); z-index: 2;
  padding: 11px 14px; border-bottom: 1px solid var(--line);
  display: flex; align-items: center; gap: 8px;
}
.rhead h2 { margin: 0; font-size: 14px; font-weight: 600; flex: 1; }
.rbody { padding: 12px 14px; }
.rbody h4 { margin: 16px 0 6px; font-size: 11px; letter-spacing: .7px;
  text-transform: uppercase; color: var(--dim); font-weight: 600; }
.rbody p { margin: 6px 0; color: var(--muted); font-size: 13px; }
.kv { display: grid; grid-template-columns: 92px 1fr; gap: 3px 8px; font-size: 13px; margin: 8px 0; }
.kv dt { color: var(--dim); }
.kv dd { margin: 0; }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

.row {
  display: flex; gap: 8px; align-items: baseline; padding: 5px 7px;
  border-radius: 3px; cursor: pointer; font-size: 13px;
}
.row:hover { background: var(--panel2); }
.row .yr { font: 11px var(--mono); color: var(--dim); flex: none; width: 62px; text-align: right; }
.row .dot { width: 7px; height: 7px; border-radius: 50%; flex: none; }
.row .t { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.grp { margin: 10px 0 2px; font-size: 11px; letter-spacing: .6px;
  text-transform: uppercase; color: var(--dim); display: flex; gap: 6px; align-items: center; }
.grp i { width: 8px; height: 8px; border-radius: 2px; display: inline-block; }
.empty { color: var(--dim); font-size: 13px; padding: 8px 0; font-style: italic; }

/* ── режим учёбы ──────────────────────────────────────────────────── */
#study {
  position: fixed; inset: 0; background: color-mix(in srgb, var(--bg) 93%, transparent);
  backdrop-filter: blur(6px); z-index: 50; display: none;
  overflow-y: auto; padding: 28px 20px 60px;
}
#study.open { display: block; }
.sw-wrap { max-width: 680px; margin: 0 auto; }
.sw-top { display: flex; align-items: center; gap: 10px; margin-bottom: 20px; }
.sw-top h2 { margin: 0; font-size: 17px; flex: 1; }
.tabs { display: flex; gap: 6px; margin-bottom: 22px; flex-wrap: wrap; }
.card {
  background: var(--panel); border: 1px solid var(--line2);
  border-radius: 4px; padding: 26px 24px; margin-bottom: 16px;
}
.card .q { font-size: 19px; font-weight: 600; margin-bottom: 6px; line-height: 1.35; }
.card .sub { color: var(--muted); font-size: 13px; }
.card .rev { margin-top: 20px; padding-top: 18px; border-top: 1px solid var(--line); }
.card .rev .big { font-size: 25px; font-weight: 650; color: var(--accent2); font-variant-numeric: tabular-nums; }
.opts { display: grid; gap: 9px; margin-top: 20px; }
.opt {
  text-align: left; padding: 12px 15px; border-radius: 3px;
  background: var(--panel2); border: 1px solid var(--line2); font-size: 15px;
}
.opt:hover:not(:disabled) { border-color: var(--accent); }
.opt:disabled { cursor: default; }
.opt.right { border-color: var(--ok); background: color-mix(in srgb, var(--ok) 14%, transparent); }
.opt.wrong { border-color: var(--bad); background: color-mix(in srgb, var(--bad) 14%, transparent); }
.grades { display: grid; grid-template-columns: repeat(4,1fr); gap: 8px; margin-top: 18px; }
.grade { padding: 11px 6px; border-radius: 3px; border: 1px solid var(--line2);
  background: var(--panel2); text-align: center; }
.grade b { display: block; font-size: 14px; }
.grade small { color: var(--dim); font-size: 11px; }
.grade:hover { border-color: var(--accent); }
.stats { display: flex; gap: 18px; color: var(--muted); font-size: 12.5px; flex-wrap: wrap; }
.stats b { color: var(--fg); font-variant-numeric: tabular-nums; }
.feed { margin-top: 14px; font-size: 14px; min-height: 22px; }
.feed.ok { color: var(--ok); } .feed.no { color: var(--bad); }

#heat { display: grid; gap: 2px; margin-top: 10px; overflow-x: auto; padding-bottom: 6px; }
#heat .hrow { display: grid; gap: 2px; align-items: center; }
#heat .hl { font-size: 11px; color: var(--muted); text-align: right; padding-right: 6px;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
#heat .hc { height: 15px; border-radius: 2px; background: var(--panel2); }
#heat .hx { font: 10px var(--mono); color: var(--dim); text-align: center; }

.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }
::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-thumb { background: var(--line2); border-radius: 5px; border: 2px solid var(--panel); }
::-webkit-scrollbar-track { background: transparent; }

@media (max-width: 900px) {
  #main, #main.with-aside { grid-template-columns: 1fr; }
  aside.left, aside.right { display: none; }
}

/* ── переключение вида и карта ─────────────────────────────────────── */
#viewport { position: relative; overflow: hidden; min-width: 0; }
#stage, #mapstage { position: absolute; inset: 0; }
#mapstage { background: var(--map-bg); cursor: grab; }
#mapstage canvas { position: absolute; inset: 0; width: 100%; height: 100%; display: block; }

#mapNow {
  position: absolute; left: 12px; top: 52px; width: 268px;
  max-height: calc(100% - 90px); overflow-y: auto;
  background: color-mix(in srgb, var(--panel) 94%, transparent); border: 1px solid var(--line2);
  border-radius: 10px; padding: 10px 10px 12px;
  backdrop-filter: blur(8px); font-size: 12.5px;
}
#mapNow .nowhead {
  font-size: 11px; letter-spacing: .7px; text-transform: uppercase;
  color: var(--dim); font-weight: 600; margin-bottom: 6px;
}
#mapNow { width: 292px; }
#mapNow .row { padding: 5px 5px; gap: 7px; align-items: flex-start; }
#mapNow .row .dot { margin-top: 5px; }
#mapNow .row .t { font-size: 12.5px; white-space: normal; display: block; }
#mapNow .row .nm { display: block; line-height: 1.3; }
#mapNow .row .yr {
  display: block; width: auto; text-align: left;
  font: 10.5px var(--mono); color: var(--dim); margin-top: 1px;
}
#mapNow .grp { margin: 8px 0 1px; }
#mapNow .nowhead { display: flex; align-items: center; }
#mapNow .nowhead button {
  margin-left: auto; background: none; border: 1px solid var(--line2);
  color: var(--muted); width: 20px; height: 18px; border-radius: 4px;
  line-height: 1; font-size: 13px; padding: 0;
}
#mapNow .nowhead button:hover { color: var(--fg); border-color: var(--accent); }
#mapNow.collapsed { width: 176px; }
#mapNow.collapsed .row, #mapNow.collapsed .grp { display: none; }

/* ── всплывающая карточка события ──────────────────────────────────── */
#popup {
  position: absolute; z-index: 12; width: 372px; max-width: calc(100% - 20px);
  max-height: calc(100% - 24px); overflow-y: auto; display: none;
  background: var(--panel); border: 1px solid var(--line2); border-radius: 4px;
  padding: 15px 17px 14px; box-shadow: 0 14px 40px rgba(0,0,0,.3);
}
#popup .pclose {
  float: right; margin: -4px -6px 0 8px; background: none; border: none;
  color: var(--dim); font-size: 15px; line-height: 1; padding: 4px;
}
#popup .pclose:hover { color: var(--fg); }
#popup .ptitle { font-size: 16.5px; font-weight: 600; line-height: 1.28; margin-bottom: 9px; }
#popup .pmeta { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; margin-bottom: 9px; }
#popup .chip {
  font-size: 10.5px; padding: 2px 8px; border-radius: 10px; color: var(--c);
  border: 1px solid color-mix(in srgb, var(--c) 45%, transparent);
  background: color-mix(in srgb, var(--c) 12%, transparent);
}
#popup .pdate { font: 11.5px var(--mono); color: var(--muted); }
#popup .pdesc { color: var(--muted); font-size: 13px; margin-bottom: 9px; }
#popup .pextract {
  font-family: var(--serif); font-size: 13.2px; line-height: 1.52; overflow: hidden;
}
#popup .pthumb {
  float: right; width: 96px; height: auto; max-height: 120px; object-fit: cover;
  margin: 2px 0 6px 12px; border-radius: 2px; border: 1px solid var(--line2);
}
#popup .ptext { color: var(--fg); }
#popup .ploading { color: var(--dim); font-style: italic; font-size: 12.5px; }
#popup .plang { clear: both; color: var(--dim); font-size: 11px; margin-top: 5px; }
#popup .pacts { clear: both; display: flex; flex-wrap: wrap; gap: 6px; margin-top: 12px; }

/* ── раздел «О проекте» ────────────────────────────────────────────── */
#about {
  position: fixed; inset: 0; z-index: 60; display: none;
  overflow-y: auto; padding: 30px 20px 70px;
  background: color-mix(in srgb, var(--bg) 95%, transparent);
  backdrop-filter: blur(7px);
}
#about.open { display: block; }
.ab-wrap { max-width: 720px; margin: 0 auto; }
.ab-top { display: flex; align-items: center; gap: 12px; margin-bottom: 22px; }
.ab-top h2 { margin: 0; font-size: 20px; font-weight: 650; flex: 1; letter-spacing: -.2px; }

#about p { font-size: 14.5px; line-height: 1.65; margin: 0 0 14px; }
#about p.lead { font-size: 16.5px; line-height: 1.55; }
#about p.muted { color: var(--muted); font-size: 13.5px; }
#about p.small { font-size: 12.5px; line-height: 1.6; }
#about b { font-weight: 600; }
#about h3 {
  margin: 30px 0 12px; font-size: 11px; font-weight: 600; letter-spacing: 1px;
  text-transform: uppercase; color: var(--dim);
  padding-bottom: 7px; border-bottom: 1px solid var(--line);
}
.ab-list { margin: 0 0 16px; padding: 0; list-style: none; }
.ab-list li {
  font-size: 14px; line-height: 1.6; padding: 7px 0 7px 18px; position: relative;
}
.ab-list li + li { border-top: 1px solid var(--line); }
.ab-list li::before {
  content: ""; position: absolute; left: 2px; top: 15px;
  width: 5px; height: 5px; border-radius: 50%; background: var(--accent2);
}
.ab-tbl { width: 100%; border-collapse: collapse; margin: 0 0 12px; font-size: 13px; }
.ab-tbl th {
  text-align: left; font-size: 10px; letter-spacing: .8px; text-transform: uppercase;
  color: var(--dim); font-weight: 600; padding: 0 10px 7px 0;
  border-bottom: 1px solid var(--line2);
}
.ab-tbl td { padding: 8px 10px 8px 0; border-bottom: 1px solid var(--line);
             vertical-align: top; line-height: 1.45; }
.ab-tbl td:last-child { color: var(--muted); white-space: nowrap; }
@media (max-width: 700px) {
  .ab-tbl td:last-child { white-space: normal; }
}

/* ── раздел «Династии» ─────────────────────────────────────────────── */
#dynasty {
  position: fixed; inset: 0; z-index: 55; display: none;
  background: var(--bg); flex-direction: column;
}
#dynasty.open { display: flex; }
.dy-bar {
  display: flex; align-items: center; gap: 10px; height: 46px; flex: none;
  padding: 0 14px; background: var(--panel); border-bottom: 1px solid var(--line);
}
.mark2 { font-weight: 600; font-size: 13.5px; white-space: nowrap; }
.dy-tabs { display: flex; gap: 6px; }
.dy-tip { font-size: 11px; color: var(--dim); white-space: nowrap; }
.dy-body { flex: 1; display: flex; min-height: 0; }
.dy-view { flex: 1; position: relative; overflow: hidden; cursor: grab; min-width: 0; }
.dy-view:active { cursor: grabbing; }
.dy-canvas { position: absolute; left: 0; top: 0; transform-origin: 0 0; }
.dy-edges { position: absolute; left: 0; top: 0; overflow: visible; pointer-events: none; }
.dy-edge path { fill: none; stroke: var(--line2); stroke-width: 1.4; }
.dy-tick { stroke: var(--line); stroke-width: 1; }
.dy-ticktext { fill: var(--dim); font: 10px var(--mono); text-anchor: end; }
.dy-nodes { position: absolute; left: 0; top: 0; }

/* Узел дерева: портрет, имя, годы. Правители крупнее — линия
   преемственности должна читаться раньше боковых ветвей. */
.dy-node {
  position: absolute; width: 96px; text-align: center; cursor: pointer;
  padding: 4px 2px; border-radius: 3px; border: 1px solid transparent;
}
.dy-node:hover { background: var(--panel2); border-color: var(--line2); }
.dy-node.sel { background: var(--panel2); border-color: var(--accent); }
.dy-node .ava {
  width: 52px; height: 52px; margin: 0 auto 5px; border-radius: 50%;
  overflow: hidden; background: var(--panel2); border: 1px solid var(--line2);
  display: grid; place-items: center; color: var(--dim); font-size: 16px;
}
.dy-node.ruler .ava {
  width: 62px; height: 62px; border-width: 2px; border-color: var(--accent2);
}
.dy-node .ava img { width: 100%; height: 100%; object-fit: cover; display: block; }
.dy-node .nm {
  font-size: 11px; line-height: 1.25; color: var(--fg);
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden;
}
.dy-node.ruler .nm { font-weight: 600; }
.dy-node .yr { font: 9.5px var(--mono); color: var(--dim); margin-top: 2px; }

/* Шкала руководителей */
/* Ширина согласована с шагом колонки в dynasty.js (COL_W = 330):
   при 620 px соседние колонки налезали друг на друга. */
.dy-lead { position: absolute; width: 302px; cursor: pointer; }
.dy-lead .bar {
  position: absolute; left: 0; top: 0; bottom: 0; width: 4px;
  background: var(--accent); border-radius: 2px;
}
.dy-lead .ava {
  position: absolute; left: 16px; top: 0; width: 46px; height: 46px;
  border-radius: 50%; overflow: hidden; background: var(--panel2);
  border: 1px solid var(--line2); display: block;
}
.dy-lead .ava img { width: 100%; height: 100%; object-fit: cover; display: block; }
.dy-lead .txt { position: absolute; left: 74px; top: 0; right: 0; }
.dy-lead .txt b { display: block; font-size: 13.5px; font-weight: 600; }
.dy-lead .txt .yr { display: block; font: 10.5px var(--mono); color: var(--muted); margin-top: 1px; }
.dy-lead .txt .fx { display: block; font-size: 11.5px; color: var(--dim); margin-top: 2px; }
.dy-lead:hover .txt b, .dy-lead.sel .txt b { color: var(--accent); }

/* Боковая карточка */
.dy-side {
  width: 348px; flex: none; background: var(--panel);
  border-left: 1px solid var(--line); overflow-y: auto; padding: 16px 16px 40px;
}
.dy-hint { color: var(--dim); font-size: 13px; line-height: 1.6; }
.dy-head { display: flex; gap: 13px; align-items: flex-start; margin-bottom: 14px; }
.dy-photo {
  width: 84px; height: 104px; object-fit: cover; flex: none;
  border-radius: 2px; border: 1px solid var(--line2);
}
.dy-head h3 { margin: 0 0 3px; font-size: 16px; font-weight: 600; line-height: 1.25; }
.dy-life { font: 11px var(--mono); color: var(--muted); }
.dy-desc { font-size: 12.5px; color: var(--muted); margin-top: 5px; line-height: 1.4; }
.dy-born {
  border-left: 2px solid var(--accent2); padding: 6px 0 6px 10px; margin: 0 0 14px;
  font-size: 12.5px;
}
.dy-born .k { display: block; font-size: 9.5px; letter-spacing: .8px;
  text-transform: uppercase; color: var(--dim); margin-bottom: 2px; }
.dy-born .from { color: var(--muted); margin-left: 6px; }
#dynasty h4 {
  margin: 18px 0 8px; font-size: 9.5px; font-weight: 600; letter-spacing: 1px;
  text-transform: uppercase; color: var(--dim);
  padding-bottom: 5px; border-bottom: 1px solid var(--line);
}
.dy-reign { display: flex; justify-content: space-between; gap: 10px;
  font-size: 12.5px; padding: 3px 0; }
.dy-reign span { font: 11px var(--mono); color: var(--muted); white-space: nowrap; }
.dy-row { display: flex; gap: 8px; padding: 4px 0; font-size: 12.5px; }
.dy-row .k { width: 96px; flex: none; color: var(--dim); font-size: 11.5px; }
.dy-row .v { flex: 1; }
.dy-kin {
  background: none; border: none; padding: 0 6px 0 0; color: var(--accent);
  font-size: 12.5px; cursor: pointer; text-align: left;
}
.dy-kin:hover { text-decoration: underline; }
.dy-wars { display: flex; flex-wrap: wrap; gap: 5px; }
.dy-wars span {
  font-size: 11.5px; padding: 2px 7px; border-radius: 10px;
  border: 1px solid var(--line2); color: var(--muted);
}
.dy-extract { margin-top: 16px; font-family: var(--serif); font-size: 13px; line-height: 1.55; }
.dy-extract p { margin: 0; }
.dy-extract .lic { font-family: var(--font); font-size: 10.5px; color: var(--dim); margin-top: 7px; }
.dy-extract .dim, .dy-side .dim { color: var(--dim); font-style: italic; font-size: 12.5px; }
.dy-acts { display: flex; gap: 6px; margin-top: 14px; }
.dy-more { font-size: 11.5px; color: var(--dim); }
.dy-lead .txt .off { display: block; font-size: 11px; color: var(--muted); margin-top: 2px; }

/* ── династии: пояснение, правящая ветвь, семейный попап ───────────── */
.dy-note {
  flex: none; padding: 8px 16px; background: var(--panel2);
  border-bottom: 1px solid var(--line); font-size: 11.5px; color: var(--muted);
  line-height: 1.5;
}
.dy-note b { color: var(--fg); font-weight: 600; }

/* Магистраль династии толще и в цвете акцента: в общем полотне должно
   быть видно, через кого прошла корона. */
.dy-edge.line path { stroke: var(--accent2); stroke-width: 2.4; }
.dy-node.online .nm { color: var(--fg); }
.dy-node:not(.online) { opacity: .72; }
.dy-node:not(.online) .ava { border-color: var(--line); }
.dy-node .rg { font: 9.5px var(--mono); color: var(--accent2); margin-top: 1px; }
.dy-lead .txt .yr.life { color: var(--dim); }

.dy-fam {
  position: absolute; inset: 0; z-index: 20; display: none;
  background: color-mix(in srgb, var(--bg) 72%, transparent);
  backdrop-filter: blur(4px); padding: 34px 20px; overflow-y: auto;
}
.dy-fam.open { display: block; }
.fam-box {
  position: relative; max-width: 940px; margin: 0 auto;
  background: var(--panel); border: 1px solid var(--line2); border-radius: 4px;
  padding: 20px 22px 18px; box-shadow: 0 18px 50px rgba(0,0,0,.35);
}
.fam-x {
  position: absolute; right: 12px; top: 10px; background: none; border: none;
  color: var(--dim); font-size: 15px; line-height: 1; padding: 4px; cursor: pointer;
}
.fam-x:hover { color: var(--fg); }
.fam-head { margin-bottom: 16px; }
.fam-head h3 { margin: 0 0 3px; font-size: 18px; font-weight: 600; }
.fam-sub { font: 11.5px var(--mono); color: var(--muted); white-space: pre; }
.fam-band { display: flex; gap: 26px; padding: 12px 0;
            border-top: 1px solid var(--line); flex-wrap: wrap; }
.fam-band:first-of-type { border-top: 0; }
.fam-band.couple { align-items: flex-start; }
.fam-grp { min-width: 0; }
.fam-lbl {
  font-size: 9.5px; letter-spacing: .9px; text-transform: uppercase;
  color: var(--dim); margin-bottom: 7px;
}
.fam-row { display: flex; gap: 8px; flex-wrap: wrap; }
.fam-row.wrap { flex-wrap: wrap; }
.fchip {
  display: flex; align-items: center; gap: 8px; text-align: left;
  background: none; border: 1px solid var(--line); border-radius: 3px;
  padding: 5px 9px 5px 5px; cursor: pointer; max-width: 236px;
}
.fchip:hover { border-color: var(--dim); background: var(--panel2); }
.fchip.ruled { border-color: var(--accent2); background: color-mix(in srgb, var(--accent2) 9%, transparent); }
.fchip .av {
  width: 34px; height: 34px; flex: none; border-radius: 50%; overflow: hidden;
  background: var(--panel2); border: 1px solid var(--line2); display: block;
}
.fchip.ruled .av { border-color: var(--accent2); border-width: 2px; }
.fchip .av img { width: 100%; height: 100%; object-fit: cover; display: block; }
.fchip .tx { min-width: 0; }
.fchip .n {
  display: block; font-size: 12.5px; color: var(--fg); line-height: 1.2;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.fchip.ruled .n { font-weight: 600; }
.fchip .y { display: block; font: 9.5px var(--mono); color: var(--dim); }
.fchip .y.rg { color: var(--accent2); }
.fchip .role {
  font-size: 10px; color: var(--muted); border-left: 1px solid var(--line);
  padding-left: 8px; margin-left: 2px; max-width: 130px; line-height: 1.3;
}
.fam-legend { margin-top: 14px; font-size: 11px; color: var(--dim);
  display: flex; align-items: center; gap: 7px; }
.fam-legend .ruled-dot {
  width: 13px; height: 13px; border-radius: 50%;
  border: 2px solid var(--accent2); display: inline-block;
}
/* Выведенная связь слабее документированной — и выглядит слабее. */
.dy-edge.guess path { stroke: var(--accent); stroke-width: 1.4; stroke-dasharray: 4 3; }
.dy-note .gs { color: var(--accent); border-bottom: 1px dashed var(--accent); }
/* Выноска от карточки к её истинной отметке на оси: показывает, насколько
   запись сместилась вниз, чтобы поместиться. */
.dy-lead-line { fill: none; stroke: var(--line2); stroke-width: 1; stroke-dasharray: 3 3; }
