/* ── Lap-time grid + "still running" chart ────────────────────────────────
   Shared by index.html and admin.html. Colours are derived from the page's
   own variables: --red is the configurable theme colour (set from
   race_config.primaryColor in applyBranding / applyAdminBranding), so the
   lap-time tones follow the event's branding automatically. */

.lg-wrap {
  position: relative;
  overflow-x: auto;
  overflow-y: hidden;
  -webkit-overflow-scrolling: touch;
  padding: 10px 0 4px;
  --lg-name-w: 180px;
  --lg-gap: 2px;
  /* Cell width stretches so the yards fill the content column, between a
     phone-friendly minimum and a cap that keeps a 12-yard race from turning
     into a row of slabs. --lg-yards is set inline by renderGrid(); the 48px
     is room for the "Completed"/out-lap label after the last cell. */
  --lg-yards: 24;
  --lg-cell: clamp(11px, calc((100% - var(--lg-name-w) - var(--lg-tail)) / var(--lg-yards) - var(--lg-gap)), 96px);
  --lg-cell-h: 16px;
  --lg-tail: 48px;   /* room for the "Completed" / out-lap label */
  --lg-step: calc(var(--lg-cell) + var(--lg-gap));
  font-family: var(--mono);
}
.lg-row {
  display: flex;
  align-items: center;
  height: 22px;
  cursor: pointer;
  white-space: nowrap;
}
.lg-row:hover .lg-name { color: var(--red); }
.lg-row.lg-sep {
  cursor: default;
  height: 28px;
  font-size: 0.66rem;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: var(--grey);
}
.lg-row.lg-sep .lg-name { color: var(--grey); }
.lg-name {
  position: sticky;
  left: 0;
  z-index: 2;
  flex: none;
  width: var(--lg-name-w);
  padding-right: 10px;
  box-sizing: border-box;
  overflow: hidden;
  text-overflow: ellipsis;
  font-family: var(--body);
  font-size: 0.9rem;
  font-weight: 600;
  color: var(--white);
  transition: color 0.15s;
}
.lg-name .lg-rank {
  display: inline-block;
  min-width: 28px;
  font-family: var(--mono);
  font-size: 0.66rem;
  font-weight: 500;
  color: var(--grey);
}
.lg-row.lg-out .lg-name { color: var(--grey-dim, #bababa); }
/* Winner's name in the same gold as the table's winner row. */
.lg-row.lg-winner .lg-name { color: #fbbf24; }
.lg-row.lg-winner:hover .lg-name { color: #fde68a; }
.lg-cell {
  flex: none;
  width: var(--lg-cell);
  height: var(--lg-cell-h);
  margin-right: var(--lg-gap);
  border-radius: 2px;
  box-sizing: border-box;
  background: var(--surface2);
  border: 1px solid #343434;
}
/* Lap-time bands, lightest → strongest, all mixed from the theme colour. */
.lg-cell[data-b="0"] { background: color-mix(in srgb, var(--red) 20%, var(--surface2)); }
.lg-cell[data-b="1"] { background: color-mix(in srgb, var(--red) 38%, var(--surface2)); }
.lg-cell[data-b="2"] { background: color-mix(in srgb, var(--red) 56%, var(--surface2)); }
.lg-cell[data-b="3"] { background: color-mix(in srgb, var(--red) 76%, var(--surface2)); }
.lg-cell[data-b="4"] { background: var(--red); }
/* Out-of-race markers deliberately avoid colour altogether: any hue can
   clash with a theme-derived tone (orange/red did against a red theme), but
   a solid white block with an ✕ and a dashed hollow block never can. */
.lg-cell.lg-dnf,
.lg-cell.lg-dns,
.lg-cell.lg-done {
  position: relative;
  font-family: var(--mono);
  font-weight: 700;
  line-height: var(--lg-cell-h);
  text-align: center;
}
.lg-cell.lg-dnf {
  background: var(--white);
  color: var(--bg, #080808);
  font-size: 10px;
}
.lg-cell.lg-dnf::after { content: '✕'; }
/* Completed a fixed-lap race (or won): white block with a tick. */
.lg-cell.lg-done {
  background: var(--white);
  color: var(--bg, #080808);
  font-size: 10px;
}
.lg-cell.lg-done::after { content: '✓'; }
.lg-row .lg-outlap { color: var(--white); opacity: 0.85; }
.lg-cell.lg-dns {
  background: transparent;
  border: 1.5px dashed var(--grey);
  color: var(--grey);
  font-size: 9px;
  line-height: calc(var(--lg-cell-h) - 3px);
}
.lg-cell.lg-dns::after { content: '–'; }
.lg-cell.lg-now {
  background: transparent;
  border: 1.5px solid color-mix(in srgb, var(--red) 70%, var(--white)) !important;
  animation: lgPulse 1.6s ease-in-out infinite;
}
@keyframes lgPulse { 0%,100% { opacity: 1; } 50% { opacity: 0.35; } }
.lg-outlap {
  flex: none;
  margin-left: 4px;
  font-size: 0.68rem;
  color: var(--grey);
}
.lg-axis {
  position: relative;
  height: 20px;
  margin-top: 6px;
  /* Padding rather than margin so that 100% inside --lg-cell's calc() means
     the same full row width here as it does in the cells. */
  padding-left: var(--lg-name-w);
  box-sizing: border-box;
  font-size: 0.64rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--grey);
}
.lg-axis span {
  position: absolute;
  top: 2px;
  transform: translateX(-50%);
  white-space: nowrap;
}
.lg-axis span:first-child { transform: translateX(calc(0px - var(--lg-cell) / 2)); }
.lg-legend {
  display: flex;
  flex-wrap: wrap;
  gap: 8px 16px;
  padding: 12px 0 4px;
  margin-top: 8px;
  border-top: 1px solid var(--border);
  font-family: var(--mono);
  font-size: 0.66rem;
  letter-spacing: 0.04em;
  color: var(--grey);
}
.lg-legend .lg-cell {
  display: inline-block;
  vertical-align: middle;
  width: 12px;
  height: 12px;
  margin: 0 5px 0 0;
}
.lg-legend .lg-cell.lg-now { animation: none; }
.lg-empty { padding: 32px; text-align: center; color: var(--grey); font-family: var(--mono); font-size: 0.8rem; }

@media (min-width: 768px) {
  .lg-wrap { --lg-name-w: 220px; --lg-cell-h: 22px; --lg-gap: 3px; --lg-tail: 96px; }
  .lg-row { height: 30px; }
  .lg-row.lg-sep { height: 34px; font-size: 0.74rem; }
  .lg-name { font-size: 1.08rem; }
  .lg-name .lg-rank { min-width: 34px; font-size: 0.74rem; }
  .lg-cell.lg-dnf, .lg-cell.lg-done { font-size: 13px; }
  .lg-cell.lg-dns { font-size: 11px; }
  .lg-outlap { font-size: 0.8rem; margin-left: 8px; }
  .lg-axis { font-size: 0.72rem; height: 22px; }
  .lg-legend { font-size: 0.76rem; gap: 10px 20px; padding-top: 14px; }
  .lg-legend .lg-cell { width: 14px; height: 14px; line-height: 14px; }
}

@media (max-width: 600px) {
  /* Cells keep the stretch formula so a short race fills the phone width;
     the 11px floor in --lg-cell is what makes a long race scroll instead. */
  .lg-wrap { --lg-name-w: 128px; --lg-tail: 24px; }
  /* No room for "Winner"/"Completed" labels on a phone — the gold name and
     the ✓ on the last yard carry that on their own. */
  .lg-status { display: none; }
  .lg-name { font-size: 0.82rem; }
  .lg-name .lg-rank { min-width: 22px; }
}

/* ── Survival chart ─────────────────────────────────────────────────────── */
.sv-wrap { font-family: var(--mono); }
.sv-head { padding: 0 0 12px; }
.sv-title { font-family: var(--head, var(--body)); font-size: 1.5rem; letter-spacing: 0.03em; color: var(--white); line-height: 1; }
.sv-sub   { margin-top: 6px; font-size: 0.72rem; color: var(--grey); }
.sv-chart { position: relative; }
.sv-chart svg { display: block; width: 100%; height: auto; overflow: visible; }
.sv-chart svg:focus { outline: none; }
.sv-chart svg:focus-visible { outline: 1px solid rgba(255, 255, 255, 0.25); outline-offset: 4px; border-radius: 4px; }
.sv-chart .sv-grid  { stroke: var(--border); stroke-width: 1; }
.sv-chart .sv-vgrid { stroke: var(--white); stroke-width: 1; opacity: 0.06; }
.sv-chart .sv-night { fill: var(--white); opacity: 0.06; }
.sv-chart .sv-line  { fill: none; stroke: var(--red); stroke-width: 2.5; stroke-linejoin: round; stroke-linecap: round; }
.sv-chart .sv-dot   { fill: var(--red); }
.sv-chart .sv-tick  { fill: var(--grey); font-size: 11px; font-family: var(--mono); }
.sv-chart .sv-now   { stroke: var(--grey); stroke-dasharray: 3 3; stroke-width: 1; }
.sv-chart .sv-ms    { stroke: var(--red); stroke-width: 1; opacity: 0.35; }
.sv-chart .sv-ms-label { fill: var(--red); font-size: 11px; font-family: var(--mono); letter-spacing: 0.02em; }
.sv-chart .sv-cmp    { fill: none; stroke: var(--white); stroke-width: 1.75; stroke-dasharray: 5 4; stroke-linejoin: round; opacity: 0.55; }
.sv-chart .sv-cmp-1  { opacity: 0.35; stroke-dasharray: 2 3; }
.sv-chart .sv-cmp-2  { opacity: 0.35; stroke-dasharray: 8 3 2 3; }
.sv-chart .sv-bar-dnf { fill: var(--status-dnf, #ff6b00); }
.sv-chart .sv-bar-dns { fill: var(--status-dns, #e11d2e); }
.sv-chart .sv-bar-n   { fill: var(--grey); font-size: 10px; font-family: var(--mono); }
.sv-tabs {
  display: inline-flex; gap: 0; margin: 0 0 14px; padding: 3px;
  border: 1px solid var(--border); border-radius: 8px; background: rgba(255, 255, 255, 0.03);
}
.sv-title + .sv-tabs { margin-top: 12px; }
.sv-tab {
  appearance: none; border: 0; border-radius: 6px; cursor: pointer;
  padding: 9px 18px; background: transparent;
  font-family: var(--mono); font-size: 0.8rem; font-weight: 600; letter-spacing: 0.04em;
  color: var(--grey); transition: background 0.15s, color 0.15s;
}
.sv-tab:hover { color: var(--white); background: rgba(255, 255, 255, 0.06); }
.sv-tab[aria-selected="true"] { color: #fff; background: var(--red); }
.sv-tab:focus-visible { outline: 2px solid var(--white); outline-offset: 2px; }
.sv-panel[hidden] { display: none; }
.sv-legend .sv-i-bar { width: 10px; height: 10px; }
.sv-legend .sv-i-dnf { background: var(--status-dnf, #ff6b00); }
.sv-legend .sv-i-dns { background: var(--status-dns, #e11d2e); }
/* Interactive readout */
.sv-chart .sv-hit { fill: transparent; cursor: crosshair; touch-action: pan-y; }
.sv-chart .sv-hl-guide { stroke: var(--white); stroke-width: 1; opacity: 0.55; pointer-events: none; }
.sv-chart .sv-hl-band  { fill: var(--white); opacity: 0.07; pointer-events: none; }
.sv-chart .sv-hl-dot   { fill: var(--red); stroke: var(--bg, #080808); stroke-width: 2; pointer-events: none; }
.sv-chart .sv-hl-dot-cmp { fill: var(--white); }
.sv-card {
  position: absolute; top: 6px; z-index: 2; min-width: 168px; max-width: 240px;
  padding: 10px 12px; border-radius: 8px; pointer-events: none;
  background: rgba(16, 16, 16, 0.94); border: 1px solid var(--border);
  box-shadow: 0 6px 24px rgba(0, 0, 0, 0.45);
  font-family: var(--mono); font-size: 0.72rem; color: var(--grey);
}
.sv-card[hidden] { display: none; }
.sv-card-h { color: var(--white); font-weight: 600; font-size: 0.8rem; margin-bottom: 6px; }
.sv-card-row { display: flex; justify-content: space-between; gap: 14px; padding: 2px 0; }
.sv-card-row span { display: flex; align-items: center; gap: 6px; }
.sv-card-row b { color: var(--white); font-weight: 600; white-space: nowrap; }
.sv-card-row b i, .sv-card-row i:not(.sv-k) { font-style: normal; color: var(--grey); font-weight: 400; margin-left: 4px; }
.sv-card-ms { margin-top: 6px; padding-top: 6px; border-top: 1px solid var(--border); color: var(--red); }
.sv-k { display: inline-block; width: 10px; height: 10px; border-radius: 2px; flex: none; }
.sv-k-line { height: 0; border-top: 2.5px solid var(--red); border-radius: 0; }
.sv-k-cmp  { height: 0; border-top: 1.75px dashed var(--white); border-radius: 0; opacity: 0.7; }
.sv-k-dnf  { background: var(--status-dnf, #ff6b00); }
.sv-k-dns  { background: var(--status-dns, #e11d2e); }
.sv-legend {
  display: flex; flex-wrap: wrap; gap: 8px 18px;
  padding-top: 12px; font-size: 0.66rem; color: var(--grey);
}
.sv-legend i { display: inline-block; vertical-align: middle; margin-right: 6px; }
.sv-legend .sv-i-line  { width: 18px; height: 0; border-top: 2.5px solid var(--red); }
.sv-legend .sv-i-night { width: 12px; height: 12px; background: var(--white); opacity: 0.14; }
.sv-legend .sv-i-now   { width: 18px; height: 0; border-top: 1px dashed var(--grey); }
.sv-legend .sv-i-cmp   { width: 18px; height: 0; border-top: 1.75px dashed var(--white); opacity: 0.6; }
.sv-legend .sv-i-ms    { width: 0; height: 12px; border-left: 1px solid var(--red); opacity: 0.6; }
