:root {
  --bg: #f4f2ee; --panel: #ffffff; --border: #e4e0d8; --text: #1d2420; --muted: #6f746f;
  --accent: #1e5b45; --accent-ink: #ffffff; --field: #faf9f6; --sahih: #2e8a57; --hasan: #2c7a8c;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #121614; --panel: #1a1f1c; --border: #2b322e; --text: #e9ece9; --muted: #98a19b;
    --accent: #4fae86; --accent-ink: #0d1411; --field: #151a17; --sahih: #4fae86; --hasan: #5fb3c4;
  }
}
* { box-sizing: border-box; }
html, body { margin: 0; }
body { background: var(--bg); color: var(--text); font: 15px/1.6 "IBM Plex Sans Arabic", system-ui, sans-serif; }
a { color: var(--accent); }
.wrap { max-width: 1120px; margin: 0 auto; padding: 0 16px; }
.top { display: flex; align-items: center; gap: 10px; padding: 18px 16px; }
.top a.brand { display: flex; align-items: center; gap: 10px; color: var(--text); text-decoration: none; }
.logo { width: 34px; height: 34px; border-radius: 9px; background: var(--accent); color: var(--accent-ink);
  display: grid; place-items: center; font: 700 20px "Amiri", serif; flex: none; }
.brand b { font-size: 18px; font-weight: 600; }
.top .spacer { flex: 1; }
.top nav a { font-size: 14px; font-weight: 600; text-decoration: none; margin-left: 16px; }
.credit { color: var(--muted); font-size: 13px; padding: 32px 0 40px; border-top: 1px solid var(--border); margin-top: 40px; }
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; font: inherit; font-weight: 600;
  border-radius: 10px; padding: 10px 16px; cursor: pointer; text-decoration: none;
  border: 1px solid var(--border); background: var(--panel); color: var(--text); }
.btn.primary { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
.btn:hover { filter: brightness(1.05); }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip { border: 1px solid var(--border); background: var(--panel); color: var(--text);
  border-radius: 999px; padding: 5px 12px; cursor: pointer; font: inherit; font-size: 13px; }
.chip[aria-pressed=true] { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
.toast { position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%); background: var(--text); color: var(--panel);
  padding: 8px 14px; border-radius: 8px; font-size: 13px; opacity: 0; transition: opacity .2s; pointer-events: none; }
.toast.show { opacity: 1; }

/* gallery */
.intro h1 { font-size: 30px; margin: 18px 0 6px; font-weight: 600; }
.intro p { color: var(--muted); margin: 0 0 20px; max-width: 640px; }
.filters { position: sticky; top: 0; z-index: 2; background: var(--bg); padding: 10px 0 16px; display: flex; flex-direction: column; gap: 12px; }
.search { width: 100%; max-width: 420px; font: inherit; color: var(--text); background: var(--panel);
  border: 1px solid var(--border); border-radius: 10px; padding: 9px 14px; outline: none; direction: rtl; }
.search:focus { border-color: var(--accent); }
.grid { columns: 3 280px; column-gap: 18px; }
.tile { break-inside: avoid; display: block; margin: 0 0 18px; text-decoration: none; color: var(--text); }
.tile img { display: block; width: 100%; height: auto; border-radius: 8px;
  box-shadow: 0 8px 24px rgba(0,0,0,.10), 0 1px 3px rgba(0,0,0,.06); transition: transform .15s; }
.tile:hover img { transform: translateY(-2px); }
.tile small { display: block; direction: rtl; text-align: right; color: var(--muted); font-size: 13px; padding: 6px 2px 0; }
.empty { color: var(--muted); padding: 40px 0; text-align: center; }

/* card page */
.card-page { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 40px; align-items: start; padding: 12px 0; }
.card-page .img img { display: block; width: 100%; height: auto; max-height: 82vh; object-fit: contain; border-radius: 8px;
  box-shadow: 0 18px 50px rgba(0,0,0,.16), 0 2px 6px rgba(0,0,0,.08); }
.info { direction: rtl; text-align: right; }
.info .matn { font: 700 26px/1.9 "Amiri", "Noto Naskh Arabic", serif; margin: 0 0 18px; }
.meta { display: grid; grid-template-columns: auto 1fr; gap: 6px 14px; margin: 0 0 22px; font-size: 15px; }
.meta dt { color: var(--muted); }
.meta dd { margin: 0; font-weight: 500; }
.grade { display: inline-block; color: #fff; border-radius: 999px; padding: 0 10px; font-size: 13px; font-weight: 600; }
.grade.sahih { background: var(--sahih); } .grade.hasan { background: var(--hasan); }
.actions { display: flex; flex-wrap: wrap; gap: 10px; direction: ltr; justify-content: flex-end; }
.links { display: flex; flex-wrap: wrap; gap: 16px; margin-top: 16px; font-size: 14px; font-weight: 600; justify-content: flex-end; direction: ltr; }
.links a { text-decoration: none; }
.pager { display: flex; justify-content: space-between; margin-top: 28px; font-size: 14px; font-weight: 600; }
.pager a { text-decoration: none; }
@media (max-width: 820px) {
  .card-page { grid-template-columns: 1fr; gap: 22px; }
  .card-page .img img { max-height: none; }
  .info .matn { font-size: 22px; }
}
