:root {
  --reading-size: 22px;
  --line-height: 1.65;
  --max-width: 44rem;

  --bg: #fbfaf6;
  --bg-elev: #ffffff;
  --bg-box: #f1ede2;
  --bg-popover: #ffffff;
  --text: #1d1c1a;
  --text-muted: #66635c;
  --border: #d9d4c4;
  --rule: #ccc6b2;
  --accent: #9a5a1f;
  --bible-bg: #f7f1e2;
  --shadow: 0 8px 28px rgba(40, 30, 10, 0.18);
}

html[data-theme="dark"] {
  --bg: #16181c;
  --bg-elev: #1d1f24;
  --bg-box: #23262d;
  --bg-popover: #24272d;
  --text: #e7e3da;
  --text-muted: #9a948a;
  --border: #353841;
  --rule: #2c2f37;
  --accent: #d2a36b;
  --bible-bg: #1e2128;
  --shadow: 0 8px 28px rgba(0, 0, 0, 0.55);
}

* { box-sizing: border-box; }

html { background: var(--bg); color: var(--text); scroll-behavior: smooth; }
body {
  margin: 0;
  font-family: "Iowan Old Style", "Charter", "Source Serif Pro", Cambria, Georgia, serif;
  font-size: var(--reading-size);
  line-height: var(--line-height);
  -webkit-font-smoothing: antialiased;
  padding-bottom: 4rem;
}

.topbar {
  position: sticky; top: 0; z-index: 50;
  display: flex; align-items: center; gap: 0.75rem;
  padding: 0.6rem 1rem;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: saturate(140%) blur(10px);
  border-bottom: 1px solid var(--border);
  font-family: -apple-system, BlinkMacSystemFont, "Inter", sans-serif;
  font-size: 14px;
}
.topbar a.home {
  color: var(--text); text-decoration: none; font-weight: 600;
  padding: 4px 10px; border: 1px solid var(--border); border-radius: 8px;
}
.topbar a.home:hover { background: var(--bg-box); }
.topbar .title {
  flex: 1; font-weight: 600;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.topbar .controls { display: flex; gap: 6px; }
.btn {
  background: var(--bg-elev); color: var(--text);
  border: 1px solid var(--border); border-radius: 8px;
  padding: 4px 10px; font-size: 13px; cursor: pointer;
  font-family: inherit;
}
.btn:hover { background: var(--bg-box); }
.btn.icon { width: 32px; padding: 4px 0; text-align: center; font-weight: 600; }
a.btn.icon { display: inline-block; line-height: 1.5; text-decoration: none; }

main {
  max-width: var(--max-width);
  margin: 0 auto;
  padding: 2rem 1.25rem 5rem;
}

/* ---------- ESV passage block ---------- */
._Chapter-Subtitle, ._Chapter-Title {
  font-size: 1.8em; font-weight: 700;
  margin: 0.4em 0 0.7em;
  color: var(--text);
}
._Chapter-Subtitle a, ._Chapter-Title a { color: inherit; text-decoration: none; }

._Chapter-Book-Subtitle-Above {
  font-size: 0.9em; color: var(--text-muted);
  margin: 0; font-variant: small-caps; letter-spacing: 0.06em;
}
._Chapter-Book-Title {
  font-size: 2.6em; font-weight: 700;
  margin: 0 0 1em;
}
._Chapter-Author {
  font-style: italic; color: var(--text-muted); margin: -0.4em 0 1.5em;
}

._Bible_p, ._Bible_p-first {
  background: var(--bible-bg);
  border-left: 3px solid var(--accent);
  border-radius: 0 8px 8px 0;
  padding: 0.7em 1em;
  margin: 0.5em 0;
  font-size: 1em;
  line-height: 1.6;
}
._Bible_p-first { padding-top: 1.1em; }

._Bible_chapter-num {
  font-size: 1.8em;
  font-weight: 700;
  color: var(--accent);
  vertical-align: top;
  line-height: 0.85;
  margin-right: 0.05em;
}
._Bible_verse-num {
  font-size: 0.78em;
  font-weight: 700;
  color: var(--accent);
  vertical-align: super;
  line-height: 0;
}

/* Verse numbers that are clickable popover triggers get a clear affordance. */
._Bible_verse-num.studynote-ref,
._Bible_chapter-num.studynote-ref {
  cursor: pointer;
  padding: 0 4px;
  border-radius: 4px;
  background: color-mix(in srgb, var(--accent) 14%, transparent);
  border-bottom: none;
  transition: background 0.12s ease, transform 0.05s ease;
}
._Bible_verse-num.studynote-ref { font-size: 0.85em; padding: 1px 5px; }
._Bible_verse-num.studynote-ref:hover,
._Bible_chapter-num.studynote-ref:hover {
  background: color-mix(in srgb, var(--accent) 30%, transparent);
}
._Bible_verse-num.studynote-ref:active,
._Bible_chapter-num.studynote-ref:active { transform: translateY(1px); }
._Bible_verse-num.studynote-ref.is-active,
._Bible_chapter-num.studynote-ref.is-active {
  background: var(--accent);
  color: var(--bg);
}
._Bible_versethinspace, ._Bible_chapthinspace { white-space: pre; }

/* ESV translator notes: small superscript number in body, clickable */
._Bible_note {
  font-size: 0.65em;
  vertical-align: super;
  line-height: 0;
  color: var(--accent);
}
.esv-note-ref {
  cursor: pointer;
  border-bottom: 1px dotted var(--accent);
  padding-bottom: 1px;
}
.esv-note-ref:hover { color: color-mix(in srgb, var(--accent) 70%, white); }

/* Hide the per-passage trailing ESV notes block (we surface via popovers) */
p._Bible_note {
  display: none !important;
}

/* ---------- commentary structure headings ---------- */
._Heading-1, ._Heading-1-After-Bible-Text, ._Heading-1-Initial {
  font-size: 1.35em;
  font-weight: 700;
  margin: 2em 0 0.5em;
  color: var(--accent);
  border-top: 1px solid var(--rule);
  padding-top: 0.8em;
}
._Heading-1-Initial { border-top: none; padding-top: 0; }

._Heading-2 {
  font-size: 1.1em; font-weight: 700;
  margin: 1.4em 0 0.4em;
  font-variant: small-caps; letter-spacing: 0.04em;
}

._Outline-1-Roman-Num-Middle, ._Outline-1-Roman-Num {
  font-weight: 700; margin: 0.5em 0 0.1em;
  padding-left: 1em; text-indent: -1em;
}
._Outline-2-Middle, ._Outline-2 {
  margin: 0.1em 0 0.1em 1.8em;
  padding-left: 1.2em; text-indent: -1.2em;
  color: var(--text-muted);
}

._First, ._First-Space-Above, ._Normal {
  margin: 0 0 0.8em;
  text-align: justify;
  hyphens: auto;
}
._First-Space-Above { margin-top: 0.9em; }
._First { margin-top: 0.5em; }

._Bold { font-weight: 700; color: var(--text); }
._Italic { font-style: italic; }
._Small-caps { font-variant: small-caps; }

._Bullet-First, ._Bullet-Middle, ._Bullet-Last {
  margin: 0.1em 0;
}

ul {
  margin: 0.6em 0 1em;
  padding-left: 1.6em;
}

/* Outline TOC at top of the book page (Romans intro file) */
._Part-Toc-Chapter-Title {
  margin: 0.3em 0;
  font-size: 1.05em;
}
._Part-Toc-Chapter-Title a {
  color: var(--accent); text-decoration: none;
  border-bottom: 1px dotted var(--accent);
}
._Part-Toc-Chapter-Title a:hover { color: var(--text); }

/* Bibliography styling */
._Bibliography {
  text-indent: -1.5em; padding-left: 1.5em;
  margin: 0.4em 0;
  font-size: 0.95em;
}

/* Footnote refs (author notes) */
a.footnote-ref {
  color: var(--accent);
  cursor: pointer;
  text-decoration: none;
  border-bottom: 1px dotted var(--accent);
  font-size: 0.8em;
}
a.footnote-ref:hover { color: var(--text); }

/* In-text bible link styling */
a.bible {
  color: var(--accent);
  text-decoration: none;
  border-bottom: 1px solid transparent;
}
a.bible:hover { border-bottom-color: var(--accent); }

a { color: var(--accent); }

/* Hide the empty anchor spans */
a.anchor { display: none; }

/* ---------- popover ---------- */
#popover-host {
  position: fixed; inset: 0; pointer-events: none; z-index: 100;
}
.popover {
  position: absolute;
  max-width: min(38rem, 92vw);
  max-height: min(60vh, 32rem);
  overflow-y: auto;
  overscroll-behavior: contain;
  background: var(--bg-popover);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 12px;
  box-shadow: var(--shadow);
  padding: 14px 16px 12px;
  font-size: 0.95em;
  line-height: 1.55;
  pointer-events: auto;
  animation: pop-in 0.14s ease-out;
}
.popover .popover-head {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 8px;
  font-family: -apple-system, BlinkMacSystemFont, "Inter", sans-serif;
  font-size: 12px; color: var(--text-muted);
  text-transform: uppercase; letter-spacing: 0.06em; font-weight: 600;
}
.popover .popover-close {
  background: transparent; border: none; color: var(--text-muted);
  font-size: 20px; line-height: 1; cursor: pointer;
  padding: 0; width: 24px; height: 24px;
}
.popover .popover-close:hover { color: var(--text); }
.popover .popover-body p { text-align: left; margin: 0.4em 0; hyphens: none; }
.popover .popover-body p:first-child { margin-top: 0; }
.popover .popover-body p:last-child { margin-bottom: 0; }

@keyframes pop-in {
  from { opacity: 0; transform: translateY(4px) scale(0.98); }
  to   { opacity: 1; transform: none; }
}

/* ---------- index page ---------- */
.index-wrap { max-width: 48rem; margin: 0 auto; padding: 2.5rem 1.25rem; }
.index-wrap h1 { font-size: 2.2em; margin: 0 0 0.15em; }
.index-wrap .subtitle { color: var(--text-muted); margin: 0 0 2em; font-style: italic; }
.section-list { list-style: none; padding: 0; margin: 1em 0 2em; }
.section-list li { margin: 0; }
.section-list li a {
  display: flex; justify-content: space-between; gap: 1em;
  padding: 10px 12px; border-radius: 8px;
  color: var(--text); text-decoration: none;
  border-bottom: 1px solid var(--rule);
}
.section-list li a:hover { background: var(--bg-box); color: var(--accent); }
.section-list .kind {
  color: var(--text-muted); font-size: 0.85em; font-style: italic;
}

/* ---------- two-column ESV layout with sticky commentary side panel ---------- */
.esv-layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 24rem;
  gap: 1.5rem;
  max-width: 78rem;
  margin: 0 auto;
  padding: 1.5rem 1.25rem 5rem;
}
.esv-bible-area {
  min-width: 0;
}
.esv-bible-area > div,
.esv-bible-area > p,
.esv-bible-area > section {
  max-width: var(--max-width);
}

.esv-side {
  position: sticky;
  top: 4rem;
  align-self: start;
  max-height: calc(100vh - 5rem);
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: 12px;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  box-shadow: var(--shadow);
}
.esv-side-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 10px 14px;
  border-bottom: 1px solid var(--border);
  font-family: -apple-system, BlinkMacSystemFont, "Inter", sans-serif;
  font-size: 13px; font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase; letter-spacing: 0.06em;
}
.esv-side-title { color: var(--accent); }
.esv-side-close {
  background: transparent; border: none;
  color: var(--text-muted);
  font-size: 22px; line-height: 1;
  cursor: pointer; padding: 0; width: 26px; height: 26px;
}
.esv-side-close:hover { color: var(--text); }
.esv-side-body {
  padding: 14px 16px;
  overflow-y: auto;
  font-size: 0.96em;
  line-height: 1.55;
}
.esv-side-body p { margin: 0.5em 0; text-align: left; hyphens: none; }
.esv-side-body p:first-child { margin-top: 0; }
.esv-side-body a {
  color: var(--accent);
  text-decoration: none;
  border-bottom: 1px dotted var(--accent);
}
.esv-side-body a:hover { border-bottom-style: solid; }
.esv-side-empty {
  color: var(--text-muted);
  font-style: italic;
  text-align: center !important;
}

/* Collapsible side-sections (Section Overview / Outline / Response) */
details.esv-section {
  border: 1px solid var(--border);
  border-radius: 8px;
  margin: 1.2em 0;
  padding: 0;
  background: var(--bg-elev);
}
details.esv-section > summary {
  list-style: none;
  cursor: pointer;
  padding: 12px 16px;
  font-size: 1.05em;
  font-weight: 700;
  color: var(--accent);
  user-select: none;
}
details.esv-section > summary::-webkit-details-marker { display: none; }
details.esv-section > summary::before {
  content: '▸';
  display: inline-block;
  margin-right: 8px;
  transition: transform 0.12s ease;
  color: var(--text-muted);
}
details.esv-section[open] > summary::before { transform: rotate(90deg); }
details.esv-section[open] > summary { border-bottom: 1px solid var(--border); }
.esv-section-body {
  padding: 0.6em 16px 12px;
}
.esv-section-body p { text-align: justify; hyphens: auto; }

@media (max-width: 920px) {
  .esv-layout { grid-template-columns: 1fr; }
  .esv-side {
    position: static;
    max-height: none;
    display: none; /* on mobile we use popovers instead */
  }
}

@media (max-width: 640px) {
  .topbar { font-size: 12px; padding: 0.5rem 0.75rem; }
  .esv-layout { padding: 1rem 0.75rem 4rem; }
}
