/* ============================================
   DEMOGRAPHIC SWINGOMETER
   Controls left, map right
   ============================================ */

:root {
    color-scheme: dark;
    --bg-primary: #0f172a;
    --bg-secondary: #1e293b;
    --bg-tertiary: #334155;
    --bg-hover: #475569;
    --bg-card: #1e293b;
    --text-primary: #f8fafc;
    --text-secondary: #e2e8f0;
    --text-muted: #cbd5e1;
    --text-dim: #94a3b8;
    --border-color: #334155;
    --accent-secondary: #3b82f6;
    --success: #22c55e;
    --warning: #eab308;
    --error: #ef4444;
    --party-labour: #E3242B;
    --party-conservative: #2E8BC0;
    --party-libdem: #FAC032;
    --party-reform: #29C5DB;
    --party-green: #3CB371;
    --party-snp: #FFED4A;
    --party-pc: #5AAD44;
    --party-others: #A8A8A8;
    --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.3);
    --shadow-md: 0 4px 6px rgba(0, 0, 0, 0.3);
    --radius: 10px;
    --radius-sm: 6px;
}

.light-mode {
    color-scheme: light;
    --bg-primary: #eef2f7;
    --bg-secondary: #f8fafc;
    --bg-tertiary: #e2e8f0;
    --bg-hover: #d5dce6;
    --bg-card: #ffffff;
    --text-primary: #1e293b;
    --text-secondary: #334155;
    --text-muted: #475569;
    --text-dim: #64748b;
    --border-color: #b8c4d0;
    --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.1);
    --shadow-md: 0 4px 8px rgba(0, 0, 0, 0.12);
    --party-snp: #b8960f;
}

/* === BASE === */
.calc-body {
    background: var(--bg-primary);
    color: var(--text-primary);
    min-height: 100vh;
    font-family: 'Inter', -apple-system, sans-serif;
    overflow-x: hidden;
}

.calc-container {
    max-width: 1400px;
    margin: 0 auto;
    padding: 0.75rem 1rem;
}

/* === HEADER === */
.calc-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 0.5rem;
    padding-bottom: 0.5rem;
    border-bottom: 0.5px solid var(--border-color);
}

.calc-header h1 {
    font-size: 1.2rem;
    font-weight: 700;
    margin: 0;
}

.calc-header-right {
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

.btn { padding: 0.35rem 0.7rem; border-radius: var(--radius-sm); font-weight: 600; font-size: 0.78rem; cursor: pointer; border: none; transition: all 0.15s; }
.btn-secondary { background: var(--bg-tertiary); color: var(--text-secondary); border: 1px solid var(--border-color); }
.btn-secondary:hover { background: var(--bg-hover); }
.btn-sm { padding: 0.3rem 0.6rem; font-size: 0.72rem; }
.theme-toggle { padding: 0.35rem 0.7rem; background: var(--bg-tertiary); border: 1px solid var(--border-color); border-radius: var(--radius-sm); color: var(--text-secondary); cursor: pointer; font-size: 0.75rem; }
.theme-toggle:hover { background: var(--bg-hover); }
.source-detail { font-size: 0.65rem; color: var(--text-dim); }

.mrp-badge {
    display: inline-block;
    padding: 2px 8px;
    background: linear-gradient(135deg, #6366f1, #8b5cf6);
    color: white;
    font-size: 0.6rem;
    font-weight: 700;
    border-radius: 4px;
    text-transform: uppercase;
    vertical-align: middle;
    margin-left: 6px;
}

/* === INTRO BAR === */
.intro-bar {
    margin-bottom: 0.5rem;
    padding-bottom: 0.5rem;
    border-bottom: 0.5px solid var(--border-color);
}
.intro-top {
    display: flex;
    align-items: baseline;
    justify-content: space-between;
    gap: 1rem;
}
.intro-subhead {
    font-size: 0.82rem;
    line-height: 1.5;
    color: var(--text-muted);
    margin: 0;
}
.intro-subhead strong {
    color: var(--text-primary);
    font-weight: 700;
}
.intro-toggle {
    background: none;
    border: none;
    color: var(--text-dim);
    font-size: 0.72rem;
    font-weight: 600;
    cursor: pointer;
    white-space: nowrap;
    padding: 0;
    font-family: inherit;
    transition: color 0.15s;
    flex-shrink: 0;
}
.intro-toggle:hover { color: var(--accent-secondary); }
.intro-toggle-icon {
    font-size: 0.55rem;
    display: inline-block;
    transition: transform 0.2s;
    margin-left: 2px;
}
.intro-toggle.open .intro-toggle-icon {
    transform: rotate(180deg);
}
.intro-detail {
    max-height: 0;
    overflow: hidden;
    transition: max-height 0.3s ease, padding 0.3s ease;
    padding: 0;
}
.intro-detail.open {
    max-height: 300px;
    padding: 0.6rem 0 0;
}
.intro-detail p {
    font-size: 0.78rem;
    line-height: 1.6;
    color: var(--text-muted);
    margin: 0 0 0.5rem;
}
.intro-detail p:last-child { margin-bottom: 0; }
.intro-detail strong {
    color: var(--text-secondary);
}
.intro-detail-link {
    display: inline-block;
    margin-top: 0.25rem;
    color: var(--accent-secondary);
    font-size: 0.72rem;
    font-weight: 600;
    text-decoration: none;
}
.intro-detail-link:hover { text-decoration: underline; }

@media (max-width: 768px) {
    .intro-top { flex-direction: column; gap: 0.3rem; }
    .intro-subhead { font-size: 0.78rem; }
}

/* === EXPLAINER BAR === */
.explainer-bar {
    background: var(--bg-card);
    border: 0.5px solid var(--border-color);
    border-radius: var(--radius);
    margin-bottom: 0.5rem;
    overflow: hidden;
}

.explainer-toggle {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0.45rem 0.75rem;
    cursor: pointer;
    user-select: none;
}
.explainer-toggle:hover { background: var(--bg-tertiary); }
.explainer-toggle-label {
    font-size: 0.72rem;
    font-weight: 600;
    color: var(--text-muted);
}
.explainer-toggle-icon {
    font-size: 0.6rem;
    color: var(--text-dim);
    transition: transform 0.2s;
}

.explainer-content {
    max-height: 0;
    overflow: hidden;
    transition: max-height 0.3s ease, padding 0.3s ease;
    padding: 0 0.75rem;
}
.explainer-content.open {
    max-height: 400px;
    padding: 0 0.75rem 0.75rem;
}

.explainer-cols {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 1rem;
}
.explainer-col h4 {
    font-size: 0.72rem;
    font-weight: 700;
    color: var(--text-primary);
    margin: 0 0 0.3rem 0;
}
.explainer-col p {
    font-size: 0.68rem;
    color: var(--text-muted);
    line-height: 1.5;
    margin: 0 0 0.35rem 0;
}
.explainer-col p:last-child { margin-bottom: 0; }
.explainer-col strong { color: var(--text-secondary); }

@media (max-width: 768px) {
    .explainer-cols {
        grid-template-columns: 1fr;
        gap: 0.6rem;
    }
}

/* === INFO BUTTONS & BOXES (control panel) === */
.info-btn {
    display: inline-block;
    font-size: 0.72rem;
    color: var(--text-dim);
    cursor: pointer;
    margin-left: 4px;
    vertical-align: middle;
    border-radius: 50%;
    transition: color 0.15s;
    line-height: 1;
}
.info-btn:hover, .info-btn.active {
    color: var(--accent-secondary);
}

.info-box {
    max-height: 0;
    overflow: hidden;
    transition: max-height 0.25s ease, padding 0.25s ease, margin 0.25s ease;
    background: var(--bg-primary);
    border-radius: var(--radius-sm);
    padding: 0 0.5rem;
    margin: 0;
}
.info-box.open {
    max-height: 300px;
    overflow-y: auto;
    padding: 0.45rem 0.5rem;
    margin: 0.3rem 0 0.4rem;
    border: 1px solid var(--border-color);
}
.info-box p {
    font-size: 0.64rem;
    color: var(--text-muted);
    line-height: 1.5;
    margin: 0 0 0.3rem 0;
}
.info-box p:last-child { margin-bottom: 0; }
.info-box strong { color: var(--text-secondary); }

/* === SEAT BAR === */
.seat-bar { margin-bottom: 0.5rem; }

.seat-results-grid {
    display: flex;
    gap: 0.4rem;
    flex-wrap: wrap;
}

.seat-card {
    flex: 1 1 0;
    min-width: 70px;
    background: var(--bg-tertiary);
    border-radius: var(--radius-sm);
    padding: 0.4rem 0.3rem;
    text-align: center;
    border-top: 3px solid var(--party-color, var(--text-muted));
}

.seat-card.labour { --party-color: var(--party-labour); }
.seat-card.conservative { --party-color: var(--party-conservative); }
.seat-card.libdem { --party-color: var(--party-libdem); }
.seat-card.reform { --party-color: var(--party-reform); }
.seat-card.green { --party-color: var(--party-green); }
.seat-card.snp { --party-color: var(--party-snp); }
.seat-card.pc { --party-color: var(--party-pc); }
.seat-card.others { --party-color: var(--party-others); }

.seat-card .party-name { font-size: 0.6rem; font-weight: 600; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.02em; }
.seat-card .seat-count { font-size: 1.3rem; font-weight: 700; color: var(--party-color); line-height: 1.2; font-variant-numeric: tabular-nums; }
.seat-card .seat-change { font-size: 0.6rem; font-weight: 600; }
.seat-card .seat-change.positive { color: var(--success); }
.seat-card .seat-change.negative { color: var(--error); }
.seat-card .seat-change.neutral { color: var(--text-dim); }

/* === SCENARIO GRID: the core 2-column layout === */
.scenario-grid {
    display: grid;
    grid-template-columns: 280px 1fr;
    gap: 0.5rem;
    height: max(calc(100vh - 110px), 960px);
    margin-bottom: 0.75rem;
}

/* === CONTROLS PANEL (left) === */
.controls-panel {
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: var(--radius);
    overflow: hidden;
}

.controls-scroll {
    height: 100%;
    overflow-y: auto;
    padding: 0.75rem;
}

.controls-scroll::-webkit-scrollbar { width: 4px; }
.controls-scroll::-webkit-scrollbar-track { background: transparent; }
.controls-scroll::-webkit-scrollbar-thumb { background: var(--bg-hover); border-radius: 2px; }

.ctrl-section { margin-bottom: 0.75rem; }
.ctrl-section:last-child { margin-bottom: 0; }

.ctrl-title {
    font-size: 0.7rem;
    font-weight: 600;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.04em;
    margin-bottom: 0.4rem;
}

/* Segmented mode toggle (slider vs manual input) */
.mode-toggle {
    float: right; display: inline-flex; border: 1px solid var(--border-color);
    border-radius: 4px; overflow: hidden; line-height: 0;
}
.mode-btn {
    background: none; border: none; padding: 3px 6px; cursor: pointer;
    color: var(--text-dim); transition: all 0.15s; line-height: 0;
    display: flex; align-items: center; justify-content: center;
}
.mode-btn + .mode-btn { border-left: 1px solid var(--border-color); }
.mode-btn:hover { color: var(--text-muted); background: var(--bg-hover); }
.mode-btn.active { background: var(--accent-secondary); color: white; }

/* Slider mode (default): inputs look like plain text */
.party-slider-input { pointer-events: none; }
.party-slider-input:hover { border-color: transparent; }

/* Input mode: sliders hidden, inputs editable */
.input-mode .party-slider { display: none; }
.input-mode .party-slider-input {
    pointer-events: auto;
    width: 56px; padding: 4px 6px;
    background: var(--bg-tertiary); color: var(--text-primary);
    border: 1px solid var(--bg-hover); border-radius: 5px;
    font-size: 0.8rem;
}
.input-mode .party-slider-input:hover { border-color: var(--text-dim); }
.input-mode .party-slider-input:focus {
    border-color: var(--accent);
    box-shadow: 0 0 0 2px rgba(99,102,241,0.2);
}

/* Input mode: hide lock buttons (redistribution doesn't apply) */
.input-mode .lock-btn { display: none; }

.input-hint { font-size: 0.65rem; color: var(--text-dim); margin: 0 0 0.4rem 0; line-height: 1.3; }

/* === POLL SELECTOR PILLS === */
.poll-selector-pills {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    margin-bottom: 0.5rem;
}
.poll-pill {
    padding: 5px 10px;
    font-size: 0.68rem;
    font-weight: 600;
    background: var(--bg-tertiary);
    color: var(--text-muted);
    border: 1px solid var(--border-color);
    border-radius: 20px;
    cursor: pointer;
    transition: all 0.15s;
    white-space: nowrap;
}
.poll-pill:hover { background: var(--bg-hover); color: var(--text-primary); }
.poll-pill.active {
    background: var(--accent-secondary);
    color: #fff;
    border-color: var(--accent-secondary);
}

/* === PARTY SLIDER ROWS === */
.party-slider-row {
    display: flex;
    align-items: center;
    gap: 0.3rem;
    padding: 0.35rem 0.4rem;
    background: var(--bg-tertiary);
    border-radius: var(--radius-sm);
    border-left: 3px solid var(--party-color, var(--text-muted));
    margin-bottom: 0.3rem;
}

.party-slider-row.labour { --party-color: var(--party-labour); }
.party-slider-row.conservative { --party-color: var(--party-conservative); }
.party-slider-row.libdem { --party-color: var(--party-libdem); }
.party-slider-row.reform { --party-color: var(--party-reform); }
.party-slider-row.green { --party-color: var(--party-green); }
.party-slider-row.snp { --party-color: var(--party-snp); }
.party-slider-row.pc { --party-color: var(--party-pc); }
.party-slider-row.others { --party-color: var(--party-others); }

.party-slider-label { min-width: 42px; font-size: 0.65rem; font-weight: 600; color: var(--text-muted); text-transform: uppercase; }
.party-slider-wrap { flex: 1; min-width: 0; display: flex; align-items: center; gap: 0.4rem; }

.party-slider {
    flex: 1; min-width: 0; -webkit-appearance: none; appearance: none;
    height: 4px; background: var(--bg-hover); border-radius: 2px; outline: none; cursor: pointer;
}
.party-slider::-webkit-slider-thumb { -webkit-appearance: none; width: 14px; height: 14px; background: var(--party-color, #f97316); border-radius: 50%; cursor: pointer; box-shadow: var(--shadow-sm); }
.party-slider::-moz-range-thumb { width: 14px; height: 14px; background: var(--party-color, #f97316); border-radius: 50%; cursor: pointer; border: none; }

.party-slider-input {
    width: 48px; font-size: 0.72rem; font-weight: 700; color: var(--text-primary);
    text-align: right; flex-shrink: 0; background: transparent;
    border: 1px solid transparent; border-radius: 3px; padding: 1px 2px;
    font-family: inherit; -moz-appearance: textfield; transition: border-color 0.15s;
}
.party-slider-input:focus { outline: none; }
.party-slider-input::-webkit-inner-spin-button,
.party-slider-input::-webkit-outer-spin-button { -webkit-appearance: none; margin: 0; }

/* Lock button (vote share sliders) */
.lock-btn {
    width: 20px; height: 20px; border-radius: 3px; border: 1px solid var(--border-color);
    background: transparent; cursor: pointer; flex-shrink: 0; padding: 0;
    color: var(--text-dim); opacity: 0.5; transition: all 0.15s;
    display: flex; align-items: center; justify-content: center;
}
.lock-btn:hover { opacity: 0.7; border-color: var(--text-muted); }
.lock-btn.locked { background: var(--accent-secondary); border-color: var(--accent-secondary); color: white; opacity: 1; }

/* === REGIONAL PARTY DIVIDER === */
.regional-divider {
    display: flex; align-items: center; gap: 0.4rem;
    margin: 0.5rem 0 0.25rem; padding: 0; font-size: 0.6rem;
    font-weight: 700; text-transform: uppercase; letter-spacing: 0.05em;
    color: var(--text-dim);
}
.regional-divider::before, .regional-divider::after {
    content: ''; flex: 1; height: 1px; background: var(--border-color);
}
.regional-tag {
    display: block; font-size: 0.5rem; font-weight: 600;
    color: var(--text-dim);
    line-height: 1.2; margin-top: 1px;
}
.regional-label-toggle { cursor: pointer; }
.rb-chevron {
    display: inline-block; font-size: 0.4rem;
    transition: transform 0.2s; margin-left: 2px;
    vertical-align: middle;
}

/* Regional breakdown panel (collapsible) */
.regional-breakdown {
    max-height: 0; overflow: hidden;
    transition: max-height 0.25s ease, padding 0.25s ease, margin 0.25s ease;
    margin: 0; padding: 0 0.5rem;
    font-size: 0.62rem;
}
.regional-breakdown.open {
    max-height: 220px;
    padding: 0.35rem 0.5rem;
    margin: 0 0 0.3rem;
    background: var(--bg-primary);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
}
.rb-header {
    font-size: 0.55rem; font-weight: 700; text-transform: uppercase;
    letter-spacing: 0.04em; color: var(--text-dim); margin-bottom: 3px;
}
.rb-row {
    display: flex; align-items: center; gap: 0.3rem;
    padding: 1px 0; line-height: 1.3;
}
.rb-party { flex: 1; font-weight: 600; }
.rb-val { min-width: 38px; text-align: right; font-weight: 700; color: var(--text-primary); }
.rb-change { min-width: 36px; text-align: right; font-weight: 600; }
.rb-change.up { color: var(--success); }
.rb-change.down { color: #ef4444; }

/* === TURNOUT / TACTICAL SLIDERS === */
.turnout-slider-group { margin-bottom: 0.4rem; }
.turnout-slider-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 2px; }
.turnout-slider-label { font-size: 0.68rem; font-weight: 600; color: var(--text-muted); }
.turnout-slider-value { font-weight: 700; font-size: 0.72rem; min-width: 40px; text-align: right; }
.turnout-slider-value.positive { color: var(--success); }
.turnout-slider-value.negative { color: var(--error); }
.turnout-slider-value.neutral { color: var(--text-dim); }

.turnout-slider-container {
    position: relative; padding: 2px 0; display: flex; align-items: center; gap: 4px;
}
.turnout-range-label { font-size: 0.55rem; color: var(--text-dim); min-width: 28px; text-align: center; }
.turnout-slider-container::after {
    content: ''; position: absolute; left: 50%; top: 50%; transform: translate(-50%, -50%);
    width: 1px; height: 10px; background: var(--text-dim); pointer-events: none; opacity: 0.4; z-index: 1;
}

.turnout-slider {
    width: 100%; -webkit-appearance: none; appearance: none;
    height: 4px; background: var(--bg-hover); border-radius: 2px; outline: none; cursor: pointer;
}
.turnout-slider::-webkit-slider-thumb { -webkit-appearance: none; width: 12px; height: 12px; background: var(--accent-secondary); border-radius: 50%; cursor: pointer; }
.turnout-slider::-moz-range-thumb { width: 12px; height: 12px; background: var(--accent-secondary); border-radius: 50%; cursor: pointer; border: none; }

/* === TACTICAL PRESET BUTTONS === */
.tactical-presets { display: flex; gap: 0.35rem; margin-top: 0.5rem; }
.tactical-preset-btn {
    flex: 1; padding: 0.3rem 0.2rem; font-size: 0.62rem; font-weight: 600;
    border: 1px solid var(--border-color); border-radius: var(--radius-sm);
    background: var(--bg-tertiary); color: var(--text-primary); cursor: pointer;
    transition: background 0.15s, border-color 0.15s;
}
.tactical-preset-btn:hover { background: var(--bg-hover); }
.tactical-preset-btn.active { border-color: var(--accent-secondary); background: var(--bg-hover); }
.tactical-preset-btn.preset-reset { color: var(--text-dim); }

/* === TOTAL ROW === */
.total-row {
    display: flex; justify-content: space-between; align-items: center; flex-wrap: wrap;
    padding: 0.3rem 0.5rem; background: var(--bg-tertiary); border-radius: var(--radius-sm);
    margin-top: 0.4rem; border: 1px solid var(--border-color);
}
.total-row.valid { border-color: var(--success); }
.total-row.warning { border-color: var(--warning); }
.total-row.error { border-color: var(--danger, #ef4444); }
.total-row .label { font-size: 0.7rem; color: var(--text-muted); }
.total-row .value { font-size: 0.85rem; font-weight: 700; }
.auto-norm-hint {
    display: none; flex-basis: 100%; font-size: 0.6rem; color: var(--text-dim);
    text-align: right; margin-top: 2px;
}

/* === SUMMARY (bottom of controls) === */
.ctrl-summary {
    background: var(--bg-tertiary);
    border-radius: var(--radius-sm);
    padding: 0.5rem;
}

.summary-row { display: grid; grid-template-columns: 1fr 1fr; gap: 0.4rem; margin-bottom: 0.3rem; }
.summary-row:last-child { margin-bottom: 0; }
.summary-cell { text-align: center; }
.summary-lbl { display: block; font-size: 0.55rem; font-weight: 600; color: var(--text-dim); text-transform: uppercase; letter-spacing: 0.03em; }
.summary-val { display: block; font-size: 1rem; font-weight: 700; }
.summary-det { display: block; font-size: 0.58rem; color: var(--text-muted); }

/* === MAP PANEL (right) === */
.map-panel {
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: var(--radius);
    overflow: visible;
    display: flex;
    flex-direction: column;
    position: relative;
}

.map-toolbar {
    display: flex; align-items: center; gap: 0.5rem; flex-wrap: wrap;
    padding: 0.4rem 0.75rem; border-bottom: 1px solid var(--border-color); flex-shrink: 0;
    position: relative;
}
.map-toolbar .filter-input { flex: 1; max-width: 220px; }

/* === MAP SEARCH DROPDOWN === */
.map-search-results {
    display: none; position: absolute; top: 100%; left: 0.75rem; right: 0.75rem;
    max-height: 240px; overflow-y: auto; background: var(--bg-primary); border: 1px solid var(--border-color);
    border-radius: var(--radius-sm); box-shadow: var(--shadow-md); z-index: 100;
}
.map-search-results.active { display: block; }
.map-search-item {
    padding: 0.4rem 0.6rem; cursor: pointer; font-size: 0.72rem; display: flex;
    align-items: center; gap: 0.4rem; border-bottom: 1px solid var(--border-color);
}
.map-search-item:last-child { border-bottom: none; }
.map-search-item:hover, .map-search-item.highlighted { background: var(--bg-tertiary); }
.map-search-item .search-dot { width: 7px; height: 7px; border-radius: 50%; flex-shrink: 0; }
.map-search-item .search-name { flex: 1; color: var(--text-primary); }
.map-search-item .search-region { font-size: 0.62rem; color: var(--text-dim); }

/* (legend removed — constituency card replaces it) */

/* === MAP AREA (map + detail panel side by side) === */
.map-area {
    display: flex; flex: 1; min-height: 0; overflow: hidden; position: relative;
}

.constituency-map-container {
    flex: 1;
    min-height: 860px;
    background: var(--bg-secondary);
    position: relative;
}

.constituency-map-container svg { display: block; }

.constituency-map-container .constituency-path {
    stroke: rgba(0, 0, 0, 0.25); stroke-width: 0.4; cursor: pointer; transition: fill 0.12s;
}
.light-mode .constituency-map-container .constituency-path {
    stroke: rgba(0, 0, 0, 0.2);
}
.constituency-map-container .constituency-path:hover {
    stroke: rgba(255, 255, 255, 0.8); stroke-width: 1.5; filter: brightness(1.15);
}
.constituency-map-container .constituency-path.selected { stroke: #fff; stroke-width: 2; }

/* === CONSTITUENCY CARD (popout overlay) === */
.constituency-card {
    position: absolute; top: 8px; right: 200px;
    width: 280px; max-height: calc(100% - 50px); overflow-y: auto;
    background: var(--bg-card); border: 1px solid var(--border-color);
    border-radius: 12px; box-shadow: 0 8px 32px rgba(0,0,0,0.25);
    padding: 14px; z-index: 200; display: none;
    font-size: 0.78rem;
}
.constituency-card::-webkit-scrollbar { width: 4px; }
.constituency-card::-webkit-scrollbar-thumb { background: var(--bg-hover); border-radius: 2px; }

.cc-header {
    display: flex; justify-content: space-between; align-items: flex-start;
    margin-bottom: 10px; padding-bottom: 10px; border-bottom: 1px solid var(--border-color);
}
.cc-title { font-size: 1rem; font-weight: 700; color: var(--text-primary); line-height: 1.2; margin: 0; }
.cc-region { font-size: 0.68rem; color: var(--text-dim); margin-top: 2px; }
.cc-turnout { font-size: 0.68rem; color: var(--text-dim); margin-top: 1px; }
.cc-close {
    background: none; border: none; font-size: 1.2rem; color: var(--text-dim);
    cursor: pointer; padding: 2px 6px; border-radius: 4px; line-height: 1; flex-shrink: 0;
}
.cc-close:hover { background: var(--bg-tertiary); color: var(--text-primary); }

/* Winner pill */
.cc-winner-pill {
    display: inline-block; padding: 4px 12px; border-radius: 12px;
    color: #fff; font-weight: 600; font-size: 0.75rem; text-align: center;
    width: 100%; box-shadow: 0 2px 8px rgba(0,0,0,0.2);
    margin-bottom: 6px; text-shadow: 0 1px 2px rgba(0,0,0,0.3);
}
.cc-winner-pill.light-bg { color: #1f2937; text-shadow: none; }
.cc-win-prob { float: right; font-weight: 500; font-size: 0.68rem; opacity: 0.85; }
.cc-winner-pill.light-bg .cc-win-prob { opacity: 0.7; }

/* Hold/Gain badge */
.cc-result { font-size: 0.72rem; font-weight: 700; margin-bottom: 10px; }
.cc-result.gain { color: var(--success); }
.cc-result.hold { color: var(--text-dim); }

/* MP info section in constituency card */
.cc-mp-section { padding: 8px 0 6px; border-bottom: 1px solid var(--border); margin-bottom: 6px; }
.cc-mp-row { display: flex; gap: 10px; align-items: flex-start; }
.cc-mp-photo { width: 48px; height: 48px; border-radius: 4px; object-fit: cover; flex-shrink: 0; background: var(--surface-alt); }
.cc-mp-info { flex: 1; min-width: 0; }
.cc-mp-name { font-family: Georgia, "Times New Roman", serif; font-size: 0.88rem; font-weight: 700; color: var(--text); }
.cc-mp-link { color: var(--text-dim); text-decoration: none; font-size: 0.75rem; }
.cc-mp-link:hover { color: var(--text); }
.cc-mp-party { font-size: 0.75rem; color: var(--text-dim); }
.cc-mp-role { font-size: 0.72rem; color: var(--accent, #1a73e8); font-weight: 600; }
.cc-mp-majority { font-size: 0.72rem; color: var(--text-dim); margin-top: 2px; }
.cc-mp-tenure { font-size: 0.72rem; color: var(--text-dim); }
.cc-mp-vuln { font-size: 0.7rem; margin-top: 4px; padding: 2px 8px; border-radius: 3px; display: inline-block; }
.cc-mp-vuln.vuln-low { background: #e8f5e9; color: #2e7d32; }
.cc-mp-vuln.vuln-med { background: #fff3e0; color: #e65100; }
.cc-mp-vuln.vuln-high { background: #ffebee; color: #c62828; }
.cc-mp-vacant { font-size: 0.82rem; color: var(--text-dim); font-style: italic; }
.cc-mp-notes { font-size: 0.72rem; color: var(--text-dim); margin-top: 2px; }

/* Table MP columns */
.td-mp-name { font-size: 0.78rem; max-width: 140px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.td-loses-seat { text-align: center; width: 50px; }
.th-mp-name { min-width: 100px; }
.th-loses-seat { width: 50px; text-align: center; }

/* Dark mode MP overrides */
[data-theme="dark"] .cc-mp-vuln.vuln-low { background: #1b5e20; color: #a5d6a7; }
[data-theme="dark"] .cc-mp-vuln.vuln-med { background: #bf360c; color: #ffcc80; }
[data-theme="dark"] .cc-mp-vuln.vuln-high { background: #b71c1c; color: #ef9a9a; }

/* Tabs */
.cc-tabs {
    display: flex; gap: 0; margin-bottom: 10px; border-bottom: 2px solid var(--border-color);
}
.cc-tab {
    padding: 5px 10px; font-size: 0.68rem; font-weight: 600; color: var(--text-dim);
    cursor: pointer; border-bottom: 2px solid transparent; margin-bottom: -2px;
    background: none; border-top: none; border-left: none; border-right: none;
    font-family: inherit; transition: color 0.15s;
}
.cc-tab:hover { color: var(--text-secondary); }
.cc-tab.active { color: var(--accent-secondary); border-bottom-color: var(--accent-secondary); }
.cc-tab-content { display: none; }
.cc-tab-content.active { display: block; }

/* Vote item rows */
.cc-vote-item {
    display: flex; justify-content: space-between; align-items: center;
    padding: 4px 0; border-bottom: 1px solid var(--border-color);
}
.cc-vote-item:last-child { border-bottom: none; }
.cc-vote-party { font-size: 0.72rem; font-weight: 600; }
.cc-vote-pct { font-size: 0.78rem; font-weight: 700; color: var(--text-primary); }

/* Results column headers */
.cc-results-header {
    display: flex; justify-content: space-between; align-items: center;
    padding: 0 0 3px 0; margin-bottom: 2px; border-bottom: 1px solid var(--border-color);
}
.cc-results-col-labels { display: flex; align-items: center; gap: 6px; }
.cc-results-col-label { font-size: 0.62rem; font-weight: 600; color: var(--text-dim); text-transform: uppercase; letter-spacing: 0.03em; min-width: 38px; text-align: right; }

/* Change row (projected vs 2024) */
.cc-change-row {
    display: flex; justify-content: space-between; align-items: center;
    padding: 4px 0; border-bottom: 1px solid var(--border-color);
}
.cc-change-row:last-child { border-bottom: none; }
.cc-change-party { font-size: 0.72rem; font-weight: 600; }
.cc-change-vals { display: flex; align-items: center; gap: 6px; font-size: 0.75rem; }
.cc-change-ge { color: var(--text-dim); }
.cc-change-arrow { color: var(--text-dim); font-size: 0.6rem; }
.cc-change-proj { font-weight: 700; color: var(--text-primary); min-width: 38px; text-align: right; }
.cc-change-delta { font-weight: 700; font-size: 0.72rem; min-width: 38px; text-align: right; }
.cc-change-delta.up { color: var(--success); }
.cc-change-delta.down { color: var(--error); }
.cc-change-delta.flat { color: var(--text-dim); }

/* Section titles */
.cc-section-title {
    font-size: 0.62rem; font-weight: 600; color: var(--text-dim); text-transform: uppercase;
    letter-spacing: 0.04em; margin: 8px 0 6px; padding-bottom: 4px;
    border-bottom: 1px solid var(--border-color);
}

/* Demographics */
.cc-demo-row {
    display: flex; justify-content: space-between; align-items: center;
    padding: 3px 0;
}
.cc-demo-label { font-size: 0.68rem; color: var(--text-muted); }
.cc-demo-val-wrap { display: flex; align-items: center; gap: 6px; }
.cc-demo-bar {
    width: 50px; height: 5px; background: var(--bg-tertiary); border-radius: 2px; overflow: hidden;
}
.cc-demo-bar-fill { height: 100%; background: var(--accent-secondary); border-radius: 2px; }
.cc-demo-val { font-size: 0.72rem; font-weight: 600; color: var(--text-primary); min-width: 36px; text-align: right; }

/* === MAP TOOLTIP === */
.map-tooltip {
    position: fixed; display: none; background: var(--bg-primary); border: 1px solid var(--border-color);
    border-radius: var(--radius-sm); padding: 0.4rem 0.6rem; font-size: 0.72rem;
    pointer-events: none; z-index: 10000; box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3); max-width: 240px;
}
.map-tooltip .tip-name { font-weight: 600; color: var(--text-primary); margin-bottom: 0.15rem; }
.map-tooltip .tip-party { display: flex; align-items: center; gap: 0.3rem; }
.map-tooltip .tip-dot { width: 8px; height: 8px; border-radius: 50%; }
.map-tooltip .tip-winner { color: var(--text-secondary); }
.map-tooltip .tip-margin { color: var(--text-muted); font-size: 0.65rem; }
.map-tooltip .tip-change { font-size: 0.65rem; margin-top: 0.1rem; }
.map-tooltip .tip-change.gain { color: #f59e0b; }
.map-tooltip .tip-change.hold { color: var(--text-muted); }

/* === FILTERS === */
.filter-row { display: flex; gap: 0.4rem; flex-wrap: wrap; margin-bottom: 0.5rem; }
.filter-input, .filter-select {
    padding: 0.3rem 0.5rem; background: var(--bg-tertiary); border: 1px solid var(--border-color);
    border-radius: var(--radius-sm); color: var(--text-primary); font-size: 0.72rem; font-family: inherit;
}
.filter-input { flex: 1; min-width: 120px; }
.filter-select { min-width: 90px; }
.filter-input:focus, .filter-select:focus { outline: none; border-color: var(--accent-secondary); }

/* === TABLE === */
.table-section {
    background: var(--bg-card); border: 1px solid var(--border-color);
    border-radius: var(--radius); overflow: hidden;
}
.table-header {
    display: flex; align-items: center; gap: 0.5rem; padding: 0.5rem 1rem;
    cursor: pointer; user-select: none;
}
.table-header:hover { background: var(--bg-tertiary); }
.table-header h3 { margin: 0; font-size: 0.9rem; font-weight: 600; }
.table-toggle-icon { margin-left: auto; font-size: 0.65rem; color: var(--text-dim); transition: transform 0.2s; }
.table-collapsible { padding: 0 1rem 1rem; }
.table-collapsible.collapsed { display: none; }

.constituency-table { width: 100%; border-collapse: collapse; font-size: 0.72rem; }
.constituency-table th {
    padding: 0.4rem 0.5rem; text-align: left; font-weight: 600; color: var(--text-muted);
    text-transform: uppercase; font-size: 0.65rem; border-bottom: 2px solid var(--border-color);
    cursor: pointer; user-select: none;
}
.constituency-table th:hover { color: var(--text-primary); }
.constituency-table td { padding: 0.35rem 0.5rem; border-bottom: 1px solid var(--border-color); color: var(--text-secondary); }
.constituency-table tr:hover td { background: var(--bg-tertiary); }
.constituency-table .party-dot { display: inline-block; width: 7px; height: 7px; border-radius: 50%; margin-right: 5px; vertical-align: middle; }
.constituency-table .result-gain { color: var(--success); font-weight: 600; font-size: 0.65rem; }
.constituency-table .result-hold { color: var(--text-dim); font-size: 0.65rem; }
.constituency-table .margin-tight { color: var(--warning); font-weight: 600; }
.table-scroll { max-height: 500px; overflow-y: auto; }
.constituency-count { font-size: 0.72rem; color: var(--text-dim); }

/* === LOADING === */
.loading-state { text-align: center; padding: 3rem; color: var(--text-dim); }
.loading-spinner {
    display: inline-block; width: 28px; height: 28px;
    border: 3px solid var(--bg-tertiary); border-top-color: var(--accent-secondary);
    border-radius: 50%; animation: spin 0.8s linear infinite; margin-bottom: 0.75rem;
}
@keyframes spin { to { transform: rotate(360deg); } }
.error-state { text-align: center; padding: 2rem; color: var(--error); }

/* === MAJORITY BOX (used in seat bar) === */
.majority-box {
    display: flex; align-items: center; gap: 0.5rem;
    padding: 0.4rem 0.75rem; background: var(--bg-tertiary); border-radius: var(--radius-sm);
    border-left: 3px solid var(--success); margin-top: 0.4rem;
}
.majority-box.hung { border-left-color: var(--warning); }
.majority-box .status-text { font-weight: 600; font-size: 0.8rem; }
.majority-box .status-detail { font-size: 0.7rem; color: var(--text-muted); }

/* === TOGGLE (tactical) === */
.toggle-label { display: flex; align-items: center; gap: 8px; cursor: pointer; font-size: 0.8rem; color: var(--text-secondary); padding: 0.3rem 0; }
.toggle-switch { position: relative; width: 36px; height: 18px; background: var(--bg-hover); border-radius: 9px; transition: background 0.2s; flex-shrink: 0; }
.toggle-switch::after { content: ''; position: absolute; top: 2px; left: 2px; width: 14px; height: 14px; background: white; border-radius: 50%; transition: transform 0.2s; }
.toggle-input { display: none; }
.toggle-input:checked + .toggle-switch { background: var(--accent-secondary); }
.toggle-input:checked + .toggle-switch::after { transform: translateX(18px); }

/* === SIMILAR SEATS (constituency card) === */
.cc-similar-item {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 4px 0;
    cursor: pointer;
    border-bottom: 1px solid var(--border-color);
    transition: background 0.1s;
    border-radius: 3px;
    padding-left: 4px;
    padding-right: 4px;
}
.cc-similar-item:last-child { border-bottom: none; }
.cc-similar-item:hover { background: var(--bg-tertiary); }
.cc-similar-dot {
    width: 7px;
    height: 7px;
    border-radius: 50%;
    flex-shrink: 0;
}
.cc-similar-name {
    flex: 1;
    font-size: 0.68rem;
    color: var(--text-secondary);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.cc-similar-winner {
    font-size: 0.62rem;
    font-weight: 700;
    flex-shrink: 0;
}

/* === SWING DECOMPOSITION (constituency card tab) === */
.cc-swing-party {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 5px 0 2px;
    font-size: 0.72rem;
    font-weight: 700;
    border-bottom: 1px solid var(--border-color);
    margin-top: 4px;
}
.cc-swing-party:first-child { margin-top: 0; }
.cc-swing-total { font-size: 0.75rem; }
.cc-swing-total.up { color: var(--success); }
.cc-swing-total.down { color: var(--error); }
.cc-swing-total.flat { color: var(--text-dim); }

.cc-swing-row {
    display: flex;
    align-items: center;
    gap: 4px;
    padding: 2px 0;
    padding-left: 8px;
}
.cc-swing-label {
    font-size: 0.6rem;
    color: var(--text-dim);
    min-width: 72px;
    flex-shrink: 0;
}
.cc-swing-bar-wrap {
    flex: 1;
    height: 5px;
    background: var(--bg-tertiary);
    border-radius: 2px;
    overflow: hidden;
}
.cc-swing-bar {
    height: 100%;
    border-radius: 2px;
    transition: width 0.2s;
}
.cc-swing-bar.up { background: var(--success); }
.cc-swing-bar.down { background: var(--error); }
.cc-swing-val {
    font-size: 0.62rem;
    font-weight: 600;
    min-width: 28px;
    text-align: right;
}
.cc-swing-val.up { color: var(--success); }
.cc-swing-val.down { color: var(--error); }

/* === TURNOUT SIDE PANEL (right of map) === */
.turnout-side-panel {
    width: 190px;
    flex-shrink: 0;
    padding: 0.6rem 0.5rem;
    overflow-y: auto;
    border-left: 1px solid var(--border-color);
    background: var(--bg-card);
}
.turnout-side-panel::-webkit-scrollbar { width: 4px; }
.turnout-side-panel::-webkit-scrollbar-track { background: transparent; }
.turnout-side-panel::-webkit-scrollbar-thumb { background: var(--bg-hover); border-radius: 2px; }

/* === MAP LEGEND === */
.map-legend {
    position: absolute;
    bottom: 12px;
    left: 12px;
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    padding: 6px 10px;
    z-index: 50;
    display: none;
}
.map-legend-title {
    font-size: 0.62rem;
    font-weight: 600;
    color: var(--text-muted);
    margin-bottom: 4px;
    text-transform: uppercase;
    letter-spacing: 0.03em;
}
.map-legend-gradient {
    width: 120px;
    height: 8px;
    border-radius: 2px;
    margin-bottom: 3px;
    border: 1px solid var(--border-color);
}
.map-legend-labels {
    display: flex;
    justify-content: space-between;
    font-size: 0.58rem;
    color: var(--text-dim);
}

/* === MAP COLOUR TOGGLE === */
.map-change-label {
    display: flex;
    align-items: center;
    gap: 4px;
    font-size: 0.7rem;
    color: var(--text-muted);
    cursor: pointer;
    white-space: nowrap;
    user-select: none;
}
.map-change-label input[type="checkbox"] {
    margin: 0;
    cursor: pointer;
}

/* === MAP FULLSCREEN === */
.map-fullscreen-btn {
    background: var(--bg-tertiary);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    color: var(--text-muted);
    cursor: pointer;
    font-size: 0.85rem;
    padding: 0.2rem 0.45rem;
    line-height: 1;
    transition: all 0.15s;
    flex-shrink: 0;
}
.map-fullscreen-btn:hover {
    background: var(--bg-hover);
    color: var(--text-primary);
}

.map-panel.fullscreen {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 9000;
    border-radius: 0;
    border: none;
}
.map-panel.fullscreen .map-area {
    height: 0;
}
.map-panel.fullscreen .constituency-map-container {
    min-height: 0;
    height: 100%;
}
.map-panel.fullscreen .constituency-card {
    max-height: calc(100vh - 60px);
    right: 216px;
}
.map-panel.fullscreen .turnout-side-panel {
    width: 200px;
}

/* === TOOLTIP HEATMAP === */
.tip-heatmap {
    font-size: 0.72rem;
    font-weight: 700;
    color: var(--text-primary);
    margin-top: 0.15rem;
    padding-top: 0.15rem;
    border-top: 1px solid var(--border-color);
}

/* === FAQ / USER GUIDE === */
.faq-section {
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: var(--radius);
    overflow: hidden;
    margin-top: 0.75rem;
}
.faq-header {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.5rem 1rem;
    cursor: pointer;
    user-select: none;
}
.faq-header:hover { background: var(--bg-tertiary); }
.faq-header h3 { margin: 0; font-size: 0.9rem; font-weight: 600; }
.faq-toggle-icon {
    margin-left: auto;
    font-size: 0.65rem;
    color: var(--text-dim);
    transition: transform 0.2s;
}
.faq-collapsible { padding: 0 1rem 1rem; }
.faq-collapsible.collapsed { display: none; }

/* FAQ overview (model explainer at top) */
.faq-overview {
    padding: 0.5rem 0.4rem 0.75rem;
    border-bottom: 2px solid var(--border-color);
    margin-bottom: 0.25rem;
}
.faq-overview h4 {
    font-size: 0.82rem;
    font-weight: 700;
    color: var(--text-primary);
    margin: 0 0 0.4rem 0;
}
.faq-overview-section {
    margin-top: 0.5rem;
}
.faq-overview-section h5 {
    font-size: 0.72rem;
    font-weight: 700;
    color: var(--text-secondary);
    margin: 0 0 0.25rem 0;
    text-transform: uppercase;
    letter-spacing: 0.03em;
}
.faq-overview p {
    font-size: 0.72rem;
    color: var(--text-muted);
    line-height: 1.6;
    margin: 0 0 0.35rem 0;
}
.faq-overview p:last-child { margin-bottom: 0; }
.faq-overview strong { color: var(--text-secondary); }
.faq-overview ul, .faq-overview ol {
    margin: 0.2rem 0 0.4rem 0;
    padding-left: 1.2rem;
}
.faq-overview li {
    font-size: 0.72rem;
    color: var(--text-muted);
    line-height: 1.6;
    margin-bottom: 0.25rem;
}
.faq-overview li strong { color: var(--text-secondary); }

.faq-item {
    border-bottom: 1px solid var(--border-color);
}
.faq-item:last-child { border-bottom: none; }

.faq-q {
    padding: 0.6rem 0.4rem;
    font-size: 0.78rem;
    font-weight: 600;
    color: var(--text-primary);
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 0.4rem;
    user-select: none;
    transition: color 0.15s;
}
.faq-q::before {
    content: '\25B6';
    font-size: 0.5rem;
    color: var(--text-dim);
    transition: transform 0.2s;
    flex-shrink: 0;
}
.faq-q:hover { color: var(--accent-secondary); }
.faq-q.open::before { transform: rotate(90deg); }

.faq-a {
    max-height: 0;
    overflow: hidden;
    transition: max-height 0.3s ease, padding 0.3s ease;
    padding: 0 0.4rem 0 1.2rem;
}
.faq-a.open {
    max-height: 600px;
    padding: 0 0.4rem 0.6rem 1.2rem;
}
.faq-a p {
    font-size: 0.72rem;
    color: var(--text-muted);
    line-height: 1.6;
    margin: 0 0 0.4rem 0;
}
.faq-a p:last-child { margin-bottom: 0; }
.faq-a strong { color: var(--text-secondary); }
.faq-a ul {
    margin: 0.2rem 0 0.5rem 0;
    padding-left: 1.2rem;
}
.faq-a li {
    font-size: 0.72rem;
    color: var(--text-muted);
    line-height: 1.6;
    margin-bottom: 0.2rem;
}
.faq-a li strong { color: var(--text-secondary); }

/* === LIGHT MODE OVERRIDES === */

/* Nav: hardcoded white text needs a dark background in light mode */
.light-mode .navbar {
    background: linear-gradient(135deg, #1e3a8a 0%, #3b82f6 100%);
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.15);
}

/* Cards & panels need visible edges against the light page */
.light-mode .controls-panel,
.light-mode .map-panel,
.light-mode .table-section,
.light-mode .faq-section,
.light-mode .explainer-bar {
    box-shadow: 0 1px 4px rgba(0, 0, 0, 0.08);
}

/* Constituency card overlay needs stronger shadow */
.light-mode .constituency-card {
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.15);
}

/* Map tooltip needs stronger shadow */
.light-mode .map-tooltip {
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
    border-color: #a0aec0;
}

/* Map search dropdown needs more separation */
.light-mode .map-search-results {
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.15);
}

/* Seat cards: ensure visible against page bg (preserve party-colour top stripe) */
.light-mode .seat-card {
    border-left: 1px solid var(--border-color);
    border-right: 1px solid var(--border-color);
    border-bottom: 1px solid var(--border-color);
}

/* Slider rows: subtle separation */
.light-mode .party-slider-row {
    border: 1px solid var(--border-color);
    border-left: 3px solid var(--party-color, var(--text-muted));
}

/* Map area bg slightly different so map panel reads as card */
.light-mode .constituency-map-container {
    background: #f0f4f8;
}

/* Hover on map paths: dark stroke instead of white */
.light-mode .constituency-map-container .constituency-path:hover {
    stroke: rgba(0, 0, 0, 0.6);
}
.light-mode .constituency-map-container .constituency-path.selected {
    stroke: #1e293b;
}

/* Turnout side panel border */
.light-mode .turnout-side-panel {
    border-left: 1px solid var(--border-color);
}

/* Sticky seat bar: lighter shadow in light mode */
.light-mode .seat-bar.stuck {
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
}

/* === RESPONSIVE: TABLET & MOBILE === */
@media (max-width: 768px) {
    /* Global box-sizing fix — prevents width + padding + border overflow.
       Exclude SVG internals so D3 rendering is unaffected. */
    .calc-container *:not(svg):not(svg *),
    .calc-container *::before,
    .calc-container *::after {
        box-sizing: border-box;
    }
    /* Prevent horizontal overflow */
    .calc-body { overflow-x: hidden; }
    .calc-container { overflow-x: hidden; max-width: 100vw; }

    /* Header: wrap to two lines */
    .calc-header {
        flex-wrap: wrap;
        gap: 0.3rem;
    }
    .calc-header h1 {
        font-size: 1rem;
        flex: 1 1 100%;
    }
    .calc-header-right {
        flex: 1 1 100%;
        justify-content: flex-end;
    }

    /* Seat cards: 4x2 grid so all visible without scrolling */
    .seat-results-grid {
        display: grid;
        grid-template-columns: repeat(4, 1fr);
        gap: 0.25rem;
    }
    .seat-card {
        min-width: 0;
        padding: 0.3rem 0.2rem;
    }
    .seat-card .party-name { font-size: 0.52rem; }
    .seat-card .seat-count { font-size: 1.1rem; }
    .seat-card .seat-change { font-size: 0.52rem; }

    /* Seat bar: sticky so results stay visible while scrolling */
    .seat-bar {
        position: sticky;
        top: 0;
        z-index: 500;
        background: var(--bg-primary);
        padding: 0.4rem 0;
        box-shadow: 0 2px 8px rgba(0, 0, 0, 0);
        transition: box-shadow 0.2s;
    }
    .seat-bar.stuck {
        box-shadow: 0 2px 8px rgba(0, 0, 0, 0.3);
    }

    /* Poll selector: when moved above grid on mobile */
    #poll-selector-wrap.m-above-map {
        margin-bottom: 0.5rem;
    }

    /* Main grid: single column, MAP FIRST */
    .scenario-grid {
        grid-template-columns: 1fr;
        height: auto;
        overflow-x: hidden;
    }
    .map-panel { order: -1; }
    .controls-panel { order: 1; }

    /* Controls: remove nested scroll, let page scroll naturally */
    .controls-panel {
        max-height: none;
        overflow: visible;
    }
    .controls-scroll {
        height: auto;
        overflow: visible;
        padding: 0.5rem;
    }

    /* Mobile collapsible sections */
    .m-collapsed > *:not(.m-expand-btn):not(.ctrl-title) {
        display: none !important;
    }
    /* Hide .ctrl-title when replaced by the m-expand-btn */
    .m-collapsed > .ctrl-title {
        display: none !important;
    }

    /* Expand button: obvious full-width tappable card */
    .m-expand-btn {
        display: flex;
        align-items: center;
        justify-content: space-between;
        width: 100%;
        padding: 0.65rem 0.75rem;
        background: var(--bg-tertiary);
        border: 1px solid var(--border-color);
        border-radius: var(--radius-sm);
        color: var(--text-secondary);
        font-size: 0.78rem;
        font-weight: 600;
        font-family: inherit;
        cursor: pointer;
        -webkit-tap-highlight-color: transparent;
        transition: background 0.15s;
    }
    .m-expand-btn:hover, .m-expand-btn:active {
        background: var(--bg-hover);
    }
    .m-expand-btn .m-expand-icon {
        font-size: 0.65rem;
        color: var(--text-dim);
        transition: transform 0.2s;
    }
    /* When section is expanded: rotate chevron */
    :not(.m-collapsed) > .m-expand-btn .m-expand-icon {
        transform: rotate(90deg);
    }
    /* When section is expanded: style as less prominent header */
    :not(.m-collapsed) > .m-expand-btn {
        background: transparent;
        border-color: transparent;
        border-bottom: 1px solid var(--border-color);
        border-radius: 0;
        padding: 0.5rem 0.25rem;
        margin-bottom: 0.4rem;
    }

    /* Map panel (mobile): explicit sizing — no flex:1 collapse */
    .map-area {
        display: block;
        min-height: 500px;
        overflow: visible;
    }
    .constituency-map-container {
        width: 100%;
        min-height: 500px;
        overflow: hidden;
        touch-action: manipulation;
    }
    .turnout-side-panel {
        width: 100%;
        border-left: none;
        border-top: 1px solid var(--border-color);
    }

    /* Map toolbar: search full-width on top row, selects share second row */
    .map-toolbar {
        gap: 0.3rem;
        padding: 0.4rem 0.5rem;
        flex-wrap: wrap;
    }
    .map-toolbar .filter-input {
        max-width: none;
        flex: 1 1 100%;
        order: -1;
        min-height: 36px;
    }
    .map-toolbar .filter-select {
        flex: 1 1 0;
        min-width: 0;
    }

    /* Constituency card: bottom sheet with drag handle */
    .constituency-card {
        position: fixed;
        top: auto;
        bottom: 0;
        left: 0;
        right: 0;
        width: 100%;
        max-height: 60vh;
        border-radius: 16px 16px 0 0;
        box-shadow: 0 -4px 24px rgba(0, 0, 0, 0.3);
        padding: 6px 14px 14px;
    }
    .constituency-card::before {
        content: '';
        display: block;
        width: 36px;
        height: 4px;
        background: var(--bg-hover);
        border-radius: 2px;
        margin: 0 auto 8px;
    }

    /* Touch targets: improved but compact */
    .party-slider::-webkit-slider-thumb { width: 20px; height: 20px; }
    .party-slider::-moz-range-thumb { width: 20px; height: 20px; }
    .turnout-slider::-webkit-slider-thumb { width: 18px; height: 18px; }
    .turnout-slider::-moz-range-thumb { width: 18px; height: 18px; }
    .party-slider-wrap { gap: 0.25rem; }
    .info-btn {
        font-size: 0.9rem;
        padding: 2px;
    }
    .btn {
        padding: 0.4rem 0.7rem;
        font-size: 0.78rem;
        min-height: 38px;
    }
    .btn-sm {
        padding: 0.35rem 0.6rem;
        font-size: 0.75rem;
        min-height: 34px;
    }
    .filter-input, .filter-select {
        min-height: 34px;
        font-size: 0.75rem;
    }
    .poll-pill {
        padding: 6px 12px;
        font-size: 0.72rem;
        min-height: 34px;
    }

    /* Slider rows: two-line layout — name+value top, full-width slider bottom.
       JS moves .party-slider-input out of .party-slider-wrap on mobile. */
    .party-slider-row {
        flex-wrap: wrap;
        padding: 0.3rem 0.4rem;
        gap: 0.15rem;
        margin-bottom: 0.25rem;
    }
    .party-slider-label {
        flex: 0 0 auto;
        min-width: 0;
        font-size: 0.68rem;
    }
    .party-slider-input {
        flex: 1 1 auto;
        min-width: 0;
        font-size: 0.75rem;
        text-align: right;
    }
    .party-slider-wrap {
        flex: 0 0 100%;
        order: 3;
        gap: 0;
        margin-top: 2px;
    }
    .party-slider { width: 100%; }
    /* Hide lock buttons on mobile */
    .lock-btn { display: none; }
    /* Input mode on mobile: hide slider wrap, input stays on first line */
    .input-mode .party-slider-wrap { display: none; }
    .input-mode .party-slider-input { width: 52px; font-size: 0.8rem; }
    .turnout-slider-group {
        margin-bottom: 0.4rem;
    }

    /* Summary: compact inline row on mobile */
    .ctrl-summary {
        padding: 0.4rem;
    }
    .summary-row {
        grid-template-columns: 1fr 1fr;
    }
    .summary-val { font-size: 0.9rem; }
    .summary-lbl { font-size: 0.5rem; }
    .summary-det { font-size: 0.52rem; }

    /* Share section: inline row of buttons */
    .share-buttons {
        flex-direction: row;
        flex-wrap: wrap;
        gap: 0.3rem;
    }
    .share-btn-full {
        width: auto;
        flex: 1 1 0;
        min-width: 0;
        font-size: 0.68rem;
        padding: 0.3rem 0.4rem;
        min-height: 32px;
    }
    #share-section .ctrl-title {
        font-size: 0.65rem;
        margin-bottom: 0.25rem;
    }

    /* Font sizes: readable but compact */
    .info-box p { font-size: 0.7rem; }
    .explainer-col p { font-size: 0.72rem; }
    .explainer-col h4 { font-size: 0.78rem; }
    .ctrl-title { font-size: 0.72rem; }
    .turnout-slider-label { font-size: 0.68rem; }
    .turnout-slider-value { font-size: 0.72rem; }
    .cc-title { font-size: 0.9rem; }

    /* Mobile seat summary: compact chips near the sliders */
    .seat-bar-mobile {
        margin-bottom: 0.5rem;
        padding: 0.3rem;
        background: var(--bg-secondary);
        border: 1px solid var(--border-color);
        border-radius: var(--radius-sm);
    }
    .seat-chips {
        display: flex;
        flex-wrap: wrap;
        gap: 4px;
        justify-content: center;
    }
    .seat-chip {
        display: flex;
        align-items: center;
        gap: 3px;
        padding: 3px 6px;
        background: var(--bg-tertiary);
        border-radius: 4px;
        border-left: 3px solid var(--party-color, var(--text-muted));
    }
    .seat-chip.labour { --party-color: var(--party-labour); }
    .seat-chip.conservative { --party-color: var(--party-conservative); }
    .seat-chip.libdem { --party-color: var(--party-libdem); }
    .seat-chip.reform { --party-color: var(--party-reform); }
    .seat-chip.green { --party-color: var(--party-green); }
    .seat-chip.snp { --party-color: var(--party-snp); }
    .seat-chip.pc { --party-color: var(--party-pc); }
    .seat-chip.others { --party-color: var(--party-others); }
    .seat-chip-name {
        font-size: 0.55rem;
        font-weight: 600;
        color: var(--text-muted);
        text-transform: uppercase;
    }
    .seat-chip-count {
        font-size: 0.75rem;
        font-weight: 700;
        color: var(--party-color, var(--text-primary));
    }
    .seat-chip-change {
        font-size: 0.5rem;
        font-weight: 600;
    }
    .seat-chip-change.positive { color: var(--success); }
    .seat-chip-change.negative { color: var(--error); }
    .seat-chip-change.neutral { color: var(--text-dim); }

    /* Table: horizontal scroll instead of crushing columns */
    .table-scroll {
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
    }
    .constituency-table {
        min-width: 520px;
    }

    /* FAQ: larger tap targets */
    .faq-q {
        padding: 0.75rem 0.4rem;
        font-size: 0.82rem;
        min-height: 44px;
    }
    .faq-header {
        min-height: 44px;
    }
    .table-header {
        min-height: 44px;
    }

    /* Fullscreen: safe areas for notched phones */
    .map-panel.fullscreen {
        padding-top: env(safe-area-inset-top);
        padding-bottom: env(safe-area-inset-bottom);
    }
    .map-panel.fullscreen .constituency-card {
        right: 0;
        max-height: calc(60vh - env(safe-area-inset-bottom));
    }
}

/* === RESPONSIVE: SMALL PHONES === */
@media (max-width: 480px) {
    .calc-container {
        padding: 0.4rem;
    }
    .calc-header h1 {
        font-size: 0.9rem;
    }
    .mrp-badge {
        font-size: 0.5rem;
        padding: 1px 5px;
    }
    .calc-header-right {
        gap: 0.4rem;
    }
    /* Hide date stamp to save space */
    .source-detail {
        display: none;
    }

    .seat-card .seat-count { font-size: 1rem; }
    .seat-card .party-name { font-size: 0.48rem; }
    .seat-card .seat-change { font-size: 0.48rem; }

    .constituency-map-container {
        min-height: 400px;
    }
    .map-area {
        min-height: 400px;
    }

    .majority-box {
        flex-wrap: wrap;
        gap: 0.2rem;
    }
    .majority-box .status-text { font-size: 0.72rem; }
    .majority-box .status-detail { font-size: 0.65rem; }

    .summary-val { font-size: 0.9rem; }

    /* FAQ: slightly smaller text on small phones */
    .faq-q { font-size: 0.75rem; }
    .faq-a p { font-size: 0.68rem; }
    .faq-overview p { font-size: 0.68rem; }
    .faq-overview li { font-size: 0.68rem; }

    /* Explainer: tighter */
    .explainer-toggle {
        padding: 0.4rem 0.5rem;
    }
}

/* Share section */
.share-buttons {
    display: flex;
    flex-direction: column;
    gap: 0.4rem;
}
.share-btn-full {
    width: 100%;
    text-align: center;
}
.share-feedback {
    display: none;
    color: #059669;
    font-size: 0.8rem;
    margin-top: 0.4rem;
    text-align: center;
}
