/* Dark is the default theme. The build ships <html data-theme="dark">, and a
   small inline script in the page <head> may switch it to "light" based on a
   saved choice or the OS preference before first paint. */
:root {
  --bg: #1a1b1e;
  --bg-sidebar: #202124;
  --bg-code: #26282c;
  --text: #e4e4e7;
  --text-dim: #9a9ba1;
  --border: #33353a;
  --accent: #7aa2f7;
  --accent-bg: #2a3550;
  --shadow: rgba(0, 0, 0, 0.4);
}

:root[data-theme='light'] {
  --bg: #ffffff;
  --bg-sidebar: #f5f6f8;
  --bg-code: #eef0f3;
  --text: #1f2328;
  --text-dim: #5b6673;
  --border: #d9dce1;
  --accent: #2f5fd0;
  --accent-bg: #e2ebfb;
  --shadow: rgba(0, 0, 0, 0.15);
}

html {
  color-scheme: dark;
}
:root[data-theme='light'] {
  color-scheme: light;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family:
    -apple-system, BlinkMacSystemFont, 'Segoe UI', Helvetica, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.6;
}

.layout {
  display: flex;
  min-height: 100vh;
}

.sidebar {
  width: 300px;
  flex-shrink: 0;
  background: var(--bg-sidebar);
  border-right: 1px solid var(--border);
  padding: 1rem;
  overflow-y: auto;
  max-height: 100vh;
  position: sticky;
  top: 0;
}

.site-title {
  display: block;
  font-weight: 700;
  font-size: 1.1rem;
  color: var(--text);
  text-decoration: none;
  margin-bottom: 1rem;
  padding-bottom: 0.75rem;
  border-bottom: 1px solid var(--border);
}

.theme-toggle {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  margin-bottom: 1rem;
  padding: 0.2rem 0.5rem;
  font: inherit;
  font-size: 1rem;
  color: var(--text-dim);
  background: var(--bg-code);
  border: 1px solid var(--border);
  border-radius: 6px;
  cursor: pointer;
}

.theme-toggle:hover {
  color: var(--text);
  border-color: var(--accent);
}

/* Each label describes the theme the button switches TO. Dark is showing by
   default, so the "Light mode" label is visible; the light theme swaps them. */
.theme-toggle .to-light,
.theme-toggle .to-dark {
  align-items: center;
  gap: 0.4rem;
}
.theme-toggle .to-light {
  display: inline-flex;
}
.theme-toggle .to-dark {
  display: none;
}
:root[data-theme='light'] .theme-toggle .to-light {
  display: none;
}
:root[data-theme='light'] .theme-toggle .to-dark {
  display: inline-flex;
}

.sidebar ul {
  list-style: none;
  margin: 0;
  padding-left: 1rem;
}

.sidebar > ul {
  padding-left: 0;
}

.sidebar li {
  margin: 0.15rem 0;
}

.sidebar a {
  color: var(--text-dim);
  text-decoration: none;
  display: block;
  padding: 0.15rem 0.4rem;
  border-radius: 4px;
  font-size: 0.92rem;
}

.sidebar a:hover {
  color: var(--text);
  background: var(--bg-code);
}

.sidebar a.active {
  color: var(--accent);
  background: var(--accent-bg);
  font-weight: 600;
}

.sidebar summary {
  cursor: pointer;
  padding: 0.15rem 0.4rem;
  border-radius: 4px;
  font-size: 0.92rem;
  color: var(--text);
}

.sidebar summary:hover {
  background: var(--bg-code);
}

.content {
  flex: 1;
  max-width: 800px;
  padding: 2.5rem 3rem;
}

.content h1 {
  margin-top: 0;
  border-bottom: 1px solid var(--border);
  padding-bottom: 0.5rem;
}

.content a {
  color: var(--accent);
  text-decoration: none;
}

/* Self-linking chapter numbers (Bible pages) stay the same color as body text */
.content h2 a[href^='#'] {
  color: var(--text);
}

.content code {
  background: var(--bg-code);
  padding: 0.15em 0.4em;
  border-radius: 4px;
  font-size: 0.9em;
}

.content pre {
  background: var(--bg-code);
  padding: 1rem;
  border-radius: 6px;
  overflow-x: auto;
}

.content pre code {
  background: none;
  padding: 0;
}

.content blockquote {
  border-left: 3px solid var(--accent);
  margin-left: 0;
  padding-left: 1rem;
  color: var(--text-dim);
}

.footnote-ref {
  position: relative;
}

.footnote-marker {
  display: inline-block;
  color: var(--accent);
  cursor: help;
  font-size: 0.75em;
  padding: 0 0.15em;
}

.footnote-tooltip {
  visibility: hidden;
  opacity: 0;
  position: absolute;
  bottom: 125%;
  left: 50%;
  transform: translateX(-50%);
  background: var(--bg-code);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 0.5rem 0.75rem;
  font-size: 0.85rem;
  line-height: 1.4;
  width: max-content;
  max-width: 280px;
  box-shadow: 0 4px 12px var(--shadow);
  z-index: 20;
  transition: opacity 0.12s ease;
  pointer-events: none;
}

.footnote-tooltip p {
  margin: 0;
}

.footnote-ref:hover .footnote-tooltip,
.footnote-ref:focus-within .footnote-tooltip {
  visibility: visible;
  opacity: 1;
}

.content table {
  border-collapse: collapse;
  width: 100%;
}

.content th,
.content td {
  border: 1px solid var(--border);
  padding: 0.5rem;
  text-align: left;
}

.content img {
  max-width: 100%;
}

.link-preview-popup {
  position: fixed;
  z-index: 100;
  background: var(--bg-code);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 1rem 1.25rem;
  box-shadow: 0 8px 24px var(--shadow);
  max-height: 360px;
  overflow-y: auto;
  font-size: 0.85rem;
  line-height: 1.5;
  color: var(--text);
  opacity: 0;
  transform: translateY(-4px);
  transition:
    opacity 0.12s ease,
    transform 0.12s ease;
  pointer-events: none;
}

.link-preview-popup.visible {
  opacity: 1;
  transform: translateY(0);
  pointer-events: auto;
}

.link-preview-popup a {
  color: var(--accent);
}

.link-preview-popup h1 {
  font-size: 1rem;
  margin-top: 0;
  border-bottom: 1px solid var(--border);
  padding-bottom: 0.4rem;
}

.link-preview-popup img {
  max-width: 100%;
}

.link-preview-loading {
  color: var(--text-dim);
  font-style: italic;
}

@media (max-width: 800px) {
  .layout {
    flex-direction: column;
  }
  .sidebar {
    width: 100%;
    position: static;
    max-height: none;
  }
  .content {
    padding: 1.5rem;
  }
}
