/* ===== CSS Custom Properties ===== */
:root {
  --primary: #1B5E20;
  --primary-light: #2E7D32;
  --primary-dark: #0D3B12;
  --gold: #C8A84E;
  --gold-light: #D4BA6A;
  --bg: #FAFAF5;
  --bg-card: #FFFFFF;
  --bg-sidebar: #F5F5EF;
  --text: #1A1A1A;
  --text-secondary: #555;
  --text-muted: #888;
  --border: #E0DDD5;
  --shadow: rgba(0,0,0,0.08);
  --radius: 12px;
  --radius-sm: 8px;
  --font-arabic: 'Amiri', 'Traditional Arabic', serif;
  --font-body: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  --sidebar-width: 280px;
  --header-height: 60px;
}

[data-theme="dark"] {
  --primary: #4CAF50;
  --primary-light: #66BB6A;
  --primary-dark: #388E3C;
  --gold: #D4BA6A;
  --gold-light: #E0CC8A;
  --bg: #121212;
  --bg-card: #1E1E1E;
  --bg-sidebar: #181818;
  --text: #E0E0E0;
  --text-secondary: #AAA;
  --text-muted: #777;
  --border: #333;
  --shadow: rgba(0,0,0,0.3);
}

/* ===== Reset ===== */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { scroll-behavior: smooth; }
body {
  font-family: var(--font-body);
  background: var(--bg);
  color: var(--text);
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
}
a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }

/* ===== Shared Nav ===== */
.nav {
  background: var(--primary);
  color: #fff;
  padding: 0 24px;
  height: var(--header-height);
  display: flex;
  align-items: center;
  justify-content: space-between;
  position: sticky;
  top: 0;
  z-index: 100;
  box-shadow: 0 2px 8px var(--shadow);
}
.nav-brand {
  font-size: 1.25rem;
  font-weight: 700;
  color: #fff;
  display: flex;
  align-items: center;
  gap: 8px;
}
.nav-brand:hover { text-decoration: none; }
.nav-brand .icon { font-size: 1.5rem; }
.nav-links { display: flex; gap: 24px; align-items: center; }
.nav-links a {
  color: rgba(255,255,255,0.9);
  font-size: 0.95rem;
  font-weight: 500;
  transition: color 0.2s;
}
.nav-links a:hover { color: #fff; text-decoration: none; }
.nav-hamburger {
  display: none;
  background: none;
  border: none;
  color: #fff;
  font-size: 1.5rem;
  cursor: pointer;
  padding: 4px;
}

/* ===== Landing Page ===== */
.hero {
  background: linear-gradient(135deg, var(--primary-dark) 0%, var(--primary) 50%, var(--primary-light) 100%);
  color: #fff;
  text-align: center;
  padding: 80px 24px 60px;
  position: relative;
  overflow: hidden;
}
.hero::before {
  content: '';
  position: absolute;
  top: 0; left: 0; right: 0; bottom: 0;
  background: url("data:image/svg+xml,%3Csvg width='60' height='60' viewBox='0 0 60 60' xmlns='http://www.w3.org/2000/svg'%3E%3Cg fill='none' fill-rule='evenodd'%3E%3Cg fill='%23ffffff' fill-opacity='0.03'%3E%3Cpath d='M36 34v-4h-2v4h-4v2h4v4h2v-4h4v-2h-4zm0-30V0h-2v4h-4v2h4v4h2V6h4V4h-4zM6 34v-4H4v4H0v2h4v4h2v-4h4v-2H6zM6 4V0H4v4H0v2h4v4h2V6h4V4H6z'/%3E%3C/g%3E%3C/g%3E%3C/svg%3E");
  opacity: 0.5;
}
.hero-content { position: relative; z-index: 1; max-width: 700px; margin: 0 auto; }
.hero h1 { font-size: 3rem; font-weight: 800; margin-bottom: 8px; }
.hero .subtitle {
  font-size: 1.25rem;
  opacity: 0.9;
  margin-bottom: 12px;
  font-weight: 300;
}
.hero .tagline {
  font-family: var(--font-arabic);
  font-size: 1.5rem;
  color: var(--gold-light);
  margin-bottom: 32px;
  direction: rtl;
}
.hero-buttons { display: flex; gap: 16px; justify-content: center; flex-wrap: wrap; }
.btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 14px 28px;
  border-radius: 50px;
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
  border: none;
  transition: transform 0.2s, box-shadow 0.2s;
}
.btn:hover { transform: translateY(-2px); box-shadow: 0 4px 16px rgba(0,0,0,0.2); text-decoration: none; }
.btn-primary { background: #fff; color: var(--primary-dark); }
.btn-secondary { background: rgba(255,255,255,0.15); color: #fff; border: 2px solid rgba(255,255,255,0.4); }
.btn-gold { background: var(--gold); color: #1a1a1a; }

/* Features Grid */
.features {
  max-width: 1100px;
  margin: 0 auto;
  padding: 60px 24px;
}
.features h2 {
  text-align: center;
  font-size: 2rem;
  margin-bottom: 40px;
  color: var(--text);
}
.features-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
  gap: 24px;
}
.feature-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 28px;
  transition: transform 0.2s, box-shadow 0.2s;
}
.feature-card:hover {
  transform: translateY(-4px);
  box-shadow: 0 8px 24px var(--shadow);
}
.feature-card .icon {
  font-size: 2rem;
  margin-bottom: 12px;
  display: block;
}
.feature-card h3 {
  font-size: 1.15rem;
  margin-bottom: 8px;
  color: var(--primary);
}
[data-theme="dark"] .feature-card h3 { color: var(--primary-light); }
.feature-card p { color: var(--text-secondary); font-size: 0.95rem; }

/* Reader Promo */
.reader-promo {
  background: var(--bg-card);
  border-top: 1px solid var(--border);
  border-bottom: 1px solid var(--border);
  padding: 60px 24px;
  text-align: center;
}
.reader-promo h2 { font-size: 2rem; margin-bottom: 12px; }
.reader-promo p { color: var(--text-secondary); max-width: 600px; margin: 0 auto 24px; font-size: 1.05rem; }

/* Footer */
.footer {
  background: var(--primary-dark);
  color: rgba(255,255,255,0.8);
  text-align: center;
  padding: 32px 24px;
}
.footer a { color: var(--gold-light); }
.footer-links { display: flex; gap: 24px; justify-content: center; margin-bottom: 12px; flex-wrap: wrap; }

/* ===== Reader Layout ===== */
.reader-layout {
  display: flex;
  height: calc(100vh - var(--header-height));
}

/* Sidebar */
.sidebar {
  width: var(--sidebar-width);
  background: var(--bg-sidebar);
  border-right: 1px solid var(--border);
  overflow-y: auto;
  flex-shrink: 0;
  transition: transform 0.3s ease;
}
.sidebar-search {
  padding: 12px;
  position: sticky;
  top: 0;
  background: var(--bg-sidebar);
  border-bottom: 1px solid var(--border);
  z-index: 1;
}
.sidebar-search input {
  width: 100%;
  padding: 8px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--bg-card);
  color: var(--text);
  font-size: 0.9rem;
  outline: none;
}
.sidebar-search input:focus { border-color: var(--primary); }
.surah-list { list-style: none; }
.surah-item {
  padding: 10px 16px;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 12px;
  border-bottom: 1px solid var(--border);
  transition: background 0.15s;
}
.surah-item:hover { background: rgba(27,94,32,0.06); }
[data-theme="dark"] .surah-item:hover { background: rgba(76,175,80,0.1); }
.surah-item.active {
  background: rgba(27,94,32,0.1);
  border-left: 3px solid var(--primary);
}
[data-theme="dark"] .surah-item.active { background: rgba(76,175,80,0.15); }
.surah-num {
  width: 32px;
  height: 32px;
  background: var(--primary);
  color: #fff;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.8rem;
  font-weight: 700;
  flex-shrink: 0;
}
.surah-info { flex: 1; min-width: 0; }
.surah-name-en {
  font-size: 0.9rem;
  font-weight: 600;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.surah-name-ar {
  font-family: var(--font-arabic);
  font-size: 1rem;
  color: var(--text-secondary);
  direction: rtl;
}
.surah-verses {
  font-size: 0.75rem;
  color: var(--text-muted);
}

/* Main Content */
.main-content {
  flex: 1;
  overflow-y: auto;
  padding: 24px;
  max-width: 900px;
  margin: 0 auto;
  width: 100%;
}

/* Surah Header Card */
.surah-header {
  background: linear-gradient(135deg, var(--primary-dark), var(--primary));
  color: #fff;
  border-radius: var(--radius);
  padding: 32px;
  text-align: center;
  margin-bottom: 24px;
}
.surah-header h1 {
  font-family: var(--font-arabic);
  font-size: 2.5rem;
  margin-bottom: 4px;
}
.surah-header h2 {
  font-size: 1.25rem;
  font-weight: 400;
  opacity: 0.9;
  margin-bottom: 8px;
}
.surah-header .verse-count {
  font-size: 0.9rem;
  opacity: 0.7;
}
.bismillah {
  font-family: var(--font-arabic);
  font-size: 1.75rem;
  color: var(--gold);
  text-align: center;
  margin-bottom: 24px;
  direction: rtl;
  padding: 16px 0;
  border-bottom: 1px solid var(--border);
}

/* Verse Cards */
.verse-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  margin-bottom: 16px;
  transition: box-shadow 0.2s;
  position: relative;
}
.verse-card:hover { box-shadow: 0 4px 16px var(--shadow); }
.verse-card.highlighted {
  border-color: var(--gold);
  box-shadow: 0 0 0 2px var(--gold), 0 4px 16px var(--shadow);
}
.verse-number-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  background: var(--primary);
  color: #fff;
  border-radius: 50%;
  font-size: 0.85rem;
  font-weight: 700;
  margin-bottom: 12px;
}
.verse-arabic {
  font-family: var(--font-arabic);
  font-size: 1.75rem;
  line-height: 2.2;
  direction: rtl;
  text-align: right;
  color: var(--text);
  margin-bottom: 12px;
  padding-bottom: 12px;
  border-bottom: 1px solid var(--border);
}
.verse-english {
  font-size: 1rem;
  color: var(--text-secondary);
  line-height: 1.7;
}
.verse-actions {
  display: flex;
  gap: 8px;
  margin-top: 12px;
  justify-content: flex-end;
}
.verse-action-btn {
  background: none;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 6px 12px;
  font-size: 0.8rem;
  color: var(--text-muted);
  cursor: pointer;
  transition: all 0.2s;
  display: flex;
  align-items: center;
  gap: 4px;
}
.verse-action-btn:hover { border-color: var(--primary); color: var(--primary); }
.verse-action-btn.bookmarked { color: var(--gold); border-color: var(--gold); }

/* Font size variants */
.font-small .verse-arabic { font-size: 1.4rem; line-height: 1.9; }
.font-small .verse-english { font-size: 0.9rem; }
.font-large .verse-arabic { font-size: 2.2rem; line-height: 2.5; }
.font-large .verse-english { font-size: 1.1rem; }

/* ===== Reader Header ===== */
.reader-header {
  display: flex;
  align-items: center;
  gap: 12px;
  flex: 1;
}
.surah-selector {
  background: rgba(255,255,255,0.15);
  border: 1px solid rgba(255,255,255,0.3);
  color: #fff;
  padding: 6px 12px;
  border-radius: var(--radius-sm);
  font-size: 0.9rem;
  cursor: pointer;
  outline: none;
  max-width: 200px;
}
.surah-selector option { background: var(--bg-card); color: var(--text); }
.header-actions { display: flex; gap: 8px; }
.header-btn {
  background: rgba(255,255,255,0.15);
  border: 1px solid rgba(255,255,255,0.3);
  color: #fff;
  width: 36px;
  height: 36px;
  border-radius: var(--radius-sm);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  font-size: 1.1rem;
  transition: background 0.2s;
}
.header-btn:hover { background: rgba(255,255,255,0.25); }

/* ===== Search Overlay ===== */
.search-overlay {
  position: fixed;
  top: 0; left: 0; right: 0; bottom: 0;
  background: rgba(0,0,0,0.5);
  z-index: 200;
  display: none;
  align-items: flex-start;
  justify-content: center;
  padding: 80px 24px;
}
.search-overlay.active { display: flex; }
.search-panel {
  background: var(--bg-card);
  border-radius: var(--radius);
  width: 100%;
  max-width: 600px;
  max-height: 70vh;
  display: flex;
  flex-direction: column;
  box-shadow: 0 16px 48px rgba(0,0,0,0.2);
}
.search-input-wrap {
  padding: 16px;
  border-bottom: 1px solid var(--border);
}
.search-input-wrap input {
  width: 100%;
  padding: 12px 16px;
  border: 2px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 1rem;
  background: var(--bg);
  color: var(--text);
  outline: none;
}
.search-input-wrap input:focus { border-color: var(--primary); }
.search-results {
  flex: 1;
  overflow-y: auto;
  padding: 8px;
}
.search-result-item {
  padding: 12px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: background 0.15s;
}
.search-result-item:hover { background: rgba(27,94,32,0.06); }
[data-theme="dark"] .search-result-item:hover { background: rgba(76,175,80,0.1); }
.search-result-key {
  font-size: 0.8rem;
  color: var(--primary);
  font-weight: 600;
  margin-bottom: 4px;
}
.search-result-arabic {
  font-family: var(--font-arabic);
  font-size: 1.1rem;
  direction: rtl;
  text-align: right;
  color: var(--text);
  margin-bottom: 4px;
}
.search-result-english {
  font-size: 0.85rem;
  color: var(--text-secondary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.search-hint {
  text-align: center;
  padding: 32px;
  color: var(--text-muted);
  font-size: 0.9rem;
}

/* ===== Settings Panel ===== */
.settings-panel {
  position: fixed;
  top: var(--header-height);
  right: 0;
  width: 300px;
  height: calc(100vh - var(--header-height));
  background: var(--bg-card);
  border-left: 1px solid var(--border);
  z-index: 150;
  padding: 24px;
  transform: translateX(100%);
  transition: transform 0.3s ease;
  box-shadow: -4px 0 16px var(--shadow);
  overflow-y: auto;
}
.settings-panel.active { transform: translateX(0); }
.settings-panel h3 { margin-bottom: 20px; font-size: 1.1rem; }
.setting-group { margin-bottom: 24px; }
.setting-group label {
  display: block;
  font-size: 0.85rem;
  color: var(--text-secondary);
  margin-bottom: 8px;
  font-weight: 600;
}
.setting-options { display: flex; gap: 8px; }
.setting-option {
  flex: 1;
  padding: 8px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  text-align: center;
  cursor: pointer;
  font-size: 0.85rem;
  background: var(--bg);
  color: var(--text);
  transition: all 0.2s;
}
.setting-option:hover { border-color: var(--primary); }
.setting-option.active {
  background: var(--primary);
  color: #fff;
  border-color: var(--primary);
}
.theme-toggle {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 0;
}
.toggle-switch {
  position: relative;
  width: 48px;
  height: 26px;
  background: var(--border);
  border-radius: 13px;
  cursor: pointer;
  transition: background 0.3s;
}
.toggle-switch.active { background: var(--primary); }
.toggle-switch::after {
  content: '';
  position: absolute;
  top: 3px;
  left: 3px;
  width: 20px;
  height: 20px;
  background: #fff;
  border-radius: 50%;
  transition: transform 0.3s;
}
.toggle-switch.active::after { transform: translateX(22px); }

/* ===== Bookmarks Panel ===== */
.bookmarks-panel {
  position: fixed;
  top: var(--header-height);
  right: 0;
  width: 340px;
  height: calc(100vh - var(--header-height));
  background: var(--bg-card);
  border-left: 1px solid var(--border);
  z-index: 150;
  transform: translateX(100%);
  transition: transform 0.3s ease;
  box-shadow: -4px 0 16px var(--shadow);
  display: flex;
  flex-direction: column;
}
.bookmarks-panel.active { transform: translateX(0); }
.bookmarks-header {
  padding: 16px;
  border-bottom: 1px solid var(--border);
  font-weight: 600;
  font-size: 1.05rem;
}
.bookmarks-list {
  flex: 1;
  overflow-y: auto;
  padding: 8px;
}
.bookmark-item {
  padding: 12px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  border-bottom: 1px solid var(--border);
  transition: background 0.15s;
}
.bookmark-item:hover { background: rgba(27,94,32,0.06); }
[data-theme="dark"] .bookmark-item:hover { background: rgba(76,175,80,0.1); }
.bookmark-key { font-weight: 600; color: var(--primary); font-size: 0.85rem; margin-bottom: 4px; }
.bookmark-text {
  font-size: 0.85rem;
  color: var(--text-secondary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.bookmark-remove {
  float: right;
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  font-size: 1rem;
  padding: 0 4px;
}
.bookmark-remove:hover { color: #e53935; }
.bookmarks-empty {
  text-align: center;
  padding: 40px 24px;
  color: var(--text-muted);
}

/* ===== Loading ===== */
.loading {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 200px;
  color: var(--text-muted);
  font-size: 1rem;
}
.loading-spinner {
  width: 32px;
  height: 32px;
  border: 3px solid var(--border);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
  margin-right: 12px;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ===== Surah Nav (bottom of verse list) ===== */
.surah-nav {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 24px 0;
  margin-top: 16px;
  border-top: 1px solid var(--border);
}
.surah-nav-btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 10px 20px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text);
  cursor: pointer;
  font-size: 0.9rem;
  transition: all 0.2s;
}
.surah-nav-btn:hover {
  border-color: var(--primary);
  color: var(--primary);
}
.surah-nav-btn:disabled {
  opacity: 0.4;
  cursor: default;
}

/* ===== Responsive ===== */
@media (max-width: 768px) {
  .nav-links { display: none; }
  .nav-links.open {
    display: flex;
    flex-direction: column;
    position: absolute;
    top: var(--header-height);
    left: 0; right: 0;
    background: var(--primary);
    padding: 16px 24px;
    gap: 16px;
    box-shadow: 0 4px 16px var(--shadow);
  }
  .nav-hamburger { display: block; }

  .hero h1 { font-size: 2rem; }
  .hero .subtitle { font-size: 1rem; }
  .hero .tagline { font-size: 1.2rem; }

  .features-grid { grid-template-columns: 1fr; }

  /* Reader mobile */
  .sidebar {
    position: fixed;
    top: var(--header-height);
    left: 0;
    bottom: 0;
    z-index: 150;
    transform: translateX(-100%);
    box-shadow: 4px 0 16px var(--shadow);
  }
  .sidebar.open { transform: translateX(0); }
  .sidebar-overlay {
    position: fixed;
    top: var(--header-height);
    left: 0; right: 0; bottom: 0;
    background: rgba(0,0,0,0.4);
    z-index: 140;
    display: none;
  }
  .sidebar-overlay.active { display: block; }

  .main-content { padding: 16px; }
  .surah-header { padding: 24px 16px; }
  .surah-header h1 { font-size: 2rem; }
  .verse-arabic { font-size: 1.4rem; line-height: 2; }

  .settings-panel, .bookmarks-panel { width: 100%; }

  .search-overlay { padding: 20px 16px; }
}

/* ===== Scrollbar ===== */
::-webkit-scrollbar { width: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--text-muted); }

/* ===== Print ===== */
@media print {
  .nav, .sidebar, .header-actions, .verse-actions, .surah-nav { display: none !important; }
  .main-content { padding: 0; max-width: 100%; }
  .verse-card { break-inside: avoid; border: none; padding: 12px 0; }
}
