/* why-islam.org — monochrome e-ink reader */

:root {
  --bg: #ffffff; --fg: #111111; --muted: #666666; --rule: #d6d6d6; --soft: #f1f1f1;
  --pad: 1.5rem;
  --serif: Bookerly, Literata, "Iowan Old Style", Georgia, serif;
  --sans: "Amazon Ember", "Helvetica Neue", Helvetica, Arial, system-ui, sans-serif;
}
[data-theme="dark"] {
  --bg: #0c0c0c; --fg: #c8c8c4; --muted: #8b8b87; --rule: #2d2d2c; --soft: #191919;
}

* { box-sizing: border-box; }
html { font-size: 18px; height: 100%; background: var(--bg); -webkit-text-size-adjust: 100%; overscroll-behavior: none; }
body {
  position: relative; margin: 0; height: 100vh; height: 100dvh; overflow: hidden;
  display: flex; flex-direction: column;
  background: var(--bg); color: var(--fg);
  font-family: var(--serif); line-height: 1.6;
  -webkit-tap-highlight-color: transparent;
}
a { color: inherit; }
button { font: inherit; color: inherit; background: none; border: 0; cursor: pointer; }
:focus-visible { outline: 2px solid var(--fg); outline-offset: 2px; }
[hidden] { display: none !important; }

/* ── Screen header: book title + two controls ── */
.bar { display: flex; align-items: center; height: 2.6rem; flex: none; font-family: var(--sans); padding-top: env(safe-area-inset-top); box-sizing: content-box; }
.bar button { width: 3.2rem; height: 100%; font-size: 1rem; color: var(--muted); flex: none; }
html:not(.js) .bar button { visibility: hidden; }
.bar-title {
  flex: 1; text-align: center; text-decoration: none; color: var(--muted);
  font-size: .68rem; letter-spacing: .04em;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}

/* ── Screen footer: location + percent ── */
.status {
  display: flex; align-items: center; flex: none; gap: 1rem;
  height: calc(1.9rem + env(safe-area-inset-bottom)); padding: 0 var(--pad) env(safe-area-inset-bottom);
  font: .66rem var(--sans); color: var(--muted);
}
.status span { flex: 1; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.status b { font-weight: 400; }
.status a { display: none; }

/* ── The page ── */
main { flex: 1; min-height: 0; overflow-x: hidden; overflow-y: auto; -webkit-overflow-scrolling: touch; }
.flow { max-width: 34rem; margin: 0 auto; padding: 1rem var(--pad) 3rem; }
.flow p { margin: 0; text-indent: 1.4em; text-align: justify; hyphens: auto; -webkit-hyphens: auto; orphans: 2; widows: 2; }
.flow :not(p) + p, .flow p:first-child, .flow p[class], .flow p[class] + p { text-indent: 0; }

.chapter-head { text-align: center; margin: 14vh 0 2.4rem; }
.chapter-head::after { content: ""; display: block; width: 2.5rem; border-top: 1px solid var(--fg); margin: 1.3rem auto 0; }
.kicker, .label { font-family: var(--sans); font-size: .64rem; letter-spacing: .14em; text-transform: uppercase; color: var(--muted); }
.flow p.kicker, .flow p.label { text-align: inherit; hyphens: manual; -webkit-hyphens: manual; }
.flow p.label { margin: 1.5em 0 .45em; break-after: avoid; }
h1 { font-size: 1.7rem; line-height: 1.2; margin: .5rem 0 0; font-weight: 700; text-wrap: balance; }
h2 { font-size: 1.15rem; line-height: 1.3; margin: 2em 0 .5em; break-after: avoid; text-wrap: balance; }
h3 { font-size: 1rem; margin: 1.5em 0 .4em; break-after: avoid; }

blockquote { margin: 1.1em 0 1.1em 1.4em; font-style: italic; break-inside: avoid; }
.flow blockquote p { text-align: left; text-indent: 0; hyphens: manual; -webkit-hyphens: manual; }
.flow blockquote p.label { font-style: normal; margin: .5em 0 0; }
blockquote.verse { margin: 1.4em 0; text-align: center; }
.flow blockquote.verse p { text-align: center; }
.flow .arabic {
  font-family: "Geeza Pro", "Noto Naskh Arabic", "Amiri", "Traditional Arabic", serif;
  font-style: normal; font-size: 1.45rem; line-height: 2; margin-bottom: .3em;
}
.flow .pull { text-align: center; font-style: italic; font-weight: 700; font-size: 1.08rem; line-height: 1.5; margin: 1.5em 0; hyphens: manual; -webkit-hyphens: manual; text-wrap: balance; }
.note { border: 1px solid var(--fg); padding: .9rem 1rem; margin: 1.4em 0; break-inside: avoid; }
.note .label:first-child { margin-top: 0; color: var(--fg); }
.flow .def { margin: .7em 0; }
.def b::after { content: " — "; font-weight: 400; }
.claim { font-style: italic; }
.claim::before { content: "Claim"; display: block; font: 700 .64rem/1.8 var(--sans); letter-spacing: .14em; text-transform: uppercase; color: var(--muted); }

.stats { list-style: none; display: flex; gap: .6rem; padding: 0; margin: 0 0 1.5em; text-align: center; }
.stats li { flex: 1; font: .66rem/1.35 var(--sans); color: var(--muted); border-top: 2px solid var(--fg); padding-top: .5rem; }
.stats b { display: block; font: 700 1.5rem/1.1 var(--serif); color: var(--fg); }

table { width: 100%; border-collapse: collapse; margin: 1.2em 0; font-size: .78rem; line-height: 1.35; }
th, td { border-bottom: 1px solid var(--rule); padding: .5em .3em; text-align: left; vertical-align: top; overflow-wrap: break-word; hyphens: auto; -webkit-hyphens: auto; }
th { font: 700 .58rem/1.3 var(--sans); letter-spacing: .03em; hyphens: manual; -webkit-hyphens: manual; text-transform: uppercase; border-bottom: 1px solid var(--fg); }
td:first-child, th:first-child { width: 40%; padding-left: 0; hyphens: manual; -webkit-hyphens: manual; }
tr { break-inside: avoid; }
.c { text-align: center; }
.yes, .num { font-weight: 700; }
.no, .mid { color: var(--muted); }

/* ── End of chapter ── */
.chapter-nav { margin-top: 2.5rem; break-inside: avoid; font-family: var(--sans); }
.chapter-nav a, .btn { display: block; text-decoration: none; }
.chapter-nav .next, .btn {
  background: var(--fg); color: var(--bg); border: 1px solid var(--fg); border-radius: 4px;
  padding: .85rem 1.1rem; font: 700 .92rem/1.3 var(--sans);
}
.chapter-nav .next small, .btn small { display: block; font-weight: 400; font-size: .66rem; letter-spacing: .1em; text-transform: uppercase; opacity: .75; margin-bottom: .15rem; }
.chapter-nav .prev { color: var(--muted); font-size: .76rem; padding: .9rem 0 0; text-align: center; }

/* ── Paged layout ── */
html.paged main { overflow: hidden; touch-action: pinch-zoom; cursor: default; }
html.paged .flow {
  height: 100%; max-width: none; margin: 0; padding: .6rem var(--pad) .4rem;
  column-width: calc(var(--w, 100vw) - 2 * var(--pad)); column-gap: calc(2 * var(--pad)); column-fill: auto;
}
html.paged .chapter-nav { margin-top: 2rem; }
/* e-ink style refresh instead of a slide */
@keyframes ink { from { opacity: .15; } to { opacity: 1; } }
html.paged .flow.ink { animation: ink .18s ease-out; }
@media (prefers-reduced-motion: reduce) { html.paged .flow.ink { animation: none; } }

.hint {
  position: absolute; left: 50%; bottom: 3.2rem; transform: translateX(-50%); z-index: 6;
  background: var(--fg); color: var(--bg); font: .72rem var(--sans); padding: .55rem .9rem;
  border-radius: 4px; white-space: nowrap; pointer-events: none; transition: opacity .4s;
}

/* ── Menus: contents + text settings ── */
.veil { position: absolute; inset: 0; z-index: 8; background: rgba(0, 0, 0, .18); }
dialog { position: absolute; z-index: 9; margin: 0; border: 1px solid var(--fg); padding: 0; background: var(--bg); color: var(--fg); font-family: var(--sans); }
#toc { inset: 0 auto 0 0; width: min(21rem, 86%); height: 100%; border-width: 0 1px 0 0; overflow-y: auto; overscroll-behavior: contain; padding-top: env(safe-area-inset-top); }
#toc header { display: flex; align-items: center; justify-content: space-between; padding: .2rem .3rem .2rem 1.2rem; position: sticky; top: 0; background: var(--bg); border-bottom: 1px solid var(--fg); }
#toc header b { font-size: .68rem; letter-spacing: .14em; text-transform: uppercase; }
#toc header button { width: 2.75rem; height: 2.75rem; font-size: 1rem; }
#toc ol { list-style: none; margin: 0; padding: 0 0 2rem; }
#toc a { display: flex; gap: .8rem; padding: .7rem 1.2rem; text-decoration: none; font-family: var(--serif); font-size: .92rem; line-height: 1.35; border-bottom: 1px solid var(--rule); }
#toc a span { color: var(--muted); font: .72rem/1.9 var(--sans); min-width: 1.2rem; }
#toc a[aria-current] { font-weight: 700; background: var(--soft); }

#settings { inset: calc(2.8rem + env(safe-area-inset-top)) .6rem auto auto; width: min(18rem, calc(100% - 1.2rem)); border-radius: 4px; padding: 1rem; }
#settings h2 { font: 700 .62rem var(--sans); letter-spacing: .14em; text-transform: uppercase; color: var(--muted); margin: 0 0 .5rem; }
#settings .row { display: flex; gap: .5rem; margin-bottom: 1.1rem; }
#settings .row:last-child { margin-bottom: 0; }
#settings .row button { flex: 1; height: 2.75rem; border: 1px solid var(--rule); border-radius: 4px; font-size: .82rem; }
#settings .row button[aria-pressed="true"] { background: var(--fg); color: var(--bg); border-color: var(--fg); font-weight: 700; }
#settings [data-size] { font-family: var(--serif); border-color: var(--fg) !important; }
#settings .row [data-size="-1"] { font-size: .85rem; }
#settings .row [data-size="1"] { font-size: 1.4rem; }

/* ── Cover + contents ── */
.cover { text-align: center; padding: 9vh 0 2.5rem; }
.cover h1 { font-size: clamp(2.2rem, 10vw, 3rem); line-height: 1.1; margin: .9rem 0 1.1rem; }
.cover h1 em { display: block; font-weight: 400; }
.flow .cover p { text-align: center; text-indent: 0; hyphens: manual; -webkit-hyphens: manual; }
.flow .cover .sub { font-style: italic; color: var(--muted); margin-bottom: 2rem; }
.btn { max-width: 20rem; margin: 0 auto .7rem; }
.btn.ghost { background: none; color: var(--fg); font-weight: 400; }
.btn small { margin: .15rem 0 0; text-transform: none; letter-spacing: 0; font-size: .72rem; }

.paths { display: grid; gap: .7rem; margin: .2rem 0 0; }
.paths a { display: block; padding: .9rem 1rem; border: 1px solid var(--fg); border-radius: 4px; text-decoration: none; font-size: .84rem; line-height: 1.45; }
.paths b { display: block; font-size: 1rem; margin-bottom: .2rem; }
.paths i { font-style: normal; font-family: var(--sans); font-size: .74rem; white-space: nowrap; color: var(--muted); }

.contents { list-style: none; margin: 0; padding: 0; counter-reset: ch; }
.contents .group { font: 700 .62rem var(--sans); letter-spacing: .14em; text-transform: uppercase; color: var(--muted); padding: 1.6rem 0 .4rem; border-bottom: 1px solid var(--fg); }
.contents li:not(.group) { counter-increment: ch; border-bottom: 1px solid var(--rule); }
.contents a { display: grid; grid-template-columns: 2rem 1fr; padding: .8rem 0; text-decoration: none; line-height: 1.35; }
.contents a::before { content: counter(ch); font: .76rem/1.8 var(--sans); color: var(--muted); }
.contents b { display: block; font-size: 1rem; }
.contents small { grid-column: 2; color: var(--muted); font-size: .78rem; line-height: 1.4; margin-top: .15rem; }
.flow p.colophon { text-align: center; color: var(--muted); font: .64rem var(--sans); letter-spacing: .08em; margin-top: 2.5rem; }

/* ── Larger screens: one centred page, plain arrows at the sides ── */
@media (min-width: 46rem) {
  html { font-size: 19px; }
  .bar, .status, main { width: 100%; max-width: 38rem; margin-left: auto; margin-right: auto; }
  .status a {
    display: grid; place-items: center; position: fixed; top: calc(50% - 3rem); width: 3rem; height: 6rem;
    color: var(--muted); text-decoration: none; font-size: 1.6rem;
  }
  .status a:hover { color: var(--fg); }
  #settings { right: calc(50% - 19rem + .6rem); }
  .status .prev { right: calc(50% + 19.5rem); }
  .status .next { left: calc(50% + 19.5rem); }
}
