.player-profile-page,
.player-identity {
    --identity-foam: #eafbff;
    --identity-muted: #a3cad7;
    --identity-aqua: #39d7d0;
    --identity-gold: #ffc857;
    --identity-ink: #102238;
    color: var(--identity-foam);
}

.player-profile-page {
    --profile-viewport-height: 100vh;
    --profile-content-width: 52rem;
    --profile-gutter: clamp(1rem, 3vw, 2rem);
    --profile-left: max(calc(var(--profile-gutter) + env(safe-area-inset-left)), calc((100% - var(--profile-content-width)) / 2));
    --profile-right: max(calc(var(--profile-gutter) + env(safe-area-inset-right)), calc((100% - var(--profile-content-width)) / 2));
    width: 100%;
    height: var(--profile-viewport-height);
    margin: 0;
    overflow: hidden;
    background: radial-gradient(ellipse at 90% 0%, rgba(57,215,208,0.16), transparent 40rem), linear-gradient(160deg, #105b71, #062543);
    font: 16px/1.5 "Trebuchet MS", "Arial Rounded MT Bold", system-ui, sans-serif;
    color-scheme: dark;
    overscroll-behavior: none;
}

@supports (height: 100dvh) {
    .player-profile-page { --profile-viewport-height: 100dvh; }
}
@media (display-mode: standalone), (display-mode: fullscreen) {
    .player-profile-page { --profile-viewport-height: 100vh; }
    @supports (height: 100lvh) {
        .player-profile-page { --profile-viewport-height: 100lvh; }
    }
}

.player-profile-page *,
.player-identity * { box-sizing: border-box; }
.player-page-shell { display: flex; flex-direction: column; height: 100%; min-height: 0; }
.player-page-header {
    display: flex;
    flex: 0 0 auto;
    align-items: center;
    gap: 1rem;
    padding: calc(1rem + env(safe-area-inset-top)) var(--profile-right) 1rem var(--profile-left);
    border-bottom: 1px solid rgba(234,251,255,0.15);
}
.player-page-header > div { min-width: 0; }
.player-page-header h1 { margin: 0.15rem 0 0; font-size: clamp(1.4rem, 4vw, 2rem); line-height: 1.15; }
.identity-eyebrow { color: var(--identity-aqua); font-size: 0.68rem; font-weight: 800; letter-spacing: 0.13em; text-transform: uppercase; }
.player-page-back {
    display: inline-grid;
    flex: 0 0 auto;
    place-items: center;
    width: 2.8rem;
    height: 2.8rem;
    border: 1px solid rgba(234,251,255,0.3);
    border-radius: 50%;
    background: rgba(3,31,54,0.4);
    color: var(--identity-foam);
    font: 800 1.8rem/1 sans-serif;
    text-decoration: none;
}
.player-page-content {
    flex: 1 1 0;
    min-height: 0;
    overflow-y: auto;
    overscroll-behavior: contain;
    padding: 1.5rem var(--profile-right) calc(1.5rem + env(safe-area-inset-bottom)) var(--profile-left);
    scrollbar-color: rgba(116,236,221,0.42) transparent;
}
.public-identity-content[data-stale="true"] { visibility: hidden; }
.player-page-intro { margin: 0 0 1.25rem; color: var(--identity-muted); font-size: 0.95rem; }
.player-identity { min-width: 0; text-align: left; }
.identity-header { display: flex; align-items: center; gap: 1.2rem; margin-bottom: 1.5rem; }
.identity-header > div { min-width: 0; }
.identity-name { display: block; margin: 0; color: var(--identity-foam); font-size: clamp(1.5rem, 5vw, 2.25rem); line-height: 1.15; overflow-wrap: anywhere; }
.identity-caption,
.identity-note { margin: 0.5rem 0 0; color: var(--identity-muted); font-size: 0.85rem; line-height: 1.5; }
.identity-portrait {
    position: relative;
    display: inline-grid;
    flex: 0 0 auto;
    place-items: center;
    width: 6.5rem;
    height: 6.5rem;
    overflow: hidden;
    border: 1px solid rgba(116,236,221,0.4);
    border-radius: 1.35rem;
    background: radial-gradient(circle at 40% 35%, rgba(57,215,208,0.25), rgba(3,31,54,0.5));
}
.identity-portrait img { width: 100%; height: 100%; object-fit: contain; }
img.identity-portrait { object-fit: contain; }
.identity-portrait img { display: block; }
.identity-portrait > :is(img, .identity-silhouette) { grid-area: 1 / 1; }
.identity-silhouette { position: relative; display: block; width: 45%; height: 30%; border-radius: 50%; background: #90b4c4; }
.identity-silhouette::before { content: ""; position: absolute; top: 9%; right: 88%; width: 48%; height: 82%; background: #90b4c4; clip-path: polygon(0 0, 100% 50%, 0 100%); }
.identity-silhouette::after { content: ""; position: absolute; top: 24%; right: 18%; width: 9%; aspect-ratio: 1; border-radius: 50%; background: #244f68; }
.identity-portrait:not(.has-missing-portrait) > img + .identity-silhouette { display: none; }
.identity-portrait.has-missing-portrait > img { display: none; }
.identity-stats { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 0.75rem; margin: 0 0 1.5rem; }
.identity-stats > div { min-width: 0; padding: 1rem; border: 1px solid rgba(234,251,255,0.12); border-radius: 1rem; background: rgba(3,31,54,0.42); }
.identity-stats dt { color: var(--identity-muted); font-size: 0.78rem; }
.identity-stats dd { margin: 0.45rem 0 0; font-size: clamp(1.1rem, 4vw, 1.65rem); font-weight: 800; line-height: 1.25; overflow-wrap: anywhere; font-variant-numeric: tabular-nums; }
.identity-stats dd small { font-size: 0.72em; font-weight: 400; }
.identity-section { padding-block: 1.25rem; border-top: 1px solid rgba(234,251,255,0.12); }
.player-identity h3 { margin: 0 0 0.65rem; color: var(--identity-foam); font-size: 1.1rem; }
.player-identity fieldset { min-width: 0; margin: 0; padding: 0; border: 0; }
.player-identity legend { padding: 0; color: var(--identity-foam); font-size: 1.1rem; font-weight: 800; }
.avatar-picker { display: grid; grid-template-columns: repeat(auto-fill, minmax(6.5rem, 1fr)); gap: 0.65rem; margin-top: 1rem; }
.avatar-picker > .identity-note { grid-column: 1 / -1; }
.avatar-option {
    display: flex;
    min-width: 0;
    flex-direction: column;
    align-items: center;
    gap: 0.45rem;
    padding: 0.65rem;
    border: 1px solid rgba(234,251,255,0.2);
    border-radius: 0.9rem;
    background: rgba(3,31,54,0.42);
    color: var(--identity-foam);
    font: 700 0.78rem/1.3 "Trebuchet MS", sans-serif;
    text-align: center;
    cursor: pointer;
    touch-action: manipulation;
}
.avatar-option img { display: block; width: 100%; max-width: 5rem; aspect-ratio: 1; object-fit: contain; }
.avatar-option .identity-portrait { width: 100%; height: auto; aspect-ratio: 1; border: 0; border-radius: 0.7rem; }
.avatar-option .identity-portrait img { max-width: none; }
.avatar-option span { overflow-wrap: anywhere; }
.avatar-option[aria-pressed="true"],
.avatar-option.is-selected { border-color: var(--identity-aqua); background: rgba(57,215,208,0.15); box-shadow: inset 0 0 0 2px var(--identity-aqua); }
.avatar-option:disabled { cursor: default; opacity: 0.6; }
.identity-visibility { display: flex; align-items: flex-start; gap: 0.75rem; margin-top: 1.25rem; padding: 1rem; border: 1px solid rgba(116,236,221,0.3); border-radius: 1rem; background: rgba(3,31,54,0.4); }
.identity-visibility input { flex: 0 0 auto; width: 1.35rem; height: 1.35rem; margin: 0.15rem 0 0; accent-color: var(--identity-aqua); }
.identity-visibility label,
.identity-visibility strong { font-size: 0.95rem; font-weight: 800; }
.identity-visibility small { display: block; margin-top: 0.4rem; color: var(--identity-muted); font-size: 0.8rem; font-weight: 400; line-height: 1.45; }
.identity-visibility .identity-note { display: block; }
.identity-settings { margin-top: 1.75rem; padding-top: 1.25rem; border-top: 1px solid rgba(234,251,255,0.15); }
.identity-actions { display: flex; flex-wrap: wrap; gap: 0.65rem; margin-top: 1rem; }
.identity-button,
.identity-button-secondary {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    min-height: 2.9rem;
    padding: 0.65rem 1rem;
    border: 1px solid #b6fff0;
    border-radius: 0.8rem;
    background: var(--identity-aqua);
    color: var(--identity-ink);
    font: 800 0.9rem/1.3 "Trebuchet MS", sans-serif;
    text-decoration: none;
    text-align: center;
    cursor: pointer;
    touch-action: manipulation;
}
.identity-button-secondary { border-color: rgba(116,236,221,0.4); background: rgba(57,215,208,0.1); color: var(--identity-foam); }
.identity-button:disabled,
.identity-button-secondary:disabled { opacity: 0.55; cursor: default; }
.public-profile-preview { margin-top: 1.25rem; padding: 1.1rem; border: 1px solid rgba(234,251,255,0.2); border-radius: 1rem; background: rgba(3,31,54,0.3); }
.public-profile-preview .identity-header { margin-block: 1rem; gap: 0.9rem; }
.public-profile-preview .identity-portrait { width: 4.5rem; height: 4.5rem; border-radius: 1rem; }
.public-profile-preview .identity-name { font-size: 1.25rem; }
.public-profile-preview .identity-stats { margin-bottom: 0; }
.public-profile-preview .identity-stats > div { padding: 0.75rem; }
.public-profile-preview .identity-stats dd { font-size: 1.05rem; }
.identity-status { min-height: 1.5em; margin: 0.9rem 0 0; color: var(--identity-muted); font-size: 0.85rem; line-height: 1.4; }
.identity-status[data-tone="error"] { color: #ffb4bb; }
.identity-status[data-tone="success"] { color: #a9e8d8; }
.player-profile-page a:focus-visible,
.player-identity :is(a, button, input):focus-visible { outline: 3px solid var(--identity-gold); outline-offset: 3px; }
.player-page-back:hover,
.identity-button-secondary:hover { background: rgba(57,215,208,0.2); }
.identity-button:hover:not(:disabled):not(.identity-button-secondary) { background: #72ebd7; }
.player-unavailable { max-width: 36rem; margin: 2rem auto; text-align: center; }
.player-unavailable h2 { font-size: 1.6rem; line-height: 1.2; }
.player-unavailable p { color: var(--identity-muted); }
.player-unavailable .identity-actions { justify-content: center; }
.leaderboard-list { margin: 0; padding: 0; list-style: none; }
.leaderboard-row { display: grid; grid-template-columns: 2.2rem minmax(0, 1fr) auto; align-items: center; gap: 0.8rem; min-height: 5rem; padding-block: 0.75rem; border-bottom: 1px solid rgba(234,251,255,0.13); }
.leaderboard-rank { color: var(--identity-muted); font-size: 0.9rem; font-variant-numeric: tabular-nums; overflow-wrap: anywhere; }
.leaderboard-player { display: flex; min-width: 0; align-items: center; gap: 0.8rem; color: var(--identity-foam); text-decoration: none; }
a.leaderboard-player:hover .leaderboard-name { color: var(--identity-aqua); text-decoration: underline; text-underline-offset: 0.2rem; }
.leaderboard-player .identity-portrait { width: 3.4rem; height: 3.4rem; border-radius: 0.9rem; }
.leaderboard-name { min-width: 0; font-size: 1rem; font-weight: 800; overflow-wrap: anywhere; }
.leaderboard-score { color: var(--identity-gold); font-size: 1rem; font-weight: 800; text-align: right; font-variant-numeric: tabular-nums; }
.leaderboard-score small { display: block; color: var(--identity-muted); font-size: 0.65rem; font-weight: 400; }
.leaderboard-pagination { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 0.7rem; margin-top: 1.5rem; }
.leaderboard-pagination > span { color: var(--identity-muted); font-size: 0.85rem; }
.leaderboard-note { margin: 1.25rem 0 0; color: var(--identity-muted); font-size: 0.8rem; }
.player-profile-page [hidden],
.player-identity [hidden] { display: none !important; }

@media (max-width: 360px) {
    .identity-header { gap: 0.9rem; }
    .identity-header > .identity-portrait { width: 5rem; height: 5rem; }
    .identity-stats > div { padding: 0.8rem; }
    .leaderboard-row { grid-template-columns: 1.6rem minmax(0, 1fr) auto; gap: 0.5rem; }
    .leaderboard-player { gap: 0.5rem; }
    .leaderboard-player .identity-portrait { width: 2.65rem; height: 2.65rem; }
    .leaderboard-name { font-size: 0.85rem; }
    .leaderboard-score { font-size: 0.85rem; }
}
@media (max-height: 480px) {
    .player-page-header { padding-top: calc(0.6rem + env(safe-area-inset-top)); padding-bottom: 0.6rem; }
}
