:root {
    /* Brand colors */
    --brand: #2e7d4f;
    --brand-deep: #205937;
    --brand-rgb: 46, 125, 79;

    /* Surfaces */
    --body-bg: var(--brand);
    --surface: #f8f6ee;
    --surface-elevated: #fff;
    --surface-shadow: rgba(0, 0, 0, 0.08);
    --surface-shadow-strong: rgba(0, 0, 0, 0.18);
    --surface-shadow-hover: rgba(0, 0, 0, 0.25);

    /* Text */
    --text: #222;
    --text-muted: #666;
    --text-faint: #555;
    --text-on-brand: #f8f6ee;

    /* Strokes */
    --border: rgba(0, 0, 0, 0.15);
    --border-soft: rgba(0, 0, 0, 0.1);
    --divider: rgba(0, 0, 0, 0.1);

    /* Banner header */
    --banner-bg: var(--brand-deep);
    --banner-text: var(--text-on-brand);
    --banner-shadow: rgba(0, 0, 0, 0.25);

    /* Interactive states */
    --brand-tint-soft: rgba(var(--brand-rgb), 0.06);
    --brand-tint: rgba(var(--brand-rgb), 0.08);
    --brand-tint-strong: rgba(var(--brand-rgb), 0.15);
    --brand-line: rgba(var(--brand-rgb), 0.2);
    --brand-line-strong: rgba(var(--brand-rgb), 0.3);
    --nav-hover: rgba(255, 255, 255, 0.08);

    /* Status: warning */
    --warning-bg: #fff7e0;
    --warning-text: #8a5a00;
    --warning-stroke: #d4a017;

    /* Geometry */
    --radius-sm: 4px;
    --radius: 6px;
    --radius-lg: 8px;
    --radius-xl: 12px;
    --radius-pill: 999px;
    --transition: 0.15s;

    /* Layout */
    --content-max: 1100px;
    --card-min-col: 220px;
}

@media (prefers-color-scheme: dark) {
    :root:not([data-theme="light"]) {
        --brand: #5ab07c;
        --brand-deep: #7dca96;
        --brand-rgb: 90, 176, 124;

        --body-bg: #0e1a13;
        --surface: #1c2a22;
        --surface-elevated: #263a30;
        --surface-shadow: rgba(0, 0, 0, 0.4);
        --surface-shadow-strong: rgba(0, 0, 0, 0.5);
        --surface-shadow-hover: rgba(0, 0, 0, 0.65);

        --text: #f0e9d6;
        --text-muted: #a8a09a;
        --text-faint: #c0b8b0;
        --text-on-brand: #0e1a13;

        --border: rgba(255, 255, 255, 0.15);
        --border-soft: rgba(255, 255, 255, 0.08);
        --divider: rgba(255, 255, 255, 0.1);

        --banner-bg: #122119;
        --banner-text: #f0e9d6;
        --banner-shadow: rgba(0, 0, 0, 0.5);

        --warning-bg: #3d3322;
        --warning-text: #f0c060;
        --warning-stroke: #d4a017;
    }
}

/* Explicit user choice via the preferences menu — wins over the media query. */
:root[data-theme="dark"] {
    --brand: #5ab07c;
    --brand-deep: #7dca96;
    --brand-rgb: 90, 176, 124;

    --body-bg: #0e1a13;
    --surface: #1c2a22;
    --surface-elevated: #263a30;
    --surface-shadow: rgba(0, 0, 0, 0.4);
    --surface-shadow-strong: rgba(0, 0, 0, 0.5);
    --surface-shadow-hover: rgba(0, 0, 0, 0.65);

    --text: #f0e9d6;
    --text-muted: #a8a09a;
    --text-faint: #c0b8b0;
    --text-on-brand: #0e1a13;

    --border: rgba(255, 255, 255, 0.15);
    --border-soft: rgba(255, 255, 255, 0.08);
    --divider: rgba(255, 255, 255, 0.1);

    --banner-bg: #122119;
    --banner-text: #f0e9d6;
    --banner-shadow: rgba(0, 0, 0, 0.5);

    --warning-bg: #3d3322;
    --warning-text: #f0c060;
    --warning-stroke: #d4a017;
}

@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after {
        transition-duration: 0.01ms !important;
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        scroll-behavior: auto !important;
    }
}

* { box-sizing: border-box; }

body {
    margin: 0;
    font-family: system-ui, sans-serif;
    background: var(--body-bg);
    color: var(--text);
    min-height: 100vh;
}

a { color: var(--brand-deep); }

/* Visually hide an element while keeping it announceable by screen readers. */
.visually-hidden {
    position: absolute;
    width: 1px;
    height: 1px;
    margin: -1px;
    padding: 0;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    border: 0;
    white-space: nowrap;
}

/* Make keyboard focus visible everywhere. */
:focus-visible {
    outline: 2px solid var(--brand);
    outline-offset: 2px;
    border-radius: var(--radius-sm);
}

/* ---------- Preferences menu (top-left of banner) ---------- */
.prefs-menu {
    position: absolute;
    top: 12px;
    left: 12px;
    z-index: 20;
}
.prefs-button {
    width: 40px;
    height: 40px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border: 1px solid rgba(255, 255, 255, 0.15);
    background: rgba(255, 255, 255, 0.08);
    color: var(--banner-text);
    border-radius: var(--radius);
    cursor: pointer;
    transition: background var(--transition);
}
.prefs-button:hover { background: rgba(255, 255, 255, 0.16); }
.prefs-button svg { width: 20px; height: 20px; display: block; }
.prefs-panel {
    position: absolute;
    top: calc(100% + 8px);
    left: 0;
    min-width: 240px;
    padding: 12px;
    background: var(--surface-elevated);
    color: var(--text);
    font-family: system-ui, sans-serif;
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    box-shadow: 0 6px 20px var(--surface-shadow-strong);
    display: flex;
    flex-direction: column;
    gap: 10px;
}
.prefs-panel[hidden] { display: none; }
.prefs-row { display: flex; flex-direction: column; gap: 6px; }
.prefs-row-label {
    font-size: 0.8rem;
    font-weight: 600;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.5px;
}
.prefs-segment {
    display: inline-flex;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    overflow: hidden;
}
.prefs-segment button {
    flex: 1;
    padding: 6px 12px;
    border: none;
    background: var(--surface-elevated);
    color: var(--text);
    font-size: 0.9rem;
    cursor: pointer;
    transition: background var(--transition);
}
.prefs-segment button + button { border-left: 1px solid var(--border); }
.prefs-segment button.active {
    background: var(--brand);
    color: var(--text-on-brand);
}
.prefs-segment button:hover:not(.active) { background: var(--brand-tint); }

/* ---------- Banner + site nav ---------- */
.banner {
    position: relative;
    background: var(--banner-bg);
    color: var(--banner-text);
    text-align: center;
    padding: 32px 16px 16px;
    font-family: "Dancing Script", "Segoe Script", cursive;
    font-weight: 700;
    line-height: 1;
    letter-spacing: 1px;
    text-shadow: 2px 2px 6px var(--banner-shadow);
}
.banner.large { font-size: clamp(3rem, 12vw, 6rem); padding: 80px 16px 40px; }
.banner.small { font-size: clamp(1.75rem, 5vw, 2.5rem); padding: 20px 16px 12px; }
.banner a {
    color: inherit;
    text-decoration: none;
}

.site-nav {
    display: flex;
    justify-content: center;
    gap: 24px;
    padding: 12px 16px 20px;
    background: var(--banner-bg);
    font-size: 1rem;
}
.site-nav a {
    color: var(--banner-text);
    text-decoration: none;
    opacity: 0.8;
    padding: 4px 8px;
    border-radius: var(--radius-sm);
    transition: opacity var(--transition), background var(--transition);
}
.site-nav a:hover { opacity: 1; background: var(--nav-hover); }
.site-nav a.active { opacity: 1; font-weight: 600; }

/* ---------- Page surface ---------- */
.page {
    padding: 24px;
}
.surface {
    background: var(--surface);
    border-radius: var(--radius-lg);
    padding: 32px;
    box-shadow: 0 2px 8px var(--surface-shadow);
    max-width: var(--content-max);
    margin: 0 auto;
}
.surface h1 { margin-top: 0; color: var(--brand-deep); }
.surface h2 { color: var(--brand-deep); }

/* ---------- Home: link cards ---------- */
.home-links {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(var(--card-min-col), 1fr));
    gap: 20px;
    max-width: 720px;
    margin: 40px auto 0;
    padding: 0 24px;
}
.home-link {
    display: block;
    background: var(--surface);
    color: var(--text);
    text-decoration: none;
    padding: 32px 24px;
    border-radius: var(--radius-xl);
    box-shadow: 0 4px 16px var(--surface-shadow-strong);
    text-align: center;
    transition: transform var(--transition), box-shadow var(--transition);
}
.home-link:hover {
    transform: translateY(-2px);
    box-shadow: 0 8px 24px var(--surface-shadow-hover);
}
.home-link-title {
    display: block;
    font-size: 1.5rem;
    font-weight: 600;
    color: var(--brand-deep);
    margin-bottom: 6px;
}
.home-link-desc {
    display: block;
    color: var(--text-muted);
    font-size: 0.95rem;
}

/* ---------- News tabs ---------- */
.tab-nav {
    display: flex;
    gap: 4px;
    border-bottom: 2px solid var(--brand-line);
    margin-bottom: 20px;
    overflow: auto hidden;       /* x: auto, y: hidden — shorthand avoids Firefox quirk */
    scrollbar-width: thin;
}
.tab-nav button {
    flex: 0 0 auto;
    padding: 10px 20px;
    border: none;
    background: transparent;
    color: var(--text-muted);
    font-size: 1rem;
    font-weight: 600;
    cursor: pointer;
    border-bottom: 3px solid transparent;
    margin-bottom: -2px;
    transition: color var(--transition), border-color var(--transition);
}
.tab-nav button:hover { color: var(--brand-deep); }
.tab-nav button.active {
    color: var(--brand-deep);
    border-bottom-color: var(--brand);
}

/* ---------- News: search filter ---------- */
.search-form {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
    gap: 12px;
    align-items: end;
    margin-bottom: 12px;
}
.search-field {
    display: flex;
    flex-direction: column;
    gap: 4px;
    font-size: 0.85rem;
    color: var(--text-faint);
}
.search-field-keyword { grid-column: 1 / -1; }
.date-input {
    position: relative;
    display: block;
}
.date-input input[type="text"] {
    width: 100%;
    padding-right: 38px;
}
.date-picker-btn {
    position: absolute;
    right: 2px;
    top: 50%;
    transform: translateY(-50%);
    width: 34px;
    height: 34px;
    padding: 0;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    background: transparent;
    color: var(--text-muted);
    border: none;
    border-radius: var(--radius);
    cursor: pointer;
    transition: background var(--transition), color var(--transition);
}
.date-picker-btn:hover { background: var(--brand-tint); color: var(--brand-deep); }
.date-picker-btn svg { width: 18px; height: 18px; display: block; }
.date-picker-hidden {
    position: absolute;
    left: 0;
    bottom: 0;
    width: 0;
    height: 0;
    opacity: 0;
    pointer-events: none;
    border: 0;
    padding: 0;
}
.search-field input,
.search-field select {
    padding: 9px 12px;
    font-size: 0.95rem;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: var(--surface-elevated);
    color: var(--text);
    transition: border-color var(--transition), box-shadow var(--transition);
}
.search-field input:focus,
.search-field select:focus {
    outline: none;
    border-color: var(--brand);
    box-shadow: 0 0 0 3px var(--brand-tint-strong);
}
.search-reset {
    padding: 9px 16px;
    border: 1px solid var(--border);
    background: var(--surface-elevated);
    color: var(--text);
    font-size: 0.9rem;
    border-radius: var(--radius);
    cursor: pointer;
    height: fit-content;
    transition: background var(--transition);
}
.search-reset:hover { background: var(--brand-tint); }

.quick-filters {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin-bottom: 16px;
}
.quick-filters button {
    padding: 5px 12px;
    border: 1px solid var(--brand-line-strong);
    background: var(--surface-elevated);
    color: var(--brand-deep);
    font-size: 0.85rem;
    border-radius: var(--radius-pill);
    cursor: pointer;
    transition: background var(--transition), border-color var(--transition);
}
.quick-filters button:hover { background: var(--brand-tint); }
.quick-filters button.active {
    background: var(--brand);
    color: var(--text-on-brand);
    border-color: var(--brand);
}
.quick-filters .search-all {
    margin-left: auto;
    background: var(--surface-elevated);
    border-color: var(--border);
    color: var(--text-faint);
}
.quick-filters .search-all:disabled {
    opacity: 0.6;
    cursor: not-allowed;
}

/* Status + CVE chips on article cards */
.article-card-title-wrap {
    flex: 1;
    min-width: 0;
    display: flex;
    flex-direction: column;
    gap: 4px;
}
.article-card-subtitle {
    color: var(--text-muted);
    font-size: 0.85rem;
    font-weight: 400;
    line-height: 1.35;
}
.status-badge {
    font-size: 0.7rem;
    font-weight: 700;
    padding: 2px 7px;
    border-radius: var(--radius-sm);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: #fff;
}
.status-itw  { background: #b91c1c; }   /* in the wild */
.status-poc  { background: #c2410c; }   /* proof of concept */
.status-none { background: #6b7280; }
.status-na   { background: #4b5563; }
.status-unknown { background: #9ca3af; }
.cve-badge {
    background: var(--brand-tint-strong);
    color: var(--brand-deep);
    font-size: 0.7rem;
    font-weight: 600;
    padding: 2px 7px;
    border-radius: var(--radius-sm);
    font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
}
.cve-badge.cve-more { background: transparent; color: var(--text-muted); }

.search-summary {
    color: var(--text-muted);
    font-size: 0.85rem;
    margin-bottom: 12px;
}

/* ---------- News: view toggle ---------- */
.toolbar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 12px;
    margin-bottom: 16px;
}
.view-toggle {
    display: inline-flex;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    overflow: hidden;
}
.view-toggle button {
    padding: 6px 16px;
    border: none;
    background: var(--surface-elevated);
    color: var(--text);
    font-size: 0.9rem;
    cursor: pointer;
    transition: background var(--transition);
}
.view-toggle button + button { border-left: 1px solid var(--border); }
.view-toggle button.active {
    background: var(--brand);
    color: var(--text-on-brand);
}
.view-toggle button:hover:not(.active) { background: var(--brand-tint); }

.news-meta {
    color: var(--text-muted);
    font-size: 0.9rem;
}

.news-warning {
    color: var(--warning-text);
    font-size: 0.9rem;
    margin-bottom: 16px;
    padding: 8px 12px;
    background: var(--warning-bg);
    border-left: 3px solid var(--warning-stroke);
    border-radius: var(--radius-sm);
}
.news-warning details summary { cursor: pointer; }
.news-warning ul { margin: 8px 0 0 0; padding-left: 20px; }
.news-warning code { font-size: 0.85em; }

/* ---------- Article cards ---------- */
.article-list {
    display: flex;
    flex-direction: column;
    gap: 12px;
}
.article-list[data-view="card"] {
    display: grid;
    grid-template-columns: repeat(
        auto-fit,
        minmax(max(var(--card-min-col), calc((100% - 24px) / 3)), 1fr)
    );
    gap: 12px;
}
.article-list[data-view="card"] .article-card-header {
    flex-direction: column;
    align-items: flex-start;
    gap: 8px;
}
.article-list[data-view="card"] .article-card[open] {
    grid-column: 1 / -1;
}

.article-card {
    border: 1px solid var(--border-soft);
    border-radius: var(--radius-lg);
    background: var(--surface-elevated);
    overflow: hidden;
}
.article-card > summary {
    list-style: none;
    cursor: pointer;
}
.article-card > summary::-webkit-details-marker { display: none; }
.article-card[open] > summary { background: var(--brand-tint); }
.article-card-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 12px;
    padding: 14px 16px;
    user-select: none;
    transition: background var(--transition);
}
.article-card-header:hover { background: var(--brand-tint-soft); }
.article-card-title {
    margin: 0;
    font-size: 1rem;
    font-weight: 600;
    color: var(--text);
    flex: 1;
    min-width: 0;
}
.article-card-meta {
    display: flex;
    gap: 8px;
    align-items: center;
    flex-shrink: 0;
    flex-wrap: wrap;
}
.source-badge {
    background: var(--brand);
    color: var(--text-on-brand);
    font-size: 0.75rem;
    font-weight: 600;
    padding: 3px 8px;
    border-radius: var(--radius-sm);
    text-transform: uppercase;
    letter-spacing: 0.5px;
}
.news-type-badge {
    background: var(--brand-tint-strong);
    color: var(--brand-deep);
    font-size: 0.7rem;
    font-weight: 600;
    padding: 2px 7px;
    border-radius: var(--radius-sm);
    text-transform: uppercase;
    letter-spacing: 0.5px;
}
.article-date {
    color: var(--text-muted);
    font-size: 0.85rem;
}
.article-card-body {
    border-top: 1px solid var(--divider);
}
.article-card-body iframe {
    width: 100%;
    height: 80vh;
    border: 0;
    display: block;
}
.pdf-fallback {
    padding: 16px;
    font-size: 0.9rem;
}
.empty-state {
    color: var(--text-muted);
    font-style: italic;
    padding: 16px 0;
}

/* ---------- Tools placeholder ---------- */
.placeholder-block {
    text-align: center;
    padding: 60px 20px;
    color: var(--text-muted);
}
.placeholder-block h2 { margin-top: 0; }

/* ---------- Responsive ---------- */
@media (max-width: 640px) {
    .page { padding: 12px; }
    .surface { padding: 20px; }
    .home-links { padding: 0 12px; gap: 12px; }
    .home-link { padding: 24px 16px; }
    .article-card-header {
        flex-direction: column;
        align-items: flex-start;
        gap: 8px;
    }
    .toolbar { flex-direction: column; align-items: stretch; }
    .article-card-body iframe { height: 70vh; }
}
