:root {
    /* Light Mode - High Contrast Warm Paper */
    --bg-body: #fefcf7;  /* Very light warm cream */
    --bg-surface: #ffffff;  /* Pure white for cards */
    --bg-surface-2: #f5f1ea;  /* Light warm grey */
    --text-main: #1a1512;  /* Almost black warm brown */
    --text-muted: #4a3f36;  /* Darker warm brown */
    --accent-color: #c2410c;  /* Deep orange (colorblind safe) */
    --border-color: #d6cfc4;  /* Warm border */
    --shadow-sm: 0 1px 2px rgba(45, 37, 32, 0.15);
    --shadow-md: 0 4px 6px -1px rgba(45, 37, 32, 0.2), 0 2px 4px -1px rgba(45, 37, 32, 0.1);

    /* Category Colors - Colorblind Safe */
    --color-human: #0369a1;  /* Blue instead of green */
    --color-ai: #7c3aed;  /* Purple */
    --color-mixed-edit: #c2410c;  /* Orange */
    --color-mixed-research: #0891b2;  /* Cyan */

    /* Spacing */
    --spacing-xs: 0.5rem;
    --spacing-sm: 1rem;
    --spacing-md: 1.5rem;
    --spacing-lg: 2rem;
    --spacing-xl: 3rem;
}

[data-theme="dark"] {
    /* Dark Mode - High Contrast */
    --bg-body: #1c1917;  /* Very dark warm stone */
    --bg-surface: #292524;  /* Dark warm stone */
    --bg-surface-2: #3c3835;  /* Medium warm stone */
    --text-main: #ffffff;  /* Pure white */
    --text-muted: #d6d3d1;  /* Light warm grey */
    --accent-color: #fb923c;  /* Bright orange */
    --border-color: #44403c;  /* Dark warm border */
    --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.4);
    --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.6);
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

body {
    font-family: 'Open Sans', sans-serif;
    background-color: var(--bg-body);
    color: var(--text-main);
    transition: background-color 0.3s ease, color 0.3s ease;
    overflow-x: hidden;
    padding-top: 120px;
}

/* Language Specific Fonts */
body[data-lang="SI"] .news-grid,
body[data-lang="SI"] .article-overlay {
    font-family: 'Noto Sans Sinhala', sans-serif;
}

body[data-lang="TA"] .news-grid,
body[data-lang="TA"] .article-overlay {
    font-family: 'Noto Sans Tamil', sans-serif;
}

/* Ensure masthead always uses English fonts */
.masthead * {
    font-family: 'Lora', serif !important;
}

/* Typography override for Brand */
h1, h2, h3 {
    font-family: 'Lora', serif;
}

/* Masthead */
.masthead {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: var(--spacing-sm) var(--spacing-lg);
    background-color: var(--bg-surface);
    border-bottom: 1px solid var(--border-color);
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    z-index: 1000;
    box-shadow: var(--shadow-sm);
}

.logo-section {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
}

.logo {
    font-size: 2.8rem;
    font-weight: 700;
    letter-spacing: -0.02em;
    color: var(--text-main);
    font-family: 'Playfair Display', serif;
    text-decoration: none;
    margin-bottom: 0.25rem;
}

.strapline {
    font-size: 0.75rem;
    color: var(--text-muted);
    font-family: 'Open Sans', sans-serif;
    font-style: italic;
    margin: 0;
    display: none;
}

/* Show appropriate strapline based on language */
body[data-lang="EN"] .strapline[data-lang="en"],
body[data-lang="SI"] .strapline[data-lang="si"],
body[data-lang="TA"] .strapline[data-lang="ta"] {
    display: block;
}

/* Default to English if no language set */
body:not([data-lang]) .strapline[data-lang="en"] {
    display: block;
}

.controls {
    display: flex;
    align-items: center;
    gap: var(--spacing-sm);
}

/* Language Switcher */
.language-switcher {
    display: flex;
    align-items: center;
    gap: 4px;
    background: var(--bg-surface-2);
    padding: 2px;
    border-radius: 6px;
}

.lang-btn {
    background: none;
    border: none;
    padding: 4px 8px;
    font-size: 0.75rem;
    font-weight: 600;
    color: var(--text-muted);
    border-radius: 4px;
    cursor: pointer;
    transition: all 0.2s;
    font-family: 'Open Sans', sans-serif;
}

.lang-btn:hover {
    color: var(--text-main);
}

.lang-btn.active {
    background-color: var(--bg-surface);
    color: var(--text-main);
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.1);
}

.icon-btn {
    background: none;
    border: none;
    color: var(--text-main);
    font-size: 1.5rem;
    cursor: pointer;
    padding: 0.2rem;
    border-radius: 50%;
    transition: background 0.2s;
    display: flex;
    align-items: center;
    justify-content: center;
}

.icon-btn:hover {
    background: var(--bg-surface-2);
}

/* News Grid */
.news-grid {
    display: flex;
    flex-direction: column;
    gap: var(--spacing-md);
    padding: var(--spacing-lg);
    height: calc(100vh - 100px);
    overflow-y: auto;
    scroll-snap-type: y mandatory;
    scroll-behavior: smooth;
    overscroll-behavior: contain;
}

.grid-row {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: var(--spacing-md);
    scroll-snap-align: start;
    scroll-snap-stop: always;
}

.news-grid::-webkit-scrollbar {
    display: none;
}

.news-grid {
    -ms-overflow-style: none;
    scrollbar-width: none;
}

/* Article Tile Styles */
.article-tile {
    background: var(--bg-surface);
    border-radius: 12px;
    border: 1px solid;
    overflow: hidden;
    transition: transform 0.2s ease, box-shadow 0.2s ease, opacity 0.3s ease;
    display: flex;
    flex-direction: column;
    aspect-ratio: 16/9;
    position: relative;
    opacity: 0;
    padding: var(--spacing-sm);
}

.article-tile.fade-in {
    opacity: 1;
}

[data-theme="dark"] .article-tile {
    border-color: white;
}

[data-theme="light"] .article-tile {
    border-color: black;
}

.article-tile[data-type="0"] {
    box-shadow: 0 0 8px rgba(139, 92, 246, 0.3);
}

.article-tile[data-type="1"] {
    box-shadow: 0 0 8px rgba(251, 146, 60, 0.3);
}

.article-tile[data-type="2"] {
    box-shadow: 0 0 8px rgba(34, 197, 194, 0.3);
}

.article-tile[data-type="3"] {
    box-shadow: 0 0 8px rgba(52, 168, 83, 0.3);
}

.article-tile[data-type="0"]:hover {
    box-shadow: 0 0 16px rgba(139, 92, 246, 0.5);
}

.article-tile[data-type="1"]:hover {
    box-shadow: 0 0 16px rgba(251, 146, 60, 0.5);
}

.article-tile[data-type="2"]:hover {
    box-shadow: 0 0 16px rgba(34, 197, 194, 0.5);
}

.article-tile[data-type="3"]:hover {
    box-shadow: 0 0 16px rgba(52, 168, 83, 0.5);
}

.article-tile.clickable {
    cursor: pointer;
}

.article-tile.non-clickable {
    opacity: 0.6;
    cursor: default;
}

.type-icon {
    font-size: clamp(12px, 1.5vw, 16px);
    color: var(--text-muted);
    cursor: help;
}

.type-icon.type-0 {
    color: var(--color-ai);
}

.type-icon.type-1 {
    color: var(--color-mixed-edit);
}

.type-icon.type-2 {
    color: var(--color-mixed-research);
}

.type-icon.type-3 {
    color: var(--color-human);
}

.tile-content {
    padding: 0;
    display: grid;
    grid-template-columns: 1fr auto;
    gap: var(--spacing-xs);
    flex-grow: 1;
}

.tile-text {
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    min-height: 0;
}

.tile-excerpt {
    font-size: clamp(0.6rem, 1.8vw, 0.85rem);
    color: var(--text-muted);
    line-height: 1.3;
    margin: 0;
    padding-left: 1rem;
    overflow: hidden;
    display: -webkit-box;
    -webkit-line-clamp: 5;
    -webkit-box-orient: vertical;
}

/* Responsive bullet point reduction */
@media (max-width: 999.98px) {
    .tile-excerpt {
        -webkit-line-clamp: 4;
    }
}

@media (max-width: 699.98px) {
    .tile-excerpt {
        -webkit-line-clamp: 3;
    }
}

.tile-excerpt li {
    margin-bottom: 0.5rem;
}

.tile-title {
    font-size: clamp(0.8rem, 2.5vw, 1.2rem);
    font-weight: 700;
    line-height: 1.4;
    font-family: inherit;
    color: var(--text-main);
    margin: 0;
}

.tile-attributes {
    display: flex;
    flex-direction: column;
    justify-content: flex-start;
    align-items: center;
    width: 20px;
    padding-top: 2px;
}

/* Responsive Grid */
@media (min-width: 1920px) {
    .grid-row {
        grid-template-columns: repeat(5, 1fr);
    }
}

@media (min-width: 1400px) and (max-width: 1919.98px) {
    .grid-row {
        grid-template-columns: repeat(4, 1fr);
    }
}

@media (min-width: 1000px) and (max-width: 1399.98px) {
    .grid-row {
        grid-template-columns: repeat(3, 1fr);
    }
}

@media (min-width: 700px) and (max-width: 999.98px) {
    .grid-row {
        grid-template-columns: repeat(2, 1fr);
    }
}

@media (max-width: 699.98px) {
    .grid-row {
        grid-template-columns: 1fr;
    }
}

/* Article Overlay */
.article-overlay {
    position: fixed;
    top: 120px;
    left: 0;
    width: 100%;
    height: calc(100vh - 120px);
    background-color: var(--bg-body);
    z-index: 1500;
    overflow-y: auto;
    overflow-x: hidden;
    transform: translateY(100%);
    transition: transform 0.3s ease-in-out;
    scrollbar-width: thin;
    scrollbar-color: var(--border-color) transparent;
}

.article-overlay::-webkit-scrollbar {
    width: 6px;
}

.article-overlay::-webkit-scrollbar-track {
    background: transparent;
}

.article-overlay::-webkit-scrollbar-thumb {
    background: var(--border-color);
    border-radius: 3px;
}

.article-overlay::-webkit-scrollbar-thumb:hover {
    background: var(--text-muted);
}

.article-overlay:not(.hidden) {
    transform: translateY(0);
}

.overlay-content {
    max-width: 920px;
    margin: 0 auto;
    padding: var(--spacing-xl) var(--spacing-lg);
    min-height: 100%;
}

.overlay-controls {
    position: fixed !important;
    top: 60px !important;
    right: calc(var(--spacing-lg) + 120px) !important;
    z-index: 1001 !important;
    display: flex;
    flex-direction: row;
    gap: 8px;
    background: var(--bg-surface);
    padding: 8px;
    border-radius: 24px;
    box-shadow: var(--shadow-md);
    pointer-events: auto;
}

.close-btn, .nav-btn {
    background: transparent;
    border-radius: 50%;
    width: 36px;
    height: 36px;
    color: var(--text-main);
}

.nav-btn {
    opacity: 0.7;
    transition: opacity 0.2s;
}

.nav-btn:hover, .close-btn:hover {
    opacity: 1;
    background: var(--bg-surface-2);
}

.article-title {
    font-size: 2.2rem;
    font-family: inherit;
    margin-bottom: var(--spacing-md);
    line-height: 1.2;
}

.article-meta {
    font-size: 0.9rem;
    color: var(--text-muted);
    margin-bottom: var(--spacing-lg);
}

.article-body {
    font-size: 1.1rem;
    line-height: 1.8;
    color: var(--text-main);
    font-family: inherit;
}

.article-body p {
    margin-bottom: var(--spacing-md);
    text-align: left;
}



.pullquote {
    font-style: italic;
    font-size: 1.2rem;
    color: var(--text-muted);
    margin: var(--spacing-lg) 0;
    padding: var(--spacing-md);
    border-left: 4px solid var(--accent-color);
    background: var(--bg-surface-2);
    position: relative;
}

.article-content {
    margin-bottom: var(--spacing-xl);
}

.article-divider {
    height: 1px;
    background: var(--border-color);
    margin: var(--spacing-xl) 0;
}



/* Mobile Overlay Adjustments */
@media (max-width: 768px) {
    .masthead {
        padding: var(--spacing-xs) var(--spacing-md);
        flex-direction: column;
        align-items: center;
        text-align: center;
    }
    
    .logo-section {
        align-items: center;
        margin-bottom: var(--spacing-sm);
    }
    
    .controls {
        width: 100%;
        justify-content: center;
    }
    
    .logo {
        font-size: 1.5rem;
    }
    
    .strapline {
        font-size: 0.65rem;
    }
    
    .language-switcher {
        gap: 2px;
    }
    
    .lang-btn {
        padding: 3px 6px;
        font-size: 0.7rem;
    }
    
    .article-title {
        font-size: 2rem;
    }
    
    .overlay-content {
        padding: var(--spacing-lg) var(--spacing-md);
    }
    
    .close-btn {
        right: var(--spacing-sm);
    }
}
/* Article page styling */
.article-page {
    min-height: calc(100vh - 120px);
    padding-bottom: 2rem;
    display: flex;
    flex-direction: column;
    justify-content: flex-start;
}
/* Article separator styling */
.article-separator {
    width: 40%;
    height: 1px;
    background: rgba(255, 255, 255, 0.3);
    margin: 3rem auto;
    border: none;
}
/* Article controls in masthead */
.article-controls {
    display: flex;
    gap: 0.5rem;
    margin-top: 0.5rem;
}

.article-controls .icon-btn {
    padding: 0.5rem;
    font-size: 1rem;
}
/* Mobile grid spacing fix */
@media (max-width: 700px) {
    .news-grid {
        padding-top: 1rem;
    }
}
/* Mobile text size improvements */
@media (max-width: 700px) {
    .tile-title {
        font-size: 1.1rem;
    }
    
    .tile-excerpt {
        font-size: 0.95rem;
    }
}
/* Translucent close button */
.close-overlay-btn {
    position: fixed;
    top: 140px;
    right: 1rem;
    width: 3rem;
    height: 3rem;
    background: rgba(0, 0, 0, 0.5);
    border: none;
    border-radius: 50%;
    color: white;
    font-size: 1.5rem;
    cursor: pointer;
    z-index: 1600;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.2s;
}

.close-overlay-btn:hover {
    background: rgba(0, 0, 0, 0.7);
}
/* Close button visibility and animation */
#close-overlay {
    opacity: 0.1;
    transition: opacity 0.3s ease;
}

#close-overlay.show-close {
    opacity: 1;
    animation: pulseAttention 2s ease-in-out 3;
}

@keyframes pulseAttention {
    0%, 100% { transform: scale(1); }
    50% { transform: scale(1.2); }
}