/* arabic subsets + latin subsets (the latter carry ( ) « » . , etc. so brackets mirror correctly) */
@font-face { font-family: "Amiri"; src: url(fonts/amiri-400.woff2) format("woff2"); font-weight: 400; font-display: swap;
  unicode-range: U+0600-06FF, U+0750-077F, U+0870-08FF, U+200C-200E, U+2010-2011, U+204F, U+2E41, U+FB50-FDFF, U+FE70-FEFC; }
@font-face { font-family: "Amiri"; src: url(fonts/amiri-400-latin.woff2) format("woff2"); font-weight: 400; font-display: swap;
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+2000-200B, U+2012-204E, U+2050-206F, U+20AC, U+2122, U+2212, U+FEFF, U+FFFD; }
@font-face { font-family: "Amiri"; src: url(fonts/amiri-700.woff2) format("woff2"); font-weight: 700; font-display: swap;
  unicode-range: U+0600-06FF, U+0750-077F, U+0870-08FF, U+200C-200E, U+2010-2011, U+204F, U+2E41, U+FB50-FDFF, U+FE70-FEFC; }
@font-face { font-family: "Amiri"; src: url(fonts/amiri-700-latin.woff2) format("woff2"); font-weight: 700; font-display: swap;
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+2000-200B, U+2012-204E, U+2050-206F, U+20AC, U+2122, U+2212, U+FEFF, U+FFFD; }
@font-face { font-family: "Noto Naskh Arabic"; src: url(fonts/naskh.woff2) format("woff2"); font-weight: 400 700; font-display: swap;
  unicode-range: U+0600-06FF, U+0750-077F, U+0870-08FF, U+200C-200E, U+2010-2011, U+204F, U+2E41, U+FB50-FDFF, U+FE70-FEFC; }
@font-face { font-family: "Noto Naskh Arabic"; src: url(fonts/naskh-latin.woff2) format("woff2"); font-weight: 400 700; font-display: swap;
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+2000-200B, U+2012-204E, U+2050-206F, U+20AC, U+2122, U+2212, U+FEFF, U+FFFD; }

:root {
  --bg: #fbf8f3;
  --surface: #ffffff;
  --surface-2: #f3eee6;
  --ink: #221a16;
  --ink-2: #6b5d55;
  --line: #e7dfd3;
  --accent: #7a2335;
  --accent-ink: #ffffff;
  --gold: #a8772a;
  --sel: #f6e3a8;
  --mark: #fbeec2;
  --bar: rgba(251, 248, 243, .92);
  --shadow: 0 10px 30px rgba(40, 20, 10, .14);
  --text-font: "Amiri", "Noto Naskh Arabic", serif;
  --ui-font: "Noto Naskh Arabic", system-ui, -apple-system, "Segoe UI", Tahoma, sans-serif;
  --fs: 1;
  --safe-t: env(safe-area-inset-top, 0px);
  --safe-b: env(safe-area-inset-bottom, 0px);
  color-scheme: light;
}
:root[data-theme="sepia"] {
  --bg: #f4ecd8; --surface: #faf4e4; --surface-2: #ebe1c8; --ink: #3b2f22; --ink-2: #77664f;
  --line: #ddd0b2; --bar: rgba(244, 236, 216, .93); --sel: #ecd58b; --mark: #efdfac;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]):not([data-theme="sepia"]) {
    --bg: #17120f; --surface: #221b17; --surface-2: #2c241f; --ink: #ece3d8; --ink-2: #a8998c;
    --line: #3a302a; --accent: #d98a99; --accent-ink: #1b1210; --gold: #d9b066;
    --sel: #5b4720; --mark: #44361c; --bar: rgba(23, 18, 15, .92); --shadow: 0 10px 30px rgba(0,0,0,.5);
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #17120f; --surface: #221b17; --surface-2: #2c241f; --ink: #ece3d8; --ink-2: #a8998c;
  --line: #3a302a; --accent: #d98a99; --accent-ink: #1b1210; --gold: #d9b066;
  --sel: #5b4720; --mark: #44361c; --bar: rgba(23, 18, 15, .92); --shadow: 0 10px 30px rgba(0,0,0,.5);
  color-scheme: dark;
}
:root[data-font="naskh"] { --text-font: "Noto Naskh Arabic", "Amiri", serif; }
:root[data-font="system"] { --text-font: system-ui, -apple-system, "Segoe UI", Tahoma, sans-serif; }

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html { -webkit-text-size-adjust: 100%; text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--ink);
  font: 16px/1.6 var(--ui-font);
  min-height: 100vh; min-height: 100dvh;
}
button { font: inherit; color: inherit; background: none; border: 0; cursor: pointer; padding: 0; }
a { color: var(--accent); }
[hidden] { display: none !important; }
svg { width: 24px; height: 24px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }

/* ---------- top bar ---------- */
.bar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; gap: 4px;
  padding: calc(var(--safe-t) + 6px) 8px 6px;
  background: var(--bar);
  -webkit-backdrop-filter: saturate(1.4) blur(14px); backdrop-filter: saturate(1.4) blur(14px);
  border-bottom: 1px solid var(--line);
}
.ib { width: 44px; height: 44px; display: grid; place-items: center; border-radius: 12px; color: var(--ink); flex: none; }
.ib:active { background: var(--surface-2); }
.title {
  flex: 1; min-width: 0; text-align: start; padding: 0 8px;
  font-weight: 700; font-size: 18px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.bar-actions { display: flex; }

main { outline: none; padding-bottom: calc(var(--safe-b) + 24px); }
.wrap { max-width: 760px; margin: 0 auto; padding: 0 16px; }

/* ---------- home ---------- */
.hero { padding: 28px 0 8px; }
.hero h1 { margin: 0; font: 700 clamp(30px, 7vw, 40px)/1.2 var(--text-font); color: var(--accent); }
.hero p { margin: 4px 0 0; color: var(--ink-2); }
.continue {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  margin: 18px 0 6px; padding: 14px 16px; border-radius: 16px;
  background: var(--accent); color: var(--accent-ink); text-decoration: none;
}
.continue small { display: block; opacity: .8; font-size: 13px; }
.continue b { font-size: 17px; }
.tabs { display: flex; gap: 6px; margin: 20px 0 12px; padding: 4px; background: var(--surface-2); border-radius: 14px; }
.tabs button { flex: 1; padding: 9px 6px; border-radius: 10px; font-weight: 700; color: var(--ink-2); }
.tabs button[aria-selected="true"] { background: var(--surface); color: var(--ink); box-shadow: 0 1px 3px rgba(0,0,0,.08); }
.books { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 8px; list-style: none; margin: 0; padding: 0; }
.books a {
  display: flex; flex-direction: column; justify-content: center; min-height: 64px;
  padding: 10px 14px; border-radius: 14px; background: var(--surface); border: 1px solid var(--line);
  color: var(--ink); text-decoration: none;
}
.books a:active { background: var(--surface-2); }
.books b { font: 700 18px/1.3 var(--text-font); }
.books small { color: var(--ink-2); font-size: 12.5px; }
.group-h { margin: 22px 0 8px; font-size: 13px; color: var(--ink-2); font-weight: 700; letter-spacing: 0; }

/* ---------- book page ---------- */
.book-h { padding: 22px 0 6px; }
.book-h h1 { margin: 0; font: 700 clamp(24px, 6vw, 32px)/1.35 var(--text-font); color: var(--accent); }
.book-h p { margin: 2px 0 0; color: var(--ink-2); font-size: 14px; }
.grid-nums { display: grid; grid-template-columns: repeat(auto-fill, minmax(52px, 1fr)); gap: 8px; margin: 14px 0; }
.grid-nums a, .grid-nums button {
  display: grid; place-items: center; height: 52px; border-radius: 12px;
  background: var(--surface); border: 1px solid var(--line); color: var(--ink);
  text-decoration: none; font-size: 18px; font-weight: 700;
}
.grid-nums .cur { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
.intro-toggle {
  width: 100%; display: flex; justify-content: space-between; align-items: center;
  margin-top: 10px; padding: 14px 16px; border-radius: 14px;
  background: var(--surface-2); font-weight: 700;
}
.intro-toggle svg { transition: transform .2s; }
.intro-toggle[aria-expanded="true"] svg { transform: rotate(180deg); }
.intro { padding: 4px 4px 10px; }

/* ---------- reader text ---------- */
.text {
  font-family: var(--text-font);
  font-size: calc(21px * var(--fs));
  line-height: 1.95;
  padding: 10px 0 30px;
  overflow-wrap: break-word;
}
:root[data-font="system"] .text { line-height: 1.85; }
.text p { margin: 0 0 .15em; text-align: start; }
.text h1, .text h2, .text h3, .text h4 { font-family: var(--text-font); line-height: 1.45; }
.text h1 { font-size: 1.15em; margin: 1.1em 0 .4em; color: var(--accent); }
.text h2 { font-size: 1.08em; margin: 1em 0 .35em; color: var(--accent); }
.text h3 { font-size: 1em; margin: 1.2em 0 .35em; color: var(--gold); }
.text h1 strong, .text h3 strong { font-weight: 700; }
.text .c { text-align: center; }
.text .ind { padding-inline-start: 1.5em; }
.text blockquote { margin: 0; padding: 0; }
.text blockquote.lbl h1, .text .ch-fallback {
  margin: .5em 0 .3em; font-size: 1.4em; color: var(--ink); text-align: start; font-weight: 700;
}
.text .v {
  font-family: var(--ui-font); font-weight: 700; font-size: .62em; color: var(--accent);
  vertical-align: .35em; padding-inline-end: .2em; line-height: 0; cursor: pointer;
}
:root[data-vn="0"] .text .v { display: none; }
.text sup { font-size: .62em; color: var(--accent); }
.text sup .v { font-size: 1em; vertical-align: 0; }
.text .vs { cursor: pointer; border-radius: 4px; transition: background-color .2s; -webkit-box-decoration-break: clone; box-decoration-break: clone; }
.text .vs.marked { background: var(--mark); }
.text .vs.sel { background: var(--sel); }
.text .vs.flash { background: var(--sel); }
.text .gl { border-bottom: 1.5px dotted var(--gold); cursor: help; }
.intro.text { font-size: calc(18.5px * var(--fs)); line-height: 1.85; }
.intro.text p { text-align: justify; margin-bottom: .6em; }

.ch-head { display: flex; align-items: baseline; justify-content: space-between; padding: 20px 0 0; gap: 12px; }
.ch-head h1 { margin: 0; font: 700 clamp(24px, 6vw, 30px)/1.3 var(--text-font); color: var(--ink); }
.ch-head a { font-size: 14px; text-decoration: none; white-space: nowrap; }
.end-nav { display: flex; gap: 10px; margin: 12px 0 0; }
.end-nav a {
  flex: 1; text-align: center; padding: 14px; border-radius: 14px; text-decoration: none;
  background: var(--surface); border: 1px solid var(--line); color: var(--ink); font-weight: 700;
}
.end-nav small { display: block; color: var(--ink-2); font-weight: 400; font-size: 12.5px; }

/* bottom reader nav */
.reader-nav {
  position: fixed; inset-inline: 0; bottom: 0; z-index: 15;
  display: flex; align-items: center; gap: 6px;
  padding: 6px 10px calc(var(--safe-b) + 6px);
  background: var(--bar); border-top: 1px solid var(--line);
  -webkit-backdrop-filter: saturate(1.4) blur(14px); backdrop-filter: saturate(1.4) blur(14px);
  transition: transform .25s ease;
}
.reader-nav.hide { transform: translateY(110%); }
body.reading main { padding-bottom: calc(var(--safe-b) + 80px); }
.nav-btn { display: flex; align-items: center; gap: 2px; height: 44px; padding: 0 10px; border-radius: 12px; color: var(--ink-2); font-size: 14px; }
.nav-btn:disabled { opacity: .3; }
.nav-mid { flex: 1; height: 44px; border-radius: 12px; background: var(--surface-2); font-weight: 700; }

/* ---------- selection bar ---------- */
.selbar {
  position: fixed; inset-inline: 10px; bottom: calc(var(--safe-b) + 66px); z-index: 25;
  display: flex; align-items: center; justify-content: space-between; gap: 8px; flex-wrap: wrap;
  max-width: 740px; margin: 0 auto;
  padding: 8px 8px 8px 8px; padding-inline-start: 14px; border-radius: 16px;
  background: var(--ink); color: var(--bg); box-shadow: var(--shadow);
}
.selbar span { font-weight: 700; font-size: 14px; }
.selbar div { display: flex; gap: 2px; }
.selbar button { padding: 8px 10px; border-radius: 10px; font-size: 14px; font-weight: 700; }
.selbar button:active { background: rgba(127,127,127,.25); }

/* ---------- sheets ---------- */
.sheet-bg { position: fixed; inset: 0; z-index: 30; background: rgba(0,0,0,.35); }
.sheet {
  position: fixed; inset-inline: 0; bottom: 0; z-index: 31;
  max-width: 640px; margin: 0 auto; max-height: 80vh; max-height: 80dvh; overflow: auto;
  padding: 8px 18px calc(var(--safe-b) + 18px);
  background: var(--surface); border-radius: 22px 22px 0 0; box-shadow: var(--shadow);
  animation: up .22s ease;
}
@keyframes up { from { transform: translateY(40px); opacity: 0; } }
.grab { width: 40px; height: 5px; border-radius: 3px; background: var(--line); margin: 4px auto 8px; }
.sheet h2 { margin: 4px 0 12px; font-size: 18px; }
.row { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 12px 0; border-top: 1px solid var(--line); }
.row.col { flex-direction: column; align-items: stretch; }
.seg { display: flex; gap: 4px; background: var(--surface-2); padding: 3px; border-radius: 12px; align-items: center; }
.seg button { padding: 6px 11px; border-radius: 9px; font-size: 14px; font-weight: 700; color: var(--ink-2); }
.seg button[aria-pressed="true"] { background: var(--surface); color: var(--ink); box-shadow: 0 1px 3px rgba(0,0,0,.1); }
.seg output { min-width: 48px; text-align: center; font-size: 14px; }
.offline small { color: var(--ink-2); }
.meter { height: 6px; border-radius: 3px; background: var(--surface-2); overflow: hidden; margin: 6px 0 4px; }
.meter i { display: block; height: 100%; width: 0; background: var(--accent); transition: width .3s; }
.links { display: flex; gap: 18px; padding-top: 14px; border-top: 1px solid var(--line); }
.links a { text-decoration: none; font-weight: 700; }

/* ---------- search ---------- */
.search-box { position: sticky; top: calc(var(--safe-t) + 57px); z-index: 5; background: var(--bg); padding: 12px 0 8px; }
.search-box input {
  width: 100%; height: 48px; padding: 0 16px; border-radius: 14px;
  border: 1px solid var(--line); background: var(--surface); color: var(--ink);
  font: 17px var(--ui-font); outline: none;
}
.search-box input:focus { border-color: var(--accent); }
.search-box .tabs { margin: 10px 0 0; }
.s-info { color: var(--ink-2); font-size: 14px; margin: 8px 0; }
.results { list-style: none; margin: 0; padding: 0; }
.results a { display: block; padding: 12px 2px; border-bottom: 1px solid var(--line); text-decoration: none; color: var(--ink); }
.results b { color: var(--accent); font-size: 14px; }
.results p { margin: 2px 0 0; font: calc(18px * var(--fs))/1.75 var(--text-font); }
.results mark { background: var(--sel); color: inherit; border-radius: 3px; padding: 0 1px; }
.more { display: block; width: 100%; margin: 14px 0; padding: 12px; border-radius: 12px; background: var(--surface-2); font-weight: 700; }

/* ---------- misc ---------- */
.empty { text-align: center; color: var(--ink-2); padding: 40px 10px; }
.page { padding: 20px 0; }
.page h1 { font: 700 26px/1.3 var(--text-font); color: var(--accent); margin: 0 0 12px; }
.page p, .page li { color: var(--ink); }
.page h2 { font-size: 17px; margin: 22px 0 6px; }
.bm { display: flex; align-items: flex-start; gap: 8px; border-bottom: 1px solid var(--line); }
.bm a { flex: 1; }
.bm button { padding: 14px 8px; color: var(--ink-2); }
.pop {
  position: fixed; z-index: 40; inset-inline: 12px; max-width: 520px; margin: 0 auto;
  padding: 14px 16px; border-radius: 14px; background: var(--surface); color: var(--ink);
  border: 1px solid var(--line); box-shadow: var(--shadow);
  font: 16px/1.8 var(--text-font);
}
.toast {
  position: fixed; z-index: 50; left: 50%; bottom: calc(var(--safe-b) + 90px); transform: translateX(-50%);
  padding: 10px 18px; border-radius: 22px; background: var(--ink); color: var(--bg); font-size: 14px; font-weight: 700;
  box-shadow: var(--shadow); white-space: nowrap;
}
.install {
  position: fixed; z-index: 35; inset-inline: 10px; bottom: calc(var(--safe-b) + 10px);
  max-width: 560px; margin: 0 auto; display: flex; align-items: center; gap: 10px;
  padding: 12px 12px 12px 12px; padding-inline-start: 16px; border-radius: 18px;
  background: var(--surface); border: 1px solid var(--line); box-shadow: var(--shadow); font-size: 14.5px;
}
.install-text { flex: 1; }
.install-actions { display: flex; gap: 4px; align-items: center; }
.install-actions button { padding: 8px 12px; border-radius: 10px; font-weight: 700; }
#install-go { background: var(--accent); color: var(--accent-ink); }
.share-ic { display: inline-block; width: 18px; height: 18px; vertical-align: -3px; }
.spinner { width: 28px; height: 28px; margin: 60px auto; border-radius: 50%; border: 3px solid var(--line); border-top-color: var(--accent); animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) { * { animation: none !important; transition: none !important; } }
@media (min-width: 700px) {
  .text { font-size: calc(23px * var(--fs)); }
}
