/* ============ CSS Variables ============ */
:root {
  --bg-primary: #f8f7f4;
  --bg-secondary: #ffffff;
  --bg-tertiary: #f0eeeb;
  --text-primary: #2c2c2c;
  --text-secondary: #5a5a5a;
  --text-muted: #999;
  --accent: #8b5a2b;
  --accent-hover: #a0673a;
  --accent-light: rgba(139, 90, 43, 0.1);
  --verse-num: #b8860b;
  --border: #e5e2dc;
  --shadow: rgba(0, 0, 0, 0.08);
  --shadow-lg: rgba(0, 0, 0, 0.12);
  --sidebar-width: 280px;
  --topbar-height: 56px;
  --selection-bg: rgba(139, 90, 43, 0.2);
}

html.dark {
  --bg-primary: #141414;
  --bg-secondary: #1c1c1c;
  --bg-tertiary: #242424;
  --text-primary: #e5e3df;
  --text-secondary: #a8a6a2;
  --text-muted: #666;
  --accent: #d4a574;
  --accent-hover: #e0b688;
  --accent-light: rgba(212, 165, 116, 0.15);
  --verse-num: #d4a574;
  --border: #2a2a2a;
  --shadow: rgba(0, 0, 0, 0.3);
  --shadow-lg: rgba(0, 0, 0, 0.4);
  --selection-bg: rgba(212, 165, 116, 0.25);
}

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

html {
  font-size: 16px;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

body {
  font-family: 'Georgia', 'Times New Roman', Times, serif;
  background: var(--bg-primary);
  color: var(--text-primary);
  line-height: 1.7;
  overflow: hidden;
  height: 100vh;
}

/* ============ Layout ============ */
.sidebar {
  position: fixed;
  left: 0;
  top: 0;
  bottom: 0;
  width: var(--sidebar-width);
  background: var(--bg-secondary);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  z-index: 100;
  transform: translateX(0);
  transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

.main-content {
  margin-left: var(--sidebar-width);
  height: 100vh;
  display: flex;
  flex-direction: column;
  transition: margin-left 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

/* ============ Sidebar ============ */
.sidebar-header {
  padding: 24px 20px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.sidebar-title {
  font-size: 1.25rem;
  font-weight: 600;
  color: var(--text-primary);
  letter-spacing: 0.02em;
}

.sidebar-subtitle {
  font-size: 0.8rem;
  color: var(--text-muted);
  font-style: italic;
  margin-top: 2px;
  display: block;
}

.sidebar-nav {
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
  padding: 16px 0;
}

.nav-testament {
  margin-bottom: 8px;
}

.testament-title {
  font-size: 0.7rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--text-muted);
  padding: 12px 20px 8px;
}

.books-list {
  display: flex;
  flex-direction: column;
}

.book-item {
  border-bottom: 1px solid transparent;
}

.book-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 20px;
  cursor: pointer;
  transition: background 0.15s ease;
  user-select: none;
}

.book-header:hover {
  background: var(--accent-light);
}

.book-name {
  font-size: 0.9rem;
  color: var(--text-primary);
}

.book-arrow {
  width: 16px;
  height: 16px;
  color: var(--text-muted);
  transition: transform 0.2s ease;
  flex-shrink: 0;
}

.book-item.expanded .book-arrow {
  transform: rotate(180deg);
}

.chapters-grid {
  display: none;
  grid-template-columns: repeat(5, 1fr);
  gap: 6px;
  padding: 8px 20px 16px;
  background: var(--bg-tertiary);
}

.book-item.expanded .chapters-grid {
  display: grid;
}

.chapter-btn {
  aspect-ratio: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.8rem;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--text-secondary);
  cursor: pointer;
  transition: all 0.15s ease;
}

.chapter-btn:hover {
  background: var(--accent);
  border-color: var(--accent);
  color: white;
}

.chapter-btn.active {
  background: var(--accent);
  border-color: var(--accent);
  color: white;
}

/* ============ Top Bar ============ */
.top-bar {
  height: var(--topbar-height);
  background: var(--bg-secondary);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  padding: 0 16px;
  gap: 12px;
  flex-shrink: 0;
}

.menu-btn {
  display: none;
  width: 40px;
  height: 40px;
  border: none;
  background: transparent;
  color: var(--text-primary);
  cursor: pointer;
  border-radius: 8px;
  align-items: center;
  justify-content: center;
  transition: background 0.15s ease;
}

.menu-btn:hover {
  background: var(--bg-tertiary);
}

.current-location {
  flex: 1;
  font-size: 1rem;
  font-weight: 500;
  color: var(--text-primary);
}

.theme-btn {
  width: 40px;
  height: 40px;
  border: none;
  background: transparent;
  color: var(--text-primary);
  cursor: pointer;
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.15s ease;
}

.theme-btn:hover {
  background: var(--bg-tertiary);
}

.sun-icon { display: none; }
.moon-icon { display: block; }
html.dark .sun-icon { display: block; }
html.dark .moon-icon { display: none; }

/* ============ Bible Content ============ */
.bible-scroll {
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
  scroll-behavior: auto;
}

.scroll-content {
  max-width: 680px;
  margin: 0 auto;
  padding: 40px 24px 120px;
}

/* Chapter */
.chapter {
  margin-bottom: 64px;
}

.chapter-header {
  text-align: center;
  margin-bottom: 32px;
  padding-bottom: 20px;
  border-bottom: 1px solid var(--border);
}

.chapter-book {
  font-size: 1.5rem;
  font-weight: 400;
  color: var(--accent);
  margin-bottom: 4px;
}

.chapter-num {
  font-size: 0.9rem;
  color: var(--text-muted);
  font-style: italic;
}

/* Verses */
.verses {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.verse {
  display: flex;
  gap: 12px;
  line-height: 1.8;
}

.verse-number {
  flex-shrink: 0;
  width: 28px;
  font-size: 0.75rem;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  font-weight: 600;
  color: var(--verse-num);
  text-align: right;
  padding-top: 3px;
  user-select: none;
}

.verse-text {
  flex: 1;
  color: var(--text-primary);
}

/* Testament Divider */
.testament-divider {
  display: flex;
  align-items: center;
  gap: 20px;
  margin: 80px 0;
}

.testament-divider::before,
.testament-divider::after {
  content: '';
  flex: 1;
  height: 1px;
  background: var(--border);
}

.testament-divider span {
  font-size: 0.8rem;
  text-transform: uppercase;
  letter-spacing: 0.15em;
  color: var(--text-muted);
  white-space: nowrap;
}

/* ============ Selection Menu ============ */
.selection-menu {
  position: fixed;
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: 8px;
  box-shadow: 0 4px 20px var(--shadow-lg);
  padding: 4px;
  z-index: 1000;
  opacity: 0;
  visibility: hidden;
  transform: translateY(8px);
  transition: all 0.15s ease;
}

.selection-menu.visible {
  opacity: 1;
  visibility: visible;
  transform: translateY(0);
}

.selection-btn {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 14px;
  border: none;
  background: transparent;
  color: var(--text-primary);
  font-size: 0.875rem;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  cursor: pointer;
  border-radius: 6px;
  transition: background 0.15s ease;
  white-space: nowrap;
}

.selection-btn:hover {
  background: var(--accent-light);
}

/* ============ Toast ============ */
.toast {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%) translateY(100px);
  background: var(--text-primary);
  color: var(--bg-primary);
  padding: 12px 24px;
  border-radius: 8px;
  font-size: 0.875rem;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  box-shadow: 0 4px 20px var(--shadow-lg);
  opacity: 0;
  transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  z-index: 1001;
}

.toast.visible {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

/* ============ Overlay ============ */
.overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.5);
  z-index: 90;
  opacity: 0;
  visibility: hidden;
  transition: all 0.3s ease;
}

.overlay.visible {
  opacity: 1;
  visibility: visible;
}

/* ============ Selection Highlight ============ */
::selection {
  background: var(--selection-bg);
}

/* ============ Scrollbar ============ */
.sidebar-nav::-webkit-scrollbar,
.bible-scroll::-webkit-scrollbar {
  width: 6px;
}

.sidebar-nav::-webkit-scrollbar-track,
.bible-scroll::-webkit-scrollbar-track {
  background: transparent;
}

.sidebar-nav::-webkit-scrollbar-thumb,
.bible-scroll::-webkit-scrollbar-thumb {
  background: var(--border);
  border-radius: 3px;
}

.sidebar-nav::-webkit-scrollbar-thumb:hover,
.bible-scroll::-webkit-scrollbar-thumb:hover {
  background: var(--text-muted);
}

/* ============ Loading State ============ */
.loading {
  text-align: center;
  padding: 40px;
  color: var(--text-muted);
  font-style: italic;
}

/* ============ Responsive ============ */
@media (max-width: 900px) {
  .sidebar {
    transform: translateX(-100%);
    box-shadow: none;
  }

  .sidebar.open {
    transform: translateX(0);
    box-shadow: 4px 0 20px var(--shadow-lg);
  }

  .main-content {
    margin-left: 0;
  }

  .menu-btn {
    display: flex;
  }

  .scroll-content {
    padding: 32px 20px 100px;
  }
}

@media (max-width: 480px) {
  .sidebar {
    width: 100%;
  }

  .scroll-content {
    padding: 24px 16px 80px;
  }

  .chapter-book {
    font-size: 1.3rem;
  }

  .verse {
    gap: 8px;
  }

  .verse-number {
    width: 24px;
  }
}

/* ============ Focus States ============ */
.book-header:focus-visible,
.chapter-btn:focus-visible,
.menu-btn:focus-visible,
.theme-btn:focus-visible,
.selection-btn:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}
