/* Race-entry page (mobile-first): tap boats in the order they finish.
 *
 * Component tokens derive from the shared OKLCH palette
 * (harmonized-palette.css) and the site tokens in styles.css. Dark mode swaps
 * only the token values. Deliberately parallel to attendance.css — the two
 * pages are used back to back on the same phone at the dock, so the header,
 * save bar and field labels are styled to match. */

/* The site stylesheet has no global box-sizing reset. */
.racing-page,
.racing-page *,
.racing-page *::before,
.racing-page *::after {
  box-sizing: border-box;
}

.racing-page {
  --race-card-bg: white;
  --race-line: oklch(87% 0.02 250deg);
  --race-muted: oklch(50% 0.02 250deg);
  --race-accent: var(--azure-20);
  --race-chip-bg: var(--azure-90);
  --race-chip-ink: var(--azure-10);
  --race-good-bg: oklch(93% 0.045 145deg);
  --race-good-ink: var(--green-10);
  --race-warn-bg: var(--amber-90);
  --race-warn-ink: var(--amber-10);
  --race-danger-ink: var(--red-20);

  /* Match the site-wide content width, as attendance.css does; width:100%
   * overrides the base `article { width: fit-content }` so the page doesn't
   * shrink-wrap and leave gutters on a phone. */
  width: 100%;
  max-width: 35em;
  margin: 0 auto;
  padding-inline: 0.6rem;
}

@media (prefers-color-scheme: dark) {
  .racing-page {
    --race-card-bg: oklch(24% 0.02 250deg);
    --race-line: oklch(35% 0.02 250deg);
    --race-muted: oklch(80% 0.02 250deg);
    --race-chip-bg: oklch(30% 0.06 250deg);
    --race-chip-ink: var(--azure-80);
    --race-good-bg: oklch(30% 0.08 145deg);
    --race-good-ink: var(--green-80);
    --race-warn-bg: oklch(32% 0.07 75deg);
    --race-warn-ink: var(--amber-80);
    --race-danger-ink: var(--red-80);
  }
}

/* ---------- meeting header ---------- */

.racing-page .meeting-header {
  position: sticky;
  top: 0;
  z-index: 10;
  background: var(--background-color);
  padding: 0.5rem 0;
  border-bottom: 1px solid var(--race-line);
  margin-bottom: 1rem;
}

.racing-page .meeting-header h2 {
  font-size: 1.15rem;
  line-height: 1.3;
  margin: 0;
  text-wrap: balance;
}

.racing-page .meeting-subline {
  font-size: 0.85rem;
  color: var(--race-muted);
  margin-top: 0.15rem;
  font-variant-numeric: tabular-nums;
}

.racing-page .save-bar {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  margin-top: 0.5rem;
  font-size: 0.8rem;
  color: var(--race-muted);
}

.racing-page .save-dot {
  width: 0.5rem;
  height: 0.5rem;
  border-radius: 50%;
  background: var(--green-20);
  flex: none;
  transition: background 0.2s;
}

.racing-page .save-bar.saving .save-dot {
  background: var(--amber-20);
}

.racing-page .save-bar.save-error .save-dot {
  background: var(--red-20);
}

/* ---------- boats today ---------- */

.racing-page .field-label {
  font-size: 0.8rem;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--race-muted);
  margin-bottom: 0.3rem;
}

.racing-page .boats-today {
  margin-bottom: 1.2rem;
}

.racing-page .boat-crews {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
}

.racing-page .boat-crew {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  padding: 0.25rem 0.5rem 0.25rem 0.25rem;
  border: 1px solid var(--race-line);
  border-radius: 999px;
  background: var(--race-card-bg);
  font-size: 0.85rem;
}

.racing-page .boat-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 1.5rem;
  height: 1.5rem;
  border-radius: 50%;
  background: var(--race-chip-bg);
  color: var(--race-chip-ink);
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}

.racing-page .boats-hint,
.racing-page .boats-empty {
  font-size: 0.8rem;
  color: var(--race-muted);
  margin-top: 0.4rem;
}

.racing-page .boats-warning {
  font-size: 0.8rem;
  margin-top: 0.4rem;
  padding: 0.35rem 0.5rem;
  border-radius: 0.4rem;
  background: var(--race-warn-bg);
  color: var(--race-warn-ink);
}

/* ---------- race cards ---------- */

.racing-page .race-list {
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.racing-page .race-card {
  border: 1px solid var(--race-line);
  border-radius: 0.6rem;
  background: var(--race-card-bg);
  padding: 0.6rem;
}

.racing-page .race-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  margin-bottom: 0.5rem;
}

.racing-page .race-head h2 {
  font-size: 1rem;
  margin: 0;
}

.racing-page .race-notice {
  font-size: 0.8rem;
  padding: 0.35rem 0.5rem;
  margin-bottom: 0.5rem;
  border-radius: 0.4rem;
  background: var(--race-warn-bg);
  color: var(--race-warn-ink);
}

/* ---------- finish order ---------- */

.racing-page .finish-order {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
}

.racing-page .finish-row {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.35rem 0.4rem;
  border-radius: 0.4rem;
  background: var(--race-good-bg);
  color: var(--race-good-ink);
}

.racing-page .finish-row .place {
  flex: none;
  min-width: 2.5rem;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}

/* Two boats reading "1st" with the next reading "3rd" looks like a mis-tap
 * unless the tie is said out loud. */
.racing-page .finish-row .tie-flag {
  flex: none;
  padding: 0.05rem 0.35rem;
  border-radius: 999px;
  border: 1px solid currentColor;
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  opacity: 0.8;
}

.racing-page .finish-row .boat-label {
  flex: none;
  font-weight: 600;
}

.racing-page .finish-row .crew {
  flex: 1 1 auto;
  font-size: 0.85rem;
  min-width: 0;
  overflow-wrap: anywhere;
}

.racing-page .finish-row .crew-missing {
  font-style: italic;
  opacity: 0.8;
}

/* A boat scored with nobody aboard still counts toward the fleet size, so it
 * changes everyone's percentage — worth looking different. */
.racing-page .finish-row.no-crew {
  background: var(--race-warn-bg);
  color: var(--race-warn-ink);
}

.racing-page .unset-boat {
  flex: none;
  /* 44px: a comfortable touch target on a moving dock. */
  min-width: 2.75rem;
  min-height: 2.75rem;
  border: none;
  border-radius: 0.4rem;
  background: transparent;
  color: inherit;
  font-size: 1rem;
  cursor: pointer;
  opacity: 0.7;
}

.racing-page .unset-boat:hover,
.racing-page .unset-boat:focus-visible {
  opacity: 1;
  background: color-mix(in oklch, currentColor 12%, transparent);
}

/* ---------- boats still racing ---------- */

.racing-page .pending {
  margin-top: 0.6rem;
  padding-top: 0.6rem;
  border-top: 1px dashed var(--race-line);
}

.racing-page .pending-label,
.racing-page .race-empty,
.racing-page .race-complete {
  font-size: 0.8rem;
  color: var(--race-muted);
  margin-bottom: 0.4rem;
}

.racing-page .race-complete {
  margin-bottom: 0;
  color: var(--race-good-ink);
}

.racing-page .boat-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
}

.racing-page .boat-chip {
  min-width: 3.25rem;
  min-height: 3.25rem;
  border: 2px solid var(--race-accent);
  border-radius: 0.6rem;
  background: var(--race-card-bg);
  color: var(--text-color);
  font-size: 1.25rem;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  cursor: pointer;
}

.racing-page .boat-chip:active {
  background: var(--race-chip-bg);
}

/* ---------- arming a code ---------- */

.racing-page .code-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.4rem;
  margin-top: 0.6rem;
}

.racing-page .code-label {
  font-size: 0.8rem;
  color: var(--race-muted);
}

.racing-page .code-btn {
  min-height: 2.25rem;
  padding-inline: 0.6rem;
  border: 1px solid var(--race-line);
  border-radius: 999px;
  background: var(--race-card-bg);
  color: var(--race-muted);
  font: inherit;
  font-size: 0.85rem;
  cursor: pointer;
}

.racing-page .code-btn.armed {
  border-color: var(--race-accent);
  background: var(--race-chip-bg);
  color: var(--race-chip-ink);
  font-weight: 700;
}

/* ---------- adding and removing races ---------- */

.racing-page .add-race-row {
  margin: 1rem 0 2rem;
}

.racing-page .add-race {
  width: 100%;
  min-height: 2.75rem;
  border: 1px dashed var(--race-accent);
  border-radius: 0.6rem;
  background: transparent;
  color: var(--race-accent);
  font: inherit;
  font-weight: 600;
  cursor: pointer;
}

.racing-page .race-remove {
  display: flex;
  align-items: center;
  gap: 0.35rem;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.racing-page .remove-prompt {
  font-size: 0.8rem;
  color: var(--race-muted);
}

.racing-page .remove-race,
.racing-page .remove-cancel {
  min-height: 2.25rem;
  padding-inline: 0.6rem;
  border: 1px solid var(--race-line);
  border-radius: 0.4rem;
  background: transparent;
  color: var(--race-muted);
  font: inherit;
  font-size: 0.8rem;
  cursor: pointer;
}

.racing-page .remove-yes {
  min-height: 2.25rem;
  padding-inline: 0.6rem;
  border: 1px solid currentColor;
  border-radius: 0.4rem;
  background: transparent;
  color: var(--race-danger-ink);
  font: inherit;
  font-size: 0.8rem;
  font-weight: 700;
  cursor: pointer;
}

/* ---------- the day's results ---------- */

/* The second scoring model on the entry page, so it is set apart from the
 * cards above it rather than reading as more of the same. */
.racing-page .day-results:not(:empty) {
  margin-top: 2rem;
  padding-top: 1.25rem;
  border-top: 1px solid var(--race-line);
}

.racing-page .day-results-note {
  color: var(--race-muted);
  font-size: 0.8rem;
  margin-bottom: 0.75rem;
}

/* Why a race the instructor can see above is missing from the table. */
.racing-page .day-results-pending,
/* What a reader sees when nothing has been scored yet. */
.racing-page .day-results-empty {
  margin-top: 0.6rem;
  color: var(--race-muted);
  font-size: 0.8rem;
}

.racing-page .day-results-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.9rem;
}

.racing-page .day-results-table th,
.racing-page .day-results-table td {
  padding: 0.35rem 0.4rem;
  text-align: left;
  border-bottom: 1px solid var(--race-line);
}

.racing-page .day-results-table th {
  font-size: 0.7rem;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--race-muted);
}

/* Re-assert the numeric alignment: the rule above is one element selector more
 * specific than .racing-page .col-num, so without this every number in the
 * table drifts left. Same trap as .sailor-days below. */
.racing-page .day-results-table .col-num {
  text-align: right;
  /* "DNF 5" is one cell, not two lines. */
  white-space: nowrap;
}

/* The crew column takes up the slack, so the rank and boat stay together on
 * the left and the races and total stay together on the right. */
.racing-page .day-results-table th:nth-child(3),
.racing-page .day-results-table td:nth-child(3) {
  width: 99%;
}

/* One race per column, so this is the table on the page that can outgrow a
 * phone. Scroll it rather than the whole page. */
.racing-page .day-results {
  overflow-x: auto;
}

/* ---------- standings ---------- */

/* Wider than the entry page: this one is read at a desk, and the day
 * breakdown needs the room. */
.racing-page.standings-page {
  max-width: 48em;
}

.racing-page .standings-summary {
  color: var(--race-muted);
  font-size: 0.85rem;
  margin-bottom: 1rem;
}

.racing-page .standings-empty {
  padding: 1rem;
  border: 1px dashed var(--race-line);
  border-radius: 0.6rem;
  color: var(--race-muted);
}

.racing-page .standings-table {
  width: 100%;
  border-collapse: collapse;
}

.racing-page .standings-table th,
.racing-page .standings-table td {
  padding: 0.4rem 0.5rem;
  text-align: left;
  border-bottom: 1px solid var(--race-line);
}

.racing-page .standings-table th {
  font-size: 0.75rem;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--race-muted);
}

/* Re-assert the numeric alignment: the rule above is one element selector more
 * specific than .racing-page .col-num, so without this Days, Races and Score
 * all drift left. Same trap as .day-results-table and .sailor-days. */
.racing-page .standings-table .col-num {
  text-align: right;
}

.racing-page .col-rank {
  width: 2.5rem;
}

.racing-page .col-num {
  text-align: right;
  font-variant-numeric: tabular-nums;
}

.racing-page .col-score {
  font-weight: 700;
}

/* The whole name is the toggle: a bigger target than a disclosure caret, and
 * it reads as "there is more here" without needing one. */
.racing-page .sailor-toggle {
  border: none;
  background: none;
  padding: 0;
  font: inherit;
  color: var(--link-color);
  text-align: left;
  cursor: pointer;
}

/* The caret reflects the row's state: closed points at the row, open points
 * down into it. Rotating one glyph rather than swapping ▸/▾ keeps the button
 * width stable, so the column does not jitter as rows open and close. */
.racing-page .sailor-toggle::after {
  content: "▸";
  display: inline-block;
  margin-left: 0.35em;
  color: var(--race-muted);
  transition: transform 0.15s ease;
}

.racing-page .sailor-toggle.expanded::after {
  transform: rotate(90deg);
}

@media (prefers-reduced-motion: reduce) {
  .racing-page .sailor-toggle::after {
    transition: none;
  }
}

.racing-page .sailor-detail.open > td {
  background: color-mix(in oklch, var(--race-chip-bg) 40%, transparent);
}

.racing-page .sailor-days {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.85rem;
}

.racing-page .sailor-days th,
.racing-page .sailor-days td {
  padding: 0.25rem 0.4rem;
  text-align: left;
  border-bottom: none;
}

.racing-page .sailor-days th {
  font-size: 0.7rem;
}

/* Re-assert the numeric alignment: the .sailor-days rule above is one element
 * selector more specific than .racing-page .col-num, so without this the Boat
 * and Score cells alone drift left. */
.racing-page .sailor-days .col-num {
  text-align: right;
}

.racing-page .racing-courses {
  list-style: none;
  padding: 0;
  margin: 0;
}

.racing-page .racing-courses li {
  padding: 0.5rem 0;
  border-bottom: 1px solid var(--race-line);
}

.racing-page .course-days {
  color: var(--race-muted);
  font-size: 0.85rem;
}

/* The standings table is the one thing here that can outgrow a phone. */
@media (max-width: 30em) {
  .racing-page .standings-content {
    overflow-x: auto;
  }
}
