/* ---------------------------------------------------------------------- *
 * Ad Hoc Tutorials — base styles
 * ---------------------------------------------------------------------- */

*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; }
img, svg { display: block; max-width: 100%; }
a { color: inherit; }

/* ---------------------------------------------------------------------- *
 * Theme tokens
 * ---------------------------------------------------------------------- */

:root {
  --bg: #ffffff;
  --bg-raised: #ffffff;
  --bg-subtle: #f4f5f7;
  --bg-hover: #eceef2;
  --border: #e4e6eb;
  --border-strong: #d3d6dd;
  --text: #16181d;
  --text-secondary: #565d6b;
  --text-tertiary: #8a91a0;
  --accent: #4338ca;
  --accent-hover: #362cad;
  --accent-contrast: #ffffff;
  --accent-soft-bg: #eef0fd;
  --accent-soft-text: #4338ca;
  --shadow-color: 220 20% 50%;
  --shadow-sm: 0 1px 2px hsl(var(--shadow-color) / 0.08);
  --shadow-md: 0 4px 16px hsl(var(--shadow-color) / 0.10);
  --shadow-lg: 0 12px 32px hsl(var(--shadow-color) / 0.14);
  --code-bg: #1d1f27;
  --code-text: #e4e6f1;
  --radius-sm: 6px;
  --radius-md: 12px;
  --radius-lg: 18px;
  --font-ui: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  --font-mono: ui-monospace, "SF Mono", SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0c0d10;
    --bg-raised: #15171c;
    --bg-subtle: #15171c;
    --bg-hover: #1e2128;
    --border: #262931;
    --border-strong: #34383f;
    --text: #eaecef;
    --text-secondary: #a2a8b4;
    --text-tertiary: #6d7380;
    --accent: #9192f0;
    --accent-hover: #a9aaf6;
    --accent-contrast: #0c0d10;
    --accent-soft-bg: #1c1c33;
    --accent-soft-text: #b3b4f8;
    --shadow-color: 220 40% 2%;
    --code-bg: #101116;
    --code-text: #dfe1ea;
    color-scheme: dark;
  }
}

:root[data-theme="dark"] {
  --bg: #0c0d10;
  --bg-raised: #15171c;
  --bg-subtle: #15171c;
  --bg-hover: #1e2128;
  --border: #262931;
  --border-strong: #34383f;
  --text: #eaecef;
  --text-secondary: #a2a8b4;
  --text-tertiary: #6d7380;
  --accent: #9192f0;
  --accent-hover: #a9aaf6;
  --accent-contrast: #0c0d10;
  --accent-soft-bg: #1c1c33;
  --accent-soft-text: #b3b4f8;
  --shadow-color: 220 40% 2%;
  --code-bg: #101116;
  --code-text: #dfe1ea;
  color-scheme: dark;
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.001ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.001ms !important;
  }
}

body {
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-ui);
  line-height: 1.55;
  transition: background-color .2s ease, color .2s ease;
}

.container {
  max-width: 1040px;
  margin: 0 auto;
  padding: 0 24px;
}

a { text-decoration: none; }
.link { color: var(--accent); text-decoration: underline; text-underline-offset: 2px; }

:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
  border-radius: 4px;
}

/* ---------------------------------------------------------------------- *
 * Header
 * ---------------------------------------------------------------------- */

.site-header {
  position: sticky;
  top: 0;
  z-index: 50;
  background: color-mix(in srgb, var(--bg) 82%, transparent);
  backdrop-filter: saturate(180%) blur(12px);
  -webkit-backdrop-filter: saturate(180%) blur(12px);
  border-bottom: 1px solid var(--border);
}

.header-inner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  height: 68px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  font-weight: 700;
  font-size: 17px;
  letter-spacing: -0.01em;
  color: var(--text);
  flex-shrink: 0;
}

.brand-mark {
  width: 32px;
  height: 32px;
  border-radius: 9px;
  background: linear-gradient(135deg, var(--accent), #06b6d4);
  display: flex;
  align-items: center;
  justify-content: center;
  color: #fff;
  font-family: var(--font-mono);
  font-weight: 700;
  font-size: 15px;
  flex-shrink: 0;
  box-shadow: var(--shadow-sm);
}

.brand-text-sub {
  display: block;
  font-weight: 500;
  font-size: 11px;
  color: var(--text-tertiary);
  letter-spacing: .02em;
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 10px;
}

.search-wrap {
  position: relative;
}

.search-wrap svg {
  position: absolute;
  left: 11px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--text-tertiary);
  pointer-events: none;
}

#search {
  width: 190px;
  max-width: 40vw;
  font: inherit;
  font-size: 14px;
  padding: 8px 12px 8px 34px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--bg-subtle);
  color: var(--text);
  transition: width .2s ease, border-color .2s ease, background .2s ease;
}

#search:focus {
  width: 240px;
  max-width: 50vw;
  background: var(--bg-raised);
  border-color: var(--border-strong);
  outline: none;
}

#search::placeholder { color: var(--text-tertiary); }

.icon-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 38px;
  height: 38px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--bg-subtle);
  color: var(--text-secondary);
  cursor: pointer;
  flex-shrink: 0;
  transition: background .15s ease, color .15s ease, transform .15s ease;
}

.icon-btn:hover { background: var(--bg-hover); color: var(--text); }
.icon-btn:active { transform: scale(0.94); }

.icon-btn svg { width: 18px; height: 18px; }
.theme-toggle .sun-icon, .theme-toggle .moon-icon { display: none; }
:root:not([data-theme="dark"]) .theme-toggle .sun-icon { display: block; }
:root[data-theme="dark"] .theme-toggle .moon-icon { display: block; }
@media (prefers-color-scheme: dark) {
  :root:not([data-theme]) .theme-toggle .sun-icon { display: none; }
  :root:not([data-theme]) .theme-toggle .moon-icon { display: block; }
}

/* ---------------------------------------------------------------------- *
 * Hero
 * ---------------------------------------------------------------------- */

.hero {
  padding: 56px 24px 28px;
  text-align: center;
}

.hero h1 {
  font-size: clamp(28px, 4vw, 40px);
  letter-spacing: -0.02em;
  margin: 0 0 10px;
}

.hero p {
  color: var(--text-secondary);
  font-size: 16px;
  margin: 0 auto;
  max-width: 480px;
}

/* ---------------------------------------------------------------------- *
 * Tag filters
 * ---------------------------------------------------------------------- */

.filters {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  justify-content: center;
  padding: 4px 24px 40px;
}

.chip {
  font: inherit;
  font-size: 13px;
  font-weight: 500;
  padding: 7px 14px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--bg-raised);
  color: var(--text-secondary);
  cursor: pointer;
  transition: all .15s ease;
  white-space: nowrap;
}

.chip:hover { border-color: var(--border-strong); color: var(--text); }

.chip[aria-pressed="true"] {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--accent-contrast);
}

/* ---------------------------------------------------------------------- *
 * Article grid / cards
 * ---------------------------------------------------------------------- */

.article-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 22px;
  padding-bottom: 72px;
}

.card {
  display: flex;
  flex-direction: column;
  background: var(--bg-raised);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  overflow: hidden;
  transition: transform .18s ease, box-shadow .18s ease, border-color .18s ease;
}

.card:hover {
  transform: translateY(-3px);
  box-shadow: var(--shadow-md);
  border-color: var(--border-strong);
}

.card-media {
  aspect-ratio: 16 / 9;
  background: var(--bg-subtle);
  overflow: hidden;
  position: relative;
}

.card-media img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  transition: transform .35s ease;
}

.card:hover .card-media img { transform: scale(1.04); }

.card-media.no-image {
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(135deg, var(--accent-soft-bg), var(--bg-subtle));
}

.card-media.no-image svg { width: 34px; height: 34px; color: var(--accent); opacity: .55; }

.card-body {
  padding: 18px 20px 20px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  flex: 1;
}

.card-meta {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 12.5px;
  color: var(--text-tertiary);
}

.card-meta .dot::before { content: "·"; margin: 0 2px; }

.card-title {
  font-size: 17px;
  font-weight: 650;
  letter-spacing: -0.01em;
  line-height: 1.35;
  margin: 0;
}

.card-title a::after { content: ""; position: absolute; inset: 0; }
.card-title a { position: static; color: var(--text); }
.card { position: relative; }

.card-excerpt {
  font-size: 14px;
  color: var(--text-secondary);
  line-height: 1.5;
  margin: 0;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.card-tags {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: auto;
  padding-top: 4px;
}

.tag-pill {
  font-size: 11.5px;
  font-weight: 600;
  padding: 3px 9px;
  border-radius: 999px;
  background: var(--accent-soft-bg);
  color: var(--accent-soft-text);
  position: relative;
  z-index: 1;
}

#empty-state {
  text-align: center;
  color: var(--text-secondary);
  padding: 60px 24px 100px;
}

/* ---------------------------------------------------------------------- *
 * Footer
 * ---------------------------------------------------------------------- */

.site-footer {
  border-top: 1px solid var(--border);
  padding: 40px 24px 40px;
  text-align: center;
  color: var(--text-tertiary);
  font-size: 13px;
}

.site-footer a { color: var(--text-secondary); text-decoration: underline; text-underline-offset: 2px; }

.hadith {
  max-width: 560px;
  margin: 0 auto 28px;
  padding: 0;
  border: none;
}

.hadith .hadith-label {
  display: block;
  font-size: 11px;
  font-style: normal;
  font-weight: 700;
  letter-spacing: .08em;
  text-transform: uppercase;
  color: var(--accent);
  margin: 0 0 10px;
}

.hadith p {
  font-size: 14.5px;
  font-style: italic;
  line-height: 1.65;
  color: var(--text-secondary);
  margin: 0 0 8px;
}

.hadith cite {
  display: block;
  font-style: normal;
  font-size: 12.5px;
  color: var(--text-tertiary);
}

/* ---------------------------------------------------------------------- *
 * Article page
 * ---------------------------------------------------------------------- */

.back-link {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 14px;
  font-weight: 550;
  color: var(--text-secondary);
  margin: 28px 0 0;
}

.back-link:hover { color: var(--text); }
.back-link svg { width: 15px; height: 15px; }

.article-page { padding-bottom: 90px; }

.article-header { padding: 22px 0 26px; }

.article-header .card-tags { margin-bottom: 14px; }

.article-header h1 {
  font-size: clamp(26px, 4vw, 38px);
  letter-spacing: -0.02em;
  line-height: 1.2;
  margin: 0 0 14px;
}

.article-meta {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  color: var(--text-tertiary);
  font-size: 14px;
}

.article-meta .dot::before { content: "·"; margin: 0 2px; }

.article-cover {
  border-radius: var(--radius-lg);
  overflow: hidden;
  margin: 24px 0 8px;
  border: 1px solid var(--border);
  background: var(--bg-subtle);
}

.article-cover img { width: 100%; aspect-ratio: 16/9; object-fit: cover; }

.prose {
  font-size: 17px;
  line-height: 1.75;
  color: var(--text);
  max-width: 720px;
  margin: 0 auto;
}

.prose > *:first-child { margin-top: 0; }

.prose p { margin: 1.15em 0; }

.prose h2 {
  font-size: 24px;
  letter-spacing: -0.01em;
  margin: 1.8em 0 .7em;
  scroll-margin-top: 90px;
}

.prose h1 {
  font-size: 22px;
  letter-spacing: -0.01em;
  margin: 1.8em 0 .7em;
  scroll-margin-top: 90px;
}

.prose h3 {
  font-size: 19px;
  margin: 1.6em 0 .6em;
  scroll-margin-top: 90px;
}

.prose ul, .prose ol { padding-left: 1.4em; margin: 1.1em 0; }
.prose li { margin: .4em 0; }
.prose li > p { margin: .5em 0; }

.prose a { color: var(--accent); text-decoration: underline; text-underline-offset: 2px; text-decoration-color: color-mix(in srgb, var(--accent) 40%, transparent); }
.prose a:hover { text-decoration-color: var(--accent); }

.prose strong { font-weight: 650; }

.prose blockquote {
  margin: 1.4em 0;
  padding: 4px 20px;
  border-left: 3px solid var(--accent);
  color: var(--text-secondary);
  background: var(--bg-subtle);
  border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
}

.prose hr {
  border: none;
  border-top: 1px solid var(--border);
  margin: 2.4em 0;
}

.prose img {
  border-radius: var(--radius-md);
  margin: 1.6em auto;
  border: 1px solid var(--border);
}

.prose iframe {
  width: 100%;
  aspect-ratio: 16 / 9;
  height: auto;
  border: 0;
  border-radius: var(--radius-md);
  margin: 1.6em 0;
  background: var(--bg-subtle);
}

.prose table {
  width: 100%;
  border-collapse: collapse;
  margin: 1.4em 0;
  font-size: 15px;
  display: block;
  overflow-x: auto;
}

.prose th, .prose td {
  border: 1px solid var(--border);
  padding: 8px 12px;
  text-align: left;
}

.prose > pre,
.prose > p > code,
.prose code {
  font-family: var(--font-mono);
}

.prose :not(pre) > code {
  background: var(--bg-subtle);
  border: 1px solid var(--border);
  padding: .15em .4em;
  border-radius: 5px;
  font-size: .87em;
}

.prose pre[class*="language-"] {
  margin: 1.6em 0;
  border-radius: var(--radius-md);
  font-size: 14px;
  line-height: 1.6;
  box-shadow: var(--shadow-sm);
}

.prose .katex { font-size: 1.02em; }

.arabic-greeting {
  text-align: center;
  margin: 0 0 2.2em;
  padding: 30px 20px 26px;
  border-top: 1px solid var(--border);
  border-bottom: 1px solid var(--border);
}

.arabic-greeting .arabic-text {
  font-family: 'Amiri', 'Traditional Arabic', 'Scheherazade New', serif;
  font-weight: 700;
  font-size: 30px;
  line-height: 1.9;
  color: var(--text);
  margin: 0;
}

.arabic-greeting .arabic-translation {
  font-size: 13.5px;
  font-style: italic;
  color: var(--text-tertiary);
  margin: 6px 0 22px;
}

.arabic-greeting .arabic-translation:last-child { margin-bottom: 0; }

/* prev/next nav */

.article-nav {
  max-width: 720px;
  margin: 56px auto 0;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 14px;
}

.article-nav-link {
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 16px 18px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  transition: border-color .15s ease, background .15s ease;
}

.article-nav-link:hover { border-color: var(--border-strong); background: var(--bg-subtle); }
.article-nav-link.next { text-align: right; grid-column: 2; }
.article-nav-link .nav-label { font-size: 12px; color: var(--text-tertiary); font-weight: 600; text-transform: uppercase; letter-spacing: .04em; }
.article-nav-link .nav-title { font-size: 14.5px; font-weight: 600; color: var(--text); }

@media (max-width: 560px) {
  .article-nav { grid-template-columns: 1fr; }
  .article-nav-link.next { grid-column: 1; text-align: left; }
}

/* back to top */

#back-to-top {
  position: fixed;
  right: 22px;
  bottom: 22px;
  z-index: 40;
  opacity: 0;
  pointer-events: none;
  transform: translateY(8px);
  transition: opacity .2s ease, transform .2s ease;
  box-shadow: var(--shadow-md);
}

#back-to-top.visible { opacity: 1; pointer-events: auto; transform: translateY(0); }

/* loading / not-found states */

.state-msg {
  text-align: center;
  padding: 90px 24px;
  color: var(--text-secondary);
}

.state-msg h2 { color: var(--text); margin-bottom: 8px; }

.skeleton {
  animation: pulse 1.4s ease-in-out infinite;
  background: var(--bg-subtle);
  border-radius: var(--radius-sm);
}

@keyframes pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: .5; }
}

noscript.noscript-banner {
  display: block;
  text-align: center;
  padding: 12px;
  background: var(--accent-soft-bg);
  color: var(--accent-soft-text);
  font-size: 14px;
}

/* ---------------------------------------------------------------------- *
 * Responsive
 * ---------------------------------------------------------------------- */

@media (max-width: 640px) {
  .header-inner { height: 60px; }
  .brand-text-sub { display: none; }
  #search { width: 130px; }
  #search:focus { width: 160px; }
  .hero { padding: 40px 20px 20px; }
  .article-grid { grid-template-columns: 1fr; }
  .prose { font-size: 16px; }
}
