:root {
  --green: #1F5A4A;
  --green-soft: #E6EFEA;
  --paper: #F6F3EA;
  --card: #FFFFFF;
  --quote: #FBF9F4;
  --line: #E2DCCB;
  --line-soft: #EFEADF;
  --ink: #1E1C17;
  --ink-2: #3D3A33;
  --muted: #5A554A;
  --note-bg: #FBF1DC;
  --note-ink: #4A3000;
  --note-h: #6B4500;
  --own-bg: #F7EFE6;
  --own-ink: #3D2810;
  --own-h: #7A4B1E;
  --hl: #FFF0B8;
  --focus-bg: #FFF8E1;
  --on-green: #FFFFFF;
  --fs: 1;
  --sans: 'IBM Plex Sans Arabic', system-ui, sans-serif;
  --serif: 'Amiri', 'Times New Roman', serif;
  color-scheme: light;
}
:root[data-theme="dark"] {
  --green: #8FCDB6; --green-soft: #1F3A32; --paper: #15171A; --card: #1E2125; --quote: #24282D; --line: #363B42; --line-soft: #2B3036;
  --ink: #ECE8DF; --ink-2: #D2CEC5; --muted: #A8A39A; --note-bg: #3A2F17; --note-ink: #F1DFB4; --note-h: #E8C77A;
  --own-bg: #3A2B1F; --own-ink: #F0DCC8; --own-h: #E3A871; --hl: #5C4A12; --focus-bg: #2E2A1B; --on-green: #10201B;
  color-scheme: dark;
}
@media (prefers-color-scheme: dark) {
  :root[data-theme="auto"] {
    --green: #8FCDB6; --green-soft: #1F3A32; --paper: #15171A; --card: #1E2125; --quote: #24282D; --line: #363B42; --line-soft: #2B3036;
    --ink: #ECE8DF; --ink-2: #D2CEC5; --muted: #A8A39A; --note-bg: #3A2F17; --note-ink: #F1DFB4; --note-h: #E8C77A;
    --own-bg: #3A2B1F; --own-ink: #F0DCC8; --own-h: #E3A871; --hl: #5C4A12; --focus-bg: #2E2A1B; --on-green: #10201B;
    color-scheme: dark;
  }
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; background: var(--paper); color: var(--ink); font-family: var(--sans); font-size: 16px; line-height: 1.7; }
a { color: var(--green); }
button, input, textarea { font: inherit; color: inherit; }
.wrap { width: 100%; max-width: 1080px; margin: 0 auto; padding: 0 16px; }
.skip { position: absolute; inset-inline-start: -999px; top: 8px; background: var(--card); padding: 8px 12px; z-index: 10; }
.skip:focus { inset-inline-start: 8px; }
:focus-visible { outline: 3px solid #C99A2E; outline-offset: 2px; }

/* header */
.top { background: var(--card); border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 5; }
.top-in { display: flex; position: relative; align-items: center; gap: 12px; min-height: 64px; flex-wrap: wrap; padding-top: 8px; padding-bottom: 8px; }
.brand { display: flex; align-items: baseline; gap: 10px; text-decoration: none; color: inherit; }
.brand-name { font-family: var(--serif); font-size: 30px; font-weight: 700; color: var(--green); line-height: 1; }
.brand-sub { font-size: 14px; color: var(--muted); }
.nav { display: flex; gap: 4px; flex: 1 1 auto; flex-wrap: wrap; }
.nav a { text-decoration: none; color: var(--ink-2); padding: 8px 12px; border-radius: 999px; font-size: 15px; min-height: 40px; display: inline-flex; align-items: center; }
.nav a[aria-current="page"] { background: var(--green-soft); color: var(--green); font-weight: 600; }
.tools { display: flex; gap: 8px; }
.notes-toggle { border: 1px solid var(--line); background: var(--card); color: var(--note-h); border-radius: 999px; padding: 8px 14px; min-height: 40px; cursor: pointer; font-size: 14px; }
.notes-toggle[aria-pressed="true"], .notes-toggle[aria-expanded="true"] { background: var(--note-bg); font-weight: 600; }
#displayToggle { color: var(--ink-2); }
.panel { position: absolute; top: calc(100% + 4px); inset-inline-end: 16px; background: var(--card); border: 1px solid var(--line); border-radius: 14px; padding: 12px 14px; width: max-content; max-width: calc(100vw - 32px); box-shadow: 0 8px 24px rgba(0,0,0,.14); z-index: 6; }
.panel .row { display: flex; align-items: center; gap: 8px; padding: 4px 0; flex-wrap: wrap; }
.panel .row > span:first-child { width: 72px; color: var(--muted); font-size: 14px; }
.panel .fsv { min-width: 48px; text-align: center; font-variant-numeric: tabular-nums; }

main { padding-top: 28px; padding-bottom: 56px; min-height: 60vh; outline: none; }
.foot { border-top: 1px solid var(--line); color: var(--muted); font-size: 14px; padding: 18px 0 28px; }
.foot p { margin: 0 0 6px; max-width: 760px; }
.foot a { color: var(--muted); }

/* home */
.hero { text-align: center; padding: 28px 0 8px; }
.hero h1 { font-family: var(--serif); font-size: clamp(34px, 6vw, 52px); color: var(--green); margin: 0; line-height: 1.3; }
.hero p { color: var(--ink-2); margin: 8px auto 0; max-width: 620px; font-size: 17px; }
.ask { display: flex; gap: 10px; max-width: 720px; margin: 26px auto 0; }
.ask.small { margin: 0 0 22px; max-width: 620px; }
.ask input { flex: 1 1 auto; min-width: 0; font-size: 18px; padding: 14px 18px; border: 1px solid var(--line); border-radius: 14px; background: var(--card); color: var(--ink); }
.ask.small input { font-size: 16px; padding: 10px 14px; }
.ask button { flex: none; border: 0; background: var(--green); color: var(--on-green); font-weight: 600; font-size: 17px; padding: 0 22px; border-radius: 14px; min-height: 52px; cursor: pointer; }
.ask.small button { font-size: 15px; min-height: 44px; padding: 0 16px; }
.chips { display: flex; flex-wrap: wrap; gap: 8px; justify-content: center; margin: 14px auto 0; max-width: 760px; }
.chip { border: 1px solid var(--line); background: var(--card); border-radius: 999px; padding: 6px 14px; font-size: 14px; color: var(--ink-2); cursor: pointer; min-height: 36px; }
.cards3 { display: grid; grid-template-columns: repeat(auto-fit, minmax(230px, 1fr)); gap: 16px; margin-top: 40px; }
.tile { background: var(--card); border: 1px solid var(--line); border-radius: 16px; padding: 20px; text-decoration: none; color: inherit; display: block; }
.tile h2 { margin: 0 0 6px; font-size: 19px; color: var(--green); }
.tile p { margin: 0; color: var(--muted); font-size: 15px; }
.principles { margin: 36px auto 0; max-width: 760px; color: var(--ink-2); font-size: 15px; }
.principles li { margin: 4px 0; }

/* generic */
.crumbs { font-size: 14px; color: var(--muted); margin-bottom: 6px; }
.crumbs a { color: var(--muted); }
h1.page { font-family: var(--serif); font-size: clamp(28px, 4.5vw, 40px); margin: 0 0 4px; line-height: 1.35; }
.sub { color: var(--muted); font-size: 15px; margin: 0 0 20px; }
.section-h { font-size: 14px; font-weight: 600; color: var(--green); margin: 26px 0 10px; }
.empty { background: var(--card); border: 1px dashed var(--line); border-radius: 14px; padding: 20px 24px; margin-bottom: 14px; }
.empty b { display: block; margin-bottom: 4px; }
.loading { color: var(--muted); padding: 20px 0; }
.mode { font-size: 13px; color: var(--muted); margin: 0 0 12px; }
.count { font-weight: 600; margin: 0 0 14px; }
.toolbar { display: flex; flex-wrap: wrap; gap: 8px; margin: 0 0 12px; }
.btn { border: 1px solid var(--line); background: var(--card); color: var(--ink-2); border-radius: 10px; padding: 8px 14px; min-height: 40px; cursor: pointer; font-size: 14px; text-decoration: none; display: inline-flex; align-items: center; justify-content: center; }
.btn[aria-pressed="true"] { background: var(--green-soft); color: var(--green); font-weight: 600; }
.btn.primary { background: var(--green); color: var(--on-green); border-color: var(--green); font-weight: 600; }
.btn:disabled { opacity: .55; cursor: default; }
.pager { display: flex; justify-content: space-between; gap: 12px; margin-top: 22px; flex-wrap: wrap; }
#toast { position: fixed; bottom: 22px; inset-inline: 0; margin: 0 auto; width: max-content; max-width: calc(100vw - 32px); background: var(--ink); color: var(--paper); padding: 10px 18px; border-radius: 999px; font-size: 14px; opacity: 0; transform: translateY(8px); transition: opacity .2s, transform .2s; pointer-events: none; z-index: 20; }
#toast.on { opacity: 1; transform: none; }

/* a passage of the book */
.passage, .hit { background: var(--card); border: 1px solid var(--line); border-radius: 14px; padding: 18px 20px; margin-bottom: 14px; }
.passage .where, .hit .where { font-size: 14px; color: var(--muted); margin-bottom: 8px; }
.passage .where a { color: var(--muted); }
.text { font-family: var(--serif); font-size: calc(23px * var(--fs)); line-height: 2.05; margin: 0; overflow-wrap: anywhere; }
.text.small { font-size: calc(20px * var(--fs)); }
.text mark, .hit mark { background: var(--hl); color: inherit; border-radius: 4px; padding: 0 2px; }
.ref { display: flex; flex-wrap: wrap; gap: 8px 14px; align-items: center; margin-top: 10px; font-size: 14px; color: var(--muted); }
.pill { background: var(--green-soft); color: var(--green); border-radius: 999px; padding: 4px 12px; font-weight: 500; }
.ref a { min-height: 40px; display: inline-flex; align-items: center; }
.fnref { font-family: var(--sans); font-size: 13px; vertical-align: super; line-height: 1; border: 0; background: none; color: var(--green); cursor: pointer; padding: 0 2px; }
.noted { text-decoration: underline dotted #B8862B 2px; text-underline-offset: 6px; }
.noted sup { font-family: var(--sans); font-size: 12px; color: var(--note-h); }
.notes { background: var(--note-bg); border-radius: 10px; padding: 10px 14px; margin-top: 10px; font-size: 15px; color: var(--note-ink); }
.notes h3, .own h3 { margin: 0 0 4px; font-size: 13px; color: var(--note-h); }
.notes p { margin: 2px 0; }
.own { border-inline-start: 4px solid var(--own-h); background: var(--own-bg); border-radius: 10px; padding: 10px 14px; margin-top: 10px; color: var(--own-ink); font-size: 16px; }
.own h3 { color: var(--own-h); }
.own p { margin: 0; }
.fns { border-top: 1px solid var(--line-soft); margin-top: 10px; padding-top: 8px; font-size: 14px; color: var(--ink-2); }
.fns p { margin: 2px 0; unicode-bidi: plaintext; }
.fns .fnrow { display: flex; gap: 10px; align-items: baseline; margin: 4px 0; }
.fns .fnn { flex: 0 0 auto; min-width: 2.2em; color: var(--green); font-weight: 600; unicode-bidi: isolate; white-space: nowrap; }
.fns .fnb { flex: 1 1 0; min-width: 0; }
.fns .fnt { text-align: right; overflow-wrap: anywhere; }
.fns .fnt bdi { unicode-bidi: isolate; }
.fns .unsure { margin-top: 2px; }
.unsure { font-size: 13px; color: var(--muted); margin-top: 6px; }
.acts { display: flex; flex-wrap: wrap; gap: 2px 4px; margin-top: 8px; }
.act { border: 0; background: none; color: var(--muted); font-size: 13px; padding: 6px 8px; min-height: 36px; border-radius: 8px; cursor: pointer; }
.act:hover { background: var(--quote); color: var(--ink); }
.act[aria-pressed="true"] { color: var(--own-h); font-weight: 600; }

/* reading */
.unit { display: grid; grid-template-columns: 92px minmax(0, 1fr); gap: 14px; padding: 14px 0 8px; border-bottom: 1px solid var(--line-soft); }
.unit.focus { background: var(--focus-bg); border-radius: 10px; }
.unit .num { font-size: 12px; color: var(--muted); padding-top: 10px; line-height: 1.5; }
.unit .num b { display: block; color: var(--green); font-size: 13px; }
.unit .text { font-size: calc(22px * var(--fs)); }
.preamble { font-family: var(--serif); font-size: 26px; text-align: center; color: var(--ink-2); margin: 0 0 10px; }
.vol { margin-bottom: 28px; }
.vol > h2 { font-family: var(--serif); font-size: 28px; margin: 0 0 10px; color: var(--green); }
details.kitab { background: var(--card); border: 1px solid var(--line); border-radius: 14px; margin-bottom: 10px; }
details.kitab > summary { cursor: pointer; padding: 14px 18px; font-size: 18px; font-weight: 600; list-style: none; display: flex; justify-content: space-between; gap: 12px; min-height: 52px; align-items: center; }
details.kitab > summary::-webkit-details-marker { display: none; }
details.kitab > summary span { font-size: 14px; color: var(--muted); font-weight: 400; }
.bablist { list-style: none; margin: 0; padding: 0 10px 10px; columns: 2 300px; column-gap: 18px; }
.bablist li { break-inside: avoid; }
.bablist a { display: flex; justify-content: space-between; gap: 10px; padding: 8px 8px; border-radius: 8px; text-decoration: none; color: var(--ink); min-height: 40px; align-items: center; }
.bablist a:hover { background: var(--quote); }
.bablist small { color: var(--muted); white-space: nowrap; }
.marklist, .qlist { list-style: none; margin: 0; padding: 0; }
.marklist li, .qlist li { display: flex; gap: 10px; align-items: center; justify-content: space-between; background: var(--card); border: 1px solid var(--line); border-radius: 12px; padding: 8px 12px; margin-bottom: 8px; }
.marklist a { text-decoration: none; color: var(--ink); display: flex; flex-direction: column; min-width: 0; font-family: var(--serif); font-size: 19px; }
.marklist small, .qlist small { color: var(--muted); font-family: var(--sans); font-size: 13px; white-space: nowrap; }
.qlist a { color: var(--ink); min-width: 0; overflow-wrap: anywhere; }

/* dialogs: page image, report */
.dlg { border: 1px solid var(--line); border-radius: 16px; padding: 0; background: var(--card); color: var(--ink); width: min(560px, calc(100vw - 24px)); max-height: calc(100vh - 32px); }
.dlg.wide { width: min(1040px, calc(100vw - 24px)); }
.dlg::backdrop { background: rgba(0,0,0,.5); }
.dlg-h { display: flex; justify-content: space-between; align-items: center; gap: 12px; padding: 12px 16px; border-bottom: 1px solid var(--line); position: sticky; top: 0; background: var(--card); z-index: 1; }
.dlg-h h2 { margin: 0; font-size: 17px; }
.dlg-b { padding: 14px 16px 18px; }
.dlg textarea { width: 100%; border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px; background: var(--paper); margin-bottom: 10px; }
.scanpage { margin: 0 0 16px; }
.scanimg { position: relative; background: #fff; border: 1px solid var(--line); border-radius: 8px; overflow: hidden; }
.scanimg img { display: block; width: 100%; height: auto; }
.scanimg .band { position: absolute; inset-inline: 0; background: rgba(255, 213, 79, .28); border-block: 2px solid rgba(201, 154, 46, .9); pointer-events: none; }
.scanpage figcaption { font-size: 13px; color: var(--muted); margin-top: 4px; text-align: center; }

/* owner page */
.tablewrap { overflow-x: auto; background: var(--card); border: 1px solid var(--line); border-radius: 12px; }
.tbl { border-collapse: collapse; width: 100%; font-size: 14px; font-variant-numeric: tabular-nums; }
.tbl th, .tbl td { padding: 8px 10px; text-align: start; border-bottom: 1px solid var(--line-soft); white-space: nowrap; }
.tbl th { color: var(--muted); font-weight: 600; }

/* كتاب الطهارة */
.qa-layout { display: grid; grid-template-columns: 260px minmax(0, 1fr); gap: 24px; align-items: start; }
.qa-nav { position: sticky; top: 84px; background: var(--card); border: 1px solid var(--line); border-radius: 14px; padding: 10px; max-height: calc(100vh - 100px); overflow: auto; }
.qa-nav a { display: flex; gap: 10px; padding: 9px 10px; border-radius: 10px; text-decoration: none; color: var(--ink); font-size: 15px; line-height: 1.5; min-height: 44px; }
.qa-nav a[aria-current="page"] { background: var(--green-soft); color: var(--green); font-weight: 600; }
.qa-nav .n { flex: none; width: 24px; color: var(--muted); }
.summary { background: var(--card); border: 1px solid var(--line); border-radius: 14px; padding: 16px 20px; margin-bottom: 16px; }
.summary ul { margin: 6px 0 0; padding-inline-start: 20px; }
.summary li { margin: 3px 0; }
.summary small { color: var(--muted); }
.item { background: var(--card); border: 1px solid var(--line); border-radius: 14px; margin-bottom: 12px; overflow: hidden; }
.item button.q { width: 100%; display: flex; gap: 14px; align-items: center; padding: 16px 20px; background: none; border: 0; cursor: pointer; text-align: right; font-size: 18px; font-weight: 600; color: var(--ink); min-height: 60px; }
.item button.q .n { flex: none; width: 32px; height: 32px; border-radius: 50%; background: var(--green-soft); color: var(--green); display: flex; align-items: center; justify-content: center; font-size: 14px; }
.item button.q .chev { margin-inline-start: auto; color: var(--muted); font-size: 14px; font-weight: 400; flex: none; }
.item .body { border-top: 1px solid var(--line-soft); padding: 16px 20px 14px; }
.item .body .quote { background: var(--quote); border-radius: 10px; padding: 14px 18px; }
.plain { margin-top: 14px; }
.plain h3 { font-size: 13px; color: var(--muted); margin: 0 0 2px; }
.plain p { margin: 0; }
.plain small { color: var(--muted); font-size: 12px; }
.babtag { font-size: 13px; color: var(--muted); margin-inline-start: 6px; font-weight: 400; }

@media (max-width: 760px) {
  .qa-layout { grid-template-columns: minmax(0, 1fr); }
  .qa-nav { position: static; max-height: none; display: flex; gap: 6px; overflow-x: auto; padding: 8px; }
  .qa-nav a { flex: none; white-space: nowrap; min-height: 40px; }
  .unit { grid-template-columns: minmax(0, 1fr); gap: 2px; }
  .unit .num { padding-top: 0; display: flex; gap: 8px; }
  .unit .num b { display: inline; }
  .text { font-size: calc(20px * var(--fs)); line-height: 2; }
  .unit .text { font-size: calc(20px * var(--fs)); }
  .ask { flex-direction: column; }
  .ask.small { flex-direction: row; }
  .ask button { min-height: 48px; }
  .top-in { gap: 6px; }
  .brand-sub { display: none; }
  .nav a { padding: 8px 9px; }
  .marklist li, .qlist li { flex-direction: column; align-items: stretch; }
}

/* فهرس الآيات */
.ayat { padding: 0 14px 12px; }
.aya { border-top: 1px solid var(--line-soft); padding: 10px 0; }
.aya-n { font-size: 14px; font-weight: 600; color: var(--green); margin-bottom: 4px; }
.aya-p { display: block; text-decoration: none; color: var(--ink); padding: 6px 8px; border-radius: 8px; }
.aya-p:hover { background: var(--quote); }
.aya-p small { display: block; color: var(--muted); font-size: 13px; font-family: var(--sans); }
.gloss { margin: 6px 0; padding: 8px 12px; background: var(--quote); border-radius: 8px; font-size: 15px; unicode-bidi: plaintext; }
