/*
 * The books page (/books/), built by build.mjs from content/books.json: the Qur'an, then every tafsir in one table with a
 * search, a filter and a sort (js/books.js). Loaded after site.css and pages.css, on this page only, and made only of
 * site.css's tokens. Arabic in the Arabic face, the Qur'an's name in the mushaf face; numbers in tabular figures.
 */

/* ---------- the library in four figures, between hairlines (as the leaderboards' facts) ---------- */
.bk-stats { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); margin: 0 0 32px; border-top: 1px solid var(--line); border-bottom: 1px solid var(--line); }
.bk-stats > div { display: grid; gap: 6px; align-content: start; padding: 20px var(--g) 20px 0; }
.bk-stats > div + div { padding-left: var(--g); border-left: 1px solid var(--line); }
.bk-stats dt { font-size: 13px; line-height: 16px; font-weight: 500; color: var(--mute); letter-spacing: 0.01em; }
.bk-stats dd { margin: 0; display: grid; gap: 4px; }
.bk-stats strong { font-weight: 500; font-size: 32px; line-height: 36px; letter-spacing: -0.02em; color: var(--ink); }
.bk-stats dd span { font-weight: 400; font-size: 15px; line-height: 20px; color: var(--mute); }
@media (max-width: 860px) {
  .bk-stats { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .bk-stats > div:nth-child(3) { padding-left: 0; border-left: 0; }
  .bk-stats > div:nth-child(n + 3) { border-top: 1px solid var(--line); }
  .bk-stats strong { font-size: 28px; line-height: 32px; }
}

/* ---------- the Qur'an: its own card, its name in the mushaf face, Tanzil credited and linked ---------- */
.bk-quran { position: relative; overflow: hidden; display: grid; grid-template-columns: minmax(0, 6fr) minmax(0, 5fr); gap: 28px 56px; align-items: center; padding: 36px 40px; margin-bottom: 72px; }
.bk-quran::before {
  /* the faint light from the top edge the landing page's cards have */
  content: "";
  position: absolute;
  inset: -40% -10% auto;
  height: 70%;
  background: radial-gradient(60% 60% at 50% 0%, rgba(var(--ink-rgb), 0.05), transparent 70%);
  pointer-events: none;
}
.bk-q-text { position: relative; display: grid; gap: 12px; align-content: start; max-width: 560px; }
.bk-q-text .h3 { margin-top: -4px; }
.bk-q-text .body { max-width: 520px; }
.bk-q-credit { margin: 6px 0 0; text-wrap: pretty; }
.bk-q-credit a { color: var(--soft); text-decoration: underline; text-decoration-color: rgba(var(--ink-rgb), 0.3); text-underline-offset: 3px; transition: text-decoration-color 0.2s, color 0.2s; }
.bk-q-credit a:hover { color: var(--ink); text-decoration-color: currentColor; }
.bk-q-side { position: relative; display: grid; gap: 18px; justify-items: end; text-align: right; }
.bk-q-name { margin: 0; font-size: clamp(44px, 5vw, 64px); line-height: 1.55; color: var(--ink); }
.bk-q-figs { margin: 0; display: flex; gap: 0; }
.bk-q-figs div { display: grid; gap: 2px; padding: 0 0 0 20px; margin-left: 20px; border-left: 1px solid var(--line); text-align: left; }
.bk-q-figs div:first-child { padding-left: 0; margin-left: 0; border-left: 0; }
.bk-q-figs dt { font-size: 13px; line-height: 16px; font-weight: 500; color: var(--mute); }
.bk-q-figs dd { margin: 0; font-size: 22px; line-height: 28px; font-weight: 500; color: var(--ink); }
.bk-q-link, .bk-open a { display: inline-flex; align-items: center; gap: 6px; height: 36px; padding: 0 14px; border-radius: 18px; background: var(--panel2); color: var(--soft); font-size: 14px; font-weight: 500; white-space: nowrap; transition: background-color 0.2s, color 0.2s; }
.bk-q-link:hover, .bk-open a:hover { background: var(--raised); color: var(--ink); }
.bk-q-link svg, .bk-open a svg { flex-shrink: 0; }
/* one column: the name first, then what it is, then its figures and the link */
@media (max-width: 860px) {
  .bk-quran { grid-template-columns: minmax(0, 1fr); gap: 20px; padding: 28px 24px; margin-bottom: 56px; }
  .bk-q-side { display: contents; }
  .bk-q-name { order: -1; justify-self: stretch; text-align: right; }
  .bk-q-figs, .bk-q-link { justify-self: start; }
}

/* ---------- the tafsirs: a heading, what the columns mean, the tools, the table ---------- */
.bk-list-head { display: grid; gap: 8px; margin-bottom: 18px; }
.bk-terms { display: grid; grid-template-columns: max-content minmax(0, 1fr); gap: 6px 24px; max-width: 860px; margin: 0 0 28px; font-size: 15px; line-height: 21px; }
.bk-terms div { display: contents; } /* each term and its meaning on one row of two columns */
.bk-terms dt { color: var(--ink); font-weight: 500; }
.bk-terms dd { margin: 0; color: var(--mute); font-weight: 400; text-wrap: pretty; }
.bk-terms a { color: var(--soft); text-decoration: underline; text-decoration-color: rgba(var(--ink-rgb), 0.3); text-underline-offset: 3px; }
.bk-terms a:hover { color: var(--ink); text-decoration-color: currentColor; }
.bk-terms .ar { font-size: 1.2em; line-height: 1; font-weight: 400; }
@media (max-width: 620px) {
  .bk-terms { grid-template-columns: minmax(0, 1fr); gap: 2px; }
  .bk-terms div + div dt { margin-top: 10px; }
}

/* the tools: shown only where the script runs (the class is set before they are drawn, so nothing moves) */
.bk-tools { display: none; flex-wrap: wrap; align-items: center; gap: 12px 16px; margin-bottom: 14px; }
.bk-js .bk-tools { display: flex; }
.bk-search { flex: 1 1 300px; display: flex; align-items: center; gap: 10px; height: 48px; padding: 0 18px; border-radius: 24px; background: var(--field); color: var(--mute); cursor: text; transition: box-shadow 0.2s; }
.bk-search:focus-within { box-shadow: inset 0 0 0 2px var(--ink); color: var(--soft); }
.bk-search svg { flex-shrink: 0; }
.bk-search input { flex: 1; min-width: 0; height: 100%; border: 0; outline: 0; padding: 0; background: none; color: var(--ink); font: inherit; font-weight: 400; font-size: 17px; }
.bk-search input::placeholder { color: var(--mute); opacity: 1; }
.bk-search input:focus-visible { outline: 0; }
/* the clear button: the header's close icon in the field's own colours, not the browser's */
.bk-search input::-webkit-search-cancel-button {
  -webkit-appearance: none;
  appearance: none;
  flex-shrink: 0;
  width: 20px;
  height: 20px;
  margin-left: 10px;
  background: var(--mute);
  cursor: pointer;
  -webkit-mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath d='M6.3 6.3a1 1 0 0 1 1.4 0L12 10.6l4.3-4.3a1 1 0 1 1 1.4 1.4L13.4 12l4.3 4.3a1 1 0 0 1-1.4 1.4L12 13.4l-4.3 4.3a1 1 0 0 1-1.4-1.4l4.3-4.3-4.3-4.3a1 1 0 0 1 0-1.4Z'/%3E%3C/svg%3E") center / 20px no-repeat;
  mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath d='M6.3 6.3a1 1 0 0 1 1.4 0L12 10.6l4.3-4.3a1 1 0 1 1 1.4 1.4L13.4 12l4.3 4.3a1 1 0 0 1-1.4 1.4L12 13.4l-4.3 4.3a1 1 0 0 1-1.4-1.4l4.3-4.3-4.3-4.3a1 1 0 0 1 0-1.4Z'/%3E%3C/svg%3E") center / 20px no-repeat;
}
.bk-search input::-webkit-search-cancel-button:hover { background: var(--ink); }
/* segmented controls (DESIGN-SYSTEM: Chip / segmented control): the panel2 track, the chosen segment solid ink */
.bk-seg { display: flex; align-items: center; gap: 10px; margin: 0; padding: 0; border: 0; min-width: 0; }
.bk-seg-label { float: left; padding: 0; font-size: 15px; line-height: 20px; font-weight: 500; color: var(--mute); } /* float: a legend set beside its controls */
.bk-seg-track { display: inline-flex; gap: 4px; padding: 4px; border-radius: 22px; background: var(--panel2); max-width: 100%; overflow-x: auto; scrollbar-width: none; }
.bk-seg-track::-webkit-scrollbar { display: none; }
.bk-seg label { position: relative; flex-shrink: 0; }
.bk-seg input { position: absolute; inset: 0; width: 100%; height: 100%; margin: 0; opacity: 0; cursor: pointer; }
.bk-seg label > span { display: inline-flex; align-items: center; gap: 6px; height: 36px; padding: 0 14px; border-radius: 18px; color: var(--soft); font-size: 15px; font-weight: 500; white-space: nowrap; transition: background-color 0.2s var(--ease), color 0.2s var(--ease); }
.bk-seg label:hover > span { color: var(--ink); }
.bk-seg input:checked + span { background: var(--ink); color: var(--black); }
.bk-seg input:focus-visible + span { outline: 2px solid var(--ink); outline-offset: 2px; }
.bk-seg .k { color: var(--mute); font-weight: 400; }
.bk-seg input:checked + span .k { color: inherit; opacity: 0.7; }
.bk-count { margin: 0 0 14px; min-height: 20px; }
@media (max-width: 620px) {
  .bk-search { flex-basis: 100%; }
  .bk-seg-track { flex: 1; }
  /* the filter takes the row under the search, its three segments sharing it, so the last is never cut off */
  .bk-seg[data-control="filter"] { flex-basis: 100%; }
  .bk-seg label { flex: 1 0 auto; }
  .bk-seg label > span { width: 100%; justify-content: center; padding: 0 10px; }
}
@media (max-width: 400px) {
  .bk-seg label > span { gap: 4px; padding: 0 8px; font-size: 14px; }
}
@media (max-width: 350px) {
  .bk-seg .k { display: none; } /* the count line under the tools still says how many each shows */
}

/* ---------- the table: one row per book; the title and its author first, then the figures ---------- */
.bk-grid { width: 100%; border-collapse: separate; border-spacing: 0; font-size: 15px; line-height: 20px; }
.bk-grid thead th {
  position: sticky;
  top: 72px; /* under the bar */
  z-index: 1;
  padding: 14px 16px;
  background: var(--fill);
  text-align: left;
  font-weight: 500;
  font-size: 13px;
  line-height: 16px;
  color: var(--mute);
  white-space: nowrap;
  border-bottom: 1px solid var(--line);
}
.bk-grid thead th:first-child { border-top-left-radius: var(--r-card); padding-left: 28px; }
.bk-grid thead th:last-child { border-top-right-radius: var(--r-card); }
.bk-grid .bk-n { text-align: right; width: 128px; }
.bk-grid .bk-cov { width: 196px; }
.bk-grid .bk-pages { width: 116px; }
.bk-grid .bk-open { width: 168px; text-align: right; padding-right: 20px; }
.bk-grid tbody th, .bk-grid tbody td { padding: 18px 16px; vertical-align: top; border-top: 1px solid var(--line); text-align: left; font-weight: 400; color: var(--soft); }
.bk-grid tbody tr:first-child > * { border-top: 0; }
/* and when the search or the filter hides the first rows, the first one still shown (a rule of its own: a browser that
   does not know "of S" drops only this) */
.bk-grid tbody tr:nth-child(1 of :not([hidden])) > * { border-top: 0; }
.bk-grid tbody .bk-n { text-align: right; }
.bk-grid tbody .bk-open { text-align: right; padding-right: 20px; }
.bk-grid tbody .bk-open a { margin-top: -2px; } /* centred on the title's first line */
.bk-grid tbody tr { transition: background-color 0.15s; }
.bk-grid tbody tr:hover { background: rgba(var(--ink-rgb), 0.03); }

/* the book: its title, its author and his death year, and whether the ayah lookup answers from it. Arabic set as the
   landing page sets a book's name in an English card: right to left, on the column's left edge. Each line is a box
   as wide as its text, so a short one sits on that edge; a title too long for one line fills the column and its lines
   start on the right, where Arabic starts, so the second line follows on from the first */
.bk-grid th.bk-book { padding-left: 28px; min-width: 0; }
.bk-title { display: block; width: fit-content; max-width: 100%; font-family: var(--arabic); direction: rtl; text-align: right; unicode-bidi: isolate; font-size: 20px; line-height: 32px; font-weight: 500; color: var(--ink); overflow-wrap: anywhere; text-wrap: pretty; }
.bk-by { display: block; width: fit-content; max-width: 100%; margin-top: 2px; font-family: var(--arabic); direction: rtl; text-align: right; unicode-bidi: isolate; font-size: 16px; line-height: 24px; color: var(--mute); }
.bk-tag { display: inline-flex; align-items: center; height: 24px; margin-top: 8px; padding: 0 10px; border-radius: 12px; background: var(--raised); color: var(--ink); font-family: var(--sans); font-size: 13px; line-height: 16px; font-weight: 500; white-space: nowrap; }
.bk-terms .bk-tag { margin-top: -2px; }

/* the figures: the value in ink, one quiet line beneath */
.bk-grid .v { display: block; font-size: 16px; line-height: 22px; font-weight: 500; color: var(--ink); }
.bk-grid .v.none, .bk-grid .v .none { color: var(--mute); font-weight: 400; }
.bk-grid .sub { display: block; margin-top: 3px; font-size: 13px; line-height: 17px; color: var(--mute); }
.bk-grid .bk-n .sub { white-space: nowrap; }
/* how much of the Qur'an: the count, a slim bar on the whole Qur'an's scale, the share and how it was read */
.bk-cov .bar { display: block; width: 100%; max-width: 160px; height: 4px; margin-top: 8px; border-radius: 2px; background: var(--line); overflow: hidden; }
.bk-cov .bar i { display: block; height: 100%; border-radius: 2px; background: var(--soft); }
.bk-cov .sub { margin-top: 6px; }

/* nothing matches */
.bk-empty { display: grid; justify-items: center; gap: 14px; padding: 48px 24px 56px; text-align: center; }
.bk-empty[hidden] { display: none; }
.bk-table.is-empty thead { display: none; }

.bk-note { margin: 20px 0 0; max-width: 860px; line-height: 21px; }
.bk-note code { font-family: var(--sans); font-size: 0.95em; padding: 1px 5px; border-radius: 6px; background: rgba(var(--ink-rgb), 0.07); color: var(--soft); white-space: nowrap; }

/* narrower screens: the quote links give way, so the titles keep a reading width; the rest stays a table */
@media (max-width: 1080px) {
  .bk-grid .bk-quotes { display: none; }
  .bk-grid .bk-n { width: 112px; }
  .bk-grid .bk-cov { width: 168px; }
  .bk-grid .bk-open { width: 150px; }
}

/* phones and small tablets: each book a card, its figures in a row beneath it, labelled */
@media (max-width: 980px) {
  .bk-grid .bk-quotes { display: block; }
  .bk-grid, .bk-grid tbody, .bk-grid tr, .bk-grid th, .bk-grid td { display: block; }
  .bk-grid thead { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }
  .bk-grid tbody tr { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 14px 16px; padding: 20px 22px; border-top: 1px solid var(--line); }
  .bk-grid tbody tr:first-child { border-top: 0; }
  .bk-grid tbody tr:nth-child(1 of :not([hidden])) { border-top: 0; }
  .bk-grid tbody tr > * { padding: 0 !important; border-top: 0; width: auto !important; text-align: left !important; }
  .bk-grid tbody th.bk-book { grid-column: 1 / span 3; }
  .bk-grid tbody td[data-label]::before { content: attr(data-label); display: block; margin-bottom: 4px; font-size: 12px; line-height: 16px; font-weight: 500; color: var(--mute); }
  .bk-grid tbody .bk-open { grid-column: 4; grid-row: 1; justify-self: end; text-align: right !important; } /* beside the title */
  .bk-cov .bar { max-width: none; }
}
/* phones: the three counts in a row, then the page numbers beside the link; the details that need room give way */
@media (max-width: 560px) {
  .bk-grid tbody tr { grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 12px 14px; padding: 18px; }
  .bk-grid tbody th.bk-book { grid-column: 1 / -1; }
  .bk-title { font-size: 19px; line-height: 30px; }
  .bk-grid .bk-n .sub, .bk-cov .sub .src { display: none; }
  .bk-grid tbody .bk-pages { grid-column: 1 / span 2; }
  .bk-pages .v, .bk-pages .sub { display: inline; margin: 0; font-size: 15px; }
  .bk-pages .sub::before { content: " · "; }
  .bk-grid tbody .bk-open { grid-column: 3; grid-row: auto; align-self: end; }
  .bk-grid tbody .bk-open a { margin-top: 0; }
}
