/* ===================================
   CSS Variables - Mid-Century Palette
   =================================== */
:root {
    /* Green to red color scale for turnout data */
    --color-turnout-1: #C85450;  /* Red - lowest turnout */
    --color-turnout-2: #D4745C;  /* Light red */
    --color-turnout-3: #D89468;  /* Orange-red */
    --color-turnout-4: #D4B074;  /* Tan */
    --color-turnout-5: #C4C080;  /* Olive */
    --color-turnout-6: #A4B87C;  /* Yellow-green */
    --color-turnout-7: #84A878;  /* Medium green */
    --color-turnout-8: #649874;  /* Green - highest turnout */

    /* Base colors */
    --bg-paper: #F4EFE6;
    --bg-darker: #E8DCC4;
    --text-primary: #2C2416;
    --text-secondary: #5A5044;
    --accent-line: #9D7C54;
    --shadow: rgba(44, 36, 22, 0.15);

    /* Typography */
    --font-display: 'Outfit', sans-serif;
    --font-body: 'Crimson Text', serif;

    /* Spacing */
    --spacing-xs: 0.5rem;
    --spacing-sm: 1rem;
    --spacing-md: 2rem;
    --spacing-lg: 3rem;
    --spacing-xl: 4rem;
}

/* ===================================
   Reset & Base Styles
   =================================== */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: var(--font-body);
    background-color: var(--bg-paper);
    color: var(--text-primary);
    line-height: 1.6;
    min-height: 100vh;

    /* Subtle paper grain texture */
    background-image:
        repeating-linear-gradient(
            0deg,
            transparent,
            transparent 2px,
            rgba(44, 36, 22, 0.01) 2px,
            rgba(44, 36, 22, 0.01) 4px
        ),
        repeating-linear-gradient(
            90deg,
            transparent,
            transparent 2px,
            rgba(44, 36, 22, 0.01) 2px,
            rgba(44, 36, 22, 0.01) 4px
        );
}

/* ===================================
   Layout
   =================================== */
.container {
    max-width: 1400px;
    margin: 0 auto;
    padding: var(--spacing-md);
    display: flex;
    flex-direction: column;
    min-height: 100vh;
}

/* ===================================
   Header
   =================================== */
.header {
    text-align: center;
    margin-bottom: var(--spacing-md);
    padding: var(--spacing-md) 0;
    border-bottom: 3px solid var(--text-primary);
    position: relative;
}

.header::after {
    content: '';
    position: absolute;
    bottom: -6px;
    left: 50%;
    transform: translateX(-50%);
    width: 60%;
    height: 1px;
    background: var(--accent-line);
}

.title {
    font-family: var(--font-display);
    font-size: clamp(2rem, 5vw, 3.5rem);
    font-weight: 800;
    letter-spacing: -0.02em;
    text-transform: uppercase;
    color: var(--text-primary);
    margin-bottom: var(--spacing-xs);
}

.subtitle {
    font-family: var(--font-body);
    font-size: clamp(1rem, 2vw, 1.25rem);
    font-style: italic;
    color: var(--text-secondary);
    font-weight: 400;
}

.subtitle #currentYear {
    font-family: var(--font-display);
    font-weight: 800;
    font-style: normal;
    color: var(--text-primary);
    font-size: clamp(1.25rem, 2.5vw, 1.5rem);
}

/* ===================================
   Main Content
   =================================== */
.main-content {
    flex: 1;
    position: relative;
}

/* ===================================
   Map Container
   =================================== */
.map-container {
    background: white;
    border: 2px solid var(--text-primary);
    box-shadow: 6px 6px 0 var(--shadow);
    padding: 0;
    position: relative;
    max-height: 80vh;
    width: 100%;
    aspect-ratio: 960 / 600;
    display: flex;
    align-items: center;
    justify-content: center;
}

.map-container.secondary {
    max-height: 80vh;
}

#map {
    width: 100%;
    height: 100%;
    max-height: none;
    display: block;
}

/* Map state styles */
.state {
    stroke: var(--bg-paper);
    stroke-width: 1.5;
    cursor: pointer;
    transition: stroke-width 0.2s ease, opacity 0.2s ease;
}

.state:hover {
    stroke: var(--text-primary);
    stroke-width: 2.5;
    opacity: 1 !important;
}

/* ===================================
   Settings Menu
   =================================== */
.settings-menu {
    position: absolute;
    top: var(--spacing-xs);
    left: var(--spacing-xs);
    z-index: 10;
}

.hamburger-btn {
    width: 20px;
    height: 20px;
    background: var(--bg-paper);
    border: 1px solid var(--text-primary);
    box-shadow: 2px 2px 0 var(--shadow);
    cursor: pointer;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 2.5px;
    padding: 0;
    transition: transform 0.2s ease;
}

.hamburger-btn:hover {
    transform: scale(1.1);
}

.hamburger-btn:active {
    box-shadow: 1px 1px 0 var(--shadow);
    transform: translate(1px, 1px) scale(1.1);
}

.hamburger-line {
    width: 10px;
    height: 1.5px;
    background: var(--text-primary);
    transition: all 0.3s ease;
}

.hamburger-btn.active .hamburger-line:nth-child(1) {
    transform: translateY(4px) rotate(45deg);
}

.hamburger-btn.active .hamburger-line:nth-child(2) {
    opacity: 0;
}

.hamburger-btn.active .hamburger-line:nth-child(3) {
    transform: translateY(-4px) rotate(-45deg);
}

.settings-panel {
    position: absolute;
    top: 0;
    left: 26px;
    background: var(--bg-paper);
    border: 2px solid var(--text-primary);
    box-shadow: 3px 3px 0 var(--shadow);
    padding: 0.5rem 0.75rem;
    opacity: 0;
    pointer-events: none;
    transform: translateX(-10px);
    transition: opacity 0.3s ease, transform 0.3s ease;
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.settings-panel.open {
    opacity: 1;
    pointer-events: auto;
    transform: translateX(0);
}

.checkbox-label {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    cursor: pointer;
    user-select: none;
    white-space: nowrap;
}

.show-all-checkbox,
.hide-legend-checkbox {
    width: 16px;
    height: 16px;
    cursor: pointer;
    appearance: none;
    -webkit-appearance: none;
    border: 2px solid var(--text-primary);
    background: white;
    position: relative;
    transition: background-color 0.2s ease;
    flex-shrink: 0;
}

.show-all-checkbox:checked,
.hide-legend-checkbox:checked {
    background: var(--text-primary);
}

.show-all-checkbox:checked::after,
.hide-legend-checkbox:checked::after {
    content: '';
    position: absolute;
    left: 3px;
    top: 0px;
    width: 4px;
    height: 8px;
    border: solid var(--bg-paper);
    border-width: 0 2px 2px 0;
    transform: rotate(45deg);
}

.checkbox-text {
    font-family: var(--font-display);
    font-size: 0.75rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--text-primary);
}

/* ===================================
   Legend
   =================================== */
.legend {
    position: absolute;
    bottom: 2%;
    right: 3%;
    width: clamp(10px, 1.2vw, 12px);
    max-height: 40%;
    background: transparent;
    padding: 0;
    border: none;
    box-shadow: none;
    display: flex;
    flex-direction: column;
    gap: 2px;
    z-index: 10;
    pointer-events: none;
    opacity: 1;
    transition: opacity 0.3s ease;
}

.legend.hidden {
    opacity: 0;
    pointer-events: none;
}

.legend-title {
    display: none;
}

.legend-scale {
    flex: 1;
    min-height: 64px;
    background: linear-gradient(
        to bottom,
        var(--color-turnout-8),
        var(--color-turnout-7),
        var(--color-turnout-6),
        var(--color-turnout-5),
        var(--color-turnout-4),
        var(--color-turnout-3),
        var(--color-turnout-2),
        var(--color-turnout-1)
    );
    border: 1px solid var(--text-primary);
    position: relative;
}

.legend-labels {
    font-family: var(--font-display);
    font-size: clamp(0.6rem, 1.2vw, 0.75rem);
    font-weight: 600;
    color: var(--text-primary);
    text-align: center;
    pointer-events: none;
    transform: translateX(-3px);
}

/* ===================================
   State Labels and Leader Lines
   =================================== */
.state-label {
    pointer-events: none;
    font-family: var(--font-display);
    font-size: 12px;
    font-weight: 800;
    fill: var(--text-primary);
    text-anchor: middle;
    opacity: 0;
    transition: opacity 0.2s ease;
    paint-order: stroke fill;
    stroke: var(--bg-paper);
    stroke-width: 3px;
    stroke-linejoin: round;
}

.state-label.visible {
    opacity: 1;
}

.leader-line {
    stroke: var(--text-primary);
    stroke-width: 1;
    stroke-dasharray: 2, 2;
    opacity: 0;
    fill: none;
    pointer-events: none;
    transition: opacity 0.2s ease;
}

.leader-line.visible {
    opacity: 0.4;
}

/* ===================================
   Timeline Slider
   =================================== */
.dataset-toggle {
    display: flex;
    gap: 1rem;
    align-items: center;
    justify-content: flex-end;
    margin: 0 0 var(--spacing-xs) 0;
    font-family: var(--font-display);
    color: var(--text-primary);
}

.dataset-toggle .toggle-label {
    font-weight: 800;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    font-size: 0.85rem;
}

.radio-label {
    display: inline-flex;
    align-items: center;
    gap: 0.35rem;
    cursor: pointer;
    font-size: 0.9rem;
}

.radio-label input[type="radio"] {
    accent-color: var(--text-primary);
}

.timeline-container {
    margin-top: var(--spacing-sm);
    margin-bottom: var(--spacing-sm);
    padding: 0;
}

.timeline-title {
    font-family: var(--font-display);
    font-size: 0.875rem;
    font-weight: 800;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    margin-top: var(--spacing-xs);
    margin-bottom: var(--spacing-xs);
    color: var(--text-primary);
    text-align: center;
}

.timeline-slider-wrapper {
    position: relative;
    padding-bottom: var(--spacing-sm);
}

.timeline-slider {
    width: 100%;
    height: 8px;
    -webkit-appearance: none;
    appearance: none;
    background: var(--bg-darker);
    outline: none;
    border-radius: 0;
    cursor: pointer;
    border: 1px solid var(--text-primary);
    touch-action: none;
}

.timeline-slider::-webkit-slider-thumb {
    -webkit-appearance: none;
    appearance: none;
    width: 24px;
    height: 24px;
    background: var(--text-primary);
    cursor: pointer;
    border-radius: 0;
    border: 2px solid var(--bg-paper);
    box-shadow: 2px 2px 0 var(--shadow);
    transition: transform 0.2s ease;
    margin-top: -16px;
}

.timeline-slider::-webkit-slider-thumb:hover {
    transform: scale(1.15);
}

.timeline-slider::-moz-range-thumb {
    width: 24px;
    height: 24px;
    background: var(--text-primary);
    cursor: pointer;
    border-radius: 0;
    border: 2px solid var(--bg-paper);
    box-shadow: 2px 2px 0 var(--shadow);
    transition: transform 0.2s ease;
}

.timeline-slider::-moz-range-thumb:hover {
    transform: scale(1.15);
}

.timeline-labels {
    position: relative;
    margin-top: var(--spacing-xs);
    height: 80px;
    font-family: var(--font-display);
    font-size: 0.95rem;
    font-weight: 600;
    color: var(--text-secondary);
}

.timeline-label {
    position: absolute;
    transform: translateX(-50%);
    text-align: center;
    cursor: pointer;
    transition: color 0.2s ease;
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
}

.timeline-year {
    font-size: 0.95rem;
    font-weight: 600;
    color: var(--text-secondary);
    transition: color 0.2s ease;
}

.timeline-label:hover .timeline-year {
    color: var(--text-primary);
}

.timeline-label.active .timeline-year {
    color: var(--text-primary);
    font-weight: 800;
}

.timeline-candidates {
    font-size: 0.75rem;
    line-height: 1.3;
    display: flex;
    flex-direction: column;
}

.candidate {
    color: var(--text-secondary);
    font-weight: 400;
}

.candidate.winner {
    font-weight: 800;
    color: var(--text-primary);
}

/* ===================================
   Summary Sections
   =================================== */
.summary-section {
    margin-top: var(--spacing-md);
    padding-top: var(--spacing-sm);
    border-top: 2px solid var(--text-primary);
}

.summary-title {
    font-family: var(--font-display);
    font-size: clamp(1.25rem, 2.5vw, 1.75rem);
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: var(--text-primary);
    margin-bottom: var(--spacing-md);
    text-align: center;
}

.summary-grid {
    display: flex;
    flex-direction: column;
    gap: var(--spacing-sm);
    align-items: center;
}

.summary-card {
    display: flex;
    flex-direction: column;
    width: min(1000px, 90%);
}

.summary-card-header {
    text-align: left;
    margin-bottom: var(--spacing-xs);
}

.summary-card-header h3 {
    font-family: var(--font-display);
    font-size: 1rem;
    text-transform: uppercase;
    letter-spacing: 0.08em;
}

.summary-map {
    width: 100%;
    height: 100%;
}

/* ===================================
   Footer
   =================================== */
.footer {
    text-align: center;
    padding: var(--spacing-md) 0;
    border-top: 1px solid var(--accent-line);
    font-family: var(--font-body);
    font-size: 0.875rem;
    color: var(--text-secondary);
}

.footer a {
    color: var(--accent-line);
    text-decoration: none;
    border-bottom: 1px solid var(--accent-line);
    transition: color 0.2s ease;
}

.footer a:hover {
    color: var(--text-primary);
    border-bottom-color: var(--text-primary);
}

/* ===================================
   Responsive Design
   =================================== */
@media (orientation: portrait) {
    .legend {
        bottom: 8%;
    }

    .map-container,
    .map-container.secondary,
    .summary-card {
        width: 100%;
        max-width: none;
    }

    .map-container.secondary {
        max-height: 80vh;
    }

    .summary-section {
        margin-top: var(--spacing-sm);
        padding-top: var(--spacing-xs);
    }

    .summary-grid {
        gap: var(--spacing-xs);
    }
}

@media (max-width: 640px) {
    .container {
        padding: var(--spacing-sm);
    }

    .timeline-labels {
        font-size: 0.75rem;
    }
}

/* ===================================
   Animations
   =================================== */
@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateY(10px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.state {
    animation: fadeIn 0.6s ease backwards;
}

/* Stagger state animations slightly */
.state:nth-child(n) {
    animation-delay: calc(0.01s * var(--state-index, 0));
}
