/* Toledot — a scriptorium ledger: vellum, oak-gall ink, rubric red for what is selected, lapis for kin and events. */

:root {
  --vellum: #f2ecdf;
  --paper: #faf6ed;
  --canvas: #f7f2e7;
  --ink: #221c16;
  --ink-soft: #5f554a;
  --ink-faint: #8e8476;
  --rule: #e2d8c5;
  --rule-strong: #cfc2aa;
  --rubric: #a2301b;
  --rubric-wash: #a2301b14;
  --lapis: #2b4c84;
  --gold: #a9842b;
  --shadow: 0 1px 0 #0000000a, 0 12px 32px -18px #3a2a1466;
  --font-display: "Cormorant Garamond", "Iowan Old Style", "Palatino Linotype", Palatino, Georgia, serif;
  --font-ui: "Instrument Sans", "Segoe UI", system-ui, -apple-system, sans-serif;
  --font-orig: "SBL Hebrew", "Noto Serif Hebrew", "Noto Serif", "Gentium Plus", "Times New Roman", serif;
  --font-mono: ui-monospace, "Cascadia Mono", "SF Mono", Consolas, monospace;
  --radius: 3px;
  --masthead-h: 60px;
  --books-w: 264px;
  --panel-w: 400px;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --vellum: #14110d;
    --paper: #1b1813;
    --canvas: #17140f;
    --ink: #ece3d1;
    --ink-soft: #b5a993;
    --ink-faint: #7f7566;
    --rule: #2c2720;
    --rule-strong: #3d362c;
    --rubric: #e57b62;
    --rubric-wash: #e57b6218;
    --lapis: #93b3e8;
    --gold: #cfa850;
    --shadow: 0 1px 0 #ffffff08, 0 16px 40px -20px #000000cc;
    color-scheme: dark;
  }
}

:root[data-theme="dark"] {
  --vellum: #14110d;
  --paper: #1b1813;
  --canvas: #17140f;
  --ink: #ece3d1;
  --ink-soft: #b5a993;
  --ink-faint: #7f7566;
  --rule: #2c2720;
  --rule-strong: #3d362c;
  --rubric: #e57b62;
  --rubric-wash: #e57b6218;
  --lapis: #93b3e8;
  --gold: #cfa850;
  --shadow: 0 1px 0 #ffffff08, 0 16px 40px -20px #000000cc;
  color-scheme: dark;
}

*, *::before, *::after { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  background: var(--vellum);
  color: var(--ink);
  font: 400 14px/1.5 var(--font-ui);
  -webkit-font-smoothing: antialiased;
  overflow: hidden;
}
button, input, select { font: inherit; color: inherit; }
a { color: var(--lapis); text-underline-offset: 2px; }
svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 1.6; stroke-linecap: round; }
svg .fill { fill: currentColor; stroke: none; }
:focus-visible { outline: 2px solid var(--rubric); outline-offset: 2px; }

.sr-only {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}
.skip {
  position: absolute; left: 12px; top: -40px; z-index: 50; padding: 6px 12px;
  background: var(--ink); color: var(--paper); border-radius: var(--radius);
}
.skip:focus { top: 10px; }
.muted { color: var(--ink-soft); }
[hidden] { display: none !important; }

/* ---------------------------------------------------------------- masthead */
.masthead {
  height: var(--masthead-h);
  display: flex; align-items: center; gap: 18px;
  padding: 0 16px;
  background: var(--paper);
  border-bottom: 1px solid var(--rule-strong);
  position: relative; z-index: 10;
}
.brand {
  display: flex; align-items: baseline; gap: 1px;
  color: var(--ink); text-decoration: none; white-space: nowrap;
}
.brand-initial {
  font: italic 600 34px/1 var(--font-display); color: var(--rubric);
  margin-right: 1px; transform: translateY(3px);
}
.brand-word { font: 600 25px/1 var(--font-display); letter-spacing: 0.01em; }
.brand-sub {
  margin-left: 12px; font: italic 500 15px/1 var(--font-display); color: var(--ink-soft);
}

.search { position: relative; flex: 1; max-width: 440px; margin-left: auto; }
.search input {
  width: 100%; height: 36px; padding: 0 34px 0 34px;
  background: var(--canvas); border: 1px solid var(--rule-strong); border-radius: var(--radius);
}
.search input::placeholder { color: var(--ink-faint); }
.search input:focus { outline: none; border-color: var(--ink-soft); box-shadow: 0 0 0 3px var(--rubric-wash); }
.search-glyph { position: absolute; left: 10px; top: 9px; color: var(--ink-faint); }
.search-key {
  position: absolute; right: 9px; top: 8px; padding: 0 6px; border: 1px solid var(--rule-strong);
  border-radius: 3px; font: 500 11px/18px var(--font-mono); color: var(--ink-faint);
}
.search input:focus ~ .search-key { display: none; }
#search-results {
  position: absolute; top: 42px; left: 0; right: 0; margin: 0; padding: 4px 0; list-style: none;
  background: var(--paper); border: 1px solid var(--rule-strong); border-radius: var(--radius);
  box-shadow: var(--shadow); max-height: min(70vh, 520px); overflow: auto;
}
#search-results li { padding: 7px 12px; cursor: pointer; display: grid; grid-template-columns: 1fr auto; gap: 0 12px; }
#search-results li[aria-selected="true"], #search-results li:hover { background: var(--rubric-wash); }
#search-results .r-name { font-weight: 600; }
#search-results .r-years { color: var(--ink-soft); font-variant-numeric: tabular-nums; font-size: 12.5px; }
#search-results .r-desc { grid-column: 1 / -1; color: var(--ink-soft); font-size: 12.5px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
#search-results .r-empty { color: var(--ink-soft); cursor: default; display: block; }

.views { display: flex; gap: 2px; }
.views a {
  padding: 7px 10px; border-radius: var(--radius); color: var(--ink-soft); text-decoration: none; font-weight: 500;
}
.views a:hover { color: var(--ink); background: var(--rubric-wash); }
.journey-link { color: var(--rubric) !important; font-style: italic; }
.views a[aria-current="page"] { color: var(--ink); box-shadow: inset 0 -2px 0 var(--rubric); border-radius: 0; }

.icon-btn {
  width: 34px; height: 34px; display: inline-grid; place-items: center; flex: none;
  background: transparent; border: 1px solid transparent; border-radius: var(--radius); cursor: pointer; color: var(--ink-soft);
}
.icon-btn:hover { color: var(--ink); border-color: var(--rule-strong); background: var(--canvas); }
.icon-btn:active { transform: translateY(1px); }
.text-btn {
  background: none; border: 0; padding: 4px 6px; color: var(--lapis); cursor: pointer; font-weight: 500;
  text-decoration: underline; text-underline-offset: 3px; text-decoration-thickness: 1px;
}
.text-btn:hover { color: var(--rubric); }
.nav-toggle { display: none; }

/* ---------------------------------------------------------------- layout */
.layout {
  height: calc(100% - var(--masthead-h));
  display: grid;
  grid-template-columns: var(--books-w) minmax(0, 1fr) auto;
}
.main { position: relative; min-width: 0; display: flex; flex-direction: column; }

/* ---------------------------------------------------------------- books */
.books {
  background: var(--paper); border-right: 1px solid var(--rule-strong);
  display: flex; flex-direction: column; min-height: 0;
}
.filters { padding: 14px 16px 12px; border-bottom: 1px solid var(--rule); display: grid; gap: 10px; }
.field { display: grid; gap: 4px; }
.field > span { font-size: 11px; font-weight: 600; letter-spacing: 0.08em; text-transform: uppercase; color: var(--ink-soft); }
.field select {
  height: 32px; padding: 0 8px; background: var(--canvas); border: 1px solid var(--rule-strong); border-radius: var(--radius);
}
.check { display: flex; align-items: center; gap: 8px; cursor: pointer; }
.check input { accent-color: var(--rubric); width: 15px; height: 15px; margin: 0; }

.book-list { overflow-y: auto; padding: 4px 0 24px; flex: 1; overscroll-behavior: contain; }
.book-section > h2 {
  margin: 0; padding: 14px 16px 6px; position: sticky; top: 0; background: var(--paper); z-index: 1;
  font: italic 600 17px/1.2 var(--font-display); color: var(--rubric);
}
.book-btn {
  display: flex; width: 100%; align-items: baseline; justify-content: space-between; gap: 8px;
  padding: 4px 16px; background: none; border: 0; text-align: left; cursor: pointer; color: var(--ink);
}
.book-btn:hover { background: var(--rubric-wash); }
.book-btn[aria-pressed="true"] { background: var(--rubric-wash); box-shadow: inset 2px 0 0 var(--rubric); font-weight: 600; }
.book-btn.is-outside { color: var(--ink-faint); }
.book-btn .count { color: var(--ink-faint); font-size: 12px; font-variant-numeric: tabular-nums; font-weight: 400; }
.chapter-grid {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(38px, 1fr)); gap: 3px;
  padding: 6px 16px 12px;
}
.chapter-btn {
  min-height: 28px; padding: 2px 3px; background: var(--canvas); border: 1px solid var(--rule); border-radius: 2px;
  font-size: 12px; font-variant-numeric: tabular-nums; cursor: pointer; color: var(--ink);
}
.chapter-btn.is-wide { grid-column: span 2; }
.chapter-btn:hover { border-color: var(--ink-soft); }
.chapter-btn.is-empty { color: var(--ink-faint); border-style: dashed; }
.chapter-btn[aria-pressed="true"] { background: var(--rubric); border-color: var(--rubric); color: var(--paper); }

/* ---------------------------------------------------------------- focus bar, views */
.focusbar {
  display: flex; align-items: center; gap: 12px; padding: 7px 16px;
  background: var(--paper); border-bottom: 1px solid var(--rule);
}
.focus-label { font: 600 17px/1.2 var(--font-display); }
.focus-label .muted { font: 400 13px var(--font-ui); margin-left: 6px; }
.view { flex: 1; min-height: 0; position: relative; }
.view-timeline { overflow: hidden; }
#timeline { display: block; width: 100%; height: 100%; touch-action: none; cursor: grab; background: var(--canvas); }
#timeline.is-dragging { cursor: grabbing; }
#timeline:focus-visible { outline-offset: -3px; }

.zoom {
  position: absolute; right: 14px; bottom: 50px; display: grid; gap: 2px; padding: 3px;
  background: var(--paper); border: 1px solid var(--rule-strong); border-radius: var(--radius); box-shadow: var(--shadow);
}
.legend {
  position: absolute; left: 0; right: 0; bottom: 0; display: flex; flex-wrap: wrap; align-items: center; gap: 6px 18px;
  padding: 8px 16px; background: color-mix(in srgb, var(--paper) 92%, transparent); border-top: 1px solid var(--rule);
  font-size: 12px; color: var(--ink-soft);
}
.lg { display: inline-flex; align-items: center; gap: 7px; }
.lg i { display: inline-block; }
.lg-bar { width: 26px; height: 5px; background: var(--ink); }
.lg-dash { width: 26px; height: 0; border-top: 1.6px dashed var(--ink); position: relative; }
.lg-diamond { width: 8px; height: 8px; border: 1.4px solid var(--lapis); transform: rotate(45deg); }
.lg-diamond.is-filled { background: var(--lapis); }
.lg-hint { margin-left: auto; color: var(--ink-faint); }
.status { color: var(--ink-faint); font-variant-numeric: tabular-nums; }
.lg-hint + .status::before { content: "·"; margin-right: 8px; }

.empty-state {
  position: absolute; left: 50%; top: 45%; transform: translate(-50%, -50%); text-align: center;
  padding: 18px 24px; background: var(--paper); border: 1px solid var(--rule-strong); border-radius: var(--radius); box-shadow: var(--shadow);
}
.empty-state p { margin: 0 0 6px; font: italic 500 19px/1.3 var(--font-display); }
.loading-state {
  position: absolute; inset: 0; display: grid; place-content: center; justify-items: center; gap: 4px;
  background: var(--canvas); color: var(--ink-soft); text-align: center; padding: 24px;
}
.loading-initial { font: italic 600 72px/1 var(--font-display); color: var(--rubric); animation: breathe 1.6s ease-in-out infinite; }
.loading-state.is-error .loading-initial { animation: none; }
.loading-state code { font-family: var(--font-mono); background: var(--paper); padding: 2px 6px; border-radius: 3px; }
@keyframes breathe { 50% { opacity: 0.35; } }

.view-list, .view-parallels, .view-about { overflow-y: auto; padding: 22px 28px 60px; }
.list-head h2, .prose h2 { font: 600 30px/1.1 var(--font-display); margin: 0 0 4px; }
.list-head h2 .muted { font: 400 15px var(--font-ui); }
.list-head p { margin: 0 0 16px; max-width: 70ch; }
.people-table { width: 100%; border-collapse: collapse; font-size: 13.5px; }
.people-table th {
  text-align: left; font-size: 11px; font-weight: 600; letter-spacing: 0.08em; text-transform: uppercase; color: var(--ink-soft);
  padding: 8px 10px; border-bottom: 1px solid var(--rule-strong); position: sticky; top: -22px; background: var(--vellum);
}
.people-table td { padding: 7px 10px; border-bottom: 1px solid var(--rule); vertical-align: top; }
.people-table td:nth-child(2) { white-space: nowrap; font-variant-numeric: tabular-nums; }
.people-table td:nth-child(4) { color: var(--ink-soft); max-width: 44ch; }
.people-table tr:hover td { background: var(--rubric-wash); }
.more { margin: 16px 0; }

/* parallels */
.parallels-table { width: 100%; border-collapse: collapse; font-size: 13.5px; }
.parallels-table th {
  text-align: left; padding: 8px 10px; border-bottom: 1px solid var(--rule-strong);
  font: italic 600 17px var(--font-display); color: var(--rubric); position: sticky; top: -22px; background: var(--vellum);
}
.parallels-table th:first-child { color: var(--ink); }
.parallels-table td { padding: 8px 10px; border-bottom: 1px solid var(--rule); vertical-align: top; }
.parallels-table td.ref-cell { font-family: var(--font-mono); font-size: 12.5px; white-space: nowrap; }
.parallels-table td.is-empty { color: var(--ink-faint); }
.parallels-table tr:hover td { background: var(--rubric-wash); }

/* prose */
.prose { max-width: 72ch; }
.prose h3 { font: 600 21px/1.2 var(--font-display); margin: 28px 0 6px; color: var(--rubric); }
.prose p, .prose li { line-height: 1.65; }
.prose dl { display: grid; grid-template-columns: auto 1fr; gap: 6px 14px; }
.prose dt { font-weight: 600; }
.prose dd { margin: 0; color: var(--ink-soft); }
.source-list { padding-left: 18px; }
.source-list li { margin-bottom: 6px; }
.license { font-size: 11px; color: var(--ink-faint); text-transform: uppercase; letter-spacing: 0.06em; margin-left: 6px; }

/* ---------------------------------------------------------------- detail panel */
.panel {
  width: var(--panel-w); background: var(--paper); border-left: 1px solid var(--rule-strong);
  display: flex; flex-direction: column; min-height: 0; box-shadow: var(--shadow);
  animation: slide-in 220ms ease-out;
}
@keyframes slide-in { from { transform: translateX(18px); opacity: 0; } }
.panel-bar { display: flex; justify-content: flex-end; padding: 8px 8px 0; }
.panel-body { overflow-y: auto; padding: 0 24px 40px; overscroll-behavior: contain; }
.eyebrow { margin: 0; font-size: 11px; font-weight: 600; letter-spacing: 0.1em; text-transform: uppercase; color: var(--ink-faint); }
.detail-title { font: 600 34px/1.05 var(--font-display); margin: 2px 0 6px; outline: none; }
.detail-title::first-letter { color: var(--rubric); font-style: italic; }
.aliases { margin: 0 0 4px; color: var(--ink-soft); font-style: italic; }
.original { margin: 2px 0 8px; display: flex; flex-wrap: wrap; gap: 4px 14px; }
.orig { font: 400 22px/1.3 var(--font-orig); color: var(--ink); }
.description { margin: 6px 0 12px; font: italic 500 17px/1.4 var(--font-display); color: var(--ink-soft); }
.dates { margin: 10px 0; padding: 10px 12px; border: 1px solid var(--rule-strong); border-radius: var(--radius); background: var(--canvas); }
.dates.is-anchored { border-left: 4px solid var(--ink); }
.dates.is-estimate { border-left: 4px dashed var(--ink-faint); }
.dates-years { font: 600 20px/1.2 var(--font-display); font-variant-numeric: lining-nums; }
.dates-grade { font-size: 12.5px; color: var(--ink-soft); margin-top: 2px; }
.explanation { font-size: 13px; color: var(--ink-soft); margin: 8px 0 4px; }
.grade {
  display: inline-grid; place-items: center; min-width: 18px; height: 18px; padding: 0 4px; border-radius: 2px;
  font: 600 11px/1 var(--font-mono); border: 1px solid currentColor;
}
.grade-A, .grade-B { color: var(--ink); background: var(--rule); border-color: var(--ink); }
.grade-C, .grade-D { color: var(--lapis); }
.grade-E { color: var(--ink-faint); border-style: dashed; }
.panel-section { margin-top: 20px; }
.panel-section h3 {
  margin: 0 0 8px; padding-bottom: 4px; border-bottom: 1px solid var(--rule);
  font: italic 600 17px/1.2 var(--font-display); color: var(--rubric);
}
.panel-section h4 { margin: 10px 0 2px; font-size: 12px; font-weight: 600; color: var(--ink-soft); }
.relation { display: grid; grid-template-columns: 96px 1fr; gap: 8px; padding: 3px 0; }
.relation-label { color: var(--ink-soft); font-size: 12.5px; }
.person-link {
  background: none; border: 0; padding: 0; color: var(--lapis); cursor: pointer; font: inherit; text-align: left;
  text-decoration: underline; text-decoration-color: color-mix(in srgb, var(--lapis) 35%, transparent); text-underline-offset: 2px;
}
.person-link:hover { color: var(--rubric); text-decoration-color: currentColor; }
.claims, .participants { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; }
.claim { padding: 8px 10px; border: 1px solid var(--rule); border-radius: var(--radius); background: var(--canvas); }
.claim.ev-editorial_anchor, .claim.ev-editorial_inference { border-style: dashed; }
.claim-head { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; }
.claim-label { font-weight: 600; font-size: 13px; }
.claim-value { font: 600 17px/1.3 var(--font-display); }
.claim-meta { font-size: 12px; color: var(--ink-soft); }
.claim-cites summary { cursor: pointer; font-size: 12px; color: var(--ink-faint); margin-top: 2px; }
.note { font-size: 12.5px; color: var(--ink-soft); margin: 4px 0 0; }
.cites { list-style: none; margin: 4px 0 0; padding: 0; display: grid; gap: 3px; font-size: 12.5px; }
.ref { font-family: var(--font-mono); font-size: 12px; color: var(--ink); }
.tag { margin-left: 6px; font-size: 10.5px; text-transform: uppercase; letter-spacing: 0.06em; color: var(--ink-faint); }
.appear { display: grid; grid-template-columns: 104px 1fr; gap: 8px; padding: 3px 0; align-items: baseline; }
.appear-book { font-size: 12.5px; color: var(--ink-soft); }
.chips { display: flex; flex-wrap: wrap; gap: 3px; }
.chip {
  padding: 1px 6px; min-width: 24px; border: 1px solid var(--rule-strong); border-radius: 2px; background: var(--canvas);
  font: 500 11.5px/18px var(--font-ui); font-variant-numeric: tabular-nums; cursor: pointer; color: var(--ink);
}
.chip:hover { border-color: var(--rubric); color: var(--rubric); }
.parallel-mini { display: grid; grid-template-columns: repeat(4, 1fr); gap: 4px; }
.pm-col { display: grid; gap: 2px; align-content: start; padding: 6px; border: 1px solid var(--rule); border-radius: 2px; background: var(--canvas); }
.pm-col.is-empty { opacity: 0.5; }
.pm-gospel { font: italic 600 15px var(--font-display); color: var(--rubric); }
.loading { font-style: italic; }

/* ---------------------------------------------------------------- tooltip */
.tooltip {
  position: fixed; z-index: 40; max-width: 300px; padding: 8px 10px; pointer-events: none;
  background: var(--ink); color: var(--paper); border-radius: var(--radius); box-shadow: var(--shadow); font-size: 12.5px;
}
.tooltip strong { font: 600 16px/1.2 var(--font-display); display: block; }
.tooltip .t-meta { opacity: 0.75; font-variant-numeric: tabular-nums; }
.noscript { padding: 24px; }

/* ---------------------------------------------------------------- responsive */
@media (max-width: 1180px) {
  .brand-sub { display: none; }
  :root { --panel-w: 360px; }
}
@media (max-width: 900px) {
  :root { --masthead-h: 104px; }
  .masthead { flex-wrap: wrap; gap: 8px 10px; padding: 8px 12px; height: auto; min-height: var(--masthead-h); }
  .nav-toggle { display: inline-grid; }
  .search { order: 3; flex-basis: 100%; max-width: none; }
  .views { margin-left: auto; overflow-x: auto; }
  .views a { padding: 6px 7px; white-space: nowrap; }
  .layout { grid-template-columns: minmax(0, 1fr); }
  .books {
    position: fixed; top: var(--masthead-h); bottom: 0; left: 0; width: min(320px, 86vw); z-index: 20;
    transform: translateX(-102%); transition: transform 200ms ease-out; box-shadow: var(--shadow);
  }
  .books.is-open { transform: none; }
  .panel {
    position: fixed; left: 0; right: 0; bottom: 0; width: auto; max-height: 72vh; z-index: 30;
    border-left: 0; border-top: 1px solid var(--rule-strong); border-radius: 10px 10px 0 0;
    animation-name: sheet-in;
  }
  @keyframes sheet-in { from { transform: translateY(24px); opacity: 0; } }
  .panel-body { padding: 0 16px 32px; }
  .lg-hint { display: none; }
  .status { margin-left: auto; }
  .lg-hint + .status::before { content: none; }
  .legend { gap: 4px 12px; padding: 6px 12px; }
  .zoom { bottom: 64px; right: 10px; }
  .view-list, .view-parallels, .view-about { padding: 16px 16px 60px; }
  .people-table td:nth-child(4), .people-table th:nth-child(4), .people-table td:nth-child(5), .people-table th:nth-child(5) { display: none; }
  .parallels-table td.ref-cell { white-space: normal; }
}
@media (max-width: 520px) {
  .brand-word { font-size: 22px; }
  .parallel-mini { grid-template-columns: repeat(2, 1fr); }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}
