:root {
  color-scheme: light;
  --page: #f9f9f7;
  --surface: #fcfcfb;
  --text-primary: #0b0b0b;
  --text-secondary: #52514e;
  --text-muted: #6f6d68;
  --grid: #e1e0d9;
  --baseline: #c3c2b7;
  --border: rgba(11, 11, 11, 0.1);
  --accent: #b5601c;
  --track: #f0efec;
  --series-1: #2a78d6; /* won / the single series */
  --series-2: #eb6834; /* lost */
  --series-3: #1baf7a; /* unfinished */
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --page: #0d0d0d;
    --surface: #1a1a19;
    --text-primary: #ffffff;
    --text-secondary: #c3c2b7;
    --text-muted: #9a9890;
    --grid: #2c2c2a;
    --baseline: #383835;
    --border: rgba(255, 255, 255, 0.1);
    --accent: #f0913c;
    --track: #242422;
    --series-1: #3987e5;
    --series-2: #d95926;
    --series-3: #199e70;
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --page: #0d0d0d;
  --surface: #1a1a19;
  --text-primary: #ffffff;
  --text-secondary: #c3c2b7;
  --text-muted: #9a9890;
  --grid: #2c2c2a;
  --baseline: #383835;
  --border: rgba(255, 255, 255, 0.1);
  --accent: #f0913c;
  --track: #242422;
  --series-1: #3987e5;
  --series-2: #d95926;
  --series-3: #199e70;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--page);
  color: var(--text-primary);
  font: 14px/1.45 system-ui, -apple-system, "Segoe UI", sans-serif;
}

.top {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  justify-content: space-between;
  gap: 12px 24px;
  max-width: 1180px;
  margin: 0 auto;
  padding: 28px 16px 8px;
}
h1 { margin: 0; font-size: 24px; font-weight: 650; letter-spacing: -0.01em; }
h1::before {
  content: "";
  display: inline-block;
  width: 10px;
  height: 14px;
  margin-right: 10px;
  border-radius: 2px;
  background: var(--accent);
  vertical-align: 1px;
}
h2 { margin: 0 0 10px; font-size: 15px; font-weight: 620; }
.sub, .note { margin: 4px 0 0; color: var(--text-secondary); font-size: 13px; }
.note { margin: -4px 0 12px; }
.toggle { display: flex; align-items: center; gap: 8px; color: var(--text-secondary); font-size: 13px; cursor: pointer; }
.toggle input { accent-color: var(--series-1); width: 16px; height: 16px; }

main { max-width: 1180px; margin: 0 auto; padding: 8px 16px 48px; }

.tiles {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 12px;
  margin: 12px 0 16px;
}
.tile, .card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
}
.tile { padding: 14px 16px; }
.tile .label { color: var(--text-secondary); font-size: 12.5px; }
.tile .value { margin-top: 4px; font-size: 26px; font-weight: 620; }
.tile .detail { margin-top: 2px; color: var(--text-muted); font-size: 12px; }
.tile.hero .value { font-size: 48px; line-height: 1.05; }

.card { padding: 16px 18px 18px; margin-bottom: 16px; min-width: 0; }
.grid2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 440px), 1fr)); gap: 0 16px; }

.empty { color: var(--text-muted); font-size: 13px; padding: 8px 0; }

/* Tables */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 13px; }
th {
  text-align: left;
  font-weight: 560;
  color: var(--text-secondary);
  border-bottom: 1px solid var(--baseline);
  padding: 6px 10px 6px 0;
  white-space: nowrap;
}
td { padding: 7px 10px 7px 0; border-bottom: 1px solid var(--grid); vertical-align: top; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
tr.clickable { cursor: pointer; }
tr.clickable:hover td { background: var(--track); }
.muted { color: var(--text-muted); }
.pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  white-space: nowrap;
}
.pill::before { content: ""; width: 8px; height: 8px; border-radius: 50%; background: var(--dot, var(--baseline)); }
.pill.won { --dot: var(--series-1); }
.pill.lost { --dot: var(--series-2); }
.pill.unfinished, .pill.abandoned, .pill.content-complete { --dot: var(--series-3); }
.tag { font-size: 11px; color: var(--text-muted); border: 1px solid var(--border); border-radius: 4px; padding: 0 4px; margin-left: 6px; }

/* Inline rate meter in tables */
.meter { display: inline-flex; align-items: center; gap: 8px; justify-content: flex-end; }
.meter .track { width: 64px; height: 6px; border-radius: 3px; background: var(--track); overflow: hidden; }
.meter .fill { height: 100%; background: var(--series-2); border-radius: 0 3px 3px 0; }

/* Horizontal bar charts */
.bars { display: grid; grid-template-columns: minmax(70px, max-content) 1fr; gap: 8px 12px; align-items: center; }
.bars .label { font-size: 13px; color: var(--text-secondary); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 220px; }
.bars .row { display: flex; align-items: center; gap: 8px; min-width: 0; }
.bars .bar { display: flex; height: 18px; gap: 2px; min-width: 0; }
.bars .seg { height: 100%; min-width: 3px; }
.bars .seg:last-child { border-radius: 0 4px 4px 0; }
.bars .value { font-size: 12.5px; color: var(--text-primary); font-variant-numeric: tabular-nums; white-space: nowrap; }
.bars .axis { grid-column: 2; border-top: 1px solid var(--baseline); height: 0; }

.legend { display: flex; flex-wrap: wrap; gap: 4px 16px; margin: -2px 0 12px; font-size: 12.5px; color: var(--text-secondary); }
.legend span { display: inline-flex; align-items: center; gap: 6px; }
.legend i { width: 10px; height: 10px; border-radius: 2px; display: inline-block; }

.tooltip {
  position: fixed;
  z-index: 10;
  pointer-events: none;
  background: var(--surface);
  color: var(--text-primary);
  border: 1px solid var(--border);
  box-shadow: 0 6px 24px rgba(0, 0, 0, 0.18);
  border-radius: 8px;
  padding: 8px 10px;
  font-size: 12.5px;
  max-width: 280px;
}
.tooltip strong { display: block; margin-bottom: 2px; }

/* Run dialog */
dialog {
  width: min(860px, calc(100vw - 32px));
  max-height: calc(100vh - 48px);
  padding: 0;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--surface);
  color: var(--text-primary);
}
dialog::backdrop { background: rgba(0, 0, 0, 0.5); }
.dialog-head {
  position: sticky;
  top: 0;
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 14px 18px;
  background: var(--surface);
  border-bottom: 1px solid var(--grid);
}
.dialog-head h2 { margin: 0; }
.close { font-size: 24px; line-height: 1; background: none; border: 0; color: var(--text-secondary); cursor: pointer; padding: 4px 8px; }
#run-body { padding: 12px 18px 20px; }
.facts { display: flex; flex-wrap: wrap; gap: 6px 18px; margin-bottom: 14px; font-size: 13px; color: var(--text-secondary); }
.facts b { color: var(--text-primary); font-weight: 560; }
.timeline { list-style: none; margin: 0; padding: 0; font-size: 13px; }
.timeline li { display: grid; grid-template-columns: 54px 1fr; gap: 10px; padding: 6px 0; border-bottom: 1px solid var(--grid); }
.timeline .when { color: var(--text-muted); font-variant-numeric: tabular-nums; }
.timeline .stage-head { display: block; font-weight: 620; padding-top: 10px; border-bottom: 1px solid var(--baseline); }
.timeline .kind { color: var(--text-muted); margin-right: 6px; }
.timeline .won { color: var(--text-primary); }
.timeline .lost { font-weight: 600; }

@media (max-width: 560px) {
  .tile.hero .value { font-size: 40px; }
  .bars .label { max-width: 120px; }
}
.note.causes { margin: 12px 0 0; }
