:root {
  --ink: #182822;
  --ink-soft: #3d5248;
  --muted: #54665c;
  --bg: #f5f3eb;
  --surface: #fffefa;
  --line: #dedfd4;
  --line-strong: #cfd3c6;
  --header: #142f25;
  --header-text: #faf8eb;
  --accent: #1e4c39;
  --accent-strong: #163c2d;
  --accent-soft: #e9efe5;
  --gold: #e2c482;
  --gold-text: #efda9e;
  --danger: #9c2a20;
  --shadow: none;
  --sans: system-ui, sans-serif;
  --serif: Georgia, "Times New Roman", serif;
  --type-label: 0.6875rem;
  --type-body: 0.8125rem;
  --type-title: 0.9375rem;
  --type-page: 1.125rem;
  --page-gutter: clamp(32px, 7vw, 128px);
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  min-height: 100%;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--sans);
  font-size: 14px;
  font-variant-numeric: tabular-nums;
  line-height: 1.45;
  color-scheme: light;
}

h1,
h2,
p {
  margin: 0;
}

h1 {
  font-family: var(--serif);
  font-weight: 500;
  font-size: clamp(32px, 4.6vw, 46px);
  letter-spacing: -0.045em;
  line-height: 1.05;
}

h2 {
  font-family: var(--serif);
  font-weight: 500;
  font-size: 25px;
  letter-spacing: 0;
  line-height: 1.1;
}

button,
input,
select {
  font: inherit;
  color: inherit;
}

a {
  color: inherit;
}

.hidden,
[hidden] {
  display: none !important;
}

.site-header {
  position: sticky;
  top: 0;
  z-index: 20;
  background: var(--header);
  color: var(--header-text);
}

.site-header-inner,
.page {
  width: auto;
  max-width: none;
  margin: 0;
  padding-left: var(--page-gutter);
  padding-right: var(--page-gutter);
}

.site-header-inner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-height: 46px;
  gap: 20px;
}

.site-nav {
  display: flex;
  align-items: center;
  gap: 2px;
}

.site-nav a {
  color: rgba(250, 248, 235, 0.72);
  text-decoration: none;
  font-size: 13px;
  font-weight: 650;
  letter-spacing: 0;
  padding: 6px 10px;
  border-radius: 999px;
}

.site-nav a:hover {
  color: var(--header-text);
}

.site-nav a[aria-current="page"] {
  color: var(--gold-text);
  background: transparent;
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  color: inherit;
  text-decoration: none;
}

.brand-mark {
  color: var(--gold);
  font-size: 14px;
  line-height: 1;
}

.brand-name {
  font-size: 14px;
  font-weight: 650;
  letter-spacing: 0;
}

.header-action {
  color: var(--header);
  background: var(--header-text);
  text-decoration: none;
  font-size: 0.92rem;
  font-weight: 600;
  padding: 10px 14px;
  border-radius: 999px;
}

.header-action:hover {
  background: white;
}

.page {
  padding-top: clamp(12px, 3vw, 28px);
  padding-bottom: 28px;
}

.kicker {
  margin-bottom: 8px;
  color: var(--muted);
  font-size: var(--type-label);
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

.file-label {
  margin-bottom: 4px;
  color: var(--muted);
  font-size: var(--type-body);
  font-weight: 500;
}

.lede,
.muted,
.summary,
.detail-caption,
.empty-card {
  color: var(--muted);
}

.lede {
  max-width: 38rem;
  margin-top: 8px;
  font-size: var(--type-body);
  font-weight: 500;
  line-height: 1.45;
}

.hero {
  display: grid;
  grid-template-columns: minmax(0, 1.15fr) minmax(280px, 0.85fr);
  gap: 40px;
  align-items: center;
  margin-bottom: 42px;
}

.upload-card,
.panel,
.recent,
.glossary article,
.view-column,
.view-row {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 9px;
  box-shadow: none;
}

.upload-card {
  padding: 18px;
}

.dropzone {
  position: relative;
  display: grid;
  justify-items: center;
  gap: 4px;
  padding: 36px 18px 28px;
  border: 1px dashed rgba(30, 76, 57, 0.35);
  border-radius: 16px;
  background: linear-gradient(180deg, #f7faf4, var(--surface));
  cursor: pointer;
  text-align: center;
}

.dropzone input {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
}

.dropzone-icon {
  display: grid;
  place-items: center;
  width: 48px;
  height: 48px;
  margin-bottom: 8px;
  border-radius: 14px;
  background: var(--accent-soft);
  color: var(--accent-strong);
}

.dropzone-title {
  font-weight: 600;
  font-size: var(--type-title);
}

.dropzone-hint,
.dropzone-file {
  color: var(--muted);
  font-size: var(--type-body);
  font-weight: 500;
}

.dropzone.is-dragover {
  border-color: var(--accent);
  background: var(--accent-soft);
}

.upload-actions {
  display: grid;
  gap: 10px;
  margin-top: 14px;
}

.button-primary {
  border: 1px solid var(--accent);
  border-radius: 6px;
  background: var(--accent);
  color: var(--surface);
  padding: 13px 16px;
  font-size: 14px;
  font-weight: 650;
  cursor: pointer;
}

.button-primary:hover {
  background: var(--accent-strong);
}

.button-primary:disabled {
  opacity: 0.65;
  cursor: progress;
}

.status {
  font-size: var(--type-body);
  font-weight: 500;
}

.status.error {
  color: var(--danger);
}

.recent {
  padding: 22px;
}

.section-head,
.panel-head {
  display: grid;
  gap: 1px;
  margin-bottom: 4px;
}

.run-list {
  display: grid;
}

.run-row {
  display: grid;
  grid-template-columns: 1.4fr 1fr auto;
  gap: 16px;
  align-items: center;
  padding: 14px 4px;
  border-top: 1px solid var(--line);
  text-decoration: none;
}

.run-row:hover .run-name {
  color: var(--accent-strong);
}

.run-name {
  font-weight: 600;
}

.status-pill {
  justify-self: end;
  padding: 4px 10px;
  border-radius: 999px;
  background: #efece2;
  color: var(--ink-soft);
  font-size: var(--type-label);
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: capitalize;
}

.status-completed {
  background: var(--accent-soft);
  color: var(--accent-strong);
}

.status-failed {
  background: #fdecea;
  color: var(--danger);
}

.empty-card {
  padding: 8px 0 2px;
}

.page-intro {
  margin: 8px 0 14px;
}

.page-intro h1 {
  font-size: clamp(35px, 6vw, 58px);
}

.page-intro .lede {
  margin-top: 6px;
}

.glossary {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
  gap: 10px;
  margin-bottom: 24px;
}

.glossary article {
  padding: 14px 16px;
}

.glossary p {
  margin-top: 6px;
  color: var(--ink-soft);
  font-size: var(--type-body);
  font-weight: 500;
  line-height: 1.45;
}

.tt-hero {
  padding-bottom: 17px;
  border-bottom: 1px solid var(--line);
}

.tt-kicker {
  margin: 0 0 5px;
  font-size: 11px;
  font-weight: 750;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--accent);
}

.tt-kicker span,
.tt-race-meta b {
  margin: 0 4px;
  color: var(--muted);
  font-weight: 400;
}

.tt-hero h1 {
  margin: 5px 0 9px;
  font-size: clamp(35px, 6vw, 58px);
}

.tt-race-meta {
  display: flex;
  align-items: baseline;
  flex-wrap: wrap;
  column-gap: 20px;
  row-gap: 5px;
}

.tt-race-meta p,
.tt-setup-heading p,
.tt-scale,
.tt-section span {
  margin: 0;
  color: var(--muted);
}

.tt-conditions {
  color: var(--accent);
}

.tt-conditions strong {
  font-weight: 650;
}

.tt-eligibility {
  flex: 1 0 100%;
  margin-top: 4px;
}

.tt-conditions-toggle {
  min-height: 0;
  padding: 0;
  border: 0;
  background: transparent;
  color: var(--accent);
  font-size: 11px;
  font-weight: 750;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  cursor: pointer;
}

.tt-conditions-toggle:hover {
  color: var(--accent-strong);
}

.tt-race-meta .tt-eligibility-copy {
  max-width: 78ch;
  margin-top: 6px;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.45;
}

.tt-setup {
  margin: 12px 0;
  padding: 12px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 9px;
}

.tt-setup-heading {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.tt-setup-heading p {
  font-size: 12px;
  margin-top: 3px;
}

.tt-setup-heading button,
.tt-extra button {
  min-height: 36px;
  border: 1px solid var(--accent);
  border-radius: 6px;
  padding: 6px 12px;
  background: var(--accent);
  color: var(--surface);
  font-weight: 650;
  cursor: pointer;
}

.tt-setup-heading button {
  margin-left: auto;
}

.tt-setup-heading button:hover,
.tt-extra button:hover {
  background: var(--accent-strong);
}

.tt-parameters {
  display: grid;
  gap: 7px 10px;
  border: 0;
  padding: 0;
  margin: 10px 0 0;
  min-width: 0;
}

.tt-parameters legend {
  padding: 0;
  margin-bottom: 4px;
  color: var(--accent);
  font-size: 14px;
  font-weight: 750;
}

.tt-parameters label,
.tt-extra label,
.custom-distance label {
  display: grid;
  gap: 3px;
  align-content: start;
  min-width: 0;
  color: var(--muted);
  font-size: 11px;
  font-weight: 700;
}

.tt-ranking {
  grid-template-columns: repeat(3, minmax(0, 1fr));
  max-width: 570px;
}

.tt-matching {
  grid-template-columns: repeat(7, minmax(0, 1fr));
}

.tt-parameters select,
.tt-parameters input,
.tt-extra input,
.custom-distance input {
  width: 100%;
  min-width: 0;
  min-height: 36px;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 6px 9px;
  background: var(--surface);
  color: var(--ink);
  font-size: 13px;
  font-weight: 500;
}

.tt-parameters select:focus,
.tt-parameters input:focus,
.tt-extra input:focus,
.custom-distance input:focus {
  outline: 2px solid rgba(30, 76, 57, 0.28);
  border-color: var(--accent);
}

.tt-parameters input::placeholder,
.tt-extra input::placeholder,
.custom-distance input::placeholder {
  color: #8b978f;
}

.tt-class-hint,
.custom-distance {
  grid-column: 1 / -1;
}

.tt-class-hint {
  color: var(--muted);
  font-size: 11px;
  font-weight: 400;
}

.custom-distance {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 180px));
  gap: 7px 10px;
}

.tt-extra {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: end;
  margin: 12px 0;
}

.tt-extra label {
  min-width: min(100%, 280px);
}

.tt-field {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 9px;
  min-width: 0;
}

.tt-section {
  display: flex;
  align-items: baseline;
  gap: 7px 12px;
  flex-wrap: wrap;
  justify-content: space-between;
  padding: 13px 12px;
}

.tt-section span,
.tt-scale {
  font-size: 11px;
}

.tt-scale {
  margin: -5px 12px 11px;
}

#chart {
  min-width: 0;
}

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

#chart th,
#chart td {
  text-align: right;
  padding: 6px 8px;
  border-top: 1px solid var(--line);
  vertical-align: middle;
}

#chart th:first-child,
#chart td:first-child {
  text-align: left;
  padding-left: 16px;
}

#chart th:last-child,
#chart td.tt-run {
  width: 5.25rem;
  padding-left: 16px;
  padding-right: 20px;
}

#chart th {
  font-size: 11px;
  font-weight: 700;
  color: var(--muted);
  white-space: nowrap;
}

#chart .tt-rank-row td {
  padding-block: 10px;
}

#chart .tt-score {
  width: 32%;
  padding-right: 20px;
}

.tt-rank-row {
  cursor: pointer;
}

.tt-rank-row:hover td,
.tt-rank-row.is-open td {
  background: var(--accent-soft);
}

.tt-horse {
  display: flex;
  gap: 7px;
  align-items: center;
  width: 100%;
  min-height: 0;
  padding: 0;
  border: 0;
  border-radius: 0;
  background: transparent;
  color: var(--ink);
  font-weight: 700;
  text-align: left;
  cursor: pointer;
}

#chart .tt-connection {
  text-align: left;
  color: var(--muted);
  font-weight: 500;
}

.tt-connection-summary {
  display: none;
}

.tt-score-cell {
  display: grid;
  grid-template-columns: minmax(72px, 1fr) minmax(4ch, max-content);
  gap: 8px;
  align-items: center;
}

.tt-score-track {
  display: block;
  height: 8px;
  border-radius: 99px;
  background: #e4e9df;
  overflow: hidden;
}

.tt-score-fill {
  display: block;
  height: 100%;
  border-radius: inherit;
  background: var(--accent);
}

.tt-value {
  font-weight: 750;
  color: var(--accent);
}

.tt-run,
.tt-empty {
  color: var(--muted);
  font-weight: 500;
}

.program {
  display: grid;
  place-items: center;
  flex: 0 0 24px;
  width: 24px;
  height: 24px;
  border-radius: 5px;
  border: 1px solid rgba(24, 40, 34, 0.15);
  background: var(--ink);
  color: white;
  font-size: 12px;
  font-weight: 750;
  letter-spacing: 0;
}

.tt-detail-row td {
  padding: 4px 12px 14px;
  background: var(--accent-soft);
  text-align: left;
}

.horse-detail {
  display: grid;
  gap: 10px;
}

.horse-detail .kicker {
  margin-bottom: 0;
  color: var(--accent);
  letter-spacing: 0.12em;
  font-weight: 750;
}

.detail-caption {
  margin-bottom: 14px;
}

.detail-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 14px;
}

.chip {
  padding: 5px 9px;
  border-radius: 999px;
  background: #efece2;
  color: var(--ink-soft);
  font-size: var(--type-body);
  font-weight: 500;
}

.chip-program {
  border: 1px solid rgba(16, 19, 26, 0.2);
  min-width: 28px;
  text-align: center;
  font-weight: 600;
}

.saddle-1 { background: #d3121a; color: #fff; }
.saddle-2 { background: #f4f4f4; color: #161616; }
.saddle-3 { background: #1f4db8; color: #fff; }
.saddle-4 { background: #f2d000; color: #161616; }
.saddle-5 { background: #1f8a3b; color: #fff; }
.saddle-6 { background: #161616; color: #f2c200; }
.saddle-7 { background: #f26a1b; color: #161616; }
.saddle-8 { background: #f48cbf; color: #161616; }
.saddle-9 { background: #2bb8c9; color: #161616; }
.saddle-10 { background: #6b2d91; color: #fff; }
.saddle-11 { background: #8e939a; color: #c4161c; }
.saddle-12 { background: #c6e018; color: #161616; }
.saddle-13 { background: #6b4423; color: #fff; }
.saddle-14 { background: #7a1e33; color: #f2d000; }
.saddle-15 { background: #c2b48a; color: #161616; }
.saddle-16 { background: #6eadd6; color: #c4161c; }
.saddle-17 { background: #102a56; color: #fff; }
.saddle-18 { background: #1d5c38; color: #f2d000; }
.saddle-19 { background: #243f8f; color: #e23b3b; }
.saddle-20 { background: #d63a9d; color: #f2d000; }

.pp-list {
  display: grid;
  gap: 8px;
}

.pp-card {
  padding: 12px 12px 10px;
  border: 1px solid var(--line);
  border-radius: 9px;
  background: var(--surface);
}

.pp-card.is-used {
  background: #f7faf4;
  border-color: rgba(30, 76, 57, 0.22);
}

.pp-where {
  font-size: var(--type-body);
  font-weight: 600;
  letter-spacing: -0.01em;
}

.pp-context {
  margin-top: 2px;
  color: var(--ink-soft);
  font-size: var(--type-body);
  font-weight: 500;
}

.pp-stats {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  margin-top: 8px;
  font-variant-numeric: tabular-nums;
}

.pp-stats strong {
  font-size: var(--type-title);
  font-weight: 600;
  letter-spacing: -0.02em;
}

.pp-stats span {
  color: var(--muted);
  font-size: var(--type-body);
  font-weight: 500;
}

.pp-calls {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 8px;
  margin-top: 8px;
}

.pp-call {
  display: grid;
  gap: 1px;
}

.pp-call span {
  color: var(--muted);
  font-size: var(--type-label);
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

.pp-call strong,
.pp-call em {
  font-style: normal;
  font-size: var(--type-body);
  font-variant-numeric: tabular-nums;
}

.pp-call strong {
  font-weight: 600;
}

.pp-call em {
  color: var(--ink-soft);
  font-weight: 500;
}

.empty-copy {
  margin: 0;
  color: var(--muted);
}

.save-view {
  display: flex;
  align-items: end;
  gap: 8px;
  margin: 0 0 12px;
}

.save-view label {
  display: grid;
  gap: 3px;
  flex: 1;
  max-width: 420px;
}

.save-view span {
  color: var(--muted);
  font-size: var(--type-label);
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

.save-view input,
.button-secondary,
.button-quiet {
  min-height: 32px;
  border-radius: 8px;
  font: inherit;
  font-size: var(--type-body);
  font-weight: 500;
}

.save-view input {
  border: 1px solid var(--line);
  padding: 0 10px;
  background: white;
  color: var(--ink);
}

.button-secondary,
.button-quiet {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0 12px;
  text-decoration: none;
  cursor: pointer;
}

.button-secondary {
  border: 1px solid var(--line-strong);
  background: var(--surface);
  color: var(--ink);
}

.button-quiet {
  border: 0;
  background: transparent;
  color: var(--muted);
}

.view-workspace {
  margin-bottom: 28px;
}

.board-head {
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 12px;
}

.view-library-head {
  margin-top: 22px;
}

.view-board {
  display: grid;
  gap: 12px;
}

.view-board[data-count="1"] {
  grid-template-columns: minmax(0, 1fr);
}

.view-board[data-count="2"] {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.view-board[data-count="3"] {
  grid-template-columns: repeat(3, minmax(0, 1fr));
}

.view-column,
.view-row {
  border: 1px solid var(--line);
  border-radius: 9px;
  background: var(--surface);
}

.view-column {
  min-width: 0;
  padding: 12px;
}

.view-column-head h3,
.view-row h3 {
  margin: 0;
  font-size: var(--type-body);
  font-weight: 600;
}

.view-column-head p,
.view-row p {
  margin: 4px 0 0;
  font-size: var(--type-label);
  line-height: 1.4;
}

.view-column-actions,
.view-row-actions {
  display: flex;
  gap: 8px;
  margin-top: 8px;
}

.view-column-actions a,
.view-column-actions button {
  border: 0;
  background: transparent;
  color: var(--ink);
  font: inherit;
  font-size: var(--type-label);
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  cursor: pointer;
  padding: 0;
  text-decoration: none;
}

.mini-field {
  display: grid;
  margin-top: 10px;
}

.mini-row {
  display: grid;
  grid-template-columns: 22px minmax(0, 1fr) minmax(36px, 0.7fr) 3.2ch;
  gap: 6px;
  align-items: center;
  padding: 4px 0;
  border-top: 1px solid var(--line);
}

.mini-row .program {
  width: 22px;
  height: 22px;
  font-size: 0.68rem;
}

.mini-name {
  overflow: hidden;
  font-size: var(--type-body);
  font-weight: 600;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.mini-bar {
  display: block;
  height: 6px;
  border-radius: 99px;
  background: var(--line);
  overflow: hidden;
}

.mini-bar span {
  display: block;
  height: 100%;
  border-radius: inherit;
  background: var(--accent);
}

@media (max-width: 950px) {
  .tt-matching {
    grid-template-columns: repeat(4, minmax(0, 1fr));
  }
}

@media (max-width: 680px) {
  #chart .tt-connection {
    display: none;
  }

  .tt-connection-summary {
    display: block;
    margin: 3px 0 0 31px;
    color: var(--muted);
    font-size: 11px;
    font-weight: 500;
    line-height: 1.35;
  }

  .tt-setup-heading button {
    margin-left: 0;
  }
}

@media (max-width: 540px) {
  .tt-ranking,
  .tt-matching {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .tt-score-cell {
    grid-template-columns: 1fr;
    gap: 3px;
  }

  .tt-score-track {
    grid-row: 2;
    height: 6px;
  }

  #chart .tt-score {
    width: 30%;
  }
}

@media (pointer: coarse) {
  .tt-parameters select,
  .tt-parameters input,
  .tt-extra input,
  .tt-extra button,
  .tt-setup-heading button {
    min-height: 44px;
  }
}

.mini-row strong {
  font-size: var(--type-body);
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  text-align: right;
}

.view-library {
  display: grid;
  gap: 8px;
}

.view-row {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: center;
  padding: 12px;
}

.view-row > div:first-child {
  min-width: 0;
}

@media (max-width: 720px) {
  .hero,
  .run-row,
  .section-head {
    grid-template-columns: 1fr;
  }

  .status-pill {
    justify-self: start;
    justify-items: start;
  }

  .site-header-inner {
    flex-wrap: wrap;
    padding-top: 8px;
    padding-bottom: 8px;
  }

  .site-nav {
    width: 100%;
  }

  .view-board[data-count="2"],
  .view-board[data-count="3"],
  .view-row,
  .save-view {
    grid-template-columns: 1fr;
  }

  .view-row,
  .save-view,
  .board-head {
    display: grid;
  }
}
