/* CSS Variables */
:root {
    --color-dem: #0015BC;
    --color-dem-light: #5580E0;
    --color-dem-lighter: #A8C8F0;
    --color-dem-guaranteed: #000D7A;
    --color-rep: #BC0000;
    --color-rep-light: #E05555;
    --color-rep-lighter: #F0A8A8;
    --color-rep-guaranteed: #7A0000;
    --color-tossup: #888888;

    --color-bg: #0a0a0a;
    --color-bg-alt: #111111;
    --color-surface: #1a1a1a;
    --color-border: #2a2a2a;
    --color-text: #ffffff;
    --color-text-muted: #888888;
    --color-accent: #3b82f6;

    --font-sans: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
    --font-mono: 'JetBrains Mono', monospace;

    --radius: 8px;
    --radius-lg: 12px;
}

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

/* Base */
html {
    scroll-behavior: smooth;
}

body {
    font-family: var(--font-sans);
    background: var(--color-bg);
    color: var(--color-text);
    line-height: 1.6;
    -webkit-font-smoothing: antialiased;
}

a {
    color: var(--color-accent);
    text-decoration: none;
}

a:hover {
    text-decoration: underline;
}

/* Container */
.container {
    max-width: 1200px;
    margin: 0 auto;
    padding: 0 24px;
}

/* Header */
.header {
    position: sticky;
    top: 0;
    background: rgba(10, 10, 10, 0.95);
    backdrop-filter: blur(10px);
    border-bottom: 1px solid var(--color-border);
    z-index: 100;
}

.header .container {
    position: relative;
}

.header-content {
    display: flex;
    justify-content: space-between;
    align-items: center;
    height: 64px;
}

.logo {
    font-weight: 600;
    font-size: 1.1rem;
    color: var(--color-text);
}

.nav {
    display: flex;
    gap: 32px;
}

.nav a {
    color: var(--color-text-muted);
    font-size: 0.9rem;
    transition: color 0.2s;
}

.nav a:hover {
    color: var(--color-text);
    text-decoration: none;
}

/* Mobile Menu */
.mobile-menu-btn {
    display: none;
    flex-direction: column;
    justify-content: center;
    gap: 5px;
    background: none;
    border: none;
    cursor: pointer;
    padding: 8px;
}

.mobile-menu-btn span {
    display: block;
    width: 24px;
    height: 2px;
    background: var(--color-text);
    transition: all 0.3s ease;
}

.mobile-menu-btn.active span:nth-child(1) {
    transform: rotate(45deg) translate(5px, 5px);
}

.mobile-menu-btn.active span:nth-child(2) {
    opacity: 0;
}

.mobile-menu-btn.active span:nth-child(3) {
    transform: rotate(-45deg) translate(5px, -5px);
}

.mobile-nav {
    display: none;
    position: absolute;
    top: 100%;
    left: 0;
    right: 0;
    background: var(--color-bg);
    border-bottom: 1px solid var(--color-border);
    padding: 16px;
}

.mobile-nav.active {
    display: block;
}

.mobile-nav a {
    display: block;
    padding: 12px 16px;
    color: var(--color-text-muted);
    font-size: 1rem;
    border-radius: var(--radius);
}

.mobile-nav a:hover {
    background: var(--color-surface);
    color: var(--color-text);
    text-decoration: none;
}

@media (max-width: 768px) {
    .mobile-menu-btn {
        display: flex;
    }
}

/* Hero Section */
.hero {
    padding: 60px 0 80px;
}

.hero-header {
    text-align: center;
    margin-bottom: 48px;
}

.hero-header h1 {
    font-size: 2.5rem;
    font-weight: 700;
    margin-bottom: 8px;
}

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

/* Stats Grid */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 24px;
    margin-bottom: 48px;
}

.stat-card {
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-lg);
    padding: 32px;
    text-align: center;
}

.stat-card.primary {
    background: linear-gradient(135deg, var(--color-dem) 0%, #001299 100%);
    border-color: var(--color-dem);
}

.stat-value {
    font-size: 3.5rem;
    font-weight: 700;
    font-family: var(--font-mono);
    line-height: 1;
    margin-bottom: 8px;
}

.stat-label {
    font-size: 1rem;
    font-weight: 500;
}

.stat-sublabel {
    font-size: 0.8rem;
    color: var(--color-text-muted);
    margin-top: 4px;
}

.stat-card.primary .stat-sublabel {
    color: rgba(255, 255, 255, 0.7);
}

/* Categories Bar */
.categories-section {
    margin-bottom: 48px;
}

.categories-section h3 {
    font-size: 1rem;
    font-weight: 500;
    margin-bottom: 16px;
    color: var(--color-text-muted);
}

.categories-bar {
    display: flex;
    height: 48px;
    border-radius: var(--radius);
    overflow: hidden;
    background: var(--color-surface);
}

.cat-segment {
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.75rem;
    font-weight: 600;
    color: white;
    transition: flex-basis 0.3s ease;
}

.cat-segment.guaranteed-d { background: #333; }
.cat-segment.safe-d { background: var(--color-dem); }
.cat-segment.likely-d { background: var(--color-dem-light); }
.cat-segment.lean-d { background: var(--color-dem-lighter); color: #333; }
.cat-segment.tossup { background: var(--color-tossup); }
.cat-segment.lean-r { background: var(--color-rep-lighter); color: #333; }
.cat-segment.likely-r { background: var(--color-rep-light); }
.cat-segment.safe-r { background: var(--color-rep); }
.cat-segment.guaranteed-r { background: #333; }

.categories-legend {
    display: flex;
    justify-content: center;
    gap: 16px;
    margin-top: 12px;
    flex-wrap: wrap;
}

.legend-item {
    font-size: 0.75rem;
    color: var(--color-text-muted);
    display: flex;
    align-items: center;
    gap: 6px;
}

.legend-item::before {
    content: '';
    width: 12px;
    height: 12px;
    border-radius: 2px;
}

.legend-item.guaranteed-d::before { background: #333; }
.legend-item.safe-d::before { background: var(--color-dem); }
.legend-item.likely-d::before { background: var(--color-dem-light); }
.legend-item.lean-d::before { background: var(--color-dem-lighter); }
.legend-item.tossup::before { background: var(--color-tossup); }
.legend-item.lean-r::before { background: var(--color-rep-lighter); }
.legend-item.likely-r::before { background: var(--color-rep-light); }
.legend-item.safe-r::before { background: var(--color-rep); }
.legend-item.guaranteed-r::before { background: #333; }
.legend-item.not-up::before { background: #444; }

/* Environment Section */
.environment-section h3 {
    font-size: 1rem;
    font-weight: 500;
    margin-bottom: 16px;
    color: var(--color-text-muted);
}

.environment-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 16px;
}

.env-item {
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
    padding: 20px;
    text-align: center;
}

.env-value {
    display: block;
    font-size: 1.5rem;
    font-weight: 600;
    font-family: var(--font-mono);
    margin-bottom: 4px;
}

.env-label {
    font-size: 0.8rem;
    color: var(--color-text-muted);
}

/* Sections */
.section {
    padding: 80px 0;
}

.section.bg-alt {
    background: var(--color-bg-alt);
}

.section h2 {
    font-size: 1.75rem;
    font-weight: 600;
    margin-bottom: 8px;
}

.section-desc {
    color: var(--color-text-muted);
    margin-bottom: 32px;
}

/* Chart */
.chart-container {
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-lg);
    padding: 24px;
    margin-bottom: 24px;
}

.chart-stats {
    display: flex;
    justify-content: center;
    gap: 48px;
    font-size: 0.9rem;
}

.chart-stats span {
    color: var(--color-text-muted);
}

.chart-stats strong {
    color: var(--color-text);
}

/* Map Placeholder */
.map-placeholder {
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-lg);
    padding: 80px;
    text-align: center;
    color: var(--color-text-muted);
}

.map-note {
    font-size: 0.85rem;
    margin-top: 8px;
}

/* Filters */
.filters {
    display: flex;
    gap: 16px;
    margin-bottom: 24px;
    flex-wrap: wrap;
}

.filter-group {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.filter-group label {
    font-size: 0.75rem;
    color: var(--color-text-muted);
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.filter-group select,
.filter-group input {
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
    padding: 10px 14px;
    color: var(--color-text);
    font-size: 0.9rem;
    min-width: 150px;
}

.filter-group input {
    min-width: 200px;
}

/* Table */
.table-wrapper {
    overflow: auto;
    max-height: 800px;
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-lg);
}

.table-wrapper::-webkit-scrollbar {
    width: 8px;
    height: 8px;
}

.table-wrapper::-webkit-scrollbar-track {
    background: var(--color-bg);
}

.table-wrapper::-webkit-scrollbar-thumb {
    background: var(--color-border);
    border-radius: 4px;
}

.table-wrapper::-webkit-scrollbar-thumb:hover {
    background: var(--color-text-muted);
}

.district-table {
    width: 100%;
    border-collapse: collapse;
}

.district-table th,
.district-table td {
    padding: 14px 16px;
    text-align: left;
    border-bottom: 1px solid var(--color-border);
}

.district-table th {
    background: var(--color-bg);
    font-size: 0.75rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--color-text-muted);
    cursor: pointer;
    user-select: none;
    position: sticky;
    top: 0;
    z-index: 10;
}

.district-table th:hover {
    color: var(--color-text);
}

.district-table tbody tr {
    cursor: pointer;
    transition: background 0.2s;
}

.district-table tbody tr:hover {
    background: rgba(255, 255, 255, 0.03);
}

.district-table .district-id {
    font-weight: 600;
    font-family: var(--font-mono);
}

.district-table .incumbent-party {
    display: inline-block;
    width: 20px;
    height: 20px;
    border-radius: 50%;
    text-align: center;
    line-height: 20px;
    font-size: 0.7rem;
    font-weight: 600;
    margin-right: 8px;
}

.incumbent-party.D { background: var(--color-dem); }
.incumbent-party.R { background: var(--color-rep); }

.district-table .pvi {
    font-family: var(--font-mono);
    font-size: 0.85rem;
}

.district-table .prob {
    font-family: var(--font-mono);
    font-weight: 600;
}

.district-table .rating {
    display: inline-block;
    padding: 4px 10px;
    border-radius: 4px;
    font-size: 0.75rem;
    font-weight: 500;
}

.rating.safe_d { background: var(--color-dem); }
.rating.likely_d { background: var(--color-dem-light); }
.rating.lean_d { background: var(--color-dem-lighter); color: #333; }
.rating.toss_up { background: var(--color-tossup); }
.rating.lean_r { background: var(--color-rep-lighter); color: #333; }
.rating.likely_r { background: var(--color-rep-light); }
.rating.safe_r { background: var(--color-rep); }

.table-info {
    padding: 16px;
    font-size: 0.85rem;
    color: var(--color-text-muted);
}

/* Methodology */
.methodology-content {
    display: grid;
    grid-template-columns: 1fr;
    gap: 24px;
    max-width: 900px;
    margin: 0 auto;
    width: 100%;
    box-sizing: border-box;
}

.method-section {
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-lg);
    padding: 24px;
    overflow-x: hidden;
    word-wrap: break-word;
    overflow-wrap: break-word;
}


.method-section h3 {
    font-size: 1.1rem;
    font-weight: 600;
    margin-bottom: 16px;
    color: var(--color-accent);
}

.method-section p,
.method-section li {
    color: var(--color-text-muted);
    line-height: 1.8;
    margin-bottom: 12px;
}

.method-section p:last-child {
    margin-bottom: 0;
}

.method-section ul,
.method-section ol {
    padding-left: 24px;
    margin-top: 12px;
    margin-bottom: 12px;
}

.method-section li {
    margin-bottom: 8px;
}

.method-section pre {
    background: var(--color-bg);
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
    padding: 16px;
    margin: 16px 0;
    overflow-x: auto;
    max-width: 100%;
    -webkit-overflow-scrolling: touch;
    white-space: pre-wrap;
    word-wrap: break-word;
}

.method-section code {
    font-family: var(--font-mono);
    font-size: 0.85rem;
    color: var(--color-text);
}

.method-section p code {
    background: var(--color-bg);
    padding: 2px 6px;
    border-radius: 4px;
    font-size: 0.85em;
    word-break: break-word;
}

.method-section strong {
    color: var(--color-text);
}

/* Timeline Section */
.timeline-toggle {
    display: flex;
    gap: 8px;
    justify-content: center;
    margin-bottom: 24px;
}

.timeline-btn {
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    color: var(--color-text-muted);
    padding: 10px 24px;
    border-radius: var(--radius);
    font-size: 0.9rem;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s;
}

.timeline-btn:hover {
    color: var(--color-text);
    border-color: var(--color-text-muted);
}

.timeline-btn.active {
    background: var(--color-accent);
    border-color: var(--color-accent);
    color: white;
}

.timeline-chart-container {
    height: 400px;
}

.timeline-stats {
    display: flex;
    justify-content: center;
    gap: 48px;
    margin-top: 24px;
    font-size: 0.9rem;
    flex-wrap: wrap;
}

.timeline-stats .stat-item {
    text-align: center;
}

.timeline-stats .stat-item .label {
    color: var(--color-text-muted);
    font-size: 0.8rem;
    margin-bottom: 4px;
}

.timeline-stats .stat-item .value {
    font-family: var(--font-mono);
    font-weight: 600;
    font-size: 1.1rem;
}

.timeline-stats .stat-item .value.up {
    color: var(--color-dem-light);
}

.timeline-stats .stat-item .value.down {
    color: var(--color-rep-light);
}

.timeline-stats .stat-item .value.neutral {
    color: var(--color-text-muted);
}

/* Chamber Toggle */
.chamber-toggle {
    display: flex;
    gap: 8px;
    justify-content: center;
    margin-bottom: 32px;
    padding-top: 24px;
}

.chamber-btn {
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    color: var(--color-text-muted);
    padding: 12px 32px;
    border-radius: var(--radius);
    font-size: 1rem;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s;
}

.chamber-btn:hover {
    color: var(--color-text);
    border-color: var(--color-text-muted);
}

.chamber-btn.active {
    background: var(--color-accent);
    border-color: var(--color-accent);
    color: white;
}

.chamber-section {
    display: none;
}

.chamber-section.active {
    display: block;
}

/* Map */
#map-container {
    height: 500px;
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-lg);
    overflow: hidden;
}

.map-legend {
    display: flex;
    justify-content: center;
    gap: 16px;
    margin-top: 16px;
    flex-wrap: wrap;
}

.leaflet-container {
    background: var(--color-surface);
}

.leaflet-popup-content-wrapper {
    background: var(--color-surface);
    color: var(--color-text);
    border-radius: var(--radius);
}

.leaflet-popup-tip {
    background: var(--color-surface);
}

.district-popup h4 {
    margin: 0 0 8px 0;
    font-size: 1.1rem;
}

.district-popup p {
    margin: 4px 0;
    font-size: 0.9rem;
    color: var(--color-text-muted);
}

.district-popup .prob {
    font-size: 1.2rem;
    font-weight: 600;
    font-family: var(--font-mono);
}

.district-popup .guaranteed {
    font-size: 1rem;
    font-weight: 600;
}

.district-popup .guaranteed.D {
    color: var(--color-dem-light);
}

.district-popup .guaranteed.R {
    color: var(--color-rep-light);
}

.district-popup .up-2026 {
    color: var(--color-accent);
    font-size: 0.8rem;
    font-weight: 500;
}

.district-popup .not-up {
    color: var(--color-text-muted);
    font-size: 0.8rem;
    font-style: italic;
}

/* Color classes for text */
.dem-text { color: var(--color-dem-light); }
.rep-text { color: var(--color-rep-light); }

/* Params table */
.params-table {
    width: 100%;
    border-collapse: collapse;
    margin-top: 12px;
}

.params-table td {
    padding: 8px 12px;
    border-bottom: 1px solid var(--color-border);
}

.params-table td:first-child {
    color: var(--color-text-muted);
}

.params-table td:last-child {
    font-family: var(--font-mono);
    text-align: right;
}

/* Footer */
.footer {
    padding: 40px 0;
    border-top: 1px solid var(--color-border);
    text-align: center;
    color: var(--color-text-muted);
    font-size: 0.85rem;
}

.footer-links {
    margin-top: 12px;
}

.footer-links a {
    margin: 0 12px;
}

/* Modal */
.modal {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.8);
    z-index: 1000;
    align-items: center;
    justify-content: center;
    padding: 24px;
}

.modal.active {
    display: flex;
}

.modal-content {
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-lg);
    max-width: 600px;
    width: 100%;
    max-height: 80vh;
    overflow-y: auto;
    position: relative;
}

.modal-close {
    position: absolute;
    top: 16px;
    right: 16px;
    background: none;
    border: none;
    color: var(--color-text-muted);
    font-size: 1.5rem;
    cursor: pointer;
    line-height: 1;
}

.modal-close:hover {
    color: var(--color-text);
}

#modal-body {
    padding: 32px;
}

.modal-header {
    margin-bottom: 24px;
}

.modal-header h3 {
    font-size: 1.5rem;
    margin-bottom: 4px;
}

.modal-header p {
    color: var(--color-text-muted);
}

.modal-stats {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 16px;
    margin-bottom: 24px;
}

.modal-stat {
    background: var(--color-bg);
    border-radius: var(--radius);
    padding: 16px;
}

.modal-stat-value {
    font-size: 1.5rem;
    font-weight: 600;
    font-family: var(--font-mono);
}

.modal-stat-label {
    font-size: 0.8rem;
    color: var(--color-text-muted);
}

/* Responsive */
@media (max-width: 768px) {
    .container {
        padding: 0 16px;
    }

    /* Header */
    .header-content {
        height: 56px;
    }

    .logo {
        font-size: 0.95rem;
    }

    .nav {
        display: none;
    }

    /* Hero */
    .hero {
        padding: 40px 0 60px;
    }

    .hero-header h1 {
        font-size: 1.75rem;
    }

    /* Chamber Toggle */
    .chamber-toggle {
        padding-top: 16px;
        margin-bottom: 24px;
    }

    .chamber-btn {
        padding: 10px 24px;
        font-size: 0.9rem;
    }

    /* Stats */
    .stats-grid {
        grid-template-columns: 1fr;
        gap: 16px;
    }

    .stat-card {
        padding: 24px;
    }

    .stat-value {
        font-size: 2.5rem;
    }

    .stat-label {
        font-size: 0.9rem;
    }

    /* Categories Bar */
    .categories-bar {
        height: 40px;
    }

    .categories-legend {
        gap: 8px;
    }

    .legend-item {
        font-size: 0.65rem;
    }

    /* Environment */
    .environment-grid {
        grid-template-columns: repeat(2, 1fr);
        gap: 12px;
    }

    .env-item {
        padding: 16px;
    }

    .env-value {
        font-size: 1.25rem;
    }

    .env-label {
        font-size: 0.7rem;
    }

    /* Sections */
    .section {
        padding: 60px 0;
    }

    .section h2 {
        font-size: 1.5rem;
    }

    /* Map */
    #map-container {
        height: 350px;
    }

    .map-legend {
        gap: 8px;
    }

    /* Chart */
    .chart-container {
        padding: 16px;
    }

    .chart-stats {
        flex-direction: column;
        gap: 12px;
        text-align: center;
    }

    /* Filters */
    .filters {
        flex-direction: column;
        gap: 12px;
    }

    .filter-group {
        width: 100%;
    }

    .filter-group select,
    .filter-group input {
        width: 100%;
    }

    /* Table */
    .table-wrapper {
        max-height: 500px;
    }

    .district-table th,
    .district-table td {
        padding: 10px 12px;
        font-size: 0.85rem;
    }

    .district-table .rating {
        padding: 3px 8px;
        font-size: 0.7rem;
    }

    /* Modal */
    .modal {
        padding: 16px;
    }

    .modal-content {
        max-height: 90vh;
    }

    #modal-body {
        padding: 24px;
    }

    .modal-header h3 {
        font-size: 1.25rem;
    }

    .modal-stats {
        grid-template-columns: 1fr;
        gap: 12px;
    }

    .modal-stat-value {
        font-size: 1.25rem;
    }

    /* Methodology */
    .methodology-content {
        grid-template-columns: 1fr;
        gap: 16px;
    }

    .method-section {
        padding: 20px;
    }

    .method-section h3 {
        font-size: 1rem;
    }

    .method-section p,
    .method-section li {
        font-size: 0.9rem;
        line-height: 1.7;
    }

    .method-section pre {
        padding: 12px;
        font-size: 0.75rem;
    }

    .method-section code {
        font-size: 0.75rem;
    }

    .params-table {
        font-size: 0.85rem;
    }

    .params-table td {
        padding: 6px 8px;
        font-size: 0.85rem;
    }

    .params-table td:last-child {
        text-align: left;
        word-break: break-word;
    }

    /* Footer */
    .footer {
        padding: 32px 0;
    }
}

/* Tablet screens */
@media (min-width: 769px) and (max-width: 1024px) {
    .methodology-content {
        grid-template-columns: 1fr;
        max-width: 800px;
        margin: 0 auto;
    }

    .stats-grid {
        grid-template-columns: repeat(3, 1fr);
        gap: 16px;
    }

    .stat-value {
        font-size: 2.5rem;
    }
}

/* Extra small screens */
@media (max-width: 480px) {
    .hero-header h1 {
        font-size: 1.5rem;
    }

    .stat-value {
        font-size: 2rem;
    }

    .environment-grid {
        grid-template-columns: 1fr;
    }

    #map-container {
        height: 300px;
    }

    .categories-legend {
        flex-wrap: wrap;
        justify-content: flex-start;
    }

    .legend-item {
        flex: 0 0 auto;
    }

    /* Methodology extra small */
    .method-section {
        padding: 16px;
    }

    .method-section h3 {
        font-size: 0.95rem;
    }

    .method-section p,
    .method-section li {
        font-size: 0.85rem;
    }

    .method-section pre {
        padding: 10px;
        margin: 12px -16px;
        border-radius: 0;
        border-left: none;
        border-right: none;
    }

    .method-section ul,
    .method-section ol {
        padding-left: 20px;
    }

    .params-table td {
        display: block;
        padding: 4px 0;
        border-bottom: none;
    }

    .params-table td:first-child {
        font-weight: 500;
        color: var(--color-text);
    }

    .params-table td:last-child {
        padding-bottom: 12px;
        border-bottom: 1px solid var(--color-border);
    }

    .params-table tr:last-child td:last-child {
        border-bottom: none;
    }
}
