/* Featured Story */
.featured-story {
    margin-bottom: var(--spacing-xxl);
}

.featured-card {
    background: var(--color-white);
    border-radius: 16px;
    overflow: hidden;
    box-shadow: var(--shadow-lg);
    transition: box-shadow var(--transition-base);
    /* Performance optimizations */
    contain: layout style paint;
}

.featured-card:hover {
    box-shadow: var(--shadow-xl);
}

/* News Grid */
.news-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(350px, 1fr));
    gap: var(--spacing-xl);
}

/* Card Styles */
.news-card {
    background: var(--color-white);
    border-radius: 16px;
    overflow: hidden;
    box-shadow: var(--shadow-lg);
    border: 1px solid transparent;
    margin-bottom: var(--spacing-md);
    /* Performance optimizations */
    contain: layout style paint;
    display: flex; /* Make card a flex container */
    flex-direction: column; /* Stack children vertically */
    height: 100%; /* Ensure card takes full height of grid cell */
}

/* Better focus states for accessibility */
.news-card:focus-within {
    outline: none;
}

/* Header Meta Data (Time, Author) */
.card-header-meta {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: var(--spacing-sm) var(--spacing-md);
    font-size: var(--font-size-sm);
    color: var(--color-text-secondary);
    border-top: 1px solid #f0f0f0; /* Separator from content */
    flex-shrink: 0;
    margin-top: auto; /* Push to bottom if space allows */
    background: transparent; /* Fix: Match card background */
    z-index: 1;
}

/* Card Actions (Star, Share) - Below Image */
.card-actions {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: var(--spacing-sm) var(--spacing-md); /* Reduced padding */
    min-height: 40px;
}

.star-btn,
.share-btn {
    background: none;
    border: none;
    color: var(--color-text-secondary);
    cursor: pointer;
    padding: var(--spacing-sm);
    border-radius: 50%;
    transition: all var(--transition-base);
    display: flex;
    align-items: center;
    justify-content: center;
    width: 40px;
    height: 40px;
    -webkit-tap-highlight-color: transparent;
}

.star-btn:focus,
.share-btn:focus {
    background-color: transparent;
    outline: none;
}

.star-btn {
    color: var(--color-text-secondary);
    margin-left: -10px; /* Offset default padding visually to align with edge */
}

.star-btn.active {
    color: var(--color-gold);
}

.star-btn.active i {
    font-weight: 900; /* Solid star */
}

@media (hover: hover) {
    .star-btn:hover,
    .share-btn:hover {
        background-color: #f0f0f0;
        color: var(--color-text-primary);
    }

    .star-btn:hover {
        color: var(--color-gold); /* Hint at action */
    }
}

/* Image Container */
.card-image {
    position: relative;
    width: 100%;
    aspect-ratio: 15 / 11;
    overflow: hidden;
    flex-shrink: 0;
}

.card-image img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
    background-color: #f0f0f0;
    image-rendering: -webkit-optimize-contrast;
    image-rendering: crisp-edges;
}

.card-category {
    position: absolute;
    top: var(--spacing-md);
    left: var(--spacing-md);
    background: var(--color-primary-gradient);
    color: var(--color-white);
    padding: var(--spacing-sm) var(--spacing-md);
    border-radius: 20px;
    font-size: var(--font-size-xs);
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

/* Content Area */
.card-content {
    padding: 0 var(--spacing-md) var(--spacing-md) var(--spacing-md); /* Removed top padding, kept sides/bottom */
    display: flex;
    flex-direction: column;
    gap: var(--spacing-xs); /* Tighter gap */
    flex-grow: 1; /* Ensure content fills space */
}

.card-title {
    font-size: var(--font-size-lg);
    font-weight: 600;
    margin-bottom: var(--spacing-xs); /* Reduced margin */
    line-height: 1.3; /* Tighter line height */
    color: #222;
    letter-spacing: -0.01em;
    text-rendering: optimizeLegibility;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    overflow-wrap: break-word;
    word-wrap: break-word;
}

.featured-card .card-title {
    font-size: var(--font-size-xxl);
    margin-bottom: var(--spacing-md);
}

.card-description {
    color: #222;
    margin-bottom: var(--spacing-sm); /* Reduced margin */
    line-height: 1.35; /* Tighter for compact look (was 1.6) */
    font-size: var(--font-size-base);
    font-weight: 400;
    letter-spacing: 0.01em;
    word-spacing: 0.05em;
    text-rendering: optimizeLegibility;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    overflow-wrap: break-word;
    word-wrap: break-word;
    hyphens: auto;
    display: block;
    max-height: none;
    flex-grow: 1;
}

/* Loading animation */
@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateY(20px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.news-card,
.featured-card {
    animation: fadeIn 0.6s ease-out;
}

/* Mobile Responsive Design */
@media (max-width: 768px) {
    .main-content {
        padding: 0;
        margin-top: 0;
    }
    
    .featured-story {
        margin-bottom: 0;
    }
    
    .featured-card {
        border-radius: 0;
        box-shadow: none;
        margin-bottom: 0;
    }
    
    .news-grid {
        grid-template-columns: 1fr;
        gap: 0;
    }
    
    .news-card {
        border-radius: 0;
        box-shadow: none;
        margin-bottom: 0;
        border-bottom: 1px solid #eee;

        /* Scroll Snap Item */
        scroll-snap-align: start;
        scroll-snap-stop: always;
        /* scroll-margin-top removed to avoid double offset with html scroll-padding-top */

        /* Ensure it covers viewport appropriately */
        /* Calculation: 100dvh - CatNav (46px) - BottomNav (60px) */
        height: calc(100dvh - 106px);
        min-height: calc(100dvh - 106px);
        overflow: hidden; /* Prevent overflow */
    }

    /* Account for Header (72px) visibility on first card */
    .news-card:first-child {
        scroll-margin-top: 72px;
    }
    
    .card-image {
        aspect-ratio: 15 / 11;
    }
    
    .card-content {
        padding: 0 1rem 0.5rem 1rem; /* Tight padding */
        flex-grow: 1; /* Take available space */
        overflow-y: auto; /* Scroll internally if text is too long */
        height: auto;
    }
    
    .card-title {
        font-size: 1.2rem;
        line-height: 1.3;
        margin-bottom: 0.5rem;
    }
    
    .card-description {
        font-size: 0.95rem;
        line-height: 1.4; /* Tighter on mobile */
        margin-bottom: 0.5rem;
    }
    
    .card-header-meta {
        font-size: 0.9rem;
        padding: 0.75rem 1rem; /* Consistent with content padding */
    }
}

/* Mobile First - Phone Screens */
@media (max-width: 480px) {
    .main-content {
        padding: 0;
    }
    
    .card-content {
        padding: 0 1rem 1.25rem 1rem;
    }
    
    .card-title {
        font-size: 1.15rem;
    }
    
    .card-description {
        font-size: 0.95rem;
    }
    
    .star-btn,
    .share-btn {
        padding: 0.4rem;
    }
}

/* Tablet Styles */
@media (min-width: 769px) and (max-width: 1024px) {
    .news-grid {
        display: flex;
        flex-direction: column;
        align-items: center;
        gap: 0;
        margin: 0 auto;
    }
    
    .news-card {
        width: 100%;
        max-width: 450px; /* Fixed width like mobile shorts but centered */
        margin-bottom: 0;
        border-radius: 16px; /* Keep rounded corners on tablet */
        border: 1px solid #eee; /* Add subtle border for definition against background */

        /* Scroll Snap Item */
        scroll-snap-align: start;
        scroll-snap-stop: always;

        /* Ensure it covers viewport appropriately */
        /* Calculation: 100dvh - CatNav (57px) - BottomNav (60px) */
        height: calc(100dvh - 117px);
        min-height: calc(100dvh - 117px);
        overflow: hidden;

        display: flex;
        flex-direction: column;
    }

    /* Account for Header (80px) visibility on first card */
    .news-card:first-child {
        scroll-margin-top: 80px;
    }

    .card-image {
        aspect-ratio: 15 / 11;
        flex-shrink: 0;
    }
    
    .card-content {
        padding: 0 1rem 0.5rem 1rem;
        flex-grow: 1;
        overflow-y: auto;
        height: auto;
    }

    .card-header-meta {
        flex-shrink: 0;
    }

    .featured-story {
        display: none; /* Hide featured story in shorts mode for consistency */
    }
}

/* Desktop Styles */
@media (min-width: 1025px) {
    .news-grid {
        grid-template-columns: repeat(2, 1fr);
    }
    
    .featured-card {
        display: grid;
        grid-template-columns: 1fr 1fr;
        align-items: center;
    }
    
    .card-content {
        height: auto;
    }
    
    .card-description {
        font-size: 1rem;
        line-height: 1.5;
    }
}

/* Dark Theme Styles */
[data-theme="dark"] .news-card {
    background: #2a2a2a;
    border-color: rgba(255, 255, 255, 0.1);
    color: var(--color-text-primary);
}

[data-theme="dark"] .news-card .card-title {
    color: #f0f0f0;
}

[data-theme="dark"] .news-card .card-description {
    color: #d0d0d0;
}

[data-theme="dark"] .featured-card {
    background: #2a2a2a;
    border-color: rgba(255, 255, 255, 0.1);
}

[data-theme="dark"] .featured-card .card-title {
    color: var(--color-text-primary);
}

[data-theme="dark"] .featured-card .card-description {
    color: var(--color-text-secondary);
}

[data-theme="dark"] .card-header-meta {
    color: #b5b5b5;
    border-bottom-color: rgba(255, 255, 255, 0.1);
}

[data-theme="dark"] .author {
    color: var(--color-text-primary);
}

[data-theme="dark"] .time {
    color: var(--color-text-primary);
    background: rgba(255, 255, 255, 0);
}

[data-theme="dark"] .star-btn:hover,
[data-theme="dark"] .share-btn:hover {
    background-color: rgba(255, 255, 255, 0.1);
    color: var(--color-text-primary);
}

[data-theme="dark"] .star-btn.active {
    color: var(--color-gold);
}

[data-theme="dark"] .news-card {
    border-bottom-color: rgba(255, 255, 255, 0.1);
}
