:root {
  --bg: #f7f7f5;
  --ink: #171717;
  --muted: #6c6c68;
  --line: #deded8;
  --card: #ffffff;
  --soft: #eeeee9;
  --focus: #6a6a64;
  --radius: 12px;
  --content: 1180px;
  --reader: 760px;
}

* { box-sizing: border-box; }
html {
  scroll-behavior: smooth;
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
}
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 16px/1.6 Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  overflow-wrap: break-word;
}
img, svg, video { max-width: 100%; height: auto; }
a { color: inherit; }
button, input { font: inherit; }
button, a { -webkit-tap-highlight-color: transparent; }
:focus-visible { outline: 3px solid var(--focus); outline-offset: 3px; }

.skip-link {
  position: fixed;
  left: 12px;
  top: 12px;
  z-index: 100;
  transform: translateY(-160%);
  background: var(--ink);
  color: #fff;
  padding: 10px 14px;
  border-radius: 8px;
  text-decoration: none;
  font-weight: 700;
}
.skip-link:focus { transform: translateY(0); }
.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0,0,0,0);
  white-space: nowrap;
  border: 0;
}

/* Mobile-first header */
.topbar {
  display: flex;
  flex-direction: column;
  gap: 10px;
  width: 100%;
  padding: max(12px, env(safe-area-inset-top)) max(16px, env(safe-area-inset-right)) 12px max(16px, env(safe-area-inset-left));
  border-bottom: 1px solid var(--line);
  background: rgba(247, 247, 245, .98);
  z-index: 20;
}
.brand {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  min-height: 44px;
  width: fit-content;
  text-decoration: none;
  font-weight: 800;
  letter-spacing: -.025em;
  line-height: 1.15;
}
.brand-mark {
  flex: 0 0 auto;
  width: 34px;
  height: 34px;
  border-radius: 9px;
  background: var(--ink);
  color: #fff;
  display: grid;
  place-items: center;
  font-size: 12px;
  font-weight: 850;
}
.topbar-actions {
  display: flex;
  flex-direction: column;
  gap: 8px;
  min-width: 0;
}
.topbar nav {
  display: flex;
  width: 100%;
  gap: 4px;
  overflow-x: auto;
  overscroll-behavior-inline: contain;
  scrollbar-width: none;
  white-space: nowrap;
}
.topbar nav::-webkit-scrollbar { display: none; }
.topbar nav a {
  display: inline-flex;
  align-items: center;
  min-height: 44px;
  padding: 8px 12px;
  border-radius: 8px;
  color: var(--muted);
  text-decoration: none;
  font-weight: 600;
}
.topbar nav a:hover,
.topbar nav a[aria-current="page"] {
  color: var(--ink);
  background: var(--soft);
}

.global-search {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 8px;
  width: 100%;
}
.global-search input {
  width: 100%;
  min-width: 0;
  min-height: 46px;
  padding: 10px 13px;
  border: 1px solid var(--line);
  border-radius: 9px;
  background: #fff;
  color: var(--ink);
  font-size: 16px; /* prevents iOS input zoom */
  outline: none;
}
.global-search input:focus {
  border-color: #9b9b94;
  box-shadow: 0 0 0 3px rgba(23,23,23,.06);
}
.global-search button,
.button-link {
  min-height: 46px;
  border: 0;
  border-radius: 9px;
  padding: 10px 15px;
  background: var(--ink);
  color: #fff;
  font-weight: 700;
  cursor: pointer;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  white-space: nowrap;
}

.shell {
  width: 100%;
  max-width: var(--content);
  min-height: 70vh;
  margin: 0 auto;
  padding: 34px max(18px, env(safe-area-inset-right)) 72px max(18px, env(safe-area-inset-left));
}
.eyebrow {
  margin: 0;
  color: var(--muted);
  font-size: 11px;
  font-weight: 800;
  letter-spacing: .14em;
}
.hero {
  max-width: 850px;
  margin: 8px 0 42px;
}
.hero h1,
.section-head h1,
.search-page > h1,
.not-found h1 {
  margin: .18em 0;
  font-size: clamp(40px, 12vw, 72px);
  line-height: .98;
  letter-spacing: -.055em;
  text-wrap: balance;
}
.hero-lead {
  max-width: 820px;
  margin: 22px 0 0;
  color: #333;
  font-size: clamp(18px, 4.8vw, 23px);
  line-height: 1.5;
}
.hero-note {
  max-width: 720px;
  margin: 16px 0 0;
  color: var(--muted);
  font-size: 16px;
}
.hero-search { margin-top: 26px; max-width: 700px; }

.cards {
  display: grid;
  grid-template-columns: 1fr;
  gap: 12px;
}
.card {
  display: block;
  min-height: 150px;
  padding: 22px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--card);
  text-decoration: none;
}
.card:active { transform: scale(.995); }
.card span { font-size: 30px; font-weight: 800; }
.card h2 { margin: 10px 0 3px; font-size: 22px; }
.card p { margin: 0; color: var(--muted); }
.archive-note {
  max-width: 760px;
  margin-top: 54px;
  padding-top: 28px;
  border-top: 1px solid var(--line);
}
.archive-note h2 { margin: 0 0 8px; font-size: 23px; letter-spacing: -.025em; }
.archive-note p { margin: 0; color: var(--muted); font-size: 16px; }

.section-head {
  display: flex;
  flex-direction: column;
  gap: 24px;
  margin-bottom: 40px;
}
.section-head > div { max-width: 720px; }
.section-description { margin: 12px 0 0; color: var(--muted); font-size: 16px; }
.section-search { max-width: 620px; }
.group { margin: 0 0 42px; scroll-margin-top: 20px; }
.group h2 { margin: 0 0 10px; font-size: 18px; }
.list { border-top: 1px solid var(--line); }
.row {
  display: grid;
  grid-template-columns: 48px minmax(0, 1fr) 24px;
  gap: 10px;
  align-items: center;
  min-height: 58px;
  padding: 10px 2px;
  border-bottom: 1px solid var(--line);
  text-decoration: none;
}
.row .title { min-width: 0; overflow-wrap: anywhere; line-height: 1.35; }
.row:hover .title { text-decoration: underline; text-decoration-thickness: 1px; text-underline-offset: 3px; }
.num { color: var(--muted); font-size: 12px; font-variant-numeric: tabular-nums; }
.arrow { text-align: right; color: var(--muted); font-size: 18px; }

/* Reader: one-column first, then expands on larger screens */
.reader-wrap {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: 28px;
  width: 100%;
}
.meta {
  min-width: 0;
  padding-bottom: 20px;
  border-bottom: 1px solid var(--line);
  color: var(--muted);
  font-size: 13px;
}
.back-link {
  display: inline-flex;
  align-items: center;
  min-height: 44px;
  color: var(--ink);
  text-decoration: none;
  font-weight: 700;
}
.source-box {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 3px 14px;
  align-items: baseline;
  margin-top: 12px;
}
.source-label {
  margin: 0;
  font-size: 10px;
  letter-spacing: .12em;
  font-weight: 800;
}
.source-value { margin: 0; color: var(--ink); }
.source-link {
  grid-column: 1 / -1;
  display: inline-flex;
  align-items: center;
  min-height: 42px;
  width: fit-content;
  color: var(--ink);
  text-underline-offset: 3px;
}
.reader {
  min-width: 0;
  max-width: var(--reader);
  font-family: Georgia, "Times New Roman", serif;
  font-size: clamp(17.5px, 4.6vw, 19px);
  line-height: 1.72;
}
.article-header {
  margin-bottom: 28px;
  padding-bottom: 24px;
  border-bottom: 1px solid var(--line);
}
.article-author {
  margin: 0 0 12px;
  color: var(--muted);
  font-family: Inter, ui-sans-serif, system-ui, sans-serif;
  font-size: 12px;
  font-weight: 700;
  letter-spacing: .02em;
}
.reader h1 {
  margin: 0;
  font-family: Inter, ui-sans-serif, system-ui, sans-serif;
  font-size: clamp(36px, 10.5vw, 56px);
  line-height: 1.02;
  letter-spacing: -.05em;
  overflow-wrap: anywhere;
  text-wrap: balance;
}
.article-body h1 { display: none; }
.reader h2,
.reader h3,
.reader h4 {
  font-family: Inter, ui-sans-serif, system-ui, sans-serif;
  line-height: 1.22;
  letter-spacing: -.02em;
  scroll-margin-top: 18px;
}
.reader h2 { margin: 1.9em 0 .55em; font-size: 1.42em; }
.reader h3 { margin: 1.7em 0 .5em; font-size: 1.2em; }
.reader p { margin: 0 0 1.15em; }
.reader ul,
.reader ol { padding-left: 1.3em; }
.reader li { margin: .35em 0; }
.reader a { text-decoration-thickness: 1px; text-underline-offset: 2px; overflow-wrap: anywhere; }
.reader img {
  display: block;
  width: auto;
  max-width: 100%;
  height: auto;
  margin: 1.2em auto;
  border-radius: 5px;
}
.reader blockquote {
  margin: 1.4em 0;
  padding: .1em 0 .1em 16px;
  border-left: 3px solid var(--ink);
  color: #444;
}
.reader pre,
.reader table {
  max-width: 100%;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}
.reader pre {
  padding: 14px;
  border-radius: 8px;
  background: #ecece7;
  font-size: 13px;
}
.reader code {
  font: .86em ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  background: #ecece7;
  padding: 2px 5px;
  border-radius: 4px;
}
.reader pre code { padding: 0; background: transparent; }
.reader table { display: block; width: 100%; border-collapse: collapse; }
.reader th,
.reader td { min-width: 120px; padding: 8px 10px; border: 1px solid var(--line); text-align: left; }

.search-page { max-width: 900px; margin: 4px auto 0; }
.search-page-form { margin: 26px 0 22px; max-width: 780px; }
.search-summary {
  margin: 24px 0 0;
  padding: 14px 0;
  border-top: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
  color: var(--muted);
}
.search-summary strong,
.search-summary span { color: var(--ink); }
.search-results { display: flex; flex-direction: column; }
.search-result { padding: 22px 0; border-bottom: 1px solid var(--line); }
.result-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  color: var(--muted);
  font-size: 11px;
  font-weight: 750;
  letter-spacing: .05em;
  text-transform: uppercase;
}
.search-result h2 { margin: 7px 0 8px; font-size: 22px; line-height: 1.2; letter-spacing: -.025em; }
.search-result h2 a { text-decoration: none; }
.search-result p { margin: 0; color: #4d4d49; line-height: 1.65; }
.search-result mark { background: #e7e7df; color: inherit; padding: 1px 2px; border-radius: 2px; font-weight: 650; }
.result-link {
  display: inline-flex;
  align-items: center;
  min-height: 42px;
  margin-top: 8px;
  font-size: 13px;
  font-weight: 700;
  text-decoration: none;
}
.no-results,
.search-help {
  margin-top: 28px;
  padding: 22px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #fff;
}
.no-results h2 { margin: 0 0 4px; font-size: 21px; }
.no-results p,
.search-help p { margin: 0; color: var(--muted); }

.not-found { max-width: 700px; padding: 30px 0 60px; }
.not-found > p:not(.eyebrow) { color: var(--muted); font-size: 18px; }
.not-found-actions { display: flex; flex-wrap: wrap; gap: 16px; align-items: center; margin-top: 24px; }

.footer {
  padding: 30px max(18px, env(safe-area-inset-right)) max(44px, env(safe-area-inset-bottom)) max(18px, env(safe-area-inset-left));
  border-top: 1px solid var(--line);
  color: var(--muted);
}
.footer-inner {
  display: flex;
  flex-direction: column;
  gap: 8px;
  max-width: var(--content);
  margin: auto;
}
.footer p { margin: 0; max-width: 760px; }
.footer strong { color: var(--ink); }

/* Tablet */
@media (min-width: 700px) {
  .topbar {
    position: sticky;
    top: 0;
    padding: 12px 28px;
  }
  .topbar-actions { flex-direction: row; align-items: center; justify-content: space-between; }
  .compact-search { max-width: 360px; }
  .shell { padding: 50px 28px 90px; }
  .cards { grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 14px; }
  .card { padding: 24px; }
  .section-head { flex-direction: row; align-items: end; justify-content: space-between; gap: 28px; }
  .section-search { width: min(420px, 42vw); }
  .row { grid-template-columns: 62px minmax(0, 1fr) 30px; gap: 14px; padding: 13px 4px; }
  .reader { font-size: 18px; }
  .source-box { grid-template-columns: 1fr; gap: 0; }
  .source-label { margin-top: 14px; }
  .source-link { margin-top: 16px; }
  .footer-inner { flex-direction: row; justify-content: space-between; gap: 40px; }
}

/* Desktop */
@media (min-width: 960px) {
  .topbar { flex-direction: row; align-items: center; justify-content: space-between; min-height: 70px; padding: 12px 5vw; }
  .topbar-actions { flex-direction: row; align-items: center; justify-content: flex-end; gap: 22px; }
  .compact-search { width: 310px; }
  .topbar nav { width: auto; overflow: visible; gap: 8px; }
  .shell { padding-top: 64px; padding-bottom: 100px; }
  .hero { margin-top: 24px; margin-bottom: 56px; }
  .card { transition: transform .15s ease, box-shadow .15s ease; }
  .card:hover { transform: translateY(-2px); box-shadow: 0 10px 28px rgba(0,0,0,.06); }
  .reader-wrap { grid-template-columns: 210px minmax(0, var(--reader)); gap: 70px; justify-content: center; }
  .meta { position: sticky; top: 96px; align-self: start; padding-bottom: 0; border-bottom: 0; }
  .source-box { margin-top: 18px; padding-top: 18px; border-top: 1px solid var(--line); }
}

@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
  *, *::before, *::after { transition-duration: .01ms !important; animation-duration: .01ms !important; animation-iteration-count: 1 !important; }
}

/* Quran Alone Institute preservation badge */
.institute-badge-wrap {
  margin-top: 22px;
}
.institute-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  min-height: 44px;
  max-width: 100%;
  padding: 10px 14px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--card);
  color: var(--ink);
  text-decoration: none;
  font-size: 14px;
  line-height: 1.25;
  box-shadow: 0 1px 0 rgba(23, 23, 23, .04);
  transition: border-color .15s ease, background-color .15s ease, transform .15s ease;
}
.institute-badge:hover {
  border-color: #b9b9b2;
  background: var(--soft);
}
.institute-badge:active {
  transform: translateY(1px);
}
.institute-badge-label {
  color: var(--muted);
  font-weight: 600;
}
.institute-badge strong {
  font-weight: 800;
}

@media (max-width: 420px) {
  .institute-badge {
    width: 100%;
    justify-content: center;
  }
}


/* Desktop footer refinement: archive name | description | institute badge */
@media (min-width: 700px) {
  .footer-inner {
    display: grid;
    grid-template-columns: 140px minmax(0, 1fr) auto;
    align-items: center;
    gap: 28px;
  }

  .footer-inner > p:first-child {
    align-self: start;
  }

  .footer-inner > p:nth-child(2) {
    max-width: 760px;
    line-height: 1.55;
  }

  .institute-badge-wrap {
    margin-top: 0;
    justify-self: end;
  }

  .institute-badge {
    width: auto;
    min-width: max-content;
    white-space: nowrap;
    padding: 10px 16px;
  }
}

@media (min-width: 1100px) {
  .footer-inner {
    grid-template-columns: 135px minmax(420px, 1fr) auto;
    gap: 34px;
  }
}

