/* ============================================================
   Bishop Jordan — The Prophetic Archive
   A nocturnal "scriptorium": midnight indigo, brass hairlines,
   a calligraphic serif, and an enumerated catalogue ledger.
   Single committed theme (no light/dark toggle).
   ============================================================ */

:root {
  --ink:        #0c0e1c;   /* page — deep midnight indigo            */
  --ink-1:      #11142780; /* raised row wash                        */
  --ink-2:      #171b34;   /* reading room / hover                   */
  --ink-3:      #1f2440;   /* pressed / active                       */

  --vellum:     #ece3d0;   /* primary text — warm ivory              */
  --vellum-2:   #c6bfab;   /* secondary                              */
  --vellum-3:   #928c79;   /* muted / captions                       */

  --gold:       #c8a45c;   /* brass accent — rules, numerals         */
  --gold-bright:#e6c886;   /* hover / emphasis                       */
  --gold-line:  rgba(200,164,92,0.26);
  --soft-line:  rgba(236,227,208,0.10);
  --mark:       rgba(230,200,134,0.28);

  --serif: "Iowan Old Style", "Palatino Linotype", Palatino, "Book Antiqua", "Hoefler Text", Georgia, serif;
  --mono:  ui-monospace, "SF Mono", "Cascadia Code", "JetBrains Mono", Menlo, Consolas, monospace;

  --measure: 60ch;
  --hall: 880px;
  color-scheme: dark;
}

* , *::before, *::after { box-sizing: border-box; }

html { scroll-behavior: smooth; }

body {
  margin: 0;
  min-height: 100vh;
  color: var(--vellum);
  background:
    radial-gradient(1200px 620px at 78% -8%, rgba(72,86,150,0.28), transparent 60%),
    radial-gradient(900px 520px at 8% 4%, rgba(120,84,150,0.14), transparent 55%),
    var(--ink);
  font-family: var(--serif);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}
button { font-family: inherit; color: inherit; }
a { color: inherit; }

/* ---------- starfield (astro-theology signature) ---------- */
.starfield {
  position: fixed; inset: 0; z-index: 0; pointer-events: none;
  overflow: hidden;
}
.starfield .star {
  position: absolute; width: 2px; height: 2px; border-radius: 50%;
  background: var(--vellum); opacity: 0.5;
}
.starfield .star.big { width: 3px; height: 3px; box-shadow: 0 0 6px rgba(236,227,208,0.6); }
.starfield .star.gold { background: var(--gold-bright); box-shadow: 0 0 7px rgba(230,200,134,0.7); }
@keyframes twinkle { 0%,100%{opacity:.2} 50%{opacity:.85} }
.starfield .tw { animation: twinkle 4.5s ease-in-out infinite; }

/* everything above the stars */
.masthead, .reading-hall, .reader { position: relative; z-index: 1; }

/* ---------- masthead ---------- */
.masthead {
  max-width: var(--hall);
  margin: 0 auto;
  padding: clamp(48px, 9vw, 104px) 24px clamp(28px, 5vw, 44px);
  text-align: center;
}
.mast-eyebrow {
  margin: 0 0 18px;
  font-family: var(--mono);
  font-size: 0.72rem; letter-spacing: 0.42em; text-transform: uppercase;
  color: var(--gold);
  padding-left: 0.42em;  /* balance the trailing letter-spacing */
}
.mast-title {
  margin: 0;
  font-weight: 500;
  font-size: clamp(2.9rem, 9vw, 5.4rem);
  line-height: 0.98;
  letter-spacing: -0.01em;
  color: var(--vellum);
}
.mast-title .amp { color: var(--gold); font-style: italic; }
.mast-rule {
  width: 62px; height: 1px; margin: 26px auto;
  background: linear-gradient(90deg, transparent, var(--gold), transparent);
}
.mast-sub {
  margin: 0 auto;
  max-width: 52ch;
  color: var(--vellum-2);
  font-size: clamp(1rem, 2.2vw, 1.16rem);
  line-height: 1.55;
  font-style: italic;
}
.mast-stats {
  display: flex; justify-content: center; gap: clamp(28px, 6vw, 64px);
  margin: 40px 0 0; padding: 0;
}
.mast-stats > div { text-align: center; }
.mast-stats dt {
  font-family: var(--mono); font-size: 0.64rem; letter-spacing: 0.24em;
  text-transform: uppercase; color: var(--vellum-3); margin-bottom: 7px;
}
.mast-stats dd {
  margin: 0; font-size: clamp(1.4rem, 3.4vw, 2rem); color: var(--gold);
  font-variant-numeric: tabular-nums;
}

/* ---------- reading hall (the library body) ---------- */
.reading-hall {
  max-width: var(--hall);
  margin: 0 auto;
  padding: 8px 24px 120px;
}

/* controls */
.controls {
  display: flex; align-items: center; gap: 18px; flex-wrap: wrap;
  padding-bottom: 22px;
  border-bottom: 1px solid var(--gold-line);
}
.search {
  flex: 1 1 320px; display: flex; align-items: center; gap: 11px;
  padding: 10px 4px; border-bottom: 1px solid var(--soft-line);
  transition: border-color 0.2s ease;
}
.search:focus-within { border-color: var(--gold); }
.search svg { width: 17px; height: 17px; color: var(--gold); flex: 0 0 auto; }
.search input {
  flex: 1; border: 0; background: none; outline: none;
  font-family: var(--serif); font-size: 1.12rem; color: var(--vellum);
}
.search input::placeholder { color: var(--vellum-3); font-style: italic; }

.modes { display: inline-flex; gap: 4px; flex: 0 0 auto; }
.modes button {
  border: 0; background: none; cursor: pointer;
  font-family: var(--mono); font-size: 0.7rem; letter-spacing: 0.18em;
  text-transform: uppercase; color: var(--vellum-3);
  padding: 8px 4px; position: relative; transition: color 0.18s ease;
}
.modes button + button { margin-left: 14px; }
.modes button::after {
  content: ""; position: absolute; left: 0; right: 0; bottom: 0; height: 1px;
  background: var(--gold); transform: scaleX(0); transform-origin: left;
  transition: transform 0.22s ease;
}
.modes button:hover { color: var(--vellum-2); }
.modes button.is-on { color: var(--gold); }
.modes button.is-on::after { transform: scaleX(1); }

/* ledger header */
.ledger-head {
  display: flex; align-items: baseline; gap: 14px;
  margin: 40px 0 6px;
}
.ledger-head h2 {
  margin: 0; font-weight: 500; font-size: 1.3rem; color: var(--vellum);
  letter-spacing: 0.01em;
}
.ledger-az {
  font-family: var(--mono); font-size: 0.66rem; letter-spacing: 0.22em;
  text-transform: uppercase; color: var(--gold);
}
.ledger-count {
  margin-left: auto; font-family: var(--mono); font-size: 0.72rem;
  color: var(--vellum-3); font-variant-numeric: tabular-nums;
}

/* ---------- the ledger (enumerated catalogue) ---------- */
.ledger { border-top: 1px solid var(--gold-line); }
.entry {
  display: grid;
  grid-template-columns: 46px 1fr auto;
  align-items: start;
  gap: 4px 16px;
  padding: 17px 10px 16px;
  border-bottom: 1px solid var(--soft-line);
  transition: background 0.16s ease;
  position: relative;
}
.entry::before {
  content: ""; position: absolute; left: 0; top: 0; bottom: -1px; width: 2px;
  background: var(--gold); transform: scaleY(0); transform-origin: top;
  transition: transform 0.2s ease;
}
.entry:hover { background: var(--ink-1); }
.entry:hover::before { transform: scaleY(1); }
.entry.is-open { background: var(--ink-2); }
.entry.is-open::before { transform: scaleY(1); }

.entry-idx {
  font-family: var(--mono); font-size: 0.82rem; color: var(--vellum-3);
  font-variant-numeric: tabular-nums; letter-spacing: 0.04em; padding-top: 3px;
}
.entry:hover .entry-idx, .entry.is-open .entry-idx { color: var(--gold); }

.entry-main { grid-column: 2; min-width: 0; }
.entry-open {
  border: 0; background: none; padding: 0; cursor: pointer; text-align: left;
  display: inline; max-width: 100%;
}
.entry-title {
  font-size: 1.24rem; line-height: 1.28; color: var(--vellum);
  transition: color 0.16s ease;
}
.entry-open:hover .entry-title { color: var(--gold-bright); }
.entry-meta {
  display: block; margin-top: 5px;
  font-family: var(--mono); font-size: 0.7rem; letter-spacing: 0.06em;
  color: var(--vellum-3); font-variant-numeric: tabular-nums;
}

.entry-actions {
  grid-column: 3; display: inline-flex; align-items: center; gap: 6px;
  padding-top: 2px;
}
.dl-chip {
  display: inline-flex; align-items: center; gap: 5px;
  font-family: var(--mono); font-size: 0.62rem; letter-spacing: 0.1em;
  text-transform: uppercase; text-decoration: none;
  color: var(--vellum-2);
  padding: 6px 9px; border: 1px solid var(--soft-line); border-radius: 2px;
  transition: border-color 0.16s ease, color 0.16s ease, background 0.16s ease;
}
.dl-chip svg { width: 12px; height: 12px; }
.dl-chip:hover { color: var(--gold-bright); border-color: var(--gold-line); background: var(--ink-1); }
.entry-read {
  border: 1px solid var(--gold-line); background: none; cursor: pointer;
  color: var(--gold); border-radius: 2px;
  font-family: var(--mono); font-size: 0.64rem; letter-spacing: 0.14em;
  text-transform: uppercase; padding: 7px 13px;
  transition: background 0.16s ease, color 0.16s ease;
}
.entry-read:hover { background: var(--gold); color: var(--ink); }

.empty {
  padding: 40px 10px; color: var(--vellum-3); font-style: italic; font-size: 1.05rem;
}
.loading {
  padding: 40px 10px; color: var(--gold); font-style: italic; font-size: 1.05rem;
  font-family: var(--serif);
}
.loading::after { content: " ✦"; }

/* ---------- full-text results ---------- */
.results-summary {
  margin: 4px 0 26px; color: var(--vellum-2); font-size: 1.05rem; font-style: italic;
}
.results-summary strong { color: var(--gold); font-style: normal; font-family: var(--mono);
  font-size: 0.95em; font-variant-numeric: tabular-nums; }
.result { border-top: 1px solid var(--soft-line); }
.result:first-child { border-top: 1px solid var(--gold-line); }
.result.is-open .result-title { color: var(--gold-bright); }
.result-head {
  display: grid; grid-template-columns: 46px 1fr auto; gap: 16px; align-items: start;
  padding: 18px 10px 12px;
}
.result-title {
  grid-column: 2; border: 0; background: none; cursor: pointer; text-align: left;
  font-family: var(--serif); font-size: 1.2rem; color: var(--vellum); padding: 0;
}
.result-title:hover { color: var(--gold-bright); }
.result-cat {
  display: block; margin-top: 4px; font-family: var(--mono); font-size: 0.64rem;
  letter-spacing: 0.16em; text-transform: uppercase; color: var(--vellum-3);
}
.result-count {
  grid-column: 3; font-family: var(--mono); font-size: 0.68rem; letter-spacing: 0.08em;
  color: var(--gold); white-space: nowrap; font-variant-numeric: tabular-nums;
}
.hits { padding: 0 10px 16px 56px; display: flex; flex-direction: column; gap: 2px; }
.hit {
  border: 0; background: none; cursor: pointer; text-align: left;
  padding: 10px 12px; border-radius: 3px; display: block;
  transition: background 0.14s ease;
}
.hit:hover { background: var(--ink-1); }
.hit-ch {
  display: block; font-family: var(--mono); font-size: 0.6rem; letter-spacing: 0.14em;
  text-transform: uppercase; color: var(--vellum-3); margin-bottom: 5px;
}
.hit-snip { display: block; color: var(--vellum-2); font-size: 0.98rem; line-height: 1.6; }
.hit-snip mark {
  background: var(--mark); color: var(--gold-bright); border-radius: 2px;
  padding: 0 2px; font-style: normal;
}
.hit-more { color: var(--vellum-3); font-style: italic; font-size: 0.86em; }
.hit-open { color: var(--gold); font-family: var(--mono); font-size: 0.68rem;
  letter-spacing: 0.1em; text-transform: uppercase; }
.hit-open:hover { background: var(--ink-1); }

/* ---------- reading room (centered overlay) ---------- */
.reader { position: fixed; inset: 0; z-index: 80; }
.reader-backdrop {
  position: absolute; inset: 0;
  background: rgba(5,6,14,0.72); backdrop-filter: blur(3px);
  animation: fade 0.24s ease;
}
@keyframes fade { from { opacity: 0; } to { opacity: 1; } }
.reader-room {
  position: absolute; top: 0; bottom: 0; right: 0;
  width: min(760px, 100%);
  display: flex; flex-direction: column;
  background:
    radial-gradient(700px 300px at 90% -6%, rgba(72,86,150,0.22), transparent 60%),
    var(--ink-2);
  border-left: 1px solid var(--gold-line);
  box-shadow: -30px 0 80px rgba(3,5,12,0.6);
  animation: slidein 0.3s cubic-bezier(.2,.7,.2,1);
}
@keyframes slidein { from { transform: translateX(40px); opacity: 0; } to { transform: none; opacity: 1; } }

.reader-bar {
  display: flex; align-items: flex-start; gap: 14px;
  padding: 22px 26px 16px; flex: 0 0 auto;
  border-bottom: 1px solid var(--soft-line);
}
.reader-id { flex: 1; min-width: 0; }
.reader-eyebrow {
  font-family: var(--mono); font-size: 0.62rem; letter-spacing: 0.24em;
  text-transform: uppercase; color: var(--gold); display: block; margin-bottom: 8px;
}
.reader-title {
  margin: 0; font-weight: 500; font-size: 1.55rem; line-height: 1.16; color: var(--vellum);
}
.reader-tools { display: flex; gap: 6px; flex: 0 0 auto; }
.reader-tools button {
  display: grid; place-items: center; min-width: 34px; height: 34px; padding: 0 8px;
  border: 1px solid var(--soft-line); border-radius: 3px; background: none;
  color: var(--vellum-2); cursor: pointer; font-family: var(--mono); font-size: 0.72rem;
  transition: border-color 0.16s ease, color 0.16s ease;
}
.reader-tools button svg { width: 16px; height: 16px; }
.reader-tools button:hover, .reader-tools button.is-on { border-color: var(--gold); color: var(--gold-bright); }

.reader-dl {
  display: flex; align-items: center; gap: 9px;
  padding: 13px 26px; flex: 0 0 auto;
  border-bottom: 1px solid var(--soft-line);
}
.reader-dl .dl-label {
  font-family: var(--mono); font-size: 0.6rem; letter-spacing: 0.2em;
  text-transform: uppercase; color: var(--vellum-3); margin-right: 3px;
}

.reader-toc {
  max-height: 44%; overflow: auto; flex: 0 0 auto;
  padding: 10px 16px; border-bottom: 1px solid var(--soft-line);
  background: rgba(8,10,22,0.5);
}
.toc-item {
  display: block; width: 100%; text-align: left; border: 0; background: none;
  cursor: pointer; color: var(--vellum-2); font-family: var(--serif);
  font-size: 0.95rem; padding: 7px 10px; border-radius: 3px;
  transition: background 0.14s ease, color 0.14s ease;
}
.toc-item:hover { background: var(--ink-1); color: var(--gold-bright); }
.toc-item.lvl2 { padding-left: 26px; font-size: 0.86rem; color: var(--vellum-3); }

.reader-scroll { flex: 1 1 auto; overflow: auto; padding: 34px 26px 80px; }
.prose {
  max-width: var(--measure); margin: 0 auto;
  font-size: calc(1.06rem * var(--reader-scale, 1));
  line-height: 1.72; color: #e7dfce;
}
.prose h3 {
  font-weight: 500; font-size: 1.4em; color: var(--vellum);
  margin: 1.9em 0 0.55em; line-height: 1.25;
}
.prose h3::before {
  content: ""; display: block; width: 34px; height: 1px;
  background: var(--gold); margin-bottom: 0.7em;
}
.prose h4 {
  font-family: var(--mono); font-weight: 500; font-size: 0.72em;
  letter-spacing: 0.16em; text-transform: uppercase; color: var(--gold);
  margin: 1.7em 0 0.5em;
}
.prose .chapter:first-child h3 { margin-top: 0; }
.prose .chapter:first-child h3::before { margin-top: 0; }
.prose p { margin: 0 0 1.05em; }
.colophon {
  margin-top: 2.8em; padding-top: 1.3em; border-top: 1px solid var(--gold-line);
  text-align: center; font-family: var(--mono); font-size: 0.66rem;
  letter-spacing: 0.16em; text-transform: uppercase; color: var(--vellum-3);
}
.colophon::before { content: "✦"; display: block; color: var(--gold); margin-bottom: 0.9em; font-size: 1.1em; }
.colophon-title { display: block; }
.colophon-lib {
  display: block; margin-top: 0.85em; color: var(--gold);
  letter-spacing: 0.2em;
}
.colophon-lib::before {
  content: ""; display: block; width: 26px; height: 1px; margin: 0 auto 0.85em;
  background: var(--gold-line);
}

/* ---------- responsive ---------- */
@media (max-width: 720px) {
  .entry { grid-template-columns: 34px 1fr; }
  .entry-idx { font-size: 0.74rem; }
  .entry-actions { grid-column: 1 / -1; grid-row: 2; padding-top: 14px; }
  .result-head { grid-template-columns: 34px 1fr; }
  .result-count { grid-column: 2; padding-top: 6px; }
  .hits { padding-left: 44px; }
  .reader-room { width: 100%; border-left: 0; }
  .mast-stats { gap: 26px; }
}

/* ---------- accessibility ---------- */
:focus-visible { outline: 2px solid var(--gold); outline-offset: 3px; border-radius: 2px; }
@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
  .starfield .tw { animation: none; }
  .reader-backdrop, .reader-room { animation: none; }
  * { transition: none !important; }
}
