/* ========================================
   HIGH-PERFORMANCE POST GRID STYLES
   ======================================== */

/* ========================================
   PROGRESSIVE GRID LAYOUTS
   Posts 1-2: 2 columns (large)
   Posts 3-8: 3 columns (medium) 
   Posts 9+: 4 columns (small)
   ======================================== */

/* Base grid containers */
.post-grid-masonry,
.post-grid-uniform,
.post-grid-compact {
    display: block; /* Allow for multiple grid sections */
}

/* Large posts section - First 2 posts in flexible grid */
.grid-section-large {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    grid-gap: 1.5rem;
    align-items: stretch;
    margin-bottom: 1.5rem;
}

/* Medium posts section - Next 6 posts in CSS Grid */
.grid-section-medium {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    grid-gap: 1.5rem;
    align-items: stretch;
    margin-bottom: 1.5rem;
}

/* Small posts section - Remaining posts in CSS Grid */
.grid-section-small {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    grid-gap: 1.5rem;
    align-items: stretch;
}

/* ========================================
   UNIFORM LAYOUT OVERRIDES
   All posts same size, consistent grid
   ======================================== */

.post-grid-uniform .grid-section-large,
.post-grid-uniform .grid-section-medium,
.post-grid-uniform .grid-section-small {
    grid-template-columns: repeat(3, 1fr);
    grid-gap: 1.5rem;
}

/* ========================================
   COMPACT LAYOUT OVERRIDES
   Smaller cards, more posts visible
   ======================================== */

.post-grid-compact .grid-section-large {
    grid-template-columns: repeat(4, 1fr);
    grid-gap: 1rem;
}

.post-grid-compact .grid-section-medium,
.post-grid-compact .grid-section-small {
    grid-template-columns: repeat(4, 1fr);
    grid-gap: 1rem;
}

.post-grid-compact .masonry-item {
    font-size: 0.9rem;
}

.post-grid-compact .masonry-item .card-image {
    height: 180px;
    overflow: hidden;
}

.post-grid-compact .masonry-item .title {
    font-size: 1.1rem !important;
    line-height: 1.3 !important;
}

.post-grid-compact .masonry-item .content p {
    font-size: 0.85rem !important;
    line-height: 1.4 !important;
}

/* ========================================
   MASONRY ITEM BASE STYLES
   ======================================== */

/* Base masonry item - shared by all sections */
.masonry-item {
    break-inside: avoid !important;
    page-break-inside: avoid !important;
    -webkit-column-break-inside: avoid !important;
    overflow: hidden;
    width: 100% !important;
    box-sizing: border-box !important;
}

/* Ensure cards don't break - Override Bulma */
.masonry-item .card {
    break-inside: avoid !important;
    page-break-inside: avoid !important;
    -webkit-column-break-inside: avoid !important;
    display: block !important;
    position: relative !important;
    margin: 0 !important;
}

/* Override any Bulma flexbox that might interfere */
.masonry-item .card-content,
.masonry-item .card-image {
    break-inside: avoid !important;
    page-break-inside: avoid !important;
    -webkit-column-break-inside: avoid !important;
}

/* ========================================
   SEMANTIC TYPESCALE SYSTEM - Override Bulma Tokens
   ======================================== */

/* Large Scale - Featured posts with maximum impact */
.post-grid-masonry .grid-scale-large .masonry-card .card .title,
.post-grid-masonry .grid-scale-large .masonry-card .title,
.post-grid-uniform .grid-scale-large .masonry-card .card .title,
.post-grid-uniform .grid-scale-large .masonry-card .title,
.post-grid-compact .grid-scale-large .masonry-card .card .title,
.post-grid-compact .grid-scale-large .masonry-card .title {
    --bulma-title-size: var(--text-xl) !important;
    --bulma-title-weight: var(--weight-semibold) !important;
    --bulma-title-line-height: var(--leading-tight) !important;
    font-size: var(--text-xl) !important;
    line-height: var(--leading-tight) !important;
    font-weight: var(--weight-semibold) !important;
    margin-bottom: var(--space-4) !important;
}

.post-grid-masonry .grid-scale-large .masonry-card .card .content p,
.post-grid-masonry .grid-scale-large .masonry-card .content p,
.post-grid-uniform .grid-scale-large .masonry-card .card .content p,
.post-grid-uniform .grid-scale-large .masonry-card .content p,
.post-grid-compact .grid-scale-large .masonry-card .card .content p,
.post-grid-compact .grid-scale-large .masonry-card .content p {
    font-size: var(--text-base) !important;
    line-height: var(--leading-relaxed) !important;
}

.post-grid-masonry .grid-scale-large .masonry-card .post-meta-flex,
.post-grid-uniform .grid-scale-large .masonry-card .post-meta-flex,
.post-grid-compact .grid-scale-large .masonry-card .post-meta-flex {
    margin-bottom: var(--space-4) !important;
}

.post-grid-masonry .grid-scale-large .masonry-card .button-container {
    margin-top: var(--space-4) !important;
}

/* Medium Scale - Balanced content presentation */
.post-grid-masonry .grid-scale-medium .masonry-card .card .title,
.post-grid-masonry .grid-scale-medium .masonry-card .title {
    --bulma-title-size: var(--text-lg) !important;
    --bulma-title-weight: var(--weight-medium) !important;
    --bulma-title-line-height: var(--leading-tight) !important;
    font-size: var(--text-lg) !important;
    line-height: var(--leading-tight) !important;
    font-weight: var(--weight-medium) !important;
    margin-bottom: var(--space-3) !important;
}

.post-grid-masonry .grid-scale-medium .masonry-card .card .content p,
.post-grid-masonry .grid-scale-medium .masonry-card .content p {
    font-size: var(--text-sm) !important;
    line-height: var(--leading-normal) !important;
}

.post-grid-masonry .grid-scale-medium .masonry-card .post-meta-flex {
    margin-bottom: var(--space-3) !important;
}

.post-grid-masonry .grid-scale-medium .masonry-card .button-container {
    margin-top: var(--space-3) !important;
}

/* Small Scale - Compact, efficient presentation */
.post-grid-masonry .grid-scale-small .masonry-card .card .title,
.post-grid-masonry .grid-scale-small .masonry-card .title {
    --bulma-title-size: var(--text-base) !important;
    --bulma-title-weight: var(--weight-normal) !important;
    --bulma-title-line-height: var(--leading-tight) !important;
    font-size: var(--text-base) !important;
    line-height: var(--leading-tight) !important;
    font-weight: var(--weight-normal) !important;
    margin-bottom: var(--space-2) !important;
}

.post-grid-masonry .grid-scale-small .masonry-card .card .content p,
.post-grid-masonry .grid-scale-small .masonry-card .content p {
    font-size: var(--text-xs) !important;
    line-height: var(--leading-normal) !important;
}

.post-grid-masonry .grid-scale-small .masonry-card .post-meta-flex {
    margin-bottom: var(--space-2) !important;
}

.post-grid-masonry .grid-scale-small .masonry-card .button-container {
    margin-top: var(--space-2) !important;
}

/* ========================================
   RESPONSIVE TYPESCALE ADJUSTMENTS
   ======================================== */

/* Mobile adjustments - scale down appropriately */
@media (max-width: 768px) {
    .post-grid-masonry .grid-scale-large .masonry-card .card .title,
    .post-grid-masonry .grid-scale-large .masonry-card .title {
        --bulma-title-size: var(--text-lg) !important;
        font-size: var(--text-lg) !important;
    }
    
    .post-grid-masonry .grid-scale-medium .masonry-card .card .title,
    .post-grid-masonry .grid-scale-medium .masonry-card .title {
        --bulma-title-size: var(--text-base) !important;
        font-size: var(--text-base) !important;
    }
    
    .post-grid-masonry .grid-scale-small .masonry-card .card .title,
    .post-grid-masonry .grid-scale-small .masonry-card .title {
        --bulma-title-size: var(--text-sm) !important;
        font-size: var(--text-sm) !important;
    }
}

/* ========================================
   RESPONSIVE BREAKPOINTS
   ======================================== */

/* Responsive adjustments for large section */
@media (max-width: 768px) {
    .masonry-section-large {
        grid-template-columns: 1fr;
        grid-gap: 1rem;
        margin-bottom: 1.5rem;
    }
}

/* Responsive adjustments for medium section */
@media (max-width: 1024px) {
    .masonry-section-medium {
        grid-template-columns: repeat(2, 1fr);
        grid-gap: 1.25rem;
    }
}

@media (max-width: 768px) {
    .masonry-section-medium {
        grid-template-columns: 1fr;
        grid-gap: 1rem;
        margin-bottom: 1.5rem;
    }
}

/* Responsive adjustments for small section */
@media (max-width: 1024px) {
    .masonry-section-small {
        grid-template-columns: repeat(2, 1fr);
        grid-gap: 1rem;
    }
}

@media (max-width: 768px) {
    .masonry-section-small {
        grid-template-columns: 1fr;
        grid-gap: 1rem;
    }
}

/* ========================================
   UNIFIED MEDIA CONTAINER SYSTEM
   ======================================== */

/* Media container with border but no bottom border-radius */
.media-container {
    position: relative;
    overflow: hidden;
    border-radius: 12px 12px 0 0; /* No bottom border-radius */
    border: 1px solid var(--bulma-border);
    border-bottom: none; /* Remove bottom border so card border shows */
    background: var(--bulma-background);
}

/* Unified image and video styles */
.post-grid-image,
.post-grid-video {
    width: 100%;
    height: auto;
    object-fit: cover;
    object-position: center;
    display: block;
    border-radius: 0;
    
    /* Smooth, consistent transitions */
    transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1), 
                opacity 0.3s ease;
    will-change: transform;
}

/* Video-specific enhancements */
.post-grid-video {
    cursor: pointer;
}

/* Mobile: No additional transforms for better performance */
@media (max-width: 768px) {
    .post-grid-masonry .masonry-item .card {
        transition: box-shadow 0.2s ease;
    }
}

/* ========================================
   UNIFIED CARD SYSTEM - Consistent Styles & Simple Hover
   ======================================== */

/* Base card styling - uniform background for all cards */
.post-grid-masonry .masonry-item .card {
    /* Unified appearance - same background for all */
    background: var(--bulma-scheme-main);
    border: 1px solid var(--bulma-border);
    border-radius: 12px;
    overflow: hidden;
    box-shadow: var(--shadow-sm);
    
    /* Simple, consistent behavior */
    transition: transform 0.2s ease, box-shadow 0.2s ease;
    will-change: transform, box-shadow;
    height: 100%;
    
    /* Reset margins */
    margin: 0;
    
    /* Prevent breaking */
    break-inside: avoid !important;
    page-break-inside: avoid !important;
    -webkit-column-break-inside: avoid !important;
    display: block !important;
    position: relative !important;
}

/* Simple unified hover effect - same for all card sizes */
.post-grid-masonry .masonry-item .card:hover {
    transform: translateY(-2px);
    box-shadow: var(--shadow-md);
}

/* Remove category-specific backgrounds - uniform cards */
.writing-post.category-writing,
.writing-post.category-design,
.writing-post.category-tools,
.writing-post.category-development,
.writing-post[class*="category-"] {
    background: var(--bulma-scheme-main) !important;
}

/* Mobile: Reduce animations for performance */
@media (max-width: 768px) {
    .post-grid-masonry .masonry-item .card:hover {
        transform: none;
        box-shadow: var(--shadow-sm);
    }
    
    .post-grid-masonry .masonry-item .card {
        transition: box-shadow 0.2s ease;
    }
}

/* ========================================
   POST META LAYOUT - Year left, Tags right
   ======================================== */

/* Flex layout for post meta - date on left, tags on right */
.post-meta-flex {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    gap: 1rem;
    margin-bottom: var(--space-3);
}

.post-date {
    display: flex;
    align-items: center;
    flex-shrink: 0;
}

.post-tags {
    display: flex;
    gap: 0.5rem;
    flex-wrap: wrap;
    justify-content: flex-end;
}

.post-tags .tag {
    margin: 0;
}

/* Enhanced stacked meta layout for editorial grid */
.post-meta-stacked {
    display: flex;
    flex-direction: column;
}

.category-wrapper {
    display: flex;
    align-items: flex-start;
}

.compact-meta-stacked {
    display: flex;
    flex-direction: column;
}

.compact-category {
    display: flex;
    align-items: flex-start;
}

/* Enhanced tag styling for better visual hierarchy */
.category-wrapper .tag,
.compact-category .tag,
.post-tags .tag {
    border-radius: 6px;
    font-weight: 600;
    letter-spacing: 0.05em;
}

/* Ensure proper text wrapping for long titles */
.post-meta-stacked .title,
.compact-meta-stacked + h4.title {
    word-wrap: break-word;
    -webkit-hyphens: auto;
    hyphens: auto;
}

/* Clean spacing for stacked layout */
.post-meta-stacked time {
    margin-bottom: 0.5rem;
    font-weight: 700;
}

.compact-meta-stacked time {
    margin-bottom: 0.25rem;
    font-weight: 700;
}

/* Consistent visual rhythm */
.category-wrapper,
.compact-category {
    margin-bottom: 0.75rem;
}

/* ========================================
   MASONRY CARD SYSTEM - VIDEO COMPONENTS
   ======================================== */

/* Writing Grid Images & Videos */
.post-grid-image,
.post-grid-video {
    transition: transform 0.25s ease;
    will-change: transform;
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
    border-radius: 0;
}

/* Video container and indicator styling */
.video-container {
    position: relative;
    width: 100%;
    height: 100%;
}

.hover-preview-video {
    cursor: pointer;
    transition: transform 0.25s ease, opacity 0.2s ease;
    width: 100%;
    height: 100%;
}

.hover-preview-video:hover {
    opacity: 0.9;
}

/* Video progress ring indicator - Modern flexbox approach */
.video-progress-indicator {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 60px;
    height: 60px;
    z-index: 10;
    pointer-events: none;
    transition: opacity 0.3s ease, transform 0.3s ease;
    opacity: 0.8;
    display: flex;
    align-items: center;
    justify-content: center;
}

.progress-ring-svg {
    position: absolute;
    width: 100%;
    height: 100%;
    transform: rotate(-90deg);
    filter: drop-shadow(0 2px 8px rgba(0, 0, 0, 0.3));
}

.play-icon-container {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 100%;
    height: 100%;
    position: relative;
    z-index: 1;
}

.play-icon-svg {
    filter: drop-shadow(0 2px 8px rgba(0, 0, 0, 0.3));
}

.progress-ring-bg {
    transition: stroke 0.3s ease;
}

.progress-ring-progress {
    transition: stroke-dashoffset 0.1s ease-out, stroke 0.3s ease;
    transform-origin: center;
}

.play-icon {
    transition: fill 0.3s ease;
}

/* Hover states */
.video-container:hover .video-progress-indicator {
    opacity: 1;
    transform: translate(-50%, -50%) scale(1.1);
}

.video-container:hover .progress-ring-bg {
    stroke: rgba(255, 255, 255, 0.5);
}

/* Size variations for different masonry sections */
.grid-scale-large .video-progress-indicator {
    width: 80px;
    height: 80px;
}

.grid-scale-medium .video-progress-indicator {
    width: 70px;
    height: 70px;
}

.grid-scale-small .video-progress-indicator {
    width: 50px;
    height: 50px;
}

/* Scale play icon with container */
.grid-scale-large .play-icon-svg {
    width: 32px;
    height: 32px;
}

.grid-scale-medium .play-icon-svg {
    width: 28px;
    height: 28px;
}

.grid-scale-small .play-icon-svg {
    width: 20px;
    height: 20px;
}

/* Pulse animation when complete */
@keyframes progress-complete-pulse {
    0% { 
        transform: translate(-50%, -50%) scale(1.1);
        opacity: 1;
    }
    50% { 
        transform: translate(-50%, -50%) scale(1.3);
        opacity: 0.8;
    }
    100% { 
        transform: translate(-50%, -50%) scale(1.1);
        opacity: 1;
    }
}

.video-progress-indicator.complete {
    animation: progress-complete-pulse 0.8s ease-in-out;
}

.video-progress-indicator.complete .progress-ring-progress {
    stroke: rgba(255, 255, 255, 1);
    stroke-dashoffset: 0;
}

.video-progress-indicator.complete .play-icon {
    fill: rgba(255, 255, 255, 1);
}

/* Mobile responsive adjustments for progress ring */
@media screen and (max-width: 768px) {
    .grid-scale-large .video-progress-indicator {
        width: 60px;
        height: 60px;
    }
    .grid-scale-medium .video-progress-indicator {
        width: 50px;
        height: 50px;
    }
    .grid-scale-small .video-progress-indicator {
        width: 40px;
        height: 40px;
    }
    .grid-scale-large .play-icon-svg {
        width: 24px;
        height: 24px;
    }
    .grid-scale-medium .play-icon-svg {
        width: 20px;
        height: 20px;
    }
    .grid-scale-small .play-icon-svg {
        width: 16px;
        height: 16px;
    }
}

/* Ensure figures use Bulma's aspect ratio system */
.masonry-grid .card-image figure {
    margin: 0;
}

/* Hover effects for media - target individual cards instead of sections */
.grid-scale-large .masonry-card:hover .post-grid-image,
.grid-scale-large .masonry-card:hover .post-grid-video {
    transform: scale(1.03);
}

.grid-scale-medium .masonry-card:hover .post-grid-image,
.grid-scale-medium .masonry-card:hover .post-grid-video {
    transform: scale(1.02);
}

.grid-scale-small .masonry-card:hover .post-grid-image,
.grid-scale-small .masonry-card:hover .post-grid-video {
    transform: scale(1.015);
}

/* Ensure 16:9 aspect on small card media even if Bulma helper is missing */
.masonry-grid .card-image .image.is-16by9 {
    aspect-ratio: 16 / 9;
}

/* Minimal CTA link styling for cards */
.post-grid-cta,
.masonry-card .post-grid-cta {
    display: inline-flex;
    align-items: center;
    gap: 0.4rem;
    font-size: 0.85rem;
    line-height: 1;
    color: var(--color-text, #fff);
    text-decoration: none;
    border: 1px solid var(--color-border-light);
    border-radius: 9999px;
    padding: 0.35rem 0.6rem;
    background: transparent;
    transition: color 0.2s ease, border-color 0.2s ease, background-color 0.2s ease;
}

.post-grid-cta:hover {
    border-color: rgba(255,255,255,0.5);
    background-color: rgba(255,255,255,0.06);
}

.post-grid-cta .icon {
    display: inline-flex;
    width: 1em;
    height: 1em;
}

/* ========================================
   RESPONSIVE DESIGN & ACCESSIBILITY
   ======================================== */

/* Responsive grid layout */
@media screen and (max-width: 1200px) {
    .masonry-grid .columns {
        margin-bottom: 1.5rem !important;
    }
}

@media screen and (max-width: 768px) {
    .masonry-grid {
        margin: 1rem 0;
    }
    .masonry-grid .columns {
        margin-bottom: 1rem !important;
    }
    /* Mobile optimizations - disable transforms to prevent jank */
    .masonry-card:hover {
        transform: none;
        box-shadow: none;
    }
    .grid-scale-large .masonry-card:hover .post-grid-image,
    .grid-scale-large .masonry-card:hover .post-grid-video,
    .grid-scale-medium .masonry-card:hover .post-grid-image,
    .grid-scale-medium .masonry-card:hover .post-grid-video,
    .grid-scale-small .masonry-card:hover .post-grid-image,
    .grid-scale-small .masonry-card:hover .post-grid-video {
        transform: none;
    }
    /* Enhanced mobile video interaction */
    .video-container {
        position: relative;
        cursor: pointer;
        -webkit-touch-callout: none;
        -webkit-user-select: none;
        user-select: none;
    }
    .video-progress-indicator {
        opacity: 1 !important;
        transform: translate(-50%, -50%) scale(1.1) !important;
    }
    .post-grid-video {
        -webkit-transform: translateZ(0);
        transform: translateZ(0);
    }
    /* Larger touch targets for better UX */
    .video-container::after {
        content: '';
        position: absolute;
        top: -15px;
        left: -15px;
        right: -15px;
        bottom: -15px;
        z-index: 1;
        pointer-events: auto;
    }
}

/* Reduce motion for users who prefer it */
@media (prefers-reduced-motion: reduce) {
    .masonry-card {
        transition: none !important;
    }
    .masonry-card:hover {
        transform: none !important;
    }
    .post-grid-image,
    .post-grid-video {
        transition: none !important;
    }
    .grid-scale-large .masonry-card:hover .post-grid-image,
    .grid-scale-large .masonry-card:hover .post-grid-video,
    .grid-scale-medium .masonry-card:hover .post-grid-image,
    .grid-scale-medium .masonry-card:hover .post-grid-video,
    .grid-scale-small .masonry-card:hover .post-grid-image,
    .grid-scale-small .masonry-card:hover .post-grid-video {
        transform: none !important;
    }
}

/* Card border standardization */
.masonry-card .card {
    border: 1px solid var(--bulma-border);
}

.masonry-card .writing-post {
    border: 1px solid var(--bulma-border);
    box-shadow: none;
}

.masonry-card .card-image,
.masonry-card .card-header,
.masonry-card .card-content {
    border: none !important;
}

/* Mobile refinements for responsive layout */
@media screen and (max-width: 768px) {
    .category-wrapper,
    .compact-category {
        margin-bottom: 0.5rem;
    }
}

