: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; }

/* ESV-style two-column layout */
main.esv-layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 28rem;
  gap: 1.5rem;
  max-width: 84rem;
  margin: 0 auto;
  padding: 1.5rem 1.25rem 5rem;
}
.esv-bible-area { min-width: 0; }
.esv-bible-area > * { max-width: var(--max-width); margin-left: auto; margin-right: auto; }
.esv-bible-area p { margin: 0.7em 0; text-align: left; }
.esv-bible-area a:not(.dagger):not(.fnref):not(.crossref-trig) {
  color: var(--accent);
  text-decoration: none;
  border-bottom: 1px dotted var(--accent);
}

.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: 16px 18px;
  overflow-y: auto;
  font-size: 0.94em;
  line-height: 1.55;
}
.esv-side-body p { margin: 0.5em 0; text-align: left; }
.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;
}

/* Bible-text typography */
.esv-bible-area .verse-num {
  display: inline-block;
  font-family: -apple-system, BlinkMacSystemFont, "Inter", sans-serif;
  font-size: 0.65em;
  font-weight: 700;
  vertical-align: super;
  line-height: 1;
  color: var(--text-muted);
  margin: 0 2px 0 1px;
  padding: 1px 3px;
}
.esv-bible-area .chapter-num {
  font-size: 2.4em;
  font-weight: 700;
  float: left;
  margin: 0.05em 0.15em 0 0;
  line-height: 0.95;
  color: var(--accent);
}
.esv-bible-area .book-name {
  font-family: -apple-system, BlinkMacSystemFont, "Inter", sans-serif;
  font-size: 0.75em;
  font-variant: small-caps;
  letter-spacing: 0.08em;
  color: var(--text-muted);
  display: block;
  margin-bottom: 0.3em;
}
.esv-bible-area .book-name a {
  color: inherit;
  border-bottom: none;
}

/* Study-note triggers */
.esv-bible-area .verse-num[data-note-id] {
  background: color-mix(in srgb, var(--accent) 14%, transparent);
  border: 1px solid color-mix(in srgb, var(--accent) 40%, transparent);
  border-radius: 4px;
  color: var(--accent);
  cursor: pointer;
  padding: 2px 5px;
  margin: 0 2px 0 1px;
  -webkit-user-select: none;
  user-select: none;
  transition: background 0.12s, color 0.12s;
}
.esv-bible-area .verse-num[data-note-id]:hover {
  background: var(--accent);
  color: var(--bg);
}
.esv-bible-area .verse-num[data-note-id].is-active {
  background: var(--accent);
  color: var(--bg);
  box-shadow: 0 0 0 2px color-mix(in srgb, var(--accent) 30%, transparent);
}
.esv-bible-area .chapter-num[data-note-id] { cursor: pointer; }
.esv-bible-area .chapter-num[data-note-id]:hover {
  color: color-mix(in srgb, var(--accent) 75%, white);
}
.esv-bible-area .chapter-num[data-note-id].is-active {
  text-shadow: 0 0 0 2px var(--accent);
  color: color-mix(in srgb, var(--accent) 75%, white);
}

/* Dagger / passage-note marker */
.esv-bible-area .dagger {
  display: inline-block;
  font-family: -apple-system, BlinkMacSystemFont, "Inter", sans-serif;
  font-size: 0.78em;
  font-weight: 700;
  vertical-align: super;
  line-height: 1;
  color: var(--accent);
  background: color-mix(in srgb, var(--accent) 14%, transparent);
  border: 1px solid color-mix(in srgb, var(--accent) 40%, transparent);
  border-radius: 4px;
  padding: 1px 4px;
  margin: 0 2px;
  cursor: pointer;
  text-decoration: none;
  -webkit-user-select: none;
  user-select: none;
}
.esv-bible-area .dagger:hover { background: var(--accent); color: var(--bg); }
.esv-bible-area .dagger.is-active {
  background: var(--accent); color: var(--bg);
  box-shadow: 0 0 0 2px color-mix(in srgb, var(--accent) 30%, transparent);
}

/* Footnote chips */
.esv-bible-area .fnref, .esv-side-body .fnref {
  display: inline-block;
  font-family: -apple-system, BlinkMacSystemFont, "Inter", sans-serif;
  font-size: 0.65em;
  font-weight: 700;
  vertical-align: super;
  line-height: 1;
  color: var(--accent);
  background: color-mix(in srgb, var(--accent) 14%, transparent);
  border: 1px solid color-mix(in srgb, var(--accent) 40%, transparent);
  border-radius: 3px;
  padding: 1px 4px;
  margin: 0 1px;
  cursor: pointer;
  text-decoration: none;
}
.esv-bible-area .fnref:hover, .esv-side-body .fnref:hover {
  background: var(--accent); color: var(--bg);
}

/* Cross-reference letter triggers */
.esv-bible-area .crossref-trig {
  display: inline-block;
  font-family: -apple-system, BlinkMacSystemFont, "Inter", sans-serif;
  font-size: 0.65em;
  font-weight: 600;
  vertical-align: super;
  line-height: 1;
  color: var(--text-muted);
  margin: 0 1px;
  cursor: pointer;
  text-decoration: none;
  font-style: italic;
}
.esv-bible-area .crossref-trig:hover { color: var(--accent); }

/* History of Salvation [^] popover triggers */
.esv-bible-area .hsref, .esv-side-body .hsref {
  display: inline-block;
  font-family: -apple-system, BlinkMacSystemFont, "Inter", sans-serif;
  font-size: 0.65em;
  font-weight: 700;
  vertical-align: super;
  line-height: 1;
  color: var(--accent);
  background: color-mix(in srgb, var(--accent) 10%, transparent);
  border: 1px dashed color-mix(in srgb, var(--accent) 40%, transparent);
  border-radius: 3px;
  padding: 1px 4px;
  margin: 0 1px;
  cursor: pointer;
  text-decoration: none;
}
.esv-bible-area .hsref:hover, .esv-side-body .hsref:hover {
  background: var(--accent); color: var(--bg);
}

/* Section heading inside bible text */
.esv-bible-area .heading {
  font-family: -apple-system, BlinkMacSystemFont, "Inter", sans-serif;
  font-weight: 700;
  font-size: 1.1em;
  margin: 1.5em 0 0.5em;
  color: var(--text);
}
.esv-bible-area .no-indent { text-indent: 0; }
.esv-bible-area .indent { text-indent: 1.5em; }

/* Footnote popover */
.fn-popover {
  position: fixed;
  z-index: 200;
  max-width: min(440px, 90vw);
  background: var(--bg-popover);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 14px 16px;
  box-shadow: var(--shadow);
  font-size: 0.92em;
  line-height: 1.45;
}
.fn-popover .fn-num {
  font-family: -apple-system, BlinkMacSystemFont, "Inter", sans-serif;
  font-size: 0.78em;
  font-weight: 700;
  color: var(--accent);
  letter-spacing: 0.04em;
  text-transform: uppercase;
  margin-bottom: 6px;
}
.fn-popover .fn-close {
  position: absolute;
  top: 6px; right: 8px;
  background: transparent; border: none;
  color: var(--text-muted);
  font-size: 18px; cursor: pointer;
  padding: 2px 6px; line-height: 1;
}
.fn-popover .fn-close:hover { color: var(--text); }
.fn-popover .fn-body a {
  color: var(--accent);
  text-decoration: none;
  border-bottom: 1px dotted var(--accent);
}
.fn-popover .fn-body a:hover {
  color: color-mix(in srgb, var(--accent) 75%, white);
  border-bottom-style: solid;
}

/* Study-note typography in side panel */
.esv-side-body .study-note strong:first-child { color: var(--accent); }
.esv-side-body .study-note { margin: 0.6em 0; }
.esv-side-body .outline-2,
.esv-side-body .outline-3 {
  display: block;
  color: var(--accent);
  font-weight: 700;
  margin: 0.6em 0 0.3em;
}

@media (max-width: 1000px) {
  main.esv-layout { grid-template-columns: 1fr; }
  .esv-side {
    position: static;
    max-height: none;
    margin-top: 1.5rem;
  }
}
@media (max-width: 640px) {
  .topbar { font-size: 12px; padding: 0.5rem 0.75rem; }
  main.esv-layout { padding: 1rem; }
}

/* Book + chapter index pages */
.index-wrap { max-width: 50rem; 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); font-style: italic; margin: 0 0 2em; }
.index-wrap h2.section-head {
  font-size: 1em;
  font-variant: small-caps;
  letter-spacing: 0.1em;
  color: var(--accent);
  margin: 2em 0 0.5em;
  padding-bottom: 6px;
  border-bottom: 1px solid var(--border);
  font-family: -apple-system, BlinkMacSystemFont, "Inter", sans-serif;
}
.index-wrap a { color: var(--accent); text-decoration: none; }
.chapter-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(3.5rem, 1fr));
  gap: 0.5rem;
  margin: 1em 0 2em;
}
.chapter-grid a {
  text-align: center;
  padding: 10px 6px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--bg-elev);
  font-family: -apple-system, BlinkMacSystemFont, "Inter", sans-serif;
  font-size: 14px;
  font-weight: 600;
}
.chapter-grid a:hover { background: var(--bg-box); border-color: var(--accent); }
.book-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(min(100%, 10rem), 1fr));
  gap: 0.6rem;
  margin: 1em 0 2em;
}
.book-grid a {
  display: block;
  padding: 10px 14px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--bg-elev);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Inter", sans-serif;
  font-size: 14px;
  font-weight: 600;
}
.book-grid a:hover { background: var(--bg-box); border-color: var(--accent); color: var(--accent); }
