/* ─── Tafsīr.ilmgage — bilingual tafsir 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;
}
.ayah-nav {
  font-family: var(--font-ui);
  display: flex;
  align-items: center;
  gap: 0.6rem;
  font-size: 0.9rem;
  color: var(--ink-soft);
}
.ayah-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;
  transition: all 0.15s ease;
}
.ayah-nav .navbtn:hover { border-color: var(--accent); color: var(--accent); text-decoration: none; }
.ayah-nav .navbtn.disabled { opacity: 0.3; pointer-events: none; }
.ayah-nav .loc { font-weight: 600; color: var(--ink); }

/* ─── Ayah header ─── */
.ayah-hero {
  max-width: 900px;
  margin: 2.5rem auto 0;
  padding: 0 1.25rem;
  text-align: center;
}
.ayah-hero .surah-title {
  font-family: var(--font-ui);
  font-size: 0.78rem;
  text-transform: uppercase;
  letter-spacing: 0.22em;
  color: var(--gold);
  font-weight: 600;
}
.ayah-hero .surah-title .ar {
  font-family: var(--font-ar);
  font-size: 1.15rem;
  letter-spacing: 0;
  text-transform: none;
  margin-inline-start: 0.4rem;
  color: var(--gold);
}
.ayah-text {
  font-family: var(--font-ar-quran);
  font-size: 2.15rem;
  line-height: 2.15;
  direction: rtl;
  color: var(--ink);
  margin: 1.4rem 0 1rem;
}
.ayah-text .ayah-num {
  font-size: 1.3rem;
  color: var(--gold);
  margin-inline-start: 0.3rem;
}
.ayah-translation {
  max-width: 640px;
  margin: 0 auto;
  color: var(--ink-soft);
  font-size: 1.02rem;
  font-style: italic;
}
.ayah-translation .translator {
  display: block;
  font-family: var(--font-ui);
  font-style: normal;
  font-size: 0.7rem;
  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: 2rem auto 0;
}

/* ─── Tafsir picker ─── */
.picker {
  max-width: 1200px;
  margin: 1.8rem auto 0.5rem;
  padding: 0 1.25rem;
}
.picker-label {
  font-family: var(--font-ui);
  font-size: 0.72rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.16em;
  color: var(--ink-faint);
  margin-bottom: 0.6rem;
}
.picker-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  direction: rtl; /* Arabic book names flow from the right edge */
}
.picker-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  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); }

.chip-group-label {
  font-family: var(--font-ui);
  font-size: 0.68rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.14em;
  color: var(--gold);
  margin: 0.9rem 0 0.45rem;
}
.chip {
  font-family: var(--font-ui);
  display: inline-flex;
  align-items: center;
  gap: 0.45rem;
  padding: 0.42rem 0.85rem;
  border-radius: 999px;
  border: 1px solid var(--rule);
  background: var(--paper-raised);
  color: var(--ink-soft);
  font-size: 0.85rem;
  cursor: pointer;
  transition: all 0.16s ease;
  user-select: none;
}
.chip:hover { border-color: var(--accent); color: var(--accent); }
.chip .chip-sign {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 1.1rem;
  height: 1.1rem;
  border-radius: 50%;
  font-size: 0.85rem;
  font-weight: 700;
  line-height: 1;
  background: var(--accent-soft);
  color: var(--accent);
}
.chip .chip-ar { font-family: var(--font-ar); font-size: 1.02rem; }
.chip.active {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}
.chip.active .chip-sign { background: rgba(255, 255, 255, 0.22); color: #fff; }
.chip.unavailable { opacity: 0.4; cursor: not-allowed; }

/* ─── Tafsir sections ─── */
.tafsir-list {
  max-width: 1200px;
  margin: 1.2rem auto 5rem;
  padding: 0 1.25rem;
}
.tafsir-card {
  background: var(--paper-raised);
  border: 1px solid var(--rule);
  border-radius: 14px;
  box-shadow: var(--shadow);
  margin-bottom: 2rem;
  overflow: hidden;
}
.tafsir-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 1.05rem 1.5rem;
  border-bottom: 1px solid var(--rule);
  background: linear-gradient(180deg, #fffdf9, #fbf8f2);
}
.tafsir-head .t-names { display: flex; flex-direction: column; gap: 0.1rem; }
.tafsir-head .t-ar {
  font-family: var(--font-ar);
  font-size: 1.5rem;
  color: var(--ink);
  line-height: 1.4;
}
.tafsir-head .t-en {
  font-family: var(--font-ui);
  font-size: 0.82rem;
  color: var(--ink-soft);
}
.tafsir-head .t-en .died { color: var(--ink-faint); }
.tafsir-head .t-close {
  font-family: var(--font-ui);
  border: 1px solid var(--rule);
  background: transparent;
  color: var(--ink-faint);
  width: 2rem;
  height: 2rem;
  border-radius: 50%;
  font-size: 1.05rem;
  cursor: pointer;
  flex-shrink: 0;
  transition: all 0.15s ease;
}
.tafsir-head .t-close:hover { color: #b0442f; border-color: #b0442f; }

/* Two-column aligned paragraph rows */
.pair {
  display: grid;
  grid-template-columns: 1fr 1fr;
  column-gap: 0;
}
.pair + .pair .cell { border-top: 1px dashed var(--rule); }
.cell { padding: 1.15rem 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.38rem;
  line-height: 2.05;
  color: var(--ink);
}
.pair:hover .cell { background: #fdfbf6; }

/* paragraph number marker */
.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;
}

/* loading / empty states */
.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); } }

/* ─── Landing page ─── */
.landing {
  max-width: 760px;
  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;
}
.ayah-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(230px, 1fr));
  gap: 1rem;
  text-align: start;
}
.ayah-card {
  display: block;
  background: var(--paper-raised);
  border: 1px solid var(--rule);
  border-radius: 12px;
  padding: 1.15rem 1.25rem;
  box-shadow: var(--shadow);
  transition: all 0.16s ease;
}
.ayah-card:hover { border-color: var(--accent); text-decoration: none; transform: translateY(-2px); }
.ayah-card .k {
  font-family: var(--font-ui);
  font-size: 0.72rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.14em;
  color: var(--gold);
}
.ayah-card .snippet {
  font-family: var(--font-ar);
  direction: rtl;
  text-align: right;
  font-size: 1.25rem;
  line-height: 1.9;
  color: var(--ink);
  margin-top: 0.5rem;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

/* ─── Footer / AI disclaimer ─── */
.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); }
.tafsir-head .ai-note { color: var(--ink-faint); font-size: 0.78rem; }
.tafsir-head .ai-note a { color: var(--gold); }

/* ─── Jump selector (Sūrah + Āyah) ─── */
.jump-bar {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  justify-content: center;
  gap: 0.75rem;
  margin: 0 auto 1rem;
  padding: 1.1rem 1.25rem;
  max-width: 720px;
  background: var(--paper-raised);
  border: 1px solid var(--rule);
  border-radius: 14px;
  box-shadow: var(--shadow);
}
.jump-field {
  display: flex;
  flex-direction: column;
  gap: 0.32rem;
  text-align: start;
  flex: 1 1 220px;
}
.jump-field.jump-field-ayah { flex: 0 1 130px; }
.jump-field > span {
  font-family: var(--font-ui);
  font-size: 0.68rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.14em;
  color: var(--ink-faint);
}
/* custom Amiri dropdown (native <select> can't style its popup list font) */
.cselect { position: relative; }
.cselect-trigger {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  font-family: var(--font-ar);
  font-size: 1.15rem;
  color: var(--ink);
  background: var(--paper);
  border: 1px solid var(--rule);
  border-radius: 9px;
  padding: 0.5rem 0.8rem;
  cursor: pointer;
  text-align: start;
  transition: border-color 0.15s ease;
}
.cselect.open .cselect-trigger, .cselect-trigger:focus { outline: none; border-color: var(--accent); }
.cselect-value { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.cselect-caret { color: var(--ink-faint); font-size: 0.7rem; flex-shrink: 0; }
.cselect-panel {
  position: absolute;
  z-index: 60;
  top: calc(100% + 4px);
  left: 0;
  right: 0;
  max-height: 300px;
  overflow-y: auto;
  background: var(--paper-raised);
  border: 1px solid var(--rule);
  border-radius: 10px;
  box-shadow: var(--shadow);
  padding: 0.3rem;
}
.cselect-opt {
  font-family: var(--font-ar);
  font-size: 1.12rem;
  color: var(--ink);
  padding: 0.5rem 0.7rem;
  border-radius: 7px;
  cursor: pointer;
  white-space: nowrap;
}
.cselect-opt:hover { background: var(--accent-soft); }
.cselect-opt.sel { background: var(--accent); color: #fff; }
.cselect-opt.off { color: var(--ink-faint); opacity: 0.5; cursor: not-allowed; }
.cselect-opt.off:hover { background: transparent; }
#jump-go {
  font-family: var(--font-ui);
  font-weight: 600;
  font-size: 0.92rem;
  color: #fff;
  background: var(--accent);
  border: none;
  border-radius: 9px;
  padding: 0.62rem 1.3rem;
  cursor: pointer;
  flex: 0 0 auto;
  transition: filter 0.15s ease;
}
#jump-go:hover { filter: brightness(1.08); }
#jump-go:disabled {
  background: var(--rule);
  color: var(--ink-faint);
  cursor: not-allowed;
  filter: none;
}
@media (max-width: 520px) {
  .jump-field, .jump-field.jump-field-ayah { flex: 1 1 100%; }
  #jump-go { width: 100%; }
}

/* ─── Library (home) ─── */
.landing { max-width: 1000px; text-align: center; }
.landing #library { text-align: start; }
.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: right;
}
.ayah-grid.rtl { direction: rtl; }
.ayah-card .ar-name { font-size: 1.3rem; }

.surah-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(170px, 1fr));
  gap: 0.7rem;
  direction: rtl;
}
.surah-card {
  display: grid;
  grid-template-columns: auto 1fr;
  grid-template-rows: auto auto;
  column-gap: 0.7rem;
  align-items: center;
  background: var(--paper-raised);
  border: 1px solid var(--rule);
  border-radius: 10px;
  padding: 0.7rem 0.9rem;
  transition: all 0.15s ease;
}
.surah-card:hover { border-color: var(--accent); text-decoration: none; transform: translateY(-1px); }
.surah-card .s-num {
  grid-row: 1 / 3;
  font-family: var(--font-ui);
  font-size: 0.72rem;
  font-weight: 700;
  color: var(--gold);
  border: 1px solid var(--gold-soft);
  background: var(--gold-soft);
  border-radius: 8px;
  min-width: 1.9rem;
  height: 1.9rem;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}
.surah-card .s-ar { font-family: var(--font-ar); font-size: 1.25rem; color: var(--ink); line-height: 1.5; }
.surah-card .s-en { font-family: var(--font-ui); font-size: 0.68rem; color: var(--ink-faint); direction: ltr; text-align: end; }
.surah-card.has-content { border-color: var(--accent); box-shadow: 0 0 0 1px var(--accent-soft); }
.surah-card.has-content .s-en { color: var(--accent); }

.surah-head { text-align: center; margin-top: 1.5rem; }
.surah-head .back {
  font-family: var(--font-ui);
  font-size: 0.85rem;
  display: inline-block;
  margin-bottom: 1rem;
}
.surah-head .s-title-ar { font-family: var(--font-ar); font-size: 2.4rem; color: var(--ink); }
.surah-head .s-title-en { font-family: var(--font-ui); color: var(--ink-soft); font-size: 0.95rem; margin-top: 0.2rem; }
.surah-head .s-hint { font-family: var(--font-ui); color: var(--ink-faint); font-size: 0.82rem; margin-top: 0.8rem; }
.ayah-num-grid {
  margin-top: 1.6rem;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(52px, 1fr));
  gap: 0.45rem;
  direction: ltr; /* Arabic numerals read left-to-right: 1 at top-left */
}
.ayah-num {
  font-family: var(--font-ui);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  height: 2.5rem;
  border-radius: 9px;
  border: 1px solid var(--rule);
  background: var(--paper-raised);
  color: var(--ink-faint);
  font-size: 0.9rem;
  opacity: 0.55;
}
.ayah-num.ready {
  opacity: 1;
  color: #fff;
  background: var(--accent);
  border-color: var(--accent);
  font-weight: 600;
  box-shadow: var(--shadow);
}
.ayah-num.ready:hover { text-decoration: none; filter: brightness(1.08); }

/* ─── 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; }
  .ayah-text { font-size: 1.65rem; }
  .topbar-inner { padding: 0.55rem 0.9rem; }
  .brand small { display: none; }
}
