:root {
  color-scheme: light;
  --page: #f9f9f7;
  --surface: #fcfcfb;
  --surface-2: #f0efec;
  --ink: #0b0b0b;
  --ink-2: #52514e;
  --muted: #898781;
  --grid: #e1e0d9;
  --axis: #c3c2b7;
  --border: rgba(11, 11, 11, 0.1);
  --s1: #2a78d6;
  --s2: #eb6834;
  --s3: #1baf7a;
  --s4: #eda100;
  --s5: #e87ba4;
  --s6: #008300;
  --s7: #4a3aa7;
  --s8: #e34948;
  --heat: 42, 120, 214;
  --heat-ink-flip: 0.82;
  --good: #0ca30c;
  --good-text: #006300;
  --warning: #fab219;
  --serious: #ec835a;
  --critical: #d03b3b;
  --critical-text: #b42f2f;
  --accent: #2a78d6;
  --font: system-ui, -apple-system, "Segoe UI", sans-serif;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --page: #0d0d0d;
    --surface: #1a1a19;
    --surface-2: #242423;
    --ink: #ffffff;
    --ink-2: #c3c2b7;
    --muted: #898781;
    --grid: #2c2c2a;
    --axis: #383835;
    --border: rgba(255, 255, 255, 0.1);
    --s1: #3987e5;
    --s2: #d95926;
    --s3: #199e70;
    --s4: #c98500;
    --s5: #d55181;
    --s6: #008300;
    --s7: #9085e9;
    --s8: #e66767;
    --heat: 57, 135, 229;
    --heat-ink-flip: 2;
    --good-text: #0ca30c;
    --critical-text: #e66767;
    --accent: #3987e5;
  }
}

:root[data-theme="dark"] {
  color-scheme: dark;
  --page: #0d0d0d;
  --surface: #1a1a19;
  --surface-2: #242423;
  --ink: #ffffff;
  --ink-2: #c3c2b7;
  --muted: #898781;
  --grid: #2c2c2a;
  --axis: #383835;
  --border: rgba(255, 255, 255, 0.1);
  --s1: #3987e5;
  --s2: #d95926;
  --s3: #199e70;
  --s4: #c98500;
  --s5: #d55181;
  --s6: #008300;
  --s7: #9085e9;
  --s8: #e66767;
  --heat: 57, 135, 229;
  --heat-ink-flip: 2;
  --good-text: #0ca30c;
  --critical-text: #e66767;
  --accent: #3987e5;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: var(--page);
  color: var(--ink);
  font: 14px/1.45 var(--font);
}

header {
  position: sticky;
  top: 0;
  z-index: 5;
  background: var(--page);
  border-bottom: 1px solid var(--grid);
  padding: 10px 16px 0;
}

header h1 {
  margin: 0 0 6px;
  font-size: 15px;
  font-weight: 600;
}

header h1 .sub {
  color: var(--ink-2);
  font-weight: 400;
}

nav {
  display: flex;
  gap: 2px;
  overflow-x: auto;
  scrollbar-width: none;
}

nav button {
  min-height: 44px;
  padding: 0 14px;
  border: 0;
  border-bottom: 2px solid transparent;
  background: none;
  color: var(--ink-2);
  font: inherit;
  font-weight: 500;
  cursor: pointer;
  white-space: nowrap;
}

nav button[aria-selected="true"] {
  color: var(--ink);
  border-bottom-color: var(--accent);
}

main {
  max-width: 1280px;
  margin: 0 auto;
  padding: 16px;
}

.grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
  align-items: start;
}

.grid > .wide {
  grid-column: 1 / -1;
}

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 14px 16px;
  min-width: 0;
}

.card h2 {
  margin: 0 0 10px;
  font-size: 14px;
  font-weight: 600;
}

.card h3 {
  margin: 14px 0 6px;
  font-size: 13px;
  font-weight: 600;
  color: var(--ink-2);
}

.note {
  color: var(--ink-2);
  font-size: 12.5px;
  margin: 6px 0 0;
}

.muted {
  color: var(--muted);
}

.banner {
  border-left: 3px solid var(--warning);
  background: var(--surface);
  padding: 10px 14px;
  margin-bottom: 16px;
  border-radius: 6px;
}

.kpis {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 12px;
  margin-bottom: 16px;
}

.kpi {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 10px 14px;
}

.kpi .label {
  color: var(--ink-2);
  font-size: 12px;
}

.kpi .value {
  font-size: 24px;
  font-weight: 600;
  line-height: 1.2;
}

.kpi .detail {
  color: var(--muted);
  font-size: 12px;
}

.moves {
  list-style: none;
  margin: 0;
  padding: 0;
}

.moves li {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  gap: 8px;
  align-items: center;
  padding: 8px 0;
  border-bottom: 1px solid var(--grid);
}

.moves .arrow {
  color: var(--muted);
}

button.link {
  border: 0;
  padding: 2px 0;
  background: none;
  color: inherit;
  font: inherit;
  text-align: inherit;
  cursor: pointer;
  text-decoration: underline dotted var(--muted);
  text-underline-offset: 3px;
}

button.link:hover,
button.link:focus-visible {
  text-decoration-color: currentColor;
}

ul.why {
  margin: 0 0 10px;
  padding-left: 18px;
}

ul.why li {
  margin: 3px 0;
}

.out-name {
  color: var(--critical-text);
}

.in-name {
  color: var(--good-text);
}

.facts {
  display: flex;
  flex-wrap: wrap;
  gap: 6px 16px;
  margin-top: 10px;
}

.facts b {
  font-weight: 600;
}

.pitch {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.pitch .line {
  display: flex;
  justify-content: center;
  gap: 8px;
  flex-wrap: wrap;
}

.pitch .line-label {
  display: none;
}

.pitch .bench {
  border-top: 1px dashed var(--axis);
  padding-top: 10px;
}

.token {
  min-width: 88px;
  max-width: 120px;
  text-align: center;
  background: var(--surface-2);
  border-radius: 8px;
  padding: 6px 6px 5px;
  position: relative;
}

.token .n {
  font-weight: 600;
  font-size: 12.5px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.token .o {
  color: var(--ink-2);
  font-size: 11.5px;
}

.token .x {
  font-size: 13px;
  font-variant-numeric: tabular-nums;
}

.badge {
  display: inline-block;
  min-width: 18px;
  padding: 0 4px;
  border-radius: 9px;
  background: var(--ink);
  color: var(--surface);
  font-size: 11px;
  font-weight: 700;
  line-height: 18px;
  text-align: center;
}

.token .badge {
  position: absolute;
  top: -7px;
  right: -5px;
}

.warn {
  color: var(--serious);
  font-weight: 700;
}

table {
  width: 100%;
  border-collapse: collapse;
  font-variant-numeric: tabular-nums;
}

th,
td {
  padding: 6px 8px;
  text-align: right;
  border-bottom: 1px solid var(--grid);
  vertical-align: middle;
}

th {
  color: var(--ink-2);
  font-weight: 500;
  font-size: 12px;
  white-space: nowrap;
}

th:first-child,
td:first-child,
td.l,
th.l {
  text-align: left;
}

tr.first td {
  font-weight: 600;
}

tr.click {
  cursor: pointer;
}

tr.click:hover td,
tr.selected td {
  background: var(--surface-2);
}

.scroll {
  overflow-x: auto;
}

th button.sort {
  border: 0;
  background: none;
  color: inherit;
  font: inherit;
  cursor: pointer;
  padding: 8px 2px;
  min-height: 36px;
}

th button.sort[aria-sort] {
  color: var(--ink);
  font-weight: 600;
}

.heat td.cell {
  text-align: center;
  min-width: 64px;
  padding: 4px;
  line-height: 1.2;
}

.heat td.cell .v {
  font-weight: 600;
  font-size: 13px;
}

.heat td.cell .s {
  font-size: 11px;
  opacity: 0.85;
}

.heat td.blank {
  background: repeating-linear-gradient(45deg, var(--surface-2), var(--surface-2) 4px, var(--surface) 4px, var(--surface) 8px);
  color: var(--muted);
}

.legend-scale {
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--ink-2);
  font-size: 12px;
  margin-top: 8px;
}

.legend-scale .bar {
  width: 120px;
  height: 10px;
  border-radius: 5px;
  background: linear-gradient(90deg, rgba(var(--heat), 0.05), rgba(var(--heat), 0.2) 35%, rgba(var(--heat), 0.9));
}

.calendar {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(52px, 1fr));
  gap: 4px;
}

.calendar .gw {
  border: 1px solid var(--grid);
  border-radius: 6px;
  padding: 4px;
  text-align: center;
  min-height: 52px;
  font-size: 12px;
}

.calendar .gw .num {
  color: var(--muted);
}

.calendar .gw.chip {
  border-color: var(--accent);
  background: rgba(var(--heat), 0.12);
}

.calendar .gw.special {
  box-shadow: inset 0 -3px 0 var(--s2);
}

.calendar .gw.now {
  outline: 2px solid var(--ink);
  outline-offset: -2px;
}

.chips-key {
  display: flex;
  flex-wrap: wrap;
  gap: 4px 14px;
  color: var(--ink-2);
  font-size: 12px;
  margin-top: 8px;
}

.list {
  list-style: none;
  margin: 0;
  padding: 0;
}

.list li {
  padding: 6px 0;
  border-bottom: 1px solid var(--grid);
  display: flex;
  justify-content: space-between;
  gap: 10px;
}

.list li .r {
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.up {
  color: var(--good-text);
}

.down {
  color: var(--critical-text);
}

.controls {
  display: flex;
  flex-wrap: wrap;
  gap: 8px 12px;
  align-items: end;
  margin-bottom: 12px;
}

.controls label {
  display: flex;
  flex-direction: column;
  gap: 2px;
  color: var(--ink-2);
  font-size: 12px;
}

input,
select,
button.btn {
  min-height: 44px;
  padding: 6px 10px;
  border: 1px solid var(--axis);
  border-radius: 8px;
  background: var(--surface);
  color: var(--ink);
  font: inherit;
}

input[type="checkbox"] {
  min-height: 0;
  width: 18px;
  height: 18px;
  margin: 0;
  accent-color: var(--accent);
}

label.tick {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 44px;
  min-height: 44px;
  cursor: pointer;
}

.segmented {
  display: inline-flex;
  border: 1px solid var(--axis);
  border-radius: 8px;
  overflow: hidden;
}

.segmented button {
  min-height: 44px;
  padding: 0 12px;
  border: 0;
  background: var(--surface);
  color: var(--ink-2);
  font: inherit;
  cursor: pointer;
}

.segmented button[aria-pressed="true"] {
  background: var(--accent);
  color: #ffffff;
}

.value-board {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 16px;
}

.chart {
  width: 100%;
  height: 260px;
}

.chart.tall {
  height: 340px;
}

.chart.small {
  height: 200px;
}

.pair {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

.compare {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
  gap: 12px;
}

.swatch {
  display: inline-block;
  width: 10px;
  height: 10px;
  border-radius: 3px;
  margin-right: 6px;
  vertical-align: baseline;
}

details.table-view {
  margin-top: 6px;
}

details.table-view summary {
  color: var(--ink-2);
  font-size: 12px;
  cursor: pointer;
  min-height: 32px;
  display: flex;
  align-items: center;
}

.hero {
  font-size: 28px;
  font-weight: 600;
}

.empty {
  color: var(--ink-2);
  margin: 4px 0;
}

[hidden] {
  display: none !important;
}

@media (max-width: 760px) {
  main {
    padding: 12px 16px;
  }

  .grid,
  .pair,
  .value-board {
    grid-template-columns: 1fr;
  }

  .kpis {
    grid-template-columns: repeat(2, 1fr);
  }

  .kpis .kpi:last-child {
    grid-column: 1 / -1;
  }

  .pitch .line {
    flex-direction: column;
    gap: 0;
  }

  .pitch .line-label {
    display: block;
    color: var(--ink-2);
    font-size: 12px;
    font-weight: 600;
    margin-top: 4px;
  }

  .token {
    max-width: none;
    min-height: 44px;
    display: grid;
    grid-template-columns: 1fr auto 52px 22px;
    gap: 8px;
    align-items: center;
    text-align: left;
    background: none;
    border-bottom: 1px solid var(--grid);
    border-radius: 0;
    padding: 6px 0;
  }

  .token .badge {
    position: static;
    grid-column: 4;
    grid-row: 1;
  }

  .token .x {
    text-align: right;
  }

  .pitch .bench {
    border-top: 0;
    padding-top: 0;
  }

  td,
  th {
    padding: 8px 6px;
  }

  tr.click td {
    height: 44px;
  }
}
