.table-actions {
    text-align: right;
    white-space: nowrap;
}

/* The single column pinned to the left edge: rank and trainer name, and in the
   header the controls that steer the horizontal scroll. */
.rank-cell {
    text-align: left;
    color: var(--text-muted);
    position: sticky;
    left: 0;
    z-index: 1;
    white-space: nowrap;
    width: max-content;
    min-width: max-content;
    box-shadow: 2px 0 6px -2px rgba(0, 0, 0, .15);
}

.rank-cell__content {
    display: inline-flex;
    align-items: center;
    gap: .45rem;
}

.rank-cell__number {
    flex-shrink: 0;
}

.rank-cell__name {
    display: inline-flex;
    align-items: center;
    gap: .4rem;
    width: max-content;
    overflow: hidden;
    color: var(--text);
}

/* Find me on the left, the back arrow against the right edge of the cell — where
   the scrolling columns start, so it points at what it pulls back. */
.rank-cell__tools {
    display: flex;
    align-items: center;
    gap: .4rem;
    width: 100%;
}

.rank-cell__tools .prev-metric-btn {
    margin-left: auto;
}

/* Chrome shared by the buttons in the pinned header cell. */
.table-tool-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    flex: 0 0 auto;
    min-height: 2.15rem;
    padding: .2rem .5rem;
    border: 1px solid var(--border);
    border-radius: 6px;
    box-sizing: border-box;
    background: var(--surface);
    box-shadow: 0 1px 0 rgba(255, 255, 255, .04), 0 1px 6px rgba(0, 0, 0, .12);
    color: var(--text-muted);
    font: inherit;
    line-height: 1;
    text-transform: none;
    letter-spacing: 0;
    white-space: nowrap;
    cursor: pointer;
    transition: background .15s, border-color .15s, color .15s, opacity .15s;
}

.table-tool-btn:hover:not(:disabled):not(.is-disabled):not([aria-disabled="true"]) {
    background: var(--surface-2);
    color: var(--text);
}

.table-tool-btn:disabled,
.table-tool-btn.is-disabled,
.table-tool-btn[aria-disabled="true"] {
    opacity: .45;
    cursor: default;
}

.find-me-btn {
    gap: .25rem;
    font-size: .7rem;
    font-weight: 700;
}

.find-me-btn.is-active,
.find-me-btn[aria-pressed="true"] {
    border-color: color-mix(in srgb, var(--accent) 35%, transparent);
    background: color-mix(in srgb, var(--accent) 12%, transparent);
    color: var(--accent);
}

/* Later than .table-tool-btn:hover, which is one step more specific and would
   otherwise wash the accent off the pressed state. */
.find-me-btn.is-active:hover,
.find-me-btn[aria-pressed="true"]:hover {
    background: color-mix(in srgb, var(--accent) 20%, transparent);
    color: var(--accent);
}

.find-me-btn__icon {
    display: block;
    flex: 0 0 auto;
    width: 14px;
    height: 14px;
    color: currentColor;
    opacity: 1;
    stroke: currentColor;
}

.back-to-top-btn,
.prev-metric-btn {
    width: 2.15rem;
    padding: 0;
}

.back-to-top-btn__icon,
.prev-metric-btn__icon {
    display: block;
    flex: 0 0 auto;
}

.data-table th.rank-cell {
    background: var(--surface);
    z-index: 2;
}

.data-table td.rank-cell {
    background: var(--bg);
}

.rank-cell__name a {
    color: inherit;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    min-width: 0;
}

.team-icon {
    width: 16px;
    height: 16px;
    object-fit: contain;
    flex-shrink: 0;
    vertical-align: middle;
    opacity: .85;
}

.current-player-badge {
    display: inline-flex;
    align-items: center;
    flex: 0 0 auto;
    padding: .12rem .4rem;
    border: 1px solid color-mix(in srgb, var(--accent) 35%, transparent);
    border-radius: 999px;
    background: color-mix(in srgb, var(--accent) 10%, transparent);
    color: var(--accent);
    font-size: .6rem;
    font-weight: 700;
    line-height: 1.2;
    text-transform: uppercase;
}

.rank-cell__name a,
.metric-card-name a {
    color: inherit;
    transition: color .15s;
}

.rank-cell__name a:hover,
.metric-card-name a:hover {
    color: var(--team-color, var(--accent));
}

.tr--rank-1 td.rank-cell { background: color-mix(in srgb, var(--tier-gold-bright) 4%, var(--bg)); }
.tr--rank-2 td.rank-cell { background: color-mix(in srgb, var(--tier-silver) 4%, var(--bg)); }
.tr--rank-3 td.rank-cell { background: color-mix(in srgb, var(--tier-bronze) 4%, var(--bg)); }

/* Outranks .tr--current-player td:first-child in data-table.css, which is imported
   later and would otherwise drop the shadow that separates the pinned column. */
.data-table .tr--current-player td.rank-cell {
    background: color-mix(in srgb, var(--accent) 8%, var(--bg));
    box-shadow: 2px 0 6px -2px rgba(0, 0, 0, .15), inset 3px 0 0 var(--accent), inset 0 1px 0 color-mix(in srgb, var(--accent) 16%, transparent), inset 0 -1px 0 color-mix(in srgb, var(--accent) 16%, transparent);
}

.data-table tbody tr:hover td.rank-cell {
    background: var(--surface-2);
}

.data-table th.sortable {
    cursor: pointer;
    user-select: none;
}

.data-table__sort-link,
.data-table__sort-link:hover,
.data-table__sort-link:focus-visible {
    color: inherit;
    text-decoration: none;
}

.data-table th.sortable:hover {
    color: var(--text);
}

.data-table th.sortable::after {
    content: '';
    display: inline-block;
    width: .45rem;
    height: .55rem;
    margin-left: .35rem;
    vertical-align: -.08em;
    background:
        linear-gradient(45deg, transparent 43%, currentColor 45%, currentColor 55%, transparent 57%) top left / 50% 50% no-repeat,
        linear-gradient(-45deg, transparent 43%, currentColor 45%, currentColor 55%, transparent 57%) top right / 50% 50% no-repeat,
        linear-gradient(-45deg, transparent 43%, currentColor 45%, currentColor 55%, transparent 57%) bottom left / 50% 50% no-repeat,
        linear-gradient(45deg, transparent 43%, currentColor 45%, currentColor 55%, transparent 57%) bottom right / 50% 50% no-repeat;
    opacity: 0.35;
}

.data-table th.sortable[data-sort-dir="asc"]::after {
    height: .45rem;
    background: none;
    border-top: 1px solid currentColor;
    border-right: 0;
    border-bottom: 0;
    border-left: 1px solid currentColor;
    transform: rotate(45deg);
    opacity: 1;
}

.data-table th.sortable[data-sort-dir="desc"]::after {
    height: .45rem;
    background: none;
    border-top: 0;
    border-right: 1px solid currentColor;
    border-bottom: 1px solid currentColor;
    border-left: 0;
    transform: rotate(45deg);
    opacity: 1;
}

/* The column the table is currently sorted by, which the leaderboard also scrolls
   up against the name. The header needs no extra class: sortByHeader() leaves
   data-sort-dir on exactly one header, and the sticky clone already mirrors that
   attribute. The body cells follow the server-selected metric because a cell carries no
   metric key of its own.

   Cells get weight only, on purpose: a background would outrank the top-3 and
   current-player row colours, and a colour would wipe out the gold/silver/bronze
   tier classes. */
.data-table th.stat-cell[data-sort-dir] {
    background: color-mix(in srgb, var(--accent) 12%, var(--surface));
    color: var(--text);
}

.data-table td.stat-cell--sorted {
    font-weight: 600;
}


@media (max-width: 600px) {
    .data-table th.rank-cell {
        padding: .35rem .3rem;
    }

    /* Every millimetre the pinned column takes is one the metrics lose. */
    .rank-cell__tools {
        gap: .3rem;
    }

    .table-tool-btn {
        min-height: 2rem;
        padding: .2rem .4rem;
    }

    .prev-metric-btn {
        width: 2rem;
    }
}
