/* ============================================================
   ionBible — Bible Web App Stylesheet
   Matches the mobile app design language.
   Primary accent : #BF7B52 (terracotta)
   Background     : #FAFAF8 (off-white)
   Text           : #2C2C2C
   Font           : Lato (loaded via Google Fonts in template)
   ============================================================ */

/* ── CSS Custom Properties ── */
:root {
  --accent:      #BF7B52;
  --accent-rgb:  191, 123, 82;
  --bg:          #FAFAF8;
  --card-bg:     #FFFFFF;
  --text:        #2C2C2C;
  --text-rgb:    44, 44, 44;
}

/* ── Reset & Base ── */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html {
  font-family: 'Lato', sans-serif;
  background: var(--bg);
  color: var(--text);
  scroll-behavior: smooth;
}

body {
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
}

a {
  color: inherit;
  text-decoration: none;
}

/* ============================================================
   1. SITE HEADER
   ============================================================ */

.site-header {
  position: sticky;
  top: 0;
  z-index: 600;
  background: var(--card-bg);
  box-shadow: 0 1px 8px rgba(0, 0, 0, 0.08);
  height: 52px;
  display: flex;
  align-items: center;
}

.header-inner {
  max-width: 860px;
  width: 100%;
  margin: 0 auto;
  padding: 0 20px;
  display: flex;
  flex-direction: row;
  align-items: center;
  justify-content: space-between;
}

.logo {
  font-family: 'Lato', sans-serif;
  font-weight: 700;
  font-size: 20px;
  color: var(--accent);
  text-decoration: none;
  letter-spacing: -0.3px;
}

.logo span {
  font-weight: 300;
}

/* Nav links in the site header (Plans / Prayer) */
.header-nav {
  display: flex;
  align-items: center;
  gap: 1.25rem;
}

.header-nav a {
  font-size: 13px;
  font-weight: 600;
  color: var(--muted);
  text-decoration: none;
  letter-spacing: 0.3px;
  transition: color 0.15s;
}

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

/* Hide on very small screens so the header doesn't crowd */
@media (max-width: 480px) {
  .header-nav { display: none; }
}

.btn-login {
  background: var(--accent);
  color: #ffffff;
  border: none;
  border-radius: 50px;
  padding: 8px 18px;
  font-family: 'Lato', sans-serif;
  font-weight: 600;
  font-size: 14px;
  cursor: pointer;
  transition: opacity 0.15s;
}

.btn-login:hover {
  opacity: 0.88;
}

.user-avatar {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: var(--accent);
  color: #ffffff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: 'Lato', sans-serif;
  font-weight: 700;
  font-size: 14px;
  cursor: pointer;
  position: relative;
  user-select: none;
}

.user-menu {
  display: none;
  position: absolute;
  top: 38px;
  right: 0;
  background: var(--card-bg);
  border-radius: 10px;
  box-shadow: 0 6px 24px rgba(0, 0, 0, 0.14);
  min-width: 120px;
  overflow: hidden;
  z-index: 700;
}

.user-menu a,
.user-menu button {
  display: block;
  width: 100%;
  padding: 10px 16px;
  font-family: 'Lato', sans-serif;
  font-size: 14px;
  color: var(--text);
  background: none;
  border: none;
  text-align: left;
  cursor: pointer;
  white-space: nowrap;
}

.user-menu a:hover,
.user-menu button:hover {
  background: rgba(var(--accent-rgb), 0.08);
}

.user-avatar:hover .user-menu {
  display: block;
}

/* ============================================================
   2. CHAPTER NAVIGATION BAR
   ============================================================ */

.chapter-nav {
  position: sticky;
  top: 52px;
  z-index: 590;
  background: var(--card-bg);
  border-bottom: 1px solid rgba(var(--accent-rgb), 0.15);
  height: 56px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.chapter-nav-inner {
  max-width: 860px;
  width: 100%;
  padding: 0 20px;
  display: flex;
  align-items: center;
  gap: 12px;
}

.nav-btn {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: rgba(var(--accent-rgb), 0.08);
  color: var(--accent);
  border: none;
  font-size: 22px;
  line-height: 1;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: background 0.15s;
  text-decoration: none;
}

.nav-btn:hover {
  background: rgba(var(--accent-rgb), 0.16);
}

.nav-btn.disabled,
.nav-btn[disabled] {
  opacity: 0.3;
  pointer-events: none;
}

.chapter-title-btn {
  display: flex;
  flex-direction: row;
  align-items: baseline;
  gap: 6px;
  background: transparent;
  border: none;
  cursor: pointer;
  padding: 0;
  flex: 1;
}

.chapter-title-btn .chapter-title-text {
  font-family: 'Lato', sans-serif;
  font-weight: 800;
  font-size: 28px;
  color: var(--accent);
  line-height: 1;
}

.chapter-title-btn .chapter-title-arrow {
  font-size: 14px;
  color: var(--accent);
  opacity: 0.7;
}

.chapter-subtitle {
  font-family: 'Lato', sans-serif;
  font-weight: 400;
  font-size: 14px;
  color: rgba(var(--text-rgb), 0.5);
  white-space: nowrap;
}

/* ============================================================
   3. CHAPTER CONTENT
   ============================================================ */

.chapter-content {
  max-width: 680px;
  margin: 0 auto;
  padding: 24px 20px 80px;
  font-family: 'Lato', sans-serif;
  font-weight: 400;
  font-size: 18px;
  line-height: 1.85;
}

.chapter-content p {
  margin-bottom: 1.1em;
}

/* Verse number superscript */
sup.versenum {
  font-size: 0.62em;
  color: var(--accent);
  font-weight: 700;
  vertical-align: super;
  margin-right: 3px;
  cursor: pointer;
  user-select: none;
}

/* Red-letter text — words of Jesus */
.red-letter {
  color: #b91c1c;
}
html[data-theme="dark"] .red-letter {
  color: #f87171;
}
@media (prefers-color-scheme: dark) {
  html:not([data-theme="light"]) .red-letter {
    color: #f87171;
  }
}

/* Chapter drop-cap number */
.chap.versenum {
  font-size: 2.2em;
  font-weight: 800;
  color: var(--accent);
  line-height: 1;
  float: left;
  margin-right: 8px;
  cursor: pointer;
  vertical-align: baseline;
}

/* Highlights */
mark.ion-highlight {
  border-radius: 3px;
  padding: 1px 0;
  mix-blend-mode: multiply;
  background-color: inherit;
}

/* ============================================================
   4. HIGHLIGHT PICKER
   ============================================================ */

#highlight-picker {
  position: absolute;
  z-index: 1000;
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--card-bg);
  border-radius: 50px;
  padding: 8px 12px;
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.15);
}

.swatch {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  border: none;
  cursor: pointer;
  transition: transform 0.15s;
  flex-shrink: 0;
}

.swatch:hover {
  transform: scale(1.2);
}

.swatch.erase {
  background: #f0f0f0;
  color: #999999;
  font-size: 13px;
  display: flex;
  align-items: center;
  justify-content: center;
}

/* ============================================================
   5. STUDY PANEL
   ============================================================ */

.study-panel {
  position: fixed;
  right: 0;
  top: 0;
  height: 100vh;
  width: min(420px, 92vw);
  background: var(--card-bg);
  box-shadow: -4px 0 30px rgba(0, 0, 0, 0.12);
  transform: translateX(100%);
  transition: transform 0.3s ease;
  z-index: 500;
  display: flex;
  flex-direction: column;
}

.study-panel.open {
  transform: translateX(0);
}

.study-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.3);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.3s;
  z-index: 499;
}

.study-overlay.active {
  opacity: 1;
  pointer-events: all;
}

.study-panel-header {
  display: flex;
  flex-direction: row;
  align-items: center;
  justify-content: space-between;
  padding: 16px 20px;
  border-bottom: 1px solid rgba(var(--accent-rgb), 0.1);
  flex-shrink: 0;
}

#study-verse-label {
  font-family: 'Lato', sans-serif;
  font-weight: 700;
  font-size: 16px;
  color: var(--accent);
}

#study-close {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: rgba(var(--accent-rgb), 0.08);
  color: var(--accent);
  border: none;
  font-size: 18px;
  line-height: 1;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.15s;
}

#study-close:hover {
  background: rgba(var(--accent-rgb), 0.16);
}

.study-tabs {
  display: flex;
  flex-direction: row;
  gap: 6px;
  padding: 12px 20px;
  border-bottom: 1px solid rgba(var(--accent-rgb), 0.1);
  overflow-x: auto;
  flex-shrink: 0;
  scrollbar-width: none;
}

.study-tabs::-webkit-scrollbar {
  display: none;
}

.study-tab {
  background: rgba(var(--accent-rgb), 0.08);
  color: var(--accent);
  border: none;
  padding: 5px 14px;
  border-radius: 50px;
  font-family: 'Lato', sans-serif;
  font-weight: 600;
  font-size: 13px;
  cursor: pointer;
  white-space: nowrap;
  transition: background 0.15s, color 0.15s;
}

.study-tab.active {
  background: var(--accent);
  color: #ffffff;
}

.study-body {
  flex: 1;
  overflow-y: auto;
  padding: 20px;
}

.commentary-title {
  font-family: 'Lato', sans-serif;
  font-weight: 700;
  font-size: 15px;
  color: var(--accent);
  margin-bottom: 8px;
}

.commentary-text {
  font-family: 'Lato', sans-serif;
  font-weight: 400;
  font-size: 15px;
  line-height: 1.75;
  color: var(--text);
}

.commentary-block + .commentary-block {
  margin-top: 24px;
  padding-top: 24px;
  border-top: 1px solid rgba(var(--accent-rgb), 0.1);
}

.study-loading {
  width: 32px;
  height: 32px;
  border: 3px solid rgba(var(--accent-rgb), 0.2);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
  margin: 40px auto;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

/* ============================================================
   6. LOGIN MODAL
   ============================================================ */

.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.5);
  z-index: 2000;
  display: flex;
  align-items: center;
  justify-content: center;
}

.modal {
  background: var(--card-bg);
  border-radius: 20px;
  padding: 32px;
  width: min(380px, 90vw);
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.2);
}

.modal h2 {
  font-family: 'Lato', sans-serif;
  font-weight: 800;
  font-size: 22px;
  color: var(--accent);
  margin-bottom: 20px;
  text-align: center;
}

.modal input {
  width: 100%;
  border: 1.5px solid rgba(var(--accent-rgb), 0.3);
  border-radius: 10px;
  padding: 12px 16px;
  font-family: 'Lato', sans-serif;
  font-weight: 400;
  font-size: 16px;
  outline: none;
  box-sizing: border-box;
  margin-bottom: 12px;
  background: var(--bg);
  color: var(--text);
  transition: border-color 0.15s;
}

.modal input:focus {
  border-color: var(--accent);
}

.modal-btn {
  width: 100%;
  background: var(--accent);
  color: #ffffff;
  border: none;
  border-radius: 10px;
  padding: 13px;
  font-family: 'Lato', sans-serif;
  font-weight: 700;
  font-size: 16px;
  cursor: pointer;
  margin-top: 4px;
  transition: opacity 0.15s;
}

.modal-btn:hover {
  opacity: 0.88;
}

.modal-btn:disabled {
  opacity: 0.6;
  cursor: not-allowed;
}

.modal-back {
  background: transparent;
  color: rgba(var(--accent-rgb), 0.7);
  border: none;
  cursor: pointer;
  font-family: 'Lato', sans-serif;
  font-size: 14px;
  text-align: center;
  width: 100%;
  margin-top: 10px;
  display: block;
}

.modal-back:hover {
  color: var(--accent);
}

.modal-message {
  font-family: 'Lato', sans-serif;
  font-size: 14px;
  text-align: center;
  color: rgba(var(--text-rgb), 0.6);
  margin-bottom: 16px;
}

.modal-switch {
  font-family: 'Lato', sans-serif;
  font-size: 13px;
  text-align: center;
  color: rgba(var(--text-rgb), 0.5);
  margin-top: 16px;
  margin-bottom: 0;
}

.modal-link {
  background: none;
  border: none;
  padding: 0;
  cursor: pointer;
  font-family: inherit;
  font-size: inherit;
  color: var(--accent);
  text-decoration: underline;
  text-underline-offset: 2px;
}

.modal-link:hover {
  opacity: 0.8;
}

#step-register input + input {
  margin-top: 10px;
}

/* ============================================================
   7. READING PROGRESS BAR
   ============================================================ */

.reading-bar {
  position: fixed;
  top: 0;
  left: 0;
  height: 2px;
  background: var(--accent);
  z-index: 999;
  transition: width 0.1s linear;
  pointer-events: none;
}

/* ============================================================
   8. RESPONSIVE — Mobile (≤ 600px)
   ============================================================ */

@media (max-width: 600px) {
  .chapter-title-btn .chapter-title-text {
    font-size: 22px;
  }

  .chapter-content {
    padding: 16px 16px 80px;
  }

  .study-panel {
    width: 100vw;
  }
}

/* ============================================================
   9. DARK MODE
   Activated by either:
     a) OS preference  → @media (prefers-color-scheme: dark)
     b) Manual toggle  → html[data-theme="dark"]
   Light forced override (beats OS dark):
     html[data-theme="light"]
   ============================================================ */

@media (prefers-color-scheme: dark) {
  :root {
    --bg:       #111318;
    --card-bg:  #1E2128;
    --text:     #E8E4DC;
    --text-rgb: 232, 228, 220;
  }
}
html[data-theme="dark"] {
  --bg:       #111318;
  --card-bg:  #1E2128;
  --text:     #E8E4DC;
  --text-rgb: 232, 228, 220;
}

/* Force light even when OS is dark */
html[data-theme="light"] {
  --bg:       #FAFAF8;
  --card-bg:  #FFFFFF;
  --text:     #2C2C2C;
  --text-rgb: 44, 44, 44;
}

/* ── Element-level dark tweaks (both triggers) ── */
@media (prefers-color-scheme: dark) {
  .site-header         { box-shadow: 0 1px 8px rgba(0,0,0,.4); }
  .modal input         { background:#111318; color:#E8E4DC; border-color:rgba(191,123,82,.3); }
  mark.ion-highlight   { mix-blend-mode: screen; }
  .user-menu a,
  .user-menu button    { color: var(--text); }
  .swatch.erase        { background:#2C2F38; color:#888; }
  #highlight-picker    { background:var(--card-bg); box-shadow:0 4px 20px rgba(0,0,0,.45); }
  .study-panel         { box-shadow:-4px 0 30px rgba(0,0,0,.5); }
  .modal               { box-shadow:0 20px 60px rgba(0,0,0,.55); }
  .chapter-nav         { border-bottom-color:rgba(191,123,82,.15); }
}
html[data-theme="dark"] {
  .site-header         { box-shadow: 0 1px 8px rgba(0,0,0,.4); }
  .modal input         { background:#111318; color:#E8E4DC; border-color:rgba(191,123,82,.3); }
  mark.ion-highlight   { mix-blend-mode: screen; }
  .user-menu a,
  .user-menu button    { color: var(--text); }
  .swatch.erase        { background:#2C2F38; color:#888; }
  #highlight-picker    { background:var(--card-bg); box-shadow:0 4px 20px rgba(0,0,0,.45); }
  .study-panel         { box-shadow:-4px 0 30px rgba(0,0,0,.5); }
  .modal               { box-shadow:0 20px 60px rgba(0,0,0,.55); }
  .chapter-nav         { border-bottom-color:rgba(191,123,82,.15); }
}

/* ── Theme toggle button ── */
.btn-theme {
  background: none;
  border: none;
  cursor: pointer;
  padding: .3rem .4rem;
  border-radius: 6px;
  color: var(--text);
  font-size: 1.1rem;
  line-height: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: .7;
  transition: opacity .15s;
}
.btn-theme:hover { opacity: 1; background: rgba(0,0,0,.06); }

/* ════════════════════════════════════════════════════════════════
   Search
   ════════════════════════════════════════════════════════════════ */

/* Search button inside the chapter nav */
.search-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  background: none;
  border: none;
  cursor: pointer;
  color: var(--text);
  opacity: 0.65;
  padding: 6px 8px;
  border-radius: 7px;
  transition: opacity 0.15s, background 0.15s;
  flex-shrink: 0;
}
.search-btn:hover {
  opacity: 1;
  background: rgba(var(--accent-rgb), 0.1);
}

/* Full-screen search overlay */
#search-overlay {
  position: fixed;
  inset: 0;
  z-index: 800;
  display: flex;
  flex-direction: column;
  /* hidden by default */
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.18s ease;
}
#search-overlay.open {
  opacity: 1;
  pointer-events: auto;
}

/* Top search panel (input + hint) */
.search-panel {
  background: var(--bg);
  border-bottom: 1px solid rgba(var(--accent-rgb), 0.18);
  padding: 14px 20px 10px;
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.12);
  /* slide in from top */
  transform: translateY(-8px);
  transition: transform 0.18s ease;
}
#search-overlay.open .search-panel {
  transform: translateY(0);
}

.search-input-row {
  display: flex;
  align-items: center;
  gap: 10px;
  background: rgba(var(--accent-rgb), 0.07);
  border: 1px solid rgba(var(--accent-rgb), 0.18);
  border-radius: 10px;
  padding: 9px 14px;
}
.search-icon-sm {
  flex-shrink: 0;
  opacity: 0.45;
  color: var(--text);
}
#search-input {
  flex: 1;
  border: none;
  background: transparent;
  font-family: var(--font-body, 'Lato', sans-serif);
  font-size: 1rem;
  color: var(--text);
  outline: none;
  min-width: 0;
  /* Remove browser default search-cancel button */
  -webkit-appearance: none;
  appearance: none;
}
#search-input::-webkit-search-cancel-button { display: none; }
#search-input::placeholder { color: var(--text-muted, #9a8f84); }
#search-close {
  background: none;
  border: none;
  cursor: pointer;
  color: var(--text-muted, #9a8f84);
  font-size: 1rem;
  padding: 0;
  line-height: 1;
  flex-shrink: 0;
  transition: color 0.15s;
}
#search-close:hover { color: var(--text); }

.search-hint {
  margin: 8px 2px 0;
  font-size: 0.72rem;
  color: var(--text-muted, #9a8f84);
  line-height: 1.5;
}
.search-hint code {
  background: rgba(var(--accent-rgb), 0.1);
  border-radius: 3px;
  padding: 1px 5px;
  font-size: 0.7rem;
  font-family: 'SFMono-Regular', 'Menlo', monospace;
}

/* Results area — scrollable backdrop */
#search-results {
  flex: 1;
  overflow-y: auto;
  background: rgba(0, 0, 0, 0.35);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  padding: 12px 16px 40px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

/* Individual result card */
.search-result-card {
  display: block;
  background: var(--bg);
  border: 1px solid rgba(var(--accent-rgb), 0.15);
  border-radius: 12px;
  padding: 14px 16px;
  text-decoration: none;
  color: inherit;
  transition: border-color 0.15s, box-shadow 0.15s, transform 0.1s;
  max-width: 700px;
  margin: 0 auto;
  width: 100%;
}
.search-result-card:hover,
.search-result-card:focus-visible {
  border-color: var(--accent);
  box-shadow: 0 3px 16px rgba(var(--accent-rgb), 0.15);
  transform: translateY(-1px);
  outline: none;
}

.src-header {
  display: flex;
  align-items: baseline;
  gap: 8px;
  margin-bottom: 6px;
}
.src-book {
  font-weight: 700;
  font-size: 0.88rem;
  color: var(--accent);
  letter-spacing: 0.01em;
}
.src-chapter {
  font-size: 0.78rem;
  color: var(--text-muted, #9a8f84);
}
.src-snippet {
  font-size: 0.84rem;
  line-height: 1.6;
  color: var(--text);
  white-space: pre-wrap;
  word-break: break-word;
}
mark.search-match {
  background: rgba(191, 123, 82, 0.22);
  color: inherit;
  border-radius: 2px;
  padding: 0 1px;
  font-weight: 600;
}

/* Loading / empty states */
.search-loading,
.search-empty {
  text-align: center;
  color: rgba(255,255,255,0.7);
  font-size: 0.9rem;
  padding: 32px 0;
  max-width: 700px;
  margin: 0 auto;
  width: 100%;
}
.search-loading::before {
  content: '';
  display: block;
  width: 24px;
  height: 24px;
  border: 2px solid rgba(191,123,82,0.4);
  border-top-color: var(--accent);
  border-radius: 50%;
  margin: 0 auto 10px;
  animation: spin 0.7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* Dark-mode tweaks — search */
@media (prefers-color-scheme: dark) {
  .search-result-card { background: var(--card-bg, #1E2128); }
  .search-panel       { box-shadow: 0 4px 24px rgba(0,0,0,.4); }
  mark.search-match   { background: rgba(191,123,82,.3); }
  .search-hint code   { background: rgba(191,123,82,.15); }
}
html[data-theme="dark"] {
  .search-result-card { background: var(--card-bg, #1E2128); }
  .search-panel       { box-shadow: 0 4px 24px rgba(0,0,0,.4); }
  mark.search-match   { background: rgba(191,123,82,.3); }
  .search-hint code   { background: rgba(191,123,82,.15); }
}

/* ── Static commentary section (KJV only, embedded by generator for SEO) ── */
.commentary-section {
  max-width: 720px;
  margin: 3rem auto 4rem;
  padding: 0 1.25rem;
  font-family: 'Lato', sans-serif;
}
.commentary-heading {
  font-size: 1.25rem;
  font-weight: 700;
  color: var(--text);
  border-bottom: 2px solid rgba(var(--accent-rgb), 0.2);
  padding-bottom: .6rem;
  margin-bottom: 2rem;
}
.commentary-verse-block {
  margin-bottom: 2.5rem;
}
.commentary-verse-label {
  font-size: .85rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .06em;
  color: var(--accent);
  margin-bottom: 1rem;
}
.commentary-entry-title {
  font-size: .9rem;
  font-weight: 700;
  color: var(--text);
  margin: .5rem 0 .25rem;
}
