:root {
  --ink: #17201c;
  --muted: #5f6b64;
  --paper: #fbf6ea;
  --paper-2: #fffdf7;
  --line: #e7dbc1;
  --emerald: #0b4f35;
  --emerald-2: #0f6b46;
  --emerald-3: #dceee6;
  --gold: #c49a3a;
  --gold-2: #f1dfb8;
  --rose: #8f3e2f;
  --shadow: 0 18px 55px rgba(19, 35, 27, 0.14);
  --radius: 24px;
  --arabic: "Noto Naskh Arabic", "Amiri", "Times New Roman", serif;
  --latin: "Inter", system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }
html { scroll-behavior: smooth; }
body {
  margin: 0;
  font-family: var(--latin);
  color: var(--ink);
  background:
    radial-gradient(circle at top left, rgba(196, 154, 58, 0.18), transparent 30rem),
    linear-gradient(180deg, #fbf6ea 0%, #fffdf7 45%, #f7efd9 100%);
  min-height: 100vh;
}

a { color: inherit; text-decoration: none; }
button, input, select { font: inherit; }
button { cursor: pointer; }
.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; }

.site-header {
  position: sticky;
  top: 0;
  z-index: 30;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 0.82rem clamp(1rem, 4vw, 3rem);
  background: rgba(255, 253, 247, 0.92);
  backdrop-filter: blur(14px);
  border-bottom: 1px solid rgba(231, 219, 193, 0.8);
}

.brand { display: inline-flex; align-items: center; gap: 0.8rem; }
.brand-mark {
  width: 46px;
  height: 46px;
  display: grid;
  place-items: center;
  border-radius: 16px;
  background: var(--emerald);
  color: var(--gold-2);
  font-family: var(--arabic);
  font-size: 1.35rem;
  box-shadow: 0 10px 28px rgba(11, 79, 53, 0.22);
}
.brand strong { display: block; font-size: 1rem; letter-spacing: -0.02em; }
.brand small { display: block; color: var(--muted); font-size: 0.78rem; margin-top: 0.1rem; }

.top-nav { display: flex; align-items: center; gap: 0.35rem; }
.top-nav a {
  color: var(--muted);
  font-weight: 700;
  font-size: 0.92rem;
  padding: 0.65rem 0.85rem;
  border-radius: 999px;
}
.top-nav a:hover { background: var(--emerald-3); color: var(--emerald); }
.menu-button { display: none; border: 1px solid var(--line); background: var(--paper-2); padding: 0.55rem 0.8rem; border-radius: 999px; color: var(--emerald); font-weight: 800; }

.hero {
  position: relative;
  overflow: hidden;
  isolation: isolate;
  padding: clamp(3.5rem, 9vw, 8rem) clamp(1rem, 4vw, 3rem) clamp(2.3rem, 5vw, 4rem);
  background: linear-gradient(135deg, #0a3d2b, #0b5a3b 60%, #173427);
  color: #fffdf7;
}
.hero-pattern {
  position: absolute;
  inset: 0;
  z-index: -1;
  opacity: 0.16;
  background-image:
    linear-gradient(30deg, rgba(255,255,255,.16) 12%, transparent 12.5%, transparent 87%, rgba(255,255,255,.16) 87.5%, rgba(255,255,255,.16)),
    linear-gradient(150deg, rgba(255,255,255,.16) 12%, transparent 12.5%, transparent 87%, rgba(255,255,255,.16) 87.5%, rgba(255,255,255,.16)),
    linear-gradient(30deg, rgba(255,255,255,.16) 12%, transparent 12.5%, transparent 87%, rgba(255,255,255,.16) 87.5%, rgba(255,255,255,.16)),
    linear-gradient(150deg, rgba(255,255,255,.16) 12%, transparent 12.5%, transparent 87%, rgba(255,255,255,.16) 87.5%, rgba(255,255,255,.16));
  background-size: 80px 140px;
  background-position: 0 0, 0 0, 40px 70px, 40px 70px;
}
.hero-content { max-width: 1120px; margin: 0 auto; text-align: center; }
.eyebrow {
  margin: 0 0 0.65rem;
  color: var(--gold);
  font-weight: 800;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  font-size: 0.78rem;
}
.hero .eyebrow {
  color: var(--gold-2);
  font-family: var(--arabic);
  font-size: 1.1rem;
  letter-spacing: 0.04em;
  text-transform: none;
}
.hero h1 {
  margin: 0 auto;
  max-width: 980px;
  font-size: clamp(2.2rem, 6vw, 5.4rem);
  line-height: 0.96;
  letter-spacing: -0.065em;
}
.hero-copy {
  max-width: 760px;
  margin: 1.1rem auto 2rem;
  color: rgba(255, 253, 247, 0.87);
  font-size: clamp(1rem, 2vw, 1.22rem);
  line-height: 1.65;
}

.search-panel {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 0.65rem;
  width: min(920px, 100%);
  margin: 0 auto;
  padding: 0.68rem;
  background: rgba(255, 253, 247, 0.13);
  border: 1px solid rgba(240, 223, 184, 0.4);
  border-radius: 24px;
  backdrop-filter: blur(10px);
}
.search-panel input {
  width: 100%;
  min-height: 66px;
  border: 0;
  border-radius: 18px;
  padding: 0 1.2rem;
  background: rgba(255, 253, 247, 0.98);
  color: var(--ink);
  font-size: 1.05rem;
  outline: none;
}
.search-panel input:focus { box-shadow: 0 0 0 4px rgba(240, 223, 184, 0.45); }
.search-panel button,
.ghost-button,
.filter-box select,
.jump-box button,
.pagination button,
.result-card button,
.collection-card button,
.dialog-close,
.show-more {
  border: 0;
  border-radius: 18px;
  font-weight: 800;
}
.search-panel button,
.jump-box button,
.result-card button,
.collection-card button,
.show-more {
  padding: 0 1.4rem;
  color: #fffdf7;
  background: linear-gradient(135deg, var(--gold), #b58023);
  box-shadow: 0 10px 28px rgba(96, 55, 5, 0.22);
}
.search-panel button:hover,
.jump-box button:hover,
.result-card button:hover,
.collection-card button:hover,
.show-more:hover { filter: brightness(1.03); transform: translateY(-1px); }
.quick-actions { display: flex; justify-content: center; flex-wrap: wrap; gap: 0.5rem; margin-top: 1rem; }
.chip {
  border: 1px solid rgba(240, 223, 184, 0.38);
  background: rgba(255, 253, 247, 0.1);
  color: #fffdf7;
  border-radius: 999px;
  padding: 0.55rem 0.8rem;
  font-weight: 750;
}
.chip:hover { background: rgba(255, 253, 247, 0.2); }

.status-strip {
  width: min(1180px, calc(100% - 2rem));
  margin: -1.45rem auto 2rem;
  position: relative;
  z-index: 5;
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 0.75rem;
}
.status-card {
  background: var(--paper-2);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 1.15rem;
}
.status-card span { display: block; font-size: clamp(1.55rem, 3vw, 2.4rem); font-weight: 850; letter-spacing: -0.05em; color: var(--emerald); }
.status-card small { color: var(--muted); font-weight: 700; }

.content-grid {
  width: min(1180px, calc(100% - 2rem));
  margin: 0 auto;
  display: grid;
  grid-template-columns: 300px 1fr;
  gap: 1rem;
  align-items: start;
}
.filters { position: sticky; top: 88px; display: grid; gap: 1rem; }
.filter-box,
.results-area,
.section,
.browse-panel,
.ledger-item,
.notice {
  background: rgba(255, 253, 247, 0.86);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}
.filter-box { padding: 1.15rem; }
.filter-box h2, .filter-box h3 { margin: 0 0 1rem; letter-spacing: -0.03em; }
.filter-box h2 { font-size: 1.25rem; }
.filter-box h3 { font-size: 1rem; }
.filter-box label {
  display: block;
  margin: 0.9rem 0 0.38rem;
  color: var(--muted);
  font-weight: 800;
  font-size: 0.85rem;
}
.filter-box select {
  width: 100%;
  min-height: 46px;
  padding: 0 0.85rem;
  border: 1px solid var(--line);
  background: var(--paper-2);
  color: var(--ink);
  outline: none;
}
.filter-box.compact p { margin: 0; color: var(--muted); line-height: 1.55; font-size: 0.94rem; }
.results-area { min-height: 420px; padding: 1.15rem; }
.results-header { display: flex; align-items: flex-start; justify-content: space-between; gap: 1rem; padding-bottom: 1rem; border-bottom: 1px solid var(--line); }
.results-header h2 { margin: 0 0 0.25rem; font-size: clamp(1.35rem, 3vw, 2rem); letter-spacing: -0.045em; }
.results-header p { margin: 0; color: var(--muted); line-height: 1.45; }
.ghost-button { padding: 0.72rem 1rem; border: 1px solid var(--line); color: var(--emerald); background: var(--paper-2); }
.loading { display: flex; align-items: center; gap: 0.65rem; margin: 1rem 0; color: var(--muted); font-weight: 800; }
.spinner { width: 18px; height: 18px; border-radius: 50%; border: 3px solid var(--line); border-top-color: var(--emerald); animation: spin 0.8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.results { display: grid; gap: 0.9rem; padding-top: 1rem; }
.empty-state {
  padding: 1.3rem;
  border: 1px dashed var(--line);
  border-radius: 20px;
  color: var(--muted);
  line-height: 1.6;
  background: rgba(251, 246, 234, 0.65);
}
.result-card,
.hadith-row {
  border: 1px solid var(--line);
  border-radius: 22px;
  padding: 1rem;
  background: #fffdf7;
}
.result-top { display: flex; align-items: flex-start; justify-content: space-between; gap: 1rem; margin-bottom: 0.8rem; }
.result-top h3 { margin: 0 0 0.2rem; color: var(--emerald); letter-spacing: -0.03em; }
.result-top p { margin: 0; color: var(--muted); font-size: 0.92rem; }
.badges { display: flex; flex-wrap: wrap; gap: 0.35rem; justify-content: flex-end; }
.badge {
  display: inline-flex;
  align-items: center;
  border-radius: 999px;
  padding: 0.34rem 0.55rem;
  background: var(--emerald-3);
  color: var(--emerald);
  font-size: 0.72rem;
  font-weight: 850;
  white-space: nowrap;
}
.badge.warn { background: #fff1d6; color: #805317; }
.badge.demo { background: #f8e1db; color: var(--rose); }
.arabic {
  direction: rtl;
  text-align: right;
  font-family: var(--arabic);
  font-size: clamp(1.45rem, 3vw, 2.05rem);
  line-height: 2.15;
  color: #111;
  margin: 0.7rem 0;
}
.english { color: #26342e; line-height: 1.75; font-size: 1rem; margin: 0.7rem 0; }
.match-line { color: var(--muted); font-size: 0.84rem; margin: 0.45rem 0 0.8rem; }
.result-card button, .collection-card button { min-height: 42px; margin-top: 0.5rem; }
.show-more { display: block; min-height: 50px; margin: 1.2rem auto 0; padding: 0 1.5rem; }

.section {
  width: min(1180px, calc(100% - 2rem));
  margin: 2rem auto;
  padding: clamp(1.2rem, 3vw, 2rem);
}
.section-heading { max-width: 760px; margin-bottom: 1.2rem; }
.section-heading h2, .section h2 { margin: 0 0 0.55rem; font-size: clamp(1.75rem, 4vw, 3rem); letter-spacing: -0.055em; }
.section-heading p, .section > div > p, .preservation > p { color: var(--muted); line-height: 1.65; }
.collection-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 1rem; }
.collection-card { padding: 1.1rem; background: #fffdf7; border: 1px solid var(--line); border-radius: 22px; }
.collection-ar { direction: rtl; text-align: right; font-family: var(--arabic); color: var(--emerald); font-size: 1.35rem; margin: 0 0 0.5rem; }
.collection-card h3 { margin: 0 0 0.3rem; letter-spacing: -0.035em; }
.collection-card p { margin: 0 0 0.8rem; color: var(--muted); line-height: 1.45; }
.browse-panel { margin-top: 1rem; padding: 1rem; }
.browse-header { display: flex; justify-content: space-between; gap: 1rem; align-items: flex-start; border-bottom: 1px solid var(--line); padding-bottom: 1rem; }
.browse-header h3 { margin: 0 0 0.3rem; font-size: 1.5rem; }
.browse-header p { margin: 0; color: var(--muted); }
.jump-box label { display: block; color: var(--muted); font-size: 0.82rem; font-weight: 800; margin-bottom: 0.35rem; }
.jump-box div { display: flex; gap: 0.4rem; }
.jump-box input { width: 120px; min-height: 44px; border: 1px solid var(--line); border-radius: 14px; padding: 0 0.8rem; background: var(--paper-2); }
.jump-box button { min-height: 44px; }
.browse-list { display: grid; gap: 0.8rem; margin-top: 1rem; }
.hadith-row h4 { margin: 0; color: var(--emerald); }
.pagination { display: flex; justify-content: center; align-items: center; gap: 1rem; margin-top: 1rem; }
.pagination button { min-height: 44px; padding: 0 1rem; background: var(--emerald); color: #fffdf7; }
.pagination button:disabled { opacity: 0.35; cursor: not-allowed; }
.pagination span { color: var(--muted); font-weight: 800; }
.split { display: grid; grid-template-columns: 0.9fr 1.1fr; gap: 1.2rem; align-items: start; }
.notice { padding: 1rem; color: #68460d; background: #fff7e6; margin-top: 1rem; line-height: 1.6; }
.ledger { display: grid; gap: 0.75rem; max-height: 640px; overflow: auto; padding-right: 0.35rem; }
.ledger-item { padding: 1rem; box-shadow: none; }
.ledger-item h3 { margin: 0 0 0.45rem; color: var(--emerald); }
.ledger-item p { margin: 0.35rem 0; color: var(--muted); font-size: 0.92rem; line-height: 1.45; }
.ledger-item code { font-size: 0.75rem; word-break: break-all; }
.preservation-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 1rem; }
.preservation-grid article { background: #fffdf7; border: 1px solid var(--line); border-radius: 22px; padding: 1rem; }
.preservation-grid h3 { margin: 0 0 0.45rem; color: var(--emerald); }
.preservation-grid p { margin: 0; color: var(--muted); line-height: 1.55; }

.hadith-dialog {
  width: min(940px, calc(100% - 1.5rem));
  max-height: min(88vh, 980px);
  border: 0;
  border-radius: 28px;
  padding: 0;
  background: var(--paper-2);
  box-shadow: 0 32px 90px rgba(0,0,0,0.32);
}
.hadith-dialog::backdrop { background: rgba(10, 28, 18, 0.58); backdrop-filter: blur(4px); }
.dialog-close {
  position: sticky;
  float: right;
  top: 0.8rem;
  right: 0.8rem;
  margin: 0.8rem 0.8rem 0 0;
  width: 42px;
  height: 42px;
  background: var(--emerald);
  color: #fffdf7;
  z-index: 3;
}
.dialog-body { padding: 1.35rem clamp(1rem, 3vw, 2rem) 2rem; }
.dialog-body h2 { margin: 0 0 0.8rem; color: var(--emerald); letter-spacing: -0.04em; }
.dialog-divider { border: 0; border-top: 1px solid var(--line); margin: 1rem 0; }
.meta-table { display: grid; grid-template-columns: repeat(2, 1fr); gap: 0.65rem; margin-top: 1.2rem; }
.meta-table div { border: 1px solid var(--line); border-radius: 16px; padding: 0.8rem; background: #fbf6ea; }
.meta-table strong { display: block; color: var(--muted); font-size: 0.78rem; margin-bottom: 0.2rem; }
.meta-table span { word-break: break-word; }
.copy-actions { display: flex; gap: 0.5rem; flex-wrap: wrap; margin-top: 1rem; }
.copy-actions button { border: 1px solid var(--line); background: #fffdf7; color: var(--emerald); padding: 0.65rem 0.85rem; border-radius: 999px; font-weight: 850; }

.site-footer { padding: 2rem 1rem; text-align: center; color: var(--muted); }
.site-footer p { margin: 0.3rem 0; }

@media (max-width: 980px) {
  .status-strip, .content-grid, .split, .preservation-grid { grid-template-columns: 1fr 1fr; }
  .content-grid { align-items: stretch; }
  .filters { position: static; }
  .collection-grid { grid-template-columns: 1fr 1fr; }
  .split { display: block; }
  .split .ledger { margin-top: 1rem; }
}

@media (max-width: 680px) {
  .site-header { align-items: flex-start; }
  .menu-button { display: inline-flex; }
  .top-nav { display: none; position: absolute; top: 70px; left: 1rem; right: 1rem; background: var(--paper-2); border: 1px solid var(--line); border-radius: 20px; padding: 0.5rem; box-shadow: var(--shadow); }
  .top-nav.open { display: grid; }
  .top-nav a { padding: 0.75rem; }
  .search-panel { grid-template-columns: 1fr; }
  .search-panel button { min-height: 54px; }
  .status-strip, .content-grid, .collection-grid, .preservation-grid, .meta-table { grid-template-columns: 1fr; }
  .result-top, .browse-header { flex-direction: column; }
  .badges { justify-content: flex-start; }
  .arabic { font-size: 1.45rem; line-height: 2.05; }
  .hero { padding-top: 3rem; }
}
