:root {
  --ink: #0d1523;
  --ink-soft: #263346;
  --muted: #667085;
  --paper: #f4f6f1;
  --panel: #fffefa;
  --panel-cool: #f8fbff;
  --line: #d7dde4;
  --line-strong: #aab4c1;
  --teal: #0d8b84;
  --blue: #2166c2;
  --coral: #e44e3f;
  --amber: #c68a13;
  --green: #4d8f2e;
  --violet: #6756a5;
  --shadow: 0 18px 45px rgba(13, 21, 35, 0.08);
  --shadow-tight: 0 8px 22px rgba(13, 21, 35, 0.08);
}

* {
  box-sizing: border-box;
}

html {
  color: var(--ink);
  background: var(--paper);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

body {
  margin: 0;
  min-width: 320px;
  overflow-x: hidden;
  background:
    linear-gradient(rgba(13, 21, 35, 0.035) 1px, transparent 1px),
    linear-gradient(90deg, rgba(13, 21, 35, 0.035) 1px, transparent 1px),
    var(--paper);
  background-size: 30px 30px;
}

button,
a {
  font: inherit;
}

button {
  color: inherit;
}

.skip-link {
  position: absolute;
  left: 16px;
  top: -48px;
  z-index: 20;
  color: #ffffff;
  background: var(--ink);
  padding: 10px 12px;
}

.skip-link:focus {
  top: 16px;
}

.command-bar {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 22px;
  padding: 14px clamp(18px, 4vw, 52px);
  border-bottom: 1px solid var(--line);
  background: rgba(255, 254, 250, 0.92);
  backdrop-filter: blur(18px);
}

.brand-zone,
.command-meta,
.metric-strip,
.legend,
.chart-key,
.chart-caption-row {
  display: flex;
  align-items: center;
}

.brand-zone {
  min-width: 0;
  gap: 14px;
}

.brand-mark {
  display: grid;
  place-items: center;
  flex: 0 0 auto;
  width: 42px;
  height: 42px;
  color: #ffffff;
  background: var(--ink);
  border: 2px solid var(--teal);
  border-radius: 8px;
  font-weight: 900;
  letter-spacing: 0;
}

.brand-zone h1 {
  margin: 0;
  font-size: clamp(1.25rem, 2vw, 1.75rem);
  line-height: 1.02;
  letter-spacing: 0;
}

.brand-zone p {
  margin: 5px 0 0;
  color: var(--muted);
  font-size: 0.9rem;
  line-height: 1.25;
}

.command-meta {
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 8px;
}

.command-meta span,
.rail-label,
.event-kind,
.gap-status {
  border: 1px solid var(--line);
  border-radius: 7px;
  padding: 7px 9px;
  background: #ffffff;
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 800;
  line-height: 1;
  white-space: nowrap;
}

.icon-command {
  display: grid;
  place-items: center;
  width: 38px;
  height: 34px;
  border: 1px solid var(--line-strong);
  border-radius: 7px;
  background: #ffffff;
  cursor: pointer;
}

.icon-command svg {
  width: 18px;
  height: 18px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.icon-command:hover,
.icon-command:focus-visible,
.icon-command.copied {
  border-color: var(--teal);
  color: var(--teal);
}

main {
  width: min(1540px, 100%);
  margin: 0 auto;
  padding: clamp(14px, 3vw, 34px) clamp(14px, 4vw, 52px) 56px;
}

.metric-rail {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 12px;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 254, 250, 0.82);
  box-shadow: var(--shadow-tight);
}

.metric-rail > div:first-child {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}

.metric-strip {
  flex-wrap: wrap;
  gap: 6px;
}

.metric-button {
  min-height: 34px;
  border: 1px solid var(--line-strong);
  border-radius: 7px;
  padding: 8px 13px;
  background: #ffffff;
  color: var(--ink-soft);
  cursor: pointer;
  font-size: 0.86rem;
  font-weight: 850;
  line-height: 1;
}

.metric-button:hover,
.metric-button:focus-visible {
  border-color: var(--ink);
}

.metric-button.active {
  color: #ffffff;
  background: var(--teal);
  border-color: var(--teal);
  box-shadow: inset 0 -2px 0 rgba(0, 0, 0, 0.14);
}

.legend {
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 8px 12px;
  color: var(--muted);
  font-size: 0.82rem;
  font-weight: 800;
}

.legend span,
.chart-key span {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.legend i,
.dot {
  display: inline-block;
  width: 10px;
  height: 10px;
  border-radius: 999px;
}

.raceboard-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(302px, 0.28fr);
  gap: 12px;
  align-items: start;
}

.chart-panel,
.pulse-panel,
.selected-panel,
.watch-panel,
.matrix-panel,
.ledger-panel,
.analysis-panel,
.sources-panel {
  min-width: 0;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 254, 250, 0.96);
  box-shadow: var(--shadow);
}

.chart-panel,
.matrix-panel,
.ledger-panel,
.analysis-panel,
.sources-panel {
  padding: clamp(14px, 2vw, 20px);
}

.panel-heading {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 18px;
  margin-bottom: 12px;
}

.panel-heading.compact {
  margin-bottom: 10px;
}

.panel-heading h2,
.pulse-panel h2,
.selected-panel h2,
.watch-panel h2 {
  margin: 0;
  color: var(--ink);
  font-size: clamp(1.15rem, 2.1vw, 1.6rem);
  line-height: 1.1;
  letter-spacing: 0;
}

.panel-heading p {
  margin: 5px 0 0;
  color: var(--muted);
  font-size: 0.92rem;
  line-height: 1.35;
}

.chart-heading h2 {
  font-size: clamp(1.25rem, 2.4vw, 2rem);
}

.chart-key {
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 12px;
  color: var(--ink-soft);
  font-size: 0.82rem;
  font-weight: 800;
}

.dot.real {
  background: var(--ink);
}

.dot.rumor {
  border: 2px dashed var(--teal);
}

.diamond {
  width: 10px;
  height: 10px;
  background: var(--blue);
  transform: rotate(45deg);
}

.chart-wrap {
  position: relative;
  width: 100%;
  max-width: 100%;
  min-height: 430px;
  overflow-x: auto;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel-cool);
}

#raceChart {
  display: block;
  width: 100%;
  min-width: 900px;
  height: clamp(480px, 45vw, 640px);
}

.chart-bg {
  fill: #fbfcff;
}

.plot-frame {
  fill: #ffffff;
  stroke: #dbe2ea;
}

.grid-line {
  stroke: #d9e1e8;
  stroke-width: 1;
}

.date-line {
  stroke: #e8edf2;
  stroke-width: 1;
}

.axis-base {
  stroke: #8e9aaa;
  stroke-width: 1.2;
}

.band {
  stroke-width: 1;
}

.band.frontier {
  stroke: rgba(13, 139, 132, 0.28);
}

.band.contested {
  stroke: rgba(198, 138, 19, 0.25);
}

.band-label,
.axis-label,
.date-label,
.axis-title,
.chart-caption,
.event-axis-label,
.point-label,
.point-score,
.rumor-label,
.anomaly-title,
.anomaly-text {
  font-family: inherit;
  letter-spacing: 0;
}

.band-label,
.axis-label,
.date-label,
.axis-title,
.chart-caption,
.event-axis-label {
  fill: var(--muted);
  font-size: 12px;
  font-weight: 800;
}

.axis-title {
  fill: var(--ink-soft);
}

.rumor-line,
.claim-stem {
  stroke: var(--teal);
  stroke-dasharray: 7 7;
  stroke-width: 2;
}

.rumor-dot {
  fill: #ffffff;
  stroke: var(--teal);
  stroke-dasharray: 3 3;
  stroke-width: 2;
}

.rumor-label {
  fill: var(--teal);
  font-size: 13px;
  font-weight: 900;
}

.frontier-line {
  fill: none;
  stroke: var(--ink);
  stroke-width: 3.2;
  stroke-linecap: round;
  stroke-linejoin: round;
  opacity: 0.38;
}

.point {
  cursor: pointer;
}

.point-stem {
  stroke: rgba(13, 21, 35, 0.22);
  stroke-width: 1.4;
}

.point circle {
  filter: drop-shadow(0 4px 7px rgba(13, 21, 35, 0.18));
}

.point.selected circle {
  filter: drop-shadow(0 0 0 rgba(0, 0, 0, 0));
}

.point-label {
  fill: var(--ink);
  font-size: 13px;
  font-weight: 900;
}

.claim-label {
  fill: #7f4a05;
}

.point-score {
  fill: var(--ink-soft);
  font-size: 12px;
  font-weight: 850;
}

.event-stem {
  stroke: #98a6b6;
  stroke-width: 1;
}

.event-diamond {
  fill: var(--blue);
}

.event-diamond.alert {
  fill: var(--coral);
}

.anomaly-leader {
  fill: none;
  stroke: var(--amber);
  stroke-width: 1.5;
}

.anomaly-box rect {
  fill: #fff8e7;
  stroke: rgba(198, 138, 19, 0.55);
}

.anomaly-title {
  fill: #7d5100;
  font-size: 12px;
  font-weight: 950;
}

.anomaly-text {
  fill: #7d5100;
  font-size: 11px;
  font-weight: 750;
}

.tooltip {
  position: absolute;
  z-index: 5;
  width: min(300px, calc(100% - 20px));
  pointer-events: none;
  border: 1px solid var(--line-strong);
  border-radius: 8px;
  padding: 12px;
  color: var(--ink);
  background: rgba(255, 254, 250, 0.98);
  box-shadow: var(--shadow);
}

.tooltip strong,
.tooltip span {
  display: block;
}

.tooltip span {
  margin-top: 4px;
  color: var(--muted);
  font-size: 0.82rem;
  font-weight: 850;
}

.tooltip p {
  margin: 10px 0 0;
  color: var(--ink-soft);
  font-size: 0.88rem;
  line-height: 1.38;
}

.chart-caption-row {
  justify-content: space-between;
  gap: 14px;
  margin-top: 10px;
  color: var(--muted);
  font-size: 0.8rem;
  font-weight: 750;
}

.side-stack {
  display: grid;
  gap: 12px;
}

.pulse-panel,
.selected-panel,
.watch-panel {
  padding: 12px;
}

.pulse-panel h2,
.selected-panel h2,
.watch-panel h2 {
  font-size: 0.9rem;
  text-transform: uppercase;
}

.pulse-list {
  display: grid;
  gap: 0;
  margin-top: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  overflow: hidden;
}

.pulse-item {
  padding: 10px 12px;
  background: #ffffff;
  border-bottom: 1px solid var(--line);
}

.pulse-item:last-child {
  border-bottom: 0;
}

.pulse-item span,
.focus-title em,
.focus-score span {
  display: block;
  color: var(--muted);
  font-size: 0.76rem;
  font-weight: 850;
  text-transform: uppercase;
}

.pulse-item strong {
  display: block;
  margin-top: 7px;
  font-size: clamp(0.94rem, 1.2vw, 1.08rem);
  line-height: 1.16;
  overflow-wrap: anywhere;
}

.pulse-item.accent {
  background: #f3fbfa;
}

.pulse-item.rumor {
  background: #fff9eb;
}

.focus-card {
  margin-top: 12px;
}

.focus-title {
  display: flex;
  align-items: flex-start;
  gap: 10px;
}

.focus-title > span {
  flex: 0 0 auto;
  width: 12px;
  height: 12px;
  margin-top: 3px;
  border-radius: 999px;
}

.focus-title strong {
  display: block;
  font-size: 1.12rem;
  line-height: 1.12;
}

.focus-title em {
  margin-top: 5px;
  font-style: normal;
}

.focus-score {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 10px;
  align-items: end;
  margin-top: 12px;
  padding-bottom: 10px;
  border-bottom: 1px solid var(--line);
}

.focus-score strong {
  color: var(--coral);
  font-size: clamp(1.85rem, 3.5vw, 2.45rem);
  line-height: 0.9;
  letter-spacing: 0;
}

.focus-card p,
.watch-card p {
  margin: 10px 0 0;
  color: var(--ink-soft);
  font-size: 0.92rem;
  line-height: 1.43;
}

.focus-card p {
  display: -webkit-box;
  overflow: hidden;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 3;
}

.focus-card dl {
  display: grid;
  gap: 6px;
  margin: 10px 0 0;
}

.focus-card dl div {
  display: grid;
  grid-template-columns: 78px 1fr;
  gap: 8px;
  align-items: start;
}

.focus-card dt {
  color: var(--muted);
  font-size: 0.76rem;
  font-weight: 850;
  text-transform: uppercase;
}

.focus-card dd {
  margin: 0;
  color: var(--ink-soft);
  font-size: 0.82rem;
  line-height: 1.28;
  display: -webkit-box;
  overflow: hidden;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 2;
}

.mini-score-row {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 5px;
  margin-top: 10px;
}

.mini-score-row span {
  display: grid;
  gap: 3px;
  min-width: 0;
  padding: 7px 5px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: #ffffff;
}

.mini-score-row span.active {
  border-color: rgba(13, 139, 132, 0.5);
  background: #effafa;
}

.mini-score-row b {
  color: var(--muted);
  font-size: 0.58rem;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.mini-score-row em {
  color: var(--ink);
  font-style: normal;
  font-size: 0.76rem;
  font-weight: 900;
}

.watch-card {
  margin-top: 12px;
  padding: 11px;
  border: 1px solid rgba(198, 138, 19, 0.45);
  border-radius: 8px;
  background: #fff8e7;
}

.watch-card strong {
  display: block;
  color: #7d5100;
  font-size: 0.98rem;
  line-height: 1.2;
}

.watch-card button {
  margin-top: 10px;
  min-height: 32px;
  border: 1px solid rgba(198, 138, 19, 0.56);
  border-radius: 7px;
  padding: 8px 10px;
  background: #ffffff;
  color: #7d5100;
  cursor: pointer;
  font-size: 0.82rem;
  font-weight: 900;
}

.matrix-ledger-grid,
.analysis-grid {
  display: grid;
  gap: 12px;
  margin-top: 12px;
  align-items: start;
}

.matrix-ledger-grid {
  grid-template-columns: minmax(420px, 0.95fr) minmax(0, 1.05fr);
}

.analysis-grid {
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
}

.score-matrix {
  width: 100%;
  overflow-x: auto;
  border: 1px solid var(--line);
  border-radius: 8px;
}

.matrix-row {
  display: grid;
  grid-template-columns: minmax(150px, 1.25fr) repeat(5, minmax(62px, 0.72fr));
  align-items: stretch;
  width: 100%;
  min-width: 620px;
  border: 0;
  border-bottom: 1px solid var(--line);
  padding: 0;
  background: #ffffff;
  text-align: left;
}

button.matrix-row {
  cursor: pointer;
}

.matrix-row:last-child {
  border-bottom: 0;
}

.matrix-row > span {
  display: flex;
  align-items: center;
  min-height: 38px;
  padding: 8px 10px;
  border-right: 1px solid var(--line);
  font-size: 0.84rem;
  font-weight: 760;
}

.matrix-row > span:last-child {
  border-right: 0;
}

.matrix-head {
  color: var(--muted);
  background: #f3f6f8;
}

.matrix-head span {
  font-size: 0.75rem;
  font-weight: 900;
  text-transform: uppercase;
}

.matrix-row.selected,
.matrix-row:hover,
.matrix-row:focus-visible {
  background: #effafa;
}

.matrix-model {
  gap: 8px;
  color: var(--ink);
}

.matrix-model i {
  flex: 0 0 auto;
  width: 10px;
  height: 10px;
  border-radius: 999px;
}

.score-cell {
  position: relative;
  justify-content: flex-end;
  color: var(--ink-soft);
  overflow: hidden;
}

.score-cell::before {
  content: "";
  position: absolute;
  inset: 7px auto 7px 7px;
  width: var(--bar, 0%);
  max-width: calc(100% - 14px);
  border-radius: 5px;
  background: rgba(33, 102, 194, 0.13);
}

.score-cell.active {
  color: var(--ink);
  font-weight: 950;
}

.score-cell.active::before {
  background: rgba(13, 139, 132, 0.2);
}

.score-cell.missing {
  color: var(--muted);
  justify-content: center;
}

.score-cell.missing::before {
  display: none;
}

.event-rail {
  display: grid;
  gap: 0;
  border: 1px solid var(--line);
  border-radius: 8px;
  overflow: hidden;
}

.event-row {
  display: grid;
  grid-template-columns: 110px minmax(148px, 0.68fr) minmax(146px, 0.82fr) minmax(180px, 1.35fr);
  gap: 12px;
  align-items: start;
  padding: 12px;
  border-bottom: 1px solid var(--line);
  background: #ffffff;
}

.event-row:last-child {
  border-bottom: 0;
}

.event-row time {
  color: var(--muted);
  font-size: 0.8rem;
  font-weight: 900;
}

.event-row .event-kind {
  line-height: 1.12;
  white-space: normal;
}

.event-row strong {
  font-size: 0.92rem;
  line-height: 1.2;
}

.event-row p {
  margin: 0;
  color: var(--ink-soft);
  font-size: 0.86rem;
  line-height: 1.35;
}

.event-row.alert {
  background: #fff7f6;
}

.event-row.rumor {
  background: #fff9eb;
}

.gap-list,
.ceiling-list,
.sources-list {
  display: grid;
  gap: 9px;
}

.gap-card,
.ceiling-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 14px;
  padding: 13px;
  border: 1px solid var(--line);
  border-left: 5px solid var(--teal);
  border-radius: 8px;
  background: #ffffff;
  cursor: pointer;
}

.gap-card.negative {
  border-left-color: var(--coral);
}

.gap-card h3 {
  margin: 8px 0 4px;
  font-size: 1rem;
  line-height: 1.12;
  overflow-wrap: anywhere;
}

.gap-card p {
  margin: 0;
  color: var(--muted);
  font-size: 0.9rem;
  line-height: 1.35;
}

.gap-card > strong {
  flex: 0 0 auto;
  font-size: 1.4rem;
}

.gap-card.negative > strong {
  color: var(--coral);
}

.gap-card.positive > strong {
  color: var(--teal);
}

.ceiling-row {
  align-items: flex-start;
}

.ceiling-row.blocked {
  border-color: rgba(228, 78, 63, 0.34);
  border-left-color: var(--coral);
  background: #fff7f6;
}

.ceiling-row strong,
.ceiling-row b,
.ceiling-row span,
.ceiling-row em {
  display: block;
}

.ceiling-row span {
  margin-top: 5px;
  color: var(--muted);
  font-size: 0.9rem;
  line-height: 1.36;
}

.ceiling-row div:last-child {
  min-width: 134px;
  text-align: right;
}

.ceiling-row b {
  font-size: 0.98rem;
}

.ceiling-row em {
  margin-top: 6px;
  color: var(--muted);
  font-size: 0.72rem;
  font-style: normal;
  font-weight: 900;
  text-transform: uppercase;
}

.sources-panel {
  margin-top: 12px;
}

.sources-list {
  grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
}

.source-link {
  display: grid;
  gap: 6px;
  min-height: 104px;
  padding: 13px;
  border: 1px solid var(--line);
  border-radius: 8px;
  color: inherit;
  text-decoration: none;
  background: #ffffff;
}

.source-link:hover,
.source-link:focus-visible {
  border-color: var(--ink);
  background: #f8fbff;
}

.source-link strong {
  line-height: 1.18;
}

.source-link span {
  color: var(--muted);
  font-size: 0.88rem;
  line-height: 1.35;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

@media (max-width: 1120px) {
  .command-bar,
  .metric-rail {
    align-items: flex-start;
    flex-direction: column;
  }

  .command-meta,
  .legend,
  .chart-key {
    justify-content: flex-start;
  }

  .raceboard-grid,
  .matrix-ledger-grid,
  .analysis-grid {
    grid-template-columns: 1fr;
  }

  .side-stack {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }
}

@media (max-width: 820px) {
  main {
    padding: 12px 12px 42px;
  }

  .brand-zone p {
    font-size: 0.82rem;
  }

  .metric-rail > div:first-child {
    align-items: flex-start;
    flex-direction: column;
    width: 100%;
  }

  .metric-strip {
    width: 100%;
  }

  .metric-button {
    flex: 1 1 calc(50% - 6px);
    min-width: 130px;
  }

  .side-stack {
    grid-template-columns: 1fr;
  }

  .panel-heading,
  .chart-caption-row {
    flex-direction: column;
    align-items: flex-start;
  }

  .chart-wrap {
    min-height: 390px;
  }

  #raceChart {
    height: 430px;
  }

  .event-row {
    grid-template-columns: 1fr;
    gap: 8px;
  }

  .event-kind {
    width: fit-content;
  }

  .gap-card,
  .ceiling-row {
    align-items: flex-start;
    flex-direction: column;
  }

  .ceiling-row div:last-child {
    min-width: 0;
    text-align: left;
  }
}

@media (max-width: 520px) {
  .command-bar {
    padding: 12px;
  }

  .brand-zone {
    align-items: flex-start;
  }

  .brand-mark {
    width: 38px;
    height: 38px;
  }

  .brand-zone h1 {
    font-size: 1.22rem;
  }

  .command-meta span {
    max-width: 100%;
    white-space: normal;
    line-height: 1.25;
  }

  .chart-panel,
  .matrix-panel,
  .ledger-panel,
  .analysis-panel,
  .sources-panel,
  .pulse-panel,
  .selected-panel,
  .watch-panel {
    padding: 12px;
  }

  .panel-heading h2,
  .chart-heading h2 {
    font-size: 1.18rem;
  }

  .focus-score {
    grid-template-columns: 1fr;
  }

  .mini-score-row {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .sources-list {
    grid-template-columns: 1fr;
  }
}
