/* =========================================
   TALLY538 UNIFIED STYLESHEET (M3 EXPRESSIVE v5)
   ========================================= */

/* =========================================
   OFFLINE LOCAL FONT FALLBACKS
   ========================================= */

@font-face {
    font-family: 'Outfit';
    font-style: normal;
    font-weight: 100 900;
    font-display: swap;
    src: local('Outfit'),
         url('fonts/outfit.ttf') format('truetype');
}

@font-face {
    font-family: 'Roboto';
    font-style: normal;
    font-weight: 100 900;
    font-display: swap;
    src: local('Roboto'),
         url('fonts/roboto.ttf') format('truetype');
}

/* Keep Outfit & Roboto @font-face rules if you have them in assets/fonts/, 
   or remove the Material Symbols @font-face block so it doesn't overwrite Google Fonts */

.material-symbols-rounded {
    font-family: 'Material Symbols Rounded' !important;
    font-weight: normal;
    font-style: normal;
    font-size: 24px;
    line-height: 1;
    letter-spacing: normal;
    text-transform: none;
    display: inline-block;
    white-space: nowrap;
    word-wrap: normal;
    direction: ltr;
    -webkit-font-feature-settings: 'liga' 1;
    font-feature-settings: 'liga' 1;
    text-rendering: optimizeLegibility;
    -webkit-font-smoothing: antialiased;
    font-variation-settings: 'FILL' 1, 'wght' 400, 'GRAD' 0, 'opsz' 24;
}

/* =========================================
   M3 EXPRESSIVE DESIGN TOKENS
   ========================================= */

:root {
    /* Surface Tones - Light Mode (Crisp Lavender-Indigo Tint) */
    --md-sys-color-background: #F4F3FF;
    --md-sys-color-surface: #F4F3FF;
    --md-sys-color-surface-container-lowest: #FFFFFF;
    --md-sys-color-surface-container-low: #ECEAF9;
    --md-sys-color-surface-container: #E3E0F5;
    --md-sys-color-surface-container-high: #D4D0EE;
    --md-sys-color-surface-container-highest: #C5C0E5;

    --md-sys-color-on-surface: #1F1C2E;
    --md-sys-color-on-surface-variant: #434056;
    --md-sys-color-outline: #6E6B82;
    --md-sys-color-outline-variant: #B8B4D0;

    /* Frosted Glass System */
    --surface-translucent: rgba(255, 255, 255, 0.80);
    --surface-translucent-card: rgba(246, 245, 255, 0.86);
    --surface-card-nested: rgba(255, 255, 255, 0.82);
    --glass-blur: blur(16px) saturate(200%);
    --glass-border: 1px solid rgba(255, 255, 255, 0.85);
    --glass-border-subtle: 1px solid rgba(184, 180, 208, 0.55);
    --glass-highlight: inset 0 1px 0 0 rgba(255, 255, 255, 0.9);

    /* Expressive Election Colors (Rich & Vibrant in Light Mode) */
    --color-primary: #1565D8;
    --color-secondary: #E02D2D;
    --color-tertiary: #169342;
    --color-uncalled: #D2CEF0;
    --color-warning: #E58800;
    --map-stroke: #F4F3FF;

    /* Shape Family Tokens */
    --radius-sm: 12px;
    --radius-md: 16px;
    --radius-lg: 24px;
    --radius-card: 28px;
    --radius-button: 100px;
    --radius-input: 16px;
    --radius-material-active: 11px;
    --radius-full: 9999px;

    /* Layout Tokens */
    --sidebar-width: 300px;
    --top-bar-height: 64px;

    /* M3 Expressive Motion System */
    --m3-ease-standard: cubic-bezier(0.2, 0.0, 0, 1.0);
    --m3-ease-emphasized: cubic-bezier(0.2, 0.0, 0, 1.0);
    --m3-ease-spring: cubic-bezier(0.34, 1.25, 0.64, 1);

    /* Elevation & Diffuse Shadows */
    --shadow-level-1: 0 2px 6px rgba(26, 20, 64, 0.08), 0 1px 2px rgba(26, 20, 64, 0.05);
    --shadow-level-2: 0 6px 18px rgba(26, 20, 64, 0.10), 0 2px 6px rgba(26, 20, 64, 0.05);
    --shadow-level-3: 0 12px 32px rgba(26, 20, 64, 0.15), 0 4px 12px rgba(26, 20, 64, 0.08);
    --elevation-1: 0 1px 2px 0 rgba(26, 20, 64, 0.12), 0 1px 3px 1px rgba(26, 20, 64, 0.06);
    --elevation-2: 0 1px 2px 0 rgba(26, 20, 64, 0.14), 0 2px 6px 2px rgba(26, 20, 64, 0.08);

    --font-family: 'Outfit', 'Roboto', sans-serif;
}

body.dark-mode {
    /* Surface Tones - Dark Mode (Deep Navy/Charcoal) */
    --md-sys-color-background: #111118;
    --md-sys-color-surface: #111118;
    --md-sys-color-surface-container-lowest: #0A0A0F;
    --md-sys-color-surface-container-low: #181822;
    --md-sys-color-surface-container: #1D1D28;
    --md-sys-color-surface-container-high: #242431;
    --md-sys-color-surface-container-highest: #2E2E3C;

    --md-sys-color-on-surface: #E3E1E9;
    --md-sys-color-on-surface-variant: #C7C5D5;
    --md-sys-color-outline: #918F9E;
    --md-sys-color-outline-variant: #464552;

    background-image: 
        radial-gradient(circle at 12% 8%, rgba(59, 130, 246, 0.11), transparent 45%),
        radial-gradient(circle at 88% 8%, rgba(239, 68, 68, 0.11), transparent 45%),
        radial-gradient(circle at 50% 92%, rgba(59, 130, 246, 0.06), transparent 50%);

    --color-primary: #3B82F6;
    --color-secondary: #EF4444;
    --color-tertiary: #34D399;
    --color-uncalled: #282838;
    --color-warning: #FBBF24;
    --map-stroke: #161622;

    /* Dark Frosted Glass System */
    --surface-translucent: rgba(17, 17, 24, 0.78);
    --surface-translucent-card: rgba(24, 24, 34, 0.84);
    --surface-card-nested: rgba(29, 29, 40, 0.75);
    --glass-border: 1px solid rgba(255, 255, 255, 0.09);
    --glass-border-subtle: 1px solid rgba(255, 255, 255, 0.06);
    --glass-highlight: inset 0 1px 0 0 rgba(255, 255, 255, 0.07);

    /* Dark Mode Shadows */
    --shadow-level-1: 0 2px 6px rgba(0, 0, 0, 0.35), 0 1px 2px rgba(0, 0, 0, 0.25);
    --shadow-level-2: 0 6px 16px rgba(0, 0, 0, 0.45), 0 2px 6px rgba(0, 0, 0, 0.25);
    --shadow-level-3: 0 12px 32px rgba(0, 0, 0, 0.6), 0 4px 12px rgba(0, 0, 0, 0.35);
}

/* =========================================
   BASE & RESET
   ========================================= */

*, *::before, *::after {
    box-sizing: border-box;
}

body {
    --bg-app: var(--md-sys-color-background);
    --bg-panel: var(--md-sys-color-surface-container-lowest);
    --bg-sidebar: var(--md-sys-color-surface-container-low);
    --bg-card: var(--md-sys-color-surface);
    --border-state: var(--md-sys-color-outline-variant);
    --text-main: var(--md-sys-color-on-surface);
    --text-muted: var(--md-sys-color-on-surface-variant);

    margin: 0;
    font-family: var(--font-family);
    background-color: var(--bg-app);
    background-image: 
        radial-gradient(circle at 12% 8%, rgba(21, 101, 216, 0.13), transparent 45%),
        radial-gradient(circle at 88% 8%, rgba(224, 45, 45, 0.13), transparent 45%),
        radial-gradient(circle at 50% 92%, rgba(21, 101, 216, 0.08), transparent 50%);
    background-attachment: fixed;
    color: var(--text-main);
    height: 100vh;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    transition: background-color 0.3s var(--m3-ease-standard), color 0.3s var(--m3-ease-standard);
}

h1 {
    margin: 0;
    font-size: 1.25rem;
    font-weight: 600;
    letter-spacing: -0.2px;
}

h3 {
    font-size: 0.92rem;
    font-weight: 700;
    color: var(--text-main);
    margin: 0 0 12px 0;
    border-bottom: 2px solid var(--md-sys-color-surface-container-high);
    padding-bottom: 10px;
}

p {
    margin: 0;
}

/* Disable text selection across interactive UI surfaces */
body,
header,
button,
.top-bar-layout,
.tally-wrapper,
.settings-menu,
.sidebar,
.map-area,
.nav-tab,
.menu-item,
.score,
.pill-info,
.split-item,
.small-state-item {
    -webkit-user-select: none;
    -moz-user-select: none;
    -ms-user-select: none;
    user-select: none;
}

.score,
.pv-pill-summary,
.pv-pill-detail,
.nat-env-display,
.multi-select-count-badge,
.small-state-item button,
#pvPctDem,
#pvPctRep,
#pvPctYel,
#tooltip {
    font-variant-numeric: tabular-nums;
}

/* Preserve text selection for inputs and editable fields */
input,
textarea,
[contenteditable="true"] {
    -webkit-user-select: text !important;
    -moz-user-select: text !important;
    -ms-user-select: text !important;
    user-select: text !important;
}

/* =========================================
   V5 FREE-FLOATING TOP BAR ARCHITECTURE
   ========================================= */

.top-bar-layout {
    display: flex;
    align-items: stretch;
    gap: 16px;
    margin: 12px 16px 0 16px;
    height: var(--top-bar-height);
    flex-shrink: 0;
    position: relative;
    z-index: 30;
}

/* 1. Left Island: Navigation Bar (Aligned with Sidebar) */
header.nav-island {
    width: var(--sidebar-width);
    height: 100%;
    padding: 0 12px;
    margin: 0;
    border-radius: var(--radius-card);
    border: var(--glass-border);
    background: var(--surface-translucent);
    backdrop-filter: var(--glass-blur);
    -webkit-backdrop-filter: var(--glass-blur);
    box-shadow: var(--shadow-level-2), var(--glass-highlight);
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-shrink: 0;
    position: relative;
    transform: translateZ(0);
}

.brand-container {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    width: 100%;
    height: 100%;
}

.brand-logo {
    height: 38px;
    width: auto;
    margin: 0 0 0 2px;
    object-fit: contain;
    flex-shrink: 0;
    pointer-events: none;
    user-select: none;
    display: block;
}

.logo-dark {
    display: none;
}

body.dark-mode .logo-light {
    display: none;
}

body.dark-mode .logo-dark {
    display: block;
}

#appTitle {
    display: none;
}

/* Segmented Pill Navigation inside 300px Nav Island */
.nav-links {
    margin-left: auto;
    display: inline-flex;
    align-items: center;
    gap: 2px;
    padding: 3px;
    background: var(--md-sys-color-surface-container);
    border: 1px solid var(--md-sys-color-outline-variant);
    border-radius: var(--radius-full);
    box-shadow: inset 0 1px 2px rgba(0, 0, 0, 0.06);
}

body.dark-mode .nav-links {
    background: var(--md-sys-color-surface-container-lowest);
    border-color: rgba(255, 255, 255, 0.1);
    box-shadow: inset 0 1px 3px rgba(0, 0, 0, 0.35);
}

.nav-links .nav-tab {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 5px;
    padding: 6px 8px;
    border-radius: var(--radius-full);
    color: var(--text-muted);
    font-weight: 600;
    font-size: 0.8rem;
    font-family: var(--font-family);
    background: transparent;
    border: none;
    cursor: pointer;
    white-space: nowrap;
    transition: background-color 0.2s var(--m3-ease-standard),
                color 0.2s var(--m3-ease-standard),
                padding 0.25s var(--m3-ease-emphasized),
                box-shadow 0.2s var(--m3-ease-standard);
}

/* Collapse inactive tab text inside the 300px island so logo + 3 tabs fit cleanly */
.nav-links .nav-tab:not(.active) span:not(.material-symbols-rounded) {
    display: none;
}

.nav-links .nav-tab.active {
    padding: 6px 10px;
    background-color: var(--text-main);
    color: var(--bg-app);
    font-weight: 700;
    box-shadow: var(--shadow-level-1);
}

.nav-links .nav-tab .material-symbols-rounded {
    font-size: 1.1rem;
    line-height: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: transform 0.25s var(--m3-ease-spring);
}

.nav-links .nav-tab:hover {
    color: var(--text-main);
    background-color: var(--md-sys-color-surface-container-high);
}

.nav-links .nav-tab:active {
    border-radius: 12px;
}

.nav-links .nav-tab.active .material-symbols-rounded {
    transform: scale(1.08);
}

/* 3. Right Island: Free-Floating Settings Card */
.settings-wrapper.settings-island {
    width: var(--top-bar-height);
    height: 100%;
    border-radius: var(--radius-card);
    border: var(--glass-border);
    background: var(--surface-translucent);
    backdrop-filter: var(--glass-blur);
    -webkit-backdrop-filter: var(--glass-blur);
    box-shadow: var(--shadow-level-2), var(--glass-highlight);
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    position: relative;
    transform: translateZ(0);
}

.icon-btn {
    width: 42px;
    height: 42px;
    flex-shrink: 0;
    padding: 0;
    background: var(--md-sys-color-surface-container-high);
    border: none;
    color: var(--md-sys-color-on-surface-variant);
    cursor: pointer;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background-color 0.2s ease, color 0.2s ease, transform 0.15s ease, border-radius 0.2s ease;
}

.icon-btn:hover {
    background-color: var(--md-sys-color-surface-container-highest);
    color: var(--md-sys-color-on-surface);
    border-radius: 12px;
}

.icon-btn:active {
    transform: scale(0.94);
}

.settings-wrapper .icon-btn {
    position: relative;
	background: none !important;
}

.settings-wrapper .icon-btn .material-symbols-rounded {
    position: absolute;
    display: flex;
    align-items: center;
    justify-content: center;
    line-height: 1;
    pointer-events: none;
    transition: transform 0.35s var(--m3-ease-spring), opacity 0.25s ease;
}

.settings-wrapper .icon-btn .icon-gear {
    transform: rotate(0deg) scale(1);
    opacity: 1;
}

.settings-wrapper .icon-btn .icon-close {
    transform: rotate(-90deg) scale(0.5);
    opacity: 0;
}

body:has(#settingsMenu.open) .settings-wrapper .icon-btn .icon-gear {
    transform: rotate(90deg) scale(0.5);
    opacity: 0;
}

body:has(#settingsMenu.open) .settings-wrapper .icon-btn .icon-close {
    transform: rotate(0deg) scale(1);
    opacity: 1;
}

/* =========================================
   TWO-COLUMN SETTINGS MENU
   ========================================= */

.settings-menu {
    position: absolute;
    top: 84px;
    right: 16px;
    background: var(--surface-translucent);
    backdrop-filter: var(--glass-blur);
    -webkit-backdrop-filter: var(--glass-blur);
    border: var(--glass-border);
    border-radius: var(--radius-card);
    padding: 16px 18px;
    display: flex;
    flex-direction: column;
    width: 500px;
    max-width: calc(100vw - 32px);
    max-height: calc(100vh - 100px);
    overflow-y: auto;
    box-shadow: var(--shadow-level-3), var(--glass-highlight);
    z-index: 100;
    transform: translateY(-10px) scale(0.98) translateZ(0);
    opacity: 0;
    visibility: hidden;
    pointer-events: none;
    transition: opacity 0.28s var(--m3-ease-emphasized),
                visibility 0.28s,
                transform 0.38s var(--m3-ease-spring);
}

.settings-menu.open {
    opacity: 1;
    visibility: visible;
    pointer-events: auto;
    transform: translateY(0) scale(1) translateZ(0);
}

.menu-two-col {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 16px;
}

.menu-col {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.menu-col .control-group {
    margin-bottom: 10px;
}

.menu-col-title {
    font-size: 0.72rem;
    font-weight: 700;
    text-transform: uppercase;
    color: var(--text-muted);
    letter-spacing: 0.5px;
    margin-bottom: 8px;
    padding-left: 4px;
}

.menu-divider {
    height: 1px;
    background: var(--md-sys-color-surface-container-high);
    border: none;
    margin: 12px 0 10px 0;
}

.menu-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 6px 10px;
}

.menu-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 10px 14px;
    font-size: 0.88rem;
    font-weight: 600;
    font-family: var(--font-family);
    color: var(--text-main);
    background: transparent;
    border: none;
    cursor: pointer;
    border-radius: var(--radius-button) !important;
    text-align: left;
    margin: 0;
    width: 100%;
    transition: background-color 0.2s ease, color 0.2s ease;
}

.menu-item:hover {
    background-color: var(--md-sys-color-surface-container-high);
}

.menu-item:active {
    border-radius: 11px !important;
}

.menu-item .material-symbols-rounded {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 24px;
    height: 24px;
    font-size: 22px;
    line-height: 1;
    flex-shrink: 0;
    pointer-events: none;
}

.menu-item > span {
    pointer-events: none;
}

.menu-item:disabled {
    opacity: 0.35;
    pointer-events: none !important;
    cursor: not-allowed;
    background: transparent !important;
}

.menu-item.active-toggle {
    background-color: var(--md-sys-color-surface-container-highest);
    color: var(--color-primary);
    border-radius: 10px !important;
}

.menu-item.active-toggle .material-symbols-rounded {
    color: var(--color-primary);
}

/* Candidate Portrait Upload Pills (Light Mode) */
.menu-item.menu-item-dem {
    background: rgba(21, 101, 216, 0.18);
    border: 1px solid rgba(21, 101, 216, 0.38);
    color: var(--color-primary);
    margin-bottom: 6px;
}

.menu-item.menu-item-dem .material-symbols-rounded {
    color: var(--color-primary);
}

.menu-item.menu-item-dem:hover {
    background: rgba(26, 115, 232, 0.22);
    border-radius: var(--radius-material-active);
}

.menu-item.menu-item-rep {
    background: rgba(224, 45, 45, 0.18);
    border: 1px solid rgba(224, 45, 45, 0.38);
    color: var(--color-secondary);
}

.menu-item.menu-item-rep .material-symbols-rounded {
    color: var(--color-secondary);
}

.menu-item.menu-item-rep:hover {
    background: rgba(234, 67, 53, 0.22);
    border-radius: var(--radius-material-active);
}

body.dark-mode .menu-item.menu-item-dem {
    background: rgba(59, 130, 246, 0.18);
    border-color: rgba(59, 130, 246, 0.32);
}

body.dark-mode .menu-item.menu-item-dem:hover {
    background: rgba(59, 130, 246, 0.28);
    border-radius: var(--radius-material-active);
}

body.dark-mode .menu-item.menu-item-rep {
    background: rgba(239, 68, 68, 0.18);
    border-color: rgba(239, 68, 68, 0.32);
}

body.dark-mode .menu-item.menu-item-rep:hover {
    background: rgba(239, 68, 68, 0.28);
    border-radius: var(--radius-material-active);
}

/* Clear Portrait Button (X) */
.clear-portrait-btn {
    margin-left: auto;
    width: 24px;
    height: 24px;
    border-radius: 50%;
    background: transparent;
    border: none;
    padding: 0;
    cursor: pointer;
    display: none;
    align-items: center;
    justify-content: center;
    color: var(--text-muted);
    opacity: 0.75;
    pointer-events: auto !important;
    z-index: 2;
    transition: background-color 0.2s ease, opacity 0.2s ease, color 0.2s ease, transform 0.15s ease;
}

.clear-portrait-btn.visible {
    display: inline-flex !important;
}

.clear-portrait-btn:hover {
    opacity: 1;
    transform: scale(1.1);
}

.clear-portrait-btn * {
    pointer-events: none;
}

.clear-portrait-btn .material-symbols-rounded {
    font-size: 16px !important;
    line-height: 1;
}

.menu-item-dem .clear-portrait-btn:hover {
    color: var(--color-primary);
    background: rgba(26, 115, 232, 0.2);
}

.menu-item-rep .clear-portrait-btn:hover {
    color: var(--color-secondary);
    background: rgba(234, 67, 53, 0.2);
}

body.dark-mode .menu-item.menu-item-dem .clear-portrait-btn:hover {
    background: rgba(59, 130, 246, 0.28);
}

body.dark-mode .menu-item.menu-item-rep .clear-portrait-btn:hover {
    background: rgba(239, 68, 68, 0.28);
}

/* =========================================
   V6 CUSTOMIZATION & SCENARIO SWITCHER UI
   ========================================= */

/* Unified 3-Slot Candidate Portrait & Name Field */
.portrait-slots-field {
    display: flex;
    flex-direction: column;
    gap: 6px;
    padding: 6px;
    border-radius: 20px;
    background: var(--md-sys-color-surface-container);
    border: 1px solid var(--md-sys-color-outline-variant);
    margin-bottom: 6px;
}

body.dark-mode .portrait-slots-field {
    background: var(--md-sys-color-surface-container-lowest);
    border-color: rgba(255, 255, 255, 0.08);
}

.candidate-custom-row {
    display: flex;
    align-items: center;
    gap: 6px;
    width: 100%;
}

.portrait-btn-wrap {
    position: relative;
    width: 38px;
    height: 38px;
    flex-shrink: 0;
}

.portrait-icon-btn {
    width: 100%;
    height: 100%;
    border-radius: 50%;
    padding: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    position: relative;
    overflow: hidden;
    transition: border-radius 0.22s var(--m3-ease-spring),
                background-color 0.2s ease,
                transform 0.15s ease,
                border-color 0.2s ease;
}

.portrait-icon-btn:hover {
    border-radius: var(--radius-material-active);
}

.portrait-icon-btn:active {
    transform: scale(0.93);
}

.portrait-icon-btn .material-symbols-rounded {
    font-size: 19px !important;
    line-height: 1;
    pointer-events: none;
}

.portrait-btn-thumb {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
    pointer-events: none;
}

.portrait-icon-btn.has-photo .material-symbols-rounded {
    display: none;
}

/* Partisan Colors for Portrait Icon Button */
.portrait-icon-btn.dem {
    background: rgba(21, 101, 216, 0.18);
    border: 1px solid rgba(21, 101, 216, 0.38);
    color: var(--color-primary);
}
.portrait-icon-btn.dem:hover {
    background: rgba(26, 115, 232, 0.26);
}

.portrait-icon-btn.rep {
    background: rgba(224, 45, 45, 0.18);
    border: 1px solid rgba(224, 45, 45, 0.38);
    color: var(--color-secondary);
}
.portrait-icon-btn.rep:hover {
    background: rgba(234, 67, 53, 0.26);
}

.portrait-icon-btn.yel {
    background: rgba(229, 136, 0, 0.18);
    border: 1px solid rgba(229, 136, 0, 0.38);
    color: var(--color-warning);
}
.portrait-icon-btn.yel:hover {
    background: rgba(245, 158, 11, 0.26);
}

body.dark-mode .portrait-icon-btn.dem {
    background: rgba(59, 130, 246, 0.18);
    border-color: rgba(59, 130, 246, 0.32);
}
body.dark-mode .portrait-icon-btn.rep {
    background: rgba(239, 68, 68, 0.18);
    border-color: rgba(239, 68, 68, 0.32);
}
body.dark-mode .portrait-icon-btn.yel {
    background: rgba(251, 191, 36, 0.16);
    border-color: rgba(251, 191, 36, 0.32);
}

/* Floating Corner Clear Portrait Badge (×) */
.portrait-btn-wrap .clear-portrait-btn {
    position: absolute;
    top: -3px;
    right: -3px;
    width: 16px;
    height: 16px;
    border-radius: 50%;
    background: var(--md-sys-color-surface-container-highest);
    border: 1.5px solid var(--md-sys-color-surface);
    color: var(--text-muted);
    box-shadow: var(--shadow-level-1);
    padding: 0;
    cursor: pointer;
    display: none;
    align-items: center;
    justify-content: center;
    z-index: 4;
    opacity: 0.95;
    transition: background-color 0.16s ease, color 0.16s ease, transform 0.16s var(--m3-ease-spring);
}

.portrait-btn-wrap .clear-portrait-btn.visible {
    display: inline-flex !important;
}

.portrait-btn-wrap .clear-portrait-btn:hover {
    background: var(--color-secondary) !important;
    color: #ffffff !important;
    border-color: var(--color-secondary) !important;
    transform: scale(1.15);
}

.portrait-btn-wrap .clear-portrait-btn .material-symbols-rounded {
    font-size: 11px !important;
    font-weight: 800;
    line-height: 1;
}

/* Candidate Name Button (Right Side of Row) */
.portrait-slots-field .menu-item.candidate-name-btn {
    flex: 1;
    min-width: 0;
    height: 38px;
    margin-bottom: 0 !important;
    padding: 0 12px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
}

.candidate-name-btn .cand-btn-text {
    font-size: 0.82rem;
    font-weight: 700;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.candidate-name-btn .edit-name-icon {
    width: 16px !important;
    height: 16px !important;
    font-size: 16px !important;
    opacity: 0.7;
    flex-shrink: 0;
}

.candidate-name-btn:hover .edit-name-icon {
    opacity: 1;
}

/* 3rd Party Portrait Pill (Yellow/Amber) */
.menu-item.menu-item-yel {
    background: rgba(229, 136, 0, 0.18);
    border: 1px solid rgba(229, 136, 0, 0.38);
    color: var(--color-warning);
}

.menu-item.menu-item-yel .material-symbols-rounded {
    color: var(--color-warning);
}

.menu-item.menu-item-yel:hover {
    background: rgba(245, 158, 11, 0.24);
    border-radius: var(--radius-material-active);
}

body.dark-mode .menu-item.menu-item-yel {
    background: rgba(251, 191, 36, 0.16);
    border-color: rgba(251, 191, 36, 0.32);
}

body.dark-mode .menu-item.menu-item-yel:hover {
    background: rgba(251, 191, 36, 0.26);
    border-radius: var(--radius-material-active);
}

.menu-item-yel .clear-portrait-btn:hover {
    color: var(--color-warning);
    background: rgba(245, 158, 11, 0.22);
}

/* Inactive / Disabled state for 3rd Party Portrait when 3rd Party is off */
.portrait-slot-yel.disabled-slot {
    opacity: 0.38;
    pointer-events: none;
    filter: grayscale(0.45);
}

/* 3rd Party Top-Bar Avatar Border */
#avatarYel {
    border-color: var(--color-warning);
}

/* Half-Width Import & Export Button Row (Matches General Options Grid) */
.scenario-btn-row {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 6px 10px;
    width: 100%;
    margin-top: 2px;
}

.scenario-btn-row .scenario-half-btn {
    justify-content: flex-start;
    padding: 10px 12px;
    gap: 10px;
    background: transparent;
    border: none;
    border-radius: var(--radius-button) !important;
    transition: background-color 0.2s ease, color 0.2s ease, border-radius 0.15s ease;
}

.scenario-btn-row .scenario-half-btn:hover {
    background-color: var(--md-sys-color-surface-container-high);
}

.scenario-btn-row .scenario-half-btn:active {
    border-radius: 11px !important;
}

/* Imported Scenarios Dropdown inside General Options Grid */
.menu-scenario-select-wrap {
    position: relative;
    display: flex;
    align-items: center;
    width: 100%;
}

.menu-scenario-icon {
    position: absolute;
    left: 14px;
    font-size: 20px !important;
    color: var(--text-main);
    pointer-events: none;
    z-index: 2;
    transition: opacity 0.2s ease, color 0.2s ease;
}

.menu-scenario-select-wrap:has(select:disabled) .menu-scenario-icon {
    opacity: 0.35;
}

.settings-menu select.menu-scenario-select {
    width: 100%;
    height: 100%;
    padding: 10px 32px 10px 44px;
    font-size: 0.86rem;
    font-weight: 600;
    border-radius: var(--radius-button);
    background-color: var(--md-sys-color-surface-container-high);
    border: 1px solid var(--md-sys-color-outline-variant);
    color: var(--text-main);
    text-overflow: ellipsis;
}

.settings-menu select.menu-scenario-select:disabled {
    opacity: 0.4;
    cursor: not-allowed;
    background-color: transparent;
    border-color: transparent;
}

/* Inline Delete Button on Scenario Select Wrapper & M3 Popover Options */

.m3-option-delete-btn {
    margin-left: auto;
    width: 22px;
    height: 22px;
    border-radius: 50%;
    border: none;
    background: transparent;
    color: var(--text-muted);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    padding: 0;
    flex-shrink: 0;
    opacity: 0.65;
    transition: background-color 0.18s ease, color 0.18s ease, opacity 0.18s ease, transform 0.15s ease;
}

.m3-option-delete-btn:hover {
    opacity: 1;
    background: rgba(224, 45, 45, 0.18);
    color: var(--color-secondary);
    transform: scale(1.12);
}

.m3-option-delete-btn .material-symbols-rounded {
    font-size: 15px !important;
    line-height: 1;
    pointer-events: none;
}

/* Compact Settings Menu Footer */
.menu-footer-version {
    padding: 10px 16px 4px 16px;
    font-size: 0.74rem;
    font-weight: 600;
    color: var(--text-muted);
    opacity: 0.85;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    letter-spacing: 0.3px;
}

.menu-footer-version .footer-sep {
    opacity: 0.45;
}

.menu-footer-version .credits-trigger-link {
    color: var(--color-primary);
    text-decoration: none;
    font-weight: 700;
    cursor: pointer;
    transition: opacity 0.2s ease, text-decoration 0.2s ease;
}

.menu-footer-version .credits-trigger-link:hover {
    text-decoration: underline;
    text-underline-offset: 3px;
    opacity: 1;
}

.menu-footer-credit {
    display: inline-block;
    margin-top: 2px;
}

.menu-footer-version a {
    color: inherit;
    text-decoration: underline;
    text-underline-offset: 2px;
    transition: color 0.2s ease;
}

.menu-footer-version a:hover {
    color: var(--text-main);
}

/* Credits Dialog Formatting */
.m3-dialog.m3-credits-dialog {
    max-width: 430px;
}

.m3-dialog-info-icon {
    font-size: 1.85rem !important;
    color: var(--color-primary) !important;
    line-height: 1;
    flex-shrink: 0;
}

.m3-credits-list {
    display: flex;
    flex-direction: column;
    gap: 10px;
    margin-top: 2px;
}

.m3-credit-item {
    padding: 10px 12px;
    border-radius: 16px;
    background: var(--md-sys-color-surface-container-high);
    border: 1px solid var(--md-sys-color-outline-variant);
}

body.dark-mode .m3-credit-item {
    background: var(--md-sys-color-surface-container-lowest);
    border-color: rgba(255, 255, 255, 0.08);
}

.m3-credit-heading {
    font-size: 0.78rem;
    font-weight: 800;
    color: var(--text-main);
    margin-bottom: 3px;
    letter-spacing: 0.2px;
}

.m3-credit-body {
    font-size: 0.78rem;
    font-weight: 500;
    color: var(--text-muted);
    line-height: 1.45;
    margin: 0;
}

.m3-credit-body a {
    color: var(--color-primary);
    font-weight: 600;
    text-decoration: underline;
    text-underline-offset: 2px;
}

.m3-credit-body a:hover {
    opacity: 0.85;
}

.m3-credits-list {
    max-height: min(60dvh, 420px);
    overflow-y: auto;
    padding-right: 4px;
}

.m3-credit-sublist {
    margin: 6px 0;
    padding-left: 18px;
    font-size: 0.78rem;
    font-weight: 500;
    color: var(--text-muted);
    line-height: 1.45;
}

.m3-credit-sublist li {
    margin-bottom: 3px;
}

.m3-credit-sublist strong,
.m3-credit-body strong {
    color: var(--text-main);
    font-weight: 700;
}

.m3-credit-sublist a {
    color: var(--color-primary);
    font-weight: 600;
    text-decoration: underline;
    text-underline-offset: 2px;
}

.m3-credit-sublist a:hover {
    opacity: 0.85;
}

/* =========================================
   M3 EXPRESSIVE CUSTOM DROPDOWN POPOVER
   ========================================= */

/* Prevent native OS popup when custom M3 menu is active on desktop */
select.m3-select-enhanced {
    pointer-events: auto;
}

.m3-select-popover {
    position: fixed;
    z-index: 3000;
    background: var(--surface-translucent-card);
    backdrop-filter: var(--glass-blur);
    -webkit-backdrop-filter: var(--glass-blur);
    border: var(--glass-border);
    border-radius: 22px;
    box-shadow: var(--shadow-level-3), var(--glass-highlight);
    padding: 6px;
    max-height: 280px;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 2px;
    opacity: 0;
    visibility: hidden;
    transform: translateY(-8px) scale(0.96);
    transform-origin: top center;
    transition: opacity 0.2s var(--m3-ease-standard),
                transform 0.3s var(--m3-ease-spring),
                visibility 0.2s;
}

.m3-select-popover.open {
    opacity: 1;
    visibility: visible;
    transform: translateY(0) scale(1);
}

.m3-select-option {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    width: 100%;
    padding: 9px 14px;
    border: none;
    border-radius: var(--radius-button);
    background: transparent;
    color: var(--text-main);
    font-family: var(--font-family);
    font-size: 0.85rem;
    font-weight: 600;
    text-align: left;
    cursor: pointer;
    white-space: nowrap;
    transition: background-color 0.15s ease, color 0.15s ease, border-radius 0.15s ease;
}

.m3-select-option:hover {
    background-color: var(--md-sys-color-surface-container-high);
}

.m3-select-option:active {
    border-radius: 10px;
}

.m3-select-option.selected {
    background-color: var(--md-sys-color-surface-container-highest);
    color: var(--color-primary);
    font-weight: 700;
}

.m3-select-option.selected::after {
    content: 'check';
    font-family: 'Material Symbols Rounded';
    font-size: 18px;
    line-height: 1;
    color: var(--color-primary);
}

/* Slim scrollbar inside the dropdown popover */
.m3-select-popover::-webkit-scrollbar {
    width: 5px;
}
.m3-select-popover::-webkit-scrollbar-track {
    margin: 10px 0;
    background: transparent;
}
.m3-select-popover::-webkit-scrollbar-thumb {
    background-color: var(--md-sys-color-outline-variant);
    border-radius: var(--radius-full);
}

.m3-select-popover.flip-up {
    transform: translateY(8px) scale(0.96);
    transform-origin: bottom center;
}

.m3-select-option {
    overflow: hidden;
    text-overflow: ellipsis;
}

/* =========================================
   MENU ACCORDION & ENVIRONMENT SHIFT TOOLS
   ========================================= */

.menu-accordion-group {
    display: flex;
    flex-direction: column;
    width: 100%;
    margin-top: 2px;
    margin-bottom: 6px;
}

.menu-accordion-group label {
    display: block;
    font-size: 0.8rem;
    font-weight: 600;
    color: var(--text-muted);
    margin-bottom: 6px;
}

.menu-accordion-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    width: 100%;
    padding: 8px 14px;
    border-radius: var(--radius-button);
    background: var(--md-sys-color-surface-container-high);
    border: 1px solid var(--md-sys-color-outline-variant);
    color: var(--text-main);
    font-family: var(--font-family);
    font-size: 0.88rem;
    font-weight: 600;
    cursor: pointer;
    transition: background-color 0.2s ease, border-color 0.2s ease, color 0.2s ease;
}

.menu-accordion-header:hover {
    background-color: var(--md-sys-color-surface-container-highest);
    border-color: var(--md-sys-color-outline);
    border-radius: var(--radius-material-active);
}

.menu-accordion-header:active {
    border-radius: var(--radius-material-active);
}

.menu-accordion-header.open {
    background-color: var(--md-sys-color-surface-container-highest);
    border-color: var(--color-primary);
}

.menu-accordion-title {
    display: flex;
    align-items: center;
    gap: 8px;
    pointer-events: none;
}

.menu-accordion-icon {
    font-size: 1.15rem;
    color: var(--color-primary);
    line-height: 1;
}

.menu-accordion-chevron {
    font-size: 1.25rem;
    color: var(--text-muted);
    line-height: 1;
    pointer-events: none;
    transition: transform 0.35s var(--m3-ease-spring);
}

.menu-accordion-header.open .menu-accordion-chevron {
    transform: rotate(180deg);
}

/* 1. Make the Vote Shift submenu span across both columns into the space under Import/Export */
.menu-col .menu-accordion-drawer {
    width: calc(200% + 16px); /* 2x column width + 16px grid gap */
    box-sizing: border-box;
    max-height: 0;
    opacity: 0;
    overflow: hidden;
    visibility: hidden;
    transform: translateY(-6px);
    transition: max-height 0.35s var(--m3-ease-emphasized),
                opacity 0.25s ease,
                transform 0.35s var(--m3-ease-emphasized),
                padding 0.35s var(--m3-ease-emphasized),
                visibility 0.35s;
    padding: 0 4px;
    display: flex;
    flex-direction: column;
}

.menu-col .menu-accordion-drawer.open {
    max-height: 320px;
    opacity: 1;
    visibility: visible;
    transform: translateY(0);
    padding: 12px 4px 4px 4px;
}

/* 2. Lock equal 50/50 column widths so .5 decimals never cause layout jitter */
.state-env-grid {
    display: grid;
    grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
    gap: 12px;
    width: 100%;
}

.nat-env-tool {
    width: 100%;
    box-sizing: border-box;
}

.nat-env-tool .nat-env-display {
    flex: 1;
    min-width: 68px; /* Reserves room for "OTH+12.5" / "BASELINE" without resizing */
    text-align: center;
    font-weight: 800;
    font-size: 0.95rem;
    letter-spacing: 0.5px;
    font-variant-numeric: tabular-nums;
    white-space: nowrap;
    color: inherit;
}

/* 3. Keep 100% width on narrow mobile portrait where .menu-two-col stacks to 1 column */
@media (max-width: 600px) and (orientation: portrait) {
    .menu-col .menu-accordion-drawer {
        width: 100%;
    }
}

.menu-sub-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    width: 100%;
    padding: 8px 12px;
    border-radius: var(--radius-button);
    background: var(--md-sys-color-surface-container-high);
    border: 1px solid var(--md-sys-color-outline-variant);
    color: var(--text-muted);
    font-family: var(--font-family);
    font-size: 0.78rem;
    font-weight: 700;
    cursor: pointer;
    transition: background-color 0.2s ease, color 0.2s ease, transform 0.15s ease, border-color 0.2s ease;
}

.menu-sub-btn:hover {
    background-color: var(--md-sys-color-surface-container-highest);
    color: var(--text-main);
    border-color: var(--md-sys-color-outline);
}

.menu-sub-btn:active {
    transform: scale(0.97);
}

.menu-sub-btn .material-symbols-rounded {
    font-size: 1.05rem;
    line-height: 1;
}

.menu-sub-btn:disabled {
    opacity: 0.35;
    pointer-events: none;
    cursor: not-allowed;
}

/* National Environment & Turnout Shift Controls */
.nat-env-tool {
    display: flex;
    align-items: center;
    justify-content: space-between;
    height: 40px;
    padding: 3px 6px;
    background: var(--md-sys-color-surface-container-high);
    border: 1px solid var(--md-sys-color-outline-variant);
    border-radius: var(--radius-button);
    box-shadow: inset 0 1px 2px rgba(0, 0, 0, 0.06);
    color: var(--text-main);
    transition: background-color 0.25s ease, border-color 0.25s ease, opacity 0.25s ease, color 0.25s ease;
}

.nat-env-tool .nat-env-display {
    flex: 1;
    text-align: center;
    font-weight: 800;
    font-size: 0.95rem;
    letter-spacing: 0.5px;
    color: inherit;
}

.nat-env-btn {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    border: none;
    background: transparent;
    color: inherit;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    padding: 0;
    transition: background-color 0.2s ease, transform 0.15s ease;
}

.nat-env-btn:hover {
    background-color: rgba(0, 0, 0, 0.08);
}

body.dark-mode .nat-env-btn:hover {
    background-color: rgba(255, 255, 255, 0.12);
}

.nat-env-btn:active {
    transform: scale(0.92);
}

.nat-env-btn .material-symbols-rounded {
    font-size: 20px;
    line-height: 1;
}

/* Partisan & Turnout Tinting */
.nat-env-tool.dem-lead {
    background: rgba(26, 115, 232, 0.12);
    border-color: rgba(26, 115, 232, 0.3);
    color: var(--color-primary);
}

body.dark-mode .nat-env-tool.dem-lead {
	background: var(--md-sys-color-surface-container-lowest);
    /* background: rgba(59, 130, 246, 0.18);*/
    border-color: rgba(59, 130, 246, 0.35);
    color: var(--color-primary);
}

.nat-env-tool.rep-lead {
    background: rgba(234, 67, 53, 0.12);
    border-color: rgba(234, 67, 53, 0.3);
    color: var(--color-secondary);
}

body.dark-mode .nat-env-tool.rep-lead {
    background: var(--md-sys-color-surface-container-lowest);
	/* background: rgba(239, 68, 68, 0.18);*/
    border-color: rgba(239, 68, 68, 0.35);
    color: var(--color-secondary);
}

.nat-env-tool.yel-lead,
.nat-env-tool.down-turnout {
    background: rgba(245, 158, 11, 0.14);
    border-color: rgba(245, 158, 11, 0.32);
    color: var(--color-warning);
}

body.dark-mode .nat-env-tool.yel-lead,
body.dark-mode .nat-env-tool.down-turnout {
    background: var(--md-sys-color-surface-container-lowest);
	/* background: rgba(251, 191, 36, 0.18); */
    border-color: rgba(251, 191, 36, 0.35);
    color: var(--color-warning);
}

.nat-env-tool.up-turnout {
    background: rgba(30, 142, 62, 0.12);
    border-color: rgba(30, 142, 62, 0.3);
    color: var(--color-tertiary);
}

body.dark-mode .nat-env-tool.up-turnout {
    background: rgba(52, 211, 153, 0.18);
    border-color: rgba(52, 211, 153, 0.35);
    color: var(--color-tertiary);
}

.nat-env-tool.disabled {
    opacity: 0.35;
    pointer-events: none !important;
    cursor: not-allowed;
    background: var(--md-sys-color-surface-container-high) !important;
    border-color: var(--md-sys-color-outline-variant) !important;
    color: var(--text-muted) !important;
}

.nat-env-tool.disabled .nat-env-btn {
    pointer-events: none !important;
}

.nat-env-tool.compact-env-tool {
    height: 32px;
    padding: 2px 3px;
}

.nat-env-tool.compact-env-tool .nat-env-btn {
    width: 26px;
    height: 26px;
}

.nat-env-tool.compact-env-tool .nat-env-btn .material-symbols-rounded {
    font-size: 18px;
}

.nat-env-tool.compact-env-tool .nat-env-display {
    font-size: 0.78rem;
    letter-spacing: 0.2px;
}

/* =========================================
   2. CENTER TALLY STACK (EV + PV SHARED FOOTPRINT)
   ========================================= */

.tally-stack {
    flex: 1;
    min-width: 0;
    height: 100%;
    display: flex;
    flex-direction: column;
    justify-content: flex-start;
    position: relative;
    z-index: 25;
}

.tally-wrapper {
    width: 100%;
    height: var(--top-bar-height);
    margin: 0;
    border-radius: var(--radius-card);
    border: var(--glass-border);
    background: var(--surface-translucent);
    backdrop-filter: var(--glass-blur);
    -webkit-backdrop-filter: var(--glass-blur);
    box-shadow: var(--shadow-level-2), var(--glass-highlight);
    position: relative;
    flex-shrink: 0;
    overflow: hidden;
    z-index: 25;
    transform: translateZ(0);
    transition: height 0.38s var(--m3-ease-emphasized),
                border-radius 0.38s var(--m3-ease-emphasized);
}

/* Shrink EV Tally Bar when PV Mode is active on the President view so both share the 64px height */
body[data-view="president"] .tally-stack:has(#pvTallyContainer.visible) .tally-wrapper {
    height: 44px;
    border-radius: 22px;
}

/* Uncalled Tally Bar Background (More visible track in Light Mode) */
.tally-bar-bg {
    position: absolute;
    inset: 0;
    background: var(--color-uncalled);
    opacity: 0.55;
}

body.dark-mode .tally-bar-bg {
    opacity: 0.3;
}

.tally-fill {
    height: 100%;
    position: absolute;
    top: 0;
    transition: width 0.7s var(--m3-ease-emphasized), left 0.7s var(--m3-ease-emphasized);
}

.tally-fill.dem {
    background-color: var(--color-primary);
    left: 0;
}

.tally-fill.rep {
    background-color: var(--color-secondary);
    right: 0;
}

.tally-fill.yel {
    background-color: var(--color-warning);
    transform: none !important;
}

.tally-content {
    position: relative;
    height: 100%;
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0 16px;
    z-index: 2;
    transition: padding 0.38s var(--m3-ease-emphasized);
}

body[data-view="president"] .tally-stack:has(#pvTallyContainer.visible) .tally-content {
    padding: 0 10px;
}

.center-marker {
    position: absolute;
    left: 50%;
    top: 0;
    bottom: 0;
    transform: translateX(-50%);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    z-index: 3;
    pointer-events: none;
}

.marker-line {
    width: 2px;
    height: 100%;
    background: var(--text-muted);
    opacity: 0.2;
}

.marker-label {
    position: absolute;
    background: var(--surface-translucent);
    backdrop-filter: var(--glass-blur);
    -webkit-backdrop-filter: var(--glass-blur);
    color: var(--text-muted);
    font-size: 0.72rem;
    font-weight: 700;
    padding: 3px 10px;
    border-radius: var(--radius-full);
    white-space: nowrap;
    box-shadow: var(--elevation-1);
    border: var(--glass-border);
    transition: opacity 0.3s ease, padding 0.38s var(--m3-ease-emphasized), font-size 0.38s var(--m3-ease-emphasized);
}

body[data-view="president"] .tally-stack:has(#pvTallyContainer.visible) .marker-label {
    font-size: 0.65rem;
    padding: 2px 8px;
}

.marker-label.subdued,
.tally-wrapper:has(#groupYel.visible) .marker-label {
    opacity: 0.05;
}

/* Score Group & Frosted Pill Containers */
.score-group {
    display: flex;
    align-items: center;
    gap: 10px;
    z-index: 4;
    transition: gap 0.38s var(--m3-ease-emphasized);
}

body[data-view="president"] .tally-stack:has(#pvTallyContainer.visible) .score-group {
    gap: 8px;
}

#groupYel {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    opacity: 0;
    visibility: hidden;
    pointer-events: none;
    z-index: 4;
    transition: opacity 0.3s var(--m3-ease-emphasized), visibility 0.3s;
}

#groupYel.visible {
    opacity: 1;
    visibility: visible;
    pointer-events: auto;
}

.pill-info {
    display: inline-flex;
    flex-direction: row;
    align-items: center;
    gap: 8px;
    height: 44px;
    padding: 0 14px;
    backdrop-filter: var(--glass-blur);
    -webkit-backdrop-filter: var(--glass-blur);
    border-radius: var(--radius-full);
    box-shadow: var(--shadow-level-1), var(--glass-highlight);
    white-space: nowrap;
    transition: height 0.38s var(--m3-ease-emphasized),
                padding 0.38s var(--m3-ease-emphasized),
                gap 0.38s var(--m3-ease-emphasized),
                background-color 0.25s ease,
                border-color 0.25s ease,
                box-shadow 0.2s ease;
}

body[data-view="president"] .tally-stack:has(#pvTallyContainer.visible) .pill-info {
    height: 32px;
    padding: 0 10px;
    gap: 6px;
}

#groupDem .pill-info {
    background: rgba(26, 115, 232, 0.12);
    border: 1px solid rgba(26, 115, 232, 0.25);
}

#groupRep .pill-info {
    flex-direction: row-reverse;
    background: rgba(234, 67, 53, 0.12);
    border: 1px solid rgba(234, 67, 53, 0.25);
}

#groupYel .pill-info {
    background: rgba(245, 158, 11, 0.14);
    border: 1px solid rgba(245, 158, 11, 0.28);
}

body.dark-mode #groupDem .pill-info {
    background: rgba(59, 130, 246, 0.18);
    border: 1px solid rgba(59, 130, 246, 0.32);
}

body.dark-mode #groupRep .pill-info {
    background: rgba(239, 68, 68, 0.18);
    border: 1px solid rgba(239, 68, 68, 0.32);
}

body.dark-mode #groupYel .pill-info {
    background: rgba(251, 191, 36, 0.18);
    border: 1px solid rgba(251, 191, 36, 0.32);
}

.pill-title {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    font-size: 0.82rem;
    font-weight: 700;
    color: var(--text-main) !important;
    letter-spacing: 0.5px;
    opacity: 0.85;
    transition: font-size 0.38s var(--m3-ease-emphasized);
}

body[data-view="president"] .tally-stack:has(#pvTallyContainer.visible) .pill-title {
    font-size: 0.74rem;
}

.edit-label-btn {
    background: transparent;
    border: none;
    color: var(--text-main) !important;
    cursor: pointer;
    padding: 0;
    margin-left: 2px;
    display: none;
    align-items: center;
    opacity: 0.65;
    transition: opacity 0.2s ease, color 0.2s ease;
}

.edit-label-btn:hover {
    opacity: 1;
}

.edit-label-btn span {
    font-size: 0.9rem;
    transition: font-size 0.38s var(--m3-ease-emphasized);
}

body[data-view="president"] .tally-stack:has(#pvTallyContainer.visible) .edit-label-btn span {
    font-size: 0.8rem;
}

@media (hover: none) {
    .edit-label-btn {
        opacity: 1 !important;
        background: var(--md-sys-color-surface-container-highest);
    }
}

.score {
    display: inline-flex;
    align-items: center;
    font-size: 1.85rem !important;
    font-weight: 900;
    line-height: 1;
    letter-spacing: -0.5px;
    padding-left: 8px;
    color: var(--text-main) !important;
    border-left: 1.5px solid var(--md-sys-color-outline-variant);
    text-shadow: 0 1px 2px rgba(0, 0, 0, 0.12);
    transition: font-size 0.38s var(--m3-ease-emphasized),
                padding 0.38s var(--m3-ease-emphasized),
                border-color 0.2s ease,
                color 0.2s ease;
}

#groupYel .score {
    font-size: 1.7rem !important;
}

#groupRep .pill-info .score {
    padding-left: 0;
    padding-right: 8px;
    border-left: none;
    border-right: 1.5px solid var(--md-sys-color-outline-variant);
}

body[data-view="president"] .tally-stack:has(#pvTallyContainer.visible) .score {
    font-size: 1.35rem !important;
    padding-left: 6px;
}

body[data-view="president"] .tally-stack:has(#pvTallyContainer.visible) #groupYel .score {
    font-size: 1.25rem !important;
}

body[data-view="president"] .tally-stack:has(#pvTallyContainer.visible) #groupRep .pill-info .score {
    padding-left: 0;
    padding-right: 6px;
}

.score-group.filled .pill-info {
    box-shadow: var(--shadow-level-1);
}

#groupDem.score-group.filled .score,
#groupDem.score-group.filled .pill-title,
#groupDem.score-group.filled .pill-title span,
#groupDem.score-group.filled .edit-label-btn,
#groupRep.score-group.filled .score,
#groupRep.score-group.filled .pill-title,
#groupRep.score-group.filled .pill-title span,
#groupRep.score-group.filled .edit-label-btn {
    color: #ffffff !important;
}

#groupYel.score-group.filled .score,
#groupYel.score-group.filled .pill-title,
#groupYel.score-group.filled .pill-title span,
#groupYel.score-group.filled .edit-label-btn {
    color: currentcolor !important;
    text-shadow: none !important;
}

/* Candidate Portraits */
.candidate-avatar {
    width: 44px;
    height: 44px;
    border-radius: 22px;
    object-fit: cover;
    box-shadow: var(--shadow-level-1);
    border: 2px solid transparent;
    flex-shrink: 0;
    transition: width 0.38s var(--m3-ease-emphasized),
                height 0.38s var(--m3-ease-emphasized),
                border-radius 0.3s var(--m3-ease-spring),
                transform 0.2s ease;
}

body[data-view="president"] .tally-stack:has(#pvTallyContainer.visible) .candidate-avatar {
    width: 32px;
    height: 32px;
    border-radius: 16px;
}

.candidate-avatar:hover {
    border-radius: 12px;
    transform: scale(1.04);
}

#avatarDem {
    border-color: var(--color-primary);
}

#avatarRep {
    border-color: var(--color-secondary);
}

/* Victory Badge */
.victory-badge {
    background: rgba(30, 142, 62, 0.90);
    backdrop-filter: var(--glass-blur);
    -webkit-backdrop-filter: var(--glass-blur);
    border: 1px solid rgba(255, 255, 255, 0.4);
    color: #ffffff;
    padding: 5px 12px;
    border-radius: var(--radius-full);
    font-weight: 800;
    font-size: 0.74rem;
    letter-spacing: 0.5px;
    display: inline-flex;
    align-items: center;
    gap: 5px;
    box-shadow: var(--shadow-level-2);
    opacity: 0;
    visibility: hidden;
    pointer-events: none;
    transform: scale(0.8);
    transition: transform 0.35s var(--m3-ease-spring),
                padding 0.38s var(--m3-ease-emphasized),
                font-size 0.38s var(--m3-ease-emphasized),
                opacity 0.25s ease,
                box-shadow 0.25s ease,
                visibility 0.35s;
    white-space: nowrap;
}

body[data-view="president"] .tally-stack:has(#pvTallyContainer.visible) .victory-badge {
    padding: 3px 9px;
    font-size: 0.66rem;
    gap: 4px;
}

.victory-badge .material-symbols-rounded {
    font-size: 1.05rem;
    line-height: 1;
}

body[data-view="president"] .tally-stack:has(#pvTallyContainer.visible) .victory-badge .material-symbols-rounded {
    font-size: 0.92rem;
}

.victory-badge.visible {
    opacity: 1;
    visibility: visible;
    pointer-events: auto;
    transform: scale(1);
}

body.dark-mode .victory-badge {
    background: rgba(30, 142, 62, 0.90);
    border: 1px solid rgba(52, 211, 153, 0.45);
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.4);
}

#badgeYel {
    position: absolute;
    left: calc(100% + 10px);
    top: 50%;
    transform: translateY(-50%) scale(0.8);
}

#badgeYel.visible {
    transform: translateY(-50%) scale(1);
}

/* =========================================
   POPULAR VOTE FLOATING BAR & EXPANDABLE PILLS
   ========================================= */

.pv-tally-container {
    width: 100%;
    max-height: 0;
    margin-top: 0;
    padding: 0;
    position: relative;
    z-index: 26;
    pointer-events: none;
    transform: translateY(-8px);
    opacity: 0;
    visibility: hidden;
    transition: max-height 0.38s var(--m3-ease-emphasized),
                margin-top 0.38s var(--m3-ease-emphasized),
                opacity 0.28s var(--m3-ease-emphasized),
                transform 0.38s var(--m3-ease-emphasized),
                visibility 0.38s;
}

/* Shares the 64px top-bar space with the 44px EV bar (44 + 6 + 14 = 64px) */
.pv-tally-container.visible {
    max-height: 14px;
    margin-top: 6px;
    opacity: 1;
    visibility: visible;
    transform: translateY(0);
    pointer-events: auto;
}

.pv-tally-wrapper {
    position: relative;
    width: 100%;
    height: 14px;
    background: var(--surface-translucent);
    backdrop-filter: var(--glass-blur);
    -webkit-backdrop-filter: var(--glass-blur);
    border: var(--glass-border);
    border-radius: var(--radius-full);
    overflow: hidden;
    margin-top: 0;
    box-shadow: var(--shadow-level-1), inset 0 1px 3px rgba(0, 0, 0, 0.12);
}

.pv-fill {
    position: absolute;
    top: 0;
    height: 100%;
    transition: width 0.4s var(--m3-ease-standard), left 0.4s var(--m3-ease-standard);
}

.pv-fill.dem {
    left: 0;
    background-color: var(--color-primary);
}

.pv-fill.rep {
    right: 0;
    background-color: var(--color-secondary);
}

.pv-fill.yel {
    background-color: var(--color-warning);
}

/* Floating PV Pills positioned cleanly beneath the PV bar without altering top-bar height */
.pv-labels {
    position: absolute;
    top: calc(100% + 6px);
    left: 0;
    right: 0;
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    margin-top: 0;
    gap: 8px;
    z-index: 30;
    pointer-events: none;
}

.pv-pill {
    pointer-events: auto;
    background: var(--surface-translucent);
    backdrop-filter: var(--glass-blur);
    -webkit-backdrop-filter: var(--glass-blur);
    border: var(--glass-border);
    border-radius: 14px;
    box-shadow: var(--shadow-level-1), var(--glass-highlight);
    padding: 4px 14px;
    display: inline-flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    overflow: hidden;
    max-height: 28px;
    transform: translateZ(0);
    transition: max-height 0.3s var(--m3-ease-emphasized),
                box-shadow 0.25s ease,
                background-color 0.2s ease;
    white-space: nowrap;
    position: relative;
    z-index: 10;
}

.pv-pill:hover {
    max-height: 56px;
    box-shadow: var(--shadow-level-2);
    background: var(--surface-translucent-card);
    z-index: 35;
}

.pv-pill-summary {
    font-size: 0.8rem;
    font-weight: 700;
    line-height: 1.25;
    white-space: nowrap;
    display: block;
}

.pv-pill.dem .pv-pill-summary {
    color: var(--color-primary);
}

.pv-pill.rep .pv-pill-summary {
    color: var(--color-secondary);
}

.pv-pill.yel .pv-pill-summary {
    color: var(--color-warning);
}

.pv-pill-detail {
    font-size: 0.72rem;
    font-weight: 600;
    color: var(--text-muted);
    opacity: 0;
    max-height: 0;
    transform: translateY(-4px);
    transition: opacity 0.2s ease, max-height 0.25s var(--m3-ease-emphasized), transform 0.2s ease;
    white-space: nowrap;
    line-height: 1.25;
    margin-top: 0;
    display: block;
}

.pv-pill:hover .pv-pill-detail {
    opacity: 1;
    max-height: 20px;
    transform: translateY(0);
    margin-top: 3px;
}

/* Third-party yellow pill collapse/expand */
#pvPillYel {
    max-width: 0;
    padding-left: 0;
    padding-right: 0;
    margin: 0;
    opacity: 0;
    border-width: 0;
    overflow: hidden;
    visibility: hidden;
    pointer-events: none;
    border-radius: 14px;
    transition: max-width 0.4s var(--m3-ease-emphasized),
                max-height 0.3s var(--m3-ease-emphasized),
                padding 0.4s var(--m3-ease-emphasized),
                opacity 0.3s ease,
                border-width 0.4s ease,
                visibility 0.4s,
                box-shadow 0.25s ease;
}

#pvPillYel.visible {
    max-width: 240px;
    padding-left: 14px;
    padding-right: 14px;
    border-width: 1px;
    opacity: 1;
    visibility: visible;
    pointer-events: auto;
}

/* =========================================
   MAIN LAYOUT, SIDEBAR & CARDS
   ========================================= */

.main-layout {
    display: flex;
    flex: 1;
    min-height: 0;
    min-width: 0;
    padding: 12px 16px 14px 16px;
    gap: 16px;
    overflow: visible;
    position: relative;
}

.sidebar {
    width: var(--sidebar-width);
    background: var(--surface-translucent-card);
    backdrop-filter: var(--glass-blur);
    -webkit-backdrop-filter: var(--glass-blur);
    border: var(--glass-border);
    border-radius: var(--radius-card);
    box-shadow: var(--shadow-level-2), var(--glass-highlight);
    padding: 16px;
    overflow-y: auto;
    flex-shrink: 0;
    position: relative;
    z-index: 20;
    transform: translateZ(0);
}

/* Slim Auto-Hiding Custom Scrollbars */
.sidebar,
.settings-menu,
.m3-select-popover,
.m3-credits-list {
    --scrollbar-thumb: transparent;
}

.sidebar.is-scrolling,
.settings-menu.is-scrolling,
.m3-select-popover.is-scrolling,
.m3-credits-list.is-scrolling,
.sidebar.scrollbar-hover,
.settings-menu.scrollbar-hover,
.m3-select-popover.scrollbar-hover,
.m3-credits-list.scrollbar-hover {
    --scrollbar-thumb: var(--md-sys-color-surface-container-highest);
}

.sidebar::-webkit-scrollbar,
.settings-menu::-webkit-scrollbar,
.m3-select-popover::-webkit-scrollbar,
.m3-credits-list::-webkit-scrollbar {
    width: 6px;
    background: transparent;
}

.sidebar::-webkit-scrollbar-track,
.settings-menu::-webkit-scrollbar-track,
.m3-select-popover::-webkit-scrollbar-track,
.m3-credits-list::-webkit-scrollbar-track {
    background: transparent;
}

.sidebar::-webkit-scrollbar-track {
    margin: 24px 0;
}

.settings-menu::-webkit-scrollbar-track,
.m3-select-popover::-webkit-scrollbar-track,
.m3-credits-list::-webkit-scrollbar-track {
    margin: 8px 0;
}

.sidebar::-webkit-scrollbar-thumb,
.settings-menu::-webkit-scrollbar-thumb,
.m3-select-popover::-webkit-scrollbar-thumb,
.m3-credits-list::-webkit-scrollbar-thumb {
    background-color: var(--scrollbar-thumb);
    border-radius: var(--radius-full);
}

.sidebar::-webkit-scrollbar-thumb:hover,
.settings-menu::-webkit-scrollbar-thumb:hover,
.m3-select-popover::-webkit-scrollbar-thumb:hover,
.m3-credits-list::-webkit-scrollbar-thumb:hover,
.sidebar::-webkit-scrollbar-thumb:active,
.settings-menu::-webkit-scrollbar-thumb:active,
.m3-select-popover::-webkit-scrollbar-thumb:active,
.m3-credits-list::-webkit-scrollbar-thumb:active {
    background-color: var(--md-sys-color-outline);
}

.sidebar::-webkit-scrollbar-button,
.settings-menu::-webkit-scrollbar-button,
.m3-select-popover::-webkit-scrollbar-button,
.m3-credits-list::-webkit-scrollbar-button {
    display: none;
    width: 0;
    height: 0;
}

/* Firefox fallback */
@supports (-moz-appearance: none) {
    .sidebar,
    .settings-menu,
    .m3-select-popover,
    .m3-credits-list {
        scrollbar-width: thin;
        scrollbar-color: var(--scrollbar-thumb) transparent;
        transition: scrollbar-color 0.25s ease;
    }
}

/* Nested Sidebar Cards */
.district-card {
    background: var(--surface-card-nested);
    border: var(--glass-border-subtle);
    border-radius: var(--radius-card);
    padding: 14px;
    box-shadow: var(--shadow-level-1), var(--glass-highlight);
    margin-bottom: 12px;
    transition: box-shadow 0.3s var(--m3-ease-standard), background-color 0.3s ease;
}

.card-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 8px;
    border-bottom: 1px solid var(--md-sys-color-surface-container-high);
    padding-bottom: 8px;
}

.card-title {
    font-weight: 700;
    font-size: 0.95rem;
    color: var(--text-main);
}

/* Paint Mode Palette Card (Accordion) */
.district-card.paint-palette-card {
    max-height: 0;
    opacity: 0;
    padding-top: 0;
    padding-bottom: 0;
    margin-bottom: 0;
    overflow: hidden;
    border-width: 0;
    box-shadow: none;
    visibility: hidden;
    transform: translateY(-10px);
    transition: max-height 0.4s var(--m3-ease-emphasized),
                padding 0.4s var(--m3-ease-emphasized),
                margin 0.4s var(--m3-ease-emphasized),
                opacity 0.3s ease,
                transform 0.4s var(--m3-ease-emphasized),
                border-width 0.4s ease,
                box-shadow 0.3s ease,
                visibility 0.4s;
}

.district-card.paint-palette-card.visible {
    display: block !important;
    max-height: 360px;
    padding: 18px;
    margin-bottom: 14px;
    border-width: 1px;
    box-shadow: var(--shadow-level-1), var(--glass-highlight);
    opacity: 1;
    visibility: visible;
    transform: translateY(0);
}

/* Multi-Select Card (Accordion) */
.district-card.multi-select-card {
    max-height: 0;
    opacity: 0;
    padding-top: 0;
    padding-bottom: 0;
    margin-bottom: 0;
    overflow: hidden;
    border-width: 0;
    box-shadow: none;
    visibility: hidden;
    transform: translateY(-10px);
    transition: max-height 0.4s var(--m3-ease-emphasized),
                padding 0.4s var(--m3-ease-emphasized),
                margin 0.4s var(--m3-ease-emphasized),
                opacity 0.3s ease,
                transform 0.4s var(--m3-ease-emphasized),
                border-width 0.4s ease,
                box-shadow 0.3s ease,
                visibility 0.4s;
}

.district-card.multi-select-card.visible {
    display: block !important;
    max-height: 280px;
    padding: 18px;
    margin-bottom: 14px;
    border-width: 1px;
    box-shadow: var(--shadow-level-1), var(--glass-highlight);
    opacity: 1;
    visibility: visible;
    transform: translateY(0);
}

.multi-select-count-badge {
    font-size: 0.75rem;
    font-weight: 700;
    padding: 3px 10px;
    border-radius: var(--radius-full);
    background: var(--md-sys-color-surface-container-high);
    color: var(--text-muted);
    letter-spacing: 0.3px;
    transition: background-color 0.2s ease, color 0.2s ease;
}

/* Show Shift Sidebar Card (Accordion) */
.district-card.pv-shift-card,
#pvShiftCard {
    max-height: 0;
    overflow: hidden;
    opacity: 0;
    margin-top: 0;
    padding-top: 0;
    padding-bottom: 0;
    border-width: 0;
    visibility: hidden;
    transition: max-height 0.35s var(--m3-ease-emphasized),
                opacity 0.25s ease,
                margin-top 0.35s var(--m3-ease-emphasized),
                padding 0.35s var(--m3-ease-emphasized),
                border-width 0.35s ease,
                visibility 0.35s;
}

.district-card.pv-shift-card.visible,
#pvShiftCard.visible {
    max-height: 430px;
    opacity: 1;
    margin-top: 12px;
    padding-top: 14px;
    padding-bottom: 14px;
    border-width: 1px;
    visibility: visible;
}

/* =========================================
   STATE SHIFTS HEATMAP (TILT / LEAN / LIKELY / SAFE)
   ========================================= */

/* SVG Map States & House Hexes */
.state.shift-dem-tilt, .hex.shift-dem-tilt     { fill: #93C5FD !important; background-image: none !important; }
.state.shift-dem-lean, .hex.shift-dem-lean     { fill: #60A5FA !important; background-image: none !important; }
.state.shift-dem-likely, .hex.shift-dem-likely { fill: #2563EB !important; background-image: none !important; }
.state.shift-dem-safe, .hex.shift-dem-safe     { fill: #1E3A8A !important; background-image: none !important; }

.state.shift-rep-tilt, .hex.shift-rep-tilt     { fill: #FCA5A5 !important; background-image: none !important; }
.state.shift-rep-lean, .hex.shift-rep-lean     { fill: #F87171 !important; background-image: none !important; }
.state.shift-rep-likely, .hex.shift-rep-likely { fill: #DC2626 !important; background-image: none !important; }
.state.shift-rep-safe, .hex.shift-rep-safe     { fill: #881337 !important; background-image: none !important; }

.state.shift-even, .hex.shift-even             { fill: #9CA3AF !important; background-image: none !important; }

/* Small State & Special Election Sidebar Buttons */
.small-state-item button.shift-dem-tilt   { background: #93C5FD !important; color: #0F172A !important; font-size: 0.64rem !important; letter-spacing: -0.3px; }
.small-state-item button.shift-dem-lean   { background: #60A5FA !important; color: #0F172A !important; font-size: 0.64rem !important; letter-spacing: -0.3px; }
.small-state-item button.shift-dem-likely { background: #2563EB !important; color: #FFFFFF !important; font-size: 0.64rem !important; letter-spacing: -0.3px; }
.small-state-item button.shift-dem-safe   { background: #1E3A8A !important; color: #FFFFFF !important; font-size: 0.64rem !important; letter-spacing: -0.3px; }

.small-state-item button.shift-rep-tilt   { background: #FCA5A5 !important; color: #0F172A !important; font-size: 0.64rem !important; letter-spacing: -0.3px; }
.small-state-item button.shift-rep-lean   { background: #F87171 !important; color: #0F172A !important; font-size: 0.64rem !important; letter-spacing: -0.3px; }
.small-state-item button.shift-rep-likely { background: #DC2626 !important; color: #FFFFFF !important; font-size: 0.64rem !important; letter-spacing: -0.3px; }
.small-state-item button.shift-rep-safe   { background: #881337 !important; color: #FFFFFF !important; font-size: 0.64rem !important; letter-spacing: -0.3px; }

.small-state-item button.shift-even       { background: #9CA3AF !important; color: #FFFFFF !important; font-size: 0.64rem !important; }

/* Keep Tilt/Lean SVG labels dark for readability, and Likely/Safe white */
.state-label-svg.shift-dark-text {
    fill: #0F172A !important;
}

/* Active state for Highlight Flips button */
.menu-sub-btn.active-toggle {
    background: var(--text-main);
    color: var(--bg-app);
    border-color: var(--text-main);
    box-shadow: var(--shadow-level-1);
}

/* Competitive States Sidebar Card (Accordion) */
.district-card.comp-states-card,
#competitiveStatesCard {
    max-height: 0;
    overflow: hidden;
    opacity: 0;
    margin-top: 0;
    margin-bottom: 0;
    padding-top: 0;
    padding-bottom: 0;
    border-width: 0;
    visibility: hidden;
    transition: max-height 0.38s var(--m3-ease-emphasized),
                opacity 0.25s ease,
                margin 0.35s var(--m3-ease-emphasized),
                padding 0.35s var(--m3-ease-emphasized),
                border-width 0.35s ease,
                visibility 0.35s;
}

.district-card.comp-states-card.visible,
#competitiveStatesCard.visible {
    max-height: 440px;
    opacity: 1;
    margin-top: 0;
    margin-bottom: 12px;
    padding-top: 14px;
    padding-bottom: 14px;
    border-width: 1px;
    visibility: visible;
}

body.multi-select-mode .district-card.comp-states-card.visible,
body.multi-select-mode #competitiveStatesCard.visible {
    max-height: 0 !important;
    padding-top: 0 !important;
    padding-bottom: 0 !important;
    margin-bottom: 0 !important;
    opacity: 0;
    visibility: hidden;
    border-width: 0 !important;
    box-shadow: none !important;
    pointer-events: none;
}

.comp-btn-stack {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.comp-btn-row {
    display: grid;
    grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
    gap: 6px;
}

.comp-btn-row .menu-sub-btn {
    padding: 8px 8px;
    font-size: 0.74rem;
    white-space: nowrap;
}

.comp-results-drawer {
    max-height: 0;
    opacity: 0;
    overflow: hidden;
    margin-top: 0;
    padding-top: 0;
    border-top: 1px solid transparent;
    transition: max-height 0.35s var(--m3-ease-emphasized),
                opacity 0.25s ease,
                margin-top 0.3s var(--m3-ease-emphasized),
                padding-top 0.3s var(--m3-ease-emphasized),
                border-color 0.25s ease;
}

.comp-results-drawer.open {
    max-height: 250px;
    opacity: 1;
    margin-top: 10px;
    padding-top: 10px;
    border-top-color: var(--md-sys-color-surface-container-high);
}

.comp-results-header {
    font-size: 0.68rem;
    font-weight: 800;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: var(--text-muted);
    margin-bottom: 6px;
    padding: 0 2px;
}

.comp-results-list {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.comp-result-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    padding: 6px 10px;
    border-radius: 12px;
    background: var(--md-sys-color-surface-container);
    border: 1px solid var(--md-sys-color-outline-variant);
    font-size: 0.78rem;
    font-weight: 700;
    font-variant-numeric: tabular-nums;
    cursor: pointer;
    transition: background-color 0.18s ease, transform 0.15s ease, border-color 0.18s ease;
}

body.dark-mode .comp-result-item {
    background: var(--md-sys-color-surface-container-lowest);
    border-color: rgba(255, 255, 255, 0.08);
}

.comp-result-item:hover {
    background: var(--md-sys-color-surface-container-high);
    border-color: var(--md-sys-color-outline);
    transform: translateX(2px);
}

.comp-result-left {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    min-width: 0;
}

.comp-rank-num {
    font-size: 0.68rem;
    font-weight: 800;
    color: var(--text-muted);
    width: 14px;
    text-align: right;
    flex-shrink: 0;
}

.comp-unit-name {
    font-weight: 800;
    color: var(--text-main);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.comp-unit-ev {
    font-size: 0.68rem;
    font-weight: 700;
    color: var(--text-muted);
}

.comp-result-right {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    flex-shrink: 0;
}

.comp-margin-pill {
    padding: 2px 7px;
    border-radius: var(--radius-full);
    font-size: 0.72rem;
    font-weight: 800;
}

.comp-margin-pill.dem {
    background: rgba(21, 101, 216, 0.15);
    color: var(--color-primary);
    border: 1px solid rgba(21, 101, 216, 0.32);
}

.comp-margin-pill.rep {
    background: rgba(224, 45, 45, 0.15);
    color: var(--color-secondary);
    border: 1px solid rgba(224, 45, 45, 0.32);
}

.comp-margin-pill.yel {
    background: rgba(229, 136, 0, 0.16);
    color: var(--color-warning);
    border: 1px solid rgba(229, 136, 0, 0.35);
}

.comp-sub-metric {
    font-size: 0.68rem;
    font-weight: 600;
    color: var(--text-muted);
}

.comp-empty-msg {
    font-size: 0.76rem;
    font-weight: 600;
    color: var(--text-muted);
    text-align: center;
    padding: 8px 4px;
}

/* Grey out states, hex districts, and sidebar buttons without Flip status when Highlight Flips is active */
.state.non-flip-dimmed,
.hex.non-flip-dimmed {
    fill: var(--md-sys-color-surface-container-highest) !important;
    opacity: 0.35 !important;
    filter: grayscale(100%);
}

.state-label-svg.non-flip-dimmed {
    fill: var(--text-muted) !important;
    opacity: 0.38 !important;
}

.small-state-item button.non-flip-dimmed {
    background: var(--md-sys-color-surface-container-highest) !important;
    color: var(--text-muted) !important;
    opacity: 0.42 !important;
    filter: grayscale(100%);
}

/* Compact Flip Badge inside ME/NE Split District Tooltip Rows */
.tooltip-dist-row .tooltip-flip-badge {
    padding: 1px 5px;
    font-size: 0.6rem;
    margin-left: 4px;
    border-radius: 5px;
}

.tooltip-dist-row .tooltip-flip-badge .material-symbols-rounded {
    font-size: 11px !important;
}

body.multi-select-mode .district-card.pv-shift-card.visible,
body.multi-select-mode #pvShiftCard.visible {
    max-height: 0 !important;
    padding-top: 0 !important;
    padding-bottom: 0 !important;
    margin-bottom: 0 !important;
    opacity: 0;
    visibility: hidden;
    border-width: 0 !important;
    box-shadow: none !important;
    transform: translateY(-10px);
    pointer-events: none;
}

/* Tooltip State Shift Colored Badge */
.tooltip-shift-badge {
    margin-top: 8px;
    padding: 4px 10px;
    border-radius: 8px;
    font-size: 0.76rem;
    font-weight: 800;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    letter-spacing: 0.3px;
}

.tooltip-shift-badge.dem-lead {
    background: rgba(26, 115, 232, 0.16);
    border: 1px solid rgba(26, 115, 232, 0.35);
    color: var(--color-primary);
}

.tooltip-shift-badge.rep-lead {
    background: rgba(234, 67, 53, 0.16);
    border: 1px solid rgba(234, 67, 53, 0.35);
    color: var(--color-secondary);
}

.tooltip-shift-badge.even-lead {
    background: var(--md-sys-color-surface-container-high);
    border: 1px solid var(--md-sys-color-outline-variant);
    color: var(--text-muted);
}

body.dark-mode .tooltip-shift-badge.dem-lead {
    background: rgba(59, 130, 246, 0.22);
    border-color: rgba(59, 130, 246, 0.4);
}

body.dark-mode .tooltip-shift-badge.rep-lead {
    background: rgba(239, 68, 68, 0.22);
    border-color: rgba(239, 68, 68, 0.4);
}

/* Tooltip Split District Sub-Entries (ME & NE) */
.tooltip-dist-section {
    margin-top: 8px;
    padding-top: 6px;
    border-top: 1px solid var(--md-sys-color-outline-variant);
    display: flex;
    flex-direction: column;
    gap: 3px;
}

.tooltip-dist-header {
    font-size: 0.65rem;
    font-weight: 800;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: var(--text-muted);
    margin-bottom: 1px;
}

.tooltip-dist-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 14px;
    font-size: 0.74rem;
    font-weight: 700;
    font-variant-numeric: tabular-nums;
}

.tooltip-dist-name {
    display: inline-flex;
    align-items: baseline;
    gap: 4px;
    font-weight: 800;
}

.tooltip-dist-margin {
    font-size: 0.68rem;
    font-weight: 700;
    opacity: 0.85;
}

.tooltip-dist-splits {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    font-size: 0.72rem;
    font-weight: 700;
}

/* Popular Vote Sidebar Editor (Compact M3 Expressive Accordion) */
#pvSidebar {
    max-height: 0;
    padding-top: 0;
    padding-bottom: 0;
    margin-bottom: 0;
    opacity: 0;
    visibility: hidden;
    overflow: hidden;
    border-width: 0;
    box-shadow: none;
    transform: translateY(-10px);
    transition: max-height 0.4s var(--m3-ease-emphasized),
                padding 0.4s var(--m3-ease-emphasized),
                margin 0.4s var(--m3-ease-emphasized),
                opacity 0.3s ease,
                transform 0.4s var(--m3-ease-emphasized),
                border-width 0.4s ease,
                box-shadow 0.3s ease,
                visibility 0.4s;
}

#pvSidebar.visible {
    display: block !important;
    max-height: 860px;
    padding: 12px 14px;
    margin-bottom: 12px;
    border-width: 1px;
    box-shadow: var(--shadow-level-1), var(--glass-highlight);
    opacity: 1;
    visibility: visible;
    transform: translateY(0);
}

body.multi-select-mode #pvSidebar.visible {
    max-height: 0;
    padding-top: 0;
    padding-bottom: 0;
    margin-bottom: 0;
    opacity: 0;
    visibility: hidden;
    border-width: 0;
    box-shadow: none;
    transform: translateY(-10px);
    pointer-events: none;
}

.pv-inputs-stack {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

/* Single-Line Partisan-Tinted Pill Input Rows */
.pv-input-row {
    display: flex;
    flex-direction: row;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    height: 38px;
    padding: 4px 6px 4px 12px;
    border-radius: var(--radius-button);
    border: 1px solid transparent;
    margin-bottom: 0;
    transition: border-radius 0.22s var(--m3-ease-spring),
                background-color 0.2s ease,
                border-color 0.2s ease,
                box-shadow 0.2s ease;
}

/* Vibrant Light Mode Partisan Pill Rows */
.pv-input-row.dem-row {
    background: linear-gradient(90deg, rgba(21, 101, 216, 0.20) 0%, rgba(21, 101, 216, 0.12) 100%);
    border-color: rgba(21, 101, 216, 0.42);
}

.pv-input-row.rep-row {
    background: linear-gradient(90deg, rgba(224, 45, 45, 0.20) 0%, rgba(224, 45, 45, 0.12) 100%);
    border-color: rgba(224, 45, 45, 0.42);
}

.pv-input-row.yel-row {
    background: linear-gradient(90deg, rgba(245, 158, 11, 0.24) 0%, rgba(245, 158, 11, 0.14) 100%);
    border-color: rgba(229, 136, 0, 0.48);
}

body.dark-mode .pv-input-row.dem-row {
    background: rgba(59, 130, 246, 0.15);
    border-color: rgba(59, 130, 246, 0.30);
}

body.dark-mode .pv-input-row.rep-row {
    background: rgba(239, 68, 68, 0.15);
    border-color: rgba(239, 68, 68, 0.30);
}

body.dark-mode .pv-input-row.yel-row {
    background: rgba(251, 191, 36, 0.15);
    border-color: rgba(251, 191, 36, 0.30);
}

.pv-input-row:focus-within {
    border-radius: var(--radius-material-active);
    background: var(--md-sys-color-surface-container-lowest);
}

.pv-input-row.dem-row:focus-within {
    border-color: var(--color-primary);
    box-shadow: 0 0 0 2px rgba(26, 115, 232, 0.2);
}

.pv-input-row.rep-row:focus-within {
    border-color: var(--color-secondary);
    box-shadow: 0 0 0 2px rgba(234, 67, 53, 0.2);
}

.pv-input-row.yel-row:focus-within {
    border-color: var(--color-warning);
    box-shadow: 0 0 0 2px rgba(245, 158, 11, 0.22);
}

.pv-party-meta {
    display: inline-flex;
    align-items: baseline;
    gap: 6px;
    flex-shrink: 0;
    pointer-events: none;
}

.pv-party-tag {
    font-size: 0.78rem;
    font-weight: 800;
    letter-spacing: 0.4px;
}

.dem-row .pv-party-tag { color: var(--color-primary); }
.rep-row .pv-party-tag { color: var(--color-secondary); }
.yel-row .pv-party-tag { color: var(--color-warning); }

.pv-party-pct {
    font-size: 0.72rem;
    font-weight: 700;
    color: var(--text-muted);
    font-variant-numeric: tabular-nums;
}

.pv-input-row input {
    flex: 1;
    min-width: 0;
    height: 28px;
    text-align: right;
    background: rgba(255, 255, 255, 0.55) !important;
    border: 1px solid transparent !important;
    border-radius: var(--radius-full);
    color: var(--md-sys-color-on-surface) !important;
    font-weight: 700;
    font-size: 0.88rem;
    padding: 2px 10px !important;
    outline: none;
    font-family: var(--font-family);
    font-variant-numeric: tabular-nums;
    transition: background-color 0.2s ease, border-radius 0.2s ease;
}

body.dark-mode .pv-input-row input {
    background: rgba(10, 10, 15, 0.45) !important;
}

.pv-input-row input:focus {
    background: transparent !important;
    border-radius: 8px;
}

#pvRowYel {
    max-height: 0;
    height: 0;
    opacity: 0;
    padding-top: 0;
    padding-bottom: 0;
    margin-top: -6px;
    border-width: 0;
    overflow: hidden;
    visibility: hidden;
    transition: max-height 0.35s var(--m3-ease-emphasized),
                height 0.35s var(--m3-ease-emphasized),
                padding 0.35s var(--m3-ease-emphasized),
                margin-top 0.35s var(--m3-ease-emphasized),
                opacity 0.25s ease,
                border-width 0.35s ease,
                visibility 0.35s;
}

#pvRowYel.visible {
    max-height: 38px;
    height: 38px;
    opacity: 1;
    padding-top: 4px;
    padding-bottom: 4px;
    margin-top: 0;
    border-width: 1px;
    visibility: visible;
}

/* Compact 2-Column Per-State Shift & Turnout Drawer */
.state-env-drawer {
    max-height: 0;
    opacity: 0;
    overflow: hidden;
    visibility: hidden;
    transform: translateY(-6px);
    pointer-events: none;
    transition: max-height 0.38s var(--m3-ease-emphasized),
                opacity 0.25s ease,
                transform 0.38s var(--m3-ease-spring),
                margin-top 0.35s var(--m3-ease-emphasized),
                padding-top 0.35s var(--m3-ease-emphasized),
                visibility 0.38s;
}

.state-env-drawer.visible {
    max-height: 140px;
    opacity: 1;
    visibility: visible;
    transform: translateY(0);
    pointer-events: auto;
    margin-top: 10px;
    padding-top: 10px;
    border-top: 1px solid var(--md-sys-color-surface-container-high);
}

.state-env-grid .control-group label {
    font-size: 0.72rem;
    margin-bottom: 4px;
    text-align: center;
}

/* =========================================
   FORM CONTROLS, INPUTS & DROPDOWNS
   ========================================= */

.control-group {
    margin-bottom: 16px;
}

.control-group label {
    display: block;
    font-size: 0.8rem;
    font-weight: 600;
    color: var(--text-muted);
    margin-bottom: 6px;
}

.control-group input {
    width: 100%;
    padding: 10px 16px;
    border-radius: var(--radius-input);
    background-color: var(--md-sys-color-surface-container-highest);
    border: 2px solid transparent;
    color: var(--md-sys-color-on-surface);
    font-family: var(--font-family);
    font-size: 0.95rem;
    font-weight: 500;
    outline: none;
    transition: border-color 0.2s ease, background-color 0.2s ease, box-shadow 0.2s ease;
}

.control-group input:hover {
    background-color: var(--md-sys-color-surface-container-high);
}

.control-group input:focus {
    background-color: var(--md-sys-color-surface-container-lowest);
    border-color: var(--color-primary);
    box-shadow: 0 0 0 2px rgba(26, 115, 232, 0.2);
}

/* Unified Pill Dropdowns */
.control-group select,
.settings-menu select {
    width: 100%;
    padding: 9px 36px 9px 16px;
    font-family: var(--font-family);
    font-size: 0.88rem;
    font-weight: 600;
    border-radius: var(--radius-button);
    border: 1px solid var(--md-sys-color-outline-variant);
    color: var(--md-sys-color-on-surface);
    background-color: var(--md-sys-color-surface-container-high);
    outline: none;
    cursor: pointer;
    appearance: none;
    -webkit-appearance: none;
    -moz-appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' height='20' viewBox='0 -960 960 960' width='20' fill='%23777684'%3E%3Cpath d='M480-360 280-560h400L480-360Z'/%3E%3C/svg%3E");
    background-repeat: no-repeat !important;
    background-position: right 14px center !important;
    background-size: 16px 16px !important;
    transition: border-color 0.2s ease, background-color 0.2s ease, box-shadow 0.2s ease;
}

.control-group select:hover,
.settings-menu select:hover {
    border-radius: var(--radius-material-active);
}

.control-group select:active,
.settings-menu select:active {
    background-color: var(--md-sys-color-surface-container-highest);
    border-color: var(--md-sys-color-outline);
}

.control-group select:focus,
.settings-menu select:focus {
    background-color: var(--md-sys-color-surface-container-lowest);
    border-color: var(--color-primary);
    box-shadow: 0 0 0 2px rgba(26, 115, 232, 0.25);
}

body.dark-mode .control-group select,
body.dark-mode .settings-menu select {
    background-color: var(--md-sys-color-surface-container-highest);
    border-color: var(--md-sys-color-outline-variant);
    color: var(--md-sys-color-on-surface);
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' height='20' viewBox='0 -960 960 960' width='20' fill='%23C7C5D5'%3E%3Cpath d='M480-360 280-560h400L480-360Z'/%3E%3C/svg%3E");
}

body.dark-mode .control-group select:hover,
body.dark-mode .settings-menu select:hover {
    background-color: var(--md-sys-color-surface-container-high);
}

body.dark-mode .control-group select:focus,
body.dark-mode .settings-menu select:focus {
    background-color: var(--md-sys-color-surface-container-lowest);
    border-color: var(--color-primary);
    box-shadow: 0 0 0 2px rgba(59, 130, 246, 0.3);
}

.control-group select option,
.settings-menu select option {
    background-color: var(--md-sys-color-surface-container);
    color: var(--md-sys-color-on-surface);
    font-weight: 500;
}

.helper-text {
    font-size: 0.8rem;
    color: var(--text-muted);
    line-height: 1.5;
    margin-top: 16px;
}

/* M3 Pill Action Buttons */
.action-btn {
    border: none;
    border-radius: var(--radius-button);
    padding: 12px 24px;
    font-size: 0.95rem;
    font-weight: 700;
    cursor: pointer;
    font-family: var(--font-family);
    transition: transform 0.25s var(--m3-ease-spring),
                box-shadow 0.25s ease,
                background-color 0.2s ease,
                filter 0.2s ease;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    margin-top: 12px;
    box-shadow: var(--shadow-level-1);
    background: var(--md-sys-color-surface-container-highest);
    color: var(--text-main);
}

.action-btn:hover {
    box-shadow: var(--shadow-level-2);
    transform: translateY(-1px);
    filter: brightness(1.05);
}

.action-btn:active {
    transform: scale(0.97);
    box-shadow: var(--shadow-level-1);
    filter: brightness(0.95);
    border-radius: 11px !important;
}

.action-btn.uncalled {
    background: var(--color-uncalled);
    color: var(--text-main);
}

.action-btn.dem {
    background: var(--color-primary);
    color: #ffffff;
}

.action-btn.rep {
    background: var(--color-secondary);
    color: #ffffff;
}

.action-btn.yel {
    background: var(--color-warning);
    color: #000000;
}

.action-btn.reset-district-btn {
    width: 100%;
    margin-top: 10px;
    padding: 10px 16px;
    font-size: 0.88rem;
    font-weight: 600;
    background: var(--md-sys-color-surface-container-high);
    color: var(--text-muted);
}

.action-btn.reset-district-btn:hover {
    background: var(--md-sys-color-surface-container-highest);
    color: var(--text-main);
}

.action-btn.reset-district-btn .material-symbols-rounded {
    font-size: 1.15rem;
}

.action-btn.reset-district-btn.active {
    background-color: var(--md-sys-color-surface-container-highest);
    color: var(--text-main);
    border: 1px solid var(--md-sys-color-outline);
    box-shadow: var(--shadow-level-2);
}

/* Segmented Status Control (House & Paint Palette) */
.status-segmented-control {
    display: flex;
    align-items: center;
    gap: 4px;
    padding: 4px;
    background: var(--md-sys-color-surface-container);
    border: 1px solid var(--md-sys-color-outline-variant);
    border-radius: var(--radius-full);
    box-shadow: inset 0 1px 2px rgba(0, 0, 0, 0.06);
    width: 100%;
}

body.dark-mode .status-segmented-control {
    background: var(--md-sys-color-surface-container-lowest);
    border-color: rgba(255, 255, 255, 0.1);
    box-shadow: inset 0 1px 3px rgba(0, 0, 0, 0.35);
}

.status-seg-btn {
    flex: 1;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 8px 10px;
    border-radius: var(--radius-full);
    color: var(--text-muted);
    font-weight: 700;
    font-size: 0.85rem;
    font-family: var(--font-family);
    background: transparent;
    border: none;
    cursor: pointer;
    white-space: nowrap;
    transition: background-color 0.2s var(--m3-ease-standard),
                color 0.2s var(--m3-ease-standard),
                box-shadow 0.2s var(--m3-ease-standard);
}

.status-seg-btn:hover {
    color: var(--text-main);
    background-color: var(--md-sys-color-surface-container-high);
}

.status-seg-btn.dem.active {
    background-color: var(--color-primary);
    color: #ffffff;
    box-shadow: var(--shadow-level-1);
}

.status-seg-btn.rep.active {
    background-color: var(--color-secondary);
    color: #ffffff;
    box-shadow: var(--shadow-level-1);
}

.status-seg-btn.yel.active {
    background-color: var(--color-warning);
    color: #000000;
    box-shadow: var(--shadow-level-1);
}

.status-seg-btn.yel-seg {
    max-width: 0;
    padding-left: 0;
    padding-right: 0;
    opacity: 0;
    overflow: hidden;
    visibility: hidden;
    transition: max-width 0.35s var(--m3-ease-emphasized),
                padding 0.35s var(--m3-ease-emphasized),
                opacity 0.25s ease,
                visibility 0.35s;
}

.status-seg-btn.yel-seg.visible {
    max-width: 120px;
    padding: 8px 10px;
    opacity: 1;
    visibility: visible;
}

/* =========================================
   SMALL STATES & SPLIT ALLOCATION
   ========================================= */

.small-states-grid {
    display: grid;
    grid-template-columns: repeat(5, 1fr);
    gap: 8px 6px;
}

.small-state-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 4px;
}

.small-state-item .label {
    font-size: 0.82rem;
    font-weight: 700;
    color: var(--text-muted);
}

.small-state-item button {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    border: none;
    box-shadow: var(--shadow-level-1);
    background: var(--bg-card);
    cursor: pointer;
    font-weight: 800;
    font-size: 0.84rem;
    font-family: var(--font-family);
    color: var(--text-main);
    display: flex;
    align-items: center;
    justify-content: center;
    transition: border-radius 0.3s var(--m3-ease-spring),
                background-color 0.2s ease,
                color 0.2s ease,
                transform 0.2s var(--m3-ease-spring),
                box-shadow 0.2s ease;
}

.small-state-item button:hover {
    box-shadow: var(--elevation-1);
    transform: translateY(-1px) scale(1.05);
}

.small-state-item button:active {
    border-radius: 10px;
    transform: scale(0.93);
}

/* Morph into squircle when assigned to a party */
.small-state-item button.dem,
.small-state-item button.rep,
.small-state-item button.yel {
    border-radius: var(--radius-material-active);
}

.small-state-item button.dem {
    background: var(--color-primary);
    color: #ffffff;
}

.small-state-item button.rep {
    background: var(--color-secondary);
    color: #ffffff;
}

.small-state-item button.yel {
    background: var(--color-warning);
    color: #000000;
}

/* Split Districts Accordion (ME & NE) */

/* 1. Dynamic Split Allocation Drawer inside Popular Vote Card */
.pv-split-section {
    max-height: 0;
    opacity: 0;
    overflow: hidden;
    visibility: hidden;
    margin-top: 0;
    padding-top: 0;
    border-top: 1px solid transparent;
    transition: max-height 0.38s var(--m3-ease-emphasized),
                opacity 0.25s ease,
                margin-top 0.35s var(--m3-ease-emphasized),
                padding-top 0.35s var(--m3-ease-emphasized),
                border-color 0.25s ease,
                visibility 0.38s;
}

.pv-split-section.visible {
    max-height: 380px;
    opacity: 1;
    visibility: visible;
    margin-top: 10px;
    padding-top: 10px;
    border-top-color: var(--md-sys-color-surface-container-high);
}

.pv-split-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 0;
    transition: margin-bottom 0.3s var(--m3-ease-emphasized);
}

.pv-split-section:has(.split-districts-list.active) .pv-split-header {
    margin-bottom: 8px;
}

.pv-split-title {
    font-size: 0.8rem;
    font-weight: 700;
    color: var(--text-main);
}

/* 2. Compact Split Allocation inside Small States & DC Card (PV Off Mode) */
.compact-split-section {
    max-height: 520px;
    opacity: 1;
    overflow: hidden;
    visibility: visible;
    transition: max-height 0.35s var(--m3-ease-emphasized),
                opacity 0.25s ease,
                visibility 0.35s;
}

.compact-split-section.hidden {
    max-height: 0;
    opacity: 0;
    visibility: hidden;
    pointer-events: none;
}

.compact-split-divider {
    height: 1px;
    background: var(--md-sys-color-surface-container-high);
    margin: 12px 0 8px 0;
}

.compact-split-header {
    font-size: 0.72rem;
    font-weight: 800;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: var(--text-muted);
    margin-bottom: 6px;
}

.compact-split-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 4px 2px;
}

.compact-split-label {
    font-size: 0.84rem;
    font-weight: 700;
    color: var(--text-main);
}

/* Horizontal Small-State Tile Row for Non-PV Split Districts (AL, ME-1, ME-2 / NE-1, NE-2, NE-3) */
.compact-split-block .split-districts-list {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 8px 6px;
    max-height: 0;
    opacity: 0;
    margin-top: 0;
    padding: 0;
    overflow: hidden;
    visibility: hidden;
    pointer-events: none;
    transform: translateY(-4px);
    transition: max-height 0.32s var(--m3-ease-emphasized),
                opacity 0.22s ease,
                margin-top 0.28s var(--m3-ease-emphasized),
                transform 0.32s var(--m3-ease-spring),
                visibility 0.32s;
}

.compact-split-block .split-districts-list.active {
    max-height: 80px;
    opacity: 1;
    margin-top: 6px;
    margin-bottom: 4px;
    visibility: visible;
    pointer-events: auto;
    transform: translateY(0);
}


.toggle-btn {
    background: var(--md-sys-color-surface-container-high);
    border: none;
    border-radius: var(--radius-button);
    padding: 6px 14px;
    font-size: 0.75rem;
    font-weight: 700;
    font-family: var(--font-family);
    cursor: pointer;
    color: var(--md-sys-color-on-surface-variant);
    transition: background-color 0.2s ease, color 0.2s ease;
}

.toggle-btn:hover {
    background: var(--md-sys-color-surface-container-highest);
    border-radius: 11px !important;
}

.toggle-btn:active {
    border-radius: 12px !important;
}

.toggle-btn.active {
    background: var(--text-main);
    color: var(--bg-app);
    border-radius: 11px !important;
}

.district-dots {
    display: none;
    gap: 6px;
    margin-top: 0 !important;
    flex-wrap: wrap;
}

.district-dots.active {
    display: flex;
}

.district-dots button {
    width: 32px;
    height: 32px;
    flex-shrink: 0;
    border-radius: 50%;
    border: 1px solid var(--md-sys-color-surface-container-highest);
    background: var(--bg-app);
    cursor: pointer;
    font-size: 0.7rem;
    font-weight: 700;
    color: var(--text-main);
    transition: border-radius 0.3s var(--m3-ease-spring),
                background-color 0.2s ease,
                border-color 0.2s ease,
                transform 0.15s ease;
}

.district-dots button.dem {
    background: var(--color-primary);
    color: #ffffff;
    border-color: var(--color-primary);
}

.district-dots button.rep {
    background: var(--color-secondary);
    color: #ffffff;
    border-color: var(--color-secondary);
}

.district-dots button.yel {
    background: var(--color-warning);
    color: #000000;
    border-color: var(--color-warning);
}

.district-dots button.dem,
.district-dots button.rep,
.district-dots button.yel {
    border-radius: 9px;
}

/* Split District PV Inputs */
.mini-pv-input {
    width: 100%;
    min-width: 0;
    text-align: center;
    background: var(--md-sys-color-surface-container-highest) !important;
    border: 1px solid transparent !important;
    border-radius: 8px !important;
    color: var(--text-main) !important;
    font-size: 0.85rem;
    padding: 6px 4px !important;
    outline: none;
    font-family: var(--font-family);
    transition: border-color 0.2s ease, background-color 0.2s ease;
}

.mini-pv-input:hover {
    background: var(--md-sys-color-surface-container-lowest) !important;
}

.mini-pv-input.dem {
    border-color: var(--color-primary) !important;
}

.mini-pv-input.rep {
    border-color: var(--color-secondary) !important;
}

.mini-pv-input.yel {
    border-color: var(--color-warning) !important;
}

.mini-pv-input.dem:focus {
    border-color: var(--color-primary) !important;
}

.mini-pv-input.rep:focus {
    border-color: var(--color-secondary) !important;
}

.mini-pv-input.yel:focus {
    border-color: var(--color-warning) !important;
}

.dem-text {
    color: var(--color-primary) !important;
}

.rep-text {
    color: var(--color-secondary) !important;
}

.yel-text {
    color: var(--color-warning) !important;
}

/* =========================================
   MAP VIEWPORT & INTERACTIVE SVG ELEMENTS
   ========================================= */

.map-area {
    flex: 1;
    min-height: 0;
    min-width: 0;
    height: 100%;
    fill: none;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px 28px;
    position: relative;
    overflow: visible;
    z-index: 1;
}

.map-area svg {
    width: 100%;
    height: 100%;
    max-width: 100%;
    max-height: 100%;
    overflow: visible !important;
    filter: drop-shadow(0 4px 12px rgba(0, 0, 0, 0.05));
}

.state,
.hex {
    fill: var(--color-uncalled);
    stroke: var(--map-stroke);
    stroke-width: 1.5px;
    cursor: pointer;
    pointer-events: auto;
    transition: fill 0.18s ease, opacity 0.18s ease;
}

.state:hover:not(.inactive) {
    opacity: 0.78;
}

.hex:hover {
    opacity: 0.82;
}

.state.dem,
.hex.dem {
    fill: var(--color-primary);
}

.state.rep,
.hex.rep {
    fill: var(--color-secondary);
}

.state.yel,
.hex.yel {
    fill: var(--color-warning);
}

.state.split {
    fill: url(#split-pattern);
}

.state.inactive {
    fill: var(--md-sys-color-surface-container-highest) !important;
    stroke-dasharray: 3, 2;
    pointer-events: none;
    opacity: 0.32;
}

/* Selected State Highlight */
.state.selected-state {
    stroke: var(--text-main, #262533) !important;
    stroke-width: 3.2px !important;
    stroke-linejoin: round !important;
    stroke-linecap: round !important;
    paint-order: stroke fill !important;
    vector-effect: non-scaling-stroke;
}

body.dark-mode .state.selected-state {
    stroke: #FFFFFF !important;
    stroke-width: 3.2px !important;
}

.small-state-item button.selected-state {
    outline: 1px solid currentcolor;
    outline-offset: 1px;
    transform: scale(1.08);
    border-radius: var(--radius-material-active);
}

/* Selected State & House Hex Highlight */
.state.selected-state,
.hex.selected-hex {
    stroke: var(--text-main, #262533) !important;
    stroke-width: 3.2px !important;
    stroke-linejoin: round !important;
    stroke-linecap: round !important;
    paint-order: stroke fill !important;
    vector-effect: non-scaling-stroke;
}

body.dark-mode .state.selected-state,
body.dark-mode .hex.selected-hex {
    stroke: #FFFFFF !important;
    stroke-width: 3.2px !important;
}

/* State & Hex Labels */
.state-label-svg {
    fill: var(--text-main);
    pointer-events: none;
    font-variant-numeric: tabular-nums;
}

.state-label-svg.filled {
    fill: #ffffff !important;
    text-shadow: none !important;
}

.island-label {
    font-size: 13px;
    font-weight: 800;
    fill: var(--text-main);
    pointer-events: none;
    text-anchor: middle;
    dominant-baseline: central;
    paint-order: stroke fill;
    stroke: var(--bg-app);
    stroke-width: 3.5px;
    stroke-linejoin: round;
    stroke-linecap: round;
}

/* Mode-Specific Cursors */
body.paint-mode .map-area,
body.paint-mode .state,
body.paint-mode .hex {
    cursor: crosshair !important;
}

body.multi-select-mode .map-area,
body.multi-select-mode .state {
    cursor: cell !important;
}

body[data-view="president"].edit-mode .state,
body[data-view="president"].edit-mode .small-state-item button {
    cursor: text !important;
}

/* =========================================
   FLOATING OVERLAYS, BANNERS & TOOLTIP
   ========================================= */

/* Zoom Reset Pill */
.reset-zoom-btn {
    position: absolute;
    bottom: 48px;
    left: 50%;
    transform: translate(-50%, 20px);
    background: rgba(245, 158, 11, 0.72);
    backdrop-filter: var(--glass-blur);
    -webkit-backdrop-filter: var(--glass-blur);
    color: #000000;
    padding: 8px 16px;
    border-radius: var(--radius-full);
    font-weight: 700;
    font-size: 0.9rem;
    font-family: var(--font-family);
    display: flex;
    align-items: center;
    gap: 6px;
    box-shadow: var(--elevation-2);
    border: 1px solid rgba(255, 255, 255, 0.45);
    cursor: pointer;
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.3s var(--m3-ease-emphasized),
                transform 0.3s var(--m3-ease-spring),
                box-shadow 0.2s ease,
                filter 0.2s ease,
                visibility 0.3s;
    z-index: 100;
}

.reset-zoom-btn.visible {
    opacity: 1;
    visibility: visible;
    transform: translate(-50%, 0);
}

.reset-zoom-btn:hover {
    filter: brightness(1.05);
    box-shadow: var(--shadow-level-3);
    transform: translate(-50%, -2px);
}

.reset-zoom-btn:active {
    filter: brightness(0.95);
    transform: translate(-50%, 1px);
    box-shadow: var(--elevation-1);
}

/* Map Size Warning Banner */
.size-warning {
    position: absolute;
    top: 16px;
    left: 50%;
    transform: translate(-50%, -24px);
    background: rgba(234, 67, 53, 0.82);
    backdrop-filter: var(--glass-blur);
    -webkit-backdrop-filter: var(--glass-blur);
    border: 1px solid rgba(255, 255, 255, 0.35);
    color: #ffffff;
    padding: 8px 16px;
    border-radius: var(--radius-full);
    font-weight: 600;
    font-size: 0.9rem;
    display: flex;
    align-items: center;
    gap: 8px;
    box-shadow: var(--elevation-2);
    z-index: 9999;
    opacity: 0;
    visibility: hidden;
    pointer-events: none;
    transition: transform 0.35s var(--m3-ease-spring),
                opacity 0.25s ease,
                visibility 0.35s;
}

.size-warning.visible {
    opacity: 1;
    visibility: visible;
    pointer-events: auto;
    transform: translate(-50%, 0);
}

.size-warning .icon-btn {
    width: 28px;
    height: 28px;
    background: transparent;
    color: #ffffff;
    margin-left: 8px;
}

.size-warning .icon-btn:hover {
    background-color: rgba(255, 255, 255, 0.2);
}

/* Faithless Elector Disclaimer */
.faithless-disclaimer {
    position: absolute;
    bottom: 16px;
    left: 24px;
    background: var(--surface-translucent);
    backdrop-filter: var(--glass-blur);
    -webkit-backdrop-filter: var(--glass-blur);
    color: var(--text-muted);
    padding: 8px 12px;
    border-radius: var(--radius-sm);
    font-size: 0.8rem;
    font-weight: 600;
    box-shadow: var(--elevation-1);
    border: var(--glass-border);
    display: flex;
    align-items: center;
    gap: 6px;
    z-index: 10;
    opacity: 0;
    visibility: hidden;
    pointer-events: none;
    transform: translateY(14px);
    transition: transform 0.35s var(--m3-ease-spring),
                opacity 0.25s ease,
                visibility 0.35s;
}

.faithless-disclaimer.visible {
    opacity: 1;
    visibility: visible;
    pointer-events: auto;
    transform: translateY(0);
}

/* Tooltip */
#tooltip {
    position: fixed;
    background: var(--surface-translucent);
    backdrop-filter: var(--glass-blur);
    -webkit-backdrop-filter: var(--glass-blur);
    color: var(--text-main);
    padding: 8px 14px;
    border-radius: var(--radius-md);
    font-size: 0.85rem;
    font-weight: 700;
    box-shadow: var(--shadow-level-2), var(--glass-highlight);
    border: var(--glass-border);
    pointer-events: none;
    opacity: 0;
    transition: opacity 0.15s ease;
    z-index: 1000;
    white-space: nowrap;
    transform: translateZ(0);
}

#tooltip.visible {
    opacity: 1;
}

/* =========================================
   SPA VIEW SCOPING & TRANSITIONS
   ========================================= */

body[data-view="president"] .view-senate:not(.view-president),
body[data-view="president"] .view-house:not(.view-president),
body[data-view="president"] .view-governor:not(.view-president),
body[data-view="senate"] .view-president:not(.view-senate),
body[data-view="senate"] .view-house:not(.view-senate),
body[data-view="senate"] .view-governor:not(.view-senate),
body[data-view="house"] .view-president:not(.view-house),
body[data-view="house"] .view-senate:not(.view-house),
body[data-view="house"] .view-governor:not(.view-house),
body[data-view="governor"] .view-president:not(.view-governor),
body[data-view="governor"] .view-senate:not(.view-governor),
body[data-view="governor"] .view-house:not(.view-governor) {
    display: none !important;
}

#geoMapSvg,
#houseMapSvg {
    width: 100%;
    height: 100%;
    max-width: 100%;
    max-height: 100%;
    background: none;
}

body[data-view="president"] #geoMapSvg,
body[data-view="senate"] #geoMapSvg,
body[data-view="governor"] #geoMapSvg {
    display: block !important;
}

body[data-view="president"] #houseMapSvg,
body[data-view="senate"] #houseMapSvg,
body[data-view="governor"] #houseMapSvg {
    display: none !important;
}

body[data-view="house"] #geoMapSvg {
    display: none !important;
}

body[data-view="house"] #houseMapSvg {
    display: block !important;
}

/* M3 Expressive Map View Transitions */
.m3e-slide-right {
    animation: m3eSlideRight 0.45s var(--m3-ease-spring) both;
    will-change: transform, opacity;
}

.m3e-slide-left {
    animation: m3eSlideLeft 0.45s var(--m3-ease-spring) both;
    will-change: transform, opacity;
}

@keyframes m3eSlideRight {
    0% {
        opacity: 0;
        transform: translateX(45px) scale(0.97);
    }
    100% {
        opacity: 1;
        transform: translateX(0) scale(1);
    }
}

@keyframes m3eSlideLeft {
    0% {
        opacity: 0;
        transform: translateX(-45px) scale(0.97);
    }
    100% {
        opacity: 1;
        transform: translateX(0) scale(1);
    }
}

/* =========================================
   M3 EXPRESSIVE MODALS (PROMPT & CONFIRM)
   ========================================= */

.m3-dialog-backdrop {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.45);
    backdrop-filter: blur(6px);
    -webkit-backdrop-filter: blur(6px);
    z-index: 2000;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 16px;
    opacity: 0;
    visibility: hidden;
    pointer-events: none;
    transition: opacity 0.25s ease, visibility 0.25s ease;
}

.m3-dialog-backdrop.open {
    opacity: 1;
    visibility: visible;
    pointer-events: auto;
}

.m3-dialog {
    width: 100%;
    max-width: 380px;
    background: var(--surface-translucent-card);
    backdrop-filter: var(--glass-blur);
    -webkit-backdrop-filter: var(--glass-blur);
    border: var(--glass-border);
    border-radius: var(--radius-card);
    box-shadow: var(--shadow-level-3), var(--glass-highlight);
    padding: 24px;
    display: flex;
    flex-direction: column;
    gap: 12px;
    transform: scale(0.92) translateY(12px) translateZ(0);
    transition: transform 0.35s var(--m3-ease-spring);
}

.m3-dialog-backdrop.open .m3-dialog {
    transform: scale(1) translateY(0) translateZ(0);
}

.m3-dialog-header {
    display: flex;
    align-items: center;
    gap: 12px;
}

.m3-dialog-alert-icon {
    font-size: 2rem !important;
    color: var(--color-warning) !important;
    line-height: 1;
    flex-shrink: 0;
}

.m3-dialog-title {
    margin: 0;
    font-size: 1.25rem;
    font-weight: 700;
    color: var(--text-main);
    border-bottom: none;
    padding-bottom: 0;
}

.m3-dialog-message {
    margin: 0;
    font-size: 0.9rem;
    color: var(--text-muted);
    line-height: 1.4;
}

.m3-dialog-input-wrapper {
    margin-top: 4px;
}

.m3-dialog-input-wrapper input {
    width: 100%;
    padding: 12px 16px;
    border-radius: var(--radius-input);
    background: var(--md-sys-color-surface-container-highest);
    border: 2px solid transparent;
    color: var(--md-sys-color-on-surface);
    font-family: var(--font-family);
    font-size: 1.05rem;
    font-weight: 600;
    outline: none;
    transition: border-color 0.2s ease, background-color 0.2s ease, box-shadow 0.2s ease;
}

.m3-dialog-input-wrapper input:focus {
    background: var(--md-sys-color-surface-container-lowest);
    border-color: var(--color-primary);
    box-shadow: 0 0 0 3px rgba(26, 115, 232, 0.2);
}

.m3-dialog-actions {
    display: flex;
    justify-content: flex-end;
    align-items: center;
    gap: 8px;
    margin-top: 8px;
}

.m3-dialog-actions .action-btn {
    margin-top: 0;
    padding: 8px 20px;
    font-size: 0.9rem;
}

.m3-dialog-actions .action-btn.cancel {
    background: transparent;
    color: var(--text-muted);
    box-shadow: none;
}

.m3-dialog-actions .action-btn.cancel:hover {
    background: var(--md-sys-color-surface-container-high);
    color: var(--text-main);
}

	/* =========================================
   DYNAMIC FLIP BADGE (ALL VIEWS)
   ========================================= */

.tooltip-flip-badge {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 2px 7px;
    border-radius: 6px;
    font-size: 0.68rem;
    font-weight: 800;
    letter-spacing: 0.5px;
    margin-left: 6px;
    vertical-align: middle;
    text-transform: uppercase;
}

.tooltip-flip-badge .material-symbols-rounded {
    font-size: 13px !important;
    line-height: 1;
	color: var(--text-main);
}

/* Color according to the flipping party */

body.dark-mode .tooltip-flip-badge.dem-flip {
    background: var(--md-sys-color-surface-container-lowest);
    color: var(--color-primary);
    border: 1px solid rgba(21, 101, 216, 0.35);
}

.tooltip-flip-badge.dem-flip {
    background: var(--color-primary);
    color: var(--md-sys-color-surface-container-lowest);
    border: 1px solid rgba(21, 101, 216, 0.35);
}

body.dark-mode .tooltip-flip-badge.rep-flip {
    background: var(--md-sys-color-surface-container-lowest);
    color: var(--color-secondary);
    border: 1px solid rgba(224, 45, 45, 0.35);
}

.tooltip-flip-badge.rep-flip {
    background: var(--color-secondary);
    color: var(--md-sys-color-surface-container-lowest);
    border: 1px solid rgba(224, 45, 45, 0.35);
}

body.dark-mode .tooltip-flip-badge.yel-flip {
    background: var(--md-sys-color-surface-container-lowest);
    color: var(--color-warning);
    border: 1px solid rgba(229, 136, 0, 0.35);
}

.tooltip-flip-badge.yel-flip {
    background: var(--color-warning);
    color: var(--md-sys-color-surface-container-lowest);
    border: 1px solid rgba(229, 136, 0, 0.35);
}

/* =========================================
   RESPONSIVE & MOBILE ADAPTABILITY
   ========================================= */

.map-input-pill,
.sidebar-backdrop,
.mobile-sheet-header {
    display: none;
}

/* =========================================
   1. TABLET & PHONE PORTRAIT MODE (BOTTOM SHEET)
   ========================================= */

@media (max-width: 960px) and (orientation: portrait) {
    .top-bar-layout {
        flex-wrap: wrap;
        height: auto;
        gap: 8px;
        margin: 8px 12px 0 12px;
    }

    header.nav-island {
        flex: 1;
        width: auto;
        height: 52px;
        order: 1;
    }

    .settings-wrapper.settings-island {
        width: 52px;
        height: 52px;
        order: 2;
    }

    .tally-stack {
        flex: 0 0 100%;
        width: 100%;
        height: var(--top-bar-height);
        order: 3;
    }

    .settings-menu {
        top: 68px;
    }

    /* Main Layout & Mobile Bottom Sheet */
    .main-layout {
        padding: 8px 12px 12px 12px;
        gap: 0;
    }

    .map-area {
        padding: 10px;
        width: 100%;
    }

    .map-input-pill {
        display: inline-flex;
        align-items: center;
        gap: 8px;
        position: fixed;
        bottom: 20px;
        left: 20px;
        height: 44px;
        padding: 0 18px;
        background: var(--surface-translucent);
        backdrop-filter: var(--glass-blur);
        -webkit-backdrop-filter: var(--glass-blur);
        border: var(--glass-border);
        border-radius: var(--radius-button);
        box-shadow: var(--shadow-level-3), var(--glass-highlight);
        color: var(--text-main);
        font-family: var(--font-family);
        font-size: 0.9rem;
        font-weight: 700;
        cursor: pointer;
        z-index: 35;
        transition: transform 0.25s var(--m3-ease-spring), box-shadow 0.2s ease, background-color 0.2s ease;
    }

    .map-input-pill:active {
        transform: scale(0.96);
    }

    .map-input-pill .material-symbols-rounded {
        font-size: 1.25rem;
        color: var(--color-primary);
    }

    .sidebar-backdrop {
        display: block;
        position: fixed;
        inset: 0;
        background: rgba(0, 0, 0, 0.45);
        backdrop-filter: blur(4px);
        -webkit-backdrop-filter: blur(4px);
        z-index: 45;
        opacity: 0;
        visibility: hidden;
        pointer-events: none;
        transition: opacity 0.3s ease, visibility 0.3s ease;
    }

    .sidebar-backdrop.active {
        opacity: 1;
        visibility: visible;
        pointer-events: auto;
    }

    .sidebar {
        position: fixed;
        left: 12px;
        right: 12px;
        bottom: 12px;
        width: auto;
        max-width: 480px;
        margin: 0 auto;
        max-height: 72vh;
        border-radius: var(--radius-card);
        background: var(--surface-translucent);
        backdrop-filter: var(--glass-blur);
        -webkit-backdrop-filter: var(--glass-blur);
        border: var(--glass-border);
        box-shadow: var(--shadow-level-3), var(--glass-highlight);
        padding: 12px 18px 20px 18px;
		
        z-index: 50;
        overflow-y: auto;
        overscroll-behavior: contain;
        transform: translateY(calc(100% + 24px));
        opacity: 0;
        visibility: hidden;
        pointer-events: none;
        transition: transform 0.42s var(--m3-ease-spring),
                    opacity 0.25s ease,
                    visibility 0.42s;
    }

    .sidebar.open {
        transform: translateY(0);
        opacity: 1;
        visibility: visible;
        pointer-events: auto;
    }

    .mobile-sheet-header {
        display: flex;
        align-items: center;
        justify-content: center;
        position: relative;
        min-height: 36px;
        padding-bottom: 6px;
        margin-bottom: 10px;
        cursor: grab;
        touch-action: none;
    }

    .mobile-sheet-header:active {
        cursor: grabbing;
    }

    .mobile-sheet-handle {
        width: 42px;
        height: 5px;
        background: var(--md-sys-color-outline-variant);
        border-radius: var(--radius-full);
        opacity: 0.85;
        transition: transform 0.2s ease, background-color 0.2s ease;
    }

    .mobile-sheet-header:active .mobile-sheet-handle {
        transform: scaleX(1.15);
        background: var(--text-muted);
    }

    .mobile-sheet-close {
        position: absolute;
        right: 0;
        top: 50%;
        transform: translateY(-50%);
        width: 32px;
        height: 32px;
    }

    .reset-zoom-btn {
        bottom: 74px;
    }
}

/* =========================================
   2. NARROW PHONE PORTRAIT OVERHAUL (<= 600px)
   ========================================= */

@media (max-width: 600px) and (orientation: portrait) {
    :root {
        --top-bar-height: 50px;
    }

    .top-bar-layout {
        margin: 8px 10px 0 10px;
        gap: 8px;
    }

    header.nav-island {
        height: 46px;
        padding: 0 10px 0 12px;
        border-radius: 23px;
    }

    .brand-logo {
        height: 30px;
        margin: 0;
    }

    .nav-links {
        padding: 2px;
        gap: 2px;
    }

    .nav-links .nav-tab {
        padding: 5px 9px;
        font-size: 0.76rem;
    }

    .nav-links .nav-tab.active {
        padding: 5px 11px;
    }

    .nav-links .nav-tab .material-symbols-rounded {
        font-size: 1.02rem;
    }

    .settings-wrapper.settings-island {
        width: 46px;
        height: 46px;
        border-radius: 23px;
    }

    .settings-wrapper .icon-btn {
        width: 36px;
        height: 36px;
    }

    /* EV & PV Tally Bar */
    .tally-stack {
        height: 50px;
    }

    .tally-wrapper {
        height: 50px;
        border-radius: 25px;
        overflow: hidden !important;
    }

    body[data-view="president"] .tally-stack:has(#pvTallyContainer.visible) .tally-wrapper {
        height: 34px;
        border-radius: 17px;
    }

    .tally-content {
        padding: 0 6px;
    }

    body[data-view="president"] .tally-stack:has(#pvTallyContainer.visible) .tally-content {
        padding: 0 4px;
    }

    .score-group {
        position: relative;
        gap: 4px !important;
        max-width: 44%;
    }

    .candidate-avatar {
        position: static !important;
        width: 34px !important;
        height: 34px !important;
        border-radius: 50% !important;
        margin: 0 !important;
        flex-shrink: 0;
    }

    body[data-view="president"] .tally-stack:has(#pvTallyContainer.visible) .candidate-avatar {
        width: 24px !important;
        height: 24px !important;
    }

    .pill-info {
        height: 34px !important;
        padding: 0 8px !important;
        gap: 5px !important;
        min-width: 0;
    }

    body[data-view="president"] .tally-stack:has(#pvTallyContainer.visible) .pill-info {
        height: 24px !important;
        padding: 0 7px !important;
        gap: 4px !important;
    }

    .pill-title {
        font-size: 0.68rem !important;
        letter-spacing: 0.1px !important;
        min-width: 0;
    }

    body[data-view="president"] .tally-stack:has(#pvTallyContainer.visible) .pill-title {
        font-size: 0.62rem !important;
    }

    #labelDem,
    #labelRep,
    #labelYel {
        display: inline-block;
        max-width: 58px;
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
    }

    .edit-label-btn {
        display: none !important;
    }

    .score {
        font-size: 1.15rem !important;
        padding-left: 5px !important;
    }

    #groupRep .pill-info .score {
        padding-left: 0 !important;
        padding-right: 5px !important;
    }

    body[data-view="president"] .tally-stack:has(#pvTallyContainer.visible) .score {
        font-size: 0.98rem !important;
        padding-left: 4px !important;
    }

    body[data-view="president"] .tally-stack:has(#pvTallyContainer.visible) #groupRep .pill-info .score {
        padding-left: 0 !important;
        padding-right: 4px !important;
    }

    .victory-badge {
        position: static !important;
        width: 22px !important;
        height: 22px !important;
        padding: 0 !important;
        border-radius: 50% !important;
        font-size: 0 !important;
        gap: 0 !important;
        justify-content: center;
        flex-shrink: 0;
    }

    body[data-view="president"] .tally-stack:has(#pvTallyContainer.visible) .victory-badge {
        width: 18px !important;
        height: 18px !important;
    }

    .victory-badge .material-symbols-rounded {
        font-size: 14px !important;
    }

    body[data-view="president"] .tally-stack:has(#pvTallyContainer.visible) .victory-badge .material-symbols-rounded {
        font-size: 12px !important;
    }

    .marker-label {
        font-size: 0.56rem !important;
        padding: 2px 6px !important;
        letter-spacing: 0.2px;
    }

    body[data-view="president"] .tally-stack:has(#pvTallyContainer.visible) .marker-label {
        font-size: 0.52rem !important;
        padding: 1px 5px !important;
    }

    /* Popular Vote Bar & Floating Pills */
    .pv-tally-container.visible {
        max-height: 10px;
        margin-top: 6px;
    }

    .pv-tally-wrapper {
        height: 10px;
    }

    .pv-labels {
        top: calc(100% + 4px);
        gap: 4px;
    }

    .pv-pill {
        padding: 2px 8px;
        max-height: 22px;
        border-radius: 11px;
    }

    .pv-pill.expanded {
        max-height: 44px;
    }

    .pv-pill-summary {
        font-size: 0.68rem;
    }

    .pv-pill-detail {
        font-size: 0.6rem;
    }

    #pvPillYel.visible {
        padding-left: 8px;
        padding-right: 8px;
    }

    /* Bottom Overlays */
    .map-input-pill {
        bottom: 14px;
        left: 12px;
        height: 40px;
        padding: 0 14px;
        font-size: 0.82rem;
    }

    .reset-zoom-btn {
        bottom: 14px !important;
        left: auto !important;
        right: 12px !important;
        transform: translateY(20px) !important;
        height: 40px;
        padding: 0 14px;
        font-size: 0.82rem;
    }

    .reset-zoom-btn.visible {
        transform: translateY(0) !important;
    }

    .faithless-disclaimer {
        bottom: 62px !important;
        left: 12px !important;
        right: 12px !important;
        width: fit-content;
        max-width: calc(100% - 24px);
        margin: 0 auto;
        padding: 5px 10px;
        font-size: 0.72rem;
        border-radius: var(--radius-full);
    }

    .size-warning {
        top: 32px;
        width: calc(100% - 24px);
        max-width: 360px;
        justify-content: space-between;
        font-size: 0.78rem;
        padding: 6px 12px;
    }

    /* Settings Menu Portrait Layout */
    .settings-menu {
        position: fixed !important;
        top: 62px !important;
        left: 10px !important;
        right: 10px !important;
        width: auto !important;
        max-width: none !important;
        max-height: calc(100dvh - 74px) !important;
        padding: 12px 14px !important;
        border-radius: 24px !important;
        overscroll-behavior: contain;
    }

    .menu-two-col {
        grid-template-columns: 1fr !important;
        gap: 8px !important;
    }

    .menu-col .view-president,
    .menu-col .view-senate,
    .menu-col .view-house {
        display: grid;
        grid-template-columns: 1fr 1fr;
        gap: 6px 8px;
    }

    .menu-accordion-group {
        grid-column: 1 / -1;
        margin-top: 0;
        margin-bottom: 2px;
    }

    .menu-col:last-child {
        display: grid;
        grid-template-columns: 1fr 1fr;
        gap: 6px 8px;
    }

    .menu-col:last-child .menu-col-title,
    .menu-col:last-child .view-president {
        grid-column: 1 / -1;
    }

    .menu-item.menu-item-dem,
    .menu-item.menu-item-rep {
        margin-bottom: 0 !important;
    }

    .menu-col .control-group {
        margin-bottom: 2px;
    }

    .control-group label,
    .menu-accordion-group label {
        font-size: 0.72rem;
        margin-bottom: 4px;
    }

    .control-group select,
    .settings-menu select {
        padding: 7px 28px 7px 12px;
        font-size: 0.78rem;
        background-position: right 10px center !important;
    }

    .menu-divider {
        margin: 8px 0 6px 0;
    }

    .menu-col-title {
        font-size: 0.68rem;
        margin-bottom: 4px;
    }

    .menu-grid {
        grid-template-columns: 1fr 1fr !important;
        gap: 5px 8px !important;
    }

    .menu-item {
        padding: 8px 10px;
        font-size: 0.76rem;
        gap: 6px;
    }

    .menu-item .material-symbols-rounded {
        width: 18px;
        height: 18px;
        font-size: 18px;
    }

    .menu-footer-version {
        padding: 8px 8px 2px 8px;
        font-size: 0.66rem;
    }

    /* Map Input Bottom Sheet */
    .sidebar {
        left: 8px;
        right: 8px;
        bottom: 8px;
        max-height: 64dvh;
        padding: 10px 14px 14px 14px;
        border-radius: 24px;
    }

    .mobile-sheet-header {
        min-height: 34px;
        padding-bottom: 4px;
        margin-bottom: 8px;
    }

    .sidebar h3 {
        font-size: 0.82rem;
        margin: 0 0 8px 0;
        padding-bottom: 6px;
    }

    .district-card {
        padding: 10px 12px;
        border-radius: 18px;
        margin-bottom: 10px;
    }

    .pv-input-row {
        flex-direction: row;
        align-items: center;
        justify-content: space-between;
        gap: 8px;
        padding: 6px 10px;
        margin-bottom: 6px;
    }

    .pv-input-row > span {
        font-size: 0.78rem;
        white-space: nowrap;
    }

    .pv-input-row input {
        width: 52%;
        font-size: 0.88rem;
        padding: 5px 10px !important;
    }

    #pvRowYel.visible {
        padding-top: 6px;
        padding-bottom: 6px;
        margin-bottom: 6px;
    }

    .state-env-drawer.visible {
        display: grid;
        grid-template-columns: 1fr 1fr;
        gap: 6px 8px;
    }

    .state-env-drawer .menu-divider,
    .state-env-drawer .menu-sub-btn {
        grid-column: 1 / -1;
    }

    .nat-env-tool {
        height: 34px;
        padding: 2px 4px;
    }

    .nat-env-tool .nat-env-display {
        font-size: 0.8rem;
    }

    .nat-env-btn {
        width: 28px;
        height: 28px;
    }

    /* Prompt & Confirm Popups */
    .m3-dialog-backdrop {
        align-items: flex-start;
        padding-top: 14dvh;
    }

    .m3-dialog {
        max-width: 340px;
        padding: 18px 18px 16px 18px;
        border-radius: 24px;
        gap: 10px;
    }

    .m3-dialog-title {
        font-size: 1.05rem;
    }

    .m3-dialog-message {
        font-size: 0.82rem;
    }

    .m3-dialog-input-wrapper input {
        padding: 10px 14px;
        font-size: 0.95rem;
    }

    .m3-dialog-actions .action-btn {
        padding: 8px 16px;
        font-size: 0.84rem;
    }
}

/* =========================================
   3. MOBILE LANDSCAPE MODE (DOCKED LEFT SIDEBAR)
   ========================================= */

@media (max-width: 960px) and (orientation: landscape),
       (max-height: 520px) and (orientation: landscape) {
    :root {
        --sidebar-width: 230px;
        --top-bar-height: 46px;
    }

    .top-bar-layout {
        margin: 6px 10px 0 10px;
        gap: 10px;
        height: var(--top-bar-height);
        flex-wrap: nowrap;
    }

    header.nav-island {
        width: var(--sidebar-width);
        height: 100%;
        padding: 0 6px 0 8px;
        border-radius: 20px;
        overflow: hidden;
    }
	
	.brand-container {
        gap: 4px;
        min-width: 0;
    }

    .brand-logo {
        height: 22px;
        margin: 0;
    }

    .nav-links {
        padding: 2px;
        gap: 1px;
        min-width: 0;
        flex-shrink: 1;
    }

    .nav-links .nav-tab {
        padding: 4px 5px;
        font-size: 0.68rem;
        gap: 3px;
    }

    .nav-links .nav-tab.active {
        padding: 4px 7px;
    }

    .nav-links .nav-tab .material-symbols-rounded {
        font-size: 0.9rem;
    }

    .settings-wrapper.settings-island {
        width: var(--top-bar-height);
        height: 100%;
        border-radius: 20px;
    }

    .settings-wrapper .icon-btn {
        width: 34px;
        height: 34px;
    }

    /* Compact Tally Stack in Landscape */
    .tally-wrapper {
        height: var(--top-bar-height);
        border-radius: 20px;
    }

    body[data-view="president"] .tally-stack:has(#pvTallyContainer.visible) .tally-wrapper {
        height: 32px;
        border-radius: 16px;
    }

    .tally-content {
        padding: 0 10px;
    }

    body[data-view="president"] .tally-stack:has(#pvTallyContainer.visible) .tally-content {
        padding: 0 6px;
    }

    .candidate-avatar {
        width: 32px;
        height: 32px;
        border-radius: 16px;
    }

    body[data-view="president"] .tally-stack:has(#pvTallyContainer.visible) .candidate-avatar {
        width: 22px;
        height: 22px;
        border-radius: 11px;
    }

    .pill-info {
        height: 32px !important;
        padding: 0 10px !important;
        gap: 6px !important;
    }

    body[data-view="president"] .tally-stack:has(#pvTallyContainer.visible) .pill-info {
        height: 22px !important;
        padding: 0 8px !important;
        gap: 4px !important;
    }

    .pill-title {
        font-size: 0.7rem !important;
    }

    body[data-view="president"] .tally-stack:has(#pvTallyContainer.visible) .pill-title {
        font-size: 0.62rem !important;
    }

    .edit-label-btn {
        display: none !important;
    }

    .score {
        font-size: 1.25rem !important;
        padding-left: 6px !important;
    }

    #groupRep .pill-info .score {
        padding-left: 0 !important;
        padding-right: 6px !important;
    }

    body[data-view="president"] .tally-stack:has(#pvTallyContainer.visible) .score {
        font-size: 0.96rem !important;
        padding-left: 4px !important;
    }

    body[data-view="president"] .tally-stack:has(#pvTallyContainer.visible) #groupRep .pill-info .score {
        padding-left: 0 !important;
        padding-right: 4px !important;
    }

    .victory-badge {
        padding: 3px 8px;
        font-size: 0.65rem;
    }

    body[data-view="president"] .tally-stack:has(#pvTallyContainer.visible) .victory-badge {
        padding: 2px 6px;
        font-size: 0.58rem;
    }

    .marker-label {
        font-size: 0.6rem !important;
        padding: 2px 7px !important;
    }

    body[data-view="president"] .tally-stack:has(#pvTallyContainer.visible) .marker-label {
        font-size: 0.54rem !important;
        padding: 1px 6px !important;
    }

    .pv-tally-container.visible {
        max-height: 9px;
        margin-top: 5px;
    }

    .pv-tally-wrapper {
        height: 9px;
    }

    .pv-labels {
        top: calc(100% + 4px);
    }

    .pv-pill {
        padding: 2px 9px;
        max-height: 21px;
    }

    .pv-pill-summary {
        font-size: 0.68rem;
    }

    /* Main Layout: Permanent Docked Left Sidebar + Map Area */
    .main-layout {
        padding: 6px 10px 8px 10px;
        gap: 10px;
    }

    .sidebar {
        width: var(--sidebar-width);
        padding: 10px;
        border-radius: 20px;
    }

    .sidebar h3 {
        font-size: 0.8rem;
        margin: 0 0 6px 0;
        padding-bottom: 5px;
    }

    .district-card {
        padding: 10px;
        border-radius: 16px;
        margin-bottom: 8px;
    }

    .small-states-grid {
        gap: 5px 4px;
    }

    .small-state-item .label {
        font-size: 0.72rem;
    }

    .small-state-item button {
        width: 30px;
        height: 30px;
        font-size: 0.76rem;
    }

    .pv-input-row {
        flex-direction: row;
        align-items: center;
        justify-content: space-between;
        padding: 5px 8px;
        margin-bottom: 5px;
    }

    .pv-input-row > span {
        font-size: 0.72rem;
    }

    .pv-input-row input {
        width: 50%;
        font-size: 0.8rem;
        padding: 4px 8px !important;
    }

    .map-area {
        padding: 6px 12px;
    }

    /* Settings Menu in Landscape */
    .settings-menu {
        top: 56px;
        right: 10px;
        max-height: calc(100dvh - 64px);
        padding: 12px 14px;
        border-radius: 20px;
    }

    .reset-zoom-btn {
        bottom: 14px;
        padding: 6px 12px;
        font-size: 0.8rem;
    }

    .faithless-disclaimer {
        bottom: 10px;
        left: 12px;
        padding: 5px 10px;
        font-size: 0.72rem;
    }
}

/* =========================================
   SENATE POPULAR VOTE MODE ADDITIONS (v5.1.0)
   ========================================= */

/* Shrink Senate Tally Bar to share the 64px top-bar space when Senate PV Mode is active */
body[data-view="senate"] .tally-stack:has(#pvTallyContainer.visible) .tally-wrapper {
    height: 44px;
    border-radius: 22px;
}

body[data-view="senate"] .tally-stack:has(#pvTallyContainer.visible) .tally-content {
    padding: 0 10px;
}

body[data-view="senate"] .tally-stack:has(#pvTallyContainer.visible) .marker-label {
    font-size: 0.65rem;
    padding: 2px 8px;
}

body[data-view="senate"] .tally-stack:has(#pvTallyContainer.visible) .score-group {
    gap: 8px;
}

body[data-view="senate"] .tally-stack:has(#pvTallyContainer.visible) .pill-info {
    height: 32px;
    padding: 0 10px;
    gap: 6px;
}

body[data-view="senate"] .tally-stack:has(#pvTallyContainer.visible) .pill-title {
    font-size: 0.74rem;
}

body[data-view="senate"] .tally-stack:has(#pvTallyContainer.visible) .score {
    font-size: 1.35rem !important;
    padding-left: 6px;
}

body[data-view="senate"] .tally-stack:has(#pvTallyContainer.visible) #groupYel .score {
    font-size: 1.25rem !important;
}

body[data-view="senate"] .tally-stack:has(#pvTallyContainer.visible) #groupRep .pill-info .score {
    padding-left: 0;
    padding-right: 6px;
}

body[data-view="senate"] .tally-stack:has(#pvTallyContainer.visible) .victory-badge {
    padding: 3px 9px;
    font-size: 0.66rem;
    gap: 4px;
}

body[data-view="senate"] .tally-stack:has(#pvTallyContainer.visible) .victory-badge .material-symbols-rounded {
    font-size: 0.92rem;
}

@media (max-width: 600px) and (orientation: portrait) {
    body[data-view="senate"] .tally-stack:has(#pvTallyContainer.visible) .tally-wrapper {
        height: 34px;
        border-radius: 17px;
    }
    body[data-view="senate"] .tally-stack:has(#pvTallyContainer.visible) .pill-info {
        height: 24px !important;
        padding: 0 7px !important;
        gap: 4px !important;
    }
    body[data-view="senate"] .tally-stack:has(#pvTallyContainer.visible) .score {
        font-size: 0.98rem !important;
        padding-left: 4px !important;
    }
    body[data-view="senate"] .tally-stack:has(#pvTallyContainer.visible) #groupRep .pill-info .score {
        padding-left: 0 !important;
        padding-right: 4px !important;
    }
    body[data-view="senate"] .tally-stack:has(#pvTallyContainer.visible) .victory-badge {
        width: 18px !important;
        height: 18px !important;
    }
}

@media (max-width: 960px) and (orientation: landscape),
       (max-height: 520px) and (orientation: landscape) {
    body[data-view="senate"] .tally-stack:has(#pvTallyContainer.visible) .tally-wrapper {
        height: 32px;
        border-radius: 16px;
    }
    body[data-view="senate"] .tally-stack:has(#pvTallyContainer.visible) .pill-info {
        height: 22px !important;
        padding: 0 8px !important;
    }
    body[data-view="senate"] .tally-stack:has(#pvTallyContainer.visible) .score {
        font-size: 0.96rem !important;
    }
}

/* Senate PV Row & Sub-Drawer Sizing */
#senatePvRowYel {
    max-height: 0;
    height: 0;
    opacity: 0;
    padding-top: 0;
    padding-bottom: 0;
    margin-top: -6px;
    border-width: 0;
    overflow: hidden;
    visibility: hidden;
    transition: max-height 0.35s var(--m3-ease-emphasized),
                height 0.35s var(--m3-ease-emphasized),
                padding 0.35s var(--m3-ease-emphasized),
                margin-top 0.35s var(--m3-ease-emphasized),
                opacity 0.25s ease,
                border-width 0.35s ease,
                visibility 0.35s;
}

#senatePvRowYel.visible {
    max-height: 38px;
    height: 38px;
    opacity: 1;
    padding-top: 4px;
    padding-bottom: 4px;
    margin-top: 0;
    border-width: 1px;
    visibility: visible;
}

#senatePVSubDrawer.visible {
    max-height: 280px;
}

/* Senate Candidate Name Input Rows */
.pv-input-row input.senate-cand-name-input {
    text-align: left;
    font-weight: 600;
    font-size: 0.84rem;
    padding: 2px 12px !important;
}

#senateNameRowYel {
    max-height: 0;
    height: 0;
    opacity: 0;
    padding-top: 0;
    padding-bottom: 0;
    margin-top: -6px;
    border-width: 0;
    overflow: hidden;
    visibility: hidden;
    transition: max-height 0.35s var(--m3-ease-emphasized),
                height 0.35s var(--m3-ease-emphasized),
                padding 0.35s var(--m3-ease-emphasized),
                margin-top 0.35s var(--m3-ease-emphasized),
                opacity 0.25s ease,
                border-width 0.35s ease,
                visibility 0.35s;
}

#senateNameRowYel.visible {
    max-height: 38px;
    height: 38px;
    opacity: 1;
    padding-top: 4px;
    padding-bottom: 4px;
    margin-top: 0;
    border-width: 1px;
    visibility: visible;
}

#senateCaucusDrawer.visible {
    max-height: 380px;
}

@media (max-width: 600px) and (orientation: portrait) {
    #senateCaucusDrawer.visible {
        display: block;
        max-height: 380px;
    }
}

/* House Popular Vote Mode Additions */
body[data-view="house"] .tally-stack:has(#pvTallyContainer.visible) .tally-wrapper {
    height: 44px;
    border-radius: 22px;
}
body[data-view="house"] .tally-stack:has(#pvTallyContainer.visible) .tally-content {
    padding: 0 10px;
}
body[data-view="house"] .tally-stack:has(#pvTallyContainer.visible) .marker-label {
    font-size: 0.65rem;
    padding: 2px 8px;
}
body[data-view="house"] .tally-stack:has(#pvTallyContainer.visible) .pill-info {
    height: 32px;
    padding: 0 10px;
    gap: 6px;
}
body[data-view="house"] .tally-stack:has(#pvTallyContainer.visible) .pill-title {
    font-size: 0.74rem;
}
body[data-view="house"] .tally-stack:has(#pvTallyContainer.visible) .score {
    font-size: 1.35rem !important;
    padding-left: 6px;
}
body[data-view="house"] .tally-stack:has(#pvTallyContainer.visible) #groupRep .pill-info .score {
    padding-left: 0;
    padding-right: 6px;
}
#housePvRowYel,
#houseNameRowYel {
    max-height: 0;
    height: 0;
    opacity: 0;
    padding-top: 0;
    padding-bottom: 0;
    margin-top: -6px;
    border-width: 0;
    overflow: hidden;
    visibility: hidden;
    transition: max-height 0.35s var(--m3-ease-emphasized), height 0.35s var(--m3-ease-emphasized), opacity 0.25s ease, visibility 0.35s;
}
#housePvRowYel.visible,
#houseNameRowYel.visible {
    max-height: 38px;
    height: 38px;
    opacity: 1;
    padding-top: 4px;
    padding-bottom: 4px;
    margin-top: 0;
    border-width: 1px;
    visibility: visible;
}
#housePVSubDrawer.visible {
    max-height: 340px;
}

/* =========================================
   GOVERNOR VIEW & POPULAR VOTE ADDITIONS (v6.0)
   ========================================= */

body[data-view="governor"] .tally-stack:has(#pvTallyContainer.visible) .tally-wrapper {
    height: 44px;
    border-radius: 22px;
}

body[data-view="governor"] .tally-stack:has(#pvTallyContainer.visible) .tally-content {
    padding: 0 10px;
}

body[data-view="governor"] .tally-stack:has(#pvTallyContainer.visible) .marker-label {
    font-size: 0.65rem;
    padding: 2px 8px;
}

body[data-view="governor"] .tally-stack:has(#pvTallyContainer.visible) .score-group {
    gap: 8px;
}

body[data-view="governor"] .tally-stack:has(#pvTallyContainer.visible) .pill-info {
    height: 32px;
    padding: 0 10px;
    gap: 6px;
}

body[data-view="governor"] .tally-stack:has(#pvTallyContainer.visible) .pill-title {
    font-size: 0.74rem;
}

body[data-view="governor"] .tally-stack:has(#pvTallyContainer.visible) .score {
    font-size: 1.35rem !important;
    padding-left: 6px;
}

body[data-view="governor"] .tally-stack:has(#pvTallyContainer.visible) #groupYel .score {
    font-size: 1.25rem !important;
}

body[data-view="governor"] .tally-stack:has(#pvTallyContainer.visible) #groupRep .pill-info .score {
    padding-left: 0;
    padding-right: 6px;
}

body[data-view="governor"] .tally-stack:has(#pvTallyContainer.visible) .victory-badge {
    padding: 3px 9px;
    font-size: 0.66rem;
    gap: 4px;
}

body[data-view="governor"] .tally-stack:has(#pvTallyContainer.visible) .victory-badge .material-symbols-rounded {
    font-size: 0.92rem;
}

#govPvRowYel,
#govNameRowYel {
    max-height: 0;
    height: 0;
    opacity: 0;
    padding-top: 0;
    padding-bottom: 0;
    margin-top: -6px;
    border-width: 0;
    overflow: hidden;
    visibility: hidden;
    transition: max-height 0.35s var(--m3-ease-emphasized),
                height 0.35s var(--m3-ease-emphasized),
                padding 0.35s var(--m3-ease-emphasized),
                margin-top 0.35s var(--m3-ease-emphasized),
                opacity 0.25s ease,
                border-width 0.35s ease,
                visibility 0.35s;
}

#govPvRowYel.visible,
#govNameRowYel.visible {
    max-height: 38px;
    height: 38px;
    opacity: 1;
    padding-top: 4px;
    padding-bottom: 4px;
    margin-top: 0;
    border-width: 1px;
    visibility: visible;
}

#govPVSubDrawer.visible {
    max-height: 280px;
}

#govCaucusDrawer.visible {
    max-height: 380px;
}

/* =========================================
   ANDROID WEBVIEW FULL-SCREEN & SAFE AREAS
   ========================================= */

:root {
    --safe-top: env(safe-area-inset-top, 0px);
    --safe-right: env(safe-area-inset-right, 0px);
    --safe-bottom: env(safe-area-inset-bottom, 0px);
    --safe-left: env(safe-area-inset-left, 0px);
    /* Balanced bezel cushion so outer pills concentric-match rounded phone corners */
    --corner-pad: 14px;
}

*, *::before, *::after {
    -webkit-tap-highlight-color: transparent;
}

html, body {
    overscroll-behavior: none;
    width: 100%;
    height: 100%;
    height: 100dvh;
    margin: 0;
    padding: 0;
}

/* Base / Desktop / Tablet */
.top-bar-layout {
    margin-top: calc(10px + var(--safe-top));
    margin-left: calc(var(--corner-pad) + var(--safe-left));
    margin-right: calc(var(--corner-pad) + var(--safe-right));
}

.main-layout {
    padding-top: 10px;
    padding-left: calc(var(--corner-pad) + var(--safe-left));
    padding-right: calc(var(--corner-pad) + var(--safe-right));
    padding-bottom: calc(12px + var(--safe-bottom));
}

.settings-menu {
    top: calc(76px + var(--safe-top));
    right: calc(var(--corner-pad) + var(--safe-right));
    max-height: calc(100dvh - 92px - var(--safe-top) - var(--safe-bottom));
}

/* =========================================
   PORTRAIT MODE CORNER & BEZEL CUSHION
   ========================================= */
@media (max-width: 960px) and (orientation: portrait) {
    .top-bar-layout {
        /* Extra 8px below the camera hole-punch + 14px side breathing room */
        margin-top: calc(8px + var(--safe-top)) !important;
        margin-left: calc(14px + var(--safe-left)) !important;
        margin-right: calc(14px + var(--safe-right)) !important;
        gap: 8px;
    }

    .main-layout {
        padding-top: 8px !important;
        padding-left: calc(14px + var(--safe-left)) !important;
        padding-right: calc(14px + var(--safe-right)) !important;
        padding-bottom: calc(16px + var(--safe-bottom)) !important;
    }

    /* Pull bottom pills inward from the curved bottom-left/right screen corners */
    .map-input-pill {
        bottom: calc(22px + var(--safe-bottom)) !important;
        left: calc(18px + var(--safe-left)) !important;
    }

    .reset-zoom-btn {
        bottom: calc(22px + var(--safe-bottom)) !important;
        right: calc(18px + var(--safe-right)) !important;
    }

    .sidebar {
        left: calc(12px + var(--safe-left)) !important;
        right: calc(12px + var(--safe-right)) !important;
        bottom: calc(16px + var(--safe-bottom)) !important;
    }

    .settings-menu {
        top: calc(66px + var(--safe-top)) !important;
        left: calc(12px + var(--safe-left)) !important;
        right: calc(12px + var(--safe-right)) !important;
    }
}

/* =========================================
   LANDSCAPE MODE CORNER & BEZEL CUSHION
   ========================================= */
@media (max-height: 600px) and (orientation: landscape),
       (max-width: 960px) and (orientation: landscape) {
    :root {
        --sidebar-width: 240px;
        --top-bar-height: 44px;
    }

    .top-bar-layout {
        /* 10px top/bottom clears the top bezel curve; 16px right clears the right corner curve */
        margin-top: calc(10px + var(--safe-top)) !important;
        margin-left: calc(10px + var(--safe-left)) !important;
        margin-right: calc(16px + max(var(--safe-right), 4px)) !important;
        gap: 10px;
        height: var(--top-bar-height);
    }

    .main-layout {
        padding-top: 8px !important;
        padding-left: calc(10px + var(--safe-left)) !important;
        padding-right: calc(16px + max(var(--safe-right), 4px)) !important;
        padding-bottom: calc(10px + var(--safe-bottom)) !important;
        gap: 10px;
    }

    .map-area {
        padding: 4px 8px;
    }

    .settings-menu {
        top: calc(60px + var(--safe-top)) !important;
        right: calc(16px + max(var(--safe-right), 4px)) !important;
        max-height: calc(100dvh - 72px - var(--safe-top) - var(--safe-bottom)) !important;
    }
}

/* =========================================
   ANDROID GPU & SVG RENDERING OPTIMIZATIONS
   ========================================= */

.main-layout,
.map-area,
.map-area svg {
    overflow: visible !important;
    contain: none !important;
}

.map-area svg {
    filter: none !important;
    /* Do NOT set will-change or translate3d at rest so desktop vectors stay razor-sharp */
}

/* Promote to a fast GPU texture ONLY during an active touch/drag gesture */
body.is-panning .map-area svg {
    will-change: transform;
}

body.is-panning .state,
body.is-panning .hex,
body.is-panning .borders {
    shape-rendering: optimizeSpeed;
    transition: none !important;
}

/* =========================================
   FIX STICKY :HOVER & :ACTIVE ON TOUCH SCREENS
   ========================================= */

@media (hover: none), (pointer: coarse) {
    /* 1. Prevent tapped SVG states and House hexes from staying faded at 0.78/0.82 opacity */
    .state:hover:not(.inactive),
    .hex:hover,
    .state:focus,
    .hex:focus {
        opacity: 1 !important;
        outline: none !important;
    }

    /* 2. Prevent small-state tiles & district dots from staying lifted/highlighted after tap */
    .small-state-item button:hover,
    .district-dots button:hover {
        transform: none;
        box-shadow: var(--shadow-level-1);
    }

    .small-state-item button.selected-state:hover {
        transform: scale(1.08);
    }

    /* 3. Prevent non-active buttons from latching onto their :hover background color */
    .icon-btn:hover {
        background-color: var(--md-sys-color-surface-container-high);
        color: var(--md-sys-color-on-surface-variant);
        border-radius: 50%;
    }

    .nav-links .nav-tab:not(.active):hover,
    .status-seg-btn:not(.active):hover,
    .menu-item:not(.active-toggle):not(.menu-item-dem):not(.menu-item-rep):not(.menu-item-yel):hover,
    .scenario-btn-row .scenario-half-btn:hover,
    .m3-select-option:not(.selected):hover {
        background-color: transparent;
    }

    .menu-sub-btn:not(.active-toggle):hover,
    .toggle-btn:not(.active):hover,
    .action-btn.reset-district-btn:not(.active):hover {
        background-color: var(--md-sys-color-surface-container-high);
        color: var(--text-muted);
    }

    .nat-env-btn:hover {
        background-color: transparent !important;
    }

    .action-btn:hover {
        transform: none;
        filter: none;
        box-shadow: var(--shadow-level-1);
    }

    /* 4. Disable hover-based expansion on Popular Vote pills (let tap handler in app.js control it) */
    .pv-pill:hover:not(.expanded) {
        max-height: 22px;
        box-shadow: var(--shadow-level-1), var(--glass-highlight);
        background: var(--surface-translucent);
    }

    .pv-pill:hover:not(.expanded) .pv-pill-detail {
        opacity: 0;
        max-height: 0;
        transform: translateY(-4px);
        margin-top: 0;
    }

    .pv-pill.expanded .pv-pill-detail {
        opacity: 1;
        max-height: 20px;
        transform: translateY(0);
        margin-top: 3px;
    }
}

/* =========================================
   MOBILE ANIMATION & COMPOSITOR OPTIMIZATIONS
   (Preserves full desktop glass/filters)
   ========================================= */

@media (hover: none), (pointer: coarse) {
    /* 1. Replace heavy real-time backdrop-filter blur on mobile with high-opacity surfaces
       so expanding sidebar cards don't trigger 60fps full-screen blur re-renders */
    :root {
        --glass-blur: none;
        --surface-translucent: rgba(255, 255, 255, 0.94);
        --surface-translucent-card: rgba(246, 245, 255, 0.96);
        --surface-card-nested: rgba(255, 255, 255, 0.95);
    }

    body.dark-mode {
        --surface-translucent: rgba(22, 22, 32, 0.95);
        --surface-translucent-card: rgba(26, 26, 38, 0.96);
        --surface-card-nested: rgba(32, 32, 46, 0.95);
    }

    /* 2. Remove software grayscale() filter on dimmed map states/hexes (use flat fill + opacity) */
    .state.non-flip-dimmed,
    .hex.non-flip-dimmed {
        filter: none !important;
        opacity: 0.28 !important;
    }

    .small-state-item button.non-flip-dimmed {
        filter: none !important;
        opacity: 0.35 !important;
    }

    /* 3. Fast, snappy accordion transitions on touch devices (180ms vs 400ms reflow) */
    .district-card.pv-shift-card,
    #pvShiftCard,
    .district-card.comp-states-card,
    #competitiveStatesCard,
    .district-card.paint-palette-card,
    .district-card.multi-select-card,
    #pvSidebar,
    .state-env-drawer,
    .comp-results-drawer,
    .pv-split-section {
        transition: opacity 0.18s ease,
                    transform 0.18s var(--m3-ease-standard),
                    max-height 0.2s var(--m3-ease-standard),
                    padding 0.2s var(--m3-ease-standard),
                    margin 0.2s var(--m3-ease-standard),
                    visibility 0.2s !important;
    }

    /* 4. Prevent SVG state/hex fill transitions from queuing 435 simultaneous style recalcs */
    .state,
    .hex {
        transition: fill 0.1s ease, opacity 0.1s ease !important;
    }

    /* 5. Isolate sidebar layout recalculations from the SVG map viewport */
    .sidebar {
        contain: layout style;
    }
}

.map-area,
.state,
.hex,
.pv-pill,
.pv-pill * {
    -webkit-touch-callout: none !important;
    -webkit-user-select: none !important;
    user-select: none !important;
}

.pv-pill.expanded {
    max-height: 56px !important;
    box-shadow: var(--shadow-level-2) !important;
    background: var(--surface-translucent-card) !important;
    z-index: 35 !important;
}