/* =========================
   Rider card — the compact layout, below 576px except on the pack page
   -----------------------------------------------------------------------------
   Switched by the media attribute of its <link> (partials/_rider_card_styles.html); the markup is
   partials/_rider_card.html, the rules both layouts share are in _rider_card.css and the layout from 576px in
   _rider_card_shield.css. Blocks top to bottom: .rider-card (the horizontal card), .rider-selection-button (the
   round + or − in a strip on its right), and under the card .rider-card-actions, .recent-averages,
   .duplicate-convert and .rider-craft.
   ========================= */

/* =========================
   .rider-card — a horizontal card: rarity tint and glow, sheen, jersey column, top row, stats, label on the top edge
   -----------------------------------------------------------------------------
    ┌─[label]──────────────────────────────┐
    │ ┌──────┐ flag First name         OVR │
    │ │jersey│      LAST NAME           82 │   <- top row
    │ └─────★┘ ┌───┬───┬───┬───┬───┐       │
    │   TLA    │CLI│HIL│SPR│TT │COB│       │   <- stats: label over value
    └──────────┴───┴───┴───┴───┴───┴───────┘

   __identity becomes display: contents, so its children sit straight on the card grid; the star or hammer sits on
   the jersey's bottom-right corner. Type scale (small text never under 0.7rem): --font-md star and hammer,
   --font-base last name, OVR value and the + or −, --font-sm-plus stat values, --font-sm first name, team code, OVR
   label, stat labels and the label on the top edge.
   ========================= */

.rider-card {
  background-image: linear-gradient(
    160deg,
    color-mix(in srgb, var(--rarity-color) 25%, var(--color-surface)),
    var(--color-surface)
  );
  border: 2px solid var(--rarity-color);
  border-radius: var(--border-radius);
  column-gap: var(--space-sm);
  display: grid;
  grid-template-areas:
    "jersey flag      name      ovr"
    "jersey stats     stats     stats";
  /* The jersey column is 2px wider than the 52px jersey, so it sits 10px from the flag */
  grid-template-columns: 54px auto minmax(0, 1fr) auto;
  padding: var(--space-sm);
}

/* Rarity glow, stronger per tier; a still glow, since an endless pulse on every Legendary card made a phone
   recalculate styles on every frame */
.rider-card.rarity-rare {
  box-shadow: 0 0 calc(var(--spacing-unit) * 0.75) var(--rarity-color);
}

.rider-card.rarity-epic {
  box-shadow: 0 0 calc(var(--spacing-unit) * 1.5) var(--rarity-color);
}

.rider-card.rarity-legendary {
  box-shadow: 0 0 calc(var(--spacing-unit) * 2) var(--rarity-color);
}

/* --- Sheen: Epic and Legendary light up on hover; Legendary keeps a still sheen at rest (an endless shimmer cost a
   phone ~3.5 s of work in every 4 s standing still) --- */

.rider-card__shine {
  background-image: linear-gradient( /* a white band */
    115deg,
    transparent 25%,
    rgba(255, 255, 255, 0.5) 38%,
    rgba(255, 255, 255, 0.12) 48%,
    transparent 65%
  );
  background-position: 20% 20%;
  background-size: 250% 250%;
  border-radius: inherit;
  mix-blend-mode: overlay;
  opacity: 0;
  transition: background-position 0.5s ease, opacity 0.4s ease;
}

.rider-card.rarity-legendary .rider-card__shine {
  opacity: 0.35;
}

/* A still card (rider-card--static) keeps its resting sheen */
.rider-card.rarity-epic:not(.rider-card--static):hover .rider-card__shine {
  background-position: 80% 80%;
  opacity: 0.5;
}

.rider-card.rarity-legendary:not(.rider-card--static):hover .rider-card__shine {
  background-position: 80% 80%;
  opacity: 0.65;
}

/* The shield face belongs to the shield layout */
.rider-card__face {
  display: none;
}

/* The dimming layers follow the card's rounded corners */
.rider-card.is-unowned::before,
.rider-card--duplicate::after {
  border-radius: var(--border-radius);
}

/* --- Jersey column (left, fixed width) --- */

.rider-card__hero {
  align-self: center;
  grid-area: jersey;
  width: 52px;
}

.rider-card__jersey svg {
  display: block;
  height: auto;
  width: 100%;
}

/* Favorite star (riders not owned) or crafted hammer (owned): the same spot, bottom-right of the jersey */
.rider-card__crafted,
.rider-card__favorite {
  bottom: -4px;
  display: flex;
  line-height: 1;
  position: absolute;
  right: -10px;
  z-index: 12; /* the card's top layer, above the badge and the round button (10) */
}

.rider-card__crafted-icon,
.rider-card__favorite-button {
  font-size: var(--font-md);
}

/* --- Top row: flag · name stack · OVR, placed straight onto the card grid --- */

.rider-card__identity {
  display: contents;
}

.rider-card__flag {
  align-self: center;
  border-radius: 3px;
  grid-area: flag;
  height: 14px;
}

.rider-card__name {
  align-self: center;
  grid-area: name;
  line-height: 1.15;
}

.rider-card__firstname {
  font-size: var(--font-sm);
  font-weight: 400;
  opacity: 0.7;
}

.rider-card__lastname {
  font-size: var(--font-base);
}

/* Team code under the jersey, sharing its column */
.rider-card__team {
  align-self: end;
  font-size: var(--font-sm);
  font-weight: 700;
  grid-area: jersey;
  justify-self: center;
  line-height: 1;
  opacity: 0.8;
}

.rider-card__overall {
  align-self: center;
  grid-area: ovr;
  text-align: right;
}

.rider-card__overall-label {
  font-size: var(--font-sm);
  font-weight: 600;
  opacity: 0.7;
  text-transform: uppercase;
}

.rider-card__overall-value {
  font-size: var(--font-base);
  font-weight: 700;
}

/* --- Stats row --- */

.rider-card__stats {
  gap: 3px;
  grid-area: stats;
  margin-top: 5px;
}

.rider-card__stat {
  background: rgba(255, 255, 255, 0.05); /* a faint white tile on every rarity tint */
  border-radius: var(--radius-sm);
  flex: 1;
  padding: 3px 2px;
}

.rider-card__stat-tla {
  font-size: var(--font-sm);
  opacity: 0.75;
}

.rider-card__stat-value {
  font-size: var(--font-sm-plus);
}

/* --- A strip on the right for the round button (.rider-selection-button), so it covers no stat: the button with a
   --space-sm gap on either side --- */

.rider-card:has(> .rider-selection-button) {
  --selection-button-size: 1.9rem;
  padding-right: calc(var(--selection-button-size) + 2 * var(--space-sm));
}

/* --- Startlist and duplicate labels: on the top edge above the jersey instead of over the name; raised so that
   the label ends where the card's content starts (padding + 2px border), above the first name --- */

.rider-card__badge {
  left: 10px;
  transform: translateY(calc(-100% + var(--space-sm) + 2px));
}

.rider-card__label {
  font-size: var(--font-sm);
  padding: 0.2em 0.5em;
}

.rider-card__label--off-startlist {
  /* !important: overrides Bootstrap's bg-danger utility, which is !important itself */
  background-color: var(--color-surface) !important;
  border: 1px solid currentcolor;
  color: var(--color-danger);
}

/* =========================
   .rider-selection-button — the round + or − in its strip on the right of the card, vertically centred
   ========================= */

.rider-selection-button {
  font-size: var(--font-base);
  height: var(--selection-button-size);
  right: var(--space-sm);
  top: 50%;
  transform: translateY(-50%);
  width: var(--selection-button-size);
}

/* =========================
   .rider-card-actions — the actions under the card, in line with the card's content (padding + 2px border)
   ========================= */

.rider-card-actions {
  padding: 0 calc(var(--space-sm) + 2px);
}

/* =========================
   .recent-averages — the points of the last 5 and 15 races on one line
   ========================= */

.recent-averages {
  display: flex;
  font-size: var(--font-sm);
  gap: 10px;
  margin-top: 3px;
  opacity: 0.8;
}

/* =========================
   .duplicate-convert — under a duplicate: the title over the shard buttons, under a hairline like .rider-craft
   ========================= */

.duplicate-convert {
  border-top: 1px solid var(--color-border);
  margin-top: var(--space-sm);
  padding-top: 7px;
}

.duplicate-convert__title {
  font-size: var(--font-sm);
}

/* =========================
   .rider-craft — the Craft button over the costs, which may wrap onto a second line here; under a hairline like
   .duplicate-convert
   ========================= */

.rider-craft {
  border-top: 1px solid var(--color-border);
  margin-top: var(--space-sm);
  padding-top: 7px;
}

.rider-craft__button {
  border-radius: var(--radius-md);
  font-size: var(--font-sm);
  padding: var(--space-sm) var(--space-md);
}

.rider-craft__label {
  align-items: center;
  display: inline-flex;
  gap: var(--space-xs);
  justify-content: center;
  letter-spacing: 0.02em;
}

.rider-craft__costs {
  margin-top: var(--space-sm);
}

/* The shared rule keeps the costs on one line */
.rider-craft__cost-list {
  flex-wrap: wrap;
  gap: calc(var(--spacing-unit) * 0.7);
  padding: calc(var(--spacing-unit) * 0.1);
}

.rider-craft__cost-icon {
  font-size: var(--font-base);
}

.rider-craft__cost,
.rider-craft__balance,
.rider-craft__separator {
  font-size: var(--font-sm);
}

.rider-craft__required {
  align-self: flex-end;
  font-size: var(--font-sm);
}
