:root {
  --ink: #1d201c;
  --muted: #5c615a;
  --line: #dcdcd4;
  --panel: #f1f0ea;
  --paper: #ffffff;
  --accent: #1b5e3b;
  --accent-dark: #134a2e;
  --highlight: #b45309;
  --chip: #e8e7de;
  --danger: #9b2c2c;
  --radius: 8px;
  --radius-sm: 6px;
  --font-ui: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --font-name: Georgia, "Times New Roman", serif;
  --font-num: ui-monospace, "Cascadia Mono", Consolas, monospace;
}
* { box-sizing: border-box; }
/* Author display rules (flex/block) would otherwise override the UA [hidden]
   style and leave modals, the list view, and stacked canvases stuck visible. */
[hidden] { display: none !important; }
html, body { height: 100%; }
body {
  margin: 0; font-family: var(--font-ui); color: var(--ink);
  background: var(--paper); display: flex; flex-direction: column;
  overflow: hidden;
}

/* Top bar */
.topbar {
  display: flex; align-items: center; gap: 12px;
  padding: 8px 14px; border-bottom: 1px solid var(--line);
  background: var(--paper); flex-wrap: wrap;
}
.brand { display: flex; align-items: center; gap: 9px; }
.brand-name { font-family: var(--font-name); font-size: 19px; font-weight: bold; line-height: 1; }
.brand-sub { font-size: 11px; color: var(--muted); }
.top-actions { display: flex; gap: 8px; }
.btn {
  font: inherit; font-size: 13.5px; padding: 7px 13px;
  border: 1px solid var(--line); background: var(--paper);
  border-radius: var(--radius-sm); cursor: pointer; color: var(--ink);
  white-space: nowrap;
}
.btn:hover:not(:disabled) { border-color: var(--accent); color: var(--accent-dark); }
.btn:disabled { opacity: 0.45; cursor: default; }
.btn-primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn-primary:hover { background: var(--accent-dark); color: #fff; }
.btn-ghost { border-color: transparent; }
.btn-sm { padding: 4px 9px; font-size: 13px; }
.search-wrap { position: relative; flex: 1; min-width: 200px; max-width: 420px; display: flex; align-items: center; }
.search-wrap svg { position: absolute; left: 10px; }
.search-wrap input {
  width: 100%; font: inherit; font-size: 14px; padding: 8px 10px 8px 30px;
  border: 1px solid var(--line); border-radius: var(--radius-sm);
}
.search-wrap input:focus { outline: 2px solid var(--accent); outline-offset: -1px; }
.search-results {
  position: absolute; top: 105%; left: 0; right: 0; z-index: 50;
  background: #fff; border: 1px solid var(--line); border-radius: var(--radius-sm);
  box-shadow: 0 8px 24px rgba(0,0,0,.12); max-height: 320px; overflow: auto;
}
.search-results button {
  display: block; width: 100%; text-align: left; background: none; border: 0;
  padding: 8px 10px; font: inherit; font-size: 13.5px; cursor: pointer;
}
.search-results button:hover, .search-results button.active { background: var(--panel); }
.search-results .years { font-family: var(--font-num); font-size: 12px; color: var(--muted); margin-left: 8px; }
.stats-chip {
  font-size: 12.5px; background: var(--chip); border-radius: 20px;
  padding: 5px 12px; color: #33362f; font-family: var(--font-num);
}
.recent-chip { display: flex; align-items: center; gap: 6px; }
.recent-chip button {
  font-size: 12px; background: none; border: 1px solid var(--line); border-radius: 20px;
  padding: 4px 10px; color: #33362f; cursor: pointer; max-width: 170px;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.recent-chip button:hover { border-color: var(--accent); color: var(--accent); }

/* View bar */
.viewbar {
  display: flex; align-items: center; gap: 14px; padding: 6px 14px;
  border-bottom: 1px solid var(--line); background: var(--panel); flex-wrap: wrap;
}
.tabs { display: flex; gap: 4px; }
.tab {
  font: inherit; font-size: 13.5px; padding: 6px 14px; cursor: pointer;
  border: 1px solid transparent; background: transparent; border-radius: var(--radius-sm);
  color: var(--muted);
}
.tab:hover { color: var(--ink); }
.tab.active { background: #fff; border-color: var(--line); color: var(--ink); font-weight: 600; }
.nav-history { display: flex; align-items: center; gap: 4px; }
.root-chip {
  font-size: 13px; background: #fff; border: 1px solid var(--line);
  border-radius: 20px; padding: 4px 12px; cursor: pointer; max-width: 280px;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.root-chip:hover { border-color: var(--accent); }
.view-opts { margin-left: auto; display: flex; align-items: center; gap: 10px; font-size: 13px; color: var(--muted); }
.view-opts label { display: flex; align-items: center; gap: 6px; }
.view-opts select, .view-opts input[type="range"] { font: inherit; }

/* Layout */
.layout { flex: 1; display: flex; min-height: 0; position: relative; }
.stage { flex: 1; position: relative; min-width: 0; background: #fff; }
.view-canvas { position: absolute; inset: 0; width: 100%; height: 100%; display: block; cursor: grab; }
.tooltip {
  position: absolute; z-index: 40; pointer-events: none; max-width: 300px;
  background: #22251f; color: #fff; font-size: 13px; padding: 8px 11px;
  border-radius: var(--radius-sm); box-shadow: 0 6px 18px rgba(0,0,0,.25);
}
.tooltip .t-name { font-family: var(--font-name); font-size: 15px; }
.tooltip .t-years { font-family: var(--font-num); font-size: 12px; opacity: .85; }
.ctx-menu {
  position: fixed; z-index: 300; min-width: 170px;
  background: #fff; border: 1px solid var(--line); border-radius: var(--radius-sm);
  box-shadow: 0 8px 24px rgba(0,0,0,.14); padding: 4px;
}
.ctx-menu button {
  display: block; width: 100%; text-align: left; background: none; border: 0;
  padding: 8px 10px; font: inherit; font-size: 13.5px; cursor: pointer;
  border-radius: 4px;
}
.ctx-menu button:hover { background: var(--panel); }

/* Detail panel */
.detail {
  width: 330px; flex-shrink: 0; border-left: 1px solid var(--line);
  background: var(--paper); display: flex; flex-direction: column; min-height: 0;
}
.detail-head { display: flex; align-items: center; justify-content: space-between; padding: 10px 14px; border-bottom: 1px solid var(--line); }
.detail-head h2 { font-size: 13px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); margin: 0; }
.detail-body { padding: 14px; overflow: auto; font-size: 14px; }
.detail-body h3 { font-family: var(--font-name); font-size: 21px; margin: 0 0 2px; }
.detail-body .d-years { font-family: var(--font-num); font-size: 13px; color: var(--muted); }
.detail-body .d-place { font-size: 13px; color: var(--muted); margin: 2px 0 8px; }
.gallery { display: flex; flex-direction: column; gap: 8px; margin: 10px 0 4px; }
.gallery-main { width: 100%; max-height: 240px; object-fit: cover; object-position: top; border-radius: 6px; border: 1px solid var(--line); background: var(--panel); }
.gallery-thumbs img { object-fit: cover; object-position: top; }
.gallery-thumbs { display: flex; gap: 6px; flex-wrap: wrap; }
.gallery-thumbs img { width: 52px; height: 52px; object-fit: cover; border-radius: 6px; border: 1px solid var(--line); cursor: pointer; background: var(--panel); }
.gallery-cap { font-size: 12px; color: var(--muted); }
.gallery-missing { border: 1px dashed var(--line); border-radius: 6px; padding: 10px 12px; font-size: 13px; color: var(--muted); background: #fbfbfa; }
.gallery-missing .btn { margin-top: 8px; }
.photo-dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; background: var(--accent); }
.gallery-main { cursor: zoom-in; }
.lightbox {
  position: fixed; inset: 0; z-index: 320; background: rgba(20,22,18,.88);
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 10px; padding: 24px; cursor: zoom-out;
}
.lightbox img { max-width: 92vw; max-height: 84vh; object-fit: contain; border-radius: 8px; background: #000; }
.lightbox-cap { color: #eee; font-size: 13px; font-family: var(--font-num); }
.lightbox-close {
  position: absolute; top: 12px; right: 16px; font-size: 26px; line-height: 1;
  background: none; border: 0; color: #eee; cursor: pointer; padding: 6px 10px;
}
.d-section { margin-top: 14px; }
.d-section h4 { font-size: 12px; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); margin: 0 0 6px; }
.person-link {
  display: block; width: 100%; text-align: left; font: inherit; font-size: 13.5px;
  background: none; border: 0; border-bottom: 1px dotted var(--line);
  padding: 6px 2px; cursor: pointer; color: var(--ink);
}
.person-link:hover { color: var(--accent); border-bottom-color: var(--accent); }
.person-link.kin-parents { background: #e9f0e4; }
.person-link.kin-spouse { background: #f4e7e0; }
.person-link.kin-children { background: #e6edf4; }
.person-link .years { font-family: var(--font-num); font-size: 11.5px; color: var(--muted); margin-left: 6px; }
.d-actions { display: flex; gap: 8px; margin-top: 12px; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.detail-fab { position: absolute; right: 12px; bottom: 12px; z-index: 30; box-shadow: 0 4px 14px rgba(0,0,0,.2); }

/* List view */
.list-view { position: absolute; inset: 0; display: flex; flex-direction: column; background: #fff; }
.list-filters { display: flex; align-items: center; gap: 10px; padding: 10px 14px; border-bottom: 1px solid var(--line); flex-wrap: wrap; }
.list-filters input[type="search"] { font: inherit; font-size: 13.5px; padding: 6px 10px; border: 1px solid var(--line); border-radius: var(--radius-sm); min-width: 220px; }
.list-filters select { font: inherit; font-size: 13px; padding: 6px; border: 1px solid var(--line); border-radius: var(--radius-sm); }
.check { font-size: 13px; display: flex; align-items: center; gap: 5px; }
.list-count { margin-left: auto; font-size: 12.5px; color: var(--muted); font-family: var(--font-num); }
.list-table-wrap { flex: 1; overflow: auto; }
.list-table { width: 100%; border-collapse: collapse; font-size: 13.5px; }
.list-table th {
  position: sticky; top: 0; background: var(--panel); text-align: left;
  padding: 8px 12px; font-size: 12px; text-transform: uppercase; letter-spacing: .04em;
  color: var(--muted); cursor: pointer; user-select: none; z-index: 2;
}
.list-table td { padding: 7px 12px; border-bottom: 1px solid #eee; }
.list-table td.num, .list-table th.num { font-family: var(--font-num); font-size: 12.5px; }
.list-table tbody tr { cursor: pointer; }
.list-table tbody tr:hover { background: #f7f6f1; }
.list-table tbody tr.selected { background: #e9f1ea; }
.list-pager { display: flex; align-items: center; justify-content: center; gap: 14px; padding: 8px; border-top: 1px solid var(--line); font-size: 13px; }
#pageJump { width: 52px; font-size: 13px; padding: 3px 8px; border: 1px solid var(--line); border-radius: 6px; background: var(--panel); color: inherit; text-align: center; }
.d-lineage { font-size: 13px; margin: 6px 0; padding: 6px 8px; background: var(--chip); border-radius: 8px; overflow-x: auto; white-space: nowrap; }
.d-lineage .person-link { display: inline; width: auto; border: 0; padding: 0; font-size: 13px; }

/* Start overlay */
.start-overlay {
  position: absolute; inset: 0; z-index: 20; overflow: auto;
  background: #fff; display: flex; justify-content: center; padding: 40px 20px;
}
.drop-card { max-width: 620px; width: 100%; }
.drop-card h1 { font-family: var(--font-name); font-size: 34px; margin: 0 0 8px; font-weight: 700; }
.lede { font-size: 15.5px; color: var(--muted); line-height: 1.5; margin: 0 0 20px; }
.drop-zone {
  border: 2px dashed var(--line); border-radius: 12px; padding: 30px 24px;
  text-align: center; background: #fbfbfa;
}
.drop-zone.drag { border-color: var(--accent); background: #eef5ef; }
.drop-zone p { margin: 6px 0; }
.drop-btns { display: flex; gap: 10px; justify-content: center; margin: 12px 0; flex-wrap: wrap; }
.promises { list-style: none; padding: 0; margin: 22px 0 0; }
.promises li { padding: 9px 0 9px 28px; position: relative; font-size: 14px; border-bottom: 1px solid #f0efe8; }
.promises li::before { content: "›"; position: absolute; left: 8px; color: var(--accent); font-weight: bold; }
.promises strong { font-weight: 650; }

/* Status bar + modal */
.statusbar {
  display: flex; justify-content: space-between; gap: 10px;
  padding: 5px 14px; font-size: 12px; color: var(--muted);
  border-top: 1px solid var(--line); background: var(--panel);
  font-family: var(--font-num); white-space: nowrap; overflow: hidden;
}
.modal { position: fixed; inset: 0; z-index: 100; background: rgba(0,0,0,.4); display: flex; align-items: center; justify-content: center; }
.modal-card { background: #fff; border-radius: 12px; padding: 24px 28px; max-width: 480px; margin: 20px; }
.modal-card h2 { margin-top: 0; font-family: var(--font-name); }
.mini {
  position: fixed; z-index: 310; width: 330px; max-height: 72vh;
  display: flex; flex-direction: column; background: #fff;
  border: 1px solid var(--line); border-radius: 10px;
  box-shadow: 0 16px 48px rgba(0,0,0,.25);
}
.mini-head {
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  padding: 8px 6px 8px 12px; cursor: grab; border-bottom: 1px solid var(--line);
  font-weight: 600; font-size: 14px;
}
.mini-era { padding: 6px 12px 0; }
.mini-body { padding: 8px 12px 12px; overflow: auto; font-size: 13.5px; }
.mini-body p { margin: 8px 0; line-height: 1.45; }
.mini-map { width: 100%; height: 170px; border: 1px solid var(--line); border-radius: 6px; }
.mini-thumb { max-width: 130px; border-radius: 6px; border: 1px solid var(--line); }
.mini-desc { font-size: 12.5px; color: var(--muted); margin: 2px 0 6px; }
.title-place, .place-link {
  background: none; border: 0; padding: 0; font: inherit; cursor: pointer;
  color: var(--accent-dark); text-decoration: underline dotted;
}
.title-place:hover, .place-link:hover { color: var(--accent); }
.title-name {
  background: none; border: 0; padding: 0; font: inherit; cursor: pointer;
  color: inherit; text-align: left;
}
.title-name:hover { text-decoration: underline dotted; }
.dev-drawer {
  position: fixed; left: 12px; bottom: 40px; z-index: 300; width: 300px;
  background: #fff; border: 1px solid var(--line); border-radius: 10px;
  box-shadow: 0 16px 48px rgba(0,0,0,.25); padding: 10px 12px 12px;
  display: flex; flex-direction: column; gap: 8px; max-height: 70vh; overflow: auto;
}
.dev-head { display: flex; align-items: center; justify-content: space-between; }
.dev-grid { display: grid; grid-template-columns: 74px 1fr; gap: 6px; align-items: center; font-size: 13px; }
.dev-grid input, .dev-grid select, .dev-grid textarea { font: inherit; padding: 4px 6px; border: 1px solid var(--line); border-radius: 4px; width: 100%; box-sizing: border-box; }
.dev-grid textarea { resize: vertical; min-height: 56px; }
.d-edit { margin-top: 10px; padding-top: 8px; border-top: 1px solid var(--line); }
.dev-row { display: flex; gap: 8px; margin-top: 8px; flex-wrap: wrap; align-items: center; }
.edited-tag { font-size: 11px; color: var(--accent-dark); border: 1px solid var(--accent); border-radius: 4px; padding: 0 5px; margin-left: 8px; vertical-align: middle; }
.d-marks { display: flex; gap: 6px; flex-wrap: wrap; margin: 4px 0 2px; }
.mark-chip { font-size: 11px; border: 1px solid var(--line); background: var(--chip); border-radius: 10px; padding: 1px 8px; white-space: nowrap; }
.mark-disp { border-color: #b3261e; color: #b3261e; }
.mark-pos { border-color: #9a6a00; color: #7a5500; }
.mark-inter { border-color: #274e7d; color: #274e7d; }
.mark-type { border-color: var(--muted); color: var(--muted); }
.dev-marks { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; margin-top: 8px; font-size: 13px; }
.d-lookup { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; margin: 6px 0 2px; font-size: 13px; }
.modal-card li { margin: 8px 0; font-size: 14px; line-height: 1.45; }
kbd { background: var(--chip); border: 1px solid var(--line); border-radius: 4px; padding: 1px 6px; font-size: 12px; font-family: var(--font-num); }

@media (max-width: 900px) {
  .detail { position: absolute; right: 0; top: 0; bottom: 0; z-index: 30; box-shadow: -8px 0 24px rgba(0,0,0,.12); }
  .search-wrap { order: 5; max-width: none; flex-basis: 100%; }
}
@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; animation: none !important; }
}
