@font-face{
  font-family:"Alkafeel Naskh";
  src:url("assets/ALKAFEELNASKH10.TTF") format("truetype");
  font-weight:normal;
  font-style:normal;
  font-display:swap;
}

:root{
  color-scheme:only light;
  --text-size:31px;
  --ink:#241d14;
  --gold:#9a6615;
  --gold-dark:#6c4d16;
  --page:#f4eee2;
}

*{box-sizing:border-box}
html{scroll-behavior:smooth;color-scheme:only light}
body{
  margin:0;
  min-height:100vh;
  background:var(--page);
  color:var(--ink);
  font-family:Tahoma,Arial,sans-serif;
  overflow-x:hidden;
}
button{font:inherit}

.book-pages{
  width:100%;
  padding:10px 10px 30px;
  display:flex;
  flex-direction:column;
  align-items:center;
  gap:22px;
}

.book-page{
  position:relative;
  width:min(920px,calc(100vw - 20px));
  aspect-ratio:799 / 1204;
  flex:0 0 auto;
  overflow:hidden;
  background:#fff url("assets/frame-cropped.png") center/100% 100% no-repeat;
  box-shadow:0 5px 20px rgba(62,43,14,.10);
}

.page-inner{
  position:absolute;
  top:7.7%;right:10.7%;bottom:11.2%;left:10.7%;
  inset:7.7% 10.7% 11.2%;
  display:flex;
  flex-direction:column;
  min-width:0;
  min-height:0;
}

.book-page:not(.first-page) .page-inner{
  inset:7.8% 10.7% 11.2%;
}

.heading{
  flex:0 0 auto;
  text-align:center;
  margin:0 0 12px;
}
h1{
  margin:0;
  color:#352812;
  font-family:"Alkafeel Naskh","Traditional Arabic",serif;
  font-size:clamp(36px,5.2vw,52px);
  line-height:1.4;
  font-weight:700;
}

.back-link{
  flex:0 0 auto;
  align-self:flex-start;
  margin:0 0 4px;
  color:var(--gold-dark);
  font-family:"Alkafeel Naskh","Traditional Arabic",serif;
  font-size:17px;
  font-weight:700;
  text-decoration:none;
  padding:4px 10px;
  border-radius:10px;
}
.back-link:hover{background:#f2e6c8}
.back-link:focus-visible{outline:3px solid #d5a53c;outline-offset:2px}

.controls{
  flex:0 0 auto;
  display:flex;
  align-items:center;
  justify-content:center;
  gap:10px;
  margin:5px auto 5px;
}
.controls button{
  min-height:50px;
  border:1px solid #cfb985;
  border-radius:14px;
  background:#fffaf0;
  color:var(--gold-dark);
  font-weight:700;
  cursor:pointer;
  box-shadow:0 4px 12px rgba(64,43,8,.10);
}
.size-btn{
  width:56px;
  font-size:20px;
}
.play-btn{
  min-width:190px;
  padding-inline:22px;
  display:inline-flex;
  align-items:center;
  justify-content:center;
  gap:9px;
  background:#76591d!important;
  border-color:#76591d!important;
  color:#fff!important;
}
.controls button:hover{filter:brightness(.98)}
.controls button:active{transform:translateY(1px)}
.controls button:focus-visible{outline:3px solid #d5a53c;outline-offset:3px}

.status{
  flex:0 0 auto;
  margin:0 0 8px;
  text-align:center;
  color:#776958;
  font-size:15px;
  line-height:1.7;
}

/* شريط تقدّم الصوت */
.audiobar{
  flex:0 0 auto;
  display:flex;
  align-items:center;
  gap:10px;
  margin:0 auto 13px;
  width:100%;
  max-width:560px;
}
.audiobar .time{
  font-family:"Alkafeel Naskh","Traditional Arabic",serif;
  font-size:15px;
  color:#6c4d16;
  min-width:52px;
  text-align:center;
  font-variant-numeric:tabular-nums;
}
.seek{
  flex:1 1 auto;
  -webkit-appearance:none;
  appearance:none;
  height:12px;
  border-radius:8px;
  background:#e2d4b4;
  cursor:pointer;
  outline:none;
}
.seek::-webkit-slider-thumb{
  -webkit-appearance:none;
  appearance:none;
  width:26px;height:26px;border-radius:50%;
  background:#76591d;border:3px solid #fffaf0;
  box-shadow:0 2px 6px rgba(64,43,8,.3);
  cursor:pointer;
}
.seek::-moz-range-thumb{
  width:26px;height:26px;border-radius:50%;
  background:#76591d;border:3px solid #fffaf0;cursor:pointer;
}

.page-text{
  flex:1 1 auto;
  min-height:0;
  overflow:hidden;
  font-family:"Alkafeel Naskh","Traditional Arabic","Noto Naskh Arabic",serif;
  font-size:var(--text-size);
  line-height:2.02;
  text-align:justify;
  text-align-last:right;
  overflow-wrap:normal;
  word-break:normal;
}
.paragraph{
  margin:0 0 18px;
  padding:3px 6px;
  border-radius:10px;
}
.paragraph.instruction{
  text-align:center;
  text-align-last:center;
  color:#7b581b;
  font-size:.86em;
  font-weight:700;
  margin-block:22px;
}
.paragraph.continued{
  margin-top:0;
}

.page-number{
  position:absolute;
  left:50%;
  bottom:.55%;
  transform:translateX(-50%);
  z-index:3;
  width:5.8%;
  aspect-ratio:1;
  display:grid;
  place-items:center;
  padding:0;
  text-align:center;
  color:#352812;
  background:transparent;
  border:0;
  border-radius:50%;
  font-family:"Alkafeel Naskh","Traditional Arabic",serif;
  font-size:clamp(11px,2vw,18px);
  font-weight:700;
  line-height:1;
  pointer-events:none;
}

/* ===== صفحة الفهرس ===== */
.index-page h1{
  font-size:clamp(26px,4.6vw,46px);
}
.toc-subtitle{
  margin:10px 0 0;
  color:var(--gold);
  font-family:"Alkafeel Naskh","Traditional Arabic",serif;
  font-size:clamp(15px,2.2vw,23px);
  line-height:1.5;
}
.toc-nav{
  flex:1 1 auto;
  min-height:0;
  display:flex;
  flex-direction:column;
}
.toc{
  flex:1 1 auto;
  min-height:0;
  overflow-y:auto;
  list-style:none;
  margin:14px 0 0;
  padding:0 4px 4px;
  display:flex;
  flex-direction:column;
  gap:11px;
  scrollbar-width:thin;
}
.toc a{
  display:flex;
  align-items:center;
  justify-content:space-between;
  gap:12px;
  padding:12px 18px;
  border:1px solid #d9c797;
  border-radius:14px;
  background:#fffaf0;
  color:#352812;
  text-decoration:none;
  font-family:"Alkafeel Naskh","Traditional Arabic",serif;
  font-size:clamp(15px,2.4vw,25px);
  font-weight:700;
  line-height:1.6;
  box-shadow:0 3px 10px rgba(64,43,8,.08);
  transition:background .15s, transform .1s;
}
.toc a:hover{background:#f6ecd3}
.toc a:active{transform:translateY(1px)}
.toc a:focus-visible{outline:3px solid #d5a53c;outline-offset:3px}
.toc .arrow{
  flex:0 0 auto;
  color:var(--gold);
  font-size:.8em;
}

@media(max-width:700px){
  :root{--text-size:23px}
  .book-pages{padding:5px 5px 18px;gap:12px}
  .book-page{width:calc(100vw - 10px);box-shadow:0 3px 12px rgba(62,43,14,.08)}
  .page-inner{inset:7.5% 10.5% 11%}
  .heading{margin-bottom:5px}
  h1{font-size:clamp(28px,8.5vw,40px);line-height:1.35}
    .back-link{font-size:14px;padding:3px 8px}
  .controls{gap:6px;margin-block:2px}
  .controls button{min-height:42px;border-radius:11px}
  .size-btn{width:44px;min-width:44px;font-size:17px}
  .play-btn{min-width:138px;padding-inline:10px;font-size:14px}
  .status{font-size:11px;line-height:1.45;margin-bottom:5px}
  .audiobar{gap:7px;margin-bottom:8px}
  .audiobar .time{font-size:13px;min-width:44px}
  .seek{height:10px}
  .seek::-webkit-slider-thumb{width:22px;height:22px}
  .page-text{line-height:1.85;text-align:right}
  .paragraph{padding-inline:2px;margin-bottom:10px}
  .paragraph.instruction{margin-block:12px}
  .page-number{bottom:.55%;font-size:clamp(10px,3vw,13px)}

  /* الفهرس على الهاتف: الإطار يتمدّد مع المحتوى بدل الارتفاع الثابت */
  .index-page{aspect-ratio:auto;height:auto;min-height:calc(100vh - 24px);min-height:calc(100svh - 24px)}
  .index-page .page-inner{position:static;inset:auto;padding:14% 11.5% 19%;height:auto}
  .index-page h1{font-size:24px;line-height:1.45}
  .toc-subtitle{font-size:13px;margin-top:6px}
  .toc-nav{flex:initial;display:block}
  .toc{flex:initial;overflow:visible;gap:8px;margin-top:12px;padding:0}
  .toc a{padding:11px 13px;border-radius:11px;font-size:15px;line-height:1.55}
  .toc .arrow{font-size:.75em}
}

@media(max-width:390px){
  :root{--text-size:21px}
  .page-inner{inset:7.2% 10.2% 10.7%}
  .play-btn{min-width:126px}
}

@media print{
  body{background:#fff}
  .book-pages{padding:0;gap:0}
  .book-page{
    width:100%;
    box-shadow:none;
    break-after:page;
    page-break-after:always;
  }
  .book-page:last-child{break-after:auto;page-break-after:auto}
}
