:root {
  --bg: #faf9fc;
  --surface: #ffffff;
  --surface-2: #f3f0fa;
  --border: #e6e1f0;
  --border-strong: #d4cce6;
  --accent: #5b4cd6;
  --accent-soft: #ede9ff;
  --accent-fade: #f7f5ff;
  --text: #1a1730;
  --text-2: #525070;
  --text-3: #8b88a8;
  --warn: #c4452a;
  --good: #1f7a4a;
  --radius: 10px;
  --radius-sm: 6px;
  --shadow: 0 1px 2px rgba(20,15,50,0.04), 0 4px 12px rgba(20,15,50,0.04);
}
* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  padding: 28px 20px 60px;
}
.container { max-width: 1080px; margin: 0 auto; }

.hero { margin-bottom: 28px; }
.back-home {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-size: 13px;
  color: var(--text-2);
  text-decoration: none;
  padding: 6px 10px;
  border-radius: var(--radius-sm);
  margin: 0 0 12px -10px;
  transition: background 0.15s, color 0.15s;
}
.back-home:hover { background: var(--accent-soft); color: var(--accent); }
.hero h1 {
  font-weight: 700;
  font-size: 30px;
  letter-spacing: -0.02em;
  margin: 0;
  color: var(--text);
}
.hero h1 em { font-style: normal; color: var(--accent); }
.hero p {
  color: var(--text-2);
  margin: 6px 0 0;
  font-size: 15px;
  max-width: 680px;
}
.unit-system {
  margin-top: 14px;
  display: inline-flex;
  align-items: center;
  gap: 10px;
}
.unit-system-label {
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--text-3);
}

/* Cards */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  margin-bottom: 14px;
  box-shadow: var(--shadow);
  position: relative;
}
.card.race-actual { border-top: 3px solid var(--text-3); }
.card.race-hypothetical { border-top: 3px solid var(--accent); }
.card-head {
  padding: 14px 18px 0;
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 12px;
}
.card-title {
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--text-3);
}
.card-title-large {
  font-size: 18px;
  text-transform: none;
  letter-spacing: -0.01em;
  color: var(--text);
  font-weight: 600;
}
.card-title-large em {
  font-style: normal;
  color: var(--accent);
}
.card-meta {
  font-size: 12px;
  color: var(--text-3);
  font-variant-numeric: tabular-nums;
}
.card-meta.invalid { color: var(--warn); }
.card-body { padding: 14px 18px 18px; }
.card-intro {
  font-size: 13px;
  color: var(--text-2);
  margin: 4px 0 0;
  max-width: 680px;
}

/* Tooltips */
.info {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 15px;
  height: 15px;
  border-radius: 50%;
  background: var(--surface-2);
  color: var(--text-3);
  font-size: 10px;
  font-weight: 600;
  cursor: help;
  margin-left: 4px;
  border: 1px solid var(--border);
  position: relative;
  vertical-align: middle;
  user-select: none;
}
.info:hover { background: var(--accent-soft); color: var(--accent); border-color: var(--accent); }
.info::after {
  content: attr(data-tip);
  position: fixed;
  background: var(--text);
  color: white;
  padding: 8px 12px;
  border-radius: 6px;
  font-size: 12px;
  font-weight: 400;
  line-height: 1.4;
  width: max-content;
  max-width: min(260px, calc(100vw - 20px));
  text-align: left;
  letter-spacing: 0;
  text-transform: none;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.15s;
  z-index: 9999;
  box-shadow: 0 4px 16px rgba(0,0,0,0.15);
  left: var(--tt-x, 0);
  top: var(--tt-y, 0);
  transform: translateY(-100%);
}
.info:hover::after { opacity: 1; }

/* Inputs */
input[type="text"], input[type="number"], select {
  padding: 8px 10px;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  font-size: 14px;
  font-family: inherit;
  background: var(--surface);
  color: var(--text);
  transition: border-color 0.15s, box-shadow 0.15s;
}
input[type="text"]:focus, input[type="number"]:focus, select:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}
input.invalid {
  border-color: var(--warn);
  background: #fdf3f1;
}
input::-webkit-outer-spin-button,
input::-webkit-inner-spin-button { -webkit-appearance: none; margin: 0; }
input[type="number"] { -moz-appearance: textfield; appearance: textfield; }
select {
  cursor: pointer;
  background: var(--surface-2);
  padding-right: 26px;
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='10' height='6' viewBox='0 0 10 6'><path d='M1 1l4 4 4-4' stroke='%23525070' stroke-width='1.5' fill='none' stroke-linecap='round'/></svg>");
  background-repeat: no-repeat;
  background-position: right 8px center;
  -webkit-appearance: none;
  appearance: none;
}

/* Sliders */
input[type="range"] {
  -webkit-appearance: none;
  appearance: none;
  width: 100%;
  height: 6px;
  background: var(--surface-2);
  border-radius: 3px;
  outline: none;
  border: 1px solid var(--border);
  cursor: pointer;
  transition: background 0.15s;
}
input[type="range"]:hover { background: var(--accent-fade); }
input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: var(--surface);
  border: 2px solid var(--accent);
  cursor: grab;
  box-shadow: 0 2px 6px rgba(91, 76, 214, 0.25);
  transition: transform 0.1s, box-shadow 0.15s;
}
input[type="range"]::-webkit-slider-thumb:hover { transform: scale(1.1); }
input[type="range"]::-webkit-slider-thumb:active {
  cursor: grabbing;
  background: var(--accent);
  box-shadow: 0 0 0 6px var(--accent-soft);
}
input[type="range"]::-moz-range-thumb {
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: var(--surface);
  border: 2px solid var(--accent);
  cursor: grab;
  box-shadow: 0 2px 6px rgba(91, 76, 214, 0.25);
}

/* Field rows */
.field {
  display: grid;
  grid-template-columns: 160px 1fr 220px;
  gap: 14px;
  align-items: center;
  margin: 10px 0;
}
.field-label {
  font-size: 13px;
  color: var(--text-2);
  font-weight: 500;
  display: flex;
  align-items: center;
  gap: 8px;
}
.field-label input[type="checkbox"] {
  appearance: none;
  -webkit-appearance: none;
  width: 16px;
  height: 16px;
  border: 1.5px solid var(--border-strong);
  border-radius: 3px;
  cursor: pointer;
  flex-shrink: 0;
  position: relative;
  background: var(--surface);
  transition: background 0.15s, border-color 0.15s;
}
.field-label input[type="checkbox"]:checked {
  background: var(--accent);
  border-color: var(--accent);
}
.field-label input[type="checkbox"]:checked::after {
  content: "";
  position: absolute;
  left: 4px;
  top: 1px;
  width: 4px;
  height: 8px;
  border: solid white;
  border-width: 0 2px 2px 0;
  transform: rotate(45deg);
}
.field-label input[type="checkbox"]:hover { border-color: var(--accent); }
.field.disabled .field-input { opacity: 0.4; pointer-events: none; }
.field.disabled input[type="range"] { opacity: 0.4; pointer-events: none; }
.field.disabled .field-label { color: var(--text-3); }
.field-input {
  display: flex;
  gap: 6px;
  align-items: center;
  justify-content: flex-end;
}
.field-input input[type="text"],
.field-input input[type="number"] {
  width: 110px;
  text-align: right;
  font-size: 13px;
  font-variant-numeric: tabular-nums;
}
.field-input select {
  min-width: 68px;
  font-size: 13px;
  padding: 7px 26px 7px 10px;
}
@media (max-width: 720px) {
  .field { grid-template-columns: 1fr; gap: 6px; }
  .field-input { justify-content: flex-start; }
}

/* Section subhead within cards */
.subhead {
  font-size: 11px;
  font-weight: 600;
  color: var(--text-3);
  text-transform: uppercase;
  letter-spacing: 0.1em;
  margin: 16px 0 4px;
  padding-top: 12px;
  border-top: 1px solid var(--border);
}
.subhead:first-child {
  margin-top: 0;
  padding-top: 0;
  border-top: 0;
}
.subhead-toggle {
  display: flex;
  align-items: center;
  gap: 8px;
}
.subhead-toggle input[type="checkbox"] {
  appearance: none;
  -webkit-appearance: none;
  width: 16px;
  height: 16px;
  border: 1.5px solid var(--border-strong);
  border-radius: 3px;
  cursor: pointer;
  flex-shrink: 0;
  position: relative;
  background: var(--surface);
  transition: background 0.15s, border-color 0.15s;
}
.subhead-toggle input[type="checkbox"]:checked {
  background: var(--accent);
  border-color: var(--accent);
}
.subhead-toggle input[type="checkbox"]:checked::after {
  content: "";
  position: absolute;
  left: 4px;
  top: 1px;
  width: 4px;
  height: 8px;
  border: solid white;
  border-width: 0 2px 2px 0;
  transform: rotate(45deg);
}
.subhead-toggle input[type="checkbox"]:hover { border-color: var(--accent); }

/* Treadmill toggle for course type */
.toggle {
  display: inline-flex;
  background: var(--surface-2);
  border-radius: var(--radius-sm);
  padding: 3px;
  border: 1px solid var(--border);
}
.toggle button {
  border: 0;
  background: transparent;
  padding: 6px 14px;
  cursor: pointer;
  font-size: 13px;
  font-family: inherit;
  color: var(--text-2);
  border-radius: 4px;
  transition: background 0.15s, color 0.15s;
  font-weight: 500;
}
.toggle button:hover:not(.active):not(:disabled) { color: var(--text); }
.toggle button.active {
  background: var(--surface);
  color: var(--accent);
  box-shadow: 0 1px 3px rgba(0,0,0,0.08);
}
.toggle button:disabled { color: var(--text-3); cursor: not-allowed; opacity: 0.5; }

/* Results grid */
.results {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 1px;
  background: var(--border);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  overflow: hidden;
  margin-top: 14px;
}
.stat {
  background: var(--surface);
  padding: 10px 12px;
}
.stat .label {
  font-size: 10px;
  color: var(--text-3);
  text-transform: uppercase;
  letter-spacing: 0.08em;
  font-weight: 600;
  margin-bottom: 3px;
  display: flex;
  align-items: center;
}
.stat .value {
  font-size: 17px;
  font-weight: 600;
  color: var(--text);
  font-variant-numeric: tabular-nums;
}
.stat.featured { background: var(--accent-fade); }
.stat.featured .value { color: var(--accent); }
@media (max-width: 720px) {
  .results { grid-template-columns: repeat(2, 1fr); }
}

/* Tables */
table {
  width: 100%;
  border-collapse: collapse;
  margin-top: 6px;
}
th, td {
  padding: 9px 12px;
  text-align: left;
  border-bottom: 1px solid var(--border);
  font-size: 13px;
}
th {
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-3);
  font-weight: 600;
  border-bottom: 1px solid var(--border-strong);
}
th.num, td.num { text-align: right; font-variant-numeric: tabular-nums; }
tbody tr:last-child td { border-bottom: none; }
.table-scroll {
  overflow-x: auto;
  margin: 0 -18px;
  padding: 0 18px;
  -webkit-overflow-scrolling: touch;
}
.train-table { min-width: 480px; }
.train-table th, .train-table td { white-space: nowrap; }

/* Delta display */
.delta-pos { color: var(--warn); }
.delta-neg { color: var(--good); }
.delta-zero { color: var(--text-3); }

/* Two-column layout for actual/hypothetical race side-by-side on wide screens */
.race-pair {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 14px;
}
@media (max-width: 980px) {
  .race-pair { grid-template-columns: 1fr; }
}

/* "Same as actual" link */
.copy-link {
  font-size: 11px;
  color: var(--accent);
  cursor: pointer;
  margin-left: 8px;
  text-decoration: underline;
  text-underline-offset: 2px;
}
.copy-link:hover { color: var(--text); }

footer {
  text-align: center;
  color: var(--text-3);
  font-size: 12px;
  margin-top: 30px;
}
footer a { color: var(--accent); text-decoration: none; }
footer a:hover { text-decoration: underline; }

/* Sensitivity chart */
.chart-container {
  width: 100%;
  position: relative;
}
.chart-container svg {
  width: 100%;
  display: block;
}
.chart-legend {
  display: flex;
  flex-wrap: wrap;
  gap: 12px 18px;
  margin-bottom: 12px;
  font-size: 12px;
}
.legend-item {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  color: var(--text-2);
}
.legend-swatch {
  width: 14px;
  height: 3px;
  border-radius: 2px;
}
.legend-marker {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  flex-shrink: 0;
}
.legend-marker-filled {
  background: var(--text-2);
}
.legend-marker-hollow {
  background: white;
  border: 2px solid var(--text-2);
}
.legend-markers {
  white-space: nowrap;
}
.legend-marker-pair {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}
.legend-marker-pair + .legend-marker-pair {
  margin-left: 14px;
}
.legend-item .label-text { color: var(--text); font-weight: 500; }
.legend-item .label-value { color: var(--text-3); font-variant-numeric: tabular-nums; }
#sensChart .axis { stroke: var(--border-strong); stroke-width: 1; }
#sensChart .grid { stroke: var(--border); stroke-width: 1; stroke-dasharray: 2 3; }
#sensChart .axis-label { font-size: 10px; fill: var(--text-3); font-family: inherit; }
#sensChart .tick-label { font-size: 10px; fill: var(--text-3); font-family: inherit; }
#sensChart .actual-marker { fill: var(--text-2); }
#sensChart .actual-line { stroke: var(--text-3); stroke-width: 1; stroke-dasharray: 3 3; }
#sensChart .series-line { fill: none; stroke-width: 2; }
#sensChart .series-dot { stroke: white; stroke-width: 2; }
#sensChart .hover-line { stroke: var(--text-3); stroke-width: 1; stroke-dasharray: 3 3; }
.sens-tooltip {
  position: absolute;
  background: var(--text);
  color: white;
  padding: 6px 10px;
  border-radius: 6px;
  font-size: 12px;
  line-height: 1.4;
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.1s;
  z-index: 9998;
  box-shadow: 0 4px 16px rgba(0,0,0,0.18);
  white-space: nowrap;
}
.sens-tooltip.visible { opacity: 1; }
.sens-tooltip .tip-color {
  display: inline-block;
  width: 10px;
  height: 10px;
  border-radius: 2px;
  margin-right: 6px;
  vertical-align: middle;
}
.sens-tooltip .tip-label { color: white; font-weight: 600; }
.sens-tooltip .tip-value { color: #c9c5e0; }
