:root {
  --bg: #0f1115;
  --panel: #171a21;
  --panel-2: #1e222b;
  --line: #2a2f3a;
  --text: #e7e9ee;
  --muted: #98a0b0;
  --accent: #fc6719;
  --accent-2: #ffb26b;
  --radius: 12px;
}

@media (prefers-color-scheme: light) {
  :root {
    --bg: #f5f6f8;
    --panel: #ffffff;
    --panel-2: #f0f2f5;
    --line: #dcdfe6;
    --text: #1a1d23;
    --muted: #626a78;
  }
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

.sr-only {
  position: absolute;
  width: 1px; height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
}

/* ---------- top bar ---------- */

.topbar {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  align-items: center;
  justify-content: space-between;
  padding: 16px 20px;
  border-bottom: 1px solid var(--line);
  background: var(--panel);
  position: sticky;
  top: 0;
  z-index: 5;
}

.topbar h1 {
  margin: 0;
  font-size: 18px;
  letter-spacing: .2px;
}

.lookup { display: flex; gap: 8px; }

input[type="text"] {
  background: var(--panel-2);
  border: 1px solid var(--line);
  color: var(--text);
  border-radius: 8px;
  padding: 9px 12px;
  min-width: 240px;
  font: inherit;
}

input[type="text"]:focus {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}

button {
  background: var(--accent);
  color: #fff;
  border: 0;
  border-radius: 8px;
  padding: 9px 16px;
  font: inherit;
  font-weight: 600;
  cursor: pointer;
}

button:hover { filter: brightness(1.08); }
button:disabled { opacity: .55; cursor: default; filter: none; }

button.ghost {
  background: transparent;
  color: var(--muted);
  border: 1px solid var(--line);
}

/* ---------- layout ---------- */

main {
  max-width: 900px;
  margin: 0 auto;
  padding: 20px;
  display: grid;
  gap: 16px;
}

.card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 18px;
  /* Grid items size to their content by default; without this a wide table
     stretches the card and the whole page scrolls sideways instead of the
     table scrolling inside it. */
  min-width: 0;
}

.card h2 { margin: 0 0 4px; font-size: 16px; }

.muted { color: var(--muted); }
.small { font-size: 13px; }

.status {
  margin: 0;
  padding: 12px 16px;
  border-radius: var(--radius);
  background: var(--panel-2);
  border: 1px solid var(--line);
}

.status.error {
  border-color: #b4402f;
  color: #ff9a86;
}

/* ---------- event card ---------- */

.event { display: flex; gap: 16px; align-items: flex-start; }
.event__img { width: 180px; border-radius: 8px; flex: none; }
.event__body { flex: 1; min-width: 0; }
.event h2 { font-size: 20px; }

.meta {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
  gap: 10px 18px;
  margin: 14px 0 0;
}

.meta > div { min-width: 0; }
.meta dt { font-size: 11px; text-transform: uppercase; letter-spacing: .6px; color: var(--muted); }
.meta dd { margin: 2px 0 0; font-weight: 600; overflow-wrap: anywhere; }

.desc { margin-top: 14px; }
.desc summary { cursor: pointer; color: var(--muted); font-size: 13px; }
.desc p { white-space: pre-wrap; font-size: 13px; color: var(--muted); }

/* ---------- subgroups ---------- */

.sg-list {
  list-style: none;
  margin: 14px 0 0;
  padding: 0;
  display: grid;
  gap: 10px;
}

.sg {
  width: 100%;
  display: flex;
  align-items: center;
  gap: 14px;
  text-align: left;
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 12px 14px;
  color: var(--text);
  font: inherit;
  cursor: pointer;
}

.sg:hover { border-color: var(--accent-2); }

.sg[aria-pressed="true"] {
  border-color: var(--accent);
  box-shadow: inset 3px 0 0 var(--accent);
}

.sg__label {
  flex: none;
  width: 40px; height: 40px;
  display: grid;
  place-items: center;
  border-radius: 8px;
  background: var(--accent);
  color: #fff;
  font-weight: 700;
  font-size: 17px;
}

.sg__main { flex: 1; min-width: 0; }
.sg__name { font-weight: 600; }
.sg__facts { color: var(--muted); font-size: 13px; }
.sg__id { flex: none; color: var(--muted); font-size: 12px; font-variant-numeric: tabular-nums; }

.selection .actions { display: flex; gap: 8px; margin-top: 14px; }

.foot {
  max-width: 900px;
  margin: 0 auto;
  padding: 8px 20px 32px;
  color: var(--muted);
  font-size: 12px;
}

@media (max-width: 620px) {
  .event { flex-direction: column; }
  .event__img { width: 100%; }
  input[type="text"] { min-width: 0; flex: 1; }
  .lookup { width: 100%; }
}

/* ---------- rows / fields ---------- */

.row { display: flex; gap: 12px; align-items: flex-end; flex-wrap: wrap; }
.row.between { justify-content: space-between; align-items: center; }
.actions { display: flex; gap: 8px; }

.field { display: flex; flex-direction: column; gap: 4px; }
.field.grow { flex: 1; min-width: 180px; }
.field > span { font-size: 12px; color: var(--muted); }

input[type="search"], select {
  background: var(--panel-2);
  border: 1px solid var(--line);
  color: var(--text);
  border-radius: 8px;
  padding: 9px 12px;
  font: inherit;
  width: 100%;
}

input[type="search"]:focus, select:focus {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}

code {
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: 4px;
  padding: 1px 5px;
  font-size: .9em;
}

/* ---------- entrants ---------- */

.filters { margin-top: 14px; }
.filters select { width: auto; }

.status.inline { margin-top: 12px; padding: 9px 12px; font-size: 13px; }

.tableWrap {
  margin-top: 14px;
  max-width: 100%;
  overflow-x: auto;
  border: 1px solid var(--line);
  border-radius: 10px;
}

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

thead th {
  position: sticky;
  top: 0;
  background: var(--panel-2);
  border-bottom: 1px solid var(--line);
  padding: 0;
  text-align: left;
  white-space: nowrap;
}

thead th.num, tbody td.num { text-align: right; }
thead th.num .sortBtn { justify-content: flex-end; width: 100%; }

.sortBtn {
  background: none;
  color: var(--muted);
  font-size: 11px;
  font-weight: 700;
  letter-spacing: .5px;
  text-transform: uppercase;
  padding: 10px 12px;
  display: flex;
  align-items: center;
  gap: 5px;
  width: 100%;
}

.sortBtn:hover { color: var(--text); filter: none; }
.sortBtn[data-dir]::after { content: '\25B2'; font-size: 8px; color: var(--accent); }
.sortBtn[data-dir="desc"]::after { content: '\25BC'; }

tbody td {
  padding: 9px 12px;
  border-bottom: 1px solid var(--line);
  white-space: nowrap;
}

tbody tr:last-child td { border-bottom: 0; }
tbody tr:hover td { background: var(--panel-2); }
tbody td.num { font-feature-settings: "tnum"; }

#rawFields p {
  font-family: ui-monospace, Menlo, Consolas, monospace;
  font-size: 12px;
  overflow-wrap: anywhere;
}


/* ---------- compact view ----------
   Rider plus the whole power curve. Nine columns is wider than a phone, so the
   rider name is pinned to the left and the numbers scroll under it - the name
   stays readable however far right you are in the curve. */

.table--compact {
  font-size: 13px;
  width: auto;
  min-width: 100%;
}

.table--compact .sortBtn {
  font-size: 11px;
  padding: 10px 6px;
  letter-spacing: 0;
}

.table--compact tbody td {
  padding: 10px 6px;
  white-space: nowrap;
}

/* Rider name: pinned, narrow, and the only cell allowed to wrap. */
.table--compact th:nth-child(2),
.table--compact td:nth-child(2) {
  position: sticky;
  left: 0;
  z-index: 2;
  background: var(--panel);
  white-space: normal;
  overflow-wrap: anywhere;
  min-width: 104px;
  max-width: 132px;
  border-right: 1px solid var(--line);
}

.table--compact thead th:nth-child(2) {
  z-index: 3;
  background: var(--panel-2);
}

.table--compact tbody tr:hover td:nth-child(2) { background: var(--panel-2); }

/* CP W/kg is the headline the view is built around. */
.table--compact td:nth-child(3) {
  font-weight: 700;
  font-size: 15px;
}

@media (max-width: 620px) {
  main { padding: 12px; }
  .card { padding: 14px; }
  .actions { flex-wrap: wrap; }
  .actions button { flex: 1; min-width: 96px; }

  /* Touch targets: a sort header has to be hittable without aiming. */
  .sortBtn { min-height: 44px; padding: 10px 8px; }

  /* Row numbers cost width the curve needs, and the order is already visible. */
  .table--compact th:first-child,
  .table--compact td:first-child { display: none; }

  .table--compact .sortBtn { min-height: 40px; }
}
