/* css/style.css
   High contrast for bright sun on snow: black on white, thick borders,
   big type, big tap targets for gloves. */

* { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  font-size: 18px;
  line-height: 1.35;
  color: #000;
  background: #fff;
}

main {
  max-width: 960px;
  margin: 0 auto;
  padding: 12px 12px calc(40px + env(safe-area-inset-bottom));
}

h2 { font-size: 1.4rem; margin: 12px 0; }
h3 { font-size: 1.15rem; margin: 0 0 10px; }
a { color: #0033cc; }

.muted { color: #444; }
.small { font-size: 0.9rem; }
.center { text-align: center; }
.error { color: #b00000; font-weight: 700; }

/* ---------- header ---------- */
.top {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 12px;
  padding-top: calc(8px + env(safe-area-inset-top));
  background: #000;
  color: #fff;
}
.brand { color: #fff; font-weight: 800; text-decoration: none; font-size: 1.1rem; }
.coach { flex: 1; font-size: 0.9rem; opacity: 0.9; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.net {
  font-weight: 800;
  font-size: 0.85rem;
  padding: 4px 10px;
  border-radius: 999px;
  white-space: nowrap;
}
.net.online  { background: #0a7d28; color: #fff; }
.net.syncing { background: #ffd000; color: #000; }
.net.offline { background: #d00000; color: #fff; }

/* ---------- forms & buttons ---------- */
.card {
  border: 3px solid #000;
  border-radius: 10px;
  padding: 14px;
  margin: 14px 0;
}

label { display: block; font-weight: 700; margin: 10px 0 4px; }

input, select, textarea {
  width: 100%;
  font: inherit;
  font-size: 18px; /* 16px+ stops iOS zooming in */
  padding: 10px;
  border: 2px solid #000;
  border-radius: 6px;
  background: #fff;
  color: #000;
}
/* iOS Safari gives date inputs a native width that overflows their box. */
input[type="date"] {
  -webkit-appearance: none;
  appearance: none;
  display: block;
  min-width: 0;
  max-width: 100%;
  min-height: 48px;
  text-align: left;
}
input[type="date"]::-webkit-date-and-time-value { text-align: left; }
input.missing { border-color: #d00000; background: #fff0f0; }

.btn {
  display: inline-block;
  font: inherit;
  font-weight: 700;
  padding: 10px 16px;
  margin: 10px 8px 0 0;
  min-height: 48px;
  border: 3px solid #000;
  border-radius: 8px;
  background: #fff;
  color: #000;
  text-decoration: none;
  cursor: pointer;
}
.btn.primary { background: #000; color: #fff; }
.btn.big { width: 100%; font-size: 1.2rem; min-height: 60px; }
.btn.small { min-height: 40px; padding: 6px 10px; margin: 0; font-size: 0.9rem; }
.btn.danger { border-color: #b00000; color: #b00000; }
.btn.danger.armed { background: #b00000; color: #fff; }
.btn.link { border: none; text-decoration: underline; color: #0033cc; min-height: 0; }
.btn:disabled { opacity: 0.5; }

.row { display: flex; flex-wrap: wrap; gap: 0; }

.grid3 { display: grid; grid-template-columns: 1fr 2fr 1.3fr; gap: 8px; }
@media (max-width: 480px) { .grid3 { grid-template-columns: 1fr 1fr; } .grid3 > :nth-child(2) { grid-column: span 2; order: 3; } }

/* ---------- race list ---------- */
.list { border-top: 2px solid #000; }
.race-item {
  display: flex;
  align-items: center;
  gap: 12px;
  min-height: 64px;
  padding: 10px 4px;
  border-bottom: 2px solid #000;
  color: #000;
  text-decoration: none;
  -webkit-tap-highlight-color: transparent;
}
.race-item:active { background: #ffd000; }
.race-text { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.race-title { font-weight: 800; font-size: 1.15rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.race-date { color: #444; font-size: 0.95rem; }
.chevron { font-size: 2.2rem; font-weight: 700; line-height: 1; padding-right: 4px; }

/* ---------- race pages ---------- */
.race-head { display: flex; align-items: center; gap: 10px; }
.race-head h2 { margin: 8px 0; font-size: 1.15rem; }

.tabs { display: flex; border: 3px solid #000; border-radius: 10px; overflow: hidden; }
.tab {
  flex: 1;
  text-align: center;
  padding: 12px 0;
  font-weight: 800;
  text-decoration: none;
  color: #000;
  background: #fff;
}
.tab + .tab { border-left: 3px solid #000; }
.tab.active { background: #000; color: #fff; }

/* ---------- timing ---------- */
.time-top { display: flex; gap: 10px; align-items: center; margin: 12px 0 8px; }
.cp-select { flex: 1; font-weight: 800; font-size: 1.15rem; min-height: 56px; border-width: 3px; }
.clock { font-size: 1.6rem; font-weight: 800; font-variant-numeric: tabular-nums; }

.flash {
  min-height: 2.2em;
  padding: 6px 10px;
  font-size: 1.25rem;
  font-weight: 800;
  font-variant-numeric: tabular-nums;
}
.flash:empty { visibility: hidden; }
.flash.pulse { animation: pulse 0.8s ease-out; }
@keyframes pulse { from { background: #ffd000; } to { background: transparent; } }

.bib-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(96px, 1fr));
  gap: 8px;
}
.bib {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: 92px;
  padding: 6px 4px;
  border: 3px solid #000;
  border-radius: 10px;
  background: #fff;
  color: #000;
  font: inherit;
  touch-action: manipulation; /* no double-tap zoom */
  -webkit-tap-highlight-color: transparent;
  cursor: pointer;
}
.bib:active { background: #ffd000; }
.bib-num { font-size: 2.1rem; font-weight: 900; line-height: 1; font-variant-numeric: tabular-nums; }
.bib-name { font-size: 0.8rem; max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.bib-time { font-size: 0.85rem; font-weight: 800; font-variant-numeric: tabular-nums; }
.bib.passed { background: #e6f4ea; }
.bib.locked, .bib:disabled { background: #bbb; border-color: #777; color: #444; }

.recent { margin-top: 18px; }
.tap-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 0;
  border-bottom: 2px solid #ddd;
  font-variant-numeric: tabular-nums;
}
.tap-bib { font-weight: 900; font-size: 1.2rem; min-width: 3.2em; }
.tap-name { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tap-time { font-weight: 800; }
.pending, .synced { width: 1.5em; text-align: center; }
.synced { color: #0a7d28; font-weight: 900; }

/* ---------- tables ---------- */
.table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
table { border-collapse: collapse; width: 100%; }
th, td { border: 1px solid #000; padding: 6px 8px; text-align: left; vertical-align: top; }
th { background: #000; color: #fff; white-space: nowrap; }
td.num { font-variant-numeric: tabular-nums; white-space: nowrap; }
th.sortable { cursor: pointer; text-decoration: underline; }
th.sorted { background: #0033cc; }
tr.unknown td { background: #fff0f0; }
.results td:nth-child(2) { white-space: nowrap; }
.roster td { padding: 4px; }
.roster input { padding: 6px 8px; }
.roster td:first-child { font-weight: 900; font-size: 1.1rem; }

.export-status { font-weight: 700; }

/* ---------- toast ---------- */
.toast {
  position: fixed;
  left: 50%;
  bottom: calc(16px + env(safe-area-inset-bottom));
  transform: translateX(-50%);
  max-width: 92vw;
  padding: 12px 18px;
  border-radius: 10px;
  background: #000;
  color: #fff;
  font-weight: 700;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s;
}
.toast.show { opacity: 1; }
.toast.error { background: #b00000; }
