:root {
  color-scheme: light;
  --bg: #f4f6f2;
  --ink: #18201b;
  --muted: #627066;
  --line: #d7ded6;
  --panel: #ffffff;
  --accent: #216b4f;
  --accent-2: #a35f22;
  --loss: #b63e35;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  line-height: 1.45;
}

.topbar {
  display: flex;
  justify-content: space-between;
  gap: 24px;
  align-items: end;
  padding: 24px 28px 18px;
  border-bottom: 1px solid var(--line);
  background: #fbfcfa;
  position: sticky;
  top: 0;
  z-index: 5;
}

.eyebrow {
  margin: 0 0 4px;
  color: var(--accent);
  font-size: 12px;
  font-weight: 700;
  letter-spacing: .08em;
  text-transform: uppercase;
}

h1, h2 { margin: 0; letter-spacing: 0; }
h1 { font-size: clamp(24px, 3vw, 38px); }
h2 { font-size: 16px; }

.notice {
  max-width: 360px;
  color: var(--muted);
  font-size: 14px;
  text-align: right;
}

main {
  width: min(1580px, 100%);
  margin: 0 auto;
  padding: 18px 20px 40px;
}

.scenario-tabs {
  display: grid;
  grid-template-columns: repeat(6, minmax(150px, 1fr));
  gap: 8px;
  margin-bottom: 14px;
}

.scenario-tab {
  border: 1px solid var(--line);
  background: #ffffff;
  border-radius: 8px;
  padding: 10px;
  color: var(--ink);
  cursor: pointer;
  text-align: left;
  transition: border-color .16s ease, transform .16s ease, background-color .16s ease;
}

.scenario-tab:hover {
  border-color: #9fb4a8;
  transform: translateY(-1px);
}

.scenario-tab.active {
  border-color: var(--accent);
  background: #edf5ef;
}

.scenario-tab span {
  display: block;
  color: var(--muted);
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
}

.scenario-tab strong {
  display: block;
  margin: 4px 0 8px;
  font-size: 15px;
}

.scenario-tab em {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  color: var(--muted);
  font-style: normal;
  font-size: 12px;
}

.summary-grid {
  display: grid;
  grid-template-columns: repeat(6, minmax(140px, 1fr));
  gap: 10px;
  margin-bottom: 16px;
}

.metric {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 14px;
  min-height: 92px;
}

.metric span {
  display: block;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
}

.metric strong {
  display: block;
  margin-top: 8px;
  font-size: 24px;
}

.filters {
  display: grid;
  grid-template-columns: repeat(6, minmax(130px, 1fr));
  gap: 10px;
  margin-bottom: 16px;
}

label {
  display: grid;
  gap: 4px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
}

input, select {
  width: 100%;
  border: 1px solid var(--line);
  background: #fff;
  border-radius: 6px;
  padding: 9px 10px;
  color: var(--ink);
  font: inherit;
  min-height: 38px;
}

.chart-grid {
  display: grid;
  grid-template-columns: repeat(6, minmax(0, 1fr));
  gap: 12px;
  margin-bottom: 18px;
}

.panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 14px;
  min-height: 310px;
}

.panel:nth-child(1), .panel:nth-child(2), .panel:nth-child(3) { grid-column: span 2; }
.panel:nth-child(4), .panel:nth-child(5) { grid-column: span 3; }

canvas {
  width: 100% !important;
  max-height: 250px;
}

.table-section {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  margin-bottom: 14px;
  overflow: hidden;
}

.section-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 12px 14px;
  border-bottom: 1px solid var(--line);
}

.section-head a {
  color: var(--accent);
  font-size: 13px;
  font-weight: 700;
}

.table-wrap {
  overflow-x: auto;
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}

th, td {
  padding: 9px 10px;
  border-bottom: 1px solid var(--line);
  text-align: left;
  white-space: nowrap;
}

th {
  color: var(--muted);
  font-size: 11px;
  text-transform: uppercase;
  background: #f9faf8;
}

tr[data-race-id] { cursor: pointer; }
tr[data-race-id]:hover { background: #eef5ef; }

.pos { color: var(--accent); font-weight: 700; }
.neg { color: var(--loss); font-weight: 700; }

dialog {
  width: min(1100px, calc(100vw - 24px));
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0;
}

dialog::backdrop { background: rgba(24, 32, 27, .42); }

.close {
  float: right;
  margin: 12px;
  border: 1px solid var(--line);
  background: #fff;
  border-radius: 6px;
  padding: 8px 10px;
  cursor: pointer;
}

#raceDetail { padding: 18px; clear: both; }
.detail-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.detail-block { border-top: 1px solid var(--line); padding-top: 12px; }
pre { white-space: pre-wrap; overflow-wrap: anywhere; background: #f7f8f6; padding: 10px; border-radius: 6px; }

@media (max-width: 1100px) {
  .scenario-tabs { grid-template-columns: repeat(3, 1fr); }
  .summary-grid { grid-template-columns: repeat(3, 1fr); }
  .filters { grid-template-columns: repeat(3, 1fr); }
  .panel:nth-child(n) { grid-column: span 6; }
}

@media (max-width: 680px) {
  .topbar { align-items: start; flex-direction: column; }
  .notice { text-align: left; }
  main { padding: 14px 10px 28px; }
  .scenario-tabs { grid-template-columns: 1fr 1fr; }
  .summary-grid, .filters { grid-template-columns: 1fr 1fr; }
  .metric strong { font-size: 20px; }
  .detail-grid { grid-template-columns: 1fr; }
}
