:root{
  --bg:#0f2e22;
  --card:#0f1f1a;   /* deep green-ish card */
  --text:#f0fff0;
  --muted:#b7d3a9;
  --accent:#39d98a;   /* vivid light green */
  --accent2:#2ee59d;  /* secondary green */
  --border:rgba(255,255,255,.10);
}

html, body { overflow-x: hidden; }

*{box-sizing:border-box}
body{
  margin:0;
  font-family: system-ui, -apple-system, Segoe UI, Roboto, Arial, sans-serif;
  background: radial-gradient(1200px 800px at 15% 10%, #0f2e22 0%, var(--bg) 55%);
  color:var(--text);
  line-height:1.55;
}
a{color:var(--accent); text-decoration:none}
a:hover{text-decoration:underline}

.container{
  max-width: 980px;
  margin: 0 auto;
  padding: 28px 18px 60px;
}

.header{
  display:flex;
  align-items:center;
  justify-content:space-between;
  gap:12px;
  padding: 14px 0 22px;
}
.brand{
  display:flex; flex-direction:column;
}
.brand h1{
  margin:0;
  font-size: 26px;
  letter-spacing:.2px;
}
.brand p{
  margin:6px 0 0;
  color:var(--muted);
  font-size: 14px;
}

.nav{
  display:flex;
  gap:10px;
  flex-wrap:wrap;
}
.nav a{
  padding:10px 12px;
  border:1px solid var(--border);
  border-radius: 10px;
  color:var(--text);
}
.nav a.active{
  border-color: rgba(57,217,138,.75);
  box-shadow: 0 0 0 3px rgba(57,217,138,.15);
}


.card.spaced{
  margin-bottom: 18px;
}

.card{
  background: rgba(15,31,26,.75);
  border:1px solid var(--border);
  border-radius: 16px;
  padding: 18px;
  box-shadow: 0 12px 40px rgba(0,0,0,.25);
}

.grid{
  display:grid;
  grid-template-columns: 1fr;
  gap:14px;
}
@media(min-width:780px){
  .grid.two{grid-template-columns: 1fr 1fr;}
}

.btn{
  display:inline-flex;
  align-items:center;
  justify-content:center;
  gap:10px;
  padding: 12px 14px;
  border-radius: 12px;
  border:1px solid var(--border);
  background: rgba(255,255,255,.05);
  color:var(--text);
  font-weight: 600;
}
.btn.primary{
  border-color: rgba(57,217,138,.55);
  background: linear-gradient(90deg, rgba(57,217,138,.22), rgba(46,229,157,.18));
}

.btn:hover{ text-decoration:none; filter:brightness(1.08); }

.small{color:var(--muted); font-size: 13px;}
hr.sep{
  border:none; height:1px; background: var(--border);
  margin:16px 0;
}

.list{
  margin:0;
  padding-left: 18px;
}
.list li{ margin: 7px 0; }

.reader-top{
  display:flex;
  flex-wrap:wrap;
  gap:10px;
  align-items:center;
  justify-content:space-between;
  margin-bottom: 12px;
}
.reader-controls{
  display:flex;
  flex-wrap:wrap;
  gap:10px;
  align-items:center;
}
.input{
  padding:10px 12px;
  border-radius: 10px;
  border:1px solid var(--border);
  background: rgba(0,0,0,.25);
  color:var(--text);
  min-width: 120px;
}
.hint{color:var(--muted); font-size: 12.5px;}

/* Hidden SEO keywords (invisible, but DOES NOT create horizontal scroll) */
.seo-tags{
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  clip-path: inset(50%);
  white-space: nowrap;
  border: 0;
}


.viewer{
  width:100%;
  height: 78vh;
  border:1px solid var(--border);
  border-radius: 14px;
  overflow:hidden;
  background: rgba(0,0,0,.25);
}
.viewer iframe{
  width:100%;
  height:100%;
  border:0;
}

.footer{
  margin-top: 18px;
  color: var(--muted);
  font-size: 13px;
}

.about-grid{
  display:grid;
  gap:16px;
}
@media(min-width:780px){
  .about-grid{
    grid-template-columns: 1fr 360px; /* text + image column */
    align-items:start;
  }
}

.about-side{
  display:flex;
  justify-content:flex-start;
}

/* thumbnail: constrained height, keeps aspect */
.thumb{
  display:block;
  max-height: 320px;   /* adjust to match your bullets height */
  width:auto;
  max-width:100%;
  border-radius:14px;
  border:1px solid var(--border);
  box-shadow: 0 12px 35px rgba(0,0,0,.35);
  cursor: zoom-in;
}

/* lightbox overlay */
.lightbox{
  display:none;
  position:fixed;
  inset:0;
  background: rgba(0,0,0,.75);
  z-index:9999;
  padding: 24px;
  align-items:center;
  justify-content:center;
}
.lightbox:target{
  display:flex;
}
.lightbox img{
  max-width: min(100%, 1100px);
  max-height: 90vh;
  border-radius:16px;
  border:1px solid rgba(255,255,255,.15);
}

/* ================================
   Read page layout + TOC (RTL + mobile drawer)
================================ */

.reader-layout{
  display:grid;
  grid-template-columns: 240px 1fr; /* TOC (right) + viewer (left) */
  gap:14px;
  align-items:start;
}

.reader-layout{
  align-items: stretch;     /* stretch both columns equally */
}

.reader-main{
  display: flex;
  flex-direction: column;
  min-height: calc(100vh - 260px); /* keeps viewer visible without pushing below */
}

.viewer{
  flex: 1;                  /* fill remaining height */
  height: auto;             /* override fixed 78vh when flex is active */
  min-height: 60vh;         /* safety */
}

.toc{
  height: 100%;
  max-height: none;         /* let it match reader height */
}

/* RTL: column 1 is the right side, so TOC goes to column 1 */
.toc{ 
  grid-column: 1; 
  width: 240px;
  max-width: 240px;
}

.reader-main{ grid-column: 2; min-width:0; }

/* Sidebar */
.toc{
  background: rgba(0,0,0,.18);
  border:1px solid var(--border);
  border-radius: 14px;
  overflow:hidden;

  position: sticky;
  top: 14px;
  max-height: calc(100vh - 28px);

  display:flex;
  flex-direction:column;
}

.toc-header{
  display:flex;
  align-items:center;
  justify-content:space-between;
  gap:10px;
  padding:12px 12px;
  border-bottom:1px solid var(--border);
}

.toc-title{
  font-weight: 800;
  font-size: 18px;
}

.toc-body{
  flex: 1;
  overflow: auto;           /* TOC has its own scroll */
  padding:10px 12px 12px;
  direction: ltr;        /* scrollbar + flow on the right */
  scrollbar-gutter: stable;  
}

.toc-list{
  display:flex;
  flex-direction:column;
  gap:8px;
}

.toc-item{
  display:flex;
  align-items:center;
  justify-content:space-between;
  gap:10px;
  direction: rtl;

  padding:10px 10px;
  border-radius: 10px;
  border:1px solid var(--border);
  background: rgba(255,255,255,.03);
  color: var(--text);
  text-decoration:none;
}
.toc-item:hover{ filter:brightness(1.08); text-decoration:none; }
.toc-item small{ 
  color: var(--muted); 
  direction: ltr;        /* numbers stay readable */
}

/* Main */
.reader-main{ min-width: 0; }

/* Jump form (prevents ugly wrapping) */
.jumpForm{
  display:flex;
  gap:10px;
  align-items:center;
  margin:0;
}
.jumpForm .input{ width: 140px; }

/* Button visibility */
.toc-open{ display:none; }
.toc-close{ display:none; }

/* Mobile drawer */
@media (max-width: 860px){
  .reader-layout{ grid-template-columns: 1fr; }

  .toc{
    position: fixed;
    top: 0;
    right: 0;               /* drawer from the RIGHT for Arabic */
    left: auto;
    height: 100vh;
    width: min(340px, 86vw);
    z-index: 50;

    transform: translateX(105%);
    transition: transform .18s ease;

    max-height: none;
    border-radius: 14px 0 0 14px;
  }

  .toc.open{ transform: translateX(0); }

  .toc-open{ display:inline-flex; }
  .toc-close{ display:inline-flex; }

  .toc-backdrop{
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,.45);
    z-index: 40;
  }
  
    /* ---- Mobile: prevent viewer collapse / blank screen ---- */
  .reader-main{
    min-height: auto !important;
  }

  .viewer{
    position: static !important;   /* disable sticky on mobile */
    max-height: none !important;   /* stop 100vh calc issues */
    height: 78vh !important;       /* give iframe a real height */
  }

  #pdfFrame{
    height: 100% !important;
    min-height: 100% !important;
  }


  .about-grid{
    grid-template-columns: 1fr;   /* stack instead of 1fr + 360px */
  }

  .about-side{
    width: 100%;
    max-width: none;
    justify-self: stretch;
  }

  .container{
    max-width: 100%;
    overflow-x: hidden;
  }
}

.toc-open, .toc-close, .toc-body details > summary { cursor: pointer; }

/* TOC search box area */
.toc-search{
  padding: 10px;
  border-bottom: 1px solid var(--border);
  background: rgba(0,0,0,.10);
}
.toc-search .input{
  width: 100%;
}

/* Active surah highlight */
.toc-item.active{
  border-color: rgba(80, 220, 140, .55);
  background: rgba(80, 220, 140, .10);
}
.toc-item.active small{
  color: rgba(160, 255, 210, .95);
}

.btn-row{
  display:flex;
  gap:10px;
  flex-wrap:wrap;
  align-items:center;
}

.toc-divider{
  height: 1px;
  background: var(--border);
  margin: 10px 0;
  opacity: .8;
}

/* Non-clickable section header row */
.toc-section{
  cursor: default;
  opacity: .95;
}
.toc-section:hover{
  transform: none;
  background: rgba(255,255,255,.04); /* subtle, same theme */
}

/* ===== Mobile safety patch (prevents blank screen) ===== */
@media (max-width: 860px){
  .reader-main{
    min-height: auto !important;
    display: block !important;
  }

  .viewer{
    height: 78vh !important;   /* stable height on mobile */
    min-height: 78vh !important;
    flex: none !important;
  }
  
  /* ===== Index page: make grids stack on mobile ===== */

  .about-grid{
    grid-template-columns: 1fr !important;
  }

  .about-side{
    justify-content: center !important;
  }

  .grid.two{
    grid-template-columns: 1fr !important;
  }

  .header{
    flex-direction: column;
    align-items: flex-start;
    gap: 10px;
  }

  .nav{
    flex-wrap: wrap;
    justify-content: flex-start;
  }

}


/* PDF.js render surface */
.pdfjs-viewer {
  width: 100%;
  background: #fff;
  border-radius: 16px;
  overflow: auto;
  -webkit-overflow-scrolling: touch;
  padding: 8px;
  max-height: 75vh;
}

.pdfjs-viewer canvas {
  display: block;
  width: 100%;
  height: auto;
}

/* PDF.js toolbar (hidden by default, shown only on mobile) */
.pdfjs-zoombar {
  display: none;                 /* default: hidden */
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 8px 10px;
  border-bottom: 1px solid rgba(0,0,0,.08);
  margin-bottom: 8px;            /* keep your spacing */
}

/* Show toolbar only on mobile */
@media (max-width: 860px) {
  .pdfjs-zoombar { display: flex; }
}

/* Small nav buttons */
.pdfjs-zoombar .btn.pdfnav {
  padding: 6px 10px;
  min-width: 38px;
  font-size: 16px;   /* match your regular button text size */
  line-height: 1;
}

/* Info label in the middle */
.pdfjs-zoombar .pdfinfo {
  min-width: 90px;
  text-align: center;
  opacity: .85;
}

/* Visual separator between nav and zoom */
.pdfjs-zoombar .pdfsep {
  display: inline-block;
  width: 1px;
  height: 22px;
  background: rgba(0,0,0,.12);
  margin: 0 4px;
}

/* PDF.js toolbar: responsive + never truncates */
#pdfjsZoombar{
  display: flex;
  flex-wrap: wrap;           /* key: allows second row */
  align-items: center;
  justify-content: center;   /* or space-between */
  gap: 8px;
  padding: 8px;
  max-width: 100%;
}

/* Each control/button keeps its size and stays clickable */
#pdfjsZoombar button,
#pdfjsZoombar a,
#pdfjsZoombar .btn {
  flex: 0 0 auto;            /* do NOT shrink */
  min-width: 40px;
  min-height: 40px;
}

/* Labels (like "PDF 1/10") should not force overflow */
#pdfjsZoombar .pdfPageInfo,
#pdfjsZoombar #pdfPageInfo {
  flex: 0 1 auto;
  min-width: 0;
  white-space: nowrap;
}
