/* ============================================================
   BLOG STYLESHEET — Bilingual (FA/EN) | Modern & Engaging
   ============================================================ */

@import url("https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700;800&family=Fira+Code:wght@400;500&family=Vazirmatn:wght@300;400;500;600;700;800&display=swap");

/* ── Design Tokens ── */
:root {
    --primary: #0078ff;
    --primary-light: #e6f2ff;
    --primary-dark: #0055cc;
    --accent: #00c6ff;
    --surface: #ffffff;
    --surface-alt: #f7faff;
    --border: #d1e3ff;
    --text-primary: #1a202c;
    --text-secondary: #4a5568;
    --text-muted: #718096;
    --shadow-sm: 0 2px 8px rgba(0, 120, 255, 0.07);
    --shadow-md: 0 6px 24px rgba(0, 120, 255, 0.12);
    --shadow-lg: 0 12px 40px rgba(0, 120, 255, 0.15);
    --radius-sm: 8px;
    --radius-md: 14px;
    --radius-lg: 20px;
    --font-en: "Inter", system-ui, sans-serif;
    --font-fa: "Vazirmatn", "Inter", sans-serif;
    --font-code: "Fira Code", "Consolas", monospace;
    --transition: 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

/* ── Base article ── */
article {
    font-family: var(--font-en);
    color: var(--text-primary);
}
article[dir="rtl"],
[dir="rtl"] article {
    font-family: var(--font-fa);
}

/* ── Direction helpers ── */
.rtl-text {
    direction: rtl;
    text-align: right;
    font-family: var(--font-fa);
}
.rtl-text * {
    direction: rtl;
    text-align: right;
}

/* code/pre are ALWAYS LTR — even inside .rtl-text */
.rtl-text pre,
.rtl-text code,
.rtl-text pre *,
.rtl-text code *,
[dir="rtl"] pre,
[dir="rtl"] code,
[dir="rtl"] pre *,
[dir="rtl"] code * {
    direction: ltr !important;
    unicode-bidi: embed !important;
    text-align: left !important;
    font-family: var(--font-code) !important;
    white-space: pre !important;
    word-break: normal !important;
}
.ltr-text {
    direction: ltr;
    text-align: left;
    font-family: var(--font-en);
}

/* ── Paragraphs — RTL default stays RTL ── */
.markdown-body p {
    font-size: 1.08rem;
    line-height: 1.95;
    color: var(--text-secondary);
    margin-bottom: 1.6rem;
    text-align: justify;
    text-justify: inter-word;
    font-weight: 400;
    letter-spacing: 0.01em;
}
/* RTL page: paragraphs are RTL by default */
[dir="rtl"] .markdown-body p {
    direction: rtl;
    text-align: right;
    letter-spacing: 0;
    word-spacing: 0.5px;
    font-family: var(--font-fa);
}
/* JS adds .para-ltr to mixed-language paragraphs — only then flip */
[dir="rtl"] .markdown-body p.para-ltr {
    direction: ltr;
    text-align: left;
    font-family: var(--font-en);
    unicode-bidi: isolate;
}
[dir="ltr"] .markdown-body p.para-rtl {
    direction: rtl;
    text-align: right;
    font-family: var(--font-fa);
    unicode-bidi: isolate;
}

.markdown-body p:first-of-type {
    font-size: 1.13rem;
    color: var(--text-primary);
}
.markdown-body p strong {
    color: var(--primary);
    font-weight: 700;
    background: rgba(0, 120, 255, 0.06);
    padding: 1px 6px;
    border-radius: 5px;
}

/* ── Headings ── */
.markdown-body h1,
.markdown-body h2,
.markdown-body h3,
.markdown-body h4,
.markdown-body h5,
.markdown-body h6 {
    position: relative;
    display: inline-block;
    font-family: var(--font-en);
    font-weight: 800;
    color: var(--text-primary);
    margin: 2.4rem 0 1.2rem;
    padding: 4px 14px;
    letter-spacing: -0.01em;
    line-height: 1.25;
    z-index: 1;
}
[dir="rtl"] .markdown-body h1,
[dir="rtl"] .markdown-body h2,
[dir="rtl"] .markdown-body h3,
[dir="rtl"] .markdown-body h4,
[dir="rtl"] .markdown-body h5,
[dir="rtl"] .markdown-body h6 {
    font-family: var(--font-fa);
    letter-spacing: 0;
}
.markdown-body h1 {
    font-size: 2.1rem;
}
.markdown-body h2 {
    font-size: 1.65rem;
}
.markdown-body h3 {
    font-size: 1.35rem;
}
.markdown-body h4 {
    font-size: 1.15rem;
}

.markdown-body h1::after,
.markdown-body h2::after,
.markdown-body h3::after,
.markdown-body h4::after,
.markdown-body h5::after,
.markdown-body h6::after {
    content: "";
    position: absolute;
    bottom: 0;
    inset-inline-start: 0;
    width: 100%;
    height: 55%;
    background: linear-gradient(135deg, var(--primary), var(--accent));
    opacity: 0.14;
    z-index: -1;
    border-radius: 3px;
    clip-path: polygon(
        0% 20%,
        10% 0%,
        90% 8%,
        100% 0%,
        98% 75%,
        88% 100%,
        12% 95%,
        0% 100%
    );
    filter: blur(1.5px);
    transition:
        opacity var(--transition),
        transform var(--transition);
}
.markdown-body h1:hover::after,
.markdown-body h2:hover::after,
.markdown-body h3:hover::after {
    opacity: 0.28;
    transform: scaleX(1.04) skewX(-1.5deg);
}

/* ── HR ── */
hr {
    border: none;
    height: 1px;
    background: linear-gradient(
        to right,
        transparent,
        var(--primary),
        transparent
    );
    margin: 3.5rem 0;
    position: relative;
    overflow: visible;
}
hr::after {
    content: "✦";
    position: absolute;
    left: 50%;
    top: 50%;
    transform: translate(-50%, -50%);
    background: var(--surface);
    padding: 0 16px;
    color: var(--primary);
    font-size: 16px;
}

/* ── Lists ── */
.markdown-body ul,
.markdown-body ol {
    list-style: none;
    padding: 0;
    margin: 20px 0;
}

.markdown-body li {
    background: #ffffff;
    border-inline-start: 4px solid #0078ff;
    margin-bottom: 12px;
    padding: 15px 25px;
    border-radius: 8px;
    display: block; /* تغییر از flex به block جهت بهبود جریان متنی RTL */
    position: relative;
    box-shadow: 0 2px 15px rgba(0, 120, 255, 0.08);
    transition: all 0.3s ease;
    color: #333;
    line-height: 1.9; /* کمی فاصله بیشتر برای خوانایی بهتر متن فارسی */
    text-align: justify; /* تراز شدن کامل متن */
    text-justify: inter-word;
    word-break: normal; /* جلوگیری از شکستن کلمات فارسی از وسط */
    overflow-wrap: break-word;
}

/* The text content of each li needs a wrapper to constrain it.
   Since markdown parsers wrap li text in <p> or leave it as text node,
   we target direct children that carry the text. */
.markdown-body li > p,
.markdown-body li > span,
.markdown-body li > div {
    display: inline; /* هماهنگی با جریان متن اصلی لیست */
    text-align: justify;
    word-break: normal;
    overflow-wrap: break-word;
}

/* For plain text nodes (no wrapping p), the li itself handles overflow */
.markdown-body li {
    word-break: break-word;
    overflow-wrap: break-word;
}

.markdown-body li:hover {
    transform: translateX(calc(var(--dir, 1) * -5px));
    box-shadow: 0 5px 20px rgba(0, 120, 255, 0.15);
    background-color: #f0f7ff;
}

[dir="rtl"] .markdown-body li:hover {
    --dir: 1;
}
[dir="ltr"] .markdown-body li:hover {
    --dir: -1;
}

/* ── Ordered list ── */
.markdown-body ol {
    counter-reset: li-counter;
}
.markdown-body ol > li {
    counter-increment: li-counter;
}

/* nested ol gets its own fresh counter */
.markdown-body ol ol {
    counter-reset: li-counter;
    margin: 8px 0;
}

.markdown-body ol > li::before {
    content: counter(li-counter);
    background: #0078ff;
    color: white;
    min-width: 28px;
    width: 28px;
    height: 28px;
    border-radius: 50%;
    display: inline-flex; /* تغییر برای هماهنگی با ساختار block */
    align-items: center;
    justify-content: center;
    margin-inline-end: 12px;
    font-size: 13px;
    font-weight: bold;
    flex-shrink: 0;
    box-shadow: 0 2px 8px rgba(0, 120, 255, 0.35);
    direction: ltr;
    unicode-bidi: isolate;
    vertical-align: middle; /* هم‌تراز شدن عمودی با خط اول متن */
    margin-top: -3px;
}

/* ── Unordered list bullet ── */
.markdown-body ul li::before {
    content: "";
    min-width: 10px;
    width: 10px;
    height: 10px;
    background: #0078ff;
    border-radius: 50%;
    display: inline-block; /* تغییر از block به inline-block */
    flex-shrink: 0;
    margin-inline-end: 12px;
    box-shadow: 0 0 6px rgba(0, 120, 255, 0.4);
    vertical-align: middle; /* هم‌تراز شدن عمودی با خط اول متن */
    margin-top: -2px;
}

/* nested ul */
.markdown-body ul ul,
.markdown-body ol ul {
    margin: 8px 0;
}

/* ── Blockquote ── */
.markdown-body blockquote {
    margin: 2rem 0;
    padding: 22px 28px;
    background: linear-gradient(
        to var(--gradient-dir, right),
        rgba(0, 120, 255, 0.06),
        transparent
    );
    border-inline-start: 5px solid var(--primary);
    border-radius: var(--radius-sm);
    position: relative;
    font-style: italic;
    color: var(--text-secondary);
    line-height: 1.85;
    box-shadow: var(--shadow-sm);
    transition: background var(--transition);
    overflow: hidden;
}
.markdown-body blockquote::before {
    content: "\201C";
    position: absolute;
    top: -12px;
    inset-inline-start: 16px;
    font-size: 72px;
    color: var(--primary);
    opacity: 0.12;
    font-family: Georgia, serif;
    line-height: 1;
    user-select: none;
}
.markdown-body blockquote::after {
    content: "";
    position: absolute;
    inset-inline-end: 0;
    top: 0;
    width: 4px;
    height: 100%;
    background: linear-gradient(to bottom, var(--primary), var(--accent));
    opacity: 0.25;
    border-radius: 4px;
}
[dir="rtl"] .markdown-body blockquote {
    --gradient-dir: left;
}
[dir="ltr"] .markdown-body blockquote {
    --gradient-dir: right;
}
.markdown-body blockquote:hover {
    background: linear-gradient(
        to var(--gradient-dir, right),
        rgba(0, 120, 255, 0.1),
        transparent
    );
}
.markdown-body blockquote cite {
    display: block;
    margin-top: 12px;
    font-weight: 700;
    color: var(--primary);
    font-style: normal;
    font-size: 0.88rem;
}

/* ── Code blocks ── */
/* ============================================================
   ── ۳. بخش اصلاح‌شده کدهای درون‌خطی و بلاک‌های کد (Code Blocks) ──
   ============================================================ */

/* ── الف) کدهای درون‌خطی (Inline Codes - مثل تک کلمه‌ها داخل پاراگراف) ── */
p code,
li code {
    background: rgba(0, 120, 255, 0.07);
    color: #0055cc !important;
    padding: 2px 7px;
    border-radius: 5px;
    font-family: var(--font-code) !important;
    font-size: 0.88em;
    border: 1px solid rgba(0, 120, 255, 0.15);
    direction: ltr !important;
    display: inline-block !important;
    unicode-bidi: embed;
    margin: 0 2px;
    vertical-align: middle;
    transition: background var(--transition);
    white-space: nowrap !important;
    word-break: normal !important;
}
p code:hover,
li code:hover {
    background: rgba(0, 120, 255, 0.13);
}


/* ── ب) بلاک‌های کدی که زبان دارند (حفظ کامل و بدون تغییر ساختار قبلی شما) ── */
div.code-toolbar {
    position: relative;
    padding-top: 42px;
    background: #0f1117;
    border-radius: var(--radius-md);
    overflow: hidden;
    margin: 1.8rem 0;
    box-shadow: var(--shadow-lg);
    border: 1px solid rgba(0, 120, 255, 0.18);
    direction: ltr !important;
}
div.code-toolbar > .toolbar {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    height: 42px;
    background: #1a1d27 !important;
    display: flex !important;
    align-items: center !important;
    padding: 0 16px !important;
    opacity: 1 !important;
    border-bottom: 1px solid rgba(255, 255, 255, 0.08);
    direction: ltr;
    gap: 8px;
}
/* div.code-toolbar > .toolbar::before {
    content: "";
    display: inline-block;
    width: 10px;
    height: 10px;
    border-radius: 50%;
    background: #ff5f56;
    box-shadow:
        18px 0 0 #ffbd2e,
        36px 0 0 #27c93f;
    margin-right: 8px;
    flex-shrink: 0;
} */
div.code-toolbar > .toolbar .toolbar-item:nth-child(2) {
    order: 1;
    margin-right: auto;
}
div.code-toolbar > .toolbar .toolbar-item:nth-child(1) {
    order: 2;
}
div.code-toolbar > .toolbar button {
    background: rgba(255, 255, 255, 0.07) !important;
    border: 1px solid rgba(255, 255, 255, 0.12) !important;
    color: #aab !important;
    padding: 4px 12px !important;
    border-radius: 6px !important;
    font-size: 0.72rem !important;
    cursor: pointer;
    transition: all var(--transition);
    font-family: var(--font-en);
    letter-spacing: 0.04em;
}
div.code-toolbar > .toolbar button:hover {
    background: rgba(0, 120, 255, 0.2) !important;
    color: var(--accent) !important;
    border-color: var(--primary) !important;
}
div.code-toolbar > .toolbar .toolbar-item span {
    color: rgba(255, 255, 255, 0.3) !important;
    font-family: var(--font-code);
    font-size: 0.75rem;
    text-transform: uppercase;
    letter-spacing: 0.08em;
}

/* استایل‌دهی preهای داخل تولبار زبان‌دار (دقیقاً بر اساس کدهای اصلی شما) */
div.code-toolbar pre,
.markdown-body pre[class*="language-"] {
    margin: 0 !important;
    border-radius: 0 !important;
    background: #0f1117 !important;
    font-family: var(--font-code) !important;
    font-size: 0.9rem !important;
    line-height: 1.7 !important;
    direction: ltr !important;
    unicode-bidi: embed !important;
    text-align: left !important;
    white-space: pre !important;
    overflow-x: auto;
    word-break: normal !important;
    word-wrap: normal !important;
}
/* اعمال قوانین LTR روی المان‌های داخلی کد زبا‌ن‌دار */
div.code-toolbar pre *,
.markdown-body pre[class*="language-"] * {
    direction: ltr !important;
    unicode-bidi: embed !important;
    white-space: pre !important;
    word-break: normal !important;
}


/* ── ج) بلاک‌های کدِ بدون زبان (شبه‌کد - بدون کادر، چپ‌چین، هماهنگ با متن) ── */
/* با کمک امضای دقیق :not() مطمئن می‌شویم preهای تولباردار یا زبان‌دار هرگز لمس نخواهند شد */
.markdown-body pre:not([class*="language-"]):not(.code-toolbar pre):not([id*="prism"]) {
    background: transparent !important; /* حذف کامل کادر و پس‌زمینه مشکی */
    border: none !important;
    box-shadow: none !important;
    padding: 5px 0 !important;
    margin: 1.4rem 0 !important;
    color: var(--text-secondary) !important; /* هماهنگ با رنگ متن اصلی وبلاگ */
    
    /* تنظیمات ساختاری نمایش شبه‌کد به صورت چپ‌چین */
    direction: ltr !important;
    unicode-bidi: embed !important;
    text-align: left !important;
    font-family: var(--font-code) !important;
    font-size: 0.95rem !important;
    line-height: 1.8 !important;
    white-space: pre !important;
    overflow-x: auto;
    word-break: normal !important;
    word-wrap: normal !important;
}

/* تنظیم رنگ فرزندان مستقیم یا متون داخل شبه‌کد جهت جلوگیری از ارث‌بری رنگ‌های متفرقه */
.markdown-body pre:not([class*="language-"]):not(.code-toolbar pre):not([id*="prism"]) * {
    color: var(--text-secondary) !important;
    direction: ltr !important;
    unicode-bidi: embed !important;
    text-align: left !important;
    background: transparent !important;
}

/* ── Tables ── */
.markdown-body table {
    width: 100%;
    border-collapse: collapse;
    margin: 1.8rem 0;
    border-radius: var(--radius-sm);
    overflow: hidden;
    box-shadow: var(--shadow-sm);
    direction: ltr;
    font-size: 0.95rem;
}
.markdown-body th,
.markdown-body td {
    border: 1px solid var(--border);
    padding: 12px 16px;
    text-align: center;
    transition: background var(--transition);
}
.markdown-body th {
    background: linear-gradient(135deg, var(--primary), var(--primary-dark));
    color: #fff;
    font-weight: 600;
    letter-spacing: 0.04em;
    font-size: 0.88rem;
    text-transform: uppercase;
}
.markdown-body tr:nth-child(even) td {
    background: var(--surface-alt);
}
.markdown-body tr:hover td {
    background: var(--primary-light);
}

/* ── KaTeX — always LTR regardless of page direction ── */

/*
 * .katex-display  =  $$ ... $$ (block, centered)
 * span.katex      =  $ ... $   (inline)
 *
 * Root problem in RTL pages: the bidi algorithm mirrors the flex/block
 * container, which flips operator order and wraps tokens.
 * Fix: turn .katex-display into a hard LTR island (direction + unicode-bidi),
 * then re-center with text-align: center on a block wrapper.
 */

/* ①  The outer display wrapper — block, LTR island, centered */
.katex-display {
    display: block !important;
    direction: ltr !important;
    unicode-bidi: isolate !important;
    text-align: center !important;
    width: 100%;
    margin: 1.8em 0 !important;
    padding: 16px;
    background: var(--surface-alt);
    border-radius: var(--radius-sm);
    border: 1px solid var(--border);
    overflow-x: auto;
    box-sizing: border-box;
}

/* ②  The katex span itself — inline-block inside the centered block */
.katex-display > .katex {
    display: inline-block !important;
    direction: ltr !important;
    unicode-bidi: bidi-override !important;
    text-align: left !important;
}

/* ③  All katex nodes */
.katex,
.katex-html,
.katex-display > .katex > .katex-html {
    direction: ltr !important;
    unicode-bidi: bidi-override !important;
    text-align: left !important;
    display: inline-block !important;
}

/* ④  RTL page: force every descendant inside katex to LTR */
[dir="rtl"] .katex-display,
[dir="rtl"] .katex-display > .katex,
[dir="rtl"] .katex-display * {
    direction: ltr !important;
    unicode-bidi: embed !important;
}

/* ⑤  Inline katex $ ... $ */
span.katex {
    direction: ltr !important;
    unicode-bidi: embed !important;
    display: inline-block !important;
    padding: 0 3px !important;
    white-space: nowrap;
}

[dir="rtl"] span.katex,
[dir="rtl"] span.katex * {
    direction: ltr !important;
    unicode-bidi: embed !important;
}

/* ⑥  Internal katex layout parts */
.katex .base,
.katex .strut,
.katex .mord,
.katex .mbin,
.katex .mrel,
.katex .mopen,
.katex .mclose,
.katex .minner,
.katex .mop,
.katex .mpunct,
.katex .mfrac,
.katex .msupsub,
.katex .vlist-t,
.katex .vlist-r,
.katex .vlist,
.katex .newline,
.katex-html {
    direction: ltr !important;
    unicode-bidi: embed !important;
}

/* ── Blog Hero Banner ── */
.blog-hero-banner {
    position: relative;
    width: 100%;
    min-height: 320px;
    border-radius: var(--radius-lg);
    overflow: hidden;
    margin-bottom: 3rem;
    display: flex;
    align-items: center;
    justify-content: center;
    background: linear-gradient(
        135deg,
        #0a1628 0%,
        #0d2246 40%,
        #0055cc 75%,
        #0078ff 100%
    );
}

/* animated mesh grid */
.blog-hero-banner::before {
    content: "";
    position: absolute;
    inset: 0;
    background-image:
        linear-gradient(rgba(0, 198, 255, 0.07) 1px, transparent 1px),
        linear-gradient(90deg, rgba(0, 198, 255, 0.07) 1px, transparent 1px);
    background-size: 40px 40px;
    animation: gridMove 20s linear infinite;
}

/* glow orbs */
.blog-hero-banner::after {
    content: "";
    position: absolute;
    inset: 0;
    background:
        radial-gradient(
            ellipse 55% 60% at 20% 50%,
            rgba(0, 120, 255, 0.35) 0%,
            transparent 70%
        ),
        radial-gradient(
            ellipse 40% 50% at 80% 40%,
            rgba(0, 198, 255, 0.2) 0%,
            transparent 65%
        );
    animation: orbPulse 6s ease-in-out infinite alternate;
}

.blog-hero-content {
    position: relative;
    z-index: 2;
    text-align: center;
    padding: 3rem 2rem;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 1rem;
}

.blog-hero-tag {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    background: rgba(0, 198, 255, 0.12);
    border: 1px solid rgba(0, 198, 255, 0.3);
    color: var(--accent);
    font-family: var(--font-en);
    font-size: 0.78rem;
    font-weight: 600;
    letter-spacing: 0.1em;
    text-transform: uppercase;
    padding: 5px 16px;
    border-radius: 999px;
    backdrop-filter: blur(8px);
    animation: fadeInUp 0.5s ease both;
}
.blog-hero-tag::before {
    content: "◈";
    font-size: 0.7rem;
    opacity: 0.8;
}

.blog-hero-title {
    font-family: var(--font-en);
    font-size: clamp(1.8rem, 4vw, 3rem);
    font-weight: 800;
    color: #fff;
    line-height: 1.15;
    letter-spacing: -0.02em;
    margin: 0;
    text-shadow: 0 2px 20px rgba(0, 0, 0, 0.4);
    animation: fadeInUp 0.55s 0.1s ease both;
}
[dir="rtl"] .blog-hero-title {
    font-family: var(--font-fa);
    letter-spacing: 0;
    font-size: clamp(1.6rem, 3.5vw, 2.6rem);
}

.blog-hero-meta {
    display: flex;
    align-items: center;
    gap: 1.2rem;
    flex-wrap: wrap;
    justify-content: center;
    animation: fadeInUp 0.55s 0.2s ease both;
}
.blog-hero-meta span {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    color: rgba(255, 255, 255, 0.65);
    font-size: 0.88rem;
    font-family: var(--font-en);
}
[dir="rtl"] .blog-hero-meta span {
    font-family: var(--font-fa);
}
.blog-hero-meta span::before {
    font-size: 0.8rem;
    opacity: 0.7;
}
.blog-hero-date::before {
    content: "";
}
.blog-hero-desc::before {
    content: "";
}

.blog-hero-divider {
    width: 60px;
    height: 3px;
    background: linear-gradient(to right, var(--primary), var(--accent));
    border-radius: 3px;
    animation: fadeInUp 0.55s 0.3s ease both;
}
[dir="rtl"] .blog-hero-divider {
    background: linear-gradient(to left, var(--primary), var(--accent));
}

/* particle dots */
.blog-hero-particles {
    position: absolute;
    inset: 0;
    z-index: 1;
    pointer-events: none;
    overflow: hidden;
}
.blog-hero-particles span {
    position: absolute;
    width: 3px;
    height: 3px;
    background: var(--accent);
    border-radius: 50%;
    opacity: 0;
    animation: particleFly var(--dur, 8s) var(--delay, 0s) linear infinite;
}

@keyframes gridMove {
    from {
        background-position: 0 0;
    }
    to {
        background-position: 40px 40px;
    }
}
@keyframes orbPulse {
    from {
        opacity: 0.7;
    }
    to {
        opacity: 1;
    }
}
@keyframes particleFly {
    0% {
        transform: translateY(100%) translateX(var(--tx, 0px));
        opacity: 0;
    }
    10% {
        opacity: 0.8;
    }
    90% {
        opacity: 0.5;
    }
    100% {
        transform: translateY(-120%) translateX(calc(var(--tx, 0px) * -1));
        opacity: 0;
    }
}

/* ── Author card ── */
.author-thank-card {
    background: linear-gradient(
        135deg,
        rgba(255, 255, 255, 0.85),
        rgba(230, 242, 255, 0.7)
    );
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    border: 1px solid rgba(0, 120, 255, 0.14);
    padding: 28px 30px;
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-md);
    position: relative;
    max-width: 420px;
    margin: 3.5rem auto 1.5rem !important;
    animation: floatingCard 5s ease-in-out infinite;
    transition:
        box-shadow var(--transition),
        border-color var(--transition);
    overflow: hidden;
    text-align: center;
}
.author-thank-card::before {
    content: "";
    position: absolute;
    inset: 0;
    background: linear-gradient(
        135deg,
        rgba(0, 120, 255, 0.04),
        rgba(0, 198, 255, 0.04)
    );
    pointer-events: none;
}
.author-thank-card:hover {
    border-color: rgba(0, 120, 255, 0.32);
    box-shadow: var(--shadow-lg);
}
.avatar-wrapper {
    position: relative;
    width: 80px;
    height: 80px;
    margin: 0 auto 14px;
}
.avatar-wrapper::before {
    content: "";
    position: absolute;
    inset: -3px;
    border-radius: 50%;
    background: linear-gradient(135deg, var(--primary), var(--accent));
    z-index: 0;
    animation: pulseGlow 2.5s ease-out infinite;
}
.avatar-wrapper .avatar {
    width: 100%;
    height: 100%;
    object-fit: cover;
    border-radius: 50%;
    border: 3px solid #fff;
    box-shadow: var(--shadow-md);
    position: relative;
    z-index: 1;
}
.author-name {
    display: block;
    font-size: 1.08rem;
    font-weight: 700;
    color: var(--text-primary);
    margin-bottom: 8px;
    letter-spacing: -0.01em;
}
[dir="rtl"] .author-name {
    font-family: var(--font-fa);
}
.thank-text {
    font-size: 0.9rem;
    color: var(--text-muted);
    font-style: italic;
    line-height: 1.7;
    margin: 0;
}
[dir="rtl"] .thank-text {
    font-family: var(--font-fa);
}

/* ── Images ── */
/* .markdown-body img {
    max-width: 100%;
    height: auto;
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-md);
    margin: 1.5rem auto;
    display: block;
    transition:
        transform var(--transition),
        box-shadow var(--transition);
}
.markdown-body img:hover {
    transform: scale(1.015);
    box-shadow: var(--shadow-lg);
} */

/* ── Links ── */
.markdown-body a {
    color: var(--primary);
    text-decoration: none;
    border-bottom: 1.5px solid rgba(0, 120, 255, 0.25);
    transition:
        border-color var(--transition),
        color var(--transition);
    padding-bottom: 1px;
}
.markdown-body a:hover {
    color: var(--primary-dark);
    border-color: var(--primary-dark);
}

/* ── Reading progress ── */
#reading-progress {
    position: fixed;
    top: 0;
    left: 0;
    height: 3px;
    width: 0%;
    background: linear-gradient(to right, var(--primary), var(--accent));
    z-index: 9999;
    transition: width 0.1s linear;
    box-shadow: 0 0 8px rgba(0, 198, 255, 0.5);
}

/* ── Keyframes ── */
@keyframes floatingCard {
    0%,
    100% {
        transform: translateY(0);
    }
    50% {
        transform: translateY(-7px);
    }
}
@keyframes pulseGlow {
    0% {
        transform: scale(1);
        opacity: 0.7;
    }
    100% {
        transform: scale(1.35);
        opacity: 0;
    }
}
@keyframes fadeInUp {
    from {
        opacity: 0;
        transform: translateY(16px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* ── Stagger content ── */
.markdown-body > * {
    animation: fadeInUp 0.45s ease both;
}
.markdown-body > *:nth-child(1) {
    animation-delay: 0.05s;
}
.markdown-body > *:nth-child(2) {
    animation-delay: 0.1s;
}
.markdown-body > *:nth-child(3) {
    animation-delay: 0.15s;
}
.markdown-body > *:nth-child(4) {
    animation-delay: 0.2s;
}
.markdown-body > *:nth-child(5) {
    animation-delay: 0.25s;
}
.markdown-body > *:nth-child(6) {
    animation-delay: 0.3s;
}
.markdown-body > *:nth-child(7) {
    animation-delay: 0.35s;
}
.markdown-body > *:nth-child(n + 8) {
    animation-delay: 0.4s;
}

/* ── Responsive ── */
@media (max-width: 768px) {
    .markdown-body h1 {
        font-size: 1.6rem;
    }
    .markdown-body h2 {
        font-size: 1.35rem;
    }
    .markdown-body h3 {
        font-size: 1.15rem;
    }
    .markdown-body p {
        font-size: 1rem;
        line-height: 1.85;
    }
    .markdown-body table {
        display: block;
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
    }
    .author-thank-card {
        padding: 22px 18px;
    }
    .blog-hero-banner {
        min-height: 240px;
    }
    .blog-hero-content {
        padding: 2rem 1.2rem;
    }
}
@media (min-width: 769px) {
    .markdown-body table {
        display: table;
        width: 100%;
    }
}

/* ── Accessibility ── */
@media (prefers-reduced-motion: reduce) {
    .markdown-body > *,
    .author-thank-card,
    .avatar-wrapper::before,
    .markdown-body li,
    .markdown-body img,
    .blog-hero-banner::before,
    .blog-hero-banner::after,
    .blog-hero-particles span {
        animation: none !important;
        transition: none !important;
    }
}

/* ════════════════════════════════════════
   HERO BANNER  v3 — Rich animated
════════════════════════════════════════ */

/* Hide original plain title-box (JS also sets display:none, this is a fallback) */
.title-box {
    display: none !important;
}

.blog-hero-banner {
    position: relative;
    width: 100%;
    min-height: 380px;
    border-radius: var(--radius-lg);
    overflow: hidden;
    margin-bottom: 3rem;
    display: flex;
    align-items: center;
    justify-content: center;
    isolation: isolate;
}

/* Layer 1 — dark blue base */
.hero-bg-layer {
    position: absolute;
    inset: 0;
    z-index: 0;
    background: linear-gradient(
        135deg,
        #060d1f 0%,
        #0a1a3e 30%,
        #0041a8 65%,
        #0066dd 85%,
        #0088ff 100%
    );
}

/* Layer 2 — animated mesh grid */
.hero-grid-layer {
    position: absolute;
    inset: 0;
    z-index: 1;
    background-image:
        linear-gradient(rgba(0, 200, 255, 0.06) 1px, transparent 1px),
        linear-gradient(90deg, rgba(0, 200, 255, 0.06) 1px, transparent 1px);
    background-size: 48px 48px;
    animation: heroGridMove 25s linear infinite;
    mask-image: radial-gradient(
        ellipse 80% 80% at 50% 50%,
        black 40%,
        transparent 100%
    );
}

/* Layer 3 — glowing orbs */
.hero-glow-layer {
    position: absolute;
    inset: 0;
    z-index: 2;
    background:
        radial-gradient(
            ellipse 60% 70% at 15% 50%,
            rgba(0, 120, 255, 0.45) 0%,
            transparent 65%
        ),
        radial-gradient(
            ellipse 45% 55% at 85% 35%,
            rgba(0, 198, 255, 0.25) 0%,
            transparent 60%
        ),
        radial-gradient(
            ellipse 30% 40% at 50% 90%,
            rgba(80, 0, 255, 0.15) 0%,
            transparent 55%
        );
    animation: heroOrbPulse 8s ease-in-out infinite alternate;
}

/* Floating code symbols */
.hero-float-icons {
    position: absolute;
    inset: 0;
    z-index: 3;
    pointer-events: none;
    overflow: hidden;
    font-family: "Fira Code", monospace;
    font-weight: 600;
    color: #fff;
    user-select: none;
}
.hero-float-icon {
    position: absolute;
    animation: heroIconFloat var(--dur, 9s) var(--delay, 0s) ease-in-out
        infinite alternate;
}

/* Particles */
.blog-hero-particles {
    position: absolute;
    inset: 0;
    z-index: 4;
    pointer-events: none;
    overflow: hidden;
}
.hero-particle {
    position: absolute;
    bottom: -10px;
    background: var(--accent);
    border-radius: 50%;
    opacity: 0;
    animation: heroParticleRise var(--dur, 9s) var(--delay, 0s) linear infinite;
}

/* Content */
.blog-hero-content {
    position: relative;
    z-index: 5;
    text-align: center;
    padding: 3.5rem 2.5rem;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 1.1rem;
    width: 100%;
}

.hero-badges {
    display: flex;
    align-items: center;
    gap: 10px;
    flex-wrap: wrap;
    justify-content: center;
    animation: fadeInUp 0.5s ease both;
}

.blog-hero-tag {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    background: rgba(0, 198, 255, 0.13);
    border: 1px solid rgba(0, 198, 255, 0.4);
    color: #7dd8ff;
    font-family: var(--font-en);
    font-size: 0.75rem;
    font-weight: 600;
    letter-spacing: 0.1em;
    text-transform: uppercase;
    padding: 5px 18px;
    border-radius: 999px;
    backdrop-filter: blur(8px);
}
[dir="rtl"] .blog-hero-tag {
    font-family: var(--font-fa);
    letter-spacing: 0;
    text-transform: none;
    font-size: 0.82rem;
}
.blog-hero-tag::before {
    content: "◈";
    font-size: 0.65rem;
    opacity: 0.8;
}

.hero-read-time {
    background: rgba(255, 255, 255, 0.08);
    border: 1px solid rgba(255, 255, 255, 0.15);
    color: rgba(255, 255, 255, 0.7);
    font-family: var(--font-en);
    font-size: 0.75rem;
    font-weight: 500;
    padding: 5px 14px;
    border-radius: 999px;
    backdrop-filter: blur(8px);
}
[dir="rtl"] .hero-read-time {
    font-family: var(--font-fa);
    font-size: 0.82rem;
}

.blog-hero-title {
    font-family: var(--font-en);
    font-size: clamp(1.9rem, 4.5vw, 3.2rem);
    font-weight: 800;
    color: #fff;
    line-height: 1.15;
    letter-spacing: -0.025em;
    margin: 0;
    text-shadow:
        0 2px 30px rgba(0, 0, 0, 0.5),
        0 0 60px rgba(0, 140, 255, 0.3);
    animation: fadeInUp 0.55s 0.1s ease both;
    max-width: 800px;
}
[dir="rtl"] .blog-hero-title {
    font-family: var(--font-fa);
    letter-spacing: 0;
    font-size: clamp(1.7rem, 4vw, 2.8rem);
}

.blog-hero-meta {
    display: flex;
    align-items: center;
    gap: 1.4rem;
    flex-wrap: wrap;
    justify-content: center;
    animation: fadeInUp 0.55s 0.18s ease both;
}
.blog-hero-meta span {
    color: rgba(255, 255, 255, 0.6);
    font-size: 0.88rem;
    font-family: var(--font-en);
    display: inline-flex;
    align-items: center;
    gap: 5px;
}
[dir="rtl"] .blog-hero-meta span {
    font-family: var(--font-fa);
    font-size: 0.9rem;
}

.hero-bottom-row {
    display: flex;
    align-items: center;
    gap: 14px;
    width: 100%;
    max-width: 360px;
    animation: fadeInUp 0.55s 0.26s ease both;
}
.blog-hero-divider {
    flex: 1;
    height: 1px;
    background: linear-gradient(
        to right,
        transparent,
        rgba(255, 255, 255, 0.25),
        transparent
    );
}
.hero-scroll-hint {
    color: rgba(255, 255, 255, 0.5);
    font-size: 0.78rem;
    font-family: var(--font-en);
    white-space: nowrap;
    letter-spacing: 0.05em;
    animation: heroScrollBounce 2s ease-in-out infinite;
}
.hero-scroll-hint.rtl {
    font-family: var(--font-fa);
    letter-spacing: 0;
}

/* ── Hero keyframes ── */
@keyframes heroGridMove {
    to {
        background-position: 48px 48px;
    }
}
@keyframes heroOrbPulse {
    from {
        opacity: 0.7;
    }
    to {
        opacity: 1;
        transform: scale(1.05);
    }
}
@keyframes heroIconFloat {
    from {
        transform: translateY(0) rotate(-3deg);
    }
    to {
        transform: translateY(-18px) rotate(3deg);
    }
}
@keyframes heroParticleRise {
    0% {
        transform: translateY(0) translateX(var(--tx, 0px));
        opacity: 0;
    }
    8% {
        opacity: 0.9;
    }
    92% {
        opacity: 0.4;
    }
    100% {
        transform: translateY(-110vh) translateX(calc(var(--tx, 0px) * -1.5));
        opacity: 0;
    }
}
@keyframes heroScrollBounce {
    0%,
    100% {
        transform: translateY(0);
    }
    50% {
        transform: translateY(4px);
    }
}

/* ── Responsive hero ── */
@media (max-width: 768px) {
    .blog-hero-banner {
        min-height: 280px;
        border-radius: var(--radius-md);
    }
    .blog-hero-content {
        padding: 2.2rem 1.2rem;
    }
    .blog-hero-title {
        font-size: clamp(1.4rem, 6vw, 2rem);
    }
    .hero-float-icons {
        display: none;
    }
}

/* ════════════════════════════════════════
   TABLE OF CONTENTS
════════════════════════════════════════ */
#blog-toc {
    position: relative;
    background: linear-gradient(135deg, #f0f7ff, #fafcff);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    padding: 0;
    margin-bottom: 2.5rem;
    box-shadow: var(--shadow-sm);
    overflow: hidden;
    transition: box-shadow var(--transition);
}
#blog-toc:hover {
    box-shadow: var(--shadow-md);
}

/* accent stripe on inline-start */
#blog-toc::before {
    content: "";
    position: absolute;
    inset-inline-start: 0;
    top: 0;
    bottom: 0;
    width: 4px;
    background: linear-gradient(to bottom, var(--primary), var(--accent));
    border-radius: 4px 0 0 4px;
}

.toc-header {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 14px 20px 14px 24px;
    border-bottom: 1px solid var(--border);
    cursor: default;
    background: rgba(0, 120, 255, 0.03);
}
[dir="rtl"] .toc-header {
    padding: 14px 24px 14px 20px;
}

.toc-icon {
    font-size: 1rem;
    color: var(--primary);
    flex-shrink: 0;
}
.toc-title {
    font-family: var(--font-en);
    font-weight: 700;
    font-size: 0.95rem;
    color: var(--text-primary);
    flex: 1;
    letter-spacing: 0.01em;
}
[dir="rtl"] .toc-title {
    font-family: var(--font-fa);
    letter-spacing: 0;
}

.toc-toggle {
    background: none;
    border: none;
    cursor: pointer;
    color: var(--text-muted);
    font-size: 0.9rem;
    padding: 2px 6px;
    border-radius: 4px;
    transition:
        background var(--transition),
        color var(--transition);
    line-height: 1;
}
.toc-toggle:hover {
    background: rgba(0, 120, 255, 0.1);
    color: var(--primary);
}

.toc-list {
    list-style: none;
    margin: 0;
    padding: 12px 0;
}

/* ── TOC: override global li styles ── */
#blog-toc .toc-list,
#blog-toc ol,
#blog-toc ul {
    list-style: none;
    margin: 0;
    padding: 12px 0;
    counter-reset: none;
}

#blog-toc .toc-item {
    background: none !important;
    border: none !important;
    border-inline-start: none !important;
    box-shadow: none !important;
    margin-bottom: 0 !important;
    padding: 0 !important;
    display: block !important;
    border-radius: 0 !important;
    counter-increment: none !important;
}
#blog-toc .toc-item:hover {
    transform: none !important;
    background: none !important;
    box-shadow: none !important;
}
#blog-toc .toc-item::before {
    display: none !important;
    content: none !important;
}

/* ── TOC counters (hierarchical: 1 / 1.1 / 1.1.1) ── */
.toc-list {
    counter-reset: toc-h1;
}
.toc-level-1 {
    counter-reset: toc-h2;
    counter-increment: toc-h1;
}
.toc-level-2 {
    counter-reset: toc-h3;
    counter-increment: toc-h2;
}
.toc-level-3 {
    counter-increment: toc-h3;
}

.toc-item {
    margin: 0;
    padding: 0;
    background: none !important;
    box-shadow: none !important;
    border: none !important;
}
.toc-item:hover {
    transform: none !important;
    background: none !important;
    box-shadow: none !important;
}
.toc-item::before {
    display: none !important;
}

.toc-link {
    display: flex;
    align-items: center;
    gap: 10px;
    /* indent via padding-inline-start so it respects RTL/LTR naturally */
    padding-block: 7px;
    padding-inline-start: calc(20px + var(--indent, 0) * 18px);
    padding-inline-end: 20px;
    color: var(--text-secondary) !important;
    font-size: 0.9rem;
    font-family: var(--font-en);
    border-bottom: none !important;
    text-decoration: none;
    border-radius: 0;
    transition:
        background var(--transition),
        color var(--transition),
        padding-inline-start var(--transition);
    position: relative;
    line-height: 1.5;
}
[dir="rtl"] .toc-link {
    font-family: var(--font-fa);
}

.toc-link:hover {
    background: rgba(0, 120, 255, 0.06);
    color: var(--primary) !important;
    padding-inline-start: calc(24px + var(--indent, 0) * 18px);
}
.toc-link.active {
    background: rgba(0, 120, 255, 0.09);
    color: var(--primary) !important;
    font-weight: 600;
}
.toc-link.active .toc-counter {
    color: var(--primary);
}
.toc-link.active .toc-bullet {
    background: var(--primary);
    transform: scale(1.4);
    box-shadow: 0 0 8px rgba(0, 120, 255, 0.5);
}

/* ── Counter badge ── */
.toc-counter {
    flex-shrink: 0;
    font-size: 0.72rem;
    font-weight: 700;
    font-family: var(--font-en) !important; /* always LTR digits */
    color: var(--primary);
    background: rgba(0, 120, 255, 0.1);
    border: 1px solid rgba(0, 120, 255, 0.2);
    border-radius: 5px;
    padding: 1px 7px;
    min-width: 28px;
    text-align: center;
    line-height: 1.6;
    transition:
        background var(--transition),
        color var(--transition);
    direction: ltr;
}
.toc-link:hover .toc-counter {
    background: rgba(0, 120, 255, 0.18);
}
.toc-link.active .toc-counter {
    background: var(--primary);
    color: #fff;
    border-color: var(--primary);
}

.toc-level-2 .toc-counter {
    font-size: 0.68rem;
    background: rgba(0, 120, 255, 0.06);
    color: var(--text-muted);
}
.toc-level-3 .toc-counter {
    font-size: 0.65rem;
    background: transparent;
    border-color: transparent;
    color: var(--text-muted);
    padding: 1px 4px;
}

/* ── Dot bullet (kept for visual rhythm between counter and text) ── */
.toc-bullet {
    flex-shrink: 0;
    width: 5px;
    height: 5px;
    border-radius: 50%;
    background: rgba(0, 120, 255, 0.25);
    transition:
        background var(--transition),
        transform var(--transition),
        box-shadow var(--transition);
}
.toc-level-1 .toc-bullet {
    width: 6px;
    height: 6px;
    background: rgba(0, 120, 255, 0.45);
}
.toc-level-3 .toc-bullet {
    width: 4px;
    height: 4px;
    border-radius: 2px;
}
.toc-link:hover .toc-bullet {
    background: var(--primary);
}

.toc-text {
    flex: 1;
}
.toc-level-1 .toc-text {
    font-weight: 600;
    color: var(--text-primary);
}
.toc-level-3 .toc-text {
    font-size: 0.85rem;
    opacity: 0.85;
}

/* vertical progress bar inside TOC */
.toc-progress-track {
    position: absolute;
    inset-inline-start: 3px;
    top: 48px;
    bottom: 0;
    width: 2px;
    background: rgba(0, 120, 255, 0.08);
    border-radius: 2px;
    z-index: 2;
}
.toc-progress-fill {
    width: 100%;
    height: 0%;
    background: linear-gradient(to bottom, var(--primary), var(--accent));
    border-radius: 2px;
    transition: height 0.3s ease;
}

/* ── Responsive TOC ── */
@media (max-width: 768px) {
    .toc-link {
        font-size: 0.85rem;
        padding-block: 8px;
        padding-inline-start: calc(14px + var(--indent, 0) * 12px);
        padding-inline-end: 14px;
    }
}

/* ── Accessibility ── */
@media (prefers-reduced-motion: reduce) {
    .hero-bg-layer,
    .hero-grid-layer,
    .hero-glow-layer,
    .hero-float-icon,
    .hero-particle,
    .hero-scroll-hint,
    .toc-progress-fill {
        animation: none !important;
        transition: none !important;
    }
}
