/* ===== Latest posts section ===== */
.latest-posts-area {
    --lp-surface: #ffffff;
    --lp-border: rgba(16, 12, 40, 0.08);
    --lp-text: #1f1d2b;
    --lp-muted: #6b6880;
    --lp-accent: var(--color-primary, #49108b);
}

body.active-dark-mode .latest-posts-area {
    --lp-surface: #1d1d24;
    --lp-border: rgba(255, 255, 255, 0.08);
    --lp-text: #f3f3f6;
    --lp-muted: #a3a1b3;
    --lp-accent: #a98bf5;
}

/* ----- Heading ----- */
.latest-posts-head {
    display: flex;
    flex-wrap: wrap;
    align-items: flex-end;
    justify-content: space-between;
    gap: 12px 24px;
    margin-bottom: 28px;
}

.latest-posts-title {
    margin: 0 0 6px;
    color: var(--lp-text);
    font-size: 28px;
    font-weight: 800;
}

.latest-posts-subtitle {
    margin: 0;
    color: var(--lp-muted);
    font-size: 15px;
}

.latest-posts-all {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 10px 18px;
    border: 1px solid var(--lp-border);
    border-radius: 999px;
    color: var(--lp-accent);
    font-size: 14px;
    font-weight: 700;
    white-space: nowrap;
    transition: background-color 0.2s ease, border-color 0.2s ease;
}

.latest-posts-all:hover,
.latest-posts-all:focus-visible {
    border-color: var(--lp-accent);
    background: color-mix(in srgb, var(--lp-accent) 8%, transparent);
    color: var(--lp-accent);
}

.latest-posts-all i {
    transition: transform 0.2s ease;
}

.latest-posts-all:hover i {
    transform: translateX(-4px);
}

/* ----- Grid ----- */
.latest-posts-grid {
    display: grid;
    grid-template-columns: 1fr;
    gap: 16px;
}

/* ----- Card ----- */
.lp-card {
    position: relative;
    display: flex;
    flex-direction: column;
    min-width: 0;
    overflow: hidden;
    border: 1px solid var(--lp-border);
    border-radius: 16px;
    background: var(--lp-surface);
    transition: transform 0.25s ease, box-shadow 0.25s ease, border-color 0.25s ease;
}

.lp-card:hover,
.lp-card:focus-within {
    border-color: color-mix(in srgb, var(--lp-accent) 30%, transparent);
    box-shadow: 0 16px 32px rgba(16, 12, 40, 0.1);
    transform: translateY(-4px);
}

.lp-thumb {
    position: relative;
    display: block;
    aspect-ratio: 16 / 9;
    overflow: hidden;
    background: var(--lp-border);
}

.lp-thumb img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    transition: transform 0.4s ease;
}

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

.lp-badge {
    position: absolute;
    top: 12px;
    right: 12px;
    padding: 4px 12px;
    border-radius: 999px;
    background: rgba(255, 255, 255, 0.92);
    color: #1f1d2b;
    font-size: 12px;
    font-weight: 700;
    backdrop-filter: blur(6px);
}

.lp-badge--news { color: #c2410c; }
.lp-badge--tutorial { color: #1d4ed8; }
.lp-badge--package { color: #7e22ce; }
.lp-badge--video { color: #be123c; }

.lp-body {
    display: flex;
    flex: 1;
    flex-direction: column;
    gap: 12px;
    padding: 16px;
}

.lp-title {
    display: -webkit-box;
    margin: 0;
    overflow: hidden;
    font-size: 16px;
    font-weight: 700;
    line-height: 1.75;
    -webkit-box-orient: vertical;
    -webkit-line-clamp: 2;
}

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

/* The whole card is clickable through the title link */
.lp-title a::after {
    content: '';
    position: absolute;
    inset: 0;
    z-index: 1;
}

.lp-title a:hover {
    color: var(--lp-accent);
}

.lp-title a:focus-visible {
    outline: none;
}

.lp-card:has(.lp-title a:focus-visible) {
    outline: 3px solid color-mix(in srgb, var(--lp-accent) 45%, transparent);
    outline-offset: 2px;
}

.lp-excerpt {
    display: -webkit-box;
    margin: 0;
    overflow: hidden;
    color: var(--lp-muted);
    font-size: 15px;
    line-height: 1.9;
    -webkit-box-orient: vertical;
    -webkit-line-clamp: 3;
}

/* The theme's heading font has Latin digits; keep dates and times Persian */
.lp-meta,
.lp-meta * {
    font-family: Dana, Dana-fallback, Tahoma, sans-serif;
}

.lp-meta {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 6px 8px;
    margin-top: auto;
    color: var(--lp-muted);
    font-size: 13px;
}

.lp-dot {
    width: 4px;
    height: 4px;
    border-radius: 50%;
    background: currentColor;
    opacity: 0.5;
}

.lp-author {
    position: relative;
    z-index: 2; /* above the card-wide title link */
    display: inline-flex;
    align-items: center;
    gap: 8px;
    color: var(--lp-text);
    font-weight: 600;
}

.lp-author:hover {
    color: var(--lp-accent);
}

.lp-author img {
    width: 28px;
    height: 28px;
    border-radius: 50%;
    object-fit: cover;
}

/* ----- Phones: compact list rows after the featured card ----- */
@media (max-width: 575px) {
    .lp-card:not(.lp-card--featured) {
        flex-direction: row;
        align-items: stretch;
    }

    .lp-card:not(.lp-card--featured) .lp-thumb {
        flex: 0 0 120px;
        aspect-ratio: auto;
        min-height: 96px;
    }

    .lp-card:not(.lp-card--featured) .lp-badge {
        display: none;
    }

    .lp-card:not(.lp-card--featured) .lp-body {
        gap: 6px;
        padding: 10px 12px;
    }

    .lp-card:not(.lp-card--featured) .lp-title {
        font-size: 14px;
    }

    .lp-card:not(.lp-card--featured) .lp-meta {
        font-size: 12px;
    }
}

/* ----- Tablet: two columns ----- */
@media (min-width: 576px) {
    .latest-posts-grid {
        grid-template-columns: repeat(2, minmax(0, 1fr));
        gap: 20px;
    }

    .lp-card--featured {
        grid-column: 1 / -1;
    }
}

/* ----- Desktop: featured post spans 2x2, four cards beside it, four below ----- */
@media (min-width: 992px) {
    .latest-posts-grid {
        grid-template-columns: repeat(4, minmax(0, 1fr));
        gap: 24px;
    }

    .lp-card--featured {
        grid-column: span 2;
        grid-row: span 2;
    }

    /* Keep 16:9: thumbnails carry their own title text, so never crop them */
    .lp-card--featured .lp-body {
        padding: 20px 24px 24px;
    }

    .lp-card--featured .lp-title {
        font-size: 22px;
        line-height: 1.7;
    }

    .lp-card--featured .lp-badge {
        top: 16px;
        right: 16px;
        padding: 6px 14px;
        font-size: 13px;
    }
}

@media (prefers-reduced-motion: reduce) {
    .lp-card,
    .lp-thumb img,
    .latest-posts-all i {
        transition: none;
    }

    .lp-card:hover,
    .lp-card:focus-within {
        transform: none;
    }

    .lp-card:hover .lp-thumb img {
        transform: none;
    }
}
