/* build-your-own.css - /build-your-own/ (prefix byo-). Builds on us.css (us-l- rating
   fills, map, seat bar) and pc-components.css; tokens only, no raw hexes.
   Note the UK html { zoom: 0.8 }: 50 CSS px is a 40px tap target on screen.
   Wide screens: sticky totals under the header, map left, panel right (key with
   counts, selected unit, undo / reset, share). Up to 900px: one column, the totals
   stay at the top and a bar fixed at the bottom (thumb reach) holds undo / paint /
   reset, the paint key when open and the selected unit's sheet. */

.byo-masthead { margin-bottom: 12px; }
.byo-masthead .pc-help { max-width: 680px; }
.byo-tabs { margin-bottom: 0; }
.byo-tabs .pc-tab { min-height: 50px; }
.byo-defs { position: absolute; width: 0; height: 0; overflow: hidden; }

/* ---- Totals dock (sticky) ---- */
.byo-dock {
    position: sticky; top: var(--us-nav-h, 60px); z-index: 30;
    background: var(--pc-surface); padding: 14px 0 10px; margin: 0 0 18px;
    border-bottom: 1px solid var(--pc-border); font-family: var(--pc-sans);
}
.byo-totals { display: flex; align-items: flex-end; gap: 16px; margin: 0 0 4px; }
.byo-total { display: flex; flex-direction: column; gap: 2px; flex: 0 0 auto; }
.byo-total-r { align-items: flex-end; text-align: right; }
.byo-total-lab { font-size: 12px; font-weight: 600; line-height: 1.2; }
.byo-total-d .byo-total-lab { color: var(--us-dem-text); }
.byo-total-r .byo-total-lab { color: var(--us-rep-text); }
.byo-total-num { font-size: 34px; font-weight: 700; line-height: 1; color: var(--pc-text); font-variant-numeric: tabular-nums; }
.byo-verdict {
    flex: 1 1 auto; margin: 0; text-align: center; align-self: center;
    font-family: var(--pc-serif); font-size: 19px; font-weight: 700; line-height: 1.25; color: var(--pc-text);
    font-variant-numeric: tabular-nums;
}
.byo-bar-wrap { position: relative; padding-top: 20px; }
.byo-bar.pc-seatbar { height: 44px; border-radius: 0; }
.byo-bar .pc-seat-seg { font-size: 14px; transition: none; }
.byo-bar .pc-seat-seg.us-l-none { background: var(--pc-border-light); }
.byo-majority {
    position: absolute; top: 14px; bottom: -5px; width: 2px; margin-left: -1px;
    background: var(--pc-text); z-index: 2; pointer-events: none;
}
.byo-majority span {
    position: absolute; top: -16px; left: 50%; transform: translateX(-50%);
    font-size: 12px; font-weight: 700; white-space: nowrap; color: var(--pc-text);
    background: var(--pc-surface); padding: 0 8px; line-height: 1.3;
}
.byo-rule { margin: 8px 0 0; font-size: 12px; color: var(--pc-text-secondary); font-variant-numeric: tabular-nums; }
.byo-msg {
    display: flex; align-items: center; gap: 12px; margin: 8px 0 0; padding: 6px 10px;
    background: var(--pc-text); color: var(--pc-surface); font-size: 13px;
}
.byo-msg[hidden] { display: none; }
.byo-msg button {
    margin-left: auto; min-height: 36px; padding: 0 12px; border: 1px solid currentColor; background: transparent;
    color: inherit; font: inherit; font-weight: 600; cursor: pointer;
}

/* ---- Layout ---- */
.byo-grid { display: grid; grid-template-columns: minmax(0, 1fr) 300px; column-gap: 40px; align-items: start; }
.byo-main { min-width: 0; }
.byo-side { position: sticky; top: calc(var(--us-nav-h, 60px) + 150px); font-family: var(--pc-sans); }
.byo-panel[hidden] { display: none; }

.byo-tools { display: flex; flex-wrap: wrap; gap: 8px 12px; align-items: center; margin: 0 0 8px; }
.byo-presets { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.byo-tools-lab { font-family: var(--pc-sans); font-size: 12px; font-weight: 600; color: var(--pc-text-secondary); }
.byo-view { margin-left: auto; }
.byo-tools .pc-btn, .byo-tools .pc-mode-btn { min-height: 40px; }
.byo-note { font-family: var(--pc-sans); font-size: 13px; line-height: 1.5; color: var(--pc-text-secondary); margin: 0 0 10px; max-width: 760px; }
.byo-note a { color: var(--pc-text-secondary); text-decoration: underline; text-underline-offset: 2px; }
.byo-readout { min-height: 18px; margin: 4px 0 0; font-family: var(--pc-sans); font-size: 13px; color: var(--pc-text-secondary); }
@media (pointer: coarse) { .byo-readout { display: none; } }

/* ---- Maps ---- */
.byo-stage { position: relative; }
.byo-map-wrap { margin: 0; }
.byo-map-wrap[hidden], .byo-svg[hidden], .byo-list[hidden], .byo-chips[hidden], .byo-hint[hidden] { display: none; }
.byo-svg { width: 100%; height: auto; display: block; user-select: none; -webkit-user-select: none; -webkit-touch-callout: none; touch-action: pan-y; }
body.byo-painting .byo-svg, .byo-house { touch-action: none; }
.byo-svg .is-link, .byo-svg [data-u] { cursor: pointer; }
.byo-svg .byo-shape { fill: var(--us-fill); }
.byo-svg path.byo-inert, .byo-svg rect.byo-inert { fill: var(--pc-surface); stroke: var(--pc-border); stroke-width: 0.8; cursor: default; }
.byo-svg .byo-inert-label { fill: var(--pc-text-meta); font-weight: 400; }
.us-map.byo-states path.us-state.us-l-tossup, .byo-states rect.us-state.us-l-tossup { fill: url(#byo-hatch); }
.byo-states path.us-state:focus { outline: none; }
.byo-states path.us-state:focus-visible, .byo-states path.us-state.is-sel { stroke: var(--pc-text); stroke-width: 2.4; }
.byo-states .us-map-label .byo-ev { font-weight: 400; font-size: 10px; }
.byo-states .byo-co-line { stroke: var(--pc-text-meta); stroke-width: 0.6; pointer-events: none; }
.byo-states rect.byo-co { fill: var(--us-fill); stroke: var(--pc-surface); stroke-width: 0.8; }
.byo-states rect.byo-co.us-l-none { stroke: var(--pc-border); }
.byo-states rect.byo-co.is-sel { stroke: var(--pc-text); stroke-width: 2; }
.byo-states .byo-co-label {
    font-family: var(--pc-sans); font-size: 9.5px; font-weight: 700; fill: var(--pc-text);
    text-anchor: middle; dominant-baseline: central; pointer-events: none;
}
.byo-states .byo-co-label.on-dark { fill: var(--pc-on-party-dark); }
.byo-states .byo-co-label .byo-ev { font-weight: 400; }

/* Tile view: one square per state (and DC) */
.byo-tiles { max-width: 720px; margin: 0 auto; }
.byo-tiles rect.byo-tile { fill: var(--us-fill); stroke: none; }
.byo-tiles rect.byo-tile.us-l-none { stroke: var(--pc-border); stroke-width: 0.15; }
.byo-tiles rect.byo-tile.us-l-tossup { fill: url(#byo-hatch-t); }
.byo-tiles rect.byo-tile.byo-inert { fill: var(--pc-surface); stroke: var(--pc-border); stroke-width: 0.15; }
.byo-tiles rect.byo-tile:focus { outline: none; }
.byo-tiles rect.byo-tile:focus-visible, .byo-tiles rect.byo-tile.is-sel { stroke: var(--pc-text); stroke-width: 0.5; }
.byo-tiles .byo-tile-label {
    font-family: var(--pc-sans); font-size: 2.9px; font-weight: 700; fill: var(--pc-text);
    text-anchor: middle; dominant-baseline: central; pointer-events: none;
}
.byo-tiles .byo-tile-label.on-dark { fill: var(--pc-on-party-dark); }
.byo-tiles .byo-tile-label .byo-ev { font-weight: 400; font-size: 2.5px; }
@media (hover: hover) {
    .byo-states path.is-link:hover, .byo-states rect.byo-co:hover { stroke: var(--pc-text); stroke-width: 1.4; }
    .byo-tiles rect.is-link:hover { stroke: var(--pc-text); stroke-width: 0.4; }
    .byo-house .byo-d:hover { stroke: var(--pc-text); stroke-width: 1.5; }
}

/* House: districts or hexes, drawn by the script; zoom by pinch, ctrl + wheel or the buttons */
.byo-house-wrap { position: relative; border: 1px solid var(--pc-border-light); overflow: hidden; }
.byo-house { min-height: 200px; }
.byo-house .byo-d { stroke: var(--pc-surface); stroke-width: 0.5; vector-effect: non-scaling-stroke; }
.byo-house .byo-d.us-l-tossup { fill: url(#byo-hatch-h); }
.byo-house .byo-d.is-sel { stroke: var(--pc-text); stroke-width: 2.5; }
.byo-house .byo-st { fill: none; stroke: var(--pc-text-meta); stroke-width: 0.8; vector-effect: non-scaling-stroke; pointer-events: none; }
.byo-house .byo-hex-st { stroke: var(--pc-text); stroke-width: 1.2; }
.byo-house .byo-hex-label {
    font-family: var(--pc-sans); font-size: 7px; font-weight: 700; fill: var(--pc-text); text-anchor: middle;
    dominant-baseline: central; pointer-events: none; paint-order: stroke; stroke: var(--pc-surface); stroke-width: 2px;
}
.byo-loading { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; margin: 0;
    font-family: var(--pc-sans); font-size: 14px; color: var(--pc-text-secondary); background: var(--pc-surface); }
.byo-loading[hidden] { display: none; }
.byo-zoom { position: absolute; top: 8px; right: 8px; display: flex; gap: 4px; }
.byo-zoom .pc-btn { min-width: 44px; min-height: 44px; padding: 0 10px; font-size: 18px; background: var(--pc-surface); }
.byo-zoom .pc-btn[data-zoom="fit"] { font-size: 13px; }
.byo-hint { margin: 6px 0 0; font-family: var(--pc-sans); font-size: 12px; color: var(--pc-text-secondary); }

/* Maine / Nebraska district chips */
.byo-chips { display: flex; flex-wrap: wrap; gap: 4px; margin: 12px 0 0; }
.byo-pill {
    display: flex; align-items: baseline; gap: 8px; min-height: 44px; padding: 0 12px; align-items: center;
    border: 1px solid var(--pc-border); background: var(--us-fill); color: var(--pc-text); cursor: pointer;
    font-family: var(--pc-sans); font-size: 13px; font-weight: 600;
}
.byo-pill b { font-weight: 400; font-variant-numeric: tabular-nums; }
.byo-pill.us-l-safe-d, .byo-pill.us-l-safe-r { color: var(--pc-on-party-dark); border-color: transparent; }
.byo-pill.us-l-tossup { background: repeating-linear-gradient(135deg, color-mix(in srgb, var(--pc-text-meta) 45%, transparent) 0 2px, transparent 2px 6px), var(--pc-border); }
.byo-pill.is-sel { outline: 2px solid var(--pc-text); outline-offset: 1px; }

/* ---- Lists (every tab) ---- */
.byo-search { display: flex; align-items: center; gap: 10px; margin: 4px 0 6px; }
.byo-search .pc-section-label { margin: 0; }
.byo-search .pc-input { flex: 1 1 auto; min-height: 44px; font-size: 16px; }
.byo-list-count { min-height: 16px; margin: 0 0 4px; font-family: var(--pc-sans); font-size: 12px; color: var(--pc-text-secondary); }
.byo-rows { border-top: 1px solid var(--pc-text); }
.byo-row {
    display: grid; grid-template-columns: minmax(64px, auto) minmax(0, 1fr) auto; gap: 4px 12px; align-items: center;
    width: 100%; min-height: 48px; padding: 6px 4px; border: 0; border-bottom: 1px solid var(--pc-border-light);
    background: transparent; color: var(--pc-text-body); text-align: left; cursor: pointer; font-family: var(--pc-sans); font-size: 14px;
}
.byo-row[hidden] { display: none; }
.byo-row:hover { background: var(--pc-hover-bg); }
.byo-row-name { font-weight: 600; color: var(--pc-text); }
.byo-row-sub { color: var(--pc-text-secondary); font-size: 13px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.byo-chip {
    min-width: 76px; padding: 4px 8px; text-align: center; font-size: 12px; font-weight: 600;
    background: var(--us-fill); color: var(--pc-text); white-space: nowrap;
}
.byo-chip.us-l-safe-d, .byo-chip.us-l-safe-r { color: var(--pc-on-party-dark); }
.byo-chip.us-l-none { box-shadow: inset 0 0 0 1px var(--pc-border); background: transparent; color: var(--pc-text-secondary); }
.byo-group { border-bottom: 1px solid var(--pc-border-light); }
.byo-group[hidden] { display: none; }
.byo-group > summary {
    display: flex; align-items: center; gap: 12px; min-height: 48px; padding: 0 4px; cursor: pointer;
    font-family: var(--pc-sans); font-size: 15px; font-weight: 600; color: var(--pc-text); list-style: none;
}
.byo-group > summary::-webkit-details-marker { display: none; }
.byo-group > summary::before { content: '+'; width: 14px; color: var(--pc-text-secondary); font-weight: 400; }
.byo-group[open] > summary::before { content: '\2212'; }
.byo-group > summary small { margin-left: auto; font-size: 12px; font-weight: 400; color: var(--pc-text-secondary); }
.byo-group > div { padding-left: 18px; }
.byo-row:focus-visible, .byo-group > summary:focus-visible, .byo-pill:focus-visible { outline: 2px solid var(--pc-text); outline-offset: -2px; }

/* ---- Rating buttons: the sheet's quick set and the paint key (D row, R row) ---- */
.byo-rates { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 4px; }
.byo-rates button {
    display: flex; align-items: center; gap: 6px; min-height: 44px; padding: 4px 6px; min-width: 0;
    border: 1px solid var(--pc-border); background: var(--pc-surface); color: var(--pc-text-body);
    font-family: var(--pc-sans); font-size: 13px; text-align: left; cursor: pointer;
}
.byo-rates button span { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.byo-rates button i { box-sizing: border-box; width: 14px; height: 14px; flex: 0 0 14px; background: var(--us-fill); border: 1px solid var(--pc-border); }
.byo-rates button i.us-l-tossup { background: repeating-linear-gradient(135deg, var(--pc-text-meta) 0 2px, var(--pc-border) 2px 4px); }
body.dark-mode .byo-rates button i { border-color: color-mix(in srgb, var(--us-fill) 45%, var(--pc-text)); }
.byo-rates button b { margin-left: auto; font-weight: 700; color: var(--pc-text); font-variant-numeric: tabular-nums; }
.byo-rates button.is-active { background: var(--pc-text); color: var(--pc-surface); border-color: var(--pc-text); }
.byo-rates button.is-active b { color: var(--pc-surface); }
.byo-rates button:focus-visible { outline: 2px solid var(--pc-text); outline-offset: 2px; }
@media (hover: hover) { .byo-rates button:not(.is-active):hover { background: var(--pc-hover-bg); } }

/* Side panel on wide screens */
.byo-bottom { display: flex; flex-direction: column; gap: 14px; }
.byo-keybox { order: 1; }
.byo-sheet { order: 2; }
.byo-actions { order: 3; display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 6px; }
.byo-actions .pc-btn { min-height: 44px; }
.byo-key-lab { display: flex; justify-content: space-between; margin: 0 0 6px; }
.byo-key-unit { text-transform: none; letter-spacing: 0; font-weight: 400; }
.byo-key { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.byo-actions .byo-paint-btn { display: none; }
body.byo-painting .byo-actions .byo-paint-btn { display: block; }
body.byo-painting .byo-actions { grid-template-columns: repeat(2, minmax(0, 1fr)); }
body.byo-painting .byo-actions .byo-paint-btn { grid-column: 1 / -1; order: -1; background: var(--pc-text); color: var(--pc-surface); border-color: var(--pc-text); }
.byo-sheet[hidden] { display: none; }
.byo-sheet { border-top: 1px solid var(--pc-text); padding-top: 10px; }
.byo-sheet-head { display: flex; align-items: flex-start; gap: 8px; margin: 0 0 8px; }
.byo-sheet-head > div { flex: 1 1 auto; min-width: 0; }
.byo-sheet-name { margin: 0 0 2px; font-family: var(--pc-serif); font-size: 17px; font-weight: 700; color: var(--pc-text); line-height: 1.25; }
.byo-sheet-sub { margin: 0; font-size: 13px; line-height: 1.45; color: var(--pc-text-secondary); }
.byo-sheet-close {
    flex: 0 0 auto; width: 44px; height: 44px; border: 1px solid var(--pc-border); background: var(--pc-surface);
    color: var(--pc-text); font-size: 22px; line-height: 1; cursor: pointer;
}
.byo-sheet .byo-rates { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.byo-sheet-link { margin: 8px 0 0; font-size: 13px; }
.byo-sheet-link a { color: var(--pc-text-body); text-decoration: underline; text-underline-offset: 2px; }

.byo-share { padding-top: 20px; }
.byo-share-row { display: flex; gap: 6px; flex-wrap: wrap; margin: 0 0 8px; }
.byo-share-row .pc-btn { flex: 1 1 auto; min-height: 44px; }
.byo-share-row .pc-btn-primary { text-transform: none; letter-spacing: 0; font-size: 13px; font-weight: 600; }
.byo-link { width: 100%; font-size: 12px; box-sizing: border-box; }

body[data-section="build-your-own"] .ps-footer a { color: var(--pc-text-secondary); text-decoration: underline; text-underline-offset: 2px; }

/* ---- Phones and tablets ---- */
@media (max-width: 900px) {
    .byo-grid { grid-template-columns: minmax(0, 1fr); }
    .byo-side { position: static; }
    .byo-bottom {
        position: fixed; left: 0; right: 0; bottom: var(--pc-ad-inset, 0px); z-index: 40; gap: 8px;
        background: var(--pc-surface); border-top: 1px solid var(--pc-text);
        padding: 8px 16px calc(8px + env(safe-area-inset-bottom, 0px));
        max-height: 70vh; overflow-y: auto;
    }
    .byo-keybox { display: none; order: 1; }
    body.byo-key-open .byo-keybox { display: block; }
    body.byo-key-open .byo-sheet { display: none; }
    .byo-sheet { border-top: 0; padding-top: 0; }
    .byo-key, .byo-sheet .byo-rates { grid-template-columns: repeat(4, minmax(0, 1fr)); }
    .byo-rates button { min-height: 50px; flex-wrap: wrap; align-content: center; gap: 2px 6px; }
    .byo-key button b { margin-left: 20px; flex-basis: 100%; font-size: 12px; }
    .byo-actions .byo-paint-btn, body.byo-painting .byo-actions .byo-paint-btn { display: block; }
    .byo-actions, body.byo-painting .byo-actions { grid-template-columns: repeat(3, minmax(0, 1fr)); }
    body.byo-painting .byo-actions .byo-paint-btn { grid-column: auto; order: 0; }
    body.byo-key-open .byo-actions .byo-paint-btn { background: var(--pc-text); color: var(--pc-surface); border-color: var(--pc-text); }
    .byo-actions .pc-btn { min-height: 50px; }
    body[data-section="build-your-own"] main.us-main { padding-bottom: 120px; }
    .byo-side .byo-share { padding-top: 28px; }
    .byo-share-row .pc-btn { min-height: 50px; }
}
@media (max-width: 768px) {
    .byo-dock { padding: 8px 0 8px; margin-bottom: 12px; }
    .byo-totals { gap: 8px; }
    .byo-verdict { font-size: 15px; }
    .byo-total-num { font-size: 28px; }
    .byo-total-lab { font-size: 11px; }
    .byo-bar.pc-seatbar { height: 32px; }
    .byo-bar .pc-seat-seg { font-size: 12px; }
    .byo-rule { margin-top: 6px; }
    .byo-tabs .pc-tab { flex: 1 1 0; padding: 12px 6px 10px; text-align: center; }
    .byo-tools { display: grid; grid-template-columns: minmax(0, 1fr); gap: 8px; }
    .byo-presets { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 6px; }
    .byo-tools-lab { grid-column: 1 / -1; }
    .byo-presets .pc-btn { min-height: 50px; padding: 4px 6px; white-space: normal; line-height: 1.2; }
    .byo-view, .byo-lines { margin: 0; display: flex; width: 100%; }
    .byo-view .pc-mode-btn, .byo-lines .pc-mode-btn { flex: 1 1 0; min-height: 50px; }
    .byo-zoom .pc-btn { min-width: 50px; min-height: 50px; }
    .byo-pill { min-height: 50px; }
    .byo-row { min-height: 54px; }
    .byo-group > summary { min-height: 54px; }
}
