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

:root, [data-theme="light"] {
  --bg: #f5f5f0;
  --surface: #fff;
  --border: #d4d0c8;
  --text: #2c2c2c;
  --text-muted: #666;
  --accent: #4a5568;
  --highlight: #fffde7;
  --header-bg: #3b3f4a;
  --header-text: #f0ece4;
  --radius: 6px;
  --highlight-border: #f9a825;
  --verse-hover: rgba(0,0,0,0.03);
  --popup-shadow: rgba(0,0,0,0.15);
}

[data-theme="dark"] {
  --bg: #1a1a2e;
  --surface: #22223a;
  --border: #333355;
  --text: #e0ddd5;
  --text-muted: #9a97a0;
  --accent: #8eaadc;
  --highlight: #2a2a50;
  --highlight-border: #6a6adb;
  --header-bg: #16162a;
  --header-text: #e0ddd5;
  --verse-hover: rgba(255,255,255,0.04);
  --popup-shadow: rgba(0,0,0,0.4);
}

html, body {
  height: 100%;
}

body {
  font-family: 'Georgia', 'Times New Roman', serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.6;
  display: flex;
  flex-direction: column;
}

/* --- Loading Overlay --- */
#loading-overlay {
  position: fixed;
  inset: 0;
  background: rgba(245, 245, 240, 0.95);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  transition: opacity 0.3s;
}

#loading-overlay.hidden {
  opacity: 0;
  pointer-events: none;
}

.spinner {
  width: 40px;
  height: 40px;
  border: 3px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
  margin-bottom: 16px;
}

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

#loading-text {
  font-size: 14px;
  color: var(--text-muted);
}

/* --- Header / Nav --- */
.app-header {
  background: var(--header-bg);
  color: var(--header-text);
  padding: 12px 20px;
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: nowrap;
}

.app-title {
  font-size: 18px;
  font-weight: bold;
  white-space: nowrap;
}

.nav-controls {
  display: flex;
  align-items: center;
  gap: 8px;
  flex: 1;
  min-width: 0;
}

.nav-controls select {
  padding: 6px 10px;
  border: 1px solid rgba(255,255,255,0.2);
  border-radius: var(--radius);
  background: rgba(255,255,255,0.1);
  color: var(--header-text);
  font-family: inherit;
  font-size: 14px;
  cursor: pointer;
  min-width: 0;
}

#book-select {
  flex: 1;
  min-width: 0;
}

#chapter-select,
#verse-select {
  width: 52px;
  flex-shrink: 0;
}

.nav-controls select option {
  background: var(--header-bg);
  color: var(--header-text);
}

.theme-btn {
  background: none;
  border: 1px solid rgba(255,255,255,0.2);
  border-radius: var(--radius);
  font-size: 16px;
  padding: 6px 8px;
  cursor: pointer;
  line-height: normal;
  flex-shrink: 0;
}

/* --- Version Picker --- */
.version-picker {
  position: relative;
}

.version-btn {
  font-size: 16px;
  background: none;
  border: 1px solid rgba(255,255,255,0.2);
  border-radius: var(--radius);
  padding: 6px 8px;
  cursor: pointer;
  line-height: normal;
}

.version-popup {
  position: absolute;
  top: calc(100% + 6px);
  left: 0;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: 0 6px 20px var(--popup-shadow);
  z-index: 500;
  min-width: 220px;
  overflow: hidden;
}

.version-popup.hidden {
  display: none;
}

.version-list {
  padding: 6px 0;
}

.version-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 16px;
  cursor: pointer;
  font-size: 14px;
  color: var(--text);
  transition: background 0.1s;
  user-select: none;
}

.version-item:hover {
  background: var(--verse-hover);
}

.version-item.selected {
  font-weight: 700;
}

.version-check {
  width: 18px;
  text-align: center;
  font-size: 14px;
  flex-shrink: 0;
}

.version-item-name {
  flex: 1;
}

.version-item-full {
  font-size: 12px;
  color: var(--text-muted);
}

.version-close {
  display: block;
  width: 100%;
  padding: 10px;
  border: none;
  border-top: 1px solid var(--border);
  background: var(--bg);
  font-family: inherit;
  font-size: 14px;
  font-weight: 600;
  color: var(--accent);
  cursor: pointer;
  transition: background 0.1s;
}

.version-close:hover {
  background: var(--border);
}

/* --- Tab Bar --- */
.tab-bar {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: 0 16px;
  display: flex;
  gap: 0;
  overflow-x: auto;
}

.tab {
  padding: 10px 18px;
  border: none;
  background: none;
  font-family: inherit;
  font-size: 14px;
  font-weight: 600;
  color: var(--text-muted);
  cursor: pointer;
  border-bottom: 3px solid transparent;
  white-space: nowrap;
  transition: color 0.15s, border-color 0.15s;
}

.tab:hover {
  color: var(--text);
}

.tab-active {
  color: var(--accent);
  border-bottom-color: var(--accent);
}

.tab-hidden {
  display: none;
}

/* --- Content Panel --- */
.content-panel {
  flex: 1;
  overflow-y: auto;
  padding: 20px;
  max-width: 800px;
  width: 100%;
  margin: 0 auto;
}

.content-panel[data-dir="rtl"] {
  direction: rtl;
  text-align: right;
  font-size: 18px;
  line-height: 1.8;
}

.content-panel[data-dir="rtl"] .verse-num {
  margin-right: 0;
  margin-left: 2px;
}

/* --- Verses --- */
.verse-num {
  font-size: 11px;
  font-weight: bold;
  color: var(--accent);
  vertical-align: super;
  margin-right: 2px;
}

.chapter-verse {
  margin-bottom: 8px;
  padding: 6px 8px;
  border-radius: 3px;
  cursor: pointer;
  transition: background 0.15s;
}

.chapter-verse:hover {
  background: var(--verse-hover);
}

.chapter-verse.highlight {
  background: var(--highlight);
  border-left: 3px solid var(--highlight-border);
  padding-left: 12px;
}

.content-panel[data-dir="rtl"] .chapter-verse.highlight {
  border-left: none;
  border-right: 3px solid var(--highlight-border);
  padding-left: 8px;
  padding-right: 12px;
}

/* --- Empty State --- */
.empty-message {
  text-align: center;
  padding: 60px 20px;
  color: var(--text-muted);
  font-style: italic;
  font-size: 16px;
}

/* --- Paging Bar --- */
.paging-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 20px;
  background: var(--surface);
  border-top: 1px solid var(--border);
  flex-shrink: 0;
}

.paging-btn {
  padding: 8px 18px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  font-family: inherit;
  font-size: 14px;
  font-weight: 600;
  color: var(--accent);
  cursor: pointer;
  transition: background 0.1s;
}

.paging-btn:hover:not(:disabled) {
  background: var(--bg);
}

.paging-btn:disabled {
  opacity: 0.35;
  cursor: default;
}

.paging-label {
  font-size: 13px;
  color: var(--text-muted);
  text-align: center;
}

/* --- Responsive --- */
@media (max-width: 600px) {
  .app-header {
    padding: 8px 10px;
    gap: 6px;
  }

  .app-title {
    font-size: 14px;
  }

  .nav-controls {
    gap: 4px;
  }

  .nav-controls select {
    padding: 5px 4px;
    font-size: 13px;
  }

  #chapter-select,
  #verse-select {
    width: 42px;
  }

  .version-btn {
    font-size: 14px;
    padding: 5px 5px;
  }

  .theme-btn {
    font-size: 14px;
    padding: 5px 5px;
  }

  .tab {
    padding: 8px 14px;
    font-size: 13px;
  }

  .content-panel {
    padding: 12px;
  }
}
