@font-face {
  font-family: Vazirmatn;
  src: url(assets/Vazirmatn.ttf) format("truetype");
  font-weight: 100 900;
  font-display: swap;
}
@font-face {
  font-family: Amiri;
  src: url(assets/Amiri-Regular.ttf) format("truetype");
  font-display: swap;
}

:root {
  color-scheme: light;
  --ink: #1c332e;
  --muted: #52665d;
  --accent: #1c5446;
  --accent-dark: #12392f;
  --tint: #e5eee7;
  --ground: #f0f2ec;
  --white: #fcfdfa;
  --paper: #fffdf6;
  --line: #d7e0d6;
  --line-strong: #b9cbbd;
  --gold: #a77434;
  --reader-size: 31px;
  --dock-height: 78px;
  --ease: cubic-bezier(.2,.8,.2,1);
  font: 16px Vazirmatn, Tahoma, sans-serif;
  color: var(--ink);
  background: var(--ground);
}
* { box-sizing: border-box; }
body { margin: 0; padding-block-end: calc(var(--dock-height) + 30px + env(safe-area-inset-bottom)); }
body:has(dialog[open]) { overflow: hidden; }
h1, h2, p { margin: 0; }
button, input, select { font: inherit; color: inherit; }
button, a, input, select { -webkit-tap-highlight-color: transparent; }
button, a, select { touch-action: manipulation; }
button:not(:disabled), select { cursor: pointer; }
button:disabled { opacity: .42; cursor: default; }
a { color: var(--accent); }
a, button, input, select, summary { scroll-margin-block: 12px calc(var(--dock-height) + 12px); }
[hidden] { display: none !important; }
:focus-visible { outline: 2px solid #8a551d; outline-offset: 3px; }
.sr-only, .skip:not(:focus), .sprites {
  position: absolute; inline-size: 1px; block-size: 1px;
  overflow: hidden; clip-path: inset(50%); white-space: nowrap;
}
.skip { position: fixed; z-index: 10; background: var(--white); padding: 12px; }
.icon {
  inline-size: 1.12em; block-size: 1.12em; flex: 0 0 auto;
  fill: none; stroke: currentColor; stroke-width: 1.65; stroke-linecap: round; stroke-linejoin: round;
}
.btn { display: inline-flex; justify-content: center; align-items: center; gap: 7px; white-space: nowrap; }
.btn:not(:disabled):active { filter: brightness(.96); }
.outline, .text-button {
  border: 1px solid var(--line-strong); border-radius: 10px; background: var(--white);
  min-block-size: 44px; padding: 5px 12px; font-weight: 650; font-size: .88rem;
}
.outline:focus-visible, .text-button:focus-visible, .outline[aria-pressed="true"], .text-button[aria-pressed="true"] { background: var(--tint); }
.text-button { border-color: transparent; background: transparent; color: var(--accent); }
.icon-button { inline-size: 44px; min-block-size: 44px; padding: 0; font-size: 1.15rem; }
@media (hover: hover) and (pointer: fine) {
  .outline:hover:not(:disabled), .text-button:hover, .icon-button:hover:not(:disabled) { background: var(--tint); }
}

.site-header { background: var(--white); border-block-end: 1px solid var(--line); }
.header-inner, .workspace, .player-inner { width: min(100%, 1320px); margin-inline: auto; padding-inline: clamp(16px,4vw,48px); }
.header-inner { min-height: 76px; display: flex; align-items: center; justify-content: space-between; gap: 14px; }
.brand { display: flex; align-items: center; gap: 10px; text-decoration: none; color: var(--ink); font-weight: 800; line-height: 1.25; }
.brand img { display: block; }
.brand small { display: block; font-size: .72rem; color: var(--muted); font-weight: 500; margin-block-start: 3px; }
.books { position: relative; display: grid; grid-template-columns: 1fr 1fr; padding: 4px; border: 1px solid var(--line); border-radius: 14px; background: #edf1eb; }
.books a {
  z-index: 1; display: inline-flex; justify-content: center; align-items: center; gap: 7px;
  min-height: 44px; padding-inline: 14px; border-radius: 10px; text-decoration: none;
  color: var(--muted); font-weight: 680; font-size: .88rem; white-space: nowrap;
  transition: color var(--m-in) var(--ease);
}
.books::before {
  content: ""; position: absolute; inset-block: 4px; inset-inline-start: 4px;
  width: calc((100% - 8px) / 2); border-radius: 10px; background: var(--accent); opacity: 0;
  transition: transform var(--m-slide) var(--ease), opacity var(--m-in) var(--ease);
}
.books:has([aria-current])::before { opacity: 1; }
.books:has([data-book="nahj"][aria-current])::before { transform: translateX(-100%); }
.books a[aria-current] { color: #fff; }
@supports not selector(:has(a)) {
  .books a[aria-current] { background: var(--accent); }
}

.book-intro {
  position: relative; isolation: isolate; overflow: hidden; display: flex; justify-content: space-between;
  align-items: end; gap: 18px; min-height: 162px; margin-block: 24px 20px;
  padding: clamp(18px, 3.3vw, 36px); border: 1px solid #d3dfd1; border-radius: 20px;
  background: #e5ede1;
}
.book-intro::before {
  content: ""; position: absolute; z-index: -1; pointer-events: none;
  width: 230px; height: 230px; inset-inline-end: -38px; inset-block-start: -94px;
  border: 1px solid #9fb6a3; outline: 1px solid #9fb6a3; outline-offset: 14px;
  border-radius: 34%; transform: rotate(35deg); opacity: .42;
}
.book-intro h1 { font-size: clamp(2rem,4vw,3.25rem); font-weight: 820; line-height: 1.16; margin-block: 6px 9px; }
.eyeline { font-size: .85rem; font-weight: 730; color: var(--accent); }
.book-summary { color: var(--muted); font-size: .92rem; }
.mode-button { gap: 8px; color: var(--accent); }

.layout { display: grid; grid-template-columns: clamp(250px,27%,326px) minmax(0,1fr); gap: 20px; align-items: start; }
.library, .reading { border: 1px solid var(--line); border-radius: 17px; background: var(--white); }
.library { position: sticky; top: 16px; }
.library-top { padding: 14px 14px 9px; }
.library-title, .reader-tools, .page-nav, .dialog-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.library-title h2 { display: flex; align-items: center; gap: 8px; font-size: 1rem; }
.library-title h2 .icon { color: var(--accent); }
.library-title .text-button { font-size: .84rem; }
.search-field {
  display: flex; align-items: center; gap: 8px; padding-inline: 11px 3px; margin-block-start: 9px;
  background: #fff; border: 1px solid var(--line-strong); border-radius: 10px; color: var(--accent);
}
.search-field:focus-within { outline: 2px solid var(--accent); outline-offset: 1px; }
.search-field input {
  flex: 1; min-width: 0; width: 100%; min-height: 43px; padding: 0; background: transparent;
  border: 0; border-radius: 6px; outline: none; color: var(--ink); font-size: .88rem;
}
.search-field input::-webkit-search-cancel-button { display: none; }
.search-field .icon-button { min-block-size: 38px; inline-size: 40px; border: 0; border-radius: 8px; background: transparent; }
select, #page-number {
  border: 1px solid var(--line-strong); border-radius: 10px; background: #fff;
  min-height: 44px; padding-inline: 10px; font-size: .9rem;
}
select {
  appearance: none; padding-inline-end: 32px;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16' fill='none' stroke='%231c5446' stroke-width='1.6' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m4 6 4 4 4-4'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-size: 16px; background-position: left 9px center;
}
#groups { display: block; width: 100%; margin-block-start: 9px; }
.results { font-size: .79rem; color: var(--muted); margin-block-start: 9px; }
.toc {
  list-style: none; margin: 0; padding: 0 7px 9px; max-height: max(170px, calc(100dvh - 600px));
  overflow: auto; overscroll-behavior: contain; scrollbar-color: #96aa9e transparent;
}
.toc a {
  display: grid; gap: 3px; min-height: 45px; padding: 9px 10px; margin: 1px;
  border-inline-start: 3px solid transparent; border-radius: 7px; text-decoration: none;
  color: var(--ink); font-size: .9rem; line-height: 1.6; overflow-wrap: anywhere;
  transition: background-color var(--m-in) var(--ease);
}
.toc a:focus-visible { outline-offset: -2px; }
.toc a[aria-current] { background: var(--tint); border-inline-start-color: var(--accent); font-weight: 710; }
@media (hover: hover) and (pointer: fine) {
  .toc a:hover { background: var(--tint); }
}
.toc small { color: var(--muted); font-size: .76rem; font-weight: 480; }
.toc .empty { padding: 16px 10px; font-size: .9rem; color: var(--muted); }

.reader-tools, .page-nav { padding: 10px 14px; }
.reader-tools { flex-wrap: wrap; }
.reader-status { display: grid; gap: 4px; min-width: 95px; color: var(--muted); font-size: .79rem; font-variant-numeric: tabular-nums; }
#book-progress { width: 100%; height: 4px; accent-color: var(--accent); }
.style-tools, .font-controls { display: flex; align-items: center; gap: 5px; }
.style-tools { margin-inline-start: auto; }
.font-controls { gap: 0; border: 1px solid var(--line-strong); border-radius: 10px; }
.font-controls .icon-button { border: 0; background: transparent; border-radius: 9px; font-size: .94rem; }
.font-controls .icon-button + .icon-button { border-inline-start: 1px solid var(--line); }
#save[aria-pressed="true"] .icon, #bookmarks[aria-pressed="true"] .icon { fill: currentColor; }
.paper { background: var(--paper); border-block: 1px solid var(--line); min-height: 350px; padding: clamp(22px,4vw,52px); }
.paper > h2 { text-align: center; font-size: clamp(1.45rem,3.15vw,2.2rem); line-height: 1.5; font-weight: 790; }
.paper > .eyeline { text-align: center; margin-block-end: 6px; }
.divider { display: grid; grid-template-columns: 1fr 9px 1fr; align-items: center; gap: 11px; max-width: 162px; margin: 17px auto 24px; }
.divider::before, .divider::after { content: ""; height: 1px; background: #d7b889; }
.divider span { width: 7px; height: 7px; background: var(--gold); transform: rotate(45deg); }
.passage { font: var(--reader-size)/1.95 Amiri,serif; margin: 0 auto 14px; max-width: 30em; overflow-wrap: anywhere; padding: 4px 8px; border-radius: 7px; }
.passage[lang="fa"] { font: calc(var(--reader-size)*.62)/2 Vazirmatn,Tahoma,sans-serif; }
.passage.is-speaking { background: #e1eee3; box-shadow: inset -3px 0 var(--accent); }
.passage.is-heading { color: var(--accent); font-weight: 700; }
.scan-image { width: 100%; height: auto; display: block; max-width: 590px; margin-inline: auto; border: 1px solid #d7c9b1; border-radius: 3px; }
.scan-text { margin: 18px auto 0; max-width: 590px; }
.scan-text summary { cursor: pointer; font-size: .9rem; color: var(--accent); margin-block-end: 12px; }
.scan-text .revision { display: inline-block; margin-block-end: 12px; font-size: .87rem; }
#jump { display: flex; align-items: center; gap: 6px; }
#page-number { width: 64px; text-align: center; }
.page-nav .outline { min-width: 106px; }

.player {
  position: fixed; inset: auto 0 0; z-index: 3; border-block-start: 1px solid #31584b;
  background: var(--accent-dark); color: #fff; padding-block-end: env(safe-area-inset-bottom);
  box-shadow: 0 -5px 26px #1c352c20;
}
.player-inner { min-height: var(--dock-height); display: flex; align-items: center; gap: 15px; }
.transport { display: flex; align-items: center; gap: 5px; }
.play {
  min-height: 46px; padding: 5px 14px; border: 1px solid transparent; border-radius: 11px;
  color: #184234; background: #edf6eb; font-size: .89rem; font-weight: 770; 
}
.play .stop-glyph, .play[data-playing] .play-glyph { display: none; }
.play[data-playing] .stop-glyph { display: block; }
.player-icon, .player-settings { color: #f9fff9; background: transparent; border: 1px solid #668377; border-radius: 10px; }
.player-settings { min-height: 44px; padding: 5px 10px; font-size: .84rem; }
.player :focus-visible { outline-color: #f4cd92; }
@media (hover: hover) and (pointer: fine) {
  .play:hover:not(:disabled) { background: #d7ecd9; }
  .player .player-icon:hover:not(:disabled), .player-settings:hover { background: #2b594b; }
}
.now { flex: 1; min-width: 0; }
.now strong, .now span { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.now strong { font-size: .89rem; }
.now span { font-size: .8rem; color: #d4e6dc; }
.mobile-tools, .close-library { display: none; }

.sheet {
  width: min(calc(100% - 32px), 560px); max-height: min(88dvh, 720px); padding: 18px;
  border: 1px solid var(--line-strong); border-radius: 18px; background: var(--white); color: var(--ink);
  box-shadow: 0 18px 60px #10271c32; overflow: auto; overscroll-behavior: contain;
}
.sheet[open] { animation: panel-in var(--m-panel) var(--ease) both; }
.sheet::backdrop { background: #102a23a8; }
.sheet[open]::backdrop { animation: backdrop-in var(--m-panel) var(--ease) both; }
@keyframes panel-in { from { opacity: .55; transform: translateY(12px); } }
@keyframes backdrop-in { from { opacity: 0; } }
.dialog-head { padding-block-end: 11px; border-block-end: 1px solid var(--line); }
.dialog-head h2 { font-size: 1.16rem; }
.sources-sheet p { margin-block-start: 12px; font-size: .9rem; line-height: 1.9; }
.sources-sheet a { text-underline-offset: 3px; }
.audio-sheet { width: min(calc(100% - 32px), 390px); margin: auto auto calc(var(--dock-height) + 14px) max(16px, calc((100vw - 1224px) / 2)); }
.player-options { display: grid; grid-template-columns: minmax(90px,auto) minmax(0,1fr); gap: 12px 10px; align-items: center; padding-block-start: 14px; }
.player-options label { font-size: .9rem; font-weight: 670; }
.player-options select { width: 100%; min-width: 0; }
.continuous { grid-column: 1/-1; display: flex; align-items: center; justify-content: space-between; min-height: 46px; border-block-start: 1px solid var(--line); padding-block-start: 8px; cursor: pointer; }
.continuous input { appearance: none; margin: 0; width: 44px; height: 26px; border: 1px solid #7c9887; border-radius: 100px; background: #e1ebe1; position: relative; cursor: pointer; }
.continuous input::after { content: ""; position: absolute; inset-block-start: 3px; inset-inline-start: 3px; width: 18px; height: 18px; border-radius: 50%; background: #476756; transition: transform var(--m-in) var(--ease); }
.continuous input:checked { background: var(--accent); border-color: var(--accent); }
.continuous input:checked::after { transform: translateX(-18px); background: white; }
.library-sheet { padding: 0; }

@media (max-width: 760px) {
  :root { --dock-height: 78px; }
  .header-inner { min-height: 64px; gap: 7px; }
  .brand { font-size: .86rem; gap: 6px; }
  .brand img { width: 33px; height: 33px; }
  .brand small, .books .icon, .source-button span { display: none; }
  .books a { min-height: 40px; padding-inline: 7px; font-size: .76rem; }
  .source-button { width: 44px; padding: 0; font-size: 1.12rem; }
  .book-intro { min-height: 134px; flex-wrap: wrap; align-items: end; gap: 10px; margin-block: 14px 13px; }
  .book-intro::before { width: 145px; height: 145px; inset-block-start: -52px; }
  .book-intro h1 { margin-block: 4px 6px; }
  .book-summary { font-size: .82rem; }
  .mode-button { font-size: .82rem; }
  .layout { display: block; }
  .mobile-tools, .close-library { display: inline-flex; }
  .library-sheet, .audio-sheet { width: 100%; max-width: none; margin: auto 0 0; border-radius: 20px 20px 0 0; }
  .library-sheet { max-height: 84dvh; }
  .library-sheet .library { position: static; border: 0; border-radius: 0; }
  .library-sheet .toc { max-height: 53dvh; padding-block-end: max(12px, env(safe-area-inset-bottom)); }
  .audio-sheet { padding-block-end: max(16px, env(safe-area-inset-bottom)); }
  .reader-tools, .page-nav { padding: 8px; }
  .reader-tools .outline { padding-inline: 9px; font-size: .8rem; }
  .reader-status { order: 3; width: 100%; padding-inline: 3px; }
  .style-tools { gap: 5px; }
  .paper { padding: 25px 13px; }
  .passage { font-size: calc(var(--reader-size)*.88); padding-inline: 4px; }
  .player-inner { gap: 8px; }
  .transport { gap: 3px; }
  .play { width: 48px; padding: 3px; }
  .play .icon { width: 21px; height: 21px; }
  .play #play-label { position: absolute; clip-path: inset(50%); width: 1px; height: 1px; overflow: hidden; }
  .player-icon { border-color: transparent; }
  .player-settings { width: 44px; padding: 0; font-size: 1.1rem; }
  .player-settings span { display: none; }
}
@media (max-width: 360px) {
  .header-inner, .workspace, .player-inner { padding-inline: 10px; }
  .brand img { width: 27px; height: 27px; }
  .brand span { display: none; }
  .books a { padding-inline: 9px; }
  .book-intro { padding: 14px; }
}
@media (prefers-reduced-motion: reduce) {
  .books a, .books::before, .toc a, .continuous input::after { transition: none; }
  .sheet[open], .sheet[open]::backdrop { animation: none; }
}
