/* The pace view (scripts/views/pace.mjs, js/views/pace.js): the sample chain's six steps at two paces, on one
   clock. The board is a real table of step times, laid out as a grid: on a phone the steps run down and each
   runner has a column; from 60rem the steps run across and each runner has a row. Without scripting it is
   that table under the line that says its times are sample data. With it, the slider sets when your team
   acts: a step reached by then is white, a step not reached is a grey ring, and a green bar stands where your
   team would stop a runner short of the end. That stop is worked out from the sample times, and the key says
   so. Green appears nowhere else. State changes move opacity and transform only. */

.view--pace { overflow: clip; border-radius: var(--radius-frame); background: var(--color-paper-2); box-shadow: inset 0 0 0 1px var(--color-frame-edge); }
.pace { --mark: var(--space-md); --thumb: var(--space-lg); display: grid; grid-template-columns: minmax(0, 1fr); gap: var(--space-lg); margin: 0; padding: var(--space-xl); }

/* ---------- The control: the label and its value, the scale, and Play ---------- */

.pace__bar { display: grid; grid-template-columns: minmax(0, 1fr) auto; align-items: center; gap: var(--space-xs) var(--space-lg); }
.pace__ask { grid-column: 1; grid-row: 1; display: grid; gap: var(--space-2xs); font-size: var(--text-md); line-height: 1.3; color: var(--color-ink-2); }
.pace__value { font-size: var(--text-title); line-height: var(--leading-title); letter-spacing: var(--tracking-title); color: var(--color-ink); font-variant-numeric: tabular-nums; white-space: nowrap; }
.pace__play { grid-column: 2; grid-row: 1; min-width: 5.5rem; text-align: center; }
.pace__play:focus-visible { outline: 2px solid var(--color-focus); outline-offset: 2px; transition: none; }

/* The scale is drawn under a bare range input: a grey line, a white fill up to the clock's hand, and the
   input's own thumb on top. The line is inset by half a thumb, so the fill ends at the thumb's centre. */
.pace__slider { position: relative; grid-column: 1 / -1; grid-row: 2; min-width: 0; }
.pace__track { position: absolute; top: calc((var(--control-hit) - var(--space-2xs)) / 2); left: calc(var(--thumb) / 2); right: calc(var(--thumb) / 2); height: var(--space-2xs); border-radius: var(--space-3xs); background: var(--color-paper-4); pointer-events: none; transition: background-color var(--dur-hover) var(--ease-out); }
.pace__slider:hover .pace__track { background: var(--color-dust-far); }
.pace__fill { position: absolute; inset: 0; border-radius: inherit; background: var(--color-ink); transform: scaleX(var(--p, 0)); transform-origin: left center; }
.pace__range { position: relative; display: block; width: 100%; height: var(--control-hit); margin: 0; padding: 0; border-radius: var(--radius-pill); background: none; cursor: pointer; touch-action: pan-y; -webkit-appearance: none; appearance: none; -webkit-tap-highlight-color: transparent; }
.pace__range::-webkit-slider-runnable-track { height: var(--thumb); background: none; }
.pace__range::-moz-range-track { height: var(--thumb); background: none; }
.pace__range::-webkit-slider-thumb { width: var(--thumb); height: var(--thumb); border: 0; border-radius: 50%; background: var(--color-ink); -webkit-appearance: none; appearance: none; transition: transform var(--dur-hover) var(--ease-out); }
.pace__range::-moz-range-thumb { width: var(--thumb); height: var(--thumb); border: 0; border-radius: 50%; background: var(--color-ink); transition: transform var(--dur-hover) var(--ease-out); }
.pace__range:active::-webkit-slider-thumb { transform: scale(0.92); }
.pace__range:active::-moz-range-thumb { transform: scale(0.92); }
.pace__range:focus-visible { outline: 2px solid var(--color-focus); outline-offset: 2px; transition: none; }
.pace__ticks { position: relative; display: block; height: 1.3em; margin: var(--space-2xs) calc(var(--thumb) / 2) 0; font-size: var(--text-md); line-height: 1.3; color: var(--color-ink-3); font-variant-numeric: tabular-nums; }
.pace__tick { position: absolute; top: 0; left: calc(var(--p) * 100%); transform: translateX(-50%); white-space: nowrap; }
.pace__tick[data-edge="start"] { transform: translateX(calc(var(--thumb) / -2)); }
.pace__tick[data-edge="end"] { transform: translateX(calc(var(--thumb) / 2 - 100%)); }

/* ---------- The sentence: what the picture shows, in words, one line per runner. Beside it, the line that
   says the step times are sample data ---------- */

.pace__now { display: grid; grid-template-columns: minmax(0, 1fr); gap: var(--space-sm) var(--space-xl); }
.pace__say { font-size: var(--text-card); line-height: var(--leading-card); letter-spacing: var(--tracking-card); color: var(--color-ink); }
.pace__line { display: block; }
.pace__when { color: var(--color-ink-3); font-variant-numeric: tabular-nums; }
.pace__note { font-size: var(--text-md); line-height: 1.4; color: var(--color-ink-3); }

/* ---------- The board. Phone first: steps down the left, one column per runner ---------- */

.pace__board { display: grid; grid-template-columns: max-content repeat(2, minmax(0, 1fr)); column-gap: var(--space-md); width: 100%; margin: 0; border: 0; border-collapse: collapse; font-size: var(--text-md); line-height: 1.3; }
.pace__board thead, .pace__board tbody, .pace__board tr { display: contents; }
.pace__board :where(th, td) { min-width: 0; padding: 0; font-weight: inherit; text-align: left; }
.pace__corner { grid-column: 1; grid-row: 1; }
.pace__step { grid-column: 1; grid-row: calc(var(--s) + 2); align-self: center; color: var(--color-ink-2); }
.pace__who { grid-column: calc(var(--r) + 2); grid-row: 1; align-self: end; padding-bottom: var(--space-xs); color: var(--color-ink); }
.pace__cell { position: relative; grid-column: calc(var(--r) + 2); grid-row: calc(var(--s) + 2); display: flex; align-items: center; gap: var(--space-xs); min-height: var(--control-hit); color: var(--color-ink-2); font-variant-numeric: tabular-nums; }
.pace__time { white-space: nowrap; }

/* A step's mark, and the line from it to the next step. */
.pace__mark { position: relative; z-index: 1; flex: none; display: block; width: var(--mark); height: var(--mark); border-radius: 50%; background: var(--color-line); }
.pace__cell:not([data-last])::before, .pace.is-ready .pace__cell:not([data-last])::after { content: ""; position: absolute; top: 50%; left: calc(var(--mark) / 2 - 1px); width: 2px; height: 100%; background: var(--color-paper-4); }

/* With scripting: a grey ring until the runner reaches the step, a white disc over it once it has, larger
   where the runner stands. The line to the next step fills white once that step is reached too. */
.pace.is-ready .pace__cell { color: var(--color-ink); }
.pace.is-ready .pace__cell:not(.is-on) .pace__time { opacity: 0.6; }
.pace.is-ready .pace__mark { background: var(--color-paper-2); box-shadow: inset 0 0 0 2px var(--color-dust-far); }
.pace.is-ready .pace__mark::before { content: ""; position: absolute; inset: 0; border-radius: 50%; background: var(--color-ink); }
.pace.is-ready .pace__cell:not(.is-on) .pace__mark::before { opacity: 0; transform: scale(0.4); }
.pace.is-ready .pace__cell.is-now .pace__mark { transform: scale(1.25); }
.pace.is-ready .pace__cell:not([data-last])::after { background: var(--color-ink); transform: scaleY(0); transform-origin: center top; }
.pace.is-ready .pace__cell.is-on:not(.is-now)::after { transform: none; }

/* The green bar: where your team would stop a runner, across the line to the step it would not reach. */
.pace__stop { flex: none; display: block; width: var(--space-lg); height: var(--space-2xs); border-radius: var(--space-3xs); background: var(--color-defense); }
.pace__cell .pace__stop { position: absolute; z-index: 1; top: 100%; left: calc(var(--mark) / 2); transform: translate(-50%, -50%); }
.pace.is-ready .pace__cell:not(.is-stopped) .pace__stop { opacity: 0; transform: translate(-50%, -50%) scale(0.4); }

/* The key to the green bar. It is there only with scripting, as the bar is. */
.pace__foot { display: flex; align-items: center; gap: var(--space-xs); font-size: var(--text-md); line-height: 1.4; color: var(--color-ink-2); }

/* ---------- From 60rem: steps across the top, one row per runner ---------- */

@media (min-width: 60rem) {
  .pace__bar { grid-template-columns: minmax(12rem, auto) minmax(0, 1fr) auto; align-items: start; column-gap: var(--space-xl); }
  .pace__slider { grid-column: 2; grid-row: 1; }
  .pace__play { grid-column: 3; }
  /* With reduced motion there is no Play: the scale runs to the frame's edge. */
  .pace__bar:has(> .pace__play[hidden]) .pace__slider { grid-column: 2 / -1; }
  .pace__board { grid-template-columns: minmax(0, 1.5fr) repeat(6, minmax(0, 1fr)); column-gap: 0; }
  .pace__step { grid-column: calc(var(--s) + 2); grid-row: 1; align-self: end; padding: 0 var(--space-2xs) var(--space-sm); text-align: center; color: var(--color-ink-3); }
  .pace__who { grid-column: 1; grid-row: calc(var(--r) + 2); align-self: stretch; padding: var(--space-md) var(--space-md) var(--space-md) 0; border-top: 1px solid var(--color-rule); font-size: var(--text-title); line-height: var(--leading-title); letter-spacing: var(--tracking-title); }
  .pace__cell { grid-column: calc(var(--s) + 2); grid-row: calc(var(--r) + 2); flex-direction: column; justify-content: flex-start; min-height: 0; padding-block: var(--space-lg) var(--space-md); border-top: 1px solid var(--color-rule); text-align: center; }
  .pace__cell:not([data-last])::before, .pace.is-ready .pace__cell:not([data-last])::after { top: calc(var(--space-lg) + var(--mark) / 2 - 1px); left: 50%; width: 100%; height: 2px; }
  .pace.is-ready .pace__cell:not([data-last])::after { transform: scaleX(0); transform-origin: left center; }
  .pace.is-ready .pace__cell.is-on:not(.is-now)::after { transform: none; }
  .pace__stop { width: var(--space-2xs); height: var(--space-lg); }
  .pace__cell .pace__stop { top: calc(var(--space-lg) + var(--mark) / 2); left: 100%; }
}
/* From 80rem the sentence's longest wording leaves room beside it: the sample line takes the right of its row,
   two lines against two. Below that it sits under the sentence. */
@media (min-width: 80rem) {
  .pace.is-ready .pace__now { grid-template-columns: minmax(0, 1fr) minmax(0, 23rem); align-items: end; }
  .pace.is-ready .pace__note { text-align: right; text-wrap: balance; }
}
/* Where a column is too narrow for the longest step name, every name takes two lines. */
@media (min-width: 60rem) and (max-width: 74.99rem) {
  .pace__step { justify-self: center; width: min-content; }
}

/* ---------- Motion, only with scripting and without reduced motion ---------- */

html:not(.rm) .pace.is-ready .pace__time { transition: opacity 240ms var(--ease-out); }
html:not(.rm) .pace.is-ready .pace__mark { transition: transform 360ms var(--ease-expo); }
html:not(.rm) .pace.is-ready .pace__mark::before { transition: opacity 200ms var(--ease-out), transform 360ms var(--ease-expo); }
/* A step lights as the line reaches it, not before. */
html:not(.rm) .pace.is-ready .pace__cell.is-on .pace__mark, html:not(.rm) .pace.is-ready .pace__cell.is-on .pace__mark::before, html:not(.rm) .pace.is-ready .pace__cell.is-on .pace__time { transition-delay: 140ms; }
html:not(.rm) .pace.is-ready .pace__cell:not([data-last])::after { transition: transform 240ms var(--ease-out); }
html:not(.rm) .pace.is-ready .pace__cell .pace__stop { transition: opacity 240ms var(--ease-out), transform 420ms var(--ease-expo); }
/* The step a runner has just reached rings once. */
.pace.is-ready .pace__cell.is-now .pace__mark::after { content: ""; position: absolute; inset: calc(-1 * var(--space-2xs)); border-radius: 50%; box-shadow: inset 0 0 0 1px var(--color-ink-3); opacity: 0; pointer-events: none; }
html:not(.rm) .pace.is-ready .pace__cell.is-now .pace__mark::after { animation: pace-ring 900ms var(--ease-out) 140ms 1 both; }
@keyframes pace-ring { 0% { opacity: 0.9; transform: scale(0.8); } 100% { opacity: 0; transform: scale(1.5); } }

@media (max-width: 39.99rem) {
  .view--pace { margin-inline: calc(-1 * var(--gutter)); border-radius: 0; box-shadow: inset 0 1px 0 var(--color-frame-edge), inset 0 -1px 0 var(--color-frame-edge); }
  .pace { padding: var(--space-lg) var(--gutter); }
}
