:root {
  color-scheme: light dark;
  --font-serif: "Charter", "Bitstream Charter", "Sitka Text", Georgia, serif;
  --font-sans: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --font-mono: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  --reader-font-family: var(--font-serif);
  --reader-font-size: 19px;
  --reader-line-height: 1.65;
  --color-bg: light-dark(oklch(98.5% 0.005 85), oklch(14% 0.005 85));
  --color-surface: light-dark(oklch(100% 0 0), oklch(18% 0.005 85));
  --color-text: light-dark(oklch(20% 0.01 60), oklch(93% 0.005 85));
  --color-text-muted: light-dark(oklch(45% 0.01 60), oklch(75% 0.005 85));
  --color-border: light-dark(oklch(88% 0.005 85), oklch(28% 0.005 85));
  --color-accent: light-dark(oklch(45% 0.12 250), oklch(75% 0.12 250));
  --color-accent-subtle: light-dark(oklch(95% 0.03 250), oklch(22% 0.04 250));
  --color-danger: oklch(55% 0.22 25);
  --color-focus: light-dark(oklch(82% 0.15 90), oklch(72% 0.15 90));
}

[data-theme="light"] {
  color-scheme: light;
  --color-bg: oklch(98.5% 0.005 85);
  --color-surface: oklch(100% 0 0);
  --color-text: oklch(20% 0.01 60);
  --color-text-muted: oklch(45% 0.01 60);
  --color-border: oklch(88% 0.005 85);
}

[data-theme="sepia"] {
  color-scheme: light;
  --color-bg: oklch(94% 0.025 80);
  --color-surface: oklch(97% 0.02 80);
  --color-text: oklch(25% 0.03 55);
  --color-text-muted: oklch(48% 0.03 60);
  --color-border: oklch(86% 0.025 80);
  --color-accent: oklch(45% 0.1 50);
}

[data-theme="dark"] {
  color-scheme: dark;
  --color-bg: oklch(14% 0.005 85);
  --color-surface: oklch(18% 0.005 85);
  --color-text: oklch(93% 0.005 85);
  --color-text-muted: oklch(75% 0.005 85);
  --color-border: oklch(28% 0.005 85);
}

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

body {
  margin: 0;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  background-color: var(--color-bg);
  color: var(--color-text);
  font-family: var(--font-sans);
  font-size: 16px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

a {
  color: inherit;
  text-decoration: underline;
  text-underline-offset: 2px;
}

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

.skip-link {
  position: absolute;
  clip: rect(0 0 0 0);
}

.skip-link:focus {
  position: fixed;
  top: 8px;
  left: 8px;
  z-index: 1000;
  clip: auto;
  background: var(--color-focus);
  color: #000;
  padding: 8px 16px;
  font-weight: 700;
}

.header {
  height: 52px;
  background: var(--color-surface);
  border-bottom: 1px solid var(--color-border);
  position: sticky;
  top: 0;
  z-index: 20;
}

.header-inner {
  max-width: 900px;
  height: 100%;
  margin: 0 auto;
  padding: 0 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.header-left, .header-right {
  display: flex;
  align-items: center;
  gap: 10px;
}

.logo-link {
  display: flex;
  align-items: center;
  gap: 8px;
  text-decoration: none;
  font-weight: 700;
  font-size: 1.1rem;
}

.logo-img {
  width: 20px;
  height: 20px;
  background: var(--color-accent);
  mask: url(/favicon.svg) no-repeat center / contain;
}

.main-nav {
  display: flex;
  gap: 6px;
}

.nav-tab {
  text-decoration: none;
  font-size: 0.9rem;
  font-weight: 600;
  padding: 4px 10px;
  border-radius: 4px;
  color: var(--color-text-muted);
}

.nav-tab:hover, .nav-tab.active {
  color: var(--color-text);
  background: var(--color-accent-subtle);
}

.icon-btn, .header-btn, .toolbar-btn {
  background: transparent;
  border: 1px solid var(--color-border);
  border-radius: 6px;
  padding: 4px 10px;
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--color-text);
  cursor: pointer;
  min-height: 32px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.icon-btn:hover, .header-btn:hover, .toolbar-btn:hover {
  border-color: var(--color-text-muted);
  background: var(--color-surface);
}

.icon-btn {
  width: 32px;
  height: 32px;
  min-width: 32px;
  min-height: 32px;
  box-sizing: border-box;
  padding: 0;
  font-family: var(--font-serif);
  font-size: 1rem;
}

.main-canvas {
  flex: 1;
  max-width: 900px;
  width: 100%;
  margin: 0 auto;
  padding: 24px 16px 80px;
}

.footer {
  border-top: 1px solid var(--color-border);
  padding: 20px 16px;
  font-size: 0.85rem;
  color: var(--color-text-muted);
  text-align: center;
}

.reader-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 24px;
  flex-wrap: wrap;
  gap: 12px;
}

.reader-breadcrumbs {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 0.9rem;
  color: var(--color-text-muted);
}

.reader-breadcrumbs .crumb-link {
  text-decoration: none;
  color: var(--color-text-muted);
}

.reader-breadcrumbs .crumb-link:hover {
  color: var(--color-text);
  text-decoration: underline;
}

.reader-breadcrumbs .crumb-current {
  color: var(--color-text);
  font-weight: 600;
}

.reader-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

.version-select {
  background: var(--color-surface);
  color: var(--color-text);
  border: 1px solid var(--color-border);
  border-radius: 6px;
  padding: 4px 8px;
  font-size: 0.85rem;
  font-weight: 600;
  cursor: pointer;
}

.scripture-canvas {
  max-width: 68ch;
  margin: 0 auto;
  font-family: var(--reader-font-family);
  font-size: var(--reader-font-size);
  line-height: var(--reader-line-height);
}

.verse-row {
  margin: 0 0 0.8em;
  padding: 2px 4px;
  border-radius: 4px;
}

.verse-row:hover, .verse-row:focus-within {
  background: var(--color-accent-subtle);
}

.verse-row:hover .study-trigger-btn, .verse-row:focus-within .study-trigger-btn {
  opacity: 1;
}

.verse-num {
  font-size: 0.68em;
  font-weight: 700;
  color: var(--color-text-muted);
  user-select: none;
  margin-right: 4px;
  vertical-align: super;
}

.verse-text {
  word-break: break-word;
}

.study-trigger-btn {
  opacity: 0;
  margin-left: 8px;
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: 4px;
  font-size: 0.65rem;
  font-weight: 600;
  padding: 2px 6px;
  color: var(--color-text-muted);
  cursor: pointer;
  vertical-align: middle;
}

.study-trigger-btn:hover {
  color: var(--color-text);
  border-color: var(--color-accent);
}

.chapter-intro {
  max-width: 68ch;
  margin: 0 auto 24px;
  padding: 16px;
  background: var(--color-surface);
  border-left: 3px solid var(--color-accent);
  border-radius: 0 6px 6px 0;
  font-family: var(--reader-font-family);
  font-size: var(--reader-font-size);
  line-height: var(--reader-line-height);
}

.chapter-intro p {
  margin: 0 0 0.8em;
}

.chapter-intro p:last-child {
  margin-bottom: 0;
}

.commentary-inset {
  display: block;
  margin: 6px 0 10px 1.5em;
  padding: 8px 12px;
  background: var(--color-surface);
  border-left: 2px solid var(--color-accent);
  border-radius: 0 4px 4px 0;
  font-size: 0.9em;
  font-family: var(--font-sans);
  line-height: 1.45;
  color: var(--color-text-muted);
}

.hidden {
  display: none !important;
}

.thumb-bar {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  height: 52px;
  background: var(--color-surface);
  border-top: 1px solid var(--color-border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 16px;
  z-index: 20;
}

.thumb-bar-left, .thumb-bar-right {
  display: flex;
  align-items: center;
  gap: 10px;
}

.thumb-breadcrumbs {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 0.88rem;
  font-weight: 600;
  color: var(--color-text-muted);
}

.header-version-select {
  background: var(--color-bg);
  color: var(--color-text);
  border: 1px solid var(--color-border);
  border-radius: 6px;
  padding: 4px 8px;
  font-size: 0.85rem;
  font-weight: 600;
  height: 32px;
  box-sizing: border-box;
}

.thumb-bar .thumb-btn {
  text-decoration: none;
  font-size: 0.9rem;
  font-weight: 600;
  padding: 6px 12px;
  border-radius: 6px;
  border: 1px solid var(--color-border);
  color: var(--color-text);
  background: var(--color-bg);
}

.thumb-bar .thumb-btn:hover {
  background: var(--color-accent-subtle);
}

.thumb-bar .thumb-btn.icon-thumb-btn {
  padding: 6px 10px;
  font-size: 1rem;
  line-height: 1;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.thumb-bar .thumb-label {
  font-size: 0.9rem;
  font-weight: 700;
}

.document-container {
  max-width: 68ch;
  margin: 0 auto;
}

.document-title {
  font-size: 1.85rem;
  font-weight: 700;
  margin: 0 0 12px;
}

.document-description {
  color: var(--color-text-muted);
  margin-bottom: 24px;
}

details.chapter-section {
  border-top: 1px solid var(--color-border);
  margin-bottom: 12px;
}

details.chapter-section summary.chapter-btn {
  list-style: none;
  cursor: pointer;
  padding: 14px 0;
  font-size: 1.25rem;
  font-weight: 700;
  color: var(--color-text);
}

details.chapter-section summary.chapter-btn::-webkit-details-marker {
  display: none;
}

details.chapter-section summary.chapter-btn:hover {
  color: var(--color-accent);
}

details.chapter-section .chapter-content {
  padding: 8px 0 20px;
}

.article {
  margin-bottom: 18px;
  font-family: var(--reader-font-family);
  font-size: var(--reader-font-size);
  line-height: var(--reader-line-height);
}

.article .article-body {
  margin: 0 0 6px;
}

.article .article-proofs {
  font-size: 0.85em;
  font-family: var(--font-sans);
  color: var(--color-text-muted);
}

.proof-link {
  color: var(--color-accent);
  text-decoration: none;
  font-weight: 600;
}

.proof-link:hover {
  text-decoration: underline;
}

.books-container, .chapters-container {
  max-width: 800px;
  margin: 0 auto;
}

.page-title {
  font-size: 1.75rem;
  font-weight: 700;
  margin: 0 0 20px;
}

.testament-group {
  margin-bottom: 32px;
}

.testament-heading {
  font-size: 1.25rem;
  border-bottom: 1px solid var(--color-border);
  padding-bottom: 6px;
  margin-bottom: 12px;
}

.books-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(130px, 1fr));
  gap: 8px;
}

.book-card, .chapter-card {
  display: flex;
  align-items: center;
  justify-content: center;
  text-decoration: none;
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: 6px;
  color: var(--color-text);
  font-weight: 600;
}

.book-card:hover, .chapter-card:hover {
  border-color: var(--color-accent);
  background: var(--color-accent-subtle);
}

.book-card {
  padding: 10px;
  font-size: 0.9rem;
}

.chapter-card {
  height: 48px;
  font-weight: 700;
}

.chapters-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(56px, 1fr));
  gap: 8px;
}

.reader-dialog {
  border: 1px solid var(--color-border);
  border-radius: 8px;
  padding: 0;
  max-width: 540px;
  width: 90%;
  background: var(--color-surface);
  color: var(--color-text);
}

.dialog-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 14px 18px;
  border-bottom: 1px solid var(--color-border);
}

.dialog-header h2 {
  margin: 0;
  font-size: 1.15rem;
}

.dialog-close-btn {
  background: none;
  border: none;
  font-size: 1.4rem;
  cursor: pointer;
  color: var(--color-text-muted);
}

.dialog-close-btn:hover {
  color: var(--color-text);
}

.dialog-body {
  padding: 18px;
  max-height: 70vh;
  overflow-y: auto;
}

@media (max-width: 600px) {
  .header-inner {
    padding: 0 8px;
  }

  .header-left {
    gap: 6px;
  }

  .main-nav {
    gap: 4px;
  }

  .nav-tab {
    padding: 4px 8px;
    font-size: 0.85rem;
  }

  .header-right {
    gap: 4px;
  }

  .header-version-select {
    padding: 2px 4px;
    font-size: 0.8rem;
    height: 28px;
  }

  .icon-btn {
    padding: 4px 6px;
    font-size: 0.85rem;
  }

  .thumb-bar {
    padding: 0 8px;
    gap: 6px;
  }

  .thumb-bar-left, .thumb-bar-right {
    gap: 6px;
  }

  .thumb-bar .thumb-btn {
    padding: 5px 8px;
    font-size: 0.8rem;
    white-space: nowrap;
  }

  .thumb-bar .thumb-btn.icon-thumb-btn {
    padding: 5px 8px;
    font-size: 0.95rem;
  }

  .thumb-breadcrumbs .crumb-link,
  .thumb-breadcrumbs .crumb-sep {
    display: none;
  }

  .thumb-breadcrumbs .crumb-current {
    font-size: 0.82rem;
    max-width: 110px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .reader-dialog.study-sheet {
    position: fixed;
    bottom: 0;
    top: auto;
    width: 100%;
    max-width: 100%;
    margin: 0;
    border-radius: 12px 12px 0 0;
  }
}

.setting-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 14px;
}

.setting-row label {
  font-weight: 600;
  font-size: 0.95rem;
}

.setting-control {
  background: var(--color-bg);
  color: var(--color-text);
  border: 1px solid var(--color-border);
  border-radius: 6px;
  padding: 6px 10px;
  font-size: 0.9rem;
  width: 180px;
  min-width: 180px;
  box-sizing: border-box;
}

.modules-container {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-top: 12px;
}

.module-card {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 12px;
  border: 1px solid var(--color-border);
  border-radius: 6px;
  background: var(--color-surface);
}

.module-name {
  font-size: 0.95rem;
}

.module-meta {
  font-size: 0.85rem;
  color: var(--color-text-muted);
}

.module-status-active {
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--color-accent);
}

.module-action-btn {
  padding: 6px 12px;
  border-radius: 6px;
  font-size: 0.85rem;
  font-weight: 600;
  cursor: pointer;
  border: 1px solid transparent;
}

.module-btn-download {
  background: var(--color-accent);
  color: #fff;
}

.module-btn-download:hover {
  opacity: 0.9;
}

.module-btn-remove {
  background: transparent;
  color: var(--color-danger);
  border-color: var(--color-danger);
}

.module-btn-remove:hover {
  background: var(--color-danger);
  color: #fff;
}

.module-progress-text {
  font-size: 0.85rem;
  font-weight: 700;
  color: var(--color-accent);
}

.study-card {
  margin-bottom: 20px;
}

.study-card-title {
  font-size: 1rem;
  margin: 0 0 10px;
  border-bottom: 1px solid var(--color-border);
  padding-bottom: 4px;
  color: var(--color-text-muted);
}

.strong-item, .study-refs-list li {
  padding: 8px 10px;
  margin-bottom: 6px;
  background: var(--color-bg);
  border-radius: 6px;
  font-size: 0.9rem;
}

.study-refs-list {
  list-style: none;
  padding: 0;
  margin: 0;
}

.study-prompt-muted {
  font-size: 0.9rem;
  color: var(--color-text-muted);
}

.study-download-link {
  color: var(--color-accent);
  font-weight: bold;
}

.study-empty-muted {
  color: var(--color-text-muted);
  font-size: 0.9rem;
}

.installer-card {
  max-width: 500px;
  margin: 40px auto;
  padding: 24px;
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: 8px;
}

.installer-card-prompt {
  margin: 20px auto;
}

.installer-card-error {
  border-left: 4px solid var(--color-danger);
}

.installer-title {
  margin: 0 0 8px;
  font-size: 1.3rem;
}

.installer-desc {
  color: var(--color-text-muted);
  font-size: 0.9rem;
  margin-bottom: 16px;
}

.installer-progress-bar {
  height: 8px;
  background: var(--color-border);
  border-radius: 4px;
  overflow: hidden;
  position: relative;
  margin-bottom: 8px;
}

.installer-progress-fill {
  height: 100%;
  background: var(--color-accent);
  width: 0%;
}

.installer-progress-fill.indeterminate {
  width: 30%;
  position: absolute;
  animation: indeterminate 1.4s infinite ease-in-out;
}

.installer-status {
  display: flex;
  justify-content: space-between;
  font-size: 0.85rem;
  color: var(--color-text-muted);
}

@keyframes indeterminate {
  0% { left: -30%; }
  100% { left: 100%; }
}

.update-banner {
  position: fixed;
  bottom: 20px;
  right: 20px;
  max-width: 420px;
  background: var(--color-surface);
  color: var(--color-text);
  border: 1px solid var(--color-border);
  border-left: 4px solid var(--color-accent);
  border-radius: 6px;
  padding: 14px;
  z-index: 1000;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.update-banner-title {
  font-size: 0.95rem;
}

.update-banner-desc {
  font-size: 0.85rem;
  color: var(--color-text-muted);
  margin: 0;
}

.update-banner-actions {
  display: flex;
  gap: 8px;
  margin-top: 4px;
}

.update-btn {
  background: var(--color-accent);
  color: #fff;
  border: none;
  border-radius: 4px;
  padding: 6px 12px;
  font-size: 0.85rem;
  font-weight: 600;
  cursor: pointer;
}

.update-btn-dismiss {
  background: transparent;
  color: var(--color-text-muted);
  border: 1px solid var(--color-border);
}

.verse-popover {
  background: var(--color-surface);
  color: var(--color-text);
  border: 1px solid var(--color-border);
  border-radius: 6px;
  padding: 10px;
  max-width: 320px;
  pointer-events: none;
  margin: 0;
}

.search-scope-bar {
  display: flex;
  gap: 8px;
  margin-bottom: 12px;
}

.search-scope-btn {
  flex: 1;
  padding: 6px 10px;
  font-size: 0.85rem;
  font-weight: 600;
  border: 1px solid var(--color-border);
  border-radius: 6px;
  background: var(--color-bg);
  color: var(--color-text-muted);
  cursor: pointer;
  transition: all 0.15s ease;
}

.search-scope-btn:hover {
  color: var(--color-text);
  border-color: var(--color-text-muted);
}

.search-scope-btn.active {
  color: #fff;
  background: var(--color-accent);
  border-color: var(--color-accent);
}

.search-input-wrap {
  margin-bottom: 12px;
}

.search-input {
  width: 100%;
  padding: 10px 14px;
  font-size: 1rem;
  border: 1px solid var(--color-border);
  border-radius: 6px;
  background: var(--color-bg);
  color: var(--color-text);
}

.search-info {
  font-size: 0.85rem;
  color: var(--color-text-muted);
  margin-bottom: 8px;
}

.search-results-list {
  max-height: 55vh;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.search-result-item {
  display: block;
  text-decoration: none;
  padding: 10px;
  border: 1px solid var(--color-border);
  border-radius: 6px;
  background: var(--color-surface);
  color: var(--color-text);
  transition: border-color 0.15s ease;
}

.search-result-item:hover {
  border-color: var(--color-accent);
}

.search-result-ref {
  font-weight: 600;
  color: var(--color-accent);
  font-size: 0.9rem;
  margin-bottom: 4px;
}

.search-result-text {
  font-size: 0.9rem;
  line-height: 1.4;
}

.search-result-text b {
  color: var(--color-accent);
  background: rgba(43, 91, 158, 0.1);
  padding: 0 2px;
  border-radius: 2px;
}

.bookmark-btn {
  font-size: 1.1rem;
  line-height: 1;
  padding: 2px 6px;
  color: var(--color-text-muted);
  border: none;
  background: transparent;
  cursor: pointer;
  border-radius: 4px;
  transition: color 0.15s ease;
}

.bookmark-btn:hover {
  color: var(--color-accent);
}

.bookmark-btn.active {
  color: #e5a00d;
}

.bookmarks-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
  max-height: 55vh;
  overflow-y: auto;
}

.bookmark-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 12px;
  border: 1px solid var(--color-border);
  border-radius: 6px;
  background: var(--color-surface);
}

.bookmark-link {
  flex: 1;
  text-decoration: none;
  color: var(--color-text);
}

.bookmark-ref {
  display: block;
  font-size: 0.9rem;
  color: var(--color-accent);
  margin-bottom: 2px;
}

.bookmark-text {
  font-size: 0.85rem;
  color: var(--color-text-muted);
}

.bookmark-delete-btn {
  background: transparent;
  border: none;
  font-size: 1.25rem;
  line-height: 1;
  color: var(--color-text-muted);
  cursor: pointer;
  padding: 4px 8px;
}

.bookmark-delete-btn:hover {
  color: #dc2626;
}

.resume-card {
  max-width: 68ch;
  margin: 0 auto 20px;
  padding: 12px 16px;
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-left: 3px solid var(--color-accent);
  border-radius: 0 6px 6px 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.resume-info {
  display: flex;
  align-items: center;
  gap: 12px;
}

.resume-label {
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  font-weight: 700;
  color: var(--color-text-muted);
}

.resume-link {
  font-weight: 600;
  color: var(--color-accent);
  text-decoration: none;
}

.resume-link:hover {
  text-decoration: underline;
}

.confession-nav-bar {
  margin-top: 24px;
}



