/*
  The election map and the two control gauges (election/js/map.js, gauge.js). Colours are the party
  tokens in election/css/tokens.css; type, radii, motion and focus follow assets/css/site.css.
*/

/* MARK: - The map */

/* The map and, beside it, the small north-eastern states as a column of chips. The column starts
   level with New England: 27% of the way down the map, as in the reference. The map's height is its
   width × 594 / 942, the art's viewBox */
.emap {
  --chips-width: 84px;
  --chips-gap: var(--space-l);
  container-type: inline-size;
}
.emap-layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) var(--chips-width);
  gap: var(--chips-gap);
  align-items: start;
}
.emap-stage { min-width: 0; }

.emap-svg {
  display: block;
  width: 100%;
  height: auto;
  overflow: visible;
  -webkit-tap-highlight-color: transparent;
}
.emap-error { color: var(--text-muted); font-size: var(--text-small); }

/* States */
.emap-state { --fill: var(--no-race); outline: none; }
.emap-state[data-tone="d-strong"] { --fill: var(--dem-strong); }
.emap-state[data-tone="d-mid"] { --fill: var(--dem-mid); }
.emap-state[data-tone="d-light"] { --fill: var(--dem-light); }
.emap-state[data-tone="r-strong"] { --fill: var(--rep-strong); }
.emap-state[data-tone="r-mid"] { --fill: var(--rep-mid); }
.emap-state[data-tone="r-light"] { --fill: var(--rep-light); }
.emap-state[data-tone="tossup"] { --fill: var(--tossup); }

.emap-fill {
  fill: var(--fill);
  stroke: var(--map-border);
  stroke-width: 1px;
  stroke-linejoin: round;
  vector-effect: non-scaling-stroke;
  transition: fill var(--dur-quick) var(--ease-out);
}
.emap-hatch { pointer-events: none; }
.emap-hatch-line { fill: var(--hatch); }

/* What you can press: the fill leans toward the text colour under the pointer, further when pressed */
.emap-state[role="button"] { cursor: pointer; }
@media (hover: hover) and (pointer: fine) {
  .emap-state[role="button"]:hover .emap-fill { fill: color-mix(in srgb, var(--fill) 84%, var(--text)); }
}
.emap-state[role="button"]:active .emap-fill,
.emap-state.is-pressed .emap-fill {
  fill: color-mix(in srgb, var(--fill) 72%, var(--text));
  transition-duration: var(--dur-press);
}

/* Labels: the abbreviation in bold caps over the favourite's chance */
.emap-labels { pointer-events: none; }
.emap-label {
  --ink: var(--no-race-text);
  fill: var(--ink);
  font-variant-numeric: tabular-nums;
}
.emap-label-code { font-weight: 700; letter-spacing: 0.06em; }
.emap-label-pct { font-weight: 400; }
:is(.emap-label, .emap-held, .emap-chip):is([data-tone="d-strong"], [data-tone="r-strong"]) { --ink: var(--on-party); }
:is(.emap-label, .emap-held, .emap-chip):is([data-tone="d-mid"], [data-tone="d-light"]) { --ink: var(--on-dem-soft); }
:is(.emap-label, .emap-held, .emap-chip):is([data-tone="r-mid"], [data-tone="r-light"]) { --ink: var(--on-rep-soft); }
:is(.emap-label, .emap-held, .emap-chip)[data-tone="tossup"] { --ink: var(--on-tossup); }
.emap-held { fill: var(--ink); }
:is(.emap-label, .emap-held).is-offshore.is-offshore { --ink: var(--text); }
.emap-label.is-offshore.is-offshore[data-tone="none"] { --ink: var(--text-muted); }

/* The chosen state: an outline in the text colour. Focus: the theme's action colour, with a band
   of the page colour under it so it shows on any fill */
.emap-marks { pointer-events: none; }
.emap-selected, .emap-focus path {
  fill: none;
  stroke-linejoin: round;
  vector-effect: non-scaling-stroke;
}
.emap-selected { stroke: var(--text); stroke-width: 2px; }
.emap-focus { display: none; }
.emap-focus.is-on { display: inline; }
.emap-focus-halo { stroke: var(--surface); stroke-width: 6px; }
.emap-focus-line { stroke: var(--action); stroke-width: 2.5px; }

/* The chips: one column, joined, with only its outer corners rounded */
.emap-chips {
  display: flex;
  flex-direction: column;
  gap: 2px;
  margin: calc((100cqi - var(--chips-width) - var(--chips-gap)) * 594 / 942 * 0.27) 0 0;
  padding: 0;
  list-style: none;
}
.emap-chips li { display: flex; }
.emap-chip {
  --ink: var(--no-race-text);
  --chip: var(--no-race);
  position: relative;
  display: flex;
  flex: 1;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-s);
  min-height: 30px;
  margin: 0;
  padding: 0 var(--space-s);
  border: 0;
  border-radius: 2px;
  background-color: var(--chip);
  color: var(--ink);
  font: inherit;
  font-size: 13px;
  line-height: 1;
  text-align: left;
  font-variant-numeric: tabular-nums;
  -webkit-tap-highlight-color: transparent;
}
.emap-chips li:first-child .emap-chip { border-top-left-radius: var(--radius-small); border-top-right-radius: var(--radius-small); }
.emap-chips li:last-child .emap-chip { border-bottom-left-radius: var(--radius-small); border-bottom-right-radius: var(--radius-small); }
.emap-chip[data-tone="d-strong"] { --chip: var(--dem-strong); }
.emap-chip[data-tone="d-mid"] { --chip: var(--dem-mid); }
.emap-chip[data-tone="d-light"] { --chip: var(--dem-light); }
.emap-chip[data-tone="r-strong"] { --chip: var(--rep-strong); }
.emap-chip[data-tone="r-mid"] { --chip: var(--rep-mid); }
.emap-chip[data-tone="r-light"] { --chip: var(--rep-light); }
.emap-chip[data-tone="tossup"] { --chip: var(--tossup); }
/* The same stripes as the map, running bottom left to top right */
.emap-chip[data-flip] {
  background-image: repeating-linear-gradient(-45deg, var(--hatch) 0 1.3px, transparent 1.3px 5px);
}
.emap-chip-code { font-weight: 700; letter-spacing: 0.06em; white-space: nowrap; }
.emap-chip-pct { font-weight: 400; }
.emap-chip[data-held] .emap-chip-code::after {
  content: "";
  display: inline-block;
  width: 5px;
  height: 5px;
  margin-left: 3px;
  border-radius: 50%;
  background: currentColor;
  vertical-align: 0.5em;
}
button.emap-chip {
  cursor: pointer;
  transition: transform var(--dur-settle) var(--spring), background-color var(--dur-quick) var(--ease-out);
}
@media (hover: hover) and (pointer: fine) {
  button.emap-chip:hover { background-color: color-mix(in srgb, var(--chip) 84%, var(--text)); }
}
button.emap-chip[aria-pressed="true"] { z-index: 1; box-shadow: 0 0 0 2px var(--surface), 0 0 0 4px var(--text); }
button.emap-chip:focus-visible { z-index: 2; }
button.emap-chip:active { background-color: color-mix(in srgb, var(--chip) 72%, var(--text)); transform: scale(0.97); transition-duration: var(--dur-press); transition-timing-function: var(--ease-out); }

/* Narrow: the chips go under the map, three to a row, each a rounded tile */
@container (max-width: 560px) {
  .emap-layout { grid-template-columns: minmax(0, 1fr); gap: var(--space-m); }
  .emap-chips {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(96px, 1fr));
    gap: var(--space-xs);
    margin: 0;
  }
  .emap-chips li .emap-chip { border-radius: var(--radius-small); }
}

/* MARK: - The gauges */

.egauge {
  container-type: inline-size;
  min-width: 0;
  padding: var(--space-m) var(--space-m) var(--space-l);
  border: 1px solid var(--rule);
  border-radius: var(--radius-large);
  background: var(--surface-raised);
  color: var(--text);
}
.egauge-title {
  margin: 0 0 var(--space-s);
  font-size: var(--text-body);
  font-weight: 700;
  letter-spacing: var(--track-small);
  text-align: center;
}
.egauge-body {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 280px) minmax(0, 1fr);
  grid-template-areas: "d dial r";
  align-items: end;
  column-gap: var(--space-xs);
}

/* The two sides and the dial are buttons: plain until pressed */
.egauge-side, .egauge-dial {
  margin: 0;
  padding: 0;
  border: 0;
  background: none;
  color: inherit;
  font: inherit;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  transition: transform var(--dur-settle) var(--spring), background-color var(--dur-quick) var(--ease-out);
}
.egauge-side {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: var(--space-s);
  align-self: stretch;
  min-width: 0;
  padding: var(--space-xs) var(--space-s);
  border-radius: var(--radius-small);
}
.egauge-side[data-side="D"] { grid-area: d; color: var(--dem-text); }
.egauge-side[data-side="R"] { grid-area: r; flex-direction: row-reverse; color: var(--rep-text); }
.egauge-dial { grid-area: dial; position: relative; display: block; width: 100%; container-type: inline-size; border-radius: var(--radius-small); }
@media (hover: hover) and (pointer: fine) {
  .egauge-side:hover { background-color: var(--surface-muted); }
}
.egauge-side:active, .egauge-dial:active {
  transform: scale(0.97);
  transition-duration: var(--dur-press);
  transition-timing-function: var(--ease-out);
}

.egauge-words { display: flex; flex-direction: column; align-items: flex-start; gap: 2px; }
.egauge-side[data-side="R"] .egauge-words { align-items: flex-end; }
.egauge-party { font-size: 15px; font-weight: 700; letter-spacing: 0.04em; line-height: 1.2; }
.egauge-stake { font-size: 13px; font-weight: 600; line-height: 1.2; white-space: nowrap; }
.egauge-stake:empty, .egauge-stake-short { display: none; }
.egauge-icon { flex: none; width: 30px; height: 30px; margin-bottom: 1px; }

.egauge-arc { display: block; width: 100%; height: auto; overflow: visible; }
.egauge-seg { fill: none; stroke-width: 9; stroke-linecap: round; }
.egauge-seg[data-tier="safe-d"] { stroke: var(--gauge-safe-d); }
.egauge-seg[data-tier="lean-d"] { stroke: var(--gauge-lean-d); }
.egauge-seg[data-tier="tossup"] { stroke: var(--gauge-tossup); }
.egauge-seg[data-tier="lean-r"] { stroke: var(--gauge-lean-r); }
.egauge-seg[data-tier="safe-r"] { stroke: var(--gauge-safe-r); }
.egauge-pointer {
  fill: var(--gauge-pointer);
  stroke: var(--gauge-pointer);
  stroke-width: 1.5;
  stroke-linejoin: round;
  transition: transform var(--dur-settle) var(--spring);
}

/* The chance and the rating, inside the arc and sat on its feet */
.egauge-readout {
  position: absolute;
  inset: auto 0 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  pointer-events: none;
  color: var(--text);
}
.egauge[data-fav="d"] .egauge-readout { color: var(--dem-text); }
.egauge[data-fav="r"] .egauge-readout { color: var(--rep-text); }
.egauge-chance {
  font-size: clamp(24px, 21cqi, 60px);
  font-weight: 700;
  line-height: 1;
  letter-spacing: -0.03em;
}
.egauge-rating {
  margin-top: 0.3em;
  font-size: clamp(12px, 7.2cqi, 19px);
  font-weight: 600;
  line-height: 1.1;
  white-space: nowrap;
}

/* Narrow cards, two side by side on a phone: the dial on top, the sides under it */
@container (max-width: 400px) {
  .egauge-title { font-size: var(--text-small); }
  .egauge-body {
    grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
    grid-template-areas: "dial dial" "d r";
    row-gap: var(--space-xs);
  }
  .egauge-dial { padding: 0 var(--space-xs); }
  .egauge-side { justify-content: flex-start; align-items: center; gap: var(--space-xs); padding: var(--space-xs); }
  .egauge-side[data-side="D"] { flex-direction: row-reverse; justify-content: flex-end; }
  .egauge-side[data-side="R"] { flex-direction: row; justify-content: flex-end; }
  .egauge-side[data-side="D"] .egauge-words { align-items: flex-start; }
  .egauge-words { flex-direction: column-reverse; }
  .egauge-party { font-size: 13px; }
  .egauge-stake { font-size: 12px; }
  .egauge-stake-long { display: none; }
  .egauge-stake-short { display: inline; }
  .egauge-icon { width: 24px; height: 24px; }
}

@media (prefers-reduced-motion: reduce) {
  .emap-fill, button.emap-chip, .egauge-side, .egauge-dial, .egauge-pointer { transition: none; }
}
