/* ══════════════════════════════════════════════════════════
   Quran Aziz — Continuous Scroll Viewer
   Design: Al-Marifat.org palette
   ══════════════════════════════════════════════════════════ */

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

:root {
  --primary:     #1A5C52;
  --primary-hv:  #14473F;
  --primary-lt:  #E8F4F2;
  --dark:        #0d0d0d;
  --navy:        #1e293b;
  --navy-lt:     #2d3f57;
  --gold:        #C9A84C;
  --green-lt:    #73a15b;
  --muted:       #7A7A7A;
  --border:      rgba(255,255,255,0.08);
  --sidebar-w:   272px;
  --header-h:    52px;
  --controls-h:  52px;
  --radius:      8px;
  --shadow:      0 4px 24px rgba(0,0,0,0.5);
  --trans:       0.2s ease;

  /* Page width: controlled by zoom slider */
  --page-max-w:  780px;
}

html, body {
  height: 100%;
  overflow: hidden;
  font-family: "DM Sans", system-ui, sans-serif;
  background: var(--dark);
  color: #e0e8e0;
  -webkit-font-smoothing: antialiased;
}

/* ── Header ─────────────────────────────────────────────── */
#header {
  position: fixed; top: 0; left: 0; right: 0; z-index: 200;
  height: var(--header-h);
  display: flex; align-items: center; gap: 10px;
  padding: 0 14px;
  background: var(--navy);
  border-bottom: 1px solid var(--border);
  box-shadow: 0 2px 12px rgba(0,0,0,0.4);
}

.icon-btn {
  width: 34px; height: 34px;
  display: flex; align-items: center; justify-content: center;
  background: transparent; border: none; color: #c8d6e5;
  border-radius: 7px; cursor: pointer;
  transition: background var(--trans), color var(--trans);
  flex-shrink: 0;
}
.icon-btn:hover { background: rgba(255,255,255,0.1); color: #fff; }

.header-brand {
  display: flex; align-items: center; gap: 8px;
  font-family: "Cormorant Garamond", Georgia, serif;
  font-size: 1.2rem; font-weight: 700; color: #fff;
  white-space: nowrap; flex-shrink: 0;
}
.brand-dot {
  width: 7px; height: 7px; border-radius: 50%;
  background: var(--gold); flex-shrink: 0;
}

.header-search {
  flex: 1; max-width: 360px; position: relative;
  display: flex; align-items: center;
  background: rgba(255,255,255,0.07);
  border: 1px solid var(--border); border-radius: 20px;
  padding: 0 12px; gap: 7px;
  transition: border-color var(--trans);
}
.header-search:focus-within { border-color: var(--primary); }
.header-search svg { color: var(--muted); flex-shrink: 0; }
#searchInput {
  flex: 1; background: transparent; border: none; outline: none;
  color: #e0e8e0; font-size: 0.88rem;
  font-family: "DM Sans", sans-serif; padding: 7px 0;
}
#searchInput::placeholder { color: var(--muted); }

.search-dropdown {
  position: absolute; top: calc(100% + 6px); left: 0; right: 0;
  background: var(--navy); border: 1px solid var(--border);
  border-radius: var(--radius); overflow-y: auto; max-height: 300px;
  box-shadow: var(--shadow); z-index: 300;
}
.search-item {
  padding: 9px 14px; cursor: pointer;
  display: flex; align-items: center; gap: 10px;
  border-bottom: 1px solid var(--border);
  transition: background var(--trans);
}
.search-item:last-child { border-bottom: none; }
.search-item:hover { background: rgba(26,92,82,0.3); }
.search-item .s-type { font-size: 0.68rem; font-weight: 600; text-transform: uppercase; color: var(--gold); min-width: 36px; }
.search-item .s-name { font-size: 0.88rem; color: #e0e8e0; flex: 1; }
.search-item .s-ar  { font-size: 1rem; color: var(--primary-lt); direction: rtl; }

.header-actions { margin-left: auto; }

/* ── Layout ─────────────────────────────────────────────── */
.layout {
  display: flex;
  margin-top: var(--header-h);
  height: calc(100vh - var(--header-h));
  overflow: hidden;
}

/* ── Sidebar ─────────────────────────────────────────────── */
#sidebar {
  width: var(--sidebar-w);
  background: var(--navy);
  border-right: 1px solid var(--border);
  display: flex; flex-direction: column;
  flex-shrink: 0;
  transition: width var(--trans);
  overflow: hidden;
}
#sidebar.collapsed { width: 0; }

.sidebar-inner {
  width: var(--sidebar-w);
  display: flex; flex-direction: column;
  height: 100%; overflow: hidden;
}

.tab-bar { display: flex; border-bottom: 1px solid var(--border); flex-shrink: 0; }
.tab-btn {
  flex: 1; padding: 11px 8px;
  background: transparent; border: none; cursor: pointer;
  display: flex; flex-direction: column; align-items: center; gap: 2px;
  border-bottom: 2px solid transparent;
  transition: border-color var(--trans), color var(--trans);
  color: var(--muted);
}
.tab-btn.active { border-bottom-color: var(--primary); color: #fff; }
.tab-btn:hover:not(.active) { background: rgba(255,255,255,0.04); color: #ccc; }
.tab-ar { font-size: 1rem; direction: rtl; }
.tab-en { font-size: 0.67rem; letter-spacing: 0.5px; text-transform: uppercase; }

/* Index list */
.index-list {
  flex: 1; overflow-y: auto; scroll-behavior: smooth;
}
.index-list::-webkit-scrollbar { width: 3px; }
.index-list::-webkit-scrollbar-thumb { background: var(--primary); border-radius: 2px; }
.hidden { display: none !important; }

.index-item {
  display: flex; align-items: center; gap: 9px;
  padding: 9px 12px; cursor: pointer;
  border-left: 3px solid transparent;
  border-bottom: 1px solid rgba(255,255,255,0.04);
  transition: background var(--trans), border-color var(--trans);
}
.index-item:hover  { background: rgba(26,92,82,0.2); border-left-color: var(--green-lt); }
.index-item.active { background: rgba(26,92,82,0.38); border-left-color: var(--primary); }

.item-num {
  width: 24px; height: 24px; border-radius: 50%;
  background: rgba(26,92,82,0.3);
  display: flex; align-items: center; justify-content: center;
  font-size: 0.7rem; font-weight: 600; color: var(--primary-lt);
  flex-shrink: 0;
}
.index-item.active .item-num { background: var(--primary); color: #fff; }

.item-text { flex: 1; min-width: 0; }
.item-en { font-size: 0.83rem; color: #ccd8cc; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.item-ar { font-size: 0.92rem; color: var(--primary-lt); direction: rtl; text-align: right; }

.item-meta { text-align: right; flex-shrink: 0; }
.item-page { font-size: 0.68rem; color: var(--muted); display: block; }
.item-type { font-size: 0.62rem; text-transform: uppercase; letter-spacing: 0.4px; color: var(--gold); display: block; }

/* ── Main viewer — continuous scroll ─────────────────────── */
#viewer {
  flex: 1; overflow-y: scroll; overflow-x: hidden;
  background: #111;
  padding-bottom: calc(var(--controls-h) + 24px);
  scroll-behavior: smooth;
  -webkit-overflow-scrolling: touch;
  will-change: scroll-position;
}
#viewer::-webkit-scrollbar { width: 6px; }
#viewer::-webkit-scrollbar-track { background: #111; }
#viewer::-webkit-scrollbar-thumb { background: var(--primary); border-radius: 3px; }

/* Pages container */
#pagesContainer {
  display: flex; flex-direction: column;
  align-items: center;
  padding: 20px 12px 12px;
  gap: 12px;
}

/* Each page slot */
.page-slot {
  width: 100%;
  max-width: var(--page-max-w);
  position: relative;
  box-shadow: 0 4px 32px rgba(0,0,0,0.6);
  border-radius: 3px;
  overflow: hidden;
  background: #1a1a1a;
  /* Reserve space before image loads using aspect ratio */
  aspect-ratio: 0.69;
}

.page-slot img {
  display: block;
  width: 100%;
  height: auto;
  position: relative;
  z-index: 1;
  opacity: 0;
  transition: opacity 0.25s ease;
  transform: translateZ(0);
  will-change: opacity;
}
.page-slot img.loaded { opacity: 1; }

/* Loading skeleton */
.page-skeleton {
  position: absolute; inset: 0; z-index: 0;
  background: linear-gradient(90deg, #1a1a1a 25%, #242424 50%, #1a1a1a 75%);
  background-size: 200% 100%;
  animation: shimmer 1.4s infinite;
}
.page-slot img.loaded + .page-skeleton,
.page-slot.loaded .page-skeleton { display: none; }

@keyframes shimmer {
  0%   { background-position: 200% 0; }
  100% { background-position: -200% 0; }
}

/* Page number label on each slot */
.page-label {
  position: absolute; bottom: 6px; right: 8px; z-index: 2;
  font-size: 0.68rem; color: rgba(255,255,255,0.35);
  background: rgba(0,0,0,0.3); padding: 1px 5px; border-radius: 3px;
  pointer-events: none;
}

/* ── Floating controls bar ───────────────────────────────── */
.controls-bar {
  position: fixed; bottom: 14px;
  left: calc(var(--sidebar-w) + 50%);
  transform: translateX(-50%);
  z-index: 150;
  display: flex; align-items: center; gap: 12px;
  padding: 8px 16px;
  background: rgba(30, 41, 59, 0.95);
  backdrop-filter: blur(10px);
  border: 1px solid var(--border);
  border-radius: 40px;
  box-shadow: 0 4px 24px rgba(0,0,0,0.5);
  transition: left var(--trans);
  white-space: nowrap;
}
#sidebar.collapsed ~ * .controls-bar,
body.sidebar-collapsed .controls-bar {
  left: 50%;
}

.nav-controls { display: flex; align-items: center; gap: 7px; }
.nav-btn {
  width: 30px; height: 30px;
  display: flex; align-items: center; justify-content: center;
  background: var(--primary); color: #fff; border: none;
  border-radius: 50%; cursor: pointer;
  transition: background var(--trans);
  flex-shrink: 0;
}
.nav-btn:hover { background: var(--primary-hv); }
.nav-btn:disabled { background: #333; color: #555; cursor: not-allowed; }

.page-indicator { display: flex; align-items: center; gap: 5px; font-size: 0.88rem; color: #c0cedc; }
#pageInput {
  width: 50px; padding: 3px 5px; text-align: center;
  background: rgba(255,255,255,0.1); border: 1px solid var(--border);
  border-radius: 5px; color: #fff; font-size: 0.88rem;
  font-family: "DM Sans", sans-serif; outline: none;
  transition: border-color var(--trans);
}
#pageInput:focus { border-color: var(--primary); }
.page-sep { color: var(--muted); }

.context-badge {
  font-size: 0.78rem; color: var(--gold);
  font-family: "Cormorant Garamond", serif;
  border-left: 1px solid var(--border);
  border-right: 1px solid var(--border);
  padding: 0 12px;
  max-width: 200px;
  overflow: hidden; text-overflow: ellipsis;
}

.zoom-controls { display: flex; align-items: center; gap: 6px; }
.zoom-btn {
  width: 26px; height: 26px;
  display: flex; align-items: center; justify-content: center;
  background: rgba(255,255,255,0.08); border: 1px solid var(--border);
  border-radius: 50%; color: #c0cedc; cursor: pointer;
  font-size: 1rem; line-height: 1;
  transition: background var(--trans);
}
.zoom-btn:hover { background: var(--primary); color: #fff; border-color: var(--primary); }
#zoomLabel { font-size: 0.78rem; color: var(--muted); min-width: 36px; text-align: center; }

/* ── Overlay ─────────────────────────────────────────────── */
.overlay {
  position: fixed; inset: 0; z-index: 150;
  background: rgba(0,0,0,0.55);
  backdrop-filter: blur(2px);
}

/* ── Responsive ──────────────────────────────────────────── */
@media (max-width: 900px) {
  .context-badge { display: none; }
}

@media (max-width: 768px) {
  :root { --sidebar-w: 78vw; }
  #sidebar {
    position: fixed; top: var(--header-h); left: 0; bottom: 0;
    z-index: 160; width: 0;
  }
  #sidebar.open { width: var(--sidebar-w); }
  .header-search { max-width: 170px; }
  .brand-name { display: none; }
  .controls-bar { left: 50% !important; bottom: 10px; padding: 6px 12px; }
  .zoom-controls { display: none; }
}

@media (max-width: 480px) {
  .header-search { display: none; }
}

/* ── Landing Page ────────────────────────────────────────── */
.landing {
  position: fixed; inset: 0; z-index: 500;
  display: flex; align-items: center; justify-content: center;
  background: var(--dark);
  padding: 20px;
  animation: landingIn 0.5s ease both;
}
.landing.exiting { animation: landingOut 0.35s ease forwards; }

.landing-card {
  max-width: 460px; width: 100%;
  padding: 48px 40px 40px;
  background: var(--navy);
  border: 1px solid rgba(201,168,76,0.2);
  border-radius: 20px;
  box-shadow: 0 24px 80px rgba(0,0,0,0.7), 0 0 100px rgba(26,92,82,0.1);
  text-align: center;
  animation: cardIn 0.7s cubic-bezier(0.34,1.2,0.64,1) both;
}

.landing-emblem {
  display: flex; align-items: center; justify-content: center;
  gap: 7px; margin-bottom: 22px;
}
.e-dot {
  width: 7px; height: 7px; border-radius: 50%;
  background: var(--gold); opacity: 0.7;
}
.e-dot.mid { width: 11px; height: 11px; background: var(--primary); opacity: 1; }

.landing-title {
  font-family: "Cormorant Garamond", Georgia, serif;
  font-size: 3rem; font-weight: 700; color: #fff;
  line-height: 1; margin-bottom: 6px;
}
.landing-brand-sub {
  font-size: 0.72rem; letter-spacing: 2.5px; text-transform: uppercase;
  color: var(--gold); margin-bottom: 20px;
}
.landing-desc {
  font-size: 0.9rem; color: #6e8299; line-height: 1.8;
  margin-bottom: 36px;
}

.landing-actions { display: flex; flex-direction: column; gap: 12px; }

.landing-btn {
  display: flex; align-items: center; justify-content: space-between;
  padding: 15px 20px;
  background: var(--primary); color: #fff;
  border: 2px solid var(--primary); border-radius: 12px;
  cursor: pointer; text-align: left;
  transition: background var(--trans), border-color var(--trans);
}
.landing-btn:hover { background: var(--primary-hv); border-color: var(--primary-hv); }
.landing-btn.outline {
  background: transparent; color: #c8d6e5;
  border-color: rgba(255,255,255,0.12);
}
.landing-btn.outline:hover {
  background: rgba(255,255,255,0.05);
  border-color: rgba(255,255,255,0.28);
}
.lbtn-left { display: flex; flex-direction: column; gap: 2px; }
.lbtn-ar { font-size: 1.1rem; direction: rtl; }
.lbtn-en { font-size: 0.8rem; opacity: 0.75; }

@keyframes landingIn  { from { opacity: 0; } to { opacity: 1; } }
@keyframes landingOut { from { opacity: 1; } to { opacity: 0; } }
@keyframes cardIn     { from { transform: translateY(18px); opacity: 0; } to { transform: none; opacity: 1; } }

/* ── Onboarding ──────────────────────────────────────────── */
.onboarding {
  position: fixed; inset: 0; z-index: 400;
  display: flex; align-items: center; justify-content: center;
  padding: 20px;
  background: rgba(0,0,0,0.72);
  backdrop-filter: blur(4px);
  animation: landingIn 0.25s ease both;
}

.ob-card {
  max-width: 380px; width: 100%;
  background: var(--navy);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 32px 28px 24px;
  box-shadow: var(--shadow);
}
.ob-step-num {
  font-size: 0.68rem; color: var(--muted);
  text-transform: uppercase; letter-spacing: 1px;
  margin-bottom: 22px;
}
.ob-icon {
  color: var(--primary-lt);
  display: flex; justify-content: center;
  margin-bottom: 16px;
}
.ob-title {
  font-family: "Cormorant Garamond", serif;
  font-size: 1.45rem; font-weight: 700; color: #fff;
  margin-bottom: 10px;
}
.ob-text {
  font-size: 0.88rem; color: #7a8ea0; line-height: 1.75;
}
.ob-footer {
  display: flex; align-items: center; justify-content: space-between;
  margin-top: 28px;
}
.ob-dots { display: flex; gap: 6px; align-items: center; }
.ob-dot {
  width: 6px; height: 6px; border-radius: 50%;
  background: rgba(255,255,255,0.18);
  transition: all var(--trans);
}
.ob-dot.active { width: 18px; border-radius: 3px; background: var(--primary); }
.ob-btns { display: flex; align-items: center; gap: 10px; }
.ob-skip {
  background: none; border: none; color: var(--muted);
  font-size: 0.82rem; cursor: pointer; padding: 6px;
  font-family: "DM Sans", sans-serif;
}
.ob-skip:hover { color: #ccc; }
.ob-next {
  background: var(--primary); color: #fff; border: none;
  padding: 9px 20px; border-radius: 8px; cursor: pointer;
  font-size: 0.88rem; font-family: "DM Sans", sans-serif;
  font-weight: 500;
  transition: background var(--trans);
}
.ob-next:hover { background: var(--primary-hv); }

/* Para list uses larger Arabic only */
.para-ar { font-size: 1rem; line-height: 1.4; }

/* ── Download button (in controls bar) ──────────────────── */
.ctrl-dl-btn {
  background: none; border: none; cursor: pointer;
  color: rgba(255,255,255,0.55); padding: 6px 8px; border-radius: 8px;
  display: flex; align-items: center;
  transition: color var(--trans), background var(--trans);
  margin-left: 2px;
}
.ctrl-dl-btn:hover { color: #fff; background: rgba(255,255,255,0.1); }

/* ── Download panel ──────────────────────────────────────── */
.download-panel {
  position: fixed;
  bottom: calc(var(--controls-h) + 12px);
  left: 50%; transform: translateX(-50%);
  /* account for sidebar on desktop */
  margin-left: calc(var(--sidebar-w) / 2);
  width: 300px;
  background: var(--navy);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 16px;
  box-shadow: 0 12px 40px rgba(0,0,0,0.6);
  z-index: 200;
  animation: cardIn 0.2s ease both;
}
@media (max-width: 768px) {
  .download-panel { margin-left: 0; }
}

.dl-title {
  font-size: 0.72rem; text-transform: uppercase; letter-spacing: 1.2px;
  color: var(--muted); margin-bottom: 12px;
}

.dl-options { display: flex; flex-direction: column; gap: 4px; }

.dl-opt {
  display: flex; align-items: center; gap: 12px;
  background: none; border: none; cursor: pointer;
  color: #c8d6e5; text-align: left;
  padding: 10px 10px; border-radius: 8px;
  transition: background var(--trans);
  width: 100%;
}
.dl-opt:hover { background: rgba(255,255,255,0.07); }
.dl-opt svg { flex-shrink: 0; color: var(--primary-lt); }
.dl-opt-label { font-size: 0.88rem; color: #e0e8e0; font-weight: 500; }
.dl-opt-sub   { font-size: 0.75rem; color: var(--muted); margin-top: 1px; }

.dl-sep { border-top: 1px solid var(--border); margin: 6px 0; }

.dl-custom { padding: 4px 2px; }
.dl-custom-label { font-size: 0.78rem; color: var(--muted); margin-bottom: 8px; display: block; }
.dl-custom-inputs {
  display: flex; align-items: center; gap: 6px;
}
.dl-custom-inputs input {
  width: 68px; padding: 6px 8px;
  background: rgba(255,255,255,0.06); border: 1px solid var(--border);
  border-radius: 6px; color: #e0e8e0; font-size: 0.82rem;
  font-family: "DM Sans", sans-serif;
}
.dl-custom-inputs span { color: var(--muted); font-size: 0.85rem; }
.dl-custom-inputs button {
  padding: 6px 12px; background: var(--primary); color: #fff;
  border: none; border-radius: 6px; cursor: pointer; font-size: 0.82rem;
  font-family: "DM Sans", sans-serif;
  transition: background var(--trans);
}
.dl-custom-inputs button:hover { background: var(--primary-hv); }

/* Progress state */
.dl-progress { padding: 6px 2px; }
.dl-prog-text { font-size: 0.82rem; color: #c8d6e5; margin-bottom: 10px; }
.dl-prog-track {
  height: 4px; background: rgba(255,255,255,0.1); border-radius: 2px; overflow: hidden;
}
.dl-prog-fill {
  height: 100%; width: 0%; background: var(--primary);
  border-radius: 2px; transition: width 0.2s ease;
}

/* ── Front Matter Navigation ─────────────────────────────── */
.front-matter-list {
  padding: 8px 0 4px;
}
.fm-item {
  padding: 9px 18px;
  font-size: 0.82rem;
  font-family: "DM Sans", sans-serif;
  color: var(--text);
  cursor: pointer;
  border-left: 3px solid transparent;
  transition: background var(--trans), color var(--trans), border-color var(--trans);
  line-height: 1.3;
}
.fm-item:hover {
  background: var(--hover);
  color: var(--primary);
  border-left-color: var(--primary);
}
.fm-divider {
  height: 1px;
  background: var(--border);
  margin: 6px 14px 4px;
}

/* ── Sidebar Para label (replaces tab bar) ───────────────── */
.sidebar-section-label {
  padding: 8px 18px 6px;
  font-size: 0.67rem;
  font-weight: 600;
  letter-spacing: 1px;
  text-transform: uppercase;
  color: var(--muted);
  flex-shrink: 0;
}

/* ── View mode toggle (controls bar) ────────────────────── */
.view-mode-toggle {
  display: flex;
  background: rgba(255,255,255,0.07);
  border-radius: 6px;
  overflow: hidden;
  gap: 0;
  flex-shrink: 0;
}
.vm-btn {
  background: transparent;
  border: none;
  cursor: pointer;
  padding: 5px 9px;
  color: rgba(255,255,255,0.45);
  display: flex; align-items: center; justify-content: center;
  transition: background var(--trans), color var(--trans);
}
.vm-btn:hover { color: rgba(255,255,255,0.8); }
.vm-btn.active {
  background: var(--primary);
  color: #fff;
}

/* ── Splash screen ────────────────────────────────────────── */
.splash-screen {
  position: fixed;
  inset: 0;
  background: #0b1a16;
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 9999;
  opacity: 1;
  transition: opacity 0.7s ease;
}
.splash-screen.fade-out {
  opacity: 0;
  pointer-events: none;
}
.splash-img {
  max-height: 100vh;
  max-width: 100vw;
  object-fit: contain;
}

/* ── Single-page mode ─────────────────────────────────────── */
#pagesContainer.single-page-mode .page-slot {
  display: none;
}
#pagesContainer.single-page-mode .page-slot.spm-visible {
  display: flex;
}
