/* Maktabah — tampilan ala kitab kuning: kertas kuning, tinta hitam-cokelat, judul bab bertinta merah */
:root {
  --paper: #f0e2ae;
  --paper-2: #e6d392;
  --paper-3: #dcc57a;
  --ink: #2b2118;
  --ink-2: #5a4a33;
  --rubric: #9c1c1f;
  --rule: #b69447;
  --focus: #1d5c8f;
  --shadow: 0 1px 0 rgba(43, 33, 24, .08);
  --ar-size: 25px;
  --ar-lh: 2.05;
  --latin: "Alegreya Sans", "Segoe UI", system-ui, sans-serif;
  --arabic: "Amiri", "Scheherazade New", "Traditional Arabic", serif;
  color-scheme: light;
}
[data-theme="putih"] {
  --paper: #fbfbf8;
  --paper-2: #efeee8;
  --paper-3: #e2e0d6;
  --ink: #1f1f1d;
  --ink-2: #5d5b55;
  --rubric: #9c1c1f;
  --rule: #c9c4b4;
}
[data-theme="malam"] {
  --paper: #191510;
  --paper-2: #241e16;
  --paper-3: #30281d;
  --ink: #e8dcb3;
  --ink-2: #a99870;
  --rubric: #e06b58;
  --rule: #5b4b30;
  --focus: #7fb5e0;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font: 17px/1.5 var(--latin);
  min-height: 100vh;
}
a { color: inherit; }
button, input { font: inherit; color: inherit; }
:focus-visible { outline: 3px solid var(--focus); outline-offset: 2px; border-radius: 4px; }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
[lang="ar"], .ar { font-family: var(--arabic); direction: rtl; }

.wrap { max-width: 760px; margin: 0 auto; padding: 0 20px; }

/* ---------- rak kitab ---------- */
.mast { padding: 34px 0 10px; display: grid; grid-template-columns: 1fr auto; align-items: end; gap: 12px; }
.mast h1 { margin: 0; font-weight: 700; font-size: 30px; letter-spacing: -.01em; }
.mast h1 .ar { display: block; font-size: 56px; line-height: 1.1; color: var(--rubric); font-weight: 700; margin-bottom: 2px; }
.mast p { margin: 6px 0 0; color: var(--ink-2); max-width: 34em; }
.iconbtn {
  border: 0; background: transparent; width: 44px; height: 44px; border-radius: 22px;
  display: inline-grid; place-items: center; cursor: pointer; color: var(--ink);
}
.iconbtn:hover { background: var(--paper-2); }
.iconbtn svg { width: 22px; height: 22px; }

.search {
  display: flex; align-items: center; gap: 8px; margin: 18px 0 8px;
  background: var(--paper-2); border-radius: 12px; padding: 0 14px; height: 50px;
}
.search svg { width: 20px; height: 20px; flex: none; color: var(--ink-2); }
.search input { flex: 1; border: 0; background: transparent; height: 100%; outline: none; min-width: 0; }
.search input::placeholder { color: var(--ink-2); }
.search:focus-within { box-shadow: 0 0 0 3px var(--focus); }

.links { display: flex; gap: 18px; flex-wrap: wrap; margin: 6px 0 0; font-size: 16px; }
.links a { color: var(--ink-2); text-decoration: underline; text-underline-offset: 3px; text-decoration-color: var(--rule); }

.resume {
  display: block; text-decoration: none; margin: 22px 0 6px; padding: 16px 18px;
  border-inline-start: 4px solid var(--rubric); background: var(--paper-2); border-radius: 0 10px 10px 0;
}
.resume small { color: var(--ink-2); display: block; }
.resume .ar { font-size: 24px; display: block; line-height: 1.6; }

.cat { margin-top: 34px; }
.cat-h { display: flex; justify-content: space-between; align-items: baseline; border-bottom: 2px solid var(--ink); padding-bottom: 6px; }
.cat-h h2 { margin: 0; font-size: 19px; font-weight: 700; }
.cat-h .ar { font-size: 22px; color: var(--rubric); }
.shelf { list-style: none; margin: 0; padding: 0; }
.shelf li { border-bottom: 1px solid var(--rule); }
.book {
  display: grid; grid-template-columns: 1fr auto; gap: 2px 16px; padding: 14px 2px; text-decoration: none; align-items: center;
}
.book:hover .b-ar { color: var(--rubric); }
.b-ar { grid-column: 1 / -1; font-family: var(--arabic); direction: rtl; font-size: 28px; line-height: 1.5; font-weight: 700; }
.b-name { font-weight: 500; }
.b-by { color: var(--ink-2); font-size: 15px; }
.b-meta { grid-row: 2 / span 2; grid-column: 2; text-align: end; font-size: 14px; color: var(--ink-2); white-space: nowrap; }
.saved { color: var(--ink); }
.saved::before { content: ""; display: inline-block; width: 8px; height: 8px; border-radius: 50%; background: var(--rubric); margin-inline-end: 6px; vertical-align: 1px; }
.empty { color: var(--ink-2); padding: 30px 0; }

footer.foot { color: var(--ink-2); font-size: 14px; padding: 40px 0 60px; }
footer.foot a { color: var(--ink-2); }

/* ---------- halaman kitab ---------- */
.topbar {
  position: sticky; top: 0; z-index: 5; background: var(--paper);
  display: flex; align-items: center; gap: 4px; height: 56px; border-bottom: 1px solid var(--rule);
}
.topbar .t { flex: 1; min-width: 0; font-size: 15px; color: var(--ink-2); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.topbar .t b { color: var(--ink); font-weight: 500; }

.cover { text-align: center; padding: 34px 0 18px; }
.cover .ar { font-size: 48px; line-height: 1.45; color: var(--rubric); font-weight: 700; margin: 0; }
.cover h1 { font-size: 22px; margin: 4px 0 2px; font-weight: 700; }
.cover .by { color: var(--ink-2); margin: 0; }
.cover .desc { max-width: 32em; margin: 16px auto 0; }
.orn { display: block; color: var(--rubric); font-family: var(--arabic); font-size: 22px; margin: 10px 0; }

.actions { display: flex; gap: 10px; justify-content: center; flex-wrap: wrap; margin: 20px 0 6px; }
.btn {
  border: 0; border-radius: 999px; padding: 0 22px; height: 48px; cursor: pointer; font-weight: 500;
  background: var(--ink); color: var(--paper); text-decoration: none; display: inline-flex; align-items: center; gap: 8px;
}
.btn.ghost { background: transparent; color: var(--ink); box-shadow: inset 0 0 0 1.5px var(--ink); }
.btn:disabled { opacity: .5; cursor: default; }
.status { text-align: center; color: var(--ink-2); font-size: 15px; min-height: 24px; margin: 8px 0; }
.bar { height: 6px; background: var(--paper-3); border-radius: 3px; overflow: hidden; max-width: 320px; margin: 10px auto 0; }
.bar i { display: block; height: 100%; width: 0; background: var(--rubric); transition: width .15s linear; }

.h2 { font-size: 19px; font-weight: 700; margin: 34px 0 6px; border-bottom: 2px solid var(--ink); padding-bottom: 6px; }
.toc { list-style: none; margin: 0; padding: 0; direction: rtl; font-family: var(--arabic); }
.toc a { display: block; padding: 9px 4px; text-decoration: none; font-size: 20px; line-height: 1.6; border-bottom: 1px solid var(--rule); }
.toc a:hover { color: var(--rubric); }
.toc .l2 a { padding-inline-start: 22px; font-size: 19px; }
.toc .l3 a { padding-inline-start: 44px; font-size: 18px; color: var(--ink-2); }
.toc .l4 a { padding-inline-start: 66px; font-size: 18px; color: var(--ink-2); }
.toc a.auto { font-family: var(--latin); direction: ltr; text-align: left; font-size: 16px; }
.toc a.auto span { font-family: var(--arabic); direction: rtl; display: block; text-align: right; color: var(--ink-2); font-size: 18px; }
.toc details > summary {
  list-style: none; cursor: pointer; padding: 9px 4px; font-size: 21px; line-height: 1.6; border-bottom: 1px solid var(--rule);
  display: flex; justify-content: space-between; gap: 10px;
}
.toc details > summary::-webkit-details-marker { display: none; }
.toc details > summary::after { content: "+"; font-family: var(--latin); color: var(--rubric); font-size: 22px; }
.toc details[open] > summary::after { content: "–"; }
.toc details[open] > summary { color: var(--rubric); }
.toc details ul { list-style: none; margin: 0; padding: 0; }
.toc details ul a { padding-inline-start: 22px; font-size: 19px; }
.toc .cnt { font-family: var(--latin); font-size: 14px; color: var(--ink-2); align-self: center; }

.info { font-size: 15px; color: var(--ink-2); margin: 30px 0 70px; }
.info dl { display: grid; grid-template-columns: max-content 1fr; gap: 4px 14px; margin: 0; }
.info dt { font-weight: 500; color: var(--ink); }
.info dd { margin: 0; }
.info .ar { font-size: 18px; }

/* hasil cari */
.results { list-style: none; padding: 0; margin: 0; }
.results a { display: block; text-decoration: none; padding: 12px 2px; border-bottom: 1px solid var(--rule); }
.results .where { font-size: 14px; color: var(--ink-2); display: block; }
.results .where .ar { font-size: 17px; }
.results .snip { font-family: var(--arabic); direction: rtl; display: block; font-size: 21px; line-height: 1.8; }
mark { background: color-mix(in srgb, var(--rubric) 22%, transparent); color: inherit; border-radius: 3px; padding: 0 1px; }

/* ---------- pembaca ---------- */
.reader { padding: 10px 0 120px; }
.page {
  direction: rtl; font-family: var(--arabic); font-size: var(--ar-size); line-height: var(--ar-lh);
  max-width: 34em; margin: 0 auto; position: relative;
}
.page .sec-h { text-align: center; color: var(--rubric); font-weight: 700; margin: 26px 0 14px; line-height: 1.6; text-wrap: balance; }
.page .sec-h.l1 { font-size: 1.35em; }
.page .sec-h.l2 { font-size: 1.2em; }
.page .sec-h.l3, .page .sec-h.l4 { font-size: 1.08em; }
.page .sec-h .cont { display: block; font-family: var(--latin); direction: ltr; font-size: 14px; font-weight: 400; color: var(--ink-2); }
.page .sec-h::after { content: "۞"; display: block; font-size: .7em; color: var(--rule); margin-top: 4px; }
.page .auto-h { text-align: center; font-family: var(--latin); direction: ltr; color: var(--ink-2); font-size: 15px; margin: 20px 0 10px; }
.page p { margin: 0 0 .55em; text-align: justify; text-justify: inter-word; hyphens: none; }
.page .no { color: var(--rubric); font-weight: 700; margin-inline-end: .3em; }
.page .no::before { content: "("; }
.page .no::after { content: ")"; }
.bait {
  display: grid; grid-template-columns: 1fr 1fr; gap: 0 1.4em; margin: 0 0 .35em; text-align: center;
}
.bait .s1, .bait .s2 { text-align: center; }
.bait .bn { grid-column: 1 / -1; display: none; }
.pg {
  position: absolute; right: calc(100% + 18px); font-family: var(--arabic); font-size: 15px; color: var(--rubric);
  white-space: nowrap; line-height: 1.4; margin-top: .45em;
}
.hit { background: color-mix(in srgb, var(--rubric) 14%, transparent); border-radius: 6px; box-shadow: 0 0 0 6px color-mix(in srgb, var(--rubric) 14%, transparent); }

.pager {
  position: fixed; bottom: 0; left: 0; right: 0; z-index: 6; background: var(--paper);
  border-top: 1px solid var(--rule); padding: 6px max(10px, env(safe-area-inset-left)) calc(6px + env(safe-area-inset-bottom));
}
.pager .in { max-width: 760px; margin: 0 auto; display: grid; grid-template-columns: 1fr auto auto 1fr; gap: 4px; align-items: center; }
.pager .nav { border: 0; background: transparent; height: 46px; border-radius: 10px; cursor: pointer; font-size: 16px; padding: 0 10px; display: flex; align-items: center; gap: 6px; }
.pager .nav:hover:not(:disabled) { background: var(--paper-2); }
.pager .nav:disabled { opacity: .35; cursor: default; }
.pager .next { justify-content: flex-start; }
.pager .prev { justify-content: flex-end; }
.pager svg { width: 20px; height: 20px; }
.pager .on { color: var(--rubric); }
.progress { position: fixed; top: 0; left: 0; height: 3px; background: var(--rubric); z-index: 7; width: 0; }

/* lembar pengaturan & daftar isi */
.sheet-bg { position: fixed; inset: 0; background: rgba(20, 14, 6, .45); z-index: 20; }
.sheet {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 21; background: var(--paper); border-radius: 18px 18px 0 0;
  max-height: 82vh; overflow: auto; padding: 8px 20px calc(24px + env(safe-area-inset-bottom));
  box-shadow: 0 -8px 30px rgba(0, 0, 0, .18); animation: up .22s ease-out;
}
.sheet .grab { width: 44px; height: 5px; border-radius: 3px; background: var(--rule); margin: 4px auto 10px; }
.sheet h2 { font-size: 19px; margin: 6px 0 14px; display: flex; justify-content: space-between; align-items: center; }
.sheet .in { max-width: 720px; margin: 0 auto; }
@keyframes up { from { transform: translateY(30px); opacity: 0; } to { transform: none; opacity: 1; } }

.row { display: flex; align-items: center; justify-content: space-between; gap: 14px; padding: 12px 0; border-bottom: 1px solid var(--rule); }
.row label { font-weight: 500; }
.seg { display: inline-flex; background: var(--paper-2); border-radius: 999px; padding: 3px; }
.seg button { border: 0; background: transparent; border-radius: 999px; height: 38px; padding: 0 14px; cursor: pointer; }
.seg button[aria-pressed="true"] { background: var(--ink); color: var(--paper); }
.sample { font-family: var(--arabic); direction: rtl; font-size: var(--ar-size); line-height: var(--ar-lh); text-align: center; padding: 14px 0 4px; }
input[type="range"] { accent-color: var(--rubric); width: 160px; }

.toast {
  position: fixed; left: 50%; bottom: 90px; transform: translateX(-50%); z-index: 30;
  background: var(--ink); color: var(--paper); padding: 10px 18px; border-radius: 999px; font-size: 15px;
}

@media (max-width: 899px) {
  .pg { position: static; display: block; text-align: center; font-size: 14px; margin: .2em 0 .4em; opacity: .85; }
}
@media (max-width: 560px) {
  .wrap { padding: 0 16px; }
  .mast h1 .ar { font-size: 48px; }
  .cover .ar { font-size: 40px; }
  .bait { grid-template-columns: 1fr; text-align: right; }
  .bait .s1, .bait .s2 { text-align: right; }
  .bait .s2 { padding-inline-start: 1.6em; }
  .pager .nav span { display: none; }
  .pager .in { grid-template-columns: 1fr auto auto 1fr; }
}
@media (prefers-reduced-motion: reduce) {
  * { animation: none !important; transition: none !important; }
}
