/* ---------- متغیرهای رنگ: حالت روشن ---------- */
:root {
    --bg:          #ffffff;
    --bg-soft:     #f9fafb;
    --card:        #ffffff;
    --border:      #e5e7eb;
    --border-soft: #f3f4f6;
    --text:        #111827;
    --text-body:   #374151;
    --text-muted:  #6b7280;
    --text-faint:  #9ca3af;
    --code-bg:     #f3f4f6;
    --code-border: #e5e7eb;
    --mark:        #fde68a;
    --link:        #111827;
    --radius:      0.65rem;
    --radius-sm:   0.45rem;
}

/* ---------- متغیرهای رنگ: حالت تاریک (طیف رینو) ---------- */
html.dark {
    --bg:          #19142d;
    --bg-soft:     #231e37;
    --card:        #231e37;
    --border:      rgba(85, 75, 105, 0.35);
    --border-soft: rgba(85, 75, 105, 0.2);
    --text:        #f0f0f5;
    --text-body:   #c3c8e4;
    --text-muted:  #a9b1d6;
    --text-faint:   #8288a8;
    --code-bg:     rgba(55, 50, 80, 0.55);
    --code-border: rgba(85, 75, 105, 0.4);
    --mark:        rgba(253, 230, 138, 0.25);
    --link:        #cdd1f0;
    color-scheme: dark;
}

/* ---------- پایه ---------- */
*,
::before,
::after {
    box-sizing: border-box;
}

html {
    -webkit-text-size-adjust: 100%;
}

body {
    margin: 0;
    background: var(--bg);
    color: var(--text-body);
    font-family: Vazirmatn, ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, Arial, sans-serif;
    font-size: 1rem;
    line-height: 1.9;
    -webkit-font-smoothing: antialiased;
    transition: background-color 0.25s ease, color 0.25s ease;
}

img,
video {
    max-width: 100%;
    height: auto;
    display: block;
}

a {
    color: var(--link);
    text-decoration: none;
}

a:hover {
    text-decoration: underline;
}

h1, h2, h3, h4, h5, h6 {
    color: var(--text);
    font-weight: 700;
    line-height: 1.5;
    margin: 0;
}

p {
    margin: 0;
}

::selection {
    background: var(--mark);
    color: var(--text);
}

/* ---------- کانتینر ---------- */
.container {
    max-width: 46rem; /* ~۷۳۶px — عرض خوانای مطالب */
    margin-inline: auto;
    padding-inline: 1rem;
}

/* ============================================================
   هدر
   ============================================================ */
.site-header {
    border-bottom: 1px solid var(--border-soft);
}

.header-inner {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    padding-block: 1.1rem;
}

.site-title {
    font-size: 1.35rem;
    font-weight: 700;
    margin: 0;
}

.site-title a {
    color: var(--text);
}

.site-title a:hover {
    text-decoration: none;
    opacity: 0.8;
}

.site-nav {
    display: flex;
    align-items: center;
    gap: 0.9rem;
}

.site-nav-link {
    display: inline-flex;
    align-items: center;
    gap: 0.3rem;
    font-size: 0.875rem;
    font-weight: 500;
    color: var(--text-muted);
    padding: 0.35rem 0.7rem;
    border-radius: var(--radius-sm);
    border: 1px solid var(--border);
    transition: color 0.2s ease, border-color 0.2s ease, background-color 0.2s ease;
}

.site-nav-link:hover {
    text-decoration: none;
    color: var(--text);
    border-color: var(--text-faint);
    background: var(--bg-soft);
}

/* ---------- جستجوی هدر ---------- */
.header-search {
    display: flex;
    align-items: center;
    gap: 0.35rem;
    flex: 1 1 9rem;
    max-width: 17rem;
    padding: 0.35rem 0.75rem;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    background: var(--bg);
    transition: border-color 0.2s ease, box-shadow 0.2s ease;
}

.header-search:focus-within {
    border-color: var(--text-faint);
    box-shadow: 0 0 0 3px var(--border-soft);
}

.header-search-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 0;
    border: none;
    background: transparent;
    color: var(--text-faint);
    cursor: pointer;
}

.header-search-btn:hover {
    color: var(--text);
}

.header-search-input {
    flex: 1;
    min-width: 0;
    border: none;
    background: transparent;
    font-family: inherit;
    font-size: 0.875rem;
    color: var(--text);
    outline: none;
}

.header-search-input::placeholder {
    color: var(--text-faint);
}

/* ---------- دکمهٔ حالت روشن/تاریک ---------- */
.theme-toggle {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 2rem;
    height: 2rem;
    padding: 0;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    background: transparent;
    color: var(--text-muted);
    cursor: pointer;
    transition: color 0.2s ease, border-color 0.2s ease, background-color 0.2s ease;
}

.theme-toggle:hover {
    color: var(--text);
    border-color: var(--text-faint);
    background: var(--bg-soft);
}

.theme-toggle .icon-sun { display: none; }
.theme-toggle .icon-moon { display: block; }

html.dark .theme-toggle .icon-sun { display: block; }
html.dark .theme-toggle .icon-moon { display: none; }

/* ============================================================
   فهرست نوشته‌ها (خانه)
   ============================================================ */
main.container {
    padding-block: 2rem 3rem;
    min-height: 60vh;
}

/* ---------- هدر آرشیو (دسته/جستجو/برچسب/…) ---------- */
.archive-header {
    padding-bottom: 1.5rem;
    margin-bottom: 0.5rem;
    border-bottom: 1px solid var(--border-soft);
}

.archive-title {
    font-size: 1.25rem;
}

.archive-desc {
    margin-top: 0.5rem;
    font-size: 0.9rem;
    color: var(--text-muted);
}

/* ---------- آیتم نوشته ----------
   حالت روشن: بدون قاب (جدا شدن با فاصله، مانند مرجع)
   حالت تاریک: کارت با پس‌زمینهٔ بنفش تیره */
.post-list {
    display: flex;
    flex-direction: column;
}

.post-item {
    padding: 0.25rem 1rem 1rem;
    margin-top: 1.5rem;
    border-radius: var(--radius);
}

html.dark .post-item {
    background: var(--card);
    border: 1px solid var(--border-soft);
    padding: 0.9rem 1.1rem 1.1rem;
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.18);
}

.post-item-title {
    font-size: 1.25rem;
    font-weight: 700;
}

.post-item-title a {
    color: var(--text);
}

.post-item-title a:hover {
    text-decoration: underline;
    text-underline-offset: 4px;
    text-decoration-thickness: 1.5px;
}

.post-item-excerpt {
    margin-top: 0.55rem;
    color: var(--text-body);
    font-size: 0.95rem;
    line-height: 1.9;
}

.post-item-more {
    display: inline-flex;
    align-items: center;
    gap: 0.35rem;
    margin-top: 0.75rem;
    font-size: 0.875rem;
    font-weight: 500;
    color: var(--text);
}

.post-item-more:hover {
    text-decoration: underline;
    text-underline-offset: 4px;
}

.post-item-date {
    display: block;
    margin-top: 0.65rem;
    font-size: 0.8rem;
    color: var(--text-faint);
}

/* ---------- حالت خالی ---------- */
.empty-state {
    padding: 4rem 1rem;
    text-align: center;
}

.empty-state h2 {
    font-size: 1.4rem;
}

.empty-state p {
    margin-top: 0.75rem;
    color: var(--text-muted);
    font-size: 0.95rem;
}

.empty-state .post-item-more {
    margin-top: 1.5rem;
}

.not-found-code {
    font-size: 4.5rem;
    font-weight: 700;
    color: var(--text-faint);
    line-height: 1;
    margin-bottom: 1rem;
}

/* ---------- صفحه‌بندی ---------- */
.pagination {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: center;
    gap: 0.4rem;
    margin-top: 2.5rem;
    font-size: 0.9rem;
}

.pagination span,
.pagination a {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 2.1rem;
    height: 2.1rem;
    padding-inline: 0.55rem;
    border-radius: var(--radius-sm);
    border: 1px solid var(--border);
    color: var(--text-muted);
}

.pagination a:hover {
    text-decoration: none;
    color: var(--text);
    border-color: var(--text-faint);
    background: var(--bg-soft);
}

.pagination .current {
    color: var(--bg);
    background: var(--text);
    border-color: var(--text);
    font-weight: 500;
}

/* ============================================================
   نوشتهٔ کامل / برگه
   ============================================================ */
.post-single {
    margin-top: 1rem;
}

.post-single-title {
    font-size: 2rem;
    line-height: 1.6;
}

.post-single-meta {
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: 0.75rem;
    margin-top: 1rem;
    padding-bottom: 1.5rem;
    border-bottom: 1px solid var(--border-soft);
}

.post-single-meta-info {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 0.5rem;
    font-size: 0.875rem;
    color: var(--text-muted);
}

.post-single-meta-info .meta-author {
    color: var(--text);
    font-weight: 500;
}

.meta-dot {
    color: var(--text-faint);
}

.back-link {
    display: inline-flex;
    align-items: center;
    gap: 0.3rem;
    font-size: 0.8rem;
    font-weight: 500;
    color: var(--text-muted);
    padding: 0.3rem 0.7rem;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    transition: color 0.2s ease, border-color 0.2s ease, background-color 0.2s ease;
}

.back-link:hover {
    text-decoration: none;
    color: var(--text);
    border-color: var(--text-faint);
    background: var(--bg-soft);
}

/* ---------- برچسب‌ها ---------- */
.post-tags {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
    margin-top: 2rem;
    padding-top: 1.5rem;
    border-top: 1px solid var(--border-soft);
}

.post-tag {
    font-size: 0.8rem;
    font-weight: 500;
    color: var(--text-muted);
    border: 1px solid var(--border);
    padding: 0.25rem 0.75rem;
    border-radius: 50px;
    transition: color 0.2s ease, border-color 0.2s ease, background-color 0.2s ease;
}

.post-tag:hover {
    text-decoration: none;
    color: var(--text);
    border-color: var(--text-faint);
    background: var(--bg-soft);
}

/* ============================================================
   محتوای نوشته (پاراگراف‌های Markdown)
   ============================================================ */
.post-content {
    margin-top: 1.75rem;
    font-size: 1.02rem;
    line-height: 2;
}

.post-content > * + * {
    margin-top: 1.15em;
}

.post-content h1,
.post-content h2,
.post-content h3,
.post-content h4 {
    margin-top: 1.8em;
    line-height: 1.6;
}

.post-content h2 { font-size: 1.45rem; }
.post-content h3 { font-size: 1.2rem; }
.post-content h4 { font-size: 1.05rem; }

.post-content a {
    color: var(--link);
    text-decoration: underline;
    text-underline-offset: 4px;
    text-decoration-thickness: 1px;
}

.post-content a:hover {
    text-decoration-thickness: 2px;
}

.post-content blockquote {
    margin-inline: 0;
    padding: 0.6rem 1.2rem;
    border-inline-start: 3px solid var(--text-faint);
    color: var(--text-muted);
    background: var(--bg-soft);
    border-radius: var(--radius-sm);
}

.post-content ul,
.post-content ol {
    padding-inline-start: 1.6rem;
    padding-inline-end: 0;
}

.post-content ul { list-style: disc; }
.post-content ol { list-style: decimal; }
.post-content li + li { margin-top: 0.4em; }

.post-content img {
    border-radius: var(--radius);
    margin-inline: auto;
}

.post-content hr {
    border: none;
    border-top: 1px solid var(--border);
    margin-block: 2.5rem;
}

/* ---------- کد ---------- */
.post-content code,
.comment-content code {
    direction: ltr;
    unicode-bidi: embed;
    display: inline-block;
    font-family: ui-monospace, "SFMono-Regular", Menlo, Consolas, "Courier New", monospace;
    font-size: 0.85em;
    background: var(--code-bg);
    border: 1px solid var(--code-border);
    border-radius: 6px;
    padding: 0.1em 0.4em;
}

.post-content pre,
.comment-content pre {
    direction: ltr;
    text-align: left;
    overflow-x: auto;
    background: var(--code-bg);
    border: 1px solid var(--code-border);
    border-radius: var(--radius);
    padding: 1rem 1.2rem;
    line-height: 1.7;
}

.post-content pre code,
.comment-content pre code {
    display: block;
    background: transparent;
    border: none;
    padding: 0;
    font-size: 0.85rem;
}

/* ---------- جدول ---------- */
.post-content table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.92rem;
}

.post-content th,
.post-content td {
    border: 1px solid var(--border);
    padding: 0.5rem 0.8rem;
    text-align: right;
}

.post-content th {
    background: var(--bg-soft);
    color: var(--text);
    font-weight: 700;
}

/* ============================================================
   نظرات
   ============================================================ */
.comments-area {
    margin-top: 3rem;
    padding-top: 2rem;
    border-top: 1px solid var(--border-soft);
}

.comments-title,
.comment-form-title {
    font-size: 1.15rem;
    margin-bottom: 1.25rem;
}

.comment-list,
.comment-children {
    list-style: none;
    margin: 0;
    padding: 0;
}

.comment-item {
    padding: 1rem;
    margin-top: 0.9rem;
    border-radius: var(--radius);
}

html.dark .comment-item {
    background: var(--card);
    border: 1px solid var(--border-soft);
}

/* ردیف اصلی نظر: آواتار + متن
   (پاسخ‌ها «زیر» همین ردیف قرار می‌گیرند، نه کنار آن) */
.comment-main {
    display: flex;
    gap: 0.85rem;
}

/* ریسهٔ پاسخ‌ها — زیر نظر والد، با تورفتگی و خط ریسه */
.comment-children {
    list-style: none;
    margin: 0.75rem 0 0;
    padding: 0;
    padding-inline-start: 0.85rem;
    border-inline-start: 2px solid var(--border);
    margin-inline-start: 2.2rem;
}

.comment-children .comment-item {
    margin-top: 0.6rem;
    padding: 0.65rem 0 0;
    border-radius: 0;
}

html.dark .comment-children .comment-item {
    background: transparent;
    border: none;
}

/* پاسخ‌های عمیق‌تر (سطح ۳ به بعد) — مسطح: بدون تورفتگی اضافه */
.comment-children .comment-children .comment-children {
    margin-inline-start: 0;
    padding-inline-start: 0.5rem;
}

.comment-avatar {
    flex-shrink: 0;
    width: 2.4rem;
    height: 2.4rem;
    border-radius: 50%;
}

.comment-body {
    flex: 1;
    min-width: 0;
}

.comment-head {
    display: flex;
    align-items: baseline;
    flex-wrap: wrap;
    gap: 0.6rem;
}

.comment-author {
    font-weight: 700;
    font-size: 0.92rem;
    color: var(--text);
}

.comment-date {
    font-size: 0.78rem;
    color: var(--text-faint);
}

.comment-reply-link {
    font-size: 0.8rem;
    font-weight: 500;
    color: var(--text-muted);
    margin-inline-start: auto;
}

.comment-reply-link:hover {
    color: var(--text);
}

.comment-content {
    margin-top: 0.45rem;
    font-size: 0.93rem;
    line-height: 1.9;
}

.comment-content p + p {
    margin-top: 0.7em;
}

/* ---------- فرم نظر ---------- */
.comment-respond {
    margin-top: 2.25rem;
}

.comment-logged-in {
    font-size: 0.9rem;
    color: var(--text-muted);
    margin-bottom: 1rem;
}

.comment-form-row {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 1rem;
}

.comment-form p {
    margin-top: 1rem;
}

.comment-form label {
    display: block;
    font-size: 0.85rem;
    font-weight: 500;
    color: var(--text-muted);
    margin-bottom: 0.4rem;
}

.comment-form .req {
    color: #ef4444;
}

.comment-form input[type="text"],
.comment-form input[type="email"],
.comment-form input[type="url"],
.comment-form textarea {
    width: 100%;
    font-family: inherit;
    font-size: 0.92rem;
    color: var(--text);
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 0.6rem 0.8rem;
    transition: border-color 0.2s ease, box-shadow 0.2s ease;
}

.comment-form textarea {
    resize: vertical;
    line-height: 1.8;
}

.comment-form input:focus,
.comment-form textarea:focus {
    outline: none;
    border-color: var(--text-faint);
    box-shadow: 0 0 0 3px var(--border-soft);
}

.comment-submit {
    font-family: inherit;
    font-size: 0.9rem;
    font-weight: 500;
    color: var(--bg);
    background: var(--text);
    border: none;
    border-radius: var(--radius-sm);
    padding: 0.65rem 1.6rem;
    cursor: pointer;
    transition: opacity 0.2s ease, transform 0.2s ease;
}

.comment-submit:hover {
    opacity: 0.88;
}

.comment-submit:active {
    transform: translateY(1px);
}

.comments-closed {
    margin-top: 1.5rem;
    font-size: 0.9rem;
    color: var(--text-faint);
}

/* ---------- لینک لغو پاسخ (خروجی cancelReply تایپچو) ---------- */
.comments-area .cancel-reply,
.comments-area .comment-cancel-reply {
    display: block;
    margin-bottom: 0.75rem;
    font-size: 0.85rem;
}

/* ============================================================
   پاورقی
   ============================================================ */
.site-footer {
    border-top: 1px solid var(--border-soft);
    padding-block: 1.5rem;
}

.footer-inner {
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: 0.6rem;
}

.footer-copy {
    font-size: 0.82rem;
    color: var(--text-faint);
}

.footer-sep {
    margin-inline: 0.4rem;
}

.footer-text {
    color: var(--text-faint);
}

/* ---------- شبکه‌های اجتماعی پاورقی ---------- */
.footer-socials {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.footer-social {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 2.25rem;
    height: 2.25rem;
    border: 1px solid var(--border);
    border-radius: 50%;
    color: var(--text-body);
    transition: color 0.2s ease, border-color 0.2s ease, background-color 0.2s ease;
}

.footer-social:hover {
    text-decoration: none;
    color: var(--text);
    border-color: var(--text-faint);
    background: var(--bg-soft);
}

/* ============================================================
   واکنش‌گرایی
   ============================================================ */
@media (max-width: 640px) {
    .container {
        padding-inline: 0.85rem;
    }

    /* هدر دو ردیفه: عنوان + ناوبری / جستجو تمام‌عرض در ردیف دوم */
    .header-inner {
        flex-wrap: wrap;
        padding-block: 0.9rem;
    }

    .site-nav {
        order: 4;
    }

    .header-search {
        order: 5;
        flex: 1 1 100%;
        max-width: none;
        margin-top: 0.15rem;
    }

    .site-title {
        font-size: 1.15rem;
    }

    .site-nav-link {
        font-size: 0.8rem;
        padding: 0.3rem 0.55rem;
    }

    .post-single-title {
        font-size: 1.45rem;
    }

    .post-item-title {
        font-size: 1.1rem;
    }

    .comment-form-row {
        grid-template-columns: 1fr;
        gap: 0;
    }

    .post-content {
        font-size: 0.98rem;
    }
}

/* ---------- کاهش حرکت ---------- */
@media (prefers-reduced-motion: reduce) {
    body,
    a,
    button,
    .site-nav-link,
    .theme-toggle,
    .header-search,
    .back-link,
    .post-tag,
    .footer-social {
        transition: none;
    }
}
