/* PT Serif (ParaType, SIL OFL 1.1, vendor/fonts/OFL.txt) for the books */
@font-face { font-family: 'PT Serif'; font-style: italic; font-weight: 400; font-display: swap; src: url(vendor/fonts/ptserif-400i-cyrillic.woff2) format('woff2'); unicode-range: U+0301, U+0400-045F, U+0490-0491, U+04B0-04B1, U+2116; }
@font-face { font-family: 'PT Serif'; font-style: italic; font-weight: 400; font-display: swap; src: url(vendor/fonts/ptserif-400i-latin.woff2) format('woff2'); unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD; }
@font-face { font-family: 'PT Serif'; font-style: normal; font-weight: 400; font-display: swap; src: url(vendor/fonts/ptserif-400-cyrillic.woff2) format('woff2'); unicode-range: U+0301, U+0400-045F, U+0490-0491, U+04B0-04B1, U+2116; }
@font-face { font-family: 'PT Serif'; font-style: normal; font-weight: 400; font-display: swap; src: url(vendor/fonts/ptserif-400-latin.woff2) format('woff2'); unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD; }
@font-face { font-family: 'PT Serif'; font-style: normal; font-weight: 700; font-display: swap; src: url(vendor/fonts/ptserif-700-cyrillic.woff2) format('woff2'); unicode-range: U+0301, U+0400-045F, U+0490-0491, U+04B0-04B1, U+2116; }
@font-face { font-family: 'PT Serif'; font-style: normal; font-weight: 700; font-display: swap; src: url(vendor/fonts/ptserif-700-latin.woff2) format('woff2'); unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD; }
:root {
  --bg: #f4efe4; --paper: #fbf8f1; --ink: #2a2622; --muted: #6f665b; --line: #d9cfbd; --line-strong: #b8a98f;
  --surface: #fff; --wash: #efe7d6; --field-edge: #94866c; --muted-on-box: #5f574c;
  --accent: #2f4a3a; --accent-ink: #f3e9d2; --accent-soft: #e3eadf;
  --male: #dbe7ef; --male-edge: #7d9bb0; --male-fill: #577a92;
  --female: #f3e1c7; --female-edge: #c49a62; --female-fill: #936c34;
  --unknown: #e8e4dc; --unknown-edge: #a39b8d; --unknown-fill: #797265;
  --edge: #8a7c64; --edge-spouse: #9c8150;
  --doc: #8f5f3f; --doc-photo: #4f7160; --doc-image: #6d5d8e; --viewer-bg: #3a352f;
  --focus: #b5452f; --danger: #a33a2a; --danger-edge: #d8b2aa; --warn-bg: #f6e3d8; --warn-ink: #8a3f22;
  --shadow: 0 1px 2px rgba(60,45,20,.08), 0 6px 20px rgba(60,45,20,.08);
  --ease: cubic-bezier(.16, 1, .3, 1);
  --top-h: calc(56px + env(safe-area-inset-top, 0px));
  --serif: "Iowan Old Style", "Palatino Linotype", Palatino, Georgia, "Times New Roman", serif;
  --sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --r: 10px;
}
* { box-sizing: border-box; }
html { color-scheme: light; accent-color: var(--accent); scrollbar-color: var(--line-strong) transparent; }
html, body { height: 100%; margin: 0; }
::selection { background: #cfdcc9; color: var(--ink); }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.top :focus-visible { outline-color: var(--accent-ink); }
body { background: var(--bg); color: var(--ink); font: 15px/1.45 var(--sans); -webkit-font-smoothing: antialiased; overflow: hidden; }
button, input, select, textarea { font: inherit; color: inherit; }
a { color: var(--accent); text-underline-offset: 2px; }
.hidden { display: none !important; }

.i { width: 1.15em; height: 1.15em; flex: none; display: block; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }

/* login */
.login { min-height: 100vh; min-height: 100dvh; display: grid; place-items: center; padding: 16px;
  background: radial-gradient(1200px 600px at 50% -10%, #fffaf0 0%, var(--bg) 60%); }
.login form { width: min(360px, 100%); background: var(--paper); border: 1px solid var(--line); border-radius: 14px; padding: 28px; box-shadow: var(--shadow); }
.login h1 { font: 600 28px/1.15 var(--serif); margin: 0 0 4px; }
.login p { color: var(--muted); margin: 0 0 20px; }
.field { display: grid; gap: 4px; margin-bottom: 12px; }
.field > span { font-size: 12.5px; color: var(--muted); }
input[type=text], input[type=password], input[type=search], select, textarea {
  width: 100%; padding: 9px 11px; border: 1px solid var(--field-edge); border-radius: 8px; background: var(--surface); outline: none; caret-color: var(--accent); }
input:focus, select:focus, textarea:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
input[type=checkbox] { width: 16px; height: 16px; margin: 0; flex: none; }
textarea { min-height: 90px; resize: vertical; }
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; padding: 8px 14px; border-radius: 8px; border: 1px solid var(--line-strong);
  background: var(--paper); cursor: pointer; white-space: nowrap; text-decoration: none; color: var(--ink); transition: background-color .12s, border-color .12s; }
.btn:hover { background: var(--surface); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.primary:hover { filter: brightness(1.08); }
.btn.danger { color: var(--danger); border-color: var(--danger-edge); }
.btn.ghost { border-color: transparent; background: transparent; }
.btn.ghost:hover { background: rgba(0,0,0,.05); }
.btn.sm { padding: 5px 10px; font-size: 13px; }
.btn:disabled { opacity: .5; cursor: default; }
.err { color: var(--danger); font-size: 13.5px; min-height: 1.2em; margin: 4px 0 8px; }

/* header */
.top { position: fixed; inset: 0 0 auto 0; height: var(--top-h); display: flex; align-items: center; gap: 12px;
  padding: env(safe-area-inset-top, 0px) calc(14px + env(safe-area-inset-right, 0px)) 0 calc(14px + env(safe-area-inset-left, 0px));
  background: var(--accent); color: var(--accent-ink); z-index: 30; }
.brand-h { margin: 0; font: inherit; }
.brand { font: 600 20px/1 var(--serif); letter-spacing: .2px; white-space: nowrap; cursor: pointer; display: flex; flex-direction: column; align-items: flex-start; gap: 3px;
  background: none; border: 0; padding: 0; color: inherit; text-align: left; border-radius: 4px; }
.brand small { font: 400 11.5px/1 var(--sans); letter-spacing: 0; opacity: .82; }
.brand small:empty { display: none; }
.nav { display: flex; gap: 2px; }
.nav button { background: transparent; border: 0; color: var(--accent-ink); opacity: .82; padding: 8px 10px; border-radius: 7px; cursor: pointer; transition: background-color .12s; }
.nav button.on, .nav button:hover { opacity: 1; background: rgba(255,255,255,.1); }
.search { position: relative; flex: 1; max-width: 420px; margin-left: auto; }
.search input { background: rgba(255,255,255,.12); border-color: transparent; color: #fff; caret-color: currentColor; }
.search input::placeholder { color: rgba(243,233,210,.78); }
.search input:placeholder-shown { text-overflow: ellipsis; }
.search input:focus { background: var(--surface); color: var(--ink); box-shadow: none; }
.menu-btn { background: transparent; border: 0; color: var(--accent-ink); font-size: 20px; width: 40px; height: 40px; display: grid; place-items: center; cursor: pointer; border-radius: 7px; }
.menu-btn:hover { background: rgba(255,255,255,.1); }
.dropdown { position: absolute; top: calc(100% + 6px); right: 0; min-width: 240px; background: var(--paper); color: var(--ink); border: 1px solid var(--line);
  border-radius: 10px; box-shadow: var(--shadow); padding: 6px; z-index: 50; max-height: 70vh; overflow: auto; }
.dropdown button, .dropdown a { display: block; width: 100%; text-align: left; padding: 8px 10px; border: 0; background: none; border-radius: 6px; cursor: pointer; color: var(--ink); text-decoration: none; }
.dropdown button:hover, .dropdown a:hover, .dropdown .sel { background: var(--accent-soft); }
.dropdown .sub { color: var(--muted); font-size: 12.5px; }
.dropdown hr { border: 0; border-top: 1px solid var(--line); margin: 6px 0; }
.who { font-size: 12.5px; color: var(--muted); padding: 6px 10px 2px; }

/* main */
main { position: fixed; inset: var(--top-h) 0 0 0; }
.view { position: absolute; inset: 0; overflow: auto; }
#tree { overflow: hidden; touch-action: none; cursor: grab; background:
  radial-gradient(circle at 1px 1px, rgba(120,100,70,.12) 1px, transparent 0) 0 0/22px 22px, var(--bg); }
#tree.drag { cursor: grabbing; }
/* family crest, a faint watermark that stays put while the tree pans and zooms */
#tree::before { content: ''; position: absolute; inset: 0; pointer-events: none; z-index: 0;
  background: url(crest.jpg) center / auto min(78%, 900px, 104vw) no-repeat; opacity: .14; mix-blend-mode: multiply; }
#tree > svg { position: relative; z-index: 1; width: 100%; height: 100%; display: block; user-select: none; -webkit-user-select: none; }
.edge { fill: none; stroke: var(--edge); stroke-width: 1.5; }
.edge.spouse { stroke: var(--edge-spouse); stroke-dasharray: 0; }
.node { cursor: pointer; outline: none; }
.node rect.box { stroke-width: 1.3; rx: 9; }
.node.M rect.box { fill: var(--male); stroke: var(--male-edge); }
.node.F rect.box { fill: var(--female); stroke: var(--female-edge); }
.node.U rect.box { fill: var(--unknown); stroke: var(--unknown-edge); }
.node.unc rect.box { stroke-dasharray: 4 3; }
.node.focus rect.box { stroke: var(--focus); stroke-width: 2.6; }
.node:hover rect.box { filter: brightness(1.04); stroke-width: 2; }
.node:focus-visible rect.box { stroke: var(--accent); stroke-width: 3; }
.node .ava { fill: var(--unknown-fill); }
.node.M .ava { fill: var(--male-fill); } .node.F .ava { fill: var(--female-fill); }
.node .nm { font: 600 13px var(--sans); fill: var(--ink); }
.node .nm2 { font: 12.5px var(--sans); fill: var(--ink); }
.node .yr { font: 11.5px var(--sans); fill: var(--muted-on-box); }
.node .clip { font: 11px var(--sans); fill: var(--muted-on-box); font-variant-numeric: tabular-nums; }
.node .clip-i { fill: none; stroke: var(--muted-on-box); stroke-width: 2.2; stroke-linecap: round; stroke-linejoin: round; }
.node .ini { font: 600 15px var(--serif); fill: #fff; }
.more { cursor: pointer; outline: none; }
.more circle { fill: var(--paper); stroke: var(--line-strong); }
.more circle.hit { fill: transparent; stroke: none; }
.more:hover circle:not(.hit) { stroke: var(--accent); }
.more:focus-visible circle:not(.hit) { stroke: var(--accent); stroke-width: 2.5; }
.more text { font: 600 13px var(--sans); fill: var(--muted); }
.tree-ctl { position: absolute; left: calc(14px + env(safe-area-inset-left, 0px)); bottom: calc(14px + env(safe-area-inset-bottom, 0px)); display: flex; flex-direction: column; gap: 6px; z-index: 5; }
.tree-ctl .grp { display: flex; background: var(--paper); border: 1px solid var(--line); border-radius: 10px; box-shadow: var(--shadow); overflow: hidden; }
.tree-ctl button { border: 0; background: transparent; padding: 7px 11px; cursor: pointer; min-width: 36px; display: inline-flex; align-items: center; justify-content: center; gap: 5px; transition: background-color .12s; }
.tree-ctl button:focus-visible { outline-offset: -2px; }
.tree-ctl .lbl.kin:focus-within { outline: 2px solid var(--accent); outline-offset: -2px; }
.tree-ctl button:hover { background: var(--accent-soft); }
.tree-ctl .lbl.kin { padding: 7px 12px 7px 10px; cursor: pointer; display: flex; align-items: center; gap: 4px; }
.tree-ctl .lbl { padding: 7px 4px 7px 10px; font-size: 12.5px; color: var(--muted); align-self: center; flex: 1; white-space: nowrap; font-variant-numeric: tabular-nums; }
.tree-ctl .lbl.kin { gap: 7px; }
.legend { position: absolute; right: calc(14px + env(safe-area-inset-right, 0px)); bottom: calc(14px + env(safe-area-inset-bottom, 0px)); background: var(--paper); border: 1px solid var(--line); border-radius: 10px; padding: 8px 10px; font-size: 12px; color: var(--muted); box-shadow: var(--shadow); display: flex; gap: 12px; }
.legend i { display: inline-block; width: 12px; height: 12px; border-radius: 3px; vertical-align: -2px; margin-right: 4px; border: 1px solid; }

/* drawer (person card) */
.drawer { position: fixed; top: var(--top-h); right: 0; bottom: 0; width: min(460px, 100%); background: var(--paper); border-left: 1px solid var(--line); padding-bottom: env(safe-area-inset-bottom, 0px);
  box-shadow: -8px 0 30px rgba(60,45,20,.12); z-index: 20; overflow-y: auto; overscroll-behavior: contain; transform: translateX(105%); visibility: hidden; transition: transform .24s var(--ease), visibility 0s .24s; }
.drawer.open { transform: none; visibility: visible; transition: transform .24s var(--ease); }
.drawer .close { position: sticky; top: 8px; float: right; margin: 8px; width: 40px; height: 40px; padding: 0; z-index: 2; background: var(--paper); }
.card-head { display: flex; gap: 16px; padding: 22px 20px 14px; align-items: flex-start; }
.avatar { width: 96px; height: 96px; border-radius: 50%; flex: none; display: grid; place-items: center; font: 600 32px var(--serif); color: #fff;
  background-size: cover; background-position: center; position: relative; border: 3px solid #fff; box-shadow: 0 0 0 1px var(--line); }
.avatar.M { background-color: var(--male-fill); } .avatar.F { background-color: var(--female-fill); } .avatar.U { background-color: var(--unknown-fill); }
.avatar .up { position: absolute; inset: auto 0 -6px auto; width: 30px; height: 30px; border-radius: 50%; background: var(--accent); color: var(--accent-ink);
  border: 2px solid #fff; display: grid; place-items: center; font-size: 15px; padding: 0; cursor: pointer; }
.card-head > div:last-child { min-width: 0; }
.card-head h2 { font: 600 22px/1.2 var(--serif); margin: 2px 0 6px; text-wrap: balance; }
.card-head .dates { color: var(--muted); font-size: 14px; font-variant-numeric: tabular-nums; }
.badges { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; }
.badge { font-size: 11.5px; padding: 2px 8px; border-radius: 99px; background: var(--accent-soft); color: var(--accent); }
.badge.warn { background: var(--warn-bg); color: var(--warn-ink); }
.actions { display: flex; flex-wrap: wrap; gap: 6px; padding: 0 20px 12px; }
.sec { border-top: 1px solid var(--line); padding: 14px 20px; }
.sec h3 { font: 600 12px var(--sans); text-transform: uppercase; letter-spacing: .7px; color: var(--muted); margin: 0 0 10px; display: flex; align-items: center; gap: 8px; }
.sec h3 .cnt { background: var(--line); color: var(--ink); border-radius: 99px; padding: 0 7px; font-size: 11px; letter-spacing: 0; }
.kv { display: grid; grid-template-columns: 110px 1fr; gap: 4px 10px; font-size: 14px; }
.kv dt { color: var(--muted); } .kv dd { margin: 0; }
.rel-group { margin-bottom: 8px; } .rel-group .k { font-size: 12.5px; color: var(--muted); margin-bottom: 4px; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip { display: inline-flex; align-items: center; gap: 6px; padding: 4px 10px 4px 4px; border-radius: 18px; border: 1px solid var(--line); background: var(--surface); cursor: pointer; font-size: 13.5px; max-width: 100%; text-align: left; transition: border-color .12s; }
.chip:hover { border-color: var(--accent); }
.chip .dot { width: 22px; height: 22px; border-radius: 50%; display: grid; place-items: center; color: #fff; font: 600 11px var(--serif); background-size: cover; flex: none; }
.chip .dot.M { background-color: var(--male-fill); } .chip .dot.F { background-color: var(--female-fill); } .chip .dot.U { background-color: var(--unknown-fill); }
.chip small { color: var(--muted); white-space: nowrap; font-variant-numeric: tabular-nums; }
.chip .x { margin-left: 2px; color: var(--muted); padding: 2px 4px; }
.chip-row { display: inline-flex; align-items: center; gap: 2px; max-width: 100%; }
.prose { white-space: pre-wrap; font-size: 14.5px; overflow-wrap: anywhere; }
.doclist { display: grid; gap: 6px; }
.doc { display: flex; gap: 10px; align-items: flex-start; padding: 8px 10px; border: 1px solid var(--line); border-radius: 8px; background: var(--surface); cursor: pointer; text-align: left; width: 100%; transition: border-color .12s; }
.doc:hover { border-color: var(--accent); }
.doc .ic { flex: none; width: 40px; height: 44px; border-radius: 4px; display: grid; place-items: center; font: 600 10px var(--sans); color: #fff; background: var(--doc); }
.doc .ic.photo { background: var(--doc-photo); } .doc .ic.image { background: var(--doc-image); }
.doc .t { font-size: 13.5px; line-height: 1.3; }
.doc .s { font-size: 12px; color: var(--muted); margin-top: 2px; }
.excerpt { border-left: 1px solid var(--line-strong); padding: 2px 0 2px 13px; margin: 0 0 12px; font: 14.5px/1.5 var(--serif); }
.excerpt .src { font: 12px var(--sans); color: var(--muted); margin-top: 3px; }
.hist { font-size: 12.5px; color: var(--muted); margin: 0 0 4px; }
.hist b { color: var(--ink); font-weight: 600; }
details > summary { cursor: pointer; color: var(--accent); font-size: 13.5px; margin-top: 4px; border-radius: 4px; }

/* modal */
.modal-bg { position: fixed; inset: 0; background: rgba(30,25,15,.45); z-index: 60; display: grid; place-items: center; padding: 16px; }
.modal { background: var(--paper); border-radius: 14px; box-shadow: 0 20px 60px rgba(0,0,0,.25); width: min(640px, 100%); max-height: calc(100vh - 32px); max-height: calc(100dvh - 32px); display: flex; flex-direction: column; }
.modal.wide { width: min(1200px, 100%); height: calc(100vh - 32px); height: calc(100dvh - 32px); }
.modal header { display: flex; align-items: center; gap: 10px; padding: 14px 18px; border-bottom: 1px solid var(--line); }
.modal header h3 { margin: 0; font: 600 18px/1.25 var(--serif); flex: 1; min-width: 0; overflow-wrap: anywhere; }
.modal .body { padding: 16px 18px; overflow: auto; }
.modal footer { display: flex; justify-content: flex-end; gap: 8px; padding: 12px 18px; border-top: 1px solid var(--line); }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 0 12px; }
.check { display: flex; align-items: center; gap: 8px; margin: 6px 0; font-size: 14px; }
.picker { position: relative; }
.picker .dropdown { left: 0; right: 0; top: 100%; }
.viewer { display: grid; grid-template-columns: 1fr 300px; flex: 1; min-height: 0; }
.viewer .pane { background: var(--viewer-bg); min-height: 0; display: flex; }
.viewer iframe { border: 0; width: 100%; height: 100%; background: #fff; }
.viewer .imgwrap { overflow: auto; width: 100%; display: grid; place-items: center; }
.viewer img { max-width: 100%; height: auto; cursor: zoom-in; }
.viewer img.zoom { max-width: none; cursor: zoom-out; }
.viewer aside { padding: 16px; overflow: auto; border-left: 1px solid var(--line); font-size: 14px; }
.viewer aside .cap { white-space: pre-wrap; color: var(--ink); margin: 8px 0 12px; }
.viewer aside .meta { color: var(--muted); font-size: 12.5px; }

/* list views */
.list-wrap { max-width: 1100px; margin: 0 auto; padding: 20px 16px 60px; }
.list-wrap h2 { font: 600 24px var(--serif); margin: 0 0 12px; }
.filters { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; margin-bottom: 12px; }
.filters input { max-width: 320px; } .filters select { width: auto; }
table.people { width: 100%; border-collapse: separate; border-spacing: 0; background: var(--paper); border: 1px solid var(--line); border-radius: 10px; overflow: clip; font-size: 14px; font-variant-numeric: tabular-nums; }
table.people th, table.people td { text-align: left; padding: 8px 10px; border-bottom: 1px solid var(--line); vertical-align: top; }
table.people tbody tr:last-child td { border-bottom: 0; }
table.people th { background: var(--wash); font-weight: 600; font-size: 12.5px; color: var(--muted); white-space: nowrap; }
table.sortable th { padding: 0; position: sticky; top: 0; z-index: 1; }
.th-btn { display: flex; align-items: center; gap: 4px; width: 100%; padding: 8px 10px; border: 0; background: none; font: inherit; color: inherit; cursor: pointer; }
.th-btn:hover { color: var(--ink); } .th-btn:focus-visible { outline-offset: -2px; }
th[aria-sort] .th-btn { color: var(--ink); }
th[aria-sort=ascending] .th-btn::after { content: '↑'; } th[aria-sort=descending] .th-btn::after { content: '↓'; }
table.sortable tbody tr, .users-table tbody tr { cursor: pointer; }
table.sortable tbody tr:focus-visible, .users-table tbody tr:focus-visible { outline-offset: -2px; }
table.people tbody tr:hover td { background: var(--surface); }
table.sortable td:nth-child(3), table.sortable td:nth-child(4) { white-space: nowrap; }
.rec { list-style: none; margin: 0; padding: 0; background: var(--paper); border: 1px solid var(--line); border-radius: 10px; font-size: 14px; }
.rec li { display: grid; grid-template-columns: 9.5em minmax(5em, 10em) minmax(6em, 14em) 1fr; gap: 2px 12px; padding: 9px 12px; border-bottom: 1px solid var(--line); }
.rec li:last-child { border-bottom: 0; }
.rec .at { color: var(--muted); font-variant-numeric: tabular-nums; }
.rec .who-n { font-weight: 600; overflow-wrap: anywhere; } .rec .fld { color: var(--muted); }
.muted { color: var(--muted); }
/* keep the people list clear of an open card on wide screens */
@media (min-width: 761px) { body:has(.drawer.open) .list-wrap { padding-right: 476px; } }
.toast { position: fixed; left: 50%; bottom: calc(20px + env(safe-area-inset-bottom, 0px)); transform: translateX(-50%); width: max-content; max-width: calc(100vw - 32px); background: var(--ink); color: #fff; padding: 10px 16px; border-radius: 10px; z-index: 90; font-size: 14px; box-shadow: var(--shadow); }
@media (prefers-reduced-motion: reduce) {
  .drawer, .drawer.open { transition: visibility 0s; }
  .btn, .nav button, .chip, .doc, .tree-ctl button { transition: none; }
}

@media (max-width: 760px) {
  .brand { font-size: 17px; }
  .nav { display: none; }
  .legend { display: none; }
  .drawer { width: 100%; }
  .viewer { grid-template-columns: 1fr; grid-template-rows: 1fr auto; }
  .viewer aside { max-height: 35vh; border-left: 0; border-top: 1px solid var(--line); }
  .grid2 { grid-template-columns: 1fr; }
  .kv { grid-template-columns: 90px 1fr; }
  .hide-sm { display: none; }
  /* tree controls: one compact strip along the bottom instead of a tall stack */
  .tree-ctl { left: calc(8px + env(safe-area-inset-left, 0px)); right: calc(8px + env(safe-area-inset-right, 0px)); bottom: calc(8px + env(safe-area-inset-bottom, 0px)); flex-direction: row; flex-wrap: wrap; gap: 4px; }
  .tree-ctl .grp { flex: 1 1 auto; }
  .tree-ctl button { padding: 0 8px; min-width: 40px; min-height: 40px; flex: 1 1 auto; }
  .tree-ctl .lbl { font-size: 12px; padding: 0 2px 0 8px; white-space: nowrap; flex: 1 1 auto; }
  .tree-ctl .lbl.kin { padding: 0 10px; min-height: 40px; }
  .brand small { font-size: 10.5px; }
  /* iOS zooms the page when a focused field is under 16px */
  input[type=text], input[type=password], input[type=search], select, textarea { font-size: 16px; }
  .btn.sm { min-height: 38px; }
  .chip { min-height: 36px; }
  .modal-bg { padding: 8px; }
  .modal { max-height: calc(100vh - 16px); max-height: calc(100dvh - 16px); }
  .modal.wide { height: calc(100vh - 16px); height: calc(100dvh - 16px); }
  .modal header { padding: 10px 12px; gap: 6px; } .modal header h3 { font-size: 16px; }
  /* the viewer repeats the full title below the document; keep the document in view */
  .modal.wide header h3 { display: -webkit-box; -webkit-box-orient: vertical; -webkit-line-clamp: 2; overflow: hidden; }
  .list-wrap { padding: 16px 12px calc(40px + env(safe-area-inset-bottom, 0px)); }
  .filters input { max-width: none; flex: 1 1 100%; } .filters select { flex: 1 1 auto; }
  /* people list: each person becomes a two-line row instead of a table wider than the phone */
  table.sortable, table.sortable tbody { display: block; }
  table.sortable thead { display: block; position: sticky; top: 0; z-index: 1; }
  table.sortable thead tr { display: flex; background: var(--wash); border-bottom: 1px solid var(--line); }
  table.sortable th { position: static; flex: 1 1 auto; border: 0; }
  table.sortable th:nth-child(2) { order: -1; flex-grow: 3; }
  .th-btn { min-height: 40px; padding: 4px 8px; }
  table.sortable tbody tr { display: grid; grid-template-columns: auto auto 1fr auto; gap: 2px 12px; padding: 9px 12px; border-bottom: 1px solid var(--line); }
  table.sortable tbody tr:last-child { border-bottom: 0; }
  table.sortable td { display: block; padding: 0; border: 0; background: none !important; }
  table.sortable td:empty { display: none; }
  table.sortable td:nth-child(2) { grid-area: 1 / 1 / 2 / 4; font-weight: 500; }
  table.sortable td:nth-child(1) { grid-area: 1 / 4; text-align: right; font-size: 12.5px; }
  table.sortable td:nth-child(n+3) { grid-row: 2; font-size: 13px; color: var(--muted); }
  table.sortable td:nth-child(3):not(:empty)::before, table.sortable td:nth-child(4):not(:empty)::before, table.sortable td:nth-child(5):not(:empty)::before { content: attr(data-l) ' '; }
  table.sortable td:nth-child(5) { grid-column: 4; text-align: right; white-space: nowrap; }
  .rec li { grid-template-columns: 1fr auto; }
  .rec .who-n { grid-area: 1 / 1; } .rec .at { grid-area: 1 / 2; font-size: 12.5px; }
  .rec .fld { grid-area: 2 / 1 / 2 / 3; font-size: 13px; } .rec .per { grid-area: 3 / 1 / 3 / 3; }
}

/* timeline: decade scale on the left (tree and people views) */
.tl { position: fixed; top: var(--top-h); left: 0; bottom: 0; width: 144px; z-index: 6; display: none; flex-direction: column; gap: 8px;
  padding: 10px 10px calc(10px + env(safe-area-inset-bottom, 0px)) calc(10px + env(safe-area-inset-left, 0px)); background: var(--paper); border-right: 1px solid var(--line); }
body.tl-on .tl { display: flex; }
body.tl-on main { left: 144px; }
.tl-head { display: flex; align-items: center; gap: 4px; }
.tl-mode { display: flex; flex: 1; border: 1px solid var(--line); border-radius: 8px; overflow: hidden; }
.tl-mode button { flex: 1; border: 0; background: transparent; padding: 5px 4px; font-size: 12px; white-space: nowrap; cursor: pointer; color: var(--muted); }
.tl-mode button.on { background: var(--accent); color: var(--accent-ink); }
.tl-x { display: none; border: 0; background: transparent; padding: 6px; cursor: pointer; }
.tl-rng { font: 600 14px var(--serif); text-align: center; font-variant-numeric: tabular-nums; }
.tl-rng.muted { font: 11.5px/1.3 var(--sans); color: var(--muted); }
.tl-scale { flex: 1; min-height: 0; display: flex; flex-direction: column; cursor: ns-resize; touch-action: none; user-select: none; -webkit-user-select: none; border-radius: 6px; }
.tl-dec { flex: 1 1 0; min-height: 3px; position: relative; display: flex; align-items: center; padding-left: 44px; }
/* a continuous axis on the left of the bars, with a tick per decade, so empty decades still read as part of the scale */
.tl-dec::before { content: ''; position: absolute; left: 43px; top: 0; bottom: 0; border-left: 1px solid var(--line-strong); }
.tl-dec::after { content: ''; position: absolute; left: 39px; width: 4px; top: 0; border-top: 1px solid var(--line-strong); }
.tl-dec.half::after { left: 34px; width: 9px; }
.tl-dec.cent::after { left: 0; right: 0; width: auto; border-top-color: var(--line); }
.tl-lbl { position: absolute; left: 0; top: -1px; font: 10.5px/1.2 var(--sans); color: var(--muted); font-variant-numeric: tabular-nums; pointer-events: none; }
.tl-dec i { display: block; height: max(2px, 62%); background: var(--line-strong); border-radius: 0 2px 2px 0; }
.tl-dec.sel { background: var(--accent-soft); }
.tl-dec.sel i { background: var(--accent); }
.tl-cent { position: absolute; left: 0; top: -1px; border: 0; background: transparent; padding: 0 4px 0 0; font: 11px var(--sans); color: var(--muted); cursor: pointer; font-variant-numeric: tabular-nums; line-height: 1.2; }
.tl-cent:hover { color: var(--accent); text-decoration: underline; }
.tl-foot { font-size: 12px; display: grid; gap: 4px; }
.tl-foot .btn { justify-self: start; }
.node.dim { opacity: .22; }
.node.dim:hover, .node.dim:focus-visible { opacity: .7; }
.tl-toggle { display: none; align-items: center; gap: 6px; }
.filters .tl-toggle { border: 1px solid var(--field-edge); border-radius: 8px; background: var(--surface); padding: 8px 11px; cursor: pointer; }
body.tl-act .tl-toggle { color: var(--accent); font-weight: 600; }
@media (min-width: 761px) { .tree-ctl .tl-grp { display: none; } }
@media (max-width: 760px) {
  body.tl-on main { left: 0; }
  body.tl-on .tl { display: none; }
  body.tl-on.tl-open .tl { display: flex; width: min(220px, 70vw); box-shadow: var(--shadow); z-index: 30; }
  .tl-x { display: block; }
  .tl-dec { padding-left: 48px; }
  .tl-toggle { display: inline-flex; }
}

/* lifelines view */
.lv-wrap { padding: 16px 36px 60px 20px; }
.lv-top { display: flex; align-items: baseline; gap: 14px; flex-wrap: wrap; }
.lv-top h2 { font: 600 24px var(--serif); margin: 0; }
.lv-hint { font-size: 12.5px; margin: 6px 0 10px; display: flex; align-items: center; gap: 8px; }
.lv-key { width: 34px; height: 8px; border-radius: 4px; flex: none; background: linear-gradient(90deg, var(--accent) 60%, transparent); }
.lv-axis, .lv-row { display: grid; grid-template-columns: 240px 1fr; align-items: center; }
.lv-axis { position: sticky; top: 0; z-index: 2; background: var(--bg); border-bottom: 1px solid var(--line-strong); height: 26px; }
.lv-track { position: relative; height: 100%; }
.lv-tick { position: absolute; top: 5px; transform: translateX(-50%); font-size: 11px; color: var(--muted); font-variant-numeric: tabular-nums; white-space: nowrap; }
.lv-tick.cent { color: var(--ink); font-weight: 600; }
.lv-line h3 { font: 600 16px var(--serif); margin: 18px 0 4px; position: sticky; top: 26px; z-index: 1; background: var(--bg); padding: 4px 0; }
.lv-row { height: 22px; cursor: pointer; border-radius: 4px; }
.lv-row:hover { background: var(--wash); }
.lv-row:focus-visible { outline-offset: -2px; }
.lv-name { display: flex; gap: 8px; min-width: 0; padding-right: 10px; font-size: 12.5px; }
.lv-name .n { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.lv-name .y { color: var(--muted); font-size: 11.5px; white-space: nowrap; margin-left: auto; font-variant-numeric: tabular-nums; }
.lv-row .lv-track { height: 22px; }
.lv-bar { position: absolute; top: 6px; height: 10px; border-radius: 5px; min-width: 3px; background: var(--unknown-edge); }
.lv-bar.M { background: var(--male-edge); } .lv-bar.F { background: var(--female-edge); }
.lv-row.anc .lv-bar { background: var(--accent); }
.lv-row.anc .lv-name .n { font-weight: 600; color: var(--accent); }
.lv-row.me .lv-bar { background: var(--focus); }
@media (min-width: 761px) { body:has(.drawer.open) .lv-wrap { padding-right: 476px; } }
.lv-top .tl-toggle { border: 1px solid var(--field-edge); border-radius: 8px; background: var(--surface); padding: 6px 10px; cursor: pointer; }
@media (max-width: 760px) {
  .lv-wrap { padding: 12px 10px 40px; }
  .lv-axis, .lv-row { grid-template-columns: 128px 1fr; }
  .lv-name .y { display: none; }
  .lv-row { height: 30px; } .lv-row .lv-track { height: 30px; } .lv-bar { top: 10px; }
}

/* map */
.mp { display: flex; flex-direction: column; padding: 16px 20px 16px; overflow: hidden; }
.mp-top { display: flex; align-items: center; gap: 14px; flex-wrap: wrap; }
.mp-top h2 { font: 600 24px var(--serif); margin: 0; }
.mp-top select { width: auto; padding: 6px 10px; }
.mp-cb { display: inline-flex; align-items: center; gap: 4px; font-size: 14px; }
.mp-map { flex: 1; min-height: 320px; border: 1px solid var(--line-strong); border-radius: var(--r); overflow: hidden; }
.mp-map.leaflet-container { background: #d6e2e6; }
.mp-pop { font: 14px/1.4 var(--sans); color: var(--ink); }
.mp-pop b { font: 600 15px var(--serif); display: block; margin-bottom: 2px; }
.mp-pop ul { margin: 8px 0; padding: 0 0 0 16px; }
.mp-pop li { margin: 2px 0; }
.mp-approx { font-size: 12.5px; color: var(--warn-ink); background: var(--warn-bg); border-radius: 6px; padding: 4px 8px; margin: 6px 0; }
.mp-off { font-size: 13px; color: var(--muted); margin-top: 8px; max-height: 30vh; overflow: auto; }
.mp-off summary { cursor: pointer; }
.leaflet-container { font: 13px var(--sans); }
@media (max-width: 700px) { .mp { padding: 10px; } .mp-top { gap: 8px; } .mp-top h2 { font-size: 20px; } }

/* book */
.bk { position: absolute; inset: 0; display: flex; flex-direction: column; background: var(--bg); }
.bk-shelf-wrap { padding: 28px 24px 40px; max-width: 980px; margin: 0 auto; width: 100%; overflow: auto; }
.bk-shelf-wrap h2 { font: 600 26px/1.2 var(--serif); margin: 0 0 6px; }
.bk-intro { max-width: 640px; margin: 0 0 28px; }
.bk-shelf { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 22px; }
.bk-cover { aspect-ratio: 2 / 3; border: 0; border-radius: 3px 8px 8px 3px; padding: 22px 16px; cursor: pointer; text-align: left;
  display: flex; flex-direction: column; justify-content: space-between; color: #f3e9d2; background: var(--c);
  background-image: linear-gradient(90deg, rgba(0,0,0,.28) 0, rgba(0,0,0,.08) 9px, rgba(255,255,255,.08) 11px, transparent 18px);
  box-shadow: inset 0 0 0 1px rgba(255,255,255,.12), 0 2px 4px rgba(40,30,15,.18), 0 10px 24px rgba(40,30,15,.16);
  transition: transform .18s var(--ease), box-shadow .18s var(--ease); }
.bk-cover:hover:not(:disabled) { transform: translateY(-4px); box-shadow: inset 0 0 0 1px rgba(255,255,255,.12), 0 4px 8px rgba(40,30,15,.2), 0 18px 34px rgba(40,30,15,.2); }
.bk-cover-t { font: 600 19px/1.2 var(--serif); padding: 10px 0; border-top: 1px solid rgba(243,233,210,.5); border-bottom: 1px solid rgba(243,233,210,.5); }
.bk-cover-s { font-size: 12.5px; opacity: .85; }
.bk-cover.has-img { padding: 0; overflow: hidden; background: var(--c); }
.bk-cover.has-img img { display: block; width: 100%; height: 100%; object-fit: cover; }
.bk-cover.soon { cursor: default; opacity: .45; filter: saturate(.5); }

.bk-bar { display: flex; align-items: center; gap: 12px; padding: 8px 16px; border-bottom: 1px solid var(--line); background: var(--paper); flex: none; }
.bk-bar .btn { display: inline-flex; align-items: center; gap: 2px; }
.bk-bar-t { font: 600 16px/1.2 var(--serif); flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.bk-toc-sel { width: auto; max-width: 220px; padding: 5px 8px; font-size: 13px; }
.bk-count { font-size: 13px; white-space: nowrap; min-width: 70px; text-align: right; font-variant-numeric: tabular-nums; }
.bk-stage { flex: 1; min-height: 0; display: flex; align-items: center; justify-content: center; gap: 8px; position: relative; }
@media (min-width: 761px) { body:has(.drawer.open) .bk-stage { padding-right: 460px; } }
.bk-turn { width: 44px; height: 44px; border-radius: 50%; border: 1px solid var(--line); background: var(--paper); color: var(--ink); display: grid; place-items: center; cursor: pointer; flex: none; }
.bk-turn:disabled { opacity: .3; cursor: default; }
.bk-turn:hover:not(:disabled) { border-color: var(--accent); }
.bk-spread { position: relative; background: #fdfaf2; border-radius: 3px; flex: none;
  box-shadow: inset 4px 0 0 var(--c), 0 1px 2px rgba(60,45,20,.12), 0 12px 32px rgba(60,45,20,.14); }
.bk-spread.two { box-shadow: 0 1px 2px rgba(60,45,20,.12), 0 12px 32px rgba(60,45,20,.14); background: linear-gradient(90deg, #fdfaf2 0, #fdfaf2 calc(50% - 22px), #efe7d6 50%, #fdfaf2 calc(50% + 22px), #fdfaf2 100%); }
.bk-vp { position: absolute; overflow: hidden; }
.bk-flow { position: relative; column-fill: auto; transition: transform .38s var(--ease); font: 17px/1.62 var(--serif); color: var(--ink);
  hyphens: auto; -webkit-hyphens: auto; text-align: justify; orphans: 2; widows: 2; }
.bk-flow p { margin: 0; text-indent: 1.4em; }
.bk-flow h3 + p, .bk-flow header + p, .bk-flow blockquote + p, .bk-flow aside + p, .bk-flow .bk-doc + p { text-indent: 0; }
.bk-flow h3 { font: 600 18px/1.3 var(--serif); margin: 1.1em 0 .5em; text-align: left; break-after: avoid; hyphens: manual; }
.bk-flow blockquote { margin: .7em 0 .7em 1.2em; padding-left: .9em; border-left: 2px solid var(--line-strong); font-style: italic; color: #4a433b; text-align: left; }
.bk-p { color: inherit; text-decoration: underline; text-decoration-color: var(--line-strong); text-decoration-thickness: 1px; text-underline-offset: 3px; }
.bk-p:hover { color: var(--accent); text-decoration-color: var(--accent); }
.bk-n { font: 600 10.5px var(--sans); color: var(--muted); margin-left: 1px; }
.bk-ctx { display: block; margin: .9em 0; padding: 10px 12px; background: #f3ecdc; border-radius: 6px; font: 14px/1.5 var(--sans); text-align: left; break-inside: avoid; }
.bk-ctx-k { display: block; font-size: 11px; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); margin-bottom: 3px; }
.bk-doc { display: flex; gap: 10px; align-items: center; width: 100%; margin: .8em 0; padding: 9px 10px; border: 1px solid var(--line); border-radius: 7px; background: var(--surface); text-align: left; cursor: pointer; break-inside: avoid; font: 13px/1.35 var(--sans); }
.bk-doc:hover { border-color: var(--accent); }
.bk-doc-ic { flex: none; width: 34px; height: 42px; border-radius: 3px; display: grid; place-items: center; font: 600 10px var(--sans); color: #fff; background: var(--doc); }
.bk-doc-k { display: block; font-size: 10.5px; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); }
.bk-doc-t { display: block; }
.bk-front { break-after: column; height: var(--ph, 600px); display: flex; align-items: center; justify-content: center; }
.bk-front img { display: block; max-width: 100%; max-height: 100%; border-radius: 2px 5px 5px 2px; box-shadow: 0 2px 10px rgba(40,30,15,.25); }
.bk-title { break-after: column; text-align: center; padding-top: 22%; }
.bk-title-line { font: 12px var(--sans); text-transform: uppercase; letter-spacing: .14em; color: var(--muted); }
.bk-title h1 { font: 600 34px/1.15 var(--serif); margin: 18px 0 14px; text-align: center; }
.bk-sub { font-style: italic; margin: 0 0 40px; text-align: center; }
.bk-built { font: 12.5px var(--sans); text-align: center; }
.bk-toc-page { break-after: column; }
.bk-toc-page h2, .bk-notes h4 { font: 600 20px/1.2 var(--serif); margin: 0 0 18px; text-align: left; }
.bk-toc { list-style: none; padding: 0; margin: 0; text-align: left; }
.bk-toc li { margin: 0 0 12px; }
.bk-toc a { display: flex; gap: 8px; color: inherit; text-decoration: none; }
.bk-toc a span:first-child { flex: 1; }
.bk-toc a:hover { color: var(--accent); }
.bk-toc-n { font-variant-numeric: tabular-nums; color: var(--muted); }
.bk-ch { break-before: column; padding: 18% 0 6%; text-align: center; }
.bk-ch h2 { font: 600 25px/1.25 var(--serif); margin: 0 0 10px; hyphens: manual; }
.bk-period { font: 13px var(--sans); color: var(--muted); letter-spacing: .06em; }
.bk-notes { margin-top: 1.6em; font: 12.5px/1.45 var(--sans); text-align: left; color: #4a433b; hyphens: manual; }
.bk-notes h4 { font-size: 16px; margin-bottom: 10px; }
.bk-notes ol { margin: 0; padding-left: 2.2em; }
.bk-notes li { margin-bottom: 3px; }
.bk-notes a { color: inherit; text-decoration: underline; text-decoration-color: rgba(0,0,0,.3); text-underline-offset: 2px; }
.bk-end { text-align: center; font-size: 22px; padding-top: 1.4em; }
/* book design: one layout, a colour and a motif per book (book.accent, book.engraving, book.ornament) */
.bk-themed { --bk-paper: #FBF7EE; --bk-ink: #302A24; --bk-gold: #B48C4E; --bk-soft: #F3ECDD; --serif-book: "PT Serif", var(--serif);
  background: var(--bk-paper); box-shadow: 0 1px 2px rgba(60,45,20,.12), 0 12px 32px rgba(60,45,20,.14); }
.bk-themed.two { background: linear-gradient(90deg, var(--bk-paper) 0, var(--bk-paper) calc(50% - 26px), #EFE6D3 50%, var(--bk-paper) calc(50% + 26px), var(--bk-paper) 100%); }
.bk-themed .bk-flow { font-family: var(--serif-book); line-height: 1.56; color: var(--bk-ink); }
.bk-themed .bk-flow p { text-indent: 1.3em; }
.bk-themed .bk-flow h3 { font: 700 1.02em/1.3 var(--serif-book); color: var(--bk-acc); margin: 1.2em 0 .45em; }
.bk-themed .bk-p { color: var(--bk-acc); text-decoration-color: color-mix(in srgb, var(--bk-acc) 45%, transparent); }
.bk-themed .bk-p:hover { color: var(--bk-ink); text-decoration-color: var(--bk-acc); }
.bk-themed .bk-n { color: var(--bk-acc); font-family: var(--serif-book); font-weight: 700; }
.bk-themed .bk-flow blockquote { border-left-color: color-mix(in srgb, var(--bk-acc) 55%, transparent); color: #4a4036; }
.bk-themed .bk-ctx, .bk-themed .bk-doc { background: var(--bk-soft); border: 0; border-left: 3px solid var(--bk-acc); border-radius: 2px 6px 6px 2px; }
.bk-themed .bk-ctx { font: .8em/1.5 var(--serif-book); color: #3d352d; }
.bk-themed .bk-ctx-k, .bk-themed .bk-doc-k { color: var(--bk-acc); font-family: var(--sans); }
.bk-themed .bk-doc { font: .78em/1.4 var(--serif-book); color: var(--bk-ink); }
.bk-themed .bk-doc:hover { background: color-mix(in srgb, var(--bk-acc) 9%, var(--bk-soft)); }
.bk-themed .bk-doc-ic { background: var(--bk-acc); }
.bk-themed .bk-doc-t { color: var(--bk-acc); text-decoration: underline; text-decoration-color: color-mix(in srgb, var(--bk-acc) 40%, transparent); text-underline-offset: 3px; }
.bk-themed .bk-fig figcaption { font-family: var(--serif-book); font-size: .7em; color: #6b6055; }
/* gold rules with an ornament */
.bk-rule { display: flex; align-items: center; justify-content: center; gap: 14px; margin: 14px auto 0; width: 100%; text-indent: 0; }
.bk-rule::before, .bk-rule::after { content: ""; height: 1px; width: 22%; max-width: 110px; background: var(--bk-gold); }
.bk-rule img { display: block; height: 30px; width: auto; max-width: 55%; }
.bk-rule.sm img { height: 22px; }
.bk-rule-dot { width: 6px; height: 6px; transform: rotate(45deg); background: var(--bk-gold); }
/* title page */
.bk-themed .bk-title { position: relative; height: var(--ph, 600px); box-sizing: border-box; padding: 9% 8% 5%; display: flex; flex-direction: column; align-items: center;
  border: 1px solid var(--bk-gold); outline: 1px solid var(--bk-gold); outline-offset: -6px; text-align: center; break-inside: avoid; }
.bk-corner { position: absolute; width: 9px; height: 9px; transform: rotate(45deg); border: 1px solid var(--bk-gold); background: var(--bk-paper); }
.bk-corner.tl { top: 8px; left: 8px; } .bk-corner.tr { top: 8px; right: 8px; } .bk-corner.bl { bottom: 8px; left: 8px; } .bk-corner.br { bottom: 8px; right: 8px; }
.bk-themed .bk-title-line { font: 700 12px/1.3 var(--serif-book); letter-spacing: .3em; color: var(--bk-acc); text-transform: uppercase; }
.bk-themed .bk-title h1 { font: 400 min(46px, calc(var(--colw, 460px) * .095))/1.08 var(--serif-book); color: var(--bk-acc); margin: 20px 0 14px; hyphens: manual; -webkit-hyphens: manual; }
.bk-themed .bk-title h1 span { display: block; white-space: nowrap; }
.bk-themed .bk-sub { font: italic 1.02em/1.35 var(--serif-book); color: var(--bk-ink); margin: 0 0 4px; max-width: 26em; hyphens: manual; }
.bk-eng { flex: 1; min-height: 0; width: 100%; display: flex; align-items: center; justify-content: center; padding: 12px 0; }
.bk-eng img { display: block; max-width: 92%; max-height: 100%; object-fit: contain; }
.bk-themed .bk-built { font: italic 12.5px var(--serif-book); color: #7a6e60; margin: 0; }
.bk-themed .bk-flow .bk-title p { text-indent: 0; }
.bk-themed .bk-notes ol { padding-left: 2.9em; }
/* contents */
.bk-themed .bk-toc-page { padding-top: 6%; }
.bk-themed .bk-toc-page h2 { font: 400 2em/1.15 var(--serif-book); color: var(--bk-acc); text-align: center; margin: 0; }
.bk-themed .bk-toc { margin-top: 26px; font-size: .9em; line-height: 1.35; hyphens: manual; -webkit-hyphens: manual; }
.bk-themed .bk-toc li { margin: 0 0 .72em; break-inside: avoid; }
.bk-themed .bk-toc li.sub { margin: 0 0 .4em 1.4em; font-size: .9em; font-style: italic; }
.bk-themed .bk-toc a { display: flex; align-items: flex-end; gap: 0; }
.bk-themed .bk-toc a span.bk-toc-t { flex: 0 1 auto; text-align: left; min-width: 0; }
.bk-themed .bk-toc a span.bk-toc-dots { flex: 1 0 1.2em; margin: 0 .35em .28em; border-bottom: 2px dotted color-mix(in srgb, var(--bk-ink) 50%, transparent); }
.bk-themed .bk-toc-n { flex: none; color: var(--bk-ink); min-width: 1.6em; text-align: right; font-style: normal; }
.bk-themed .bk-toc a:hover .bk-toc-t { color: var(--bk-acc); }
/* chapter opening */
.bk-themed .bk-ch { padding: 7% 0 7%; }
.bk-ch-eng { display: block; margin: 0 auto 16px; max-height: calc(var(--ph, 600px) * .2); max-width: 62%; object-fit: contain; }
.bk-themed .bk-ch h2 { font: 400 1.75em/1.15 var(--serif-book); color: var(--bk-acc); margin: 0 0 8px; }
.bk-themed .bk-period { font: italic .82em var(--serif-book); color: #7a6e60; letter-spacing: .04em; }
.bk-themed .bk-ch .bk-rule { margin-top: 12px; }
.bk-themed .bk-flow p.bk-first { text-indent: 0; }
.bk-themed .bk-flow p.bk-first::first-letter { float: left; font: 400 3.35em/.82 var(--serif-book); color: var(--bk-acc); padding: .07em .08em 0 0; }
/* running header and page number */
.bk-pgs { position: absolute; inset: 0; pointer-events: none; }
.bk-pg-head { position: absolute; height: 26px; display: flex; align-items: flex-end; justify-content: center; border-bottom: 1px solid var(--bk-gold);
  font: 700 10.5px/1.2 var(--serif-book); letter-spacing: .18em; text-transform: uppercase; color: var(--bk-acc); padding-bottom: 5px; }
.bk-pg-head span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 100%; }
.bk-pg-foot { position: absolute; display: flex; align-items: center; justify-content: center; gap: 12px; font: 15px var(--serif-book); color: var(--bk-acc); font-variant-numeric: lining-nums; }
.bk-pg-foot img { height: 16px; width: auto; max-width: 70px; opacity: .9; }
.bk-pg-foot img.flip { transform: scaleX(-1); }
.bk-themed .bk-end { padding-top: 1.2em; }
@media (max-width: 760px) {
  .bk-bar { gap: 8px; padding: 6px 10px; }
  .bk-bar-t { display: none; }
  .bk-toc-sel { flex: 1; min-width: 0; max-width: none; }
  .bk-count { min-width: 0; }
  .bk-turn { display: none; }
  .bk-flow { font-size: 16.5px; line-height: 1.55; }
  .bk-shelf { grid-template-columns: repeat(2, 1fr); gap: 16px; }
  .bk-shelf-wrap { padding: 20px 16px 32px; }
}
@media (prefers-reduced-motion: reduce) { .bk-flow, .bk-cover { transition: none; } }
.bk-toc li.sub { margin: 0 0 6px 1.1em; font-size: 15px; }
.bk-toc li:not(.sub) { margin-top: 14px; font-weight: 600; }
.bk-toc li:first-child { margin-top: 0; }
.bk-fig { margin: .9em 0; break-inside: avoid; text-align: center; }
.bk-sketch { display: block; margin: 0 auto; max-width: 100%; max-height: calc(var(--ph, 600px) * .5); cursor: zoom-in;
  filter: grayscale(1) contrast(1.45) brightness(1.12) sepia(.35); mix-blend-mode: multiply; }
.bk-fig figcaption { font: italic 13px/1.4 var(--serif); color: var(--muted); margin-top: 6px; text-align: center; hyphens: manual; }
.bk-fig.cover { margin: 0 auto 18px; }
.bk-fig.cover .bk-sketch { max-height: calc(var(--ph, 600px) * .38); }
.bk-fig.cover figcaption { display: none; }
.bk-fig.drawn .bk-sketch { filter: none; cursor: default; }
.bk-fig.cover.drawn .bk-sketch { max-height: calc(var(--ph, 600px) * .45); border-radius: 2px; }
.bk-photo { cursor: zoom-in; }
.bk-ph { height: calc(var(--ph, 600px) * .46); display: flex; align-items: center; justify-content: center; }
.bk-ph img { max-width: 100%; max-height: 100%; box-shadow: 0 1px 4px rgba(0,0,0,.18); }
.bk-ph:empty { background: color-mix(in srgb, var(--muted) 8%, transparent); border-radius: 3px; }
.bk-ph-err { font-size: 13px; }
.bk-n { cursor: pointer; }
.bk-notes h4 { margin: 1.1em 0 .4em; font-size: 15px; break-after: avoid; }
.bk-notes h4:first-child { margin-top: 0; }
.bk-notes li { cursor: pointer; }
.bk-print { display: none; }
@media print {
  @page { size: A5; margin: 16mm 14mm 18mm; }
  html, body.printing { overflow: visible !important; height: auto !important; background: #fff; }
  body.printing > *:not(.bk-print) { display: none !important; }
  body.printing .bk-print { display: block; }
  .bk-print .bk-flow { column-width: auto !important; height: auto !important; transform: none !important; font-size: 11pt; line-height: 1.5; color: #000; }
  .bk-print .bk-front { break-after: page; height: auto; }
  .bk-print .bk-front img { max-height: 170mm; box-shadow: none; border-radius: 0; }
  .bk-print .bk-title { break-after: page; padding-top: 30%; }
  .bk-print .bk-toc-page { break-after: page; }
  .bk-print .bk-toc-n { display: none; }
  .bk-print .bk-ch { break-before: page; padding: 25% 0 8%; }
  .bk-print .bk-p { text-decoration: none; color: inherit; }
  .bk-print .bk-doc { border: 0; padding: 0; margin: .6em 0; }
  .bk-print .bk-doc-ic { display: none; }
  .bk-print .bk-sketch { max-height: 80mm; }
  .bk-print .bk-ph { height: 85mm; }
  .bk-print .bk-cover-img { max-height: 70mm; }
  .bk-print .bk-title { height: 168mm; break-after: page; padding-top: 10mm; }
  .bk-print .bk-front { height: 168mm; }
  .bk-print .bk-eng { flex: none; height: 72mm; }
  .bk-print .bk-eng img { max-height: 68mm; }
  .bk-print .bk-ch-eng { max-height: 32mm; }
  .bk-print .bk-toc-dots { border-bottom-color: #999; }
  .bk-print h3 { break-after: avoid; }
}
