/**
 * Cinematic Posts Grid Stylesheet
 * High-impact dark cinematic cards with smooth hover animations,
 * adaptive image fitting for non-square images, and configurable rows/columns.
 */

:root {
    --cpg-cols-desktop: 4;
    --cpg-cols-tablet: 2;
    --cpg-cols-mobile: 1;
    --cpg-rows: 1;
    --cpg-gap: 20px;
    --cpg-row-gap: 24px;
    --cpg-card-height: 470px;
    --cpg-img-height: 210px;
    --cpg-img-fit: cover;
    --cpg-img-pos: center top;
    --cpg-img-bg: #080a14;
    --cpg-radius: 14px;
    --cpg-accent-purple: #4b47b0;
    --cpg-deep-blue: #151532;
    --cpg-dark-bg: #06070a;
}

/* ==========================================================================
   GRID CONTAINER & ROW/COLUMN LAYOUT
   ========================================================================== */
.cpg-posts-grid {
    display: grid;
    grid-template-columns: repeat(var(--cpg-cols-desktop, 4), minmax(0, 1fr));
    gap: var(--cpg-row-gap, 24px) var(--cpg-gap, 20px);
    width: 100%;
    box-sizing: border-box;
    margin: 0 auto;
}

/* Column Helpers */
.cpg-posts-grid[data-cols="1"], .cpg-cols-1 { grid-template-columns: minmax(0, 1fr); }
.cpg-posts-grid[data-cols="2"], .cpg-cols-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.cpg-posts-grid[data-cols="3"], .cpg-cols-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.cpg-posts-grid[data-cols="4"], .cpg-cols-4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.cpg-posts-grid[data-cols="5"], .cpg-cols-5 { grid-template-columns: repeat(5, minmax(0, 1fr)); }
.cpg-posts-grid[data-cols="6"], .cpg-cols-6 { grid-template-columns: repeat(6, minmax(0, 1fr)); }

/* ==========================================================================
   POST CARD
   ========================================================================== */
.cpg-card {
    position: relative;
    border-radius: var(--cpg-radius, 14px);
    height: var(--cpg-card-height, 470px);
    overflow: hidden;
    display: flex;
    flex-direction: column;
    justify-content: flex-end;
    background-color: var(--cpg-dark-bg, #06070a);
    box-shadow: 0 10px 25px -8px rgba(0, 0, 0, 0.45);
    border: 1px solid rgba(255, 255, 255, 0.08);
    transition: transform 0.45s cubic-bezier(0.16, 1, 0.3, 1),
                box-shadow 0.45s cubic-bezier(0.16, 1, 0.3, 1),
                border-color 0.45s ease;
    text-decoration: none;
    outline: none;
    user-select: none;
    box-sizing: border-box;
    -webkit-font-smoothing: antialiased;
}

/* ==========================================================================
   IMAGE BOX & FITTING (Cover, Contain, Stretch, Centered, Scale-Down)
   ========================================================================== */
.cpg-card-img-wrap {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    height: var(--cpg-img-height, 210px);
    overflow: hidden;
    background-color: var(--cpg-img-bg, #080a14);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1;
    transition: height 0.3s ease;
}

.cpg-card-img {
    width: 100%;
    height: 100%;
    max-width: 100%;
    max-height: 100%;
    object-fit: var(--cpg-img-fit, cover);
    object-position: var(--cpg-img-pos, center top);
    display: block;
    transform: scale(1.001);
    transition: transform 0.65s cubic-bezier(0.16, 1, 0.3, 1),
                filter 0.65s ease;
    will-change: transform;
}

/* --- Explicit Fit Modes --- */
/* Cover: fills container, crops excess, maintains ratio */
.cpg-fit-cover .cpg-card-img,
.cpg-posts-grid[data-img-fit="cover"] .cpg-card-img {
    object-fit: cover;
}

/* Contain: fits whole image inside box without cropping */
.cpg-fit-contain .cpg-card-img,
.cpg-posts-grid[data-img-fit="contain"] .cpg-card-img {
    object-fit: contain;
    padding: 6px;
    box-sizing: border-box;
}

/* Stretch / Fill: forces image to stretch across the full width and height */
.cpg-fit-fill .cpg-card-img,
.cpg-posts-grid[data-img-fit="fill"] .cpg-card-img {
    object-fit: fill;
}

/* Centered / Natural size: does not scale photo, centers inside box */
.cpg-fit-none .cpg-card-img,
.cpg-posts-grid[data-img-fit="none"] .cpg-card-img {
    object-fit: none;
    width: auto;
    height: auto;
}

/* Scale Down: scales down only if larger than container */
.cpg-fit-scale-down .cpg-card-img,
.cpg-posts-grid[data-img-fit="scale-down"] .cpg-card-img {
    object-fit: scale-down;
}

/* --- Layout Modes --- */
/* Full Bleed Mode: Image spans 100% of card behind text */
.cpg-layout-full .cpg-card-img-wrap,
.cpg-posts-grid[data-img-layout="full"] .cpg-card-img-wrap {
    height: 100% !important;
    position: absolute;
    inset: 0;
}

.cpg-layout-full .cpg-card-img-fade,
.cpg-posts-grid[data-img-layout="full"] .cpg-card-img-fade {
    display: none !important;
}

/* Fallback if post has no thumbnail */
.cpg-card-no-img {
    width: 100%;
    height: 100%;
    background: radial-gradient(circle at 75% 25%, #2a2360 0%, #0c0b1e 70%);
}

/* Image Bottom Gradient Fade (smoothly blends image into card dark background) */
.cpg-card-img-fade {
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    height: 70px;
    background: linear-gradient(180deg, rgba(6, 7, 10, 0) 0%, rgba(6, 7, 10, 0.75) 60%, #06070a 100%);
    pointer-events: none;
    z-index: 2;
}

/* Signature Purple/Indigo Gradient Overlay across card bottom */
.cpg-card-overlay {
    position: absolute;
    inset: 0;
    z-index: 2;
    pointer-events: none;
    background: linear-gradient(
        180deg,
        rgba(6, 7, 10, 0.05) 0%,
        rgba(6, 7, 10, 0.25) 30%,
        rgba(10, 11, 25, 0.70) 50%,
        rgba(21, 21, 50, 0.92) 72%,
        rgba(48, 47, 98, 0.96) 88%,
        var(--cpg-accent-purple, #4b47b0) 100%
    );
    transition: opacity 0.4s ease;
}

/* In full-bleed mode, deepen gradient overlay so text remains razor-sharp */
.cpg-layout-full .cpg-card-overlay,
.cpg-posts-grid[data-img-layout="full"] .cpg-card-overlay {
    background: linear-gradient(
        180deg,
        rgba(6, 7, 10, 0.25) 0%,
        rgba(6, 7, 10, 0.55) 30%,
        rgba(21, 21, 50, 0.90) 65%,
        rgba(48, 47, 98, 0.95) 82%,
        var(--cpg-accent-purple, #4b47b0) 100%
    );
}

/* ==========================================================================
   CARD CONTENT
   ========================================================================== */
.cpg-card-content {
    position: relative;
    z-index: 3;
    padding: 24px 22px 20px 22px;
    display: flex;
    flex-direction: column;
    justify-content: flex-end;
    box-sizing: border-box;
    transition: transform 0.4s cubic-bezier(0.16, 1, 0.3, 1);
}

/* Post Title */
.cpg-card-title {
    font-family: 'Montserrat', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
    font-size: 1.35rem;
    font-weight: 700;
    line-height: 1.24;
    color: #ffffff;
    margin: 0 0 10px 0;
    letter-spacing: -0.015em;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
    text-overflow: ellipsis;
    text-shadow: 0 2px 10px rgba(0, 0, 0, 0.5);
    transition: color 0.3s ease;
}

.cpg-card-title a {
    color: inherit;
    text-decoration: none;
}

/* Post Excerpt */
.cpg-card-excerpt {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
    font-size: 0.90rem;
    line-height: 1.5;
    color: rgba(230, 233, 255, 0.82);
    margin: 0 0 18px 0;
    display: -webkit-box;
    -webkit-line-clamp: 3;
    -webkit-box-orient: vertical;
    overflow: hidden;
    text-overflow: ellipsis;
    font-weight: 400;
    text-shadow: 0 1px 3px rgba(0, 0, 0, 0.4);
}

/* Meta Footer Row (Date + Read More) */
.cpg-card-footer {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding-top: 14px;
    border-top: 1px solid rgba(255, 255, 255, 0.12);
    box-sizing: border-box;
}

/* Post Date */
.cpg-card-date {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    font-size: 0.82rem;
    font-weight: 500;
    color: #b5b8e4;
    letter-spacing: 0.01em;
    display: inline-flex;
    align-items: center;
    gap: 6px;
}

/* Read More Link */
.cpg-card-readmore {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    font-size: 0.86rem;
    font-weight: 600;
    color: #ffffff;
    text-decoration: none;
    display: inline-flex;
    align-items: center;
    gap: 6px;
    transition: color 0.25s ease, transform 0.25s ease;
    cursor: pointer;
}

.cpg-card-readmore .cpg-arrow {
    display: inline-block;
    transition: transform 0.3s cubic-bezier(0.16, 1, 0.3, 1);
    font-size: 1.05rem;
    line-height: 1;
}

/* Whole card clickable link overlay */
.cpg-card-full-link {
    position: absolute;
    inset: 0;
    z-index: 4;
    opacity: 0;
}

/* ==========================================================================
   ANIMATIONS & HOVER STATES
   ========================================================================== */
.cpg-card:hover {
    transform: translateY(-8px);
    box-shadow: 0 24px 44px -10px rgba(75, 71, 176, 0.5),
                0 0 20px rgba(75, 71, 176, 0.25);
    border-color: rgba(145, 140, 255, 0.38);
}

.cpg-card:hover .cpg-card-img {
    transform: scale(1.08);
    filter: brightness(1.06);
}

.cpg-card:hover .cpg-card-content {
    transform: translateY(-3px);
}

.cpg-card:hover .cpg-card-readmore .cpg-arrow {
    transform: translateX(4px);
}

/* Staggered Scroll Entrance Animation */
.cpg-animated .cpg-card {
    opacity: 0;
    transform: translateY(24px);
    transition: opacity 0.6s cubic-bezier(0.16, 1, 0.3, 1),
                transform 0.6s cubic-bezier(0.16, 1, 0.3, 1),
                box-shadow 0.45s ease,
                border-color 0.45s ease;
}

.cpg-animated.cpg-visible .cpg-card {
    opacity: 1;
    transform: translateY(0);
}

/* Stagger delays across items */
.cpg-animated.cpg-visible .cpg-card:nth-child(1) { transition-delay: 0.05s; }
.cpg-animated.cpg-visible .cpg-card:nth-child(2) { transition-delay: 0.10s; }
.cpg-animated.cpg-visible .cpg-card:nth-child(3) { transition-delay: 0.15s; }
.cpg-animated.cpg-visible .cpg-card:nth-child(4) { transition-delay: 0.20s; }
.cpg-animated.cpg-visible .cpg-card:nth-child(5) { transition-delay: 0.25s; }
.cpg-animated.cpg-visible .cpg-card:nth-child(6) { transition-delay: 0.30s; }
.cpg-animated.cpg-visible .cpg-card:nth-child(7) { transition-delay: 0.35s; }
.cpg-animated.cpg-visible .cpg-card:nth-child(8) { transition-delay: 0.40s; }

.cpg-animated.cpg-visible .cpg-card:hover {
    transition-delay: 0s !important;
    transform: translateY(-8px);
}

/* ==========================================================================
   RESPONSIVE BREAKPOINTS
   ========================================================================== */
@media screen and (max-width: 1024px) {
    .cpg-posts-grid {
        grid-template-columns: repeat(var(--cpg-cols-tablet, 2), minmax(0, 1fr)) !important;
        gap: 18px 16px;
    }
    .cpg-card {
        height: max(430px, var(--cpg-card-height, 460px));
    }
    .cpg-card-img-wrap {
        height: 190px;
    }
    .cpg-card-title {
        font-size: 1.25rem;
    }
    .cpg-card-content {
        padding: 20px 18px 16px 18px;
    }
}

@media screen and (max-width: 640px) {
    .cpg-posts-grid {
        grid-template-columns: repeat(var(--cpg-cols-mobile, 1), minmax(0, 1fr)) !important;
        gap: 18px 14px;
    }
    .cpg-card {
        height: 420px;
    }
    .cpg-card-img-wrap {
        height: 180px;
    }
    .cpg-card-title {
        font-size: 1.20rem;
    }
    .cpg-card-content {
        padding: 18px 16px 14px 16px;
    }
}
