.profile-back {
    display: flex;
    justify-content: flex-end;
}

.profile-hero {
    background: linear-gradient(135deg,
        color-mix(in srgb, var(--team-color, var(--accent)) 12%, var(--surface)) 0%,
        var(--surface) 65%
    );
    border: 1px solid color-mix(in srgb, var(--team-color, var(--border)) 30%, var(--border));
    border-radius: 12px;
    padding: 1.5rem;
    display: flex;
    flex-direction: column;
    gap: .75rem;
}

.profile-hero__name .country-flag {
    width: 24px;
    height: 18px;
}

.profile-hero__name {
    display: flex;
    align-items: center;
    gap: .5rem;
    color: var(--text);
    font-size: 1.75rem;
    font-weight: 700;
    margin: 0;
    line-height: 1.2;
}

.profile-hero__team-icon {
    display: block;
    width: 28px;
    height: 28px;
    object-fit: contain;
    flex-shrink: 0;
}

.profile-hero__badges {
    display: flex;
    align-items: center;
    gap: .4rem;
    flex-wrap: wrap;
}

.profile-hero__rank {
    display: inline-flex;
    align-items: center;
    background: color-mix(in srgb, var(--team-color, var(--accent)) 15%, transparent);
    color: var(--team-color, var(--accent));
    border: 1px solid color-mix(in srgb, var(--team-color, var(--accent)) 35%, transparent);
    border-radius: .3rem;
    font-size: .8rem;
    font-weight: 700;
    padding: .2rem .5rem;
}

/* Only the owner sees this: a value of theirs is kept off the leaderboards. */
.profile-capped-notice {
    background: var(--surface-2);
    border: 1px solid var(--border);
    border-left: 3px solid var(--red);
    border-radius: 8px;
    color: var(--text-muted);
    font-size: .82rem;
    line-height: 1.45;
    padding: .7rem .9rem;
}

.profile-hero__flag {
    display: inline-flex;
    align-items: center;
    gap: .3rem;
    background: var(--surface-2);
    border: 1px solid var(--border);
    border-radius: .3rem;
    font-size: .75rem;
    color: var(--text-muted);
    padding: .2rem .5rem;
}

.profile-highlights {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: .75rem;
}

.profile-highlights__card {
    background: var(--surface-2);
    border: 1px solid color-mix(in srgb, var(--card-accent, var(--border)) 24%, var(--border));
    border-radius: var(--radius);
    min-width: 0;
    padding: 1rem;
    display: flex;
    flex-direction: column;
    gap: .45rem;
    box-shadow: 0 1px 0 color-mix(in srgb, var(--card-accent, var(--border)) 18%, transparent);
}

.profile-highlights__header {
    display: flex;
    /* DOM order is icon → label so mobile reads left to right; desktop flips it back. */
    flex-direction: row-reverse;
    align-items: flex-start;
    justify-content: space-between;
    margin-bottom: .15rem;
}

.profile-highlights__label {
    font-size: .75rem;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: .05em;
    line-height: 1.25;
}

.profile-highlights__icon {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 2rem;
    height: 2rem;
    color: var(--card-accent, var(--text-muted));
    background: color-mix(in srgb, var(--card-accent, var(--accent)) 14%, transparent);
    border: 1px solid color-mix(in srgb, var(--card-accent, var(--border)) 28%, var(--border));
    border-radius: 50%;
    opacity: .9;
    flex-shrink: 0;
}

.profile-highlights__value {
    min-width: 0;
    overflow: hidden;
    font-size: 1.35rem;
    font-weight: 700;
    color: var(--text);
    font-variant-numeric: tabular-nums;
    line-height: 1.2;
    text-overflow: ellipsis;
    white-space: nowrap;
}

@media (max-width: 900px) {
    .profile-highlights {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }
}

.profile-flag {
    font-size: .8rem;
    color: var(--text-muted);
    display: inline-flex;
    align-items: center;
    gap: .25rem;
    line-height: 1;
}

.profile-flag svg {
    flex: 0 0 auto;
}

.profile-section {
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

.profile-section__title {
    margin: 0;
    color: var(--text);
    font-size: 1.1rem;
    font-weight: 700;
}

.profile-medal-sections {
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

.profile-metric-category-title {
    font-size: .75rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: .05em;
    color: var(--text-muted);
    margin: 0;
}

.profile-stat-list {
    display: grid;
    gap: .25rem;
}

.profile-stat-row {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    align-items: baseline;
    gap: 1rem;
    padding: .45rem 0;
    border-bottom: 1px solid var(--border);
}

.profile-stat-row__label {
    min-width: 0;
    color: var(--text-muted);
    font-size: .9rem;
}

.profile-stat-row__value {
    color: var(--text);
    font-weight: 700;
    font-variant-numeric: tabular-nums;
    text-align: right;
    white-space: nowrap;
}

/* Opens an explanation in a popover, which the browser light-dismisses. */
.profile-info-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 2rem;
    min-height: 2rem;
    margin: -.5rem 0;
    padding: 0;
    border: 0;
    background: none;
    color: var(--text-muted);
    vertical-align: middle;
    cursor: pointer;
}

.profile-info-btn:hover,
.profile-info-btn:focus-visible {
    color: var(--accent);
}

/* The global margin reset removes the browser's centring, so it is restored here. */
.profile-info-popover {
    position: fixed;
    inset: 0;
    width: min(26rem, calc(100vw - 2rem));
    height: fit-content;
    max-height: calc(100dvh - 2rem);
    margin: auto;
    overflow-y: auto;
    padding: 1rem;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: var(--surface);
    color: var(--text);
    font-size: .9rem;
    line-height: 1.5;
}

.profile-info-popover:popover-open {
    display: flex;
    flex-direction: column;
    gap: .6rem;
}

.profile-info-popover::backdrop {
    background: rgba(0, 0, 0, .6);
}

.profile-info-popover a {
    color: var(--accent);
    text-decoration: underline;
}

.profile-info-popover__title {
    font-size: 1rem;
}

.profile-info-popover__close {
    align-self: flex-end;
}

.profile-medal-section {
    display: flex;
    flex-direction: column;
    gap: .75rem;
}

.profile-medal-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(132px, 1fr));
    gap: .65rem;
}

.profile-medal-card {
    display: flex;
    min-width: 0;
    align-items: center;
    gap: .6rem;
    padding: .65rem;
    color: var(--text);
    text-decoration: none;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
}

.profile-medal-card__image {
    position: relative;
    flex: 0 0 auto;
    width: 56px;
    height: 56px;
}

.profile-medal-card__image img {
    display: block;
    width: 56px;
    height: 56px;
    object-fit: contain;
}

.profile-medal-card--untracked .profile-medal-card__image img {
    opacity: .58;
}

.profile-medal-card__value {
    position: absolute;
    left: 50%;
    bottom: -.25rem;
    display: inline-flex;
    align-items: baseline;
    justify-content: center;
    max-width: 4.8rem;
    overflow: hidden;
    padding: .12rem .35rem;
    color: var(--text);
    background: rgba(8, 13, 20, .88);
    border: 1px solid var(--border);
    border-radius: 999px;
    font-size: .68rem;
    font-weight: 700;
    line-height: 1.2;
    font-variant-numeric: tabular-nums;
    white-space: nowrap;
    transform: translateX(-50%);
}

.profile-medal-card__value small {
    color: var(--text-muted);
    font-size: .58rem;
    font-weight: 600;
}

.profile-medal-card--bronze { border-color: rgba(205,127,50,.25); }
.profile-medal-card--silver { border-color: rgba(184,184,200,.3); }
.profile-medal-card--gold { border-color: rgba(213,169,0,.3); }
.profile-medal-card--platinum { border-color: rgba(159,183,217,.35); }

.profile-medal-card__name {
    min-width: 0;
    overflow: hidden;
    color: var(--text);
    font-size: .86rem;
    font-weight: 650;
    line-height: 1.25;
    text-overflow: ellipsis;
}

@media (max-width: 600px) {
    .profile-highlights {
        grid-template-columns: 1fr;
    }

    /* One row per card: icon, label, then the value pushed to the right. */
    .profile-highlights__card {
        flex-direction: row;
        align-items: center;
        justify-content: space-between;
        gap: .75rem;
        padding: .65rem .85rem;
    }

    .profile-highlights__header {
        flex: 1 1 auto;
        min-width: 0;
        flex-direction: row;
        align-items: center;
        justify-content: flex-start;
        gap: .6rem;
        margin-bottom: 0;
    }

    .profile-highlights__icon {
        width: 1.75rem;
        height: 1.75rem;
    }

    .profile-highlights__label {
        min-width: 0;
        overflow: hidden;
        text-transform: none;
        letter-spacing: 0;
        font-size: .85rem;
        text-overflow: ellipsis;
        white-space: nowrap;
    }

    .profile-highlights__value {
        flex-shrink: 0;
        font-size: 1.05rem;
        text-align: right;
    }

    .profile-medal-grid {
        grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
    }
}
