.profile-dialog {
    width: min(100%, 430px);
}

.profile-header {
    display: grid;
    grid-template-columns: auto minmax(0, 1fr) auto;
    gap: 0.9rem;
    align-items: center;
    margin-bottom: 1.3rem;

    h2 {
        margin: 0;
        min-width: 0;
        color: var(--text-primary);
        font-size: var(--font-size-title-lg);
        line-height: var(--font-leading-tight);
        font-weight: var(--font-weight-heading);
        overflow-wrap: anywhere;
    }
}

.profile-dialog.is-menu {
    .profile-header {
        grid-template-columns: minmax(0, 1fr) auto;
    }
}

.profile-dialog.is-leaderboard {
    width: min(100%, 500px);
}

.profile-icon-button,
.profile-code-copy {
    width: var(--component-icon-button-size);
    height: var(--component-icon-button-size);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border: none;
    border-radius: 999px;
    background: var(--surface-dialog-section);
    color: var(--text-primary);
    transition:
        background var(--motion-duration-fast) var(--motion-ease-out),
        transform var(--motion-duration-fast) var(--motion-ease-out);

    &:hover {
        background: var(--surface-raised);
        transform: scale(1.04);
    }

    &[disabled] {
        opacity: 0.55;
        transform: none;
        cursor: not-allowed;
    }
}

.profile-header-spacer {
    display: block;
    width: var(--component-icon-button-size);
    height: var(--component-icon-button-size);
}

.profile-stats {
    margin-bottom: 1.5rem;
}

.profile-actions {
    display: grid;
    gap: 0.85rem;
}

.profile-settings {
    margin-bottom: 1rem;
}

.profile-action-button {
    justify-content: flex-start;
    align-items: center;
    gap: 0.75rem;
    border-radius: var(--component-button-radius);
    font-size: var(--font-size-body-lg);
    white-space: normal;
    text-align: left;
    line-height: 1.25;

    i {
        font-size: 1.15rem;
        line-height: 1;
    }

    span {
        min-width: 0;
    }
}

.profile-code-card {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    gap: 0.75rem;
    align-items: center;
    padding: 0.8rem 0.95rem;
    margin-bottom: 0.95rem;
    border: 2px dashed var(--border-muted);
    border-radius: var(--radius-lg);
    background: var(--surface-inset-ghost);
}

.profile-code {
    color: var(--text-primary);
    font-size: clamp(1.6rem, 6vw, 2rem);
    letter-spacing: 0.16em;
    text-align: center;
}

.profile-copy-help,
.profile-form-help {
    margin: 0;
    color: var(--text-helper);
    font-size: var(--font-size-body-md);
    line-height: var(--font-leading-copy);
}

.profile-copy-help {
    text-align: center;
    text-wrap: balance;
}

.profile-link-button {
    display: block;
    margin: 0.9rem auto 0;
    max-width: 100%;
    padding: 0;
    border: none;
    background: transparent;
    color: var(--text-primary);
    font: inherit;
    font-size: var(--font-size-body-lg);
    font-weight: 600;
    line-height: 1.35;
    text-align: center;
    text-decoration: underline;
    text-underline-offset: 0.18em;
}

.profile-form {
    display: grid;
    gap: 0.95rem;
    min-width: 0;
}

.profile-section {
    display: grid;
    gap: var(--space-4);
    min-width: 0;
}

.leaderboard-section-header {
    margin-bottom: 0;

    .section-header-action[disabled] {
        opacity: 0.55;
        cursor: wait;
        text-decoration: none;
    }
}

.leaderboard-note {
    padding: 0.85rem 1rem;
    border-radius: var(--radius-lg);
    background: var(--surface-inset);
}

.leaderboard-list,
.leaderboard-skeleton {
    gap: var(--space-3);
}

.leaderboard-row {
    align-items: center;
    padding: 0.95rem 1rem;
}

.leaderboard-row.is-current-user {
    background: linear-gradient(180deg, var(--surface-blue-soft), var(--surface-card));
    border: 1px solid var(--border-strong);
    box-shadow: var(--shadow-sm);
}

.leaderboard-row .list-row-rank {
    min-width: 2rem;
}

.leaderboard-title {
    display: flex;
    align-items: center;
    gap: 0.55rem;
    flex-wrap: wrap;
}

.leaderboard-self-chip {
    flex-shrink: 0;
}

.leaderboard-score {
    min-width: 5.8rem;
    justify-content: center;
}

.leaderboard-empty {
    padding-inline: var(--space-4);
    border-radius: var(--radius-lg);
    background: var(--surface-inset-ghost);
}

.leaderboard-skeleton-rank {
    width: 2rem;
    height: 2rem;
}

.leaderboard-skeleton-body {
    display: grid;
    gap: 0.45rem;
}

.leaderboard-skeleton-title {
    width: min(12rem, 70%);
}

.leaderboard-skeleton-subtitle {
    width: min(8rem, 45%);
}

.leaderboard-skeleton-score {
    width: 5.8rem;
    height: 1.75rem;
    border-radius: var(--radius-full);
}

.profile-input {
    width: 100%;
    min-height: 3.25rem;
    border: 2px solid var(--border-default);
    border-radius: var(--radius-md);
    background: transparent;
    color: var(--text-primary);
    box-shadow: none;
    font-size: clamp(1.1rem, 4.8vw, 1.28rem);
    font-weight: var(--font-weight-regular);
    line-height: 1.2;

    &::placeholder {
        color: var(--text-placeholder);
    }

    &:focus {
        border-color: var(--border-strong);
        box-shadow: none;
    }
}

.profile-code-input {
    text-transform: uppercase;
    letter-spacing: 0.16em;
}

.profile-submit-button {
    width: 100%;
    min-height: 3rem;
    border-radius: var(--component-button-radius);
    font-size: var(--font-size-body-lg);
    font-weight: var(--font-weight-strong);
    white-space: normal;
}

.offline-notice {
    display: flex;
    align-items: center;
    gap: 0.4rem;
    font-size: 0.8rem;
    padding: 0.4rem 1rem;
    background: var(--surface-system-subtle);
    border-top: 1px solid var(--border-subtle);
    color: var(--text-secondary);
}
