/* ─── Books.ilmgage — bilingual classics reader ─────────────────── */

:root {
  --paper: #faf7f1;
  --paper-raised: #ffffff;
  --ink: #2b2620;
  --ink-soft: #6b6257;
  --ink-faint: #9a9084;
  --accent: #1e6f5c;        /* deep green */
  --accent-soft: #e4efeb;
  --gold: #b28a3e;
  --gold-soft: #f3ead8;
  --rule: #e6dfd3;
  --shadow: 0 1px 3px rgba(60, 50, 30, 0.08), 0 8px 24px rgba(60, 50, 30, 0.06);
  --font-ar: "Amiri", "Scheherazade New", "Noto Naskh Arabic", "Geeza Pro", serif;
  --font-ar-quran: "Amiri Quran", "Amiri", "Scheherazade New", serif;
  --font-en: "Source Serif 4", "Iowan Old Style", Georgia, serif;
  --font-ui: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* { margin: 0; padding: 0; box-sizing: border-box; }
html { scroll-behavior: smooth; }
body {
  background: var(--paper);
  color: var(--ink);
  font-family: var(--font-en);
  font-size: 17px;
  line-height: 1.7;
  -webkit-font-smoothing: antialiased;
}
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

/* ─── Top bar ─── */
.topbar {
  position: sticky;
  top: 0;
  z-index: 50;
  background: rgba(250, 247, 241, 0.92);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--rule);
}
.topbar-inner {
  max-width: 1200px;
  margin: 0 auto;
  padding: 0.65rem 1.25rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
}
.brand {
  font-family: var(--font-ui);
  font-weight: 700;
  font-size: 1.02rem;
  letter-spacing: 0.01em;
  color: var(--ink);
}
.brand:hover { text-decoration: none; }
.brand .brand-ar {
  font-family: var(--font-ar);
  font-size: 1.25rem;
  color: var(--accent);
  margin-inline-start: 0.35rem;
}
.brand small {
  display: block;
  font-weight: 400;
  font-size: 0.68rem;
  color: var(--ink-faint);
  letter-spacing: 0.06em;
  text-transform: uppercase;
}
.topbar-links {
  font-family: var(--font-ui);
  display: flex;
  align-items: center;
  gap: 1rem;
  font-size: 0.88rem;
}
.topbar-links a { color: var(--ink-soft); font-weight: 500; }
.topbar-links a:hover { color: var(--accent); text-decoration: none; }
.topbar-links a.current { color: var(--accent); font-weight: 600; }

.sec-nav {
  font-family: var(--font-ui);
  display: flex;
  align-items: center;
  gap: 0.6rem;
  font-size: 0.9rem;
  color: var(--ink-soft);
  min-width: 0;
}
.sec-nav .navbtn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 2rem;
  height: 2rem;
  border-radius: 50%;
  border: 1px solid var(--rule);
  background: var(--paper-raised);
  color: var(--ink);
  font-size: 1rem;
  flex-shrink: 0;
  transition: all 0.15s ease;
}
.sec-nav .navbtn:hover { border-color: var(--accent); color: var(--accent); text-decoration: none; }
.sec-nav .navbtn.disabled { opacity: 0.3; pointer-events: none; }
.sec-nav .loc {
  font-weight: 600;
  color: var(--ink);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 40vw;
}
.sec-nav .loc a { color: var(--ink); }

/* ─── Section hero (reader) ─── */
.sec-hero {
  max-width: 900px;
  margin: 2.5rem auto 0;
  padding: 0 1.25rem;
  text-align: center;
}
.sec-hero .book-kicker {
  font-family: var(--font-ui);
  font-size: 0.78rem;
  text-transform: uppercase;
  letter-spacing: 0.22em;
  color: var(--gold);
  font-weight: 600;
}
.sec-hero .book-kicker a { color: var(--gold); }
.sec-hero .book-kicker .ar {
  font-family: var(--font-ar);
  font-size: 1.15rem;
  letter-spacing: 0;
  text-transform: none;
  margin-inline-start: 0.4rem;
}
.sec-hero .sec-title-ar {
  font-family: var(--font-ar);
  font-size: 2.3rem;
  line-height: 1.8;
  direction: rtl;
  color: var(--ink);
  margin: 1.1rem 0 0.2rem;
}
.sec-hero .sec-title-en {
  font-family: var(--font-ui);
  color: var(--ink-soft);
  font-size: 1.02rem;
}
.sec-hero .sec-source {
  font-family: var(--font-ui);
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.14em;
  color: var(--ink-faint);
  margin-top: 0.5rem;
}
.hero-rule {
  width: 72px;
  height: 3px;
  border: 0;
  border-radius: 2px;
  background: linear-gradient(90deg, var(--gold), var(--accent));
  margin: 1.8rem auto 0;
}

/* ─── Reader toolbar ─── */
.toolbar {
  max-width: 1200px;
  margin: 1.6rem auto 0.4rem;
  padding: 0 1.25rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  flex-wrap: wrap;
}
.toolbar-label {
  font-family: var(--font-ui);
  font-size: 0.72rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.16em;
  color: var(--ink-faint);
}
.toolbar-switches { display: flex; gap: 1.4rem; flex-wrap: wrap; }
.switch {
  font-family: var(--font-ui);
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  background: none;
  border: none;
  cursor: pointer;
  color: var(--ink-soft);
  font-size: 0.82rem;
  padding: 0.2rem 0;
}
.switch .switch-ar { font-family: var(--font-ar); font-size: 1rem; }
.switch-track {
  width: 2.1rem;
  height: 1.15rem;
  border-radius: 999px;
  background: var(--rule);
  position: relative;
  transition: background 0.18s ease;
  flex-shrink: 0;
}
.switch-thumb {
  position: absolute;
  top: 2px;
  left: 2px;
  width: 0.85rem;
  height: 0.85rem;
  border-radius: 50%;
  background: #fff;
  box-shadow: 0 1px 2px rgba(0,0,0,0.25);
  transition: transform 0.18s ease;
}
.switch.on .switch-track { background: var(--accent); }
.switch.on .switch-thumb { transform: translateX(0.95rem); }

/* ─── Reading card: two aligned columns ─── */
.reader {
  max-width: 1200px;
  margin: 1.2rem auto 3rem;
  padding: 0 1.25rem;
}
.text-card {
  background: var(--paper-raised);
  border: 1px solid var(--rule);
  border-radius: 14px;
  box-shadow: var(--shadow);
  overflow: hidden;
}
.pair {
  display: grid;
  grid-template-columns: 1fr 1fr;
  column-gap: 0;
}
.pair + .pair .cell { border-top: 1px dashed var(--rule); }
.cell { padding: 1.05rem 1.5rem; }
.cell.en {
  order: 1;
  font-family: var(--font-en);
  font-size: 0.99rem;
  line-height: 1.75;
  color: var(--ink);
  border-inline-end: 1px solid var(--rule);
}
.cell.ar {
  order: 2;
  direction: rtl;
  text-align: right;
  font-family: var(--font-ar);
  font-size: 1.42rem;
  line-height: 2.1;
  color: var(--ink);
}
.pair:hover .cell { background: #fdfbf6; }
.cell .pnum {
  font-family: var(--font-ui);
  font-size: 0.62rem;
  font-weight: 600;
  color: var(--gold);
  letter-spacing: 0.08em;
  display: block;
  margin-bottom: 0.35rem;
}

/* sub-headings inside a section */
.pair.heading .cell { background: var(--gold-soft); border-top: 1px solid var(--rule) !important; }
.pair.heading .cell.ar { font-size: 1.55rem; font-weight: 700; }
.pair.heading .cell.en { font-family: var(--font-ui); font-weight: 600; font-size: 0.95rem; color: var(--ink-soft); }
/* Qurʾān quotations */
.pair.verse .cell.ar { font-family: var(--font-ar-quran); font-size: 1.5rem; color: #3c5a2a; }
.pair.verse .cell.en { font-style: italic; }
/* poetry: hemistichs on one line */
.pair.poetry .cell.ar { display: flex; justify-content: space-between; gap: 2rem; flex-wrap: wrap; }
.pair.poetry .cell.ar .hemi { flex: 1 1 40%; }
.pair.poetry .cell.ar .hemi + .hemi { text-align: left; }
.pair.poetry .hemi-sep { color: var(--gold); }
.pair.poetry .cell.en { font-style: italic; color: var(--ink-soft); }
/* footnotes / editorial notes */
.pair.note .cell { font-size: 0.85em; color: var(--ink-soft); }
.pair.note .cell.ar { font-size: 1.15rem; line-height: 1.9; }

/* Arabic-only practice mode: hide English, let Arabic span the card */
.reader.hide-en .cell.en { display: none; }
.reader.hide-en .pair { grid-template-columns: 1fr; }

/* status */
.status-note {
  font-family: var(--font-ui);
  text-align: center;
  color: var(--ink-faint);
  font-size: 0.9rem;
  padding: 3rem 1rem;
}
.spin {
  display: inline-block;
  width: 1rem;
  height: 1rem;
  border: 2px solid var(--rule);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
  vertical-align: -0.2rem;
  margin-inline-end: 0.5rem;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* prev / next at the foot of a section */
.pager {
  max-width: 1200px;
  margin: 0 auto 4rem;
  padding: 0 1.25rem;
  display: flex;
  justify-content: space-between;
  gap: 1rem;
  font-family: var(--font-ui);
  font-size: 0.9rem;
}
.pager a {
  display: inline-flex;
  flex-direction: column;
  gap: 0.15rem;
  padding: 0.8rem 1.1rem;
  border: 1px solid var(--rule);
  border-radius: 12px;
  background: var(--paper-raised);
  color: var(--ink);
  max-width: 48%;
  transition: all 0.15s ease;
}
.pager a:hover { border-color: var(--accent); text-decoration: none; transform: translateY(-1px); }
.pager a .k { font-size: 0.68rem; text-transform: uppercase; letter-spacing: 0.14em; color: var(--gold); font-weight: 700; }
.pager a .t-ar { font-family: var(--font-ar); font-size: 1.15rem; direction: rtl; }
.pager a.next { margin-inline-start: auto; text-align: end; align-items: flex-end; }
.pager a .t-ar { text-align: inherit; }

/* ─── Landing / library ─── */
.landing {
  max-width: 1000px;
  margin: 4rem auto;
  padding: 0 1.25rem;
  text-align: center;
}
.landing h1 {
  font-family: var(--font-ar);
  font-size: 3rem;
  color: var(--accent);
  font-weight: 400;
}
.landing .tagline {
  font-family: var(--font-ui);
  color: var(--ink-soft);
  margin: 0.8rem 0 2.5rem;
  font-size: 1.02rem;
}
.lib-heading {
  font-family: var(--font-ui);
  font-size: 0.78rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.18em;
  color: var(--gold);
  margin: 2.4rem 0 0.9rem;
  text-align: left;
}
.book-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(290px, 1fr));
  gap: 1.1rem;
  text-align: start;
}
.book-card {
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
  background: var(--paper-raised);
  border: 1px solid var(--rule);
  border-radius: 14px;
  padding: 1.3rem 1.4rem 1.1rem;
  box-shadow: var(--shadow);
  transition: all 0.16s ease;
  color: var(--ink);
}
.book-card:hover { border-color: var(--accent); text-decoration: none; transform: translateY(-2px); }
.book-card .b-ar {
  font-family: var(--font-ar);
  direction: rtl;
  text-align: right;
  font-size: 1.75rem;
  line-height: 1.6;
}
.book-card .b-en {
  font-family: var(--font-ui);
  font-size: 0.78rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.14em;
  color: var(--gold);
}
.book-card .b-author {
  font-family: var(--font-ui);
  font-size: 0.85rem;
  color: var(--ink-soft);
}
.book-card .b-author .ar { font-family: var(--font-ar); font-size: 1.05rem; margin-inline-start: 0.3rem; }
.book-card .b-blurb {
  font-family: var(--font-en);
  font-size: 0.92rem;
  line-height: 1.6;
  color: var(--ink-soft);
  margin-top: 0.2rem;
}
.book-card .b-foot {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.6rem;
  margin-top: 0.6rem;
  font-family: var(--font-ui);
  font-size: 0.72rem;
  color: var(--ink-faint);
  letter-spacing: 0.04em;
}
.level {
  display: inline-block;
  font-family: var(--font-ui);
  font-size: 0.66rem;
  font-weight: 700;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  padding: 0.2rem 0.6rem;
  border-radius: 999px;
  background: var(--accent-soft);
  color: var(--accent);
}
.level.beginner { background: #e4efeb; color: #1e6f5c; }
.level.intermediate { background: #f3ead8; color: #8a6a2a; }
.level.advanced { background: #ece4f3; color: #5a3f7a; }
.progress {
  height: 4px;
  border-radius: 2px;
  background: var(--rule);
  overflow: hidden;
  margin-top: 0.5rem;
}
.progress > span { display: block; height: 100%; background: linear-gradient(90deg, var(--gold), var(--accent)); }

/* recents */
.recent-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(230px, 1fr));
  gap: 1rem;
  text-align: start;
  direction: rtl;
}
.recent-card {
  display: block;
  background: var(--paper-raised);
  border: 1px solid var(--rule);
  border-radius: 12px;
  padding: 1rem 1.15rem;
  box-shadow: var(--shadow);
  transition: all 0.16s ease;
  color: var(--ink);
}
.recent-card:hover { border-color: var(--accent); text-decoration: none; transform: translateY(-2px); }
.recent-card .k {
  font-family: var(--font-ui);
  font-size: 0.7rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.14em;
  color: var(--gold);
  direction: ltr;
  display: block;
  text-align: right;
}
.recent-card .t { font-family: var(--font-ar); font-size: 1.3rem; line-height: 1.8; display: block; }

/* ─── Book page: header + table of contents ─── */
.book-head { text-align: center; margin-top: 1.5rem; }
.book-head .back { font-family: var(--font-ui); font-size: 0.85rem; display: inline-block; margin-bottom: 1rem; }
.book-head .b-title-ar { font-family: var(--font-ar); font-size: 2.6rem; color: var(--ink); direction: rtl; line-height: 1.6; }
.book-head .b-title-en { font-family: var(--font-ui); color: var(--ink-soft); font-size: 1rem; margin-top: 0.2rem; }
.book-head .b-author { font-family: var(--font-ui); color: var(--ink-faint); font-size: 0.85rem; margin-top: 0.4rem; }
.book-head .b-author .ar { font-family: var(--font-ar); font-size: 1.1rem; }
.book-about {
  max-width: 760px;
  margin: 1.6rem auto 0;
  text-align: start;
  background: var(--paper-raised);
  border: 1px solid var(--rule);
  border-radius: 14px;
  box-shadow: var(--shadow);
  padding: 1.2rem 1.5rem;
  font-size: 0.95rem;
  line-height: 1.7;
  color: var(--ink-soft);
}
.book-about p + p { margin-top: 0.7rem; }
.book-about strong { color: var(--ink); }

.toc { max-width: 760px; margin: 2rem auto 0; text-align: start; }
.toc-part {
  font-family: var(--font-ui);
  font-size: 0.78rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.18em;
  color: var(--gold);
  margin: 2rem 0 0.7rem;
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 1rem;
}
.toc-part .ar { font-family: var(--font-ar); font-size: 1.25rem; letter-spacing: 0; text-transform: none; color: var(--ink); }
.toc-list { display: flex; flex-direction: column; gap: 0.45rem; }
.toc-item {
  display: grid;
  grid-template-columns: 2.2rem 1fr auto;
  align-items: center;
  column-gap: 0.8rem;
  background: var(--paper-raised);
  border: 1px solid var(--rule);
  border-radius: 10px;
  padding: 0.55rem 0.9rem;
  color: var(--ink);
  transition: all 0.15s ease;
}
a.toc-item:hover { border-color: var(--accent); text-decoration: none; transform: translateY(-1px); }
.toc-item.off { opacity: 0.5; }
.toc-item .n {
  font-family: var(--font-ui);
  font-size: 0.72rem;
  font-weight: 700;
  color: var(--gold);
  background: var(--gold-soft);
  border-radius: 8px;
  height: 1.9rem;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}
.toc-item .names { display: flex; flex-direction: column; line-height: 1.35; min-width: 0; }
.toc-item .t-ar { font-family: var(--font-ar); font-size: 1.25rem; direction: rtl; text-align: right; }
.toc-item .t-en { font-family: var(--font-ui); font-size: 0.74rem; color: var(--ink-faint); }
.toc-item .pg { font-family: var(--font-ui); font-size: 0.68rem; color: var(--ink-faint); white-space: nowrap; }
.toc-item.ready .pg { color: var(--accent); font-weight: 600; }

/* ─── Footer ─── */
.site-footer {
  max-width: 900px;
  margin: 0 auto 3rem;
  padding: 1.4rem 1.25rem 0;
  border-top: 1px solid var(--rule);
  font-family: var(--font-ui);
  font-size: 0.82rem;
  color: var(--ink-faint);
  text-align: center;
  line-height: 1.7;
}
.site-footer p { margin-bottom: 0.4rem; }
.site-footer strong { color: var(--ink-soft); }

/* ─── Responsive ─── */
@media (max-width: 720px) {
  .pair { grid-template-columns: 1fr; }
  .cell.ar { order: 1; border-inline-end: none; padding-bottom: 0.4rem; }
  .cell.en { order: 2; border-inline-end: none; padding-top: 0.4rem; color: var(--ink-soft); }
  .pair + .pair .cell.en { border-top: none; }
  .sec-hero .sec-title-ar { font-size: 1.8rem; }
  .topbar-inner { padding: 0.55rem 0.9rem; }
  .brand small { display: none; }
  .sec-nav .loc { max-width: 34vw; }
  .toc-item { grid-template-columns: 2rem 1fr; }
  .toc-item .pg { display: none; }
}
