/* ==========================================================================
   Run metric cards (owner 2026-10-09): the Biomechanical Signature cards for
   one run, shared by the run page (/run) and the upload report (/report).
   - The metric's level shows only in the card colour (value, light, arrow);
     there is no word or tag inside the card.
   - Choosing a card lights it, dims the others and opens its explanation
     right under that card's row (a full-width item of the grid); the page
     focuses that metric's line in its chart.
   - The card is the shared tile (.ri-tile--glow) lit in its level colour,
     set as --card-glow-rgb ("r, g, b").
   Markup and behaviour: js/run-metric-cards.js.
   ========================================================================== */
.rmc-grid {
  --rmc-gap: 12px;
  display: grid;
  grid-template-columns: repeat(7, minmax(0, 1fr));
  gap: 0 var(--rmc-gap);
  margin-top: 24px;
  /* Rows are spaced by each item's own margin, so a closed explanation between two rows
     adds no gap; this takes back the last row's. */
  margin-bottom: calc(-1 * var(--rmc-gap));
}
.rmc-grid > :not(.rmc-expl) { margin-bottom: var(--rmc-gap); }
.rmc-card {
  --card-glow-rgb: 156, 163, 175;
  --tile-color: rgb(var(--card-glow-rgb));
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  min-width: 0;
  min-height: 102px;
  padding: 15px 6px 10px;
  border-radius: var(--ri-radius-md, 12px);
  text-align: center;
  cursor: pointer;
  outline: none;
}
.rmc-card.ri-tile--glow {
  transition: var(--_tile-out), opacity 240ms ease, filter 240ms ease, transform 180ms ease-out;
}
.rmc-card:focus-visible {
  outline: 2px solid var(--ri-cyan, #2ED1F4);
  outline-offset: 2px;
}
.rmc-title {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 5px;
  max-width: 100%;
  margin: 0 0 2px;
  color: var(--ri-text-muted, rgba(255, 255, 255, 0.74));
  font-size: var(--ri-text-caption, 13px);
  font-weight: var(--ri-weight-body, 300);
  line-height: var(--ri-leading-caption, 1.35);
}
.rmc-title img {
  flex: none;
  width: 14px;
  height: 14px;
  object-fit: contain; /* the Run-It mark is wider than tall: fit, never squeeze */
}
.rmc-value {
  margin: 0;
  color: rgb(var(--card-glow-rgb));
  font-size: var(--ri-text-metric-lg, 24px);
  font-weight: 600;
  line-height: var(--ri-leading-metric, 1.15);
  white-space: nowrap;
  transition: color 0.35s ease;
}
.rmc-unit {
  color: var(--ri-text-faint, rgba(255, 255, 255, 0.62));
  font-size: var(--ri-text-label, 12px);
  font-weight: 400;
}
.rmc-note {
  color: var(--ri-text-faint, rgba(255, 255, 255, 0.62));
  font-size: var(--ri-text-label, 12px);
  line-height: 1.2;
}
.rmc-arrow {
  width: 16px;
  height: 16px;
  margin-top: 8px;
  transition: transform 0.16s ease-out;
}
/* The arrow takes the card's level colour, like its value (owner 2026-10-10: not cyan on
   every card): the sprite's two tones in that colour, the muted one at half strength. */
.rmc-card .rmc-arrow {
  --icon-accent: rgb(var(--card-glow-rgb));
  --icon-muted: rgba(var(--card-glow-rgb), 0.5);
}
.rmc-card.is-active {
  --tile-lift: 1;
  --_tile-edge: 100%;
  transform: translateY(-2px);
  transition: var(--_tile-in), opacity 240ms ease, filter 240ms ease, transform 180ms ease-out;
}
.rmc-card.is-active .rmc-arrow { transform: rotate(180deg); }
.rmc-grid.has-active .rmc-card:not(.is-active) {
  opacity: 0.35;
  filter: saturate(0.15) brightness(0.6);
}
.rmc-card.is-unavailable {
  cursor: default;
  --card-glow-rgb: 148, 163, 184;
}
.rmc-card.is-unavailable .rmc-arrow { visibility: hidden; }
@media (hover: hover) {
  .rmc-card:not(.is-unavailable):hover {
    --tile-lift: 1;
    --_tile-edge: 45%;
    transition: var(--_tile-in), opacity 240ms ease, filter 240ms ease, transform 180ms ease-out;
  }
  .rmc-grid.has-active .rmc-card:not(.is-active):not(.is-unavailable):hover { opacity: 0.7; }
}

/* Explanation under the chosen card's row: opens and closes in place, 16 px from the
   cards above and below. */
.rmc-expl {
  display: grid;
  grid-template-rows: 0fr;
  margin-top: 0;
  margin-bottom: 0;
  opacity: 0;
  transition: grid-template-rows 320ms cubic-bezier(0.3, 0.1, 0.3, 1), opacity 240ms ease, margin-top 320ms ease, margin-bottom 320ms ease;
}
.rmc-grid > .rmc-expl { grid-column: 1 / -1; }
.rmc-expl.is-open {
  grid-template-rows: 1fr;
  margin-top: 16px;
  opacity: 1;
}
.rmc-grid > .rmc-expl.is-open {
  margin-top: calc(16px - var(--rmc-gap));
  margin-bottom: 16px;
}
.rmc-grid > .rmc-expl.is-open:last-child { margin-bottom: var(--rmc-gap); }
.rmc-expl > div { min-height: 0; overflow: hidden; }
.rmc-expl-box {
  --card-glow-rgb: 46, 209, 244;
  --tile-color: rgb(var(--card-glow-rgb));
  display: grid;
  grid-template-columns: minmax(0, 1.3fr) repeat(3, minmax(0, 1fr));
  align-items: center;
  gap: 16px 24px;
  padding: 18px 20px;
  border-radius: var(--ri-radius-md, 12px);
}
.rmc-expl-box h3 {
  margin: 0 0 4px;
  color: #fff;
  font-size: var(--ri-text-lead, 16px);
  font-weight: 400;
}
.rmc-expl-box p {
  margin: 0;
  color: var(--ri-text-muted, rgba(255, 255, 255, 0.74));
  font-size: var(--ri-text-secondary, 14px);
  line-height: 1.5;
}
.rmc-stat { display: grid; gap: 2px; min-width: 0; }
.rmc-stat span {
  color: var(--ri-text-faint, rgba(255, 255, 255, 0.62));
  font-size: var(--ri-text-caption, 13px);
  font-weight: 400;
}
.rmc-stat b {
  color: rgb(var(--card-glow-rgb));
  font-size: 20px;
  font-weight: 400;
  white-space: nowrap;
}
.rmc-stat b small {
  margin-left: 3px;
  color: var(--ri-text-faint, rgba(255, 255, 255, 0.62));
  font-size: 12px;
}
/* A page action in the panel (the run page's "Inspect details", owner 2026-10-09):
   the shared secondary button built in the panel's own level colour, as
   .ri-btn--neutral is the secondary in grey. It keeps the last column. */
.rmc-expl-box.has-action {
  grid-template-columns: minmax(0, 1.3fr) repeat(3, minmax(0, 1fr)) auto;
}
.rmc-expl-action.ri-btn--secondary {
  --_btn-ring: linear-gradient(90deg, rgba(var(--card-glow-rgb), 0.55) 0.01%, rgba(var(--card-glow-rgb), 0.42) 100%);
  --_btn-shadow: inset 0 -6px 15px rgba(var(--card-glow-rgb), 0.22), inset 0 6px 15px rgba(var(--card-glow-rgb), 0.16);
  --_btn-wash: linear-gradient(90deg, rgba(var(--card-glow-rgb), 0.16), rgba(var(--card-glow-rgb), 0.06));
  grid-column: -2;
  grid-row: 1;
  justify-self: end;
  white-space: nowrap;
}

@media (max-width: 1180px) {
  .rmc-grid { grid-template-columns: repeat(4, minmax(0, 1fr)); }
}
/* Narrow panels with an action: the explanation on its own row, the button under the
   figures, so the title never has to squeeze into a fifth of the width. */
@media (max-width: 900px) {
  .rmc-expl-box.has-action { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .rmc-expl-box.has-action > :first-child { grid-column: 1 / -1; }
  .rmc-expl-action.ri-btn--secondary { grid-column: 1 / -1; grid-row: auto; justify-self: start; }
}
@media (max-width: 640px) {
  .rmc-grid { --rmc-gap: 10px; grid-template-columns: repeat(3, minmax(0, 1fr)); margin-top: 20px; }
  .rmc-card { min-height: 88px; padding: 10px 4px 6px; }
  .rmc-card[data-metric="hr"] { grid-column: 1 / -1; }
  .rmc-expl-box { grid-template-columns: repeat(3, minmax(0, 1fr)); padding: 16px; }
  .rmc-expl-box > :first-child { grid-column: 1 / -1; }
  .rmc-stat b { font-size: 18px; }
  .rmc-expl-box.has-action { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .rmc-expl-action.ri-btn--secondary { grid-column: 1 / -1; grid-row: auto; justify-self: stretch; }
}
@media (prefers-reduced-motion: reduce) {
  .rmc-card, .rmc-card.is-active, .rmc-expl, .rmc-arrow { transition: none !important; }
}
