/* Markets panel, home "On the desk" strip, election charts (election-night.js) and project-window replays.
   Type, colour and controls follow the site tokens in styles.css; series colours below. */

:root {
  --mk-d: #1f5fbf;
  --mk-r: #c8102e;
  --mk-model: #c4501b;
  --mk-poly: #1d1d1f;
  --mk-kalshi: #2f8a6c;
  --mk-rule-strong: rgba(29, 29, 31, 0.45);
}

.mk-num {
  font-family: var(--font-num);
  font-variant-numeric: tabular-nums;
}

.is-d {
  color: var(--mk-d);
}

.is-r {
  color: var(--mk-r);
}

/* ---------- Home: On the desk ---------- */

.home-desk {
  margin: 0 0 var(--space-gap, 1.25rem);
}

.home-desk-grid,
.mk-stats {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  grid-template-columns: repeat(var(--cols, 3), minmax(0, 1fr));
  border-top: 1.5px solid var(--mk-rule-strong);
  border-bottom: 1px solid var(--border-light);
}

.mk-stats {
  --cols: 4;
}

.home-desk-grid li + li,
.mk-stats li + li {
  border-left: 1px solid var(--border-light);
}

.home-desk-card {
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
  width: 100%;
  height: 100%;
  padding: 0.8rem 0.9rem 0.75rem;
  background: none;
  border: none;
  text-align: left;
  cursor: pointer;
  color: var(--text);
}

.home-desk-card:hover {
  background: var(--accent-fill);
}

.mk-stats li {
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
  padding: 0.8rem 0.9rem 0.75rem;
  min-width: 0;
}

.home-desk-num,
.mk-stat-num {
  font-family: var(--font-num);
  font-size: var(--text-xl);
  font-weight: 600;
  line-height: 1.15;
  letter-spacing: -0.02em;
  font-variant-numeric: tabular-nums;
  color: var(--text);
}

.home-desk-label,
.mk-stat-label {
  font-family: var(--font-body);
  font-size: var(--text-caption);
  line-height: 1.4;
  color: var(--text-muted);
}

.mk-stats--compact {
  margin-bottom: 1rem;
}

.mk-stats--compact .mk-stat-num {
  font-size: var(--text-lg);
}

/* ---------- Markets panel ---------- */

body.site-scroll #markets-panel .page-shell {
  display: flex;
  flex-direction: column;
  gap: 2.5rem;
}

#markets-panel .page-header {
  margin: 0;
  padding-bottom: 0.85rem;
  border-bottom: 1px solid var(--border-light);
}

.mk-project {
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.mk-kicker {
  font-family: var(--font-body);
  font-size: var(--type-section);
  font-weight: 600;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--mk-model);
  margin: 0;
}

.mk-title {
  font-family: var(--font-display);
  font-size: var(--text-xl);
  font-weight: 600;
  line-height: 1.2;
  letter-spacing: -0.015em;
  margin: 0;
  color: var(--text);
}

.mk-lede {
  font-family: var(--font-body);
  font-size: var(--text-base);
  line-height: 1.55;
  color: var(--text-muted);
  margin: 0;
  max-width: 42rem;
}

.mk-block {
  border-top: 1.5px solid var(--mk-rule-strong);
  padding-top: 0.75rem;
}

.mk-block-head {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  justify-content: space-between;
  gap: 0.35rem 1rem;
  margin-bottom: 0.9rem;
}

.mk-block-title {
  font-family: var(--font-body);
  font-size: var(--type-section);
  font-weight: 700;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  margin: 0;
  color: var(--text);
}

.mk-asof {
  font-family: var(--font-body);
  font-size: var(--text-caption);
  color: var(--text-muted);
}

.mk-sub {
  font-family: var(--font-body);
  font-size: var(--text-caption);
  font-weight: 600;
  color: var(--text-muted);
  margin: 0 0 0.45rem;
}

.mk-note {
  font-family: var(--font-body);
  font-size: var(--text-caption);
  line-height: 1.5;
  color: var(--text-muted);
  margin: 0.75rem 0 0;
  max-width: 46rem;
}

.mk-links {
  margin: 0;
}

/* Small text link: shared look with .desk-note-link and publication toggles (styles.css). */
.mk-link {
  display: inline;
  padding: 0;
  background: none;
  border: none;
  font-family: var(--font-body);
  font-size: var(--text-caption);
  font-weight: 600;
  color: var(--text);
  text-decoration: underline;
  text-underline-offset: 2px;
  cursor: pointer;
}

.mk-link:hover {
  color: var(--text-muted);
}

.mk-row-head {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem 1rem;
  margin: 0 0 0.75rem;
}

.mk-row-head .mk-sub {
  margin: 0;
}

/* Segmented control: same as the Brazil night toggle (.bn-toggle-btn). */
.mk-seg {
  display: inline-flex;
}

.mk-seg-btn {
  height: 28px;
  padding: 0 0.75rem;
  font-family: var(--font-body);
  font-size: var(--text-caption);
  font-weight: 600;
  color: var(--text);
  background: transparent;
  border: 1px solid var(--border-strong);
  cursor: pointer;
}

.mk-seg-btn + .mk-seg-btn {
  border-left: none;
}

.mk-seg-btn:hover {
  background: var(--accent-fill);
}

.mk-seg-btn.is-active {
  background: var(--text);
  border-color: var(--text);
  color: var(--bg-main);
}

/* ---------- Charts ---------- */

.mk-chart {
  display: block;
  width: 100%;
  height: auto;
  overflow: visible;
}

.mk-chart-grid {
  stroke: rgba(29, 29, 31, 0.08);
  stroke-width: 1;
}

.mk-chart-grid--settle {
  stroke: rgba(29, 29, 31, 0.28);
  stroke-dasharray: 2 3;
}

.mk-chart-tick {
  font-family: var(--font-num);
  font-size: 9.5px;
  fill: var(--text-muted);
}

.mk-chart-line {
  fill: none;
  stroke-width: 1.5;
  stroke-linejoin: round;
}

.mk-chart-line--strong {
  stroke-width: 2.2;
}

.mk-chart-line--model {
  stroke: var(--mk-model);
}

.mk-chart-line--polymarket {
  stroke: var(--mk-poly);
}

.mk-chart-line--kalshi {
  stroke: var(--mk-kalshi);
}

.mk-chart-line--returns {
  stroke: var(--text);
}

.mk-chart-end {
  font-family: var(--font-num);
  font-size: 9.5px;
  font-weight: 600;
}

.mk-chart-end--model {
  fill: var(--mk-model);
}

.mk-chart-end--polymarket {
  fill: var(--mk-poly);
}

.mk-chart-end--kalshi {
  fill: var(--mk-kalshi);
}

.mk-chart-mark {
  stroke-width: 1;
  stroke-dasharray: 3 2;
}

.mk-chart-mark--model {
  stroke: var(--mk-model);
}

.mk-chart-mark--media {
  stroke: var(--text);
}

.mk-night-chart {
  max-width: 760px;
}

.mk-legend {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.3rem 0.9rem;
  font-family: var(--font-body);
  font-size: var(--text-caption);
  color: var(--text-muted);
  margin: 0.35rem 0 0;
}

.mk-key {
  display: inline-block;
  width: 9px;
  height: 9px;
  border-radius: 50%;
  margin-right: 0.3rem;
  vertical-align: -1px;
}

.mk-key--model {
  background: var(--mk-model);
}

.mk-key--media {
  background: var(--bg-main);
  border: 1.4px solid var(--text);
}

.mk-key--line {
  width: 14px;
  height: 0;
  border-radius: 0;
  border: none;
  border-top: 1.5px dashed;
  vertical-align: 3px;
}

.mk-key--line.mk-key--model {
  background: none;
  border-top-color: var(--mk-model);
}

.mk-key--line.mk-key--media {
  background: none;
  border-top-color: var(--text);
}

/* Call-time dumbbells */

.mk-us-chart {
  overflow-x: auto;
}

.mk-calls-chart {
  max-width: 760px;
  min-width: 560px;
}

.mk-call-row {
  cursor: pointer;
}

.mk-call-hit {
  fill: transparent;
}

.mk-call-row:hover .mk-call-hit,
.mk-call-row.is-selected .mk-call-hit {
  fill: var(--accent-fill);
}

.mk-call-row:focus-visible {
  outline: none;
}

.mk-call-row:focus-visible .mk-call-hit {
  fill: var(--accent-fill-strong);
}

.mk-call-name {
  font-family: var(--font-body);
  font-size: 10.5px;
  fill: var(--text);
}

.mk-call-row.is-selected .mk-call-name {
  font-weight: 700;
}

.mk-call-gap {
  stroke: var(--mk-model);
  stroke-width: 2;
  stroke-opacity: 0.45;
}

.mk-call-gap.is-late {
  stroke: var(--text-muted);
}

.mk-call-model {
  fill: var(--mk-model);
}

.mk-call-media {
  fill: var(--bg-main);
  stroke: var(--text);
  stroke-width: 1.4;
}

.mk-call-lead {
  font-family: var(--font-num);
  font-size: 10px;
  font-weight: 600;
  fill: var(--text);
}

.mk-call-lead.is-late {
  fill: var(--text-muted);
}

.mk-us-night,
.mk-replay-chart {
  margin: 1.25rem 0;
}

/* ---------- Tables ---------- */

.mk-scroll {
  overflow-x: auto;
}

.mk-table {
  width: 100%;
  border-collapse: collapse;
  font-family: var(--font-body);
  font-size: var(--type-body);
}

.mk-table th,
.mk-table td {
  padding: 0.4rem 0.5rem;
  border-bottom: 1px solid var(--border-light);
  text-align: left;
  white-space: nowrap;
}

.mk-table th:first-child,
.mk-table td:first-child {
  padding-left: 0;
}

.mk-table thead th {
  font-size: var(--text-caption);
  font-weight: 600;
  color: var(--text-muted);
  border-bottom: 1.5px solid var(--mk-rule-strong);
}

.mk-table tbody th {
  font-weight: 600;
  color: var(--text);
}

.mk-table .mk-num {
  text-align: right;
}

.mk-table td.mk-num {
  font-size: 0.78rem;
}

.mk-edge-val {
  font-weight: 600;
}

.mk-cell-sub {
  display: block;
  font-family: var(--font-body);
  font-size: 0.625rem;
  color: var(--text-muted);
}

.mk-rows tbody tr[data-race] {
  cursor: pointer;
}

.mk-rows tbody tr[data-race]:hover,
.mk-rows tbody tr.is-selected {
  background: var(--accent-fill);
}

.mk-rows tbody tr[data-race]:focus-visible {
  outline: 1px solid var(--text);
  outline-offset: -1px;
}

.mk-tag {
  font-family: var(--font-body);
  font-size: 0.625rem;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--text-muted);
  border: 1px solid var(--border-light);
  padding: 0.05rem 0.3rem;
  vertical-align: middle;
}

.mk-miss {
  color: var(--mk-model);
  font-weight: 600;
}

/* ---------- Replay returns ---------- */

.mk-returns {
  margin: 0 0 1.25rem;
}

.mk-returns .mk-note {
  margin-top: 0.25rem;
}

.mk-returns-big {
  font-size: var(--text-lg);
  font-weight: 600;
  margin: 0;
  color: var(--text);
}

.mk-returns-chart {
  max-width: 360px;
  margin-top: 0.5rem;
}

/* ---------- finmath-open ---------- */

.mk-fm-bar {
  display: flex;
  height: 10px;
  gap: 2px;
  margin-bottom: 0.55rem;
}

.mk-fm-seg {
  min-width: 3px;
}

.mk-fm--solved {
  background: var(--text);
}

.mk-fm--answered {
  background: rgba(29, 29, 31, 0.68);
}

.mk-fm--partly {
  background: rgba(29, 29, 31, 0.32);
}

.mk-fm--open {
  background: rgba(29, 29, 31, 0.08);
  box-shadow: inset 0 0 0 1px rgba(29, 29, 31, 0.18);
}

.mk-fm--literature {
  background: repeating-linear-gradient(135deg, rgba(29, 29, 31, 0.4) 0 2px, transparent 2px 5px);
}

.mk-fm-legend {
  list-style: none;
  margin: 0 0 1rem;
  padding: 0;
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem 1.1rem;
  font-family: var(--font-body);
  font-size: var(--text-caption);
  color: var(--text-muted);
}

.mk-fm-legend li {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
}

.mk-fm-legend b {
  color: var(--text);
  font-weight: 600;
}

.mk-fm-swatch {
  width: 10px;
  height: 10px;
  display: inline-block;
}

.mk-fm-groups {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 1rem 1.75rem;
}

.mk-fm-list {
  list-style: none;
  margin: 0;
  padding: 0;
  border-top: 1.5px solid var(--mk-rule-strong);
}

.mk-fm-item {
  border-bottom: 1px solid var(--border-light);
}

.mk-fm-item summary {
  display: grid;
  grid-template-columns: 2.4rem minmax(0, 1fr) auto;
  align-items: baseline;
  gap: 0.5rem;
  padding: 0.45rem 0;
  cursor: pointer;
  list-style: none;
  font-family: var(--font-body);
  font-size: var(--type-body);
}

.mk-fm-item summary::-webkit-details-marker {
  display: none;
}

.mk-fm-item summary:hover .mk-fm-title {
  text-decoration: underline;
  text-underline-offset: 2px;
}

.mk-fm-id {
  font-size: var(--text-xs);
  color: var(--text-muted);
}

.mk-fm-title {
  color: var(--text);
  line-height: 1.35;
}

.mk-fm-pill {
  font-family: var(--font-body);
  font-size: 0.625rem;
  font-weight: 600;
  white-space: nowrap;
  padding: 0.12rem 0.4rem;
  color: var(--text);
  border: 1px solid var(--border-strong);
}

.mk-fm-pill.mk-fm--solved,
.mk-fm-pill.mk-fm--answered {
  background: var(--text);
  color: var(--bg-main);
  border-color: var(--text);
}

.mk-fm-pill.mk-fm--partly,
.mk-fm-pill.mk-fm--open {
  background: none;
  box-shadow: none;
}

.mk-fm-pill.mk-fm--literature {
  background: none;
  border-style: dashed;
}

.mk-fm-detail {
  padding: 0 0 0.7rem 2.9rem;
}

.mk-fm-answer {
  font-family: var(--font-body);
  font-size: var(--type-body);
  line-height: 1.55;
  color: var(--text);
  margin: 0;
}

.mk-fm-links {
  margin: 0.45rem 0 0;
  font-family: var(--font-body);
  font-size: var(--text-caption);
}

.mk-fm-links a {
  color: var(--text);
  font-weight: 600;
  text-underline-offset: 2px;
}

/* ---------- Project windows ---------- */

.project-viz-replay {
  padding: 0.75rem 0.9rem 1rem;
}

.project-viz-replay .mk-stats {
  --cols: 2;
}

.project-viz-replay .mk-stats li:nth-child(3) {
  border-left: none;
}

.project-viz-replay .mk-stats li:nth-child(n + 3) {
  border-top: 1px solid var(--border-light);
}

/* ---------- Narrow screens ---------- */

@media (max-width: 860px) {
  .mk-stats {
    --cols: 2;
  }
  .mk-stats li:nth-child(3) {
    border-left: none;
  }
  .mk-stats li:nth-child(n + 3) {
    border-top: 1px solid var(--border-light);
  }
  .mk-fm-groups {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 640px) {
  .home-desk-grid {
    --cols: 1;
  }
  .home-desk-grid li + li {
    border-left: none;
    border-top: 1px solid var(--border-light);
  }
}

@media (max-width: 520px) {
  .mk-table th,
  .mk-table td {
    padding: 0.35rem 0.3rem;
  }
  .mk-fm-detail {
    padding-left: 0;
  }
}

/* The Brazil section draws its own top rule (.bn-head). */
.mk-block.mk-brazil {
  border-top: none;
  padding-top: 0;
}

/* ---------- Night player (night-player.js): play/pause, scrubber, time ---------- */

.np {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  margin: 0.5rem 0 0.75rem;
}

.np-btn {
  height: 28px;
  min-width: 4.25rem;
  padding: 0 0.75rem;
  font-family: var(--font-body);
  font-size: var(--text-caption);
  font-weight: 600;
  color: var(--bg-main);
  background: var(--text);
  border: 1px solid var(--text);
  border-radius: 0;
  cursor: pointer;
}

.np-btn.is-active {
  color: var(--text);
  background: transparent;
}

.np-range {
  --np-fill: 100%;
  flex: 1 1 auto;
  min-width: 0;
  height: 18px;
  margin: 0;
  background: transparent;
  appearance: none;
  -webkit-appearance: none;
  cursor: pointer;
}

.np-range::-webkit-slider-runnable-track {
  height: 2px;
  background: linear-gradient(90deg, var(--mk-model) var(--np-fill), var(--border-light, #dcd9d2) var(--np-fill));
}

.np-range::-moz-range-track {
  height: 2px;
  background: linear-gradient(90deg, var(--mk-model) var(--np-fill), var(--border-light, #dcd9d2) var(--np-fill));
}

.np-range::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 12px;
  height: 12px;
  margin-top: -5px;
  border-radius: 50%;
  background: var(--mk-model);
  border: 2px solid var(--bg-main);
}

.np-range::-moz-range-thumb {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--mk-model);
  border: 2px solid var(--bg-main);
}

.np-range:focus-visible {
  outline: 1px solid var(--text);
  outline-offset: 2px;
}

.np-time {
  min-width: 7.5rem;
  text-align: right;
  font-size: var(--text-caption);
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  color: var(--text);
  white-space: nowrap;
}

/* ---------- US night: Senate / Governor / House maps above the story's race ---------- */

.mk-us-maps {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0 1rem;
}

.mk-us-maps--3 {
  grid-template-columns: repeat(3, minmax(0, 1fr));
}

.mk-us-mapfig {
  margin: 0;
  min-width: 0;
}

.mk-map-title {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 0 0.5rem;
  margin: 0 0 0.2rem;
  font-size: var(--text-caption);
  font-weight: 600;
  color: var(--text);
}

.mk-map-count {
  font-size: var(--text-xs);
  font-weight: 400;
  color: var(--text-muted);
  font-variant-numeric: tabular-nums;
}

.mk-cap-note {
  margin: 0.3rem 0 1.25rem;
  font-size: var(--text-caption);
  color: var(--text-muted);
}

/* Full width; election-night.js shortens the viewBox when the pinned panel is short of room. */
.mk-sticky .mk-night-chart {
  max-width: none;
}

.mk-scope {
  margin: 0 0 0.75rem;
}

.mk-map {
  display: block;
  width: 100%;
  height: auto;
}

.mk-map-state {
  fill-rule: evenodd;
  fill: #f3f1ec;
  stroke: var(--bg-main);
  stroke-width: 0.8;
  transition: fill 0.25s linear;
}

.mk-map-state.has-race {
  cursor: pointer;
}

.mk-map-state.is-precount {
  fill-opacity: 0.5;
}

.mk-map-state.is-called {
  stroke: var(--text);
  stroke-width: 1.2;
}

.mk-map-state.is-selected {
  stroke: var(--mk-model);
  stroke-width: 2.4;
}

.mk-map-cap {
  font-size: var(--text-caption);
  color: var(--text-muted);
  margin: 0.4rem 0 0;
}

.mk-ramp {
  display: inline-block;
  width: 56px;
  height: 8px;
  margin-right: 0.3rem;
  background: linear-gradient(90deg, #c8102e, #ece8e1 50%, #1f5fbf);
}

.mk-key--called {
  border-radius: 0;
  background: transparent;
  border: 1.2px solid var(--text);
}

.mk-key--precount {
  border-radius: 0;
  background: rgba(31, 95, 191, 0.4);
}

.mk-readout {
  display: flex;
  flex-wrap: wrap;
  gap: 0.15rem 1rem;
  min-height: 1.6rem;
  margin: 0.25rem 0 0.35rem;
  font-size: var(--text-caption);
  color: var(--text-muted);
}

.mk-ro-cell {
  display: inline-flex;
  align-items: baseline;
  gap: 0.35rem;
  white-space: nowrap;
}

.mk-ro-k {
  font-size: var(--text-xs);
}

.mk-ro-v {
  font-weight: 600;
  color: var(--text);
  font-variant-numeric: tabular-nums;
}

.mk-chart-now {
  stroke: var(--mk-model);
  stroke-width: 1;
}

.mk-us-mapfig[data-office="house"] .mk-map-state {
  stroke-width: 0.35;
}

.mk-us-mapfig[data-office="house"] .mk-map-state.is-selected {
  stroke-width: 1.6;
}

@media (prefers-reduced-motion: reduce) {
  .mk-map-state {
    transition: none;
  }
}

/* ---------- Scroll track (night-player.js): the panel sticks while the track scrolls past ---------- */

.np-sticky {
  position: sticky;
  top: 0;
  z-index: 2;
  display: flex;
  flex-direction: column;
  justify-content: center;
  padding: 0.6rem 0 0.4rem;
  background: var(--bg-main);
}

.np-free .np-sticky {
  position: static;
}

/* Story line for the current moment of the night */
.ns-cap {
  min-height: 3.2em;
  margin: 0 0 0.4rem;
  padding-left: 0.7rem;
  border-left: 2px solid var(--mk-model);
  font-size: var(--text-caption);
  line-height: 1.5;
  color: var(--text);
}

.ns-cap-t {
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  margin-right: 0.25rem;
}

.ns-cap-race {
  font-weight: 600;
}

/* Short screens: the maps give up height before the race chart does. */
.mk-us-mapfig .mk-map {
  max-height: calc(var(--np-view, 900px) * 0.24);
}
