/* Shared map visual foundations. */
* { margin: 0; padding: 0; box-sizing: border-box; }
@font-face {
    font-family: 'Rethink Sans';
    src: url('./fonts/RethinkSans-VariableFont_wght.woff2?v=e7a1bed4332ae3e9') format('woff2');
    font-weight: 300 700;
    font-style: normal;
    font-display: swap;
}
:root {
    --font-family: 'Fira Code' , monospace;
    --font-family-sans: 'Rethink Sans' , sans-serif;
    --font-family-serif: 'Domine' , serif;
    --font-base-size: 1rem;
    --font-small-size: 0.8rem;
    --font-muted-color: #808080;
    --default-one-third-post-subelement-width: 205px;
    --highlight: #cfcfcf;
    --mountain-with-background: #cfcfcf;
    --highlight-text-color: var(--background-content-color);
    --added-background-color: #def3df;
    --added-text-color: #225c2a;
    --removed-background-color: #fbe0df;
    --removed-text-color: #842e2a;

    --background-color: #DEDEDE;
    --background-content-color: #111;
    --mobile-breakpoint: 599px;

    --alt-background-color: #000;
    --alt-background-content-color: #fff;


    --border-color: #000;

    --base-rounding: 0.5rem;
    --inner-rounding: 0.25rem;

    --heading-color: var(--alt-background-color);

    [data-theme='dark'] {
        --highlight-text-color: var(--background-content-color);
        --added-background-color: #17351f;
        --added-text-color: #bce8c5;
        --removed-background-color: #431e22;
        --removed-text-color: #f6c3c4;
        --highlight: #2b2b2b;
        --mountain-with-background: #242424;
        --background-color: #000;
        --border-color: #fff;
        --background-content-color: #DEDEDE;
        --alt-background-color: #eee;
        --font-muted-color: #adadad;
        --alt-background-content-color: #333;
        --heading-color: #fff;

        img[src*="svg"] {
            filter: invert(1);
        }
    }
}


@media (prefers-color-scheme: dark) {
    :root {
        --highlight-text-color: var(--background-content-color);
        --added-background-color: #17351f;
        --added-text-color: #bce8c5;
        --removed-background-color: #431e22;
        --removed-text-color: #f6c3c4;
        --highlight: #2b2b2b;
        --mountain-with-background: #242424;
        --background-color: #000;
        --border-color: #fff;
        --background-content-color: #DEDEDE;
        --alt-background-color: #eee;
        --alt-background-content-color: #333;
        --font-muted-color: #adadad;

        --heading-color: #fff;

        img[src*="svg"] {
            filter: invert(1);
        }
    }

    [data-theme='light'] {
        --highlight-text-color: var(--background-content-color);
        --font-muted-color: #808080;
        --added-background-color: #def3df;
        --added-text-color: #225c2a;
        --removed-background-color: #fbe0df;
        --removed-text-color: #842e2a;
        --highlight: #cfcfcf;
        --mountain-with-background: #cfcfcf;
        --background-color: #DEDEDE;
        --background-content-color: #111;
        --border-color: #000;

        --alt-background-color: #000;
        --alt-background-content-color: #fff;
        --heading-color: var(--alt-background-color);

        img[src*="svg"] {
            filter: invert(0);
        }
    }
}


[data-theme="pink"] {
    --highlight: #f4b5d5;
    --highlight-text-color: #4b1936;
    --mountain-with-background: #f6c5df;
    --background-color: #ffe4f1;
    --background-content-color: #4b1936;
    --font-muted-color: #8a3a65;
    --border-color: #b84280;

    --alt-background-color: #a32669;
    --alt-background-content-color: #fff4fa;

    --heading-color: var(--alt-background-color);

    img[src*="svg"] {
        filter: invert(0);
    }
}

[data-theme="hacker"] {
    --highlight-text-color: var(--background-content-color);
    --highlight: #242424;
    --mountain-with-background: #242424;
    --background-color: #000;
    --background-content-color: #00b838;

    --alt-background-color: #00b838;
    --alt-background-content-color: #000;

    --heading-color: #00b838;
}


body {
    font-family: var(--font-family-sans);
    font-size: var(--font-base-size);
    line-height: 1.5;
    color: var(--background-content-color);
    background: var(--background-color);
    font-variant-ligatures: no-common-ligatures;
}
h1 { color: var(--heading-color); }
a { text-decoration: none; color: inherit; }
a:hover { text-decoration: underline; }
button { border: none; font: inherit; color: inherit; background: transparent; cursor: pointer; }
.main-header-wrapper {
    width: 100%; font-size: 0.75rem; margin: 0 auto;
    border-bottom: 1px solid transparent;
    background: var(--background-color); color: var(--background-content-color);
}
.main-header {
    max-width: 1280px; padding: 0.5rem 1rem; width: 100%; margin: 0 auto;
    align-items: center; display: flex; gap: 0.5rem;
}
.main-header a { text-decoration: none; height: 28px; display: flex; align-items: center; }
.vertical-page {
    padding: 0.75rem 1rem; max-width: 1280px; display: flex;
    flex-direction: column; margin: 0 auto; gap: 0.75rem;
}

/* Election map. */
html,
        body {
            width: 100%;
            min-width: 0;
            height: 100%;
            overflow: hidden;
        }

        body {
            opacity: 1;
        }

        .election-app {
            display: grid;
            grid-template-columns: minmax(0, 1fr);
            grid-template-rows: auto minmax(0, 1fr);
            width: 100%;
            height: 100dvh;
            min-height: 32rem;
            font-family: var(--font-family-sans);
        }

        .election-header-wrapper {
            border-bottom-color: var(--border-color);
        }

        .election-header {
            height: 44px;
            max-width: none;
            gap: 0.75rem;
            font-family: var(--font-family-sans);
        }

        .election-title-line {
            display: flex;
            align-items: center;
            min-width: 0;
            margin-right: auto;
            height: 28px;
            flex: 1;
            overflow: hidden;
            white-space: nowrap;
        }

        .election-title-line h1 {
            display: inline;
            flex: 0 1 auto;
            min-width: 0;
            overflow: hidden;
            text-overflow: ellipsis;
            font-size: inherit;
            line-height: inherit;
        }

        .election-title-line [hidden] {
            display: none;
        }

        .election-status {
            flex: none;
            color: var(--font-muted-color);
            font-family: var(--font-family-sans);
            font-size: var(--font-small-size);
            white-space: nowrap;
        }

        .election-layout {
            display: grid;
            grid-template-columns: minmax(16rem, 23rem) minmax(0, 1fr);
            min-height: 0;
        }

        .results-panel {
            z-index: 3;
            min-width: 0;
            max-width: none;
            margin: 0;
            overflow-y: auto;
            border-right: 1px solid var(--border-color);
            background: var(--background-color);
        }

        .field-label {
            display: block;
            margin-bottom: 0.25rem;
            font-family: var(--font-family-sans);
            font-size: var(--font-small-size);
            font-weight: 600;
        }

        .contest-control {
            position: relative;
        }

        .contest-control:not([data-contest-loading])::after {
            content: '';
            position: absolute;
            top: 50%;
            right: 0.9rem;
            width: 0.45rem;
            height: 0.45rem;
            border-right: 1.5px solid currentColor;
            border-bottom: 1.5px solid currentColor;
            transform: translateY(-70%) rotate(45deg);
            pointer-events: none;
        }

        .contest-select {
            appearance: none;
            width: 100%;
            min-height: 2.25rem;
            padding: 0.3rem 2.5rem 0.3rem 0.55rem;
            border: 1px solid var(--border-color);
            border-radius: 0;
            background: var(--background-color);
            color: var(--background-content-color);
            font: inherit;
        }

        .contest-control[data-contest-loading] .contest-select {
            color: transparent;
        }

        .contest-skeleton {
            display: none;
            position: absolute;
            inset: 1px;
            align-items: center;
            padding: 0.3rem 0.55rem;
            background: var(--background-color);
            pointer-events: none;
        }

        .contest-control[data-contest-loading] .contest-skeleton {
            display: flex;
        }

        .contest-skeleton > span {
            width: 65%;
            height: 0.85rem;
            background: var(--highlight);
            animation: contest-skeleton-pulse 1.3s ease-in-out infinite alternate;
        }

        @keyframes contest-skeleton-pulse {
            from { opacity: 0.45; }
            to { opacity: 1; }
        }

        .visually-hidden {
            position: absolute;
            width: 1px;
            height: 1px;
            padding: 0;
            margin: -1px;
            overflow: hidden;
            clip-path: inset(50%);
            white-space: nowrap;
            border: 0;
        }

        .contest-select:focus-visible,
        .map-control:focus-visible {
            outline: 2px solid currentColor;
            outline-offset: 2px;
        }

        .contest-title {
            font-size: 0.95rem;
            line-height: 1.3;
        }

        .contest-summary,
        .data-note,
        .sources,
        .map-help {
            color: var(--font-muted-color);
            font-family: var(--font-family-sans);
            font-size: var(--font-small-size);
        }

        .result-list {
            display: grid;
            gap: 0.75rem;
            padding: 0;
            list-style: none;
        }

        .result-row {
            min-width: 0;
        }

        .result-label {
            display: grid;
            grid-template-columns: minmax(0, 1fr) auto;
            gap: 0.75rem;
            align-items: baseline;
            margin-bottom: 0.25rem;
            font-family: var(--font-family-sans);
            font-size: var(--font-small-size);
        }

        .result-name {
            overflow: hidden;
            font-weight: 600;
            text-overflow: ellipsis;
            white-space: nowrap;
        }

        .result-count {
            color: var(--font-muted-color);
            font-variant-numeric: tabular-nums;
            white-space: nowrap;
        }

        .result-track {
            height: 0.55rem;
            overflow: hidden;
            border: 1px solid var(--border-color);
        }

        .result-bar {
            width: var(--result-percent);
            height: 100%;
            background: var(--result-color);
        }

        .data-note {
            padding: 0.75rem;
            border: 1px solid var(--border-color);
            color: var(--background-content-color);
        }

        .data-note summary {
            cursor: pointer;
            font-weight: 600;
        }

        .data-note p {
            margin-top: 0.5rem;
        }

        .sources {
            display: flex;
            flex-wrap: wrap;
            gap: 0.25rem 0.75rem;
        }

        .map-panel {
            position: relative;
            min-width: 0;
            min-height: 0;
            overflow: hidden;
            background: var(--highlight);
        }

        .map-view {
            display: block;
            width: 100%;
            height: 100%;
            touch-action: none;
            cursor: grab;
        }

        .map-view.is-dragging {
            cursor: grabbing;
        }

        .precinct {
            --precinct-color: var(--font-muted-color);
            --precinct-strength: 30%;
            fill: color-mix(in srgb, var(--precinct-color) var(--precinct-strength), var(--background-color));
            stroke: color-mix(in srgb, var(--background-content-color) 45%, transparent);
            stroke-width: 0.55;
            vector-effect: non-scaling-stroke;
            transition: fill 120ms ease, opacity 120ms ease;
        }

        .precinct.is-withheld,
        .precinct.is-zero {
            fill: var(--highlight);
        }

        .precinct:hover,
        .precinct.is-selected {
            stroke: var(--background-content-color);
            stroke-width: 2.5;
        }

        .map-toolbar {
            position: absolute;
            z-index: 2;
            top: 0.75rem;
            right: 0.75rem;
            display: grid;
            border: 1px solid var(--border-color);
            background: var(--background-color);
        }

        .map-control {
            display: grid;
            place-items: center;
            width: 2.25rem;
            height: 2.25rem;
            border-bottom: 1px solid var(--border-color);
        }

        .map-control:last-child {
            border-bottom: 0;
        }

        .map-control:hover {
            background: var(--highlight);
            text-decoration: none;
        }

        .map-status {
            position: absolute;
            z-index: 2;
            right: 0.75rem;
            bottom: 0.75rem;
            width: min(26rem, calc(100% - 1.5rem));
            padding: 0.65rem 0.75rem;
            border: 1px solid var(--border-color);
            background: var(--background-color);
            font-family: var(--font-family-sans);
            font-size: var(--font-small-size);
        }

        .map-status-title {
            display: block;
            margin-bottom: 0.25rem;
            font-family: inherit;
        }

        .precinct-result {
            display: grid;
            grid-template-columns: minmax(0, 1fr) auto;
            gap: 0.75rem;
            padding-top: 0.2rem;
            font-variant-numeric: tabular-nums;
        }

        .precinct-result span:first-child {
            overflow: hidden;
            text-overflow: ellipsis;
            white-space: nowrap;
        }

        .map-help {
            margin-top: 0.35rem;
        }

        .loading {
            position: absolute;
            z-index: 3;
            inset: 0;
            display: grid;
            place-items: center;
            padding: 2rem;
            background: var(--highlight);
            color: var(--font-muted-color);
            text-align: center;
        }

        .loading[hidden] {
            display: none;
        }

        @media (prefers-reduced-motion: reduce) {
            .contest-skeleton > span {
                animation: none;
            }

            .precinct {
                transition: none;
            }
        }

        a:hover {
            background: transparent;
        }

        h1 {
            font-weight: normal;
        }

/* Selector and results remain in the desktop sidebar; mobile places the map first. */
.election-layout {
    grid-template-rows: auto minmax(0, 1fr);
    grid-template-areas: 'selector map' 'results map';
}
.contest-panel {
    grid-area: selector;
    min-width: 0;
    padding: 0.75rem 1rem 0;
    border-right: 1px solid var(--border-color);
    background: var(--background-color);
}
.results-panel { grid-area: results; }
.map-panel { grid-area: map; }
.results-expanded { display: flex; flex-direction: column; gap: 0.75rem; }
.mobile-results-toggle, .mobile-map-status, .mobile-updated { display: none; }

@media (max-width: 720px) {
    html, body { overflow: hidden; }
    .election-app { height: 100dvh; min-height: 0; }
    .election-header { height: 40px; flex-wrap: nowrap; padding: 0.35rem 0.75rem; }
    .election-title-line { flex-basis: auto; overflow: hidden; white-space: nowrap; }
    .election-title-line h1 { flex: 0 1 auto; min-width: 0; overflow: hidden; text-overflow: ellipsis; }
    .election-title-line a, .election-title-line > span { flex-shrink: 0; }
    .election-status { display: none; }
    .election-layout {
        grid-template-columns: minmax(0, 1fr);
        grid-template-areas: 'selector' 'map' 'results';
        grid-template-rows: auto minmax(0, 1fr) auto;
    }
    .contest-panel { padding: 0.5rem 0.75rem; border-right: 0; border-bottom: 1px solid var(--border-color); }
    .contest-panel .field-label { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); }
    .contest-select { min-height: 2.75rem; border: 0; font-size: 1rem; }
    .map-toolbar { top: 0.5rem; right: 0.5rem; }
    .map-control { width: 2.75rem; height: 2.75rem; }
    .map-status { display: none; }
    .results-panel {
        margin: 0;
        padding: 0 0 env(safe-area-inset-bottom);
        border: 0;
        border-top: 1px solid color-mix(in srgb, var(--background-content-color) 25%, transparent);
        border-radius: 0;
        max-height: 52dvh;
        overscroll-behavior: contain;
    }
    .mobile-results-toggle {
        position: sticky;
        top: 0;
        z-index: 1;
        display: flex;
        align-items: center;
        justify-content: space-between;
        gap: 0.75rem;
        width: 100%;
        padding: 0.9rem 1rem;
        text-align: left;
        background: var(--background-color);
    }
    .mobile-results-overview { display: grid; gap: 0.5rem; flex: 1; min-width: 0; }
    .mobile-results-overview > strong { font-size: 1rem; }
    .mobile-result-choices { display: flex; flex-wrap: wrap; gap: 0.35rem 0.9rem; font-size: 0.85rem; }
    .compact-choice { display: inline-flex; align-items: center; gap: 0.35rem; max-width: 100%; min-width: 0; }
    .compact-choice-name { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
    .compact-choice-count { flex: none; color: var(--font-muted-color); }
    .choice-swatch { width: 0.65rem; height: 0.65rem; border-radius: 2px; background: var(--choice-color); flex: none; }
    .compact-more { color: var(--font-muted-color); }
    .results-chevron { display: grid; place-items: center; width: 2.75rem; height: 2.75rem; flex: none; border: 0; border-radius: 0; background: var(--highlight); }
    .mobile-results-toggle[aria-expanded='true'] .results-chevron svg { transform: rotate(180deg); }
    .mobile-results-toggle:focus-visible { outline: 2px solid currentColor; outline-offset: -4px; }
    .results-panel:not(.is-expanded) .results-expanded { display: none; }
    .results-expanded { padding: 0 1rem 1rem; }
    .mobile-map-status:not([hidden]), .mobile-updated { display: block; }
    .mobile-map-status { padding-bottom: 0.75rem; border-bottom: 1px solid var(--font-muted-color); font-size: 0.85rem; }
    .mobile-updated { color: var(--font-muted-color); font-size: 0.75rem; }
    .result-list { grid-template-columns: 1fr; }
    .result-name { white-space: normal; }
}

@media (max-width: 720px) and (max-height: 500px) {
    .map-toolbar { display: flex; }
    .map-control { border-bottom: 0; border-right: 1px solid var(--border-color); }
    .map-control:last-child { border-right: 0; }
}
