* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

/* Optimize font loading and prevent layout shifts */
@font-face {
    font-display: optional; /* Prevents layout shifts */
    size-adjust: 100%;
}

@font-face {
    font-family: "Noto Sans";
    font-display: optional; /* Prevents layout shifts */
    size-adjust: 100%;
}

body {
    font-family: "Noto Sans", sans-serif;
    font-optical-sizing: auto;
    font-weight: 400;
    font-style: normal;
    font-variation-settings: "wdth" 100;
    line-height: 1.6;
    background: linear-gradient(135deg, #0a0a0a 0%, #1a1a1a 100%);
    min-height: 100vh;
    padding: 20px;
    color: #f0f0f0;
    overflow-x: hidden;
    /* Performance optimizations */
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    text-rendering: optimizeSpeed;
}

header {
    text-align: center;
    margin: 0 auto 30px auto;
    max-width: 1400px;
    padding: 45px;
}

#loading {
    display: none;
}

.sources-credit {
    font-size: 0.85em;
    color: #a0a0a0;
    margin-top: 10px;
    margin-bottom: 0;
}

.loading {
    text-align: center;
    padding: 40px;
    color: #d0d0d0;
    font-size: 1.2em;
}

.loading::after {
    content: '';
    display: inline-block;
    width: 20px;
    height: 20px;
    border: 3px solid #e60012;
    border-radius: 50%;
    border-top-color: transparent;
    animation: spin 1s ease-in-out infinite;
    margin-left: 10px;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

main {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(min(100%, 350px), 1fr));
    gap: 20px;
    max-width: 1400px;
    margin: 0 auto;
}

section {
    background: #1a1a1a;
    border-radius: 15px;
    padding: 25px;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.3);
    transition: transform 0.3s ease, box-shadow 0.3s ease;
    border: 1px solid #333;
    /* Prevent layout shifts */
    min-height: 400px;
    contain: layout;
}

.loading-placeholder {
    background: #1a1a1a;
    border-radius: 15px;
    padding: 25px;
    border: 1px solid #333;
    /* Match final section dimensions exactly */
    min-height: 400px;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.3);
    contain: layout;
}

.loading-spinner {
    font-size: 0.9em;
    color: #aaa;
    animation: pulse 1.5s ease-in-out infinite;
}

.error-indicator {
    font-size: 0.9em;
    color: #ff6b6b;
}

@keyframes pulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.5; }
}

.source-header {
    display: flex;
    align-items: center;
    margin-bottom: 20px;
    padding-bottom: 15px;
    border-bottom: 2px solid #333;
}

h2.source-name {
    font-weight: 900;
    font-style: normal;
    font-size: 1em;
    flex: 1;
}

h2.source-name a {
    text-decoration: none;
    transition: opacity 0.2s ease;
}

h2.source-name a:hover {
    opacity: 0.8;
}

h3.article-title {
    font-weight: 400;
    font-style: normal;
}

.articles {
    max-height: 500px;
    overflow-y: auto;
}

.articles::-webkit-scrollbar {
    width: 6px;
}

.articles::-webkit-scrollbar-track {
    background: #2a2a2a;
    border-radius: 10px;
}

.articles::-webkit-scrollbar-thumb {
    background: #e60012;
    border-radius: 10px;
}

article {
    padding: 15px;
    border-bottom: 1px solid #333;
    transition: background-color 0.2s ease;
    display: flex;
    gap: 15px;
    align-items: flex-start;
}

article:last-child {
    border-bottom: none;
}

article:hover {
    background-color: #252525;
}

.article-image {
    width: 80px;
    height: 80px;
    object-fit: cover;
    border-radius: 8px;
    flex-shrink: 0;
    background: #333;
    /* Prevent layout shifts during image loading */
    display: block;
    contain: layout;
    /* Performance optimizations */
    will-change: auto;
    backface-visibility: hidden;
    -webkit-backface-visibility: hidden;
}

.placeholder-spacer {
    background: transparent;
    border: 1px solid #444;
}

.article-content {
    flex: 1;
    min-width: 0;
}

.article-title {
    margin: 0 0 8px 0;
}

.article-title a {
    font-weight: bold;
    color: #f0f0f0;
    text-decoration: none;
    display: block;
    line-height: 1.4;
}

.article-title a:hover {
    color: #ff4d4d;
}

.article-meta {
    font-size: 0.9em;
    color: #d0d0d0;
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-wrap: wrap;
    gap: 10px;
}

time.article-date {
    font-style: italic;
}

.article-description {
    margin-top: 8px;
    color: #e0e0e0;
    font-size: 0.95em;
    line-height: 1.5;
    display: -webkit-box;
    -webkit-line-clamp: 3;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

.error-message {
    background: #4a2c2c;
    color: #ffc0c0;
    padding: 15px;
    border-radius: 8px;
    margin: 10px 0;
    border-left: 4px solid #ff6b6b;
}

footer {
    text-align: center;
    margin-top: 30px;
    color: #d0d0d0;
    font-style: italic;
    /* Prevent layout shifts */
    min-height: 60px;
    padding: 15px 0;
    contain: layout;
}

footer a {
    color: white;
}

@media (max-width: 768px) {
    main {
        grid-template-columns: 1fr;
    }

    header h1 {
        font-size: 2em;
    }

    section {
        padding: 20px;
    }
}