/* Midterms (#/midterms, pages/midterms.js): his endorsement record, the chart by state, the wall of candidate cards
   that turn over to show the result (the turn itself is the credits card's, credits.css), and the election-night
   watch. Won is green, lost is the logo red, through to November is yellow-orange, waiting is grey. */

:root {
  --s-won: var(--good);
  --s-lost: var(--red);
  --s-ahead: light-dark(#c27c0e, #f2b552);
  --s-waiting: light-dark(#9aa3b2, #56637c);
  --s-out: light-dark(#c4c9d4, #3a4560);
}
.s-won { --s: var(--s-won); }
.s-lost { --s: var(--s-lost); }
.s-ahead { --s: var(--s-ahead); }
.s-waiting { --s: var(--s-waiting); }
.s-out { --s: var(--s-out); }
.s-none { --s: var(--line); }

.mhead .eyebrow a { color: inherit; text-decoration: none; border-bottom: 1px dashed currentColor; }
.mhead .eyebrow a:hover { border-bottom-style: solid; }
.mt-stamp-line { margin: 6px 0 0; }

/* ---- Election night watch ---- */
.mt-watch {
  --w: var(--blue);
  position: relative; display: flex; align-items: center; gap: 18px 22px; flex-wrap: wrap; overflow: hidden;
  margin: 0 0 var(--gap); padding: 16px 20px; isolation: isolate;
  background: linear-gradient(100deg, color-mix(in srgb, var(--w) 13%, var(--panel)), var(--panel) 60%);
  border-left: 4px solid var(--w);
}
.mt-watch.w-live { --w: var(--red); }
.mt-watch.w-over, .mt-watch.w-off { --w: var(--muted); }
.mt-watch h2 { margin: 0 0 2px; font: 800 20px/1.1 var(--display); font-stretch: 85%; }
.mt-watch p { margin: 0; color: var(--muted); max-width: 70ch; }
.mt-watch-words { flex: 1 1 320px; min-width: 0; }
/* A beacon: three rings that keep spreading out from a dot, faster when the watch is live. */
.mt-beacon { position: relative; width: 34px; height: 34px; flex: none; }
.mt-beacon i { position: absolute; inset: 0; border-radius: 50%; border: 2px solid var(--w); opacity: 0; animation: mt-ring 2.6s cubic-bezier(.2, .7, .3, 1) infinite; }
.mt-beacon i:nth-child(2) { animation-delay: .85s; }
.mt-beacon i:nth-child(3) { animation-delay: 1.7s; }
.mt-beacon::after { content: ""; position: absolute; inset: 11px; border-radius: 50%; background: var(--w); box-shadow: 0 0 14px var(--w); }
.w-live .mt-beacon i { animation-duration: 1.4s; }
.w-over .mt-beacon i, .w-off .mt-beacon i { animation: none; }
@keyframes mt-ring { 0% { opacity: .9; transform: scale(.3); } 100% { opacity: 0; transform: scale(1.35); } }
.mt-count { display: grid; gap: 4px; justify-items: end; }
.mt-count-label { font: 600 10.5px/1 var(--mono); text-transform: uppercase; letter-spacing: .08em; color: var(--muted); }
.mt-count > div { display: flex; gap: 6px; }
.mt-count span { display: grid; justify-items: center; min-width: 46px; padding: 6px 6px 5px; background: var(--panel-2); border: 1px solid var(--line); }
.mt-count b { font: 700 22px/1 var(--mono); font-variant-numeric: tabular-nums; color: var(--ink); }
.mt-count small { font: 500 9.5px/1.4 var(--mono); color: var(--muted); text-transform: uppercase; letter-spacing: .06em; }

/* ---- The year switch, the record and the map ---- */
.mt-years { margin: 0 0 var(--gap); }
.mt-top { display: grid; grid-template-columns: minmax(0, 1.25fr) minmax(0, 1fr); gap: var(--gap); margin-bottom: var(--gap); align-items: start; }
@media (max-width: 980px) { .mt-top { grid-template-columns: minmax(0, 1fr); } }
.mt-top > .panel { margin: 0; }
.mt-record { display: flex; flex-direction: column; gap: 14px; }
.mt-record-top { display: flex; justify-content: space-between; align-items: center; gap: 10px; flex-wrap: wrap; }
.mt-record-top .eyebrow { margin: 0; }
.mt-record-acts { display: flex; gap: 8px; flex-wrap: wrap; }
.mt-line { margin: 0; font: 800 clamp(28px, 3.4vw, 44px)/1.04 var(--display); font-stretch: 78%; letter-spacing: -.01em; text-wrap: balance; }
.mt-line b { font-variant-numeric: tabular-nums; }
.mt-lostline { display: inline-block; color: var(--red-ink); }
.mt-lostline b { font-size: 1.12em; }
.mt-lostline.wait { color: var(--muted); }
.mt-bar { display: flex; gap: 3px; height: 26px; padding: 3px; background: var(--panel-2); border: 1px solid var(--line); overflow: hidden; }
.mt-seg { display: block; min-width: 4px; background: var(--s); transform-origin: left center; }
.mt-seg.s-out { background: repeating-linear-gradient(135deg, var(--s-out) 0 5px, transparent 5px 9px); }
.mt-seg.s-lost { box-shadow: 0 0 18px -4px var(--s-lost); }
.mt-legend { display: flex; flex-wrap: wrap; gap: 6px 16px; margin: 0; padding: 0; list-style: none; font: 600 13px/1.3 var(--body); }
.mt-legend li { display: inline-flex; align-items: center; gap: 7px; }
.mt-legend li.none { opacity: .45; }
.mt-legend i { width: 11px; height: 11px; background: var(--s); flex: none; }
.mt-legend b { font-variant-numeric: tabular-nums; }
.mt-legend.mini { font-size: 12px; margin-top: 12px; }
.mt-splits { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 10px; margin: 0; }
.mt-splits > div { padding: 10px 12px; background: var(--panel-2); border: 1px solid var(--line); }
.mt-splits dt { font: 600 10.5px/1.3 var(--mono); text-transform: uppercase; letter-spacing: .06em; color: var(--muted); }
.mt-splits dd { margin: 4px 0 0; font: 800 24px/1 var(--display); font-stretch: 85%; font-variant-numeric: tabular-nums; }
.mt-splits .g { color: var(--good); }
.mt-splits .r { color: var(--red-ink); }
.mt-eday { margin: 0; }
@media (max-width: 560px) { .mt-splits { grid-template-columns: minmax(0, 1fr); } }

.mt-map-top { display: flex; align-items: baseline; justify-content: space-between; gap: 6px 14px; flex-wrap: wrap; margin-bottom: 12px; }
.mt-map-top h2 { margin: 0; font: 800 20px/1.1 var(--display); font-stretch: 85%; }
.mt-map-top p { margin: 0; }
.mt-states { display: grid; grid-template-columns: repeat(12, minmax(0, 1fr)); gap: 4px; perspective: 700px; }
.mt-st {
  --loss: clamp(0, var(--lean, 0), 1); --win: clamp(0, calc(var(--lean, 0) * -1), 1);
  appearance: none; position: relative; aspect-ratio: 1; min-width: 0; padding: 4px 2px 7px; margin: 0;
  display: grid; align-content: center; justify-items: center; gap: 1px; overflow: hidden;
  border: 1px solid var(--line); border-radius: 6px; color: var(--ink); cursor: pointer; font: inherit;
  background: color-mix(in srgb, var(--s-lost) calc(var(--loss) * 42%), color-mix(in srgb, var(--s-won) calc(var(--win) * 36%), var(--panel-2)));
  transition: transform .25s var(--spring), box-shadow .25s, opacity .25s, border-color .2s;
}
.mt-st b { font: 700 clamp(9px, 1vw, 12px)/1 var(--mono); letter-spacing: .02em; }
.mt-st small { font: 600 clamp(8px, .85vw, 10.5px)/1 var(--mono); color: var(--muted); font-variant-numeric: tabular-nums; }
.mt-st-fill { position: absolute; left: 3px; right: 3px; bottom: 3px; height: 3px; display: flex; gap: 1px; transform-origin: left center; }
.mt-st-fill i { display: block; background: var(--s); min-width: 2px; }
.mt-st.empty { cursor: default; opacity: .4; border-style: dashed; background: transparent; }
button.mt-st:hover { transform: translateY(-3px) scale(1.12); z-index: 2; box-shadow: var(--shadow-up); border-color: color-mix(in srgb, var(--ink) 30%, var(--line)); }
button.mt-st:active { transform: scale(.94); }
.mt-st.on { border-color: var(--ink); box-shadow: 0 0 0 2px var(--ink); z-index: 1; }
.mt-states:has(.mt-st.on) .mt-st:not(.on) { opacity: .45; }

/* ---- Filters ---- */
.mt-tools { display: flex; flex-wrap: wrap; align-items: center; gap: 10px 12px; margin: 6px 0 calc(var(--gap) / 2); scroll-margin-top: 140px; }
.mt-show .n { margin-left: 6px; font: 600 11px/1 var(--mono); color: var(--muted); font-variant-numeric: tabular-nums; }
.mt-level select { min-height: 36px; }
.mt-statechip[hidden] { display: none; }
.mt-statechip { display: inline-flex; align-items: center; gap: 6px; padding: 5px 6px 5px 12px; font: 600 13px/1 var(--body); background: var(--ink); color: var(--panel); }
.mt-statechip .mt-x { appearance: none; border: 0; background: transparent; color: inherit; cursor: pointer; font-size: 12px; padding: 2px 5px; }
.mt-flipall { margin-left: auto; }
.mt-flipall .ic { transition: transform .6s var(--spring); }
.mt-flipall:hover .ic { transform: rotateY(180deg); }

/* ---- The cards ---- */
.mt-card { --st: var(--s-waiting); height: 100%; }
.mt-card.st-won { --st: var(--s-won); }
.mt-card.st-lost { --st: var(--s-lost); }
.mt-card.st-ahead { --st: var(--s-ahead); }
.mt-card.st-out { --st: var(--s-out); }
.mt-card .flip-face { padding: 16px 18px 14px; gap: 8px; }
.mt-card .flip-btn { margin: 0; }
.mt-front { cursor: pointer; }
.mt-front:hover { box-shadow: var(--shadow-up); }
.mt-head { display: flex; justify-content: space-between; align-items: center; gap: 8px; }
.mt-lvl { font: 650 10.5px/1 var(--mono); text-transform: uppercase; letter-spacing: .07em; padding: 4px 7px; color: var(--muted); background: var(--panel-2); border: 1px solid var(--line); }
.mt-lvl.l-senate, .mt-lvl.l-governor { color: var(--blue-ink); border-color: color-mix(in srgb, var(--blue) 40%, var(--line)); }
.mt-lvl.l-abroad { color: light-dark(#0d7d73, #2dd4bf); }
.mt-yr { font: 600 11px/1 var(--mono); color: var(--muted); }
.mt-name { margin: 2px 0 0; font: 800 23px/1.05 var(--display); font-stretch: 80%; letter-spacing: -.005em; text-wrap: balance; }
.mt-party { display: inline-block; vertical-align: .22em; font: 700 10.5px/1 var(--mono); padding: 3px 5px; color: #fff; background: var(--muted); }
.mt-party.p-R { background: var(--red); }
.mt-party.p-D { background: var(--blue); }
.mt-race { margin: 0; color: var(--muted); font-size: 13.5px; }
.mt-quote {
  appearance: none; display: block; width: 100%; text-align: left; margin: 4px 0 0; padding: 2px 0 2px 12px; cursor: pointer;
  border: 0; border-left: 3px solid var(--red); background: none; color: var(--ink);
  font: italic 500 15.5px/1.45 var(--body); transition: border-color .2s, transform .2s var(--ease);
}
.mt-quote:hover { border-left-color: var(--blue); transform: translateX(2px); }
.mt-foot, .mt-acts { margin-top: auto; padding-top: 8px; display: flex; justify-content: space-between; align-items: center; gap: 8px; flex-wrap: wrap; font-size: 12.5px; color: var(--muted); }

.mt-back { --lvl: var(--st); border-top: 4px solid var(--st); }
.mt-stamp {
  position: absolute; top: 14px; right: 14px; z-index: 3; transform: rotate(-8deg); pointer-events: none;
  padding: 5px 10px 4px; border: 3px solid var(--st); color: var(--st); border-radius: 4px;
  font: 900 18px/1 var(--display); font-stretch: 75%; letter-spacing: .08em; text-transform: uppercase;
  box-shadow: inset 0 0 0 1px color-mix(in srgb, var(--st) 30%, transparent);
  mix-blend-mode: normal;
}
.mt-back .mt-name { padding-right: 96px; }
.mt-stages { list-style: none; margin: 4px 0 0; padding: 0; display: grid; gap: 8px; }
.mt-stages li {
  --o: var(--s-waiting);
  position: relative; isolation: isolate; overflow: hidden;
  display: grid; grid-template-columns: auto 1fr; grid-template-areas: "stage out" "detail detail"; gap: 2px 10px; align-items: baseline;
  padding: 7px 10px; background: var(--panel-2); border-left: 3px solid var(--o);
}
.mt-stages li.o-won, .mt-stages li.o-unopposed { --o: var(--s-won); }
.mt-stages li.o-lost { --o: var(--s-lost); }
.mt-stages li.o-withdrew { --o: var(--s-out); }
.mt-stage { grid-area: stage; font: 650 10.5px/1.2 var(--mono); text-transform: uppercase; letter-spacing: .06em; color: var(--muted); }
.mt-out { grid-area: out; justify-self: end; font: 800 15px/1 var(--display); font-stretch: 85%; color: var(--o); text-transform: uppercase; letter-spacing: .03em; }
/* Their share of the vote fills the row from the left, behind the words. */
.mt-share { position: absolute; inset: 0; z-index: -1; pointer-events: none; }
.mt-share i { display: block; height: 100%; background: color-mix(in srgb, var(--o) 20%, transparent); transform-origin: left center; transform: scaleX(var(--s)); }
.mt-detail { grid-area: detail; font-size: 12.5px; color: var(--ink); }
.mt-note { margin: 2px 0 0; color: var(--muted); font-size: 13px; }
.mt-src { margin: 0; font-size: 12px; color: var(--muted); }
.mt-src a { color: var(--blue-ink); }
.tile.mt-hidden .mt-card { opacity: .55; }
.tile.mt-hidden .flip-face { border-style: dashed; }
.mt-none { text-align: center; }
.mt-none .btn { margin-top: 6px; }
.mt-empty h2 { margin-top: 0; }

/* ---- The dialogs ---- */
.mt-dialog h3 { margin: 18px 0 8px; font: 700 15px/1.2 var(--body); }
.mt-fields { display: flex; flex-wrap: wrap; gap: 10px; margin: 8px 0; }
.mt-fields label { display: grid; gap: 4px; flex: 1 1 120px; font-size: 13px; color: var(--muted); }
.mt-fields input, .mt-fields select { width: 100%; }

/* ---- The chart video (#/render/endorsements) ---- */
/* The record on the left, the states on the right, so the chart fills a 16:9 frame. */
html[data-film="endorsements"] .film-fit { width: auto; }
.film-midterms { width: 1560px; display: grid; grid-template-columns: 1fr 1.15fr; align-items: center; gap: 48px; padding: 40px 44px; }
.film-midterms .mt-record { display: grid; gap: 22px; }
.film-midterms .mt-line { font-size: 64px; line-height: 1.05; }
.film-midterms .mt-bar { height: 40px; }
.film-midterms .mt-legend { font-size: 19px; gap: 10px 20px; }
.film-midterms .mt-states { gap: 6px; }
.film-midterms .mt-st b { font-size: 15px; }
.film-midterms .mt-st small { font-size: 12px; }

@media (prefers-reduced-motion: reduce) {
  .mt-beacon i { animation: none; }
  button.mt-st:hover { transform: none; }
  .mt-quote:hover { transform: none; }
}
