@import url('https://fonts.googleapis.com/css2?family=Playfair+Display:ital,wght@0,700;0,900;1,700&display=swap');

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

:root {
    --bg-color: #f4f1ea;
    --container-bg: #fff;
    --text-color: #111;
    --secondary-text: #444;
    --border-color: #000;
    --side-border: #999;
    --sep-border: #bbb;
    font-size: 15px;
}

body.dark-mode {
    --bg-color: #121212;
    --container-bg: #1e1e1e;
    --text-color: #e4e4e4;
    --secondary-text: #a0a0a0;
    --border-color: #e4e4e4;
    --side-border: #444;
    --sep-border: #333;
    --header-bg: #2a2a2a; /* Higher contrast background for headers */
}

body {
    --header-bg: #f9f9f9; /* Light mode default */
    background-color: var(--bg-color);
    font-family: 'Times New Roman', Times, serif;
    color: var(--text-color);
    transition: background-color 0.3s, color 0.3s;
    overflow-x: hidden;
    line-height: 1.25;
    background-image: url("data:image/svg+xml,%3Csvg viewBox='0 0 200 200' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='noiseFilter'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.65' numOctaves='3' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23noiseFilter)' opacity='0.05'/%3E%3C/svg%3E");
}

.container {
    max-width: 1400px;
    width: 98%;
    margin: 5px auto;
    border: 1px solid var(--border-color);
    padding: 15px;
    background: var(--container-bg);
    box-shadow: 0 0 20px rgba(0,0,0,0.1);
    position: relative;
}

/* HEADER RESPONSIVENESS */
header {
    border-bottom: 4px double var(--border-color);
    margin-bottom: 1rem;
}

.masthead-container {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 10px;
    flex-wrap: wrap; /* Allow stacking on mobile */
}

.masthead {
    flex: 1;
    text-align: center;
    min-width: 300px; /* Force title to center or stack */
}

.masthead h1 {
    font-size: clamp(2.5rem, 8vw, 6.5rem);
    font-family: 'Playfair Display', serif;
    font-weight: 900;
    letter-spacing: -2px;
    line-height: 0.85;
    margin: 0;
    padding: 10px 0;
}

.ear {
    flex: 0 0 220px;
    font-size: 0.7rem;
    text-transform: uppercase;
    font-weight: bold;
    line-height: 1.2;
}

.ear-left { text-align: left; }
.ear-right { text-align: right; }

.folio {
    display: flex;
    justify-content: space-between;
    border-top: 1px solid var(--border-color);
    border-bottom: 1px solid var(--border-color);
    padding: 3px 8px;
    margin-top: 0.2rem;
    font-weight: bold;
    font-size: 0.7rem;
    text-transform: uppercase;
    flex-wrap: wrap;
    gap: 5px;
}

/* EXTRAS RESPONSIVENESS */
.front-page-extras {
    display: grid;
    grid-template-columns: 1fr 2fr;
    gap: 30px;
    margin-bottom: 20px;
    padding-bottom: 15px;
    border-bottom: 1px solid var(--border-color);
    align-items: start;
}

.extra-header {
    font-family: 'Playfair Display', serif;
    font-weight: 900;
    font-size: 0.7rem;
    text-transform: uppercase;
    letter-spacing: 1px;
    border-bottom: 1px solid var(--border-color);
    margin-bottom: 8px;
    padding-bottom: 2px;
}

.market-glance-box { padding: 0; }
.market-items { display: flex; flex-direction: column; gap: 4px; }
.market-item { display: flex; justify-content: space-between; font-family: 'Courier New', monospace; font-size: 0.85rem; font-weight: 900; }
.m-name { flex: 0 0 80px; }
.m-value { flex: 1; text-align: right; padding-right: 20px; }
.m-change { flex: 0 0 80px; text-align: right; }

.on-this-day-box h3 { font-size: 1.1rem; margin-bottom: 3px; }
.on-this-day-box p { font-size: 0.9rem; line-height: 1.3; }

/* SECTIONS & COLLAPSIBLE */
.section-header {
    border-top: 1px solid var(--border-color);
    border-bottom: 1px solid var(--border-color);
    padding: 8px 15px;
    margin: 10px 0 0 0;
    text-align: left;
    background: var(--header-bg);
    cursor: pointer;
    display: flex;
    justify-content: space-between;
    align-items: center;
    transition: background 0.2s;
}

.section-header:hover {
    filter: brightness(1.1); /* Works for both light and dark */
}

.section-header h2 {
    margin: 0;
    font-size: 1rem;
    text-transform: uppercase;
    font-family: 'Playfair Display', serif;
    letter-spacing: 2px;
    flex: 1;
}

.section-header .article-count {
    font-size: 0.7rem;
    font-weight: bold;
    font-style: italic;
    color: var(--secondary-text);
    margin-right: 10px;
}

.section-header::after { content: '\25BC'; font-size: 0.7rem; transition: transform 0.3s; }
.topic-section.collapsed .section-header::after { transform: rotate(-90deg); }
.topic-section.collapsed .topic-content { display: none; }
.topic-content { padding-top: 20px; }

/* NEWS GRID - MOBILE FRIENDLY */
.topic-stories-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)); /* Automatically wrap based on width */
    gap: 30px;
    margin-bottom: 30px;
}

.news-item-block {
    display: flex;
    flex-direction: column;
    padding-bottom: 20px;
}

/* Vertical rules only on desktop */
@media (min-width: 901px) {
    .news-item-block:not(:last-child) {
        border-right: 1px solid var(--sep-border);
        padding-right: 25px;
    }
}

/* Horizontal rules on mobile */
@media (max-width: 900px) {
    .news-item-block:not(:last-child) {
        border-bottom: 1px solid var(--sep-border);
        margin-bottom: 20px;
    }
    .front-page-extras {
        grid-template-columns: 1fr;
        gap: 20px;
    }
    .masthead-container {
        flex-direction: column;
        gap: 15px;
    }
    .ear { flex: none; width: 100%; text-align: center; }
    .masthead { order: -1; } /* Title first on mobile */
    .folio { justify-content: center; text-align: center; }
}

.news-item-block h3 { font-family: 'Playfair Display', serif; font-size: 1.45rem; line-height: 1.1; margin-bottom: 5px; font-weight: 900; }
.news-item-block h4 { font-size: 0.95rem; font-style: italic; font-weight: normal; color: var(--secondary-text); margin-bottom: 10px; border-bottom: 1px solid #eee; padding-bottom: 5px; }
.news-item-block p { font-size: 1rem; line-height: 1.4; text-align: justify; margin-bottom: 10px; }
.news-item-block a { color: #d32f2f; text-transform: uppercase; font-weight: 900; font-size: 0.75rem; text-decoration: none; letter-spacing: 0.5px; margin-top: auto; padding-top: 5px; border-top: 1px dotted var(--sep-border); }

/* SETTINGS */
.menu-trigger {
    position: absolute;
    top: 15px;
    right: 15px;
    background: none;
    border: none;
    cursor: pointer;
    color: var(--text-color);
    font-size: 1.5rem;
    line-height: 1;
    z-index: 10;
    opacity: 0.6;
    transition: opacity 0.2s;
}

.menu-trigger:hover {
    opacity: 1;
}
.drawer {
    position: fixed;
    top: 0;
    right: -100%;
    width: 100%;
    max-width: 320px;
    height: 100%;
    background: var(--container-bg);
    border-left: 1px solid var(--border-color);
    z-index: 1000;
    transition: right 0.4s ease;
    padding: 40px 30px; /* Increased top padding for the X */
    box-shadow: -5px 0 15px rgba(0,0,0,0.1);
}

#close-menu {
    position: absolute;
    top: 15px;
    right: 15px;
    background: none;
    border: none;
    font-size: 2rem;
    cursor: pointer;
    color: var(--text-color);
    line-height: 1;
    opacity: 0.6;
    transition: opacity 0.2s;
}

#close-menu:hover {
    opacity: 1;
}
.drawer.open { right: 0; }
.drawer button:not(#close-menu) { background: none; border: 1px solid var(--border-color); color: var(--text-color); padding: 12px; font-size: 0.9rem; cursor: pointer; text-transform: uppercase; font-weight: bold; width: 100%; margin-bottom: 10px; }
.drawer button.active { background: var(--text-color); color: var(--container-bg); }
.theme-controls, .font-controls { display: flex; gap: 10px; width: 100%; }
.theme-controls button, .font-controls button { flex: 1; }
.overlay { position: fixed; top: 0; left: 0; width: 100%; height: 100%; background: rgba(0,0,0,0.2); display: none; z-index: 999; }
.overlay.active { display: block; }

footer { text-align: center; margin-top: 20px; padding: 15px 0; border-top: 4px double var(--border-color); font-size: 0.7rem; font-weight: bold; text-transform: uppercase; }
